diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-03-27 16:13:10 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-03-27 16:13:10 -0400 |
| commit | c65204648f0a81cce25c12c6dcd58d76810ac303 (patch) | |
| tree | 4634f98672d00e321ab19d51629af130f1a27fbf /test | |
| parent | be07962dc264b732f9facafec7bbe4019bf91ad2 (diff) | |
pkuuid: add << and >> for const char *
Diffstat (limited to 'test')
| -rw-r--r-- | test/pkuuid.c | 36 | ||||
| -rw-r--r-- | test/pkuuid.cpp | 74 |
2 files changed, 107 insertions, 3 deletions
diff --git a/test/pkuuid.c b/test/pkuuid.c index 42cf3e4..3491ea3 100644 --- a/test/pkuuid.c +++ b/test/pkuuid.c @@ -110,6 +110,42 @@ main(int argc, char *argv[]) fprintf(stdout, "\n"); } + // test parse + { + bool res; + unsigned char i; + struct pk_uuid idm; + struct pk_uuid idz; + struct pk_uuid id; + struct pk_uuid id_expected = { .uuid = { 0x67, 0xe5, 0x98, 0x5c, 0x82, 0xb7, 0x72, 0x69, 0x94, 0xda, 0x81, 0x9c, 0x18, 0xa7, 0xec, 0xe8 } }; + const char * s_idm = "ffffffff-ffff-ffff-ffff-ffffffffffff"; + const char * s_idz = "00000000-0000-0000-0000-000000000000"; + const char * s_id = "67e5985c-82b7-7269-94da-819c18a7ece8"; + + fprintf(stdout, "[%s] test parse.\n", __FILE__); + res = pk_uuid_parse(s_idm, &idm); + fprintf(stdout, "[%s] expected: " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(pk_uuid_max)); + fprintf(stdout, "[%s] parsed : " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(idm)); + if (res == false) exit(1); + + res = pk_uuid_parse(s_idz, &idz); + fprintf(stdout, "[%s] expected: " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(pk_uuid_zed)); + fprintf(stdout, "[%s] parsed : " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(idz)); + if (res == false) exit(1); + + res = pk_uuid_parse(s_id, &id); + fprintf(stdout, "[%s] expected: " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(id_expected)); + fprintf(stdout, "[%s] parsed : " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(id)); + if (res == false) exit(1); + + for (i = 0; i < 16; ++i) { + if (idm.uuid[i] != 0xFF) exit(1); + if (idz.uuid[i] != 0x00) exit(1); + if (id.uuid[i] != id_expected.uuid[i]) exit(1); + } + fprintf(stdout, "\n"); + } + { double ms; const int count = 1000; diff --git a/test/pkuuid.cpp b/test/pkuuid.cpp index da59264..35c099f 100644 --- a/test/pkuuid.cpp +++ b/test/pkuuid.cpp @@ -144,11 +144,29 @@ main(int argc, char *argv[]) // >> { - struct pk_uuid id; - std::istringstream ssi("017f22e2-79b0-7cc3-98c4-dc0c0c07398f"); + struct pk_uuid id = pk_uuid_max; + std::istringstream ssi("017f22e2-79b0-7cc3-98c4-dc0c0c07398fX"); ssi >> id; + + fprintf(stdout, "\n"); + fprintf(stdout, "[%s] leftovers: ", __FILE__); ssi >> std::cout.rdbuf(); + std::cout << std::endl; + fprintf(stdout, "[%s] excpected: 017f22e2-79b0-7cc3-98c4-dc0c0c07398f\n", __FILE__); + fprintf(stdout, "[%s] result : " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(id)); + + for (int i = 0; i < 16; ++i) { + if (example_id.uuid[i] != id.uuid[i]) return 1; + } + } + + // >> + { + struct pk_uuid id = pk_uuid_max; + const char *ssi = "017f22e2-79b0-7cc3-98c4-dc0c0c07398f"; + + ssi >> id; fprintf(stdout, "\n"); fprintf(stdout, "[%s] excpected: 017f22e2-79b0-7cc3-98c4-dc0c0c07398f\n", __FILE__); @@ -159,9 +177,59 @@ main(int argc, char *argv[]) } } - // >> err + // << { struct pk_uuid id; + const char *ssi = "017f22e2-79b0-7cc3-98c4-dc0c0c07398f"; + + id << ssi; + + fprintf(stdout, "\n"); + fprintf(stdout, "[%s] excpected: 017f22e2-79b0-7cc3-98c4-dc0c0c07398f\n", __FILE__); + fprintf(stdout, "[%s] result : " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(id)); + + for (int i = 0; i < 16; ++i) { + if (example_id.uuid[i] != id.uuid[i]) return 1; + } + } + + // >> + { + struct pk_uuid id = pk_uuid_max; + const char *ssi = "017f22e2-79b0-7cc3-98c4-dc0c0c07398fX"; + + const char *res = ssi >> id; + + fprintf(stdout, "\n"); + fprintf(stdout, "[%s] leftovers: %.2s\n", __FILE__, res); + fprintf(stdout, "[%s] excpected: 017f22e2-79b0-7cc3-98c4-dc0c0c07398f\n", __FILE__); + fprintf(stdout, "[%s] result : " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(id)); + + if (res[0] != 'X') exit(1); + for (int i = 0; i < 16; ++i) { + if (example_id.uuid[i] != id.uuid[i]) return 1; + } + } + + // >> err + { + struct pk_uuid id = example_id; + const char *ssi = "gnud"; + + ssi >> id; + + fprintf(stdout, "\n"); + fprintf(stdout, "[%s] excpected: 00000000-0000-0000-0000-000000000000\n", __FILE__); + fprintf(stdout, "[%s] result : " pk_uuid_printf_format "\n", __FILE__, pk_uuid_printf_var(id)); + + for (int i = 0; i < 16; ++i) { + if (pk_uuid_zed.uuid[i] != id.uuid[i]) return 1; + } + } + + // >> err + { + struct pk_uuid id = example_id; std::istringstream ssi("gnud"); ssi >> id; |
