From nobody Sat Apr 27 09:16:36 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 1499642207399316.766572958235; Sun, 9 Jul 2017 16:16:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62C2B85A05; Sun, 9 Jul 2017 23:16:45 +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 2EF5117CCF; Sun, 9 Jul 2017 23:16:45 +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 2AE3941F76; Sun, 9 Jul 2017 23:16:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v69NGgCC029031 for ; Sun, 9 Jul 2017 19:16:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id B433417B4F; Sun, 9 Jul 2017 23:16:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF7FE17CCF for ; Sun, 9 Jul 2017 23:16:41 +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 ED89985A05 for ; Sun, 9 Jul 2017 23:16:37 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id v31so10811787qtb.3 for ; Sun, 09 Jul 2017 16:16:37 -0700 (PDT) Received: from localhost.localdomain ([187.107.160.21]) by smtp.googlemail.com with ESMTPSA id z1sm6988958qkb.37.2017.07.09.16.16.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Jul 2017 16:16:35 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 62C2B85A05 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx02.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 62C2B85A05 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CuFQdGYi" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ED89985A05 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ED89985A05 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=CuFQdGYifZ5OQVdhNP2IdCFTofs05UUMQQM5Lin6VUSQRz1ZtRC0BlxNWQZwTo0Ecg j86hJO/dp3Gm/2KzUsk6myoc/yeP6bbou0K6PzJywrKX7WMsQRQV8GWSTzAqA7stLg8k aaBEslE0+sUAmBPgk1RujwPwZoQMOHZ+bxfkk5zVx17hxRLeJhe1Xuj09aCBEZlj1YtO 8zm/mLv9XVvmcJCItqVSJ4eNKjNtOaaatVR74k/SXp/fJLbiufJKEUp595AKB4PmvSqw FNOW0ABn27C5qU+wb1Ua1DOkHUB5I1IERlRfa6VkbR2yxT26FC4809OPvp9Ox2gex7f0 f3ug== 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=Nyh6KihjC1ge3RNGwj7PkFIMObiep9oXOBnLY5IVE+zrMchNra6rhj9v4DfZI2cUJT mn3W9g+nOEjQvjR4f4j4qQ4fTo/XTOBSdYgC/Yt7QdjLN4LusPPo7/cWGnhMVgecHBMv 3qN87ktKyGuTvLqYrxiHlfaPEn674wAAcLos+XGdqOdE/DEAOsIUYKybZO+yz/DcuO/n HvyvCwjaKaKGT84m6zhSsgU1Vp5GiSs7hnhDUE/MGj17PnPwb23RRyiONRCGzPk6Jd8B gLPv8r95IeE4wZKabK731AUqjVzNNSknAp2XRmkCE+w5vJ/gJZcK5kmAO8CJzCUd3+PJ kB9g== X-Gm-Message-State: AIVw1104+t+fOOBt1+5Y2mlGWJtHBZNozHXD88YSch85nxOtT+2yIRIh /uAmpWHhe4glv4Sr X-Received: by 10.237.32.70 with SMTP id 64mr1045202qta.218.1499642196477; Sun, 09 Jul 2017 16:16:36 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 9 Jul 2017 20:16:30 -0300 Message-Id: <1499642190-25451-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.26]); Sun, 09 Jul 2017 23:16:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 09 Jul 2017 23:16:38 +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.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 09 Jul 2017 23:16:46 +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