From: Max Reitz <mreitz@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 5/5] tests: Add check-qobject for equality tests
Date: Mon, 3 Jul 2017 18:13:50 +0200 [thread overview]
Message-ID: <2994bfb3-b442-c6e2-a600-a2644ad2331f@redhat.com> (raw)
In-Reply-To: <78e9f722-b6b8-ed94-cf1e-4760059b077f@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3422 bytes --]
On 2017-07-03 16:15, Eric Blake wrote:
> On 07/03/2017 07:25 AM, Max Reitz wrote:
>> Add a new test file (check-qobject.c) for unit tests that concern
>> QObjects as a whole.
>>
>> Its only purpose for now is to test the qobject_is_equal() function.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>> tests/Makefile.include | 4 +-
>> tests/check-qobject.c | 312 +++++++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 315 insertions(+), 1 deletion(-)
>> create mode 100644 tests/check-qobject.c
>>
>
>> + * Note that qobject_is_equal() is not really an equivalence relation,
>> + * so this function may not be used for all objects (reflexivity is
>> + * not guaranteed).
>
> May be worth expanding the comment to mention NaN in QNum as the culprit
> for this fact.
True.
>> +static void do_test_equality(bool expected, ...)
>> +{
>> + va_list ap_count, ap_extract;
>> + QObject **args;
>> + int arg_count = 0;
>> + int i, j;
>> +
>> + va_start(ap_count, expected);
>> + va_copy(ap_extract, ap_count);
>> + while (va_arg(ap_count, QObject *) != &_test_equality_end_of_arguments) {
>
> Here, you're careful to allow a NULL argument,
>
>
>> +static void do_free_all(int _, ...)
>> +{
>> + va_list ap;
>> + QObject *obj;
>> +
>> + va_start(ap, _);
>> + while ((obj = va_arg(ap, QObject *)) != NULL) {
>> + qobject_decref(obj);
>> + }
>
> Here, you stop on the first NULL, and aren't checking for the special
> sentinel that can't be freed.
>
>> + va_end(ap);
>> +}
>> +
>> +#define free_all(...) \
>> + do_free_all(0, __VA_ARGS__, NULL)
>
> Then again, you don't pass the special sentinel. So as long as NULL is
> the last argument(s) on any test that passes NULL (rather than an
> intermediate argument), you don't need to use the sentinel, and stopping
> iteration on the first NULL is okay. A bit magic, but I can live with it.
I don't mind using the sentinel here, too, but passing NULL doesn't make
much sense here. It does for test_equality(), though.
>> +
>> +static void qobject_is_equal_null_test(void)
>> +{
>> + test_equality(false, qnull(), NULL);
>> +}
>
> Where do you test_equality(true, NULL, NULL) ?
Automatically in do_test_equality().
(It automatically tests whether all arguments are equal to itself --
which is why I can't use it to test NaN.)
>> +
>> +static void qobject_is_equal_num_test(void)
>> +{
>> + QNum *u0, *i0, *d0, *d0p25, *dnan, *um42, *im42, *dm42;
>> + QString *s0, *s_empty;
>> + QBool *bfalse;
>> +
>> + u0 = qnum_from_uint(0u);
>> + i0 = qnum_from_int(0);
>> + d0 = qnum_from_double(0.0);
>> + d0p25 = qnum_from_double(0.25);
>> + dnan = qnum_from_double(0.0 / 0.0);
>
> Ah, so you ARE testing NaN as a QNum, even though it can't occur in
> JSON. Might be worth a comment.
Sure, why not.
>> +
>> + /* Containing an NaN value will make this dict compare unequal to
>
> s/an/a/ (if you pronounce it "nan" or "not-a-number") (but I guess no
> change if you pronounce it "en-a-en")
I pronounce it en-a-en, but I don't know whether that's the usual way. ;-)
> There might be some improvements to add, but as written the test is
> reasonable, and some testing is better than none, so:
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks!
Max
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 498 bytes --]
next prev parent reply other threads:[~2017-07-03 16:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-03 12:25 [Qemu-devel] [PATCH v3 0/5] block: Don't compare strings in bdrv_reopen_prepare() Max Reitz
2017-07-03 12:25 ` [Qemu-devel] [PATCH v3 1/5] qapi/qnull: Add own header Max Reitz
2017-07-03 12:35 ` Eric Blake
2017-07-03 12:25 ` [Qemu-devel] [PATCH v3 2/5] qapi: Add qobject_is_equal() Max Reitz
2017-07-03 12:44 ` Eric Blake
2017-07-05 7:07 ` Markus Armbruster
2017-07-05 13:48 ` Max Reitz
2017-07-05 14:15 ` Eric Blake
2017-07-05 16:11 ` Markus Armbruster
2017-07-05 16:05 ` Max Reitz
2017-07-05 16:22 ` Max Reitz
2017-07-05 16:29 ` Eric Blake
2017-07-05 17:00 ` Max Reitz
2017-07-05 17:04 ` Max Reitz
2017-07-05 17:22 ` Eric Blake
2017-07-05 17:18 ` Eric Blake
2017-07-05 16:30 ` Max Reitz
2017-07-03 12:25 ` [Qemu-devel] [PATCH v3 3/5] block: qobject_is_equal() in bdrv_reopen_prepare() Max Reitz
2017-07-03 12:51 ` Eric Blake
2017-07-03 13:01 ` Max Reitz
2017-07-03 14:29 ` Eric Blake
2017-07-05 7:14 ` Markus Armbruster
2017-07-05 17:50 ` Max Reitz
2017-07-03 12:25 ` [Qemu-devel] [PATCH v3 4/5] iotests: Add test for non-string option reopening Max Reitz
2017-07-03 12:25 ` [Qemu-devel] [PATCH v3 5/5] tests: Add check-qobject for equality tests Max Reitz
2017-07-03 14:15 ` Eric Blake
2017-07-03 16:13 ` Max Reitz [this message]
2017-07-05 7:22 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2994bfb3-b442-c6e2-a600-a2644ad2331f@redhat.com \
--to=mreitz@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).