# HG changeset patch # User Matti Hamalainen # Date 1575506951 -7200 # Node ID 185a6ea03fea9785b8b3e9bdf6146b8df596358e # Parent 76653f979a62587fbb20bd60bc820d334843b54c Add some tests for PRI* types. diff -r 76653f979a62 -r 185a6ea03fea tests.c --- 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 //