From nobody Fri Apr 19 13:28:15 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 14996415340589.424373742978446; Sun, 9 Jul 2017 16:05:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83ED181227; Sun, 9 Jul 2017 23:05:29 +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 4D3B31711D; Sun, 9 Jul 2017 23:05:28 +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 4BE4A41F77; Sun, 9 Jul 2017 23:05:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v69N4qYv027458 for ; Sun, 9 Jul 2017 19:04:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A16460E3D; Sun, 9 Jul 2017 23:04:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50FA1756BF for ; Sun, 9 Jul 2017 23:04:50 +0000 (UTC) Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) (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 20043C04B310 for ; Sun, 9 Jul 2017 23:04:49 +0000 (UTC) Received: by mail-qt0-f194.google.com with SMTP id m54so10782195qtb.1 for ; Sun, 09 Jul 2017 16:04:49 -0700 (PDT) Received: from localhost.localdomain ([187.107.160.21]) by smtp.googlemail.com with ESMTPSA id p13sm3354009qkl.58.2017.07.09.16.04.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Jul 2017 16:04:47 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83ED181227 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx01.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 83ED181227 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iFsRa+Ft" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 20043C04B310 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 20043C04B310 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=iFsRa+FtSj8FRkNu+bZ93xsps21QwPIKA8L7ioEnWSfC7Cg5enngjaDoBriq9hLNdk k8l/sN1eMczjenopZq0vVWkVPNo59bDxAC/3vNCRdx7UbeLV4z5ZM7HlKuis2IVGeiNs Zj2Kviuljgh2KYy4YrtDwI4gU4+ICZbTo8MTj5sAAUmmfsmLCDZeOCcx+52GUuDkpCFP mLln0cu9RIfqMSbD3pjY2w/vs6kQIn6OdHoWDzrVgoRyaTnfSkXLjbOxW46aNYic/i/h rcb5J6wzTqmKtAGnJw6PvIB5RkV7O4n3ufJ6x5A/gWJhKM75NxHveufUor5+QmxwRwe6 ly9Q== 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=E+r8EaRNPfmXtoOzqCdovBRruHlUsJAULFSLiQ6yGBvX1kVjrECPyc7LK+KsA9AQ0B ArN9jqp8OTQBNYP3bL+DZ0gZ0HRqFdWsz8WKiKvLeYhMTCsJzxJLPkcvRNHReX+gGjo3 hqmMYCnEXSb2ox+Em5+/2FTUhreEazkYuKcFfIYwhG8Hr+dcGJXNyNGvuDcUaMdEFLCE 103CFA6KSeT8PSKd4vnD4QPgX7bIB1VrTNtRpa5QzprMFW2Xn4O+bUhy0WB4k14WAbtK MruDv4/N6Z92vStCX+5Pv6I0Lda3cdah7+8UzucbykM/7SlZ7vRvqcinIkqVo0sR4tzh qI9w== X-Gm-Message-State: AIVw112H/q5QgzD5loZbm+YdLha3m3oNRjXqEpL/j7/Fx+XB6yz02IQi O28mJER+muyif4cB X-Received: by 10.200.13.4 with SMTP id q4mr989625qti.221.1499641488192; Sun, 09 Jul 2017 16:04:48 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 9 Jul 2017 20:04:37 -0300 Message-Id: <1499641477-25001-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.31]); Sun, 09 Jul 2017 23:04:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 09 Jul 2017 23:04:49 +0000 (UTC) for IP:'209.85.216.194' DOMAIN:'mail-qt0-f194.google.com' HELO:'mail-qt0-f194.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.194 mail-qt0-f194.google.com 209.85.216.194 mail-qt0-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 09 Jul 2017 23:05:32 +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