From nobody Mon Apr 29 15:44:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499641575061948.3330088428659; Sun, 9 Jul 2017 16:06:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69DF5267C7; Sun, 9 Jul 2017 23:06:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B93D1715A; Sun, 9 Jul 2017 23:06:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3779E41F76; Sun, 9 Jul 2017 23:06:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v69N6AOT027503 for ; Sun, 9 Jul 2017 19:06:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3263117DC6; Sun, 9 Jul 2017 23:06:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B14318223 for ; Sun, 9 Jul 2017 23:06:08 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1094BC0587F6 for ; Sun, 9 Jul 2017 23:06:07 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id c20so10787989qte.0 for ; Sun, 09 Jul 2017 16:06:07 -0700 (PDT) Received: from localhost.localdomain ([187.107.160.21]) by smtp.googlemail.com with ESMTPSA id w28sm7978259qth.8.2017.07.09.16.06.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Jul 2017 16:06:05 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 69DF5267C7 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 69DF5267C7 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LuC4LDIN" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1094BC0587F6 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1094BC0587F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=9EojIi/gtlg/6PauMsNh1JN+s6EpfM7o7VMcvfDX6LE=; b=LuC4LDINuWhrp83LWhQ8X9dQxsGIw8DJrIib1/9NAYrOR08tvAYZmL0DotCODVWTBr 4P6iYdDVoTjWxdHHeO81iWgohxlaBdiNJwh3BZOaBZuzob7s48dIR2rFZcHbYT6Oy+Ft C4Vz8XD5a733ICiJXbrvPxFLgXuHlX+9sEIYT+DJqGWqYjyg/DIA563Wp+6CarpMaw5j jnpu2ZwjxJsz2ItktoROTlgoYRtHIt6ZHBiojzXdr8ku/QNbsiuC4Aa6AY2mx+9FzmDw IoIChPCk+wS5Z/1IbXhiUqjR9rTTKyauquGrrK6dPS0D6Org0i4zV68XNmkZpCfbZMxB lBew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=9EojIi/gtlg/6PauMsNh1JN+s6EpfM7o7VMcvfDX6LE=; b=MFmJyyM2uSHdrr0IddnbH0sgRF+hDQGfP8HjKKsqJcD24HoiQqP3jy5/52SbJN+Qgm 8Iw6WlWJXNUF1IOo193bB8OSCOGokGAj5uB03o4OLhARcEWkBqgB0W8IbS6r58DL6e27 HOsU8Y9zTnKngwE9oJXZYWtnfDhLF7f1xDmsxOSkfXj2Qtsq3VvBz1kQjfwbTQqzqShN 1et0tug/K+DROT32rVoo1w59/4ptxWIj8I8eNQybXkKSYcazIFLb7E3knUAohip6bEps lHrd5w0shhSnN15VsE9uC9y4dDamDTYPog2YTgRe7TRkAMttLp5irSA3OyTmHUB/k/mb QGHA== X-Gm-Message-State: AIVw110WSU8zNMIRt5j3VAphT6DY16ISxSsltDhkPisoAxvcW/8VNstw tDYy7xsvkJYjNbLV X-Received: by 10.237.42.129 with SMTP id t1mr963701qtd.93.1499641565960; Sun, 09 Jul 2017 16:06:05 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 9 Jul 2017 20:05:55 -0300 Message-Id: <1499641555-25056-1-git-send-email-jcfaracco@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 09 Jul 2017 23:06:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 09 Jul 2017 23:06:07 +0000 (UTC) for IP:'209.85.216.195' DOMAIN:'mail-qt0-f195.google.com' HELO:'mail-qt0-f195.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.17 * (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.195 mail-qt0-f195.google.com 209.85.216.195 mail-qt0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] test: adding tests to virStrToDouble() inside virstringtest. X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 09 Jul 2017 23:06:13 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There are no occurrences of tests related to Strings and Double numbers inside virstringtest.c. This commit introduces some tests to validate the conversion. The test does not include locale changes yet. Signed-off-by: Julio Faracco --- tests/virstringtest.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 80 insertions(+) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 97c6e76..cc95d3c 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -652,6 +652,48 @@ testStringToLong(const void *opaque) } =20 =20 +struct stringToDoubleData { + const char *str; + const char *end_ptr; + double res; +}; + +/* This test checks if double strings are successfully converted to double + * number considering the byproduct string too. */ +static int +testStringToDouble(const void *opaque) +{ + const struct stringToDoubleData *data =3D opaque; + int ret =3D -1; + char *end_ptr =3D NULL; + double res =3D 0; + + /* end_ptr returns or a substring or an empty string. + * It never returns a NULL pointer. */ + if ((ret =3D virStrToDouble(data->str, + data->end_ptr ? &end_ptr : NULL, + &res)) < 0) { + fprintf(stderr, "Convert error of '%s', expected '%lf'\n", + data->str, data->res); + return ret; + } + + if (res !=3D data->res) { + fprintf(stderr, "Returned '%lf', expected '%lf'\n", + res, data->res); + return -1; + } + + /* Comparing substrings. */ + if (STRNEQ_NULLABLE(end_ptr, data->end_ptr)) { + fprintf(stderr, "Expected substring '%s', but got '%s'\n", + end_ptr, data->end_ptr); + return -1; + } + + return ret; +} + /* The point of this test is to check whether all members of the array are * freed. The test has to be checked using valgrind. */ static int @@ -965,6 +1007,44 @@ mymain(void) TEST_STRTOL("-18446744073709551616", NULL, 0, -1, 0U, -1, 0LL, -1, 0ULL, -1); =20 +#define TEST_STRTOD(str, end_ptr, res) \ + do { \ + struct stringToDoubleData data =3D { \ + str, end_ptr, res, \ + }; \ + if (virTestRun("virStringToDouble '" str "'", \ + testStringToDouble, &data) < 0) \ + ret =3D -1; \ + } while (0) + + /* Simple numbers. */ + TEST_STRTOD("0.0", NULL, 0); + TEST_STRTOD("1.0", NULL, 1); + TEST_STRTOD("3.14159", NULL, 3.14159); + TEST_STRTOD("0.57721", NULL, 0.57721); + + /* Testing ending string. */ + TEST_STRTOD("2.718", "", 2.718); + TEST_STRTOD("2.718 281 828 459", " 281 828 459", 2.718); + TEST_STRTOD("2.718,281,828,459", ",281,828,459", 2.718); + + /* Scientific numbers. */ + TEST_STRTOD("3.14159e+000", NULL, 3.14159); + TEST_STRTOD("2.00600e+003", NULL, 2006); + TEST_STRTOD("1.00000e-010", NULL, 1e-010); + + /* Negative numbers. */ + TEST_STRTOD("-1.6180339887", NULL, -1.6180339887); + TEST_STRTOD("-0.00031e-010", NULL, -0.00031e-010); + + /* Long numbers. */ + TEST_STRTOD("57089907708238388904078437636832797971793838081897.0", + NULL, + 57089907708238388904078437636832797971793838081897.0); + TEST_STRTOD("3.141592653589793238462643383279502884197169399375105", + NULL, + 3.141592653589793238462643383279502884197169399375105); + /* test virStringListFreeCount */ if (virTestRun("virStringListFreeCount", testVirStringListFreeCount, NULL) < 0) --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list