[Git][NTPsec/ntpsec][master] Remove mstolfp() and tests for mstolfp() since it only exists in test code
Gary E. Miller (@garyedmundsmiller)
gitlab at mg.gitlab.com
Thu Apr 20 18:58:35 UTC 2023
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
86bc7f98 by Matt Selsky at 2023-04-20T18:42:56+00:00
Remove mstolfp() and tests for mstolfp() since it only exists in test code
- - - - -
1 changed file:
- tests/libntp/strtolfp.c
Changes:
=====================================
tests/libntp/strtolfp.c
=====================================
@@ -9,7 +9,6 @@
#include "unity.h"
#include "unity_fixture.h"
-static bool mstolfp (const char *, l_fp *);
static bool atolfp (const char *, l_fp *);
/*
@@ -133,105 +132,6 @@ atolfp(
return true;
}
-/*
- * mstolfp - convert an ascii string in milliseconds to an l_fp number
- */
-static bool
-mstolfp(
- const char *str,
- l_fp *lfp
- )
-{
- const char *cp;
- char *bp;
- const char *cpdec;
- char buf[100];
-
- /*
- * We understand numbers of the form:
- *
- * [spaces][-][digits][.][digits][spaces|\n|\0]
- *
- * This is one enormous hack. Since I didn't feel like
- * rewriting the decoding routine for milliseconds, what
- * is essentially done here is to make a copy of the string
- * with the decimal moved over three places so the seconds
- * decoding routine can be used.
- */
- bp = buf;
- cp = str;
- while (isspace((unsigned char)*cp)) {
- cp++;
- }
-
- if (*cp == '-') {
- *bp++ = '-';
- cp++;
- }
-
- if (*cp != '.' && !isdigit((unsigned char)*cp))
- return false;
-
-
- /*
- * Search forward for the decimal point or the end of the string.
- */
- cpdec = cp;
- while (isdigit((unsigned char)*cpdec)) {
- cpdec++;
- }
-
- /*
- * Found something. If we have more than three digits copy the
- * excess over, else insert a leading 0.
- */
- if ((cpdec - cp) > 3) {
- do {
- *bp++ = (char)*cp++;
- } while ((cpdec - cp) > 3);
- } else {
- *bp++ = '0';
- }
-
- /*
- * Stick the decimal in. If we've got less than three digits in
- * front of the millisecond decimal we insert the appropriate number
- * of zeros.
- */
- *bp++ = '.';
- if ((cpdec - cp) < 3) {
- int i = 3 - (cpdec - cp);
-
- do {
- *bp++ = '0';
- } while (--i > 0);
- }
-
- /*
- * Copy the remainder up to the millisecond decimal. If cpdec
- * is pointing at a decimal point, copy in the trailing number too.
- */
- while (cp < cpdec) {
- *bp++ = (char)*cp++;
- }
-
- if (*cp == '.') {
- cp++;
- while (isdigit((unsigned char)*cp)) {
- *bp++ = (char)*cp++;
- }
- }
- *bp = '\0';
-
- /*
- * Check to make sure the string is properly terminated. If
- * so, give the buffer to the decoding routine.
- */
- if (*cp != '\0' && !isspace((unsigned char)*cp))
- return false;
- return atolfp(buf, lfp);
-}
-
TEST_GROUP(strtolfp);
TEST_SETUP(strtolfp) {}
@@ -240,98 +140,79 @@ TEST_TEAR_DOWN(strtolfp) {}
#include "lfptest.h"
-/* This class tests both atolfp and mstolfp */
+/* This class tests atolfp */
TEST(strtolfp, PositiveInteger) {
const char *str = "500";
- const char *str_ms = "500000";
l_fp expected = lfpinit(500, 0);
- l_fp actual, actual_ms;
+ l_fp actual;
TEST_ASSERT_TRUE(atolfp(str, &actual));
- TEST_ASSERT_TRUE(mstolfp(str_ms, &actual_ms));
TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
- TEST_ASSERT_TRUE(IsEqual(&expected, &actual_ms));
}
TEST(strtolfp, NegativeInteger) {
const char *str = "-300";
- const char *str_ms = "-300000";
l_fp expected = lfpinit(-300, 0);
- l_fp actual, actual_ms;
+ l_fp actual;
TEST_ASSERT_TRUE(atolfp(str, &actual));
- TEST_ASSERT_TRUE(mstolfp(str_ms, &actual_ms));
TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
- TEST_ASSERT_TRUE(IsEqual(&expected, &actual_ms));
}
TEST(strtolfp, PositiveFraction) {
const char *str = "+500.5";
- const char *str_ms = "500500.0";
l_fp expected = lfpinit(500, HALF);
- l_fp actual, actual_ms;
+ l_fp actual;
TEST_ASSERT_TRUE(atolfp(str, &actual));
- TEST_ASSERT_TRUE(mstolfp(str_ms, &actual_ms));
TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
- TEST_ASSERT_TRUE(IsEqual(&expected, &actual_ms));
}
TEST(strtolfp, NegativeFraction) {
const char *str = "-300.75";
- const char *str_ms = "-300750";
l_fp expected = lfpinit(-301, QUARTER);
- l_fp actual, actual_ms;
+ l_fp actual;
TEST_ASSERT_TRUE(atolfp(str, &actual));
- TEST_ASSERT_TRUE(mstolfp(str_ms, &actual_ms));
TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
- TEST_ASSERT_TRUE(IsEqual(&expected, &actual_ms));
}
TEST(strtolfp, PositiveMsFraction) {
const char *str = "300.00025";
- const char *str_ms = "300000.25";
l_fp expected = lfpinit(300, QUARTER_PROMILLE_APPRX);
- l_fp actual, actual_ms;
+ l_fp actual;
TEST_ASSERT_TRUE(atolfp(str, &actual));
- TEST_ASSERT_TRUE(mstolfp(str_ms, &actual_ms));
TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
- TEST_ASSERT_TRUE(IsEqual(&expected, &actual_ms));
}
TEST(strtolfp, NegativeMsFraction) {
const char *str = "-199.99975";
- const char *str_ms = "-199999.75";
l_fp expected = lfpinit(-200, QUARTER_PROMILLE_APPRX);
- l_fp actual, actual_ms;
+ l_fp actual;
TEST_ASSERT_TRUE(atolfp(str, &actual));
- TEST_ASSERT_TRUE(mstolfp(str_ms, &actual_ms));
TEST_ASSERT_TRUE(IsEqual(&expected, &actual));
- TEST_ASSERT_TRUE(IsEqual(&expected, &actual_ms));
}
TEST(strtolfp, InvalidChars) {
const char *str = "500.4a2";
- l_fp actual, actual_ms;
+ l_fp actual;
TEST_ASSERT_FALSE(atolfp(str, &actual));
- TEST_ASSERT_FALSE(mstolfp(str, &actual_ms));
}
TEST_GROUP_RUNNER(strtolfp) {
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/86bc7f9837134185d7a715dfc0fd8532804a9e1f
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/86bc7f9837134185d7a715dfc0fd8532804a9e1f
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/20230420/86e31f64/attachment-0001.htm>
More information about the vc
mailing list