From 987942a206ef0f2342bf81d5de6432c6af42b7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Tue, 21 Nov 2023 09:56:26 +0100 Subject: New upstream version 4.17 --- src/tc-string.c | 88 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 31 deletions(-) (limited to 'src/tc-string.c') diff --git a/src/tc-string.c b/src/tc-string.c index 9bf668b..1c7ed09 100644 --- a/src/tc-string.c +++ b/src/tc-string.c @@ -21,14 +21,14 @@ #include #include "internal.h" -static void t_mc(void) +static int t_mc(void) { hxmc_t *s, *old_s; s = HXmc_meminit(NULL, 4096); printf("%" HX_SIZET_FMT "u\n", HXmc_length(s)); if (HXmc_length(s) != 0) - abort(); + return EXIT_FAILURE; old_s = s; HXmc_trunc(&s, 8192); if (old_s != s) @@ -37,6 +37,7 @@ static void t_mc(void) HXmc_setlen(&s, 16384); printf("Length is now %" HX_SIZET_FMT "u\n", HXmc_length(s)); HXmc_free(s); + return EXIT_SUCCESS; } static void t_path(void) @@ -60,13 +61,12 @@ static void t_path(void) } } -static void t_strcpy(void) +static int t_strcpy(void) { hxmc_t *vp = NULL; HXmc_strcpy(&vp, NULL); - if (vp != NULL) - abort(); + return vp == nullptr ? EXIT_SUCCESS : EXIT_FAILURE; } static void t_strdup(void) @@ -291,7 +291,7 @@ static void t_strlcpy2(void) assert(a[0] == 49 && a[0] == a[1] && a[1] == a[2]); } -static void t_units(void) +static int t_units(void) { static const struct { unsigned long long num; @@ -320,18 +320,19 @@ static void t_units(void) printf("\t%llu -> %s\n", vt[i].num, buf); if (strcmp(buf, vt[i].exp_1024) != 0) { printf("\texpected %s\n", vt[i].exp_1024); - abort(); + return EXIT_FAILURE; } HX_unit_size(buf, ARRAY_SIZE(buf), vt[i].num, 1000, 9120); printf("\t%llu -> %s\n", vt[i].num, buf); if (strcmp(buf, vt[i].exp_1000) != 0) { printf("\texpected %s\n", vt[i].exp_1000); - abort(); + return EXIT_FAILURE; } } + return EXIT_SUCCESS; } -static void t_units_cu(void) +static int t_units_cu(void) { static const struct { unsigned long long num; @@ -360,18 +361,19 @@ static void t_units_cu(void) printf("\t%llu -> %s\n", vt[i].num, buf); if (strcmp(buf, vt[i].exp_1024) != 0) { printf("\texpected %s\n", vt[i].exp_1024); - abort(); + return EXIT_FAILURE; } HX_unit_size_cu(buf, ARRAY_SIZE(buf), vt[i].num, 1000); printf("\t%llu -> %s\n", vt[i].num, buf); if (strcmp(buf, vt[i].exp_1000) != 0) { printf("\texpected %s\n", vt[i].exp_1000); - abort(); + return EXIT_FAILURE; } } + return EXIT_SUCCESS; } -static void t_units_strto(void) +static int t_units_strto(void) { static const struct { const char input[24]; @@ -416,8 +418,9 @@ static void t_units_strto(void) unsigned long long q = HX_strtoull_unit(vt[i].input, &end, vt[i].exponent); printf("%s -> %llu __ %s\n", vt[i].input, q, end); if (q != vt[i].expect_out || strcmp(end, vt[i].expect_rem) != 0) - printf("BUG\n"); + return EXIT_FAILURE; } + return EXIT_SUCCESS; } static void t_time_units(void) @@ -454,25 +457,30 @@ static void t_time_units(void) static void t_time_strto(void) { + #define NS_PER_S 1000000000ULL static const struct { const char *input; - unsigned long long expect_out; - const char expect_rem[4]; + unsigned long long expect_s, expect_ns; + const char expect_rem[8]; } vt[] = { - {"1y1month1week1d1h1min1s ", 31557600+2629800+86400*8+3600+60+1, ""}, - {" -1d", 0, "-1d"}, - {"1 -", 1, "-"}, - {"1s", 1, ""}, - {"1min", 60, ""}, - {"0", 0, ""}, + {"29µs", 0, 29000, ""}, + {"1y", 31557600, NS_PER_S * 31557600, ""}, + {"1y1month1week1d1h1min1s ", 31557600+2629800+86400*8+3600+60+1, NS_PER_S * (31557600+2629800+86400*8+3600+60+1), ""}, + {" -1d", 0, 0, "-1d"}, + {"1 -", 1, NS_PER_S, "-"}, + {"12.5 hours .5 hours 240 minutes 25200 seconds", 86400, NS_PER_S * 86400, ""}, + {"1s", 1, NS_PER_S, ""}, + {"1min", 60, 60 * NS_PER_S, ""}, + {"0", 0, 0, ""}, }; char *end; printf("===== t_time_strto\n"); for (size_t i = 0; i < ARRAY_SIZE(vt); ++i) { unsigned long long q = HX_strtoull_sec(vt[i].input, &end); - printf("\"%s\" => %llus + \"%s\"\n", vt[i].input, q, end); - if (q != vt[i].expect_out) - printf("\tBUG: expected %llus\n", vt[i].expect_out); + unsigned long long qn = HX_strtoull_nsec(vt[i].input, &end); + printf("\"%s\" => %llus [%lluns] + \"%s\"\n", vt[i].input, q, qn, end); + if (q != vt[i].expect_s || qn != vt[i].expect_ns) + printf("\tBUG: expected %llus [%lluns]\n", vt[i].expect_s, vt[i].expect_ns); if (strcmp(end, vt[i].expect_rem) != 0) printf("\tBUG: expected remainder \"%s\"\n", vt[i].expect_rem); } @@ -507,14 +515,14 @@ static int t_strmid(void) #undef T } -int main(int argc, const char **argv) +static int runner(int argc, const char **argv) { hxmc_t *tx = NULL; const char *file = (argc >= 2) ? argv[1] : "tx-string.cpp"; FILE *fp; if (HX_init() <= 0) - abort(); + return EXIT_FAILURE; int ret = t_strmid(); if (ret != EXIT_SUCCESS) return EXIT_FAILURE; @@ -528,9 +536,13 @@ int main(int argc, const char **argv) fclose(fp); } - t_mc(); + ret = t_mc(); + if (ret != EXIT_SUCCESS) + return EXIT_FAILURE; t_path(); - t_strcpy(); + ret = t_strcpy(); + if (ret != EXIT_SUCCESS) + return EXIT_FAILURE; t_strncat(); t_strnlen(); t_strdup(); @@ -538,9 +550,15 @@ int main(int argc, const char **argv) t_strtrim(); t_split(); t_split2(); - t_units(); - t_units_cu(); - t_units_strto(); + ret = t_units(); + if (ret != EXIT_SUCCESS) + return EXIT_FAILURE; + ret = t_units_cu(); + if (ret != EXIT_SUCCESS) + return EXIT_FAILURE; + ret = t_units_strto(); + if (ret != EXIT_SUCCESS) + return EXIT_FAILURE; t_time_units(); t_time_strto(); t_strlcpy(); @@ -549,3 +567,11 @@ int main(int argc, const char **argv) HX_exit(); return EXIT_SUCCESS; } + +int main(int argc, const char **argv) +{ + int ret = runner(argc, argv); + if (ret != EXIT_FAILURE) + fprintf(stderr, "FAILED\n"); + return ret; +} -- cgit v1.2.3