[Git][NTPsec/ntpsec][master] Remove atolfp() and tests for atolfp() since it only exists in test code

Matt Selsky (@selsky) gitlab at mg.gitlab.com
Sat Apr 22 03:06:48 UTC 2023



Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
59b571a6 by Matt Selsky at 2023-04-20T21:23:21-04:00
Remove atolfp() and tests for atolfp() since it only exists in test code

This was the only functionality in tests/libntp/strtolfp.c

- - - - -


4 changed files:

- libntp/dolfptoa.c
- tests/common/tests_main.c
- − tests/libntp/strtolfp.c
- tests/wscript


Changes:

=====================================
libntp/dolfptoa.c
=====================================
@@ -2,9 +2,8 @@
  * dolfptoa - do the grunge work of converting an l_fp number to decimal
  *
  * Warning: this conversion is lossy in the low-order bits of the fractional
- * part.  It's good enough for statistics and logging, but do not expect
- * it to round-trip through atolfp(). 1444359386.1798776096, for example, may
- * dump as ...095 or ...097.
+ * part.  It's good enough for statistics and logging. 1444359386.1798776096,
+ * for example, may dump as ...095 or ...097.
  */
 #include "config.h"
 #include <stdio.h>


=====================================
tests/common/tests_main.c
=====================================
@@ -55,7 +55,6 @@ static void RunAllTests(void)
 	RUN_TEST_GROUP(refidsmear);
 	RUN_TEST_GROUP(socktoa);
 	RUN_TEST_GROUP(statestr);
-	RUN_TEST_GROUP(strtolfp);
 	RUN_TEST_GROUP(timespecops);
 	RUN_TEST_GROUP(vi64ops);
 	RUN_TEST_GROUP(ymd2yd);


=====================================
tests/libntp/strtolfp.c deleted
=====================================
@@ -1,226 +0,0 @@
-#include "config.h"
-#include "ntp_stdlib.h"
-#include "ntp_fp.h"
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include "ntp_assert.h"
-
-#include "unity.h"
-#include "unity_fixture.h"
-
-static	bool	atolfp		(const char *, l_fp *);
-
-/*
- * atolfp - convert an ascii string to an l_fp number
- */
-/*
- * Powers of 10
- */
-static unsigned long ten_to_the_n[10] = {
-	0,
-	10,
-	100,
-	1000,
-	10000,
-	100000,
-	1000000,
-	10000000,
-	100000000,
-	1000000000,
-};
-
-
-static bool
-atolfp(
-	const char *str,
-	l_fp *lfp
-	)
-{
-	const char *cp;
-	unsigned long dec_i;
-	unsigned long dec_f;
-	char *ind;
-	int ndec;
-	bool isneg;
-	static const char *digits = "0123456789";
-
-	REQUIRE(str != NULL);
-
-	isneg = false;
-	dec_i = dec_f = 0;
-	ndec = 0;
-	cp = str;
-
-	/*
-	 * We understand numbers of the form:
-	 *
-	 * [spaces][-|+][digits][.][digits][spaces|\n|\0]
-	 */
-	while (isspace((unsigned char)*cp)) {
-	    cp++;
-	}
-
-	if (*cp == '-') {
-		cp++;
-		isneg = true;
-	}
-
-	if (*cp == '+') {
-	    cp++;
-	}
-
-	if (*cp != '.' && !isdigit((unsigned char)*cp))
-	    return false;
-
-	while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) {
-		dec_i = (dec_i << 3) + (dec_i << 1);	/* multiply by 10 */
-		dec_i += (unsigned long)(ind - digits);
-		cp++;
-	}
-
-	if (*cp != '\0' && !isspace((unsigned char)*cp)) {
-		if (*cp++ != '.')
-		    return false;
-
-		while (ndec < 9 && *cp != '\0'
-		       && (ind = strchr(digits, *cp)) != NULL) {
-			ndec++;
-			dec_f = (dec_f << 3) + (dec_f << 1);	/* *10 */
-			dec_f += (unsigned long)(ind - digits);
-			cp++;
-		}
-
-		while (isdigit((unsigned char)*cp)) {
-		    cp++;
-		}
-
-		if (*cp != '\0' && !isspace((unsigned char)*cp))
-		    return false;
-	}
-
-	if (ndec > 0) {
-		unsigned long tmp;
-		unsigned long bit;
-		unsigned long ten_fact;
-
-		ten_fact = ten_to_the_n[ndec];
-
-		tmp = 0;
-		bit = 0x80000000;
-		while (bit != 0) {
-			dec_f <<= 1;
-			if (dec_f >= ten_fact) {
-				tmp |= bit;
-				dec_f -= ten_fact;
-			}
-			bit >>= 1;
-		}
-		if ((dec_f << 1) > ten_fact) {
-		    tmp++;
-		}
-		dec_f = tmp;
-	}
-
-	if (isneg)
-	{
-		(dec_f) = ~(dec_f) + 1U;
-		(dec_i) = ~(dec_i) + ((dec_f) == 0);
-	}
-
-	*lfp = lfpinit_u(dec_i, dec_f);
-	return true;
-}
-
-TEST_GROUP(strtolfp);
-
-TEST_SETUP(strtolfp) {}
-
-TEST_TEAR_DOWN(strtolfp) {}
-
-#include "lfptest.h"
-
-/* This class tests atolfp */
-
-TEST(strtolfp, PositiveInteger) {
-	const char *str = "500";
-
-	l_fp expected = lfpinit(500, 0);
-	l_fp actual;
-
-	TEST_ASSERT_TRUE(atolfp(str, &actual));
-
-	TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
-}
-
-TEST(strtolfp, NegativeInteger) {
-	const char *str = "-300";
-
-	l_fp expected = lfpinit(-300, 0);
-	l_fp actual;
-
-	TEST_ASSERT_TRUE(atolfp(str, &actual));
-
-	TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
-}
-
-TEST(strtolfp, PositiveFraction) {
-	const char *str = "+500.5";
-
-	l_fp expected = lfpinit(500, HALF);
-	l_fp actual;
-
-	TEST_ASSERT_TRUE(atolfp(str, &actual));
-
-	TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
-}
-
-TEST(strtolfp, NegativeFraction) {
-	const char *str = "-300.75";
-
-	l_fp expected = lfpinit(-301, QUARTER);
-	l_fp actual;
-
-	TEST_ASSERT_TRUE(atolfp(str, &actual));
-
-	TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
-}
-
-TEST(strtolfp, PositiveMsFraction) {
-	const char *str = "300.00025";
-
-	l_fp expected = lfpinit(300, QUARTER_PROMILLE_APPRX);
-	l_fp actual;
-
-	TEST_ASSERT_TRUE(atolfp(str, &actual));
-
-	TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
-}
-
-TEST(strtolfp, NegativeMsFraction) {
-	const char *str = "-199.99975";
-
-	l_fp expected = lfpinit(-200, QUARTER_PROMILLE_APPRX);
-	l_fp actual;
-
-	TEST_ASSERT_TRUE(atolfp(str, &actual));
-
-	TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
-}
-
-TEST(strtolfp, InvalidChars) {
-	const char *str = "500.4a2";
-	l_fp actual;
-
-	TEST_ASSERT_FALSE(atolfp(str, &actual));
-}
-
-TEST_GROUP_RUNNER(strtolfp) {
-	RUN_TEST_CASE(strtolfp, PositiveInteger);
-	RUN_TEST_CASE(strtolfp, NegativeInteger);
-	RUN_TEST_CASE(strtolfp, PositiveFraction);
-	RUN_TEST_CASE(strtolfp, NegativeFraction);
-	RUN_TEST_CASE(strtolfp, PositiveMsFraction);
-	RUN_TEST_CASE(strtolfp, NegativeMsFraction);
-	RUN_TEST_CASE(strtolfp, InvalidChars);
-}


=====================================
tests/wscript
=====================================
@@ -49,7 +49,6 @@ def build(ctx):
         "libntp/refidsmear.c",
         "libntp/socktoa.c",
         "libntp/statestr.c",
-        "libntp/strtolfp.c",
         "libntp/timespecops.c",
         "libntp/vi64ops.c",
         "libntp/ymd2yd.c"



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/59b571a630e5f537ab427b4a67ded01ad822ae4f

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/59b571a630e5f537ab427b4a67ded01ad822ae4f
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20230422/c2c0bcdd/attachment-0001.htm>


More information about the vc mailing list