Additions to inttypes.h format strings

This commit is contained in:
Erik van der Kouwe
2010-01-25 18:16:25 +00:00
parent 58024f9eb0
commit f8804c0240
5 changed files with 278 additions and 20 deletions

View File

@@ -10,11 +10,11 @@ OBJ= test1 test2 test3 test4 test5 test6 test7 test8 test9 \
test21 test22 test23 test25 test26 test27 test28 test29 \
test30 test31 test32 test34 test35 test36 test37 test38 \
test39 t10a t11a t11b test40 t40a t40b t40c t40d t40e t40f test41 \
test42 test44 test45 test47 test48
test42 test44 test45 test47 test48 test49
BIGOBJ= test20 test24
ROOTOBJ= test11 test33 test43 test46
GCCOBJ= test45-gcc
GCCOBJ= test45-gcc test49-gcc
all: $(OBJ) $(BIGOBJ) $(GCCOBJ) $(ROOTOBJ) Benchmarks
chmod 755 *.sh run
@@ -100,4 +100,6 @@ test45-gcc: test45.c test45.h
test46: test46.c
test47: test47.c
test48: test48.c
test49: test49.c
test49-gcc: test49.c

View File

@@ -13,13 +13,13 @@ badones= # list of tests that failed
# Print test welcome message
clr
echo "Running POSIX compliance test suite. There are 51 tests in total."
echo "Running POSIX compliance test suite. There are 53 tests in total."
echo " "
# Run all the tests, keeping track of who failed.
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 45-gcc 46 47 48 sh1.sh sh2.sh
41 42 43 44 45 45-gcc 46 47 48 49 49-gcc sh1.sh sh2.sh
do
if [ -x ./test$i ]
then

212
test/test49.c Executable file
View File

@@ -0,0 +1,212 @@
#include <assert.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if defined(__LONG_LONG_SUPPORTED) || (_WORD_SIZE > 2 && __L64)
#define TEST_64_BIT
#endif
#define ERR err(__LINE__)
#define MAX_ERROR 4
static int errct;
static void quit(void)
{
if (errct == 0)
{
printf("ok\n");
exit(0);
}
else
{
printf("%d errors\n", errct);
exit(1);
}
}
static void err(int line)
{
printf("error at line %d\n", line);
if (++errct >= MAX_ERROR)
quit();
}
#define TEST_PRINTF(type, macro, value, result) \
{ \
char buffer[256]; \
snprintf(buffer, sizeof(buffer), "%" macro, (type) value); \
if (strcmp(buffer, result) != 0) err(__LINE__); \
}
int main(void)
{
#ifdef __LONG_LONG_SUPPORTED
printf("Test 49 (GCC) ");
#else
printf("Test 49 (ACK) ");
#endif
fflush(stdout);
/* test integer sizes */
if (sizeof(int8_t) != 1) ERR;
if (sizeof(uint8_t) != 1) ERR;
if (sizeof(int_fast8_t) < 1) ERR;
if (sizeof(uint_fast8_t) < 1) ERR;
if (sizeof(int_least8_t) < 1) ERR;
if (sizeof(uint_least8_t) < 1) ERR;
if (sizeof(int16_t) != 2) ERR;
if (sizeof(uint16_t) != 2) ERR;
if (sizeof(int_fast16_t) < 2) ERR;
if (sizeof(uint_fast16_t) < 2) ERR;
if (sizeof(int_least16_t) < 2) ERR;
if (sizeof(uint_least16_t) < 2) ERR;
if (sizeof(int32_t) != 4) ERR;
if (sizeof(uint32_t) != 4) ERR;
if (sizeof(int_fast32_t) < 4) ERR;
if (sizeof(uint_fast32_t) < 4) ERR;
if (sizeof(int_least32_t) < 4) ERR;
if (sizeof(uint_least32_t) < 4) ERR;
#ifdef TEST_64_BIT
if (sizeof(int64_t) != 8) ERR;
if (sizeof(uint64_t) != 8) ERR;
if (sizeof(int_fast64_t) < 8) ERR;
if (sizeof(uint_fast64_t) < 8) ERR;
if (sizeof(int_least64_t) < 8) ERR;
if (sizeof(uint_least64_t) < 8) ERR;
#endif
if (sizeof(intptr_t) != sizeof(void *)) ERR;
if (sizeof(uintptr_t) != sizeof(void *)) ERR;
#ifdef TEST_64_BIT
if (sizeof(intmax_t) < 8) ERR;
if (sizeof(uintmax_t) < 8) ERR;
#else
if (sizeof(intmax_t) < 4) ERR;
if (sizeof(uintmax_t) < 4) ERR;
#endif
/* test integer signedness */
if ((int8_t) (-1) >= 0) ERR;
if ((uint8_t) (-1) <= 0) ERR;
if ((int_fast8_t) (-1) >= 0) ERR;
if ((uint_fast8_t) (-1) <= 0) ERR;
if ((int_least8_t) (-1) >= 0) ERR;
if ((uint_least8_t) (-1) <= 0) ERR;
if ((int16_t) (-1) >= 0) ERR;
if ((uint16_t) (-1) <= 0) ERR;
if ((int_fast16_t) (-1) >= 0) ERR;
if ((uint_fast16_t) (-1) <= 0) ERR;
if ((int_least16_t) (-1) >= 0) ERR;
if ((uint_least16_t) (-1) <= 0) ERR;
if ((int32_t) (-1) >= 0) ERR;
if ((uint32_t) (-1) <= 0) ERR;
if ((int_fast32_t) (-1) >= 0) ERR;
if ((uint_fast32_t) (-1) <= 0) ERR;
if ((int_least32_t) (-1) >= 0) ERR;
if ((uint_least32_t) (-1) <= 0) ERR;
#ifdef TEST_64_BIT
if ((int64_t) (-1) >= 0) ERR;
if ((uint64_t) (-1) <= 0) ERR;
if ((int_fast64_t) (-1) >= 0) ERR;
if ((uint_fast64_t) (-1) <= 0) ERR;
if ((int_least64_t) (-1) >= 0) ERR;
if ((uint_least64_t) (-1) <= 0) ERR;
#endif
if ((intptr_t) (-1) >= 0) ERR;
if ((uintptr_t) (-1) <= 0) ERR;
if ((intptr_t) (-1) >= 0) ERR;
if ((uintptr_t) (-1) <= 0) ERR;
/* test printf */
TEST_PRINTF(int32_t, PRId32, INT32_MIN, "-2147483648");
TEST_PRINTF(int32_t, PRId32, INT32_MAX, "2147483647");
TEST_PRINTF(int32_t, PRIi32, INT32_MIN, "-2147483648");
TEST_PRINTF(int32_t, PRIi32, INT32_MAX, "2147483647");
TEST_PRINTF(uint32_t, PRIu32, UINT32_MAX, "4294967295");
TEST_PRINTF(uint32_t, PRIX32, UINT32_MAX, "FFFFFFFF");
TEST_PRINTF(uint32_t, PRIx32, UINT32_MAX, "ffffffff");
TEST_PRINTF(uint32_t, PRIo32, UINT32_MAX, "37777777777");
TEST_PRINTF(int_fast32_t, PRIdFAST32, INT32_MIN, "-2147483648");
TEST_PRINTF(int_fast32_t, PRIdFAST32, INT32_MAX, "2147483647");
TEST_PRINTF(int_fast32_t, PRIiFAST32, INT32_MIN, "-2147483648");
TEST_PRINTF(int_fast32_t, PRIiFAST32, INT32_MAX, "2147483647");
TEST_PRINTF(uint_fast32_t, PRIuFAST32, UINT32_MAX, "4294967295");
TEST_PRINTF(uint_fast32_t, PRIXFAST32, UINT32_MAX, "FFFFFFFF");
TEST_PRINTF(uint_fast32_t, PRIxFAST32, UINT32_MAX, "ffffffff");
TEST_PRINTF(uint_fast32_t, PRIoFAST32, UINT32_MAX, "37777777777");
TEST_PRINTF(int_least32_t, PRIdLEAST32, INT32_MIN, "-2147483648");
TEST_PRINTF(int_least32_t, PRIdLEAST32, INT32_MAX, "2147483647");
TEST_PRINTF(int_least32_t, PRIiLEAST32, INT32_MIN, "-2147483648");
TEST_PRINTF(int_least32_t, PRIiLEAST32, INT32_MAX, "2147483647");
TEST_PRINTF(uint_least32_t, PRIuLEAST32, UINT32_MAX, "4294967295");
TEST_PRINTF(uint_least32_t, PRIXLEAST32, UINT32_MAX, "FFFFFFFF");
TEST_PRINTF(uint_least32_t, PRIxLEAST32, UINT32_MAX, "ffffffff");
TEST_PRINTF(uint_least32_t, PRIoLEAST32, UINT32_MAX, "37777777777");
#ifdef TEST_64_BIT
TEST_PRINTF(int64_t, PRId64, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(int64_t, PRId64, INT64_MAX, "9223372036854775807");
TEST_PRINTF(int64_t, PRIi64, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(int64_t, PRIi64, INT64_MAX, "9223372036854775807");
TEST_PRINTF(uint64_t, PRIu64, UINT64_MAX, "18446744073709551615");
TEST_PRINTF(uint64_t, PRIX64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
TEST_PRINTF(uint64_t, PRIx64, UINT64_MAX, "ffffffffffffffff");
TEST_PRINTF(uint64_t, PRIo64, UINT64_MAX, "1777777777777777777777");
TEST_PRINTF(int_fast64_t, PRIdFAST64, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(int_fast64_t, PRIdFAST64, INT64_MAX, "9223372036854775807");
TEST_PRINTF(int_fast64_t, PRIiFAST64, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(int_fast64_t, PRIiFAST64, INT64_MAX, "9223372036854775807");
TEST_PRINTF(uint_fast64_t, PRIuFAST64, UINT64_MAX, "18446744073709551615");
TEST_PRINTF(uint_fast64_t, PRIXFAST64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
TEST_PRINTF(uint_fast64_t, PRIxFAST64, UINT64_MAX, "ffffffffffffffff");
TEST_PRINTF(uint_fast64_t, PRIoFAST64, UINT64_MAX, "1777777777777777777777");
TEST_PRINTF(int_least64_t, PRIdLEAST64, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(int_least64_t, PRIdLEAST64, INT64_MAX, "9223372036854775807");
TEST_PRINTF(int_least64_t, PRIiLEAST64, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(int_least64_t, PRIiLEAST64, INT64_MAX, "9223372036854775807");
TEST_PRINTF(uint_least64_t, PRIuLEAST64, UINT64_MAX, "18446744073709551615");
TEST_PRINTF(uint_least64_t, PRIXLEAST64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
TEST_PRINTF(uint_least64_t, PRIxLEAST64, UINT64_MAX, "ffffffffffffffff");
TEST_PRINTF(uint_least64_t, PRIoLEAST64, UINT64_MAX, "1777777777777777777777");
TEST_PRINTF(intmax_t, PRIdMAX, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(intmax_t, PRIdMAX, INT64_MAX, "9223372036854775807");
TEST_PRINTF(intmax_t, PRIiMAX, INT64_MIN, "-9223372036854775808");
TEST_PRINTF(intmax_t, PRIiMAX, INT64_MAX, "9223372036854775807");
TEST_PRINTF(uintmax_t, PRIuMAX, UINT64_MAX, "18446744073709551615");
TEST_PRINTF(uintmax_t, PRIXMAX, UINT64_MAX, "FFFFFFFFFFFFFFFF");
TEST_PRINTF(uintmax_t, PRIxMAX, UINT64_MAX, "ffffffffffffffff");
TEST_PRINTF(uintmax_t, PRIoMAX, UINT64_MAX, "1777777777777777777777");
#else
TEST_PRINTF(intmax_t, PRIdMAX, INT32_MIN, "-2147483648");
TEST_PRINTF(intmax_t, PRIdMAX, INT32_MAX, "2147483647");
TEST_PRINTF(intmax_t, PRIiMAX, INT32_MIN, "-2147483648");
TEST_PRINTF(intmax_t, PRIiMAX, INT32_MAX, "2147483647");
TEST_PRINTF(uintmax_t, PRIuMAX, UINT32_MAX, "4294967295");
TEST_PRINTF(uintmax_t, PRIXMAX, UINT32_MAX, "FFFFFFFF");
TEST_PRINTF(uintmax_t, PRIxMAX, UINT32_MAX, "ffffffff");
TEST_PRINTF(uintmax_t, PRIoMAX, UINT32_MAX, "37777777777");
#endif
TEST_PRINTF(intptr_t, PRIdPTR, INT32_MIN, "-2147483648");
TEST_PRINTF(intptr_t, PRIdPTR, INT32_MAX, "2147483647");
TEST_PRINTF(intptr_t, PRIiPTR, INT32_MIN, "-2147483648");
TEST_PRINTF(intptr_t, PRIiPTR, INT32_MAX, "2147483647");
TEST_PRINTF(uintptr_t, PRIuPTR, UINT32_MAX, "4294967295");
TEST_PRINTF(uintptr_t, PRIXPTR, UINT32_MAX, "FFFFFFFF");
TEST_PRINTF(uintptr_t, PRIxPTR, UINT32_MAX, "ffffffff");
TEST_PRINTF(uintptr_t, PRIoPTR, UINT32_MAX, "37777777777");
/* done */
quit();
assert(0);
return -1;
}