From nobody Mon Apr 29 04:24:48 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.zoho.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 1498349772214875.566655110032; Sat, 24 Jun 2017 17:16:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C10CB4E33D; Sun, 25 Jun 2017 00:16:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5890C7010A; Sun, 25 Jun 2017 00:16:09 +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 28074184383F; Sun, 25 Jun 2017 00:16:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5P0G7UQ021612 for ; Sat, 24 Jun 2017 20:16:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A3A16A47F; Sun, 25 Jun 2017 00:16:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 124B4692B6 for ; Sun, 25 Jun 2017 00:16:05 +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 39DEE80462 for ; Sun, 25 Jun 2017 00:16:04 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id c20so10220294qte.0 for ; Sat, 24 Jun 2017 17:16:04 -0700 (PDT) Received: from localhost.localdomain ([187.107.181.9]) by smtp.googlemail.com with ESMTPSA id b13sm5343463qta.25.2017.06.24.17.16.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 24 Jun 2017 17:16:02 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C10CB4E33D Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx09.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 C10CB4E33D Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mN5R6KJE" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 39DEE80462 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 39DEE80462 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=8aIqB1cY02gtz/hyAgzBv/94fMOdNYkX4QLh5W+zh5A=; b=mN5R6KJEV3nJE2YTmz7iGFyMwjJFvkmVG/DWb/x+HWtZF2WUKSuOALsISoI3UzPc2t l/u5lSyVw/Lar0j1ppOmi+dMpKVtQifWHTj1w2gskJN5ympk9g7hZXdAYc/g1yP/RkzR Db9x5KK19CA+tyBfq2SYDuly+UYHrNL6TwysXXQVYh9a2iumYm2paFlLkC/pcXRZ4Qpi qhWlTzadDraqlTVaJCGIZckrGyI1xUtKgMhkqtfA6a63hilZskcS/1TBL53Khsom1TDK BGSpOlJSQTrCi3oJuZW3JGCYb8GLJvwbhZVlB8wrPDt8LBiWs0q+ENzALTNHQJUFF4DV fcEg== 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=8aIqB1cY02gtz/hyAgzBv/94fMOdNYkX4QLh5W+zh5A=; b=jQaogk7bCze3rWUVLbtVhXQrH842AUlkLCBQ3uiNm4OEyiqjt4mxPCCyBZFcg3RenA /DcBCGHdJOnEKmlYivlqcM1dnAgVVAVdz1VExdhjrxWQcwNzH5Evct8sK8eWe93Z55lX IvQMsUQq8oZ5T8zAgiea1jK6s1zX1/A8zC7j+v2u21O2lOvxRZuGtNTJv+KNjfET68Oh QTJczte8MlJ+jXWb7he/5h0GyoRcephZ2eDxO+v35sXt90uM1TzAd+02SdTAPCZaHZ55 rUx8skBBXznwltXshY31mD75viizbRZUGHkA9PlNP3kM9PJHNzNDutQwGQdsxgKrPKXQ AfSw== X-Gm-Message-State: AKS2vOxZAIFerQ/eUAv6E8PLP/M2LDugqQlpZBdYyRis7I6eC3hOAkwm JUtcSI7eNxtE1hfs X-Received: by 10.237.35.216 with SMTP id k24mr16644856qtc.125.1498349763218; Sat, 24 Jun 2017 17:16:03 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sat, 24 Jun 2017 21:15:52 -0300 Message-Id: <1498349752-32619-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.28]); Sun, 25 Jun 2017 00:16:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sun, 25 Jun 2017 00:16:04 +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.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 25 Jun 2017 00:16:10 +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=20 inside virstringtest.c. This commit introduces some tests to validate the=20 conversion. The test does not include locale changes yet. Signed-off-by: Julio Faracco --- tests/virstringtest.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 84 insertions(+) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 97c6e76..32ce79c 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -652,6 +652,52 @@ 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; + + if (data->end_ptr) { + ret =3D virStrToDouble(data->str, &end_ptr, &res); + } else { + /* end_ptr returns or a substring or an empty string. + * It never returns a NULL pointer. */ + ret =3D virStrToDouble(data->str, NULL, &res); + } + + if (ret < 0) { + fprintf(stderr, "Convert error of '%s', expected '%f'\n", + data->str, data->res); + return ret; + } + + if (res !=3D data->res) { + fprintf(stderr, "Returned '%f', expected '%f'\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 +1011,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