From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46661) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMcoz-0004Is-II for qemu-devel@nongnu.org; Sun, 09 Mar 2014 08:27:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WMcot-0002b1-JP for qemu-devel@nongnu.org; Sun, 09 Mar 2014 08:27:13 -0400 Received: from lnantes-156-75-100-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:55954 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMcot-0002at-99 for qemu-devel@nongnu.org; Sun, 09 Mar 2014 08:27:07 -0400 Date: Sun, 9 Mar 2014 13:27:05 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140309122705.GF3307@irqsave.net> References: <1394232956-27852-1-git-send-email-mreitz@redhat.com> <1394232956-27852-3-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1394232956-27852-3-git-send-email-mreitz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 02/12] check-qdict: Add test for qdict_join() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , =?iso-8859-1?Q?Beno=EEt?= Canet , qemu-devel@nongnu.org, Stefan Hajnoczi The Friday 07 Mar 2014 =E0 23:55:46 (+0100), Max Reitz wrote : > Add some test cases for qdict_join(). >=20 > Signed-off-by: Max Reitz > --- > tests/check-qdict.c | 87 +++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 1 file changed, 87 insertions(+) >=20 > diff --git a/tests/check-qdict.c b/tests/check-qdict.c > index 2ad0f78..a9296f0 100644 > --- a/tests/check-qdict.c > +++ b/tests/check-qdict.c > @@ -444,6 +444,92 @@ static void qdict_array_split_test(void) > QDECREF(test_dict); > } > =20 > +static void qdict_join_test(void) > +{ > + QDict *dict1, *dict2; > + bool overwrite =3D false; > + int i; > + > + dict1 =3D qdict_new(); > + dict2 =3D qdict_new(); > + > + > + /* Test everything once without overwrite and once with */ > + do > + { > + /* Test empty dicts */ > + qdict_join(dict1, dict2, overwrite); > + > + g_assert(qdict_size(dict1) =3D=3D 0); > + g_assert(qdict_size(dict2) =3D=3D 0); > + > + > + /* First iteration: Test movement */ > + /* Second iteration: Test empty source and non-empty destinati= on */ > + qdict_put(dict2, "foo", qint_from_int(42)); > + > + for (i =3D 0; i < 2; i++) { > + qdict_join(dict1, dict2, overwrite); > + > + g_assert(qdict_size(dict1) =3D=3D 1); > + g_assert(qdict_size(dict2) =3D=3D 0); > + > + g_assert(qdict_get_int(dict1, "foo") =3D=3D 42); > + } > + > + > + /* Test non-empty source and destination without conflict */ > + qdict_put(dict2, "bar", qint_from_int(23)); > + > + qdict_join(dict1, dict2, overwrite); > + > + g_assert(qdict_size(dict1) =3D=3D 2); > + g_assert(qdict_size(dict2) =3D=3D 0); > + > + g_assert(qdict_get_int(dict1, "foo") =3D=3D 42); > + g_assert(qdict_get_int(dict1, "bar") =3D=3D 23); > + > + > + /* Test conflict */ > + qdict_put(dict2, "foo", qint_from_int(84)); > + > + qdict_join(dict1, dict2, overwrite); > + > + g_assert(qdict_size(dict1) =3D=3D 2); > + g_assert(qdict_size(dict2) =3D=3D !overwrite); > + > + g_assert(qdict_get_int(dict1, "foo") =3D=3D overwrite ? 84 : 4= 2); > + g_assert(qdict_get_int(dict1, "bar") =3D=3D 23); > + > + if (!overwrite) { > + g_assert(qdict_get_int(dict2, "foo") =3D=3D 84); > + } > + > + > + /* Check the references */ > + g_assert(qdict_get(dict1, "foo")->refcnt =3D=3D 1); > + g_assert(qdict_get(dict1, "bar")->refcnt =3D=3D 1); > + > + if (!overwrite) { > + g_assert(qdict_get(dict2, "foo")->refcnt =3D=3D 1); > + } > + > + > + /* Clean up */ > + qdict_del(dict1, "foo"); > + qdict_del(dict1, "bar"); > + > + if (!overwrite) { > + qdict_del(dict2, "foo"); > + } > + } > + while (overwrite ^=3D true); > + > + > + QDECREF(dict1); > + QDECREF(dict2); > +} > + > /* > * Errors test-cases > */ > @@ -584,6 +670,7 @@ int main(int argc, char **argv) > g_test_add_func("/public/iterapi", qdict_iterapi_test); > g_test_add_func("/public/flatten", qdict_flatten_test); > g_test_add_func("/public/array_split", qdict_array_split_test); > + g_test_add_func("/public/join", qdict_join_test); > =20 > g_test_add_func("/errors/put_exists", qdict_put_exists_test); > g_test_add_func("/errors/get_not_exists", qdict_get_not_exists_tes= t); > --=20 > 1.9.0 >=20 Reviewed-by: Benoit Canet