From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcFQM-0003VX-Ud for qemu-devel@nongnu.org; Wed, 16 Sep 2015 12:19:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcFQJ-0001HV-PS for qemu-devel@nongnu.org; Wed, 16 Sep 2015 12:19:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcFQJ-0001HN-Hq for qemu-devel@nongnu.org; Wed, 16 Sep 2015 12:19:07 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 0F2F791C19 for ; Wed, 16 Sep 2015 16:19:07 +0000 (UTC) References: <1442419377-9309-1-git-send-email-marcandre.lureau@redhat.com> <1442419377-9309-2-git-send-email-marcandre.lureau@redhat.com> From: Eric Blake Message-ID: <55F9967A.2010408@redhat.com> Date: Wed, 16 Sep 2015 10:19:06 -0600 MIME-Version: 1.0 In-Reply-To: <1442419377-9309-2-git-send-email-marcandre.lureau@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Uj6LA0wkoDJL2Td49wLGv5nx4FTH9II1R" Subject: Re: [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Uj6LA0wkoDJL2Td49wLGv5nx4FTH9II1R Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/16/2015 10:02 AM, marcandre.lureau@redhat.com wrote: > From: Marc-Andr=C3=A9 Lureau >=20 > While reading the function I decided to write some tests. >=20 > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > tests/test-cutils.c | 91 +++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 1 file changed, 91 insertions(+) >=20 > diff --git a/tests/test-cutils.c b/tests/test-cutils.c > index 0046c61..a3de6ab 100644 > --- a/tests/test-cutils.c > +++ b/tests/test-cutils.c > @@ -1352,6 +1352,86 @@ static void test_qemu_strtoull_full_max(void) > g_assert_cmpint(res, =3D=3D, ULLONG_MAX); > } > =20 > +static void test_qemu_strtosz_simple(void) > +{ > + const char *str =3D "12345M"; > + char *endptr =3D NULL; > + int64_t res; > + > + res =3D qemu_strtosz(str, &endptr); > + g_assert_cmpint(res, =3D=3D, 12345 * M_BYTE); > + g_assert(endptr =3D=3D str + 6); > + > + res =3D qemu_strtosz(str, NULL); > + g_assert_cmpint(res, =3D=3D, 12345 * M_BYTE); > +} Would it also be worth some negative tests, such as bogus suffix (for example, does "1234x" fail to parse, or parse "1234" and leave "x" unparsed?) But what you have is a strict improvement (any test is better than none!)= so Reviewed-by: Eric Blake > +static void test_qemu_strtosz_erange(void) > +{ > + const char *str =3D "10E"; > + int64_t res; > + > + res =3D qemu_strtosz(str, NULL); > + g_assert_cmpint(res, =3D=3D, -ERANGE); > +} This was the only negative test I see. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --Uj6LA0wkoDJL2Td49wLGv5nx4FTH9II1R Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJV+ZZ6AAoJEKeha0olJ0Nqaj8H/1puJJXjOAqHfC/Uogl/jW21 I4iGfvGKQ+sO6OYlUBSGYqDkLte3y66hEyuVVo0U3AD08iNH4Fdr/HuaJU0Sl7uV 6bPhGDGUSbIQosCN0fiBVaiKazo1964T9L9R55K4kI3BYlnh+1x9emV8/MC19e22 ny/IFO2S0C1aMsJDBsfcNQ2nHK0RNhe49u4FjnlOoXD59Zpw4QirdROt8YBEsCYG E1xKU+ZGRwHLXvPTcqDBuFrwAvg4ChcTjze/4u7mwR0Eh9YKvImVE/MAaBIs6jcR nYVAhZz9BTzz4KT+pkKPC1dgY3BocHovvbiyv0VZ9K6m8eFvEksDkps/aCOYlqU= =5ccE -----END PGP SIGNATURE----- --Uj6LA0wkoDJL2Td49wLGv5nx4FTH9II1R--