diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-04 15:11:53 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-04 15:13:55 -0400 |
| commit | 5e2783b6a8a65aba17789aa388c320bb85804d45 (patch) | |
| tree | 13d5ba5802f8fe04ea872da7cbb0a03b7c81ea93 | |
| parent | 5715acd12cae75cc5fdf395567cb5603fd906a71 (diff) | |
pkstn: INCONVERTIBLE overhaul
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | pkstn.h | 117 | ||||
| -rw-r--r-- | pkuuid.h | 2 | ||||
| -rw-r--r-- | test/pkstn.c | 21 | ||||
| -rw-r--r-- | test/pkstn.cpp | 166 |
5 files changed, 192 insertions, 116 deletions
@@ -1,5 +1,5 @@ # pk.h version -VERSION = 0.4.5 +VERSION = 0.4.6 # paths PREFIX = /usr/local @@ -14,53 +14,56 @@ enum PK_STN_RES { PK_STN_RES_INCONVERTIBLE }; -enum PK_STN_RES pk_stn_int64_t(int64_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_uint64_t(uint64_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_int32_t(int32_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_uint32_t(uint32_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_int16_t(int16_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_uint16_t(uint16_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_int8_t(int8_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_uint8_t(uint8_t *i, char const *s, int base); -enum PK_STN_RES pk_stn_float(float *f, char const *s); -enum PK_STN_RES pk_stn_double(double *d, char const *s); -enum PK_STN_RES pk_stn_float_e(float *f, char const *s, char **pEnd); -enum PK_STN_RES pk_stn_double_e(double *d, char const *s, char **pEnd); +enum PK_STN_RES pk_stn_int64_t(int64_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_uint64_t(uint64_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_int32_t(int32_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_uint32_t(uint32_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_int16_t(int16_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_uint16_t(uint16_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_int8_t(int8_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_uint8_t(uint8_t *i, char const *s, char **pEnd, int base); +enum PK_STN_RES pk_stn_float(float *f, char const *s, char **pEnd); +enum PK_STN_RES pk_stn_double(double *d, char const *s, char **pEnd); #if defined(__cplusplus) template <typename T> -enum PK_STN_RES pk_stn(T *n, char const *s, int base = 0) +enum PK_STN_RES pk_stn(T *n, char const *s, char **pEnd, int base = 0) { if constexpr(std::is_same<T, int64_t>::value) { - return pk_stn_int64_t(n, s, base); + return pk_stn_int64_t(n, s, pEnd, base); } if constexpr(std::is_same<T, uint64_t>::value) { - return pk_stn_uint64_t(n, s, base); + return pk_stn_uint64_t(n, s, pEnd, base); } if constexpr(std::is_same<T, int32_t>::value) { - return pk_stn_int32_t(n, s, base); + return pk_stn_int32_t(n, s, pEnd, base); } if constexpr(std::is_same<T, uint32_t>::value) { - return pk_stn_uint32_t(n, s, base); + return pk_stn_uint32_t(n, s, pEnd, base); } if constexpr(std::is_same<T, int16_t>::value) { - return pk_stn_int16_t(n, s, base); + return pk_stn_int16_t(n, s, pEnd, base); } if constexpr(std::is_same<T, uint16_t>::value) { - return pk_stn_uint16_t(n, s, base); + return pk_stn_uint16_t(n, s, pEnd, base); } if constexpr(std::is_same<T, int8_t>::value) { - return pk_stn_int8_t(n, s, base); + return pk_stn_int8_t(n, s, pEnd, base); } if constexpr(std::is_same<T, uint8_t>::value) { - return pk_stn_uint8_t(n, s, base); + return pk_stn_uint8_t(n, s, pEnd, base); + } + if constexpr(std::is_same<T, bool>::value) { + static_assert(sizeof(bool) == sizeof(uint8_t)); + static_assert(alignof(bool) == alignof(uint8_t)); + return pk_stn_uint8_t((uint8_t*)n, s, pEnd, base); } if constexpr(std::is_same<T, float>::value) { - return pk_stn_float(n, s); + return pk_stn_float(n, s, pEnd); } if constexpr(std::is_same<T, double>::value) { - return pk_stn_double(n, s); + return pk_stn_double(n, s, pEnd); } return (PK_STN_RES)-1; } @@ -72,17 +75,18 @@ enum PK_STN_RES pk_stn(T *n, char const *s, int base = 0) #ifdef PK_IMPL_STN enum PK_STN_RES -pk_stn_int64_t(int64_t *i, char const *s, int base) +pk_stn_int64_t(int64_t *i, char const *s, char **pEnd, int base) { char *end; long long l; errno = 0; l = strtoll(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == LLONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -90,17 +94,18 @@ pk_stn_int64_t(int64_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_uint64_t(uint64_t *i, char const *s, int base) +pk_stn_uint64_t(uint64_t *i, char const *s, char **pEnd, int base) { char *end; unsigned long long l; errno = 0; l = strtoull(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == ULLONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -108,17 +113,18 @@ pk_stn_uint64_t(uint64_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_int32_t(int32_t *i, char const *s, int base) +pk_stn_int32_t(int32_t *i, char const *s, char **pEnd, int base) { char *end; long l; errno = 0; l = strtol(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == LONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -126,17 +132,18 @@ pk_stn_int32_t(int32_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_uint32_t(uint32_t *i, char const *s, int base) +pk_stn_uint32_t(uint32_t *i, char const *s, char **pEnd, int base) { char *end; unsigned long l; errno = 0; l = strtoul(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == ULONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -144,17 +151,18 @@ pk_stn_uint32_t(uint32_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_int16_t(int16_t *i, char const *s, int base) +pk_stn_int16_t(int16_t *i, char const *s, char **pEnd, int base) { char *end; long l; errno = 0; l = strtol(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == LONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -162,17 +170,18 @@ pk_stn_int16_t(int16_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_uint16_t(uint16_t *i, char const *s, int base) +pk_stn_uint16_t(uint16_t *i, char const *s, char **pEnd, int base) { char *end; unsigned long l; errno = 0; l = strtoul(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == ULONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -180,17 +189,18 @@ pk_stn_uint16_t(uint16_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_int8_t(int8_t *i, char const *s, int base) +pk_stn_int8_t(int8_t *i, char const *s, char **pEnd, int base) { char *end; long l; errno = 0; l = strtol(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == LONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -198,17 +208,18 @@ pk_stn_int8_t(int8_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_uint8_t(uint8_t *i, char const *s, int base) +pk_stn_uint8_t(uint8_t *i, char const *s, char **pEnd, int base) { char *end; unsigned long l; errno = 0; l = strtoul(s, &end, base); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE) { if (l == ULONG_MAX) return PK_STN_RES_OVERFLOW; return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *i = l; @@ -216,32 +227,20 @@ pk_stn_uint8_t(uint8_t *i, char const *s, int base) } enum PK_STN_RES -pk_stn_float(float *f, char const *s) -{ - char *end; - return pk_stn_float_e(f, s, &end); -} - -enum PK_STN_RES -pk_stn_double(double *d, char const *s) +pk_stn_float(float *f, char const *s, char **pEnd) { char *end; - return pk_stn_double_e(d, s, &end); -} - -enum PK_STN_RES -pk_stn_float_e(float *f, char const *s, char **pEnd) -{ float l; errno = 0; - l = strtof(s, pEnd); + l = strtof(s, &end); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE && l == HUGE_VALF) { return PK_STN_RES_OVERFLOW; } if (errno == ERANGE && l == -HUGE_VALF) { return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || &s == (const char **)pEnd) { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *f = l; @@ -249,18 +248,20 @@ pk_stn_float_e(float *f, char const *s, char **pEnd) } enum PK_STN_RES -pk_stn_double_e(double *d, char const *s, char **pEnd) +pk_stn_double(double *d, char const *s, char **pEnd) { + char *end; double l; errno = 0; - l = strtod(s, pEnd); + l = strtod(s, &end); + if (pEnd != nullptr) *pEnd = end; if (errno == ERANGE && l == HUGE_VAL) { return PK_STN_RES_OVERFLOW; } if (errno == ERANGE && l == -HUGE_VAL) { return PK_STN_RES_UNDERFLOW; } - if (*s == '\0' || &s == (const char **)pEnd) { + if (s == end) { return PK_STN_RES_INCONVERTIBLE; } *d = l; @@ -168,7 +168,7 @@ bool pk_uuid_parse(const char *s, struct pk_uuid *uuid) } c[0] = s[k]; c[1] = s[k+1]; - if (pk_stn_uint8_t(&uuid->uuid[kk], c, 16) != PK_STN_RES_SUCCESS) { + if (pk_stn_uint8_t(&uuid->uuid[kk], c, nullptr, 16) != PK_STN_RES_SUCCESS) { goto err_out; } } diff --git a/test/pkstn.c b/test/pkstn.c index 8884804..032d7e2 100644 --- a/test/pkstn.c +++ b/test/pkstn.c @@ -8,12 +8,13 @@ int main(int argc, char *argv[]) { (void)argc; (void)argv; + char *s; enum PK_STN_RES res = {0}; // stn_int64_t { int64_t i = {0}; - res = pk_stn_int64_t(&i, "-1", 0); + res = pk_stn_int64_t(&i, "-1", &s, 0); fprintf(stdout, "pkstn: stn_int64_t res: %ld\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (-1 != i) exit(1); @@ -22,7 +23,7 @@ int main(int argc, char *argv[]) // stn_uint64_t { uint64_t i = {0}; - res = pk_stn_uint64_t(&i, "1", 0); + res = pk_stn_uint64_t(&i, "1", &s, 0); fprintf(stdout, "pkstn: stn_uint64_t res: %lu\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (1 != i) exit(1); @@ -31,7 +32,7 @@ int main(int argc, char *argv[]) // stn_int32_t { int32_t i = {0}; - res = pk_stn_int32_t(&i, "-1", 0); + res = pk_stn_int32_t(&i, "-1", &s, 0); fprintf(stdout, "pkstn: stn_int32_t res: %d\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (-1 != i) exit(1); @@ -40,7 +41,7 @@ int main(int argc, char *argv[]) // stn_uint32_t { uint32_t i = {0}; - res = pk_stn_uint32_t(&i, "1", 0); + res = pk_stn_uint32_t(&i, "1", &s, 0); fprintf(stdout, "pkstn: stn_uint32_t res: %u\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (1 != i) exit(1); @@ -49,7 +50,7 @@ int main(int argc, char *argv[]) // stn_int16_t { int16_t i = {0}; - res = pk_stn_int16_t(&i, "-1", 0); + res = pk_stn_int16_t(&i, "-1", &s, 0); fprintf(stdout, "pkstn: stn_int16_t res: %d\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (-1 != i) exit(1); @@ -58,7 +59,7 @@ int main(int argc, char *argv[]) // stn_uint16_t { uint16_t i = {0}; - res = pk_stn_uint16_t(&i, "1", 0); + res = pk_stn_uint16_t(&i, "1", &s, 0); fprintf(stdout, "pkstn: stn_uint16_t res: %u\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (1 != i) exit(1); @@ -67,7 +68,7 @@ int main(int argc, char *argv[]) // stn_int8_t { int8_t i = {0}; - res = pk_stn_int8_t(&i, "-1", 0); + res = pk_stn_int8_t(&i, "-1", &s, 0); fprintf(stdout, "pkstn: stn_int8_t res: %d\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (-1 != i) exit(1); @@ -76,7 +77,7 @@ int main(int argc, char *argv[]) // stn_uint8_t { uint8_t i = {0}; - res = pk_stn_uint8_t(&i, "1", 0); + res = pk_stn_uint8_t(&i, "1", &s, 0); fprintf(stdout, "pkstn: stn_uint8_t res: %u\n", i); if (res != PK_STN_RES_SUCCESS) exit(1); if (1 != i) exit(1); @@ -85,7 +86,7 @@ int main(int argc, char *argv[]) // stn_float { float f = {0}; - res = pk_stn_float(&f, "-1"); + res = pk_stn_float(&f, "-1", &s); fprintf(stdout, "pkstn: stn_float res: %f\n", f); if (res != PK_STN_RES_SUCCESS) exit(1); if (-1 != f) exit(1); @@ -94,7 +95,7 @@ int main(int argc, char *argv[]) // stn_double { double f = {0}; - res = pk_stn_double(&f, "-1"); + res = pk_stn_double(&f, "-1", &s); fprintf(stdout, "pkstn: stn_double res: %f\n", f); if (res != PK_STN_RES_SUCCESS) exit(1); if (-1 != f) exit(1); diff --git a/test/pkstn.cpp b/test/pkstn.cpp index 8a4d901..b6c9329 100644 --- a/test/pkstn.cpp +++ b/test/pkstn.cpp @@ -1,75 +1,143 @@ #include "../pkstn.h" +#include <cstring> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <type_traits> +const char *STRNUM_NIL = ""; +const char *STRNUM_ZED = "0"; const char *STRNUM_ONE = "1"; const char *STRNUM_ONE_MINUS = "-1"; const char *STRNUM_UNDERFLOW = "-99999999999999999999999999999999"; const char *STRNUM_OVERFLOW = "99999999999999999999999999999999"; +const char *STRNUM_FLOAT_NIL = ""; +const char *STRNUM_FLOAT_ZED = "0.0"; +const char *STRNUM_FLOAT_ONE = "15.0"; +const char *STRNUM_FLOAT_ONE_MINUS = "-15.0"; const char *STRNUM_UNDERFLOW_FLOAT = "-1.0e9999"; const char *STRNUM_OVERFLOW_FLOAT = "1.0e9999"; const char *STRNUM_INCONVERTIBLE = "junk"; -enum STRNUM_TESTS : uint8_t { - TEST_ONE = 0x01, - TEST_ONE_MINUS = 0x02, - TEST_UNDERFLOW = 0x04, - TEST_OVERFLOW = 0x08, - TEST_INCONVERTIBLE = 0x10, - TEST_NO_NEG = TEST_ONE | TEST_OVERFLOW | TEST_INCONVERTIBLE, - TEST_FLOATS = TEST_ONE | TEST_ONE_MINUS | TEST_UNDERFLOW | TEST_OVERFLOW, - TEST_ALL = 0xFF, +#define VAL_SCALAR_ZED 0 +#define VAL_SCALAR_ONE 1 +#define VAL_SCALAR_ONE_MINUS -1 +#define VAL_FLOATING_ZED 0.0 +#define VAL_FLOATING_ONE 0x1.ep+3 +#define VAL_FLOATING_ONE_MINUS -0x1.ep+3 + +enum STRNUM_TESTS : uint32_t { + TEST_SCALAR_NIL = 0x00000001, + TEST_SCALAR_ZED = 0x00000002, + TEST_SCALAR_ONE = 0x00000004, + TEST_SCALAR_ONE_MINUS = 0x00000008, + TEST_SCALAR_UNDERFLOW = 0x00000010, + TEST_SCALAR_OVERFLOW = 0x00000020, + TEST_FLOATING_NIL = 0x00000100, + TEST_FLOATING_ZED = 0x00000200, + TEST_FLOATING_ONE = 0x00000400, + TEST_FLOATING_ONE_MINUS = 0x00000800, + TEST_FLOATING_UNDERFLOW = 0x00001000, + TEST_FLOATING_OVERFLOW = 0x00002000, + TEST_INCONVERTIBLE = 0x00010000, + TEST_SCALAR = 0x000100FF, + TEST_FLOATS = 0x0001FF00, + TEST_ALL = 0xFFFFFFFF, }; template <typename T, enum STRNUM_TESTS t> void test() { + char *s; enum PK_STN_RES res = {}; - T i = {0}; - if constexpr (t & TEST_ONE) { - res = pk_stn(&i, STRNUM_ONE); - std::cout << "pkstn: TEST_ONE res: " << i << "\n"; + T i = {1}; + if constexpr (t & TEST_SCALAR_NIL) { + res = pk_stn(&i, STRNUM_NIL, &s); + std::cout << "pkstn: TEST_SCALAR_NIL res: " << i << "\n"; + if (s != STRNUM_NIL) exit(1); + if (res != PK_STN_RES_INCONVERTIBLE) exit(1); + } + if constexpr (t & TEST_FLOATING_NIL) { + res = pk_stn(&i, STRNUM_FLOAT_NIL, &s); + std::cout << "pkstn: TEST_FLOATING_NIL res: " << i << "\n"; + if (s != STRNUM_FLOAT_NIL) exit(1); + if (res != PK_STN_RES_INCONVERTIBLE) exit(1); + } + if constexpr (t & TEST_SCALAR_ZED) { + res = pk_stn(&i, STRNUM_ZED, &s); + std::cout << "pkstn: TEST_SCALAR_ZED res: " << i << "\n"; + if (s != STRNUM_ZED + strlen(STRNUM_ZED)) exit(1); if (res != PK_STN_RES_SUCCESS) exit(1); - if (1 != i) exit(1); + if (T(VAL_SCALAR_ZED) != i) exit(1); } - if constexpr (t & TEST_ONE_MINUS) { - res = pk_stn(&i, STRNUM_ONE_MINUS); - std::cout << "pkstn: STRNUM_ONE_MINUS res: " << i << "\n"; + if constexpr (t & TEST_FLOATING_ZED) { + res = pk_stn(&i, STRNUM_FLOAT_ZED, &s); + std::cout << "pkstn: TEST_FLOATING_ZED res: " << i << "\n"; + if (s != STRNUM_FLOAT_ZED + strlen(STRNUM_FLOAT_ZED)) exit(1); if (res != PK_STN_RES_SUCCESS) exit(1); - if (T(-1) != i) exit(1); - } - if constexpr (t & TEST_UNDERFLOW) { - const char * str; - if constexpr(std::is_same<T, float>::value == true || std::is_same<T, double>::value == true) { - str = STRNUM_UNDERFLOW_FLOAT; - } else { - str = STRNUM_UNDERFLOW; - } - res = pk_stn(&i, str); - std::cout << "pkstn: TEST_UNDERFLOW res: " << i << "\n"; + if (T(VAL_FLOATING_ZED) != i) exit(1); + } + if constexpr (t & TEST_SCALAR_ONE) { + res = pk_stn(&i, STRNUM_ONE, &s); + std::cout << "pkstn: TEST_SCALAR_ONE res: " << i << "\n"; + if (s != STRNUM_ONE + strlen(STRNUM_ONE)) exit(1); + if (res != PK_STN_RES_SUCCESS) exit(1); + if (T(VAL_SCALAR_ONE) != i) exit(1); + } + if constexpr (t & TEST_FLOATING_ONE) { + res = pk_stn(&i, STRNUM_FLOAT_ONE, &s); + std::cout << "pkstn: TEST_FLOATING_ONE res: " << i << "\n"; + if (s != STRNUM_FLOAT_ONE + strlen(STRNUM_FLOAT_ONE)) exit(1); + if (res != PK_STN_RES_SUCCESS) exit(1); + if (T(VAL_FLOATING_ONE) != i) exit(1); + } + if constexpr (t & TEST_SCALAR_ONE_MINUS) { + res = pk_stn(&i, STRNUM_ONE_MINUS, &s); + std::cout << "pkstn: TEST_SCALAR_ONE_MINUS res: " << i << "\n"; + if (s != STRNUM_ONE_MINUS + strlen(STRNUM_ONE_MINUS)) exit(1); + if (res != PK_STN_RES_SUCCESS) exit(1); + if (T(VAL_SCALAR_ONE_MINUS) != i) exit(1); + } + if constexpr (t & TEST_FLOATING_ONE_MINUS) { + res = pk_stn(&i, STRNUM_FLOAT_ONE_MINUS, &s); + std::cout << "pkstn: TEST_FLOATING_ONE_MINUS res: " << i << "\n"; + if (s != STRNUM_FLOAT_ONE_MINUS + strlen(STRNUM_FLOAT_ONE_MINUS)) exit(1); + if (res != PK_STN_RES_SUCCESS) exit(1); + if (T(VAL_FLOATING_ONE_MINUS) != i) exit(1); + } + if constexpr (t & TEST_SCALAR_UNDERFLOW) { + res = pk_stn(&i, STRNUM_UNDERFLOW, &s); + std::cout << "pkstn: TEST_SCALAR_UNDERFLOW res: " << i << "\n"; + if (s != STRNUM_UNDERFLOW + strlen(STRNUM_UNDERFLOW)) exit(1); if constexpr(std::is_unsigned_v<T> == true) { if (res != PK_STN_RES_OVERFLOW) exit(1); } else { if (res != PK_STN_RES_UNDERFLOW) exit(1); } } - if constexpr (t & TEST_OVERFLOW) { - const char * str; - if constexpr(std::is_same<T, float>::value == true || std::is_same<T, double>::value == true) { - str = STRNUM_OVERFLOW_FLOAT; - } else { - str = STRNUM_OVERFLOW; - } - res = pk_stn(&i, str); - std::cout << "pkstn: TEST_OVERFLOW res: " << i << "\n"; + if constexpr (t & TEST_FLOATING_UNDERFLOW) { + res = pk_stn(&i, STRNUM_UNDERFLOW_FLOAT, &s); + std::cout << "pkstn: TEST_FLOATING_UNDERFLOW res: " << i << "\n"; + if (s != STRNUM_UNDERFLOW_FLOAT + strlen(STRNUM_UNDERFLOW_FLOAT)) exit(1); + if (res != PK_STN_RES_UNDERFLOW) exit(1); + } + if constexpr (t & TEST_SCALAR_OVERFLOW) { + res = pk_stn(&i, STRNUM_OVERFLOW, &s); + std::cout << "pkstn: TEST_SCALAR_OVERFLOW res: " << i << "\n"; + if (s != STRNUM_OVERFLOW + strlen(STRNUM_OVERFLOW)) exit(1); + if (res != PK_STN_RES_OVERFLOW) exit(1); + } + if constexpr (t & TEST_FLOATING_OVERFLOW) { + res = pk_stn(&i, STRNUM_OVERFLOW_FLOAT, &s); + std::cout << "pkstn: TEST_FLOATING_OVERFLOW res: " << i << "\n"; + if (s != STRNUM_OVERFLOW_FLOAT + strlen(STRNUM_OVERFLOW_FLOAT)) exit(1); if (res != PK_STN_RES_OVERFLOW) exit(1); } if constexpr (t & TEST_INCONVERTIBLE) { - res = pk_stn(&i, STRNUM_INCONVERTIBLE); + res = pk_stn(&i, STRNUM_INCONVERTIBLE, &s); std::cout << "pkstn: TEST_INCONVERTIBLE res: " << i << "\n"; + if (s != STRNUM_INCONVERTIBLE) exit(1); if (res != PK_STN_RES_INCONVERTIBLE) exit(1); } }; @@ -83,48 +151,54 @@ int main(int argc, char *argv[]) // stn_int64_t { fprintf(stdout, "\npkstn: starting int64_t\n"); - test<int64_t, TEST_ALL>(); + test<int64_t, TEST_SCALAR>(); } // stn_uint64_t { fprintf(stdout, "\npkstn: starting uint64_t\n"); - test<uint64_t, TEST_ALL>(); } + test<uint64_t, TEST_SCALAR>(); } // stn_int32_t { fprintf(stdout, "\npkstn: starting int32_t\n"); - test<int32_t, TEST_ALL>(); + test<int32_t, TEST_SCALAR>(); } // stn_uint32_t { fprintf(stdout, "\npkstn: starting uint32_t\n"); - test<uint32_t, TEST_ALL>(); + test<uint32_t, TEST_SCALAR>(); } // stn_int16_t { fprintf(stdout, "\npkstn: starting int16_t\n"); - test<int16_t, TEST_ALL>(); + test<int16_t, TEST_SCALAR>(); } // stn_uint16_t { fprintf(stdout, "\npkstn: starting uint16_t\n"); - test<uint16_t, TEST_ALL>(); + test<uint16_t, TEST_SCALAR>(); } // stn_int8_t { fprintf(stdout, "\npkstn: starting int8_t\n"); - test<int8_t, TEST_ALL>(); + test<int8_t, TEST_SCALAR>(); } // stn_uint8_t { fprintf(stdout, "\npkstn: starting uint8_t\n"); - test<uint8_t, TEST_ALL>(); + test<uint8_t, TEST_SCALAR>(); + } + + // bool + { + fprintf(stdout, "\npkstn: starting bool\n"); + test<bool, TEST_SCALAR>(); } // stn_float |
