X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=support%2Fregression%2Ftests%2Fzeropad.c;h=fef5ff50f62b8e766c6af6cfb5f549dc5676a82a;hb=8e6223aa3e8082a6f4be63a3aa2d05d4d7a8c4a5;hp=d8cab98a9b293ae8126364f4f9d4a409061bcb09;hpb=fd593a3df97b2d4742d2c81ba81d3edfdf5ac342;p=fw%2Fsdcc diff --git a/support/regression/tests/zeropad.c b/support/regression/tests/zeropad.c index d8cab98a..fef5ff50 100644 --- a/support/regression/tests/zeropad.c +++ b/support/regression/tests/zeropad.c @@ -1,13 +1,46 @@ /** Zeropad tests. - storage: idata, xdata, code, + storage: idata, pdata, xdata, code, */ +#ifndef STORAGE +#define STORAGE {storage} +#endif + +#if defined (__GNUC__) && defined (__alpha__) && (__GNUC__ < 3) + /* since g fails on GCC 2.95.4 on alpha... */ + #define FLEXARRAY 0 + #define TEST_G 0 +#else + #define FLEXARRAY 1 + #define TEST_G 1 +#endif + #include -#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) -# define idata -# define xdata -# define code +typedef unsigned int size_t; +#define offsetof(s,m) (size_t)&(((s *)0)->m) + +const char *string1 = "\x00\x01"; +const char string2[] = "\x00\x01"; + +#ifndef PORT_HOST +#pragma disable_warning 147 //no warning about excess initializers (W_EXCESS_INITIALIZERS) +//array will be truncated but warning will be suppressed +//if truncation is incorrect, other ASSERTs will fail with high probability +char STORAGE trunc[2] = {'a', 'b', 'c'}; +#endif + +char STORAGE array[5] = {'a', 'b', 'c'}; + +#if TEST_G + struct w { + char a; + int b; + } STORAGE g[3] = { + {'x', 1}, + {'y'}, + {'z', 3} + }; #endif struct x { @@ -15,21 +48,56 @@ struct x { char b[10]; }; -struct x {storage} teststruct[6] = { +struct x STORAGE teststruct[5] = { { 10, { 1, 2, 3, 4, 5} }, { 20, { 11 } }, { 30, { 6, 7, 8} } }; +#if FLEXARRAY + struct y { + short a; + char b[]; + }; + +struct y STORAGE incompletestruct = { + 10, {1, 2, 3, 4, 5} +}; +#endif + void testZeropad(void) { + ASSERT(string1[1] == '\x01'); + ASSERT(string2[1] == '\x01'); + + ASSERT(array[2] == 'c'); + ASSERT(array[4] == 0); + +#if TEST_G + ASSERT(g[1].a == 'y'); + ASSERT(g[1].b == 0); + ASSERT(g[2].a == 'z'); + ASSERT(g[2].b == 3); +#endif + ASSERT(teststruct[0].b[1] == 2); ASSERT(teststruct[0].b[5] == 0); ASSERT(teststruct[1].b[0] == 11); + ASSERT(teststruct[4].b[9] == 0); ASSERT(sizeof(teststruct[2].a) == 2); ASSERT(sizeof(teststruct[1].b) == 10); ASSERT(sizeof(teststruct[1]) == 12); - ASSERT(sizeof(teststruct) == 72); + ASSERT(sizeof(teststruct) == 60); + +#if FLEXARRAY + ASSERT(incompletestruct.a == 10); + ASSERT(incompletestruct.b[0] == 1); + ASSERT(incompletestruct.b[4] == 5); + + ASSERT(sizeof(incompletestruct) == sizeof(struct y)); + ASSERT(sizeof(incompletestruct) == offsetof(struct y, b)); + ASSERT(sizeof(incompletestruct) == offsetof(struct x, b)); +#endif }