type_printers.inc (1243B)
1 #include <limits.h> 2 3 #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L 4 5 #ifdef __cplusplus 6 UTEST(type_printers, cpp) { 7 #elif defined(UTEST_OVERLOADABLE) 8 UTEST(type_printers, overloadable) { 9 #elif __STDC_VERSION__ 10 UTEST(type_printers, stdc) { 11 #else 12 #error 13 #endif 14 15 FILE *old = utest_state.output; 16 FILE *out = tmpfile(); 17 ASSERT_TRUE(!!out); 18 utest_state.output = out; 19 20 int i = INT_MIN; 21 long l = LONG_MIN; 22 long long ll = LLONG_MIN; 23 unsigned u = UINT_MAX; 24 unsigned long ul = ULONG_MAX; 25 unsigned long long ull = ULLONG_MAX; 26 float f = 0.f; 27 double d = 0.; 28 long double ld = 0.l; 29 utest_type_printer(i); 30 utest_type_printer(l); 31 utest_type_printer(ll); 32 utest_type_printer(u); 33 utest_type_printer(ul); 34 utest_type_printer(ull); 35 utest_type_printer(f); 36 utest_type_printer(d); 37 utest_type_printer(ld); 38 39 char expected[1024] = {0}; 40 size_t expected_len = 41 UTEST_SNPRINTF(expected, sizeof expected - 1, "%d%ld%lld%u%lu%llu%f%f%Lf", 42 i, l, ll, u, ul, ull, f, d, ld); 43 fflush(out); 44 rewind(out); 45 char buf[1024] = {'\0'}; 46 const size_t n = fread(buf, 1, sizeof buf, out); 47 fclose(out); 48 utest_state.output = old; 49 ASSERT_EQ(n, expected_len); 50 ASSERT_STREQ(buf, expected); 51 } 52 #endif