changeset 492:185a6ea03fea

Add some tests for PRI* types.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Dec 2019 02:49:11 +0200
parents 76653f979a62
children 3a733cdfc576
files tests.c
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Thu Dec 05 02:33:48 2019 +0200
+++ b/tests.c	Thu Dec 05 02:49:11 2019 +0200
@@ -506,6 +506,34 @@
         TEST2B(th_strmatch, "öriÖRI! lol", "?ri?RI!*", FALSE); // should match
     }
 
+    // printf PRI* format specifiers, also a compile time test
+    if (test_set_start("PRI*"))
+    {
+        char tmp[32];
+        uint32_t u32 = 0xaabbccdd;
+        uint64_t u64 = 0xaabbccdd11223344;
+        size_t usiz =
+#if TH_ARCH == 32
+            0x11223344;
+#elif TH_ARCH == 64
+            0xaabbccdd11223344;
+#else
+#error Unsupported TH_ARCH value.
+#endif
+
+        snprintf(tmp, sizeof(tmp), "%16" PRIx_SIZE_T "h", usiz);
+#if TH_ARCH == 32
+        TEST2(strcmp, tmp, "0000000011223344h", TRUE);
+#else
+        TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE);
+#endif
+
+        snprintf(tmp, sizeof(tmp), "%08" PRIx32 "h", u32);
+        TEST2(strcmp, tmp, "aabbccddh", TRUE);
+        snprintf(tmp, sizeof(tmp), "%16" PRIx64 "h", u64);
+        TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE);
+    }
+
     //
     // Print summary and exit
     //