From: mrdudz Date: Thu, 9 Jul 2015 15:36:12 +0000 (+0200) Subject: two more tests X-Git-Tag: V2.16~255^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F173%2Fhead;p=cc65 two more tests --- diff --git a/test/val/add3a.c b/test/val/add3a.c new file mode 100755 index 000000000..4ca32d06b --- /dev/null +++ b/test/val/add3a.c @@ -0,0 +1,73 @@ + +/* + !!DESCRIPTION!! Addition tests - mostly int's + !!ORIGIN!! SDCC regression tests + !!LICENCE!! GPL, read COPYING.GPL +*/ + +#include +#include + +static unsigned int failures = 0; + +/* + this test assumes: + sizeof(long) == 4 + + CAUTION: the wraparound behaviour is actually undefined, to get the "expected" + behaviour with GCC, use -fwrapv or -fno-strict-overflow + + see: https://gcc.gnu.org/wiki/FAQ#signed_overflow +*/ + +#ifdef REFERENCE + +/* + make sure the reference output uses types with + proper size +*/ + +#include + +int32_t long0 = 0; + +#else + +long long0 = 0; + +#endif + +void print(void) +{ +#if defined(REFERENCE) && defined(REFCC_SIZEOF_LONG_64BIT) + printf("long0: %d\n", long0); +#else + printf("long0: %ld\n", long0); +#endif +} + +int main(void) +{ + long0 = 0x7f000000L; + /* wrap around zero */ + print(); + long0 = long0 + 0x2000000L; + if(long0 != -0x7f000000L) { + printf("failed!\n"); + failures++; + } + print(); + + long0 = 0x7f000000L; + /* wrap around zero */ + print(); + long0 = long0 + 0x2000000L; + print(); + if(long0 != -0x7f000000L) { + printf("failed!\n"); + failures++; + } + print(); + + return failures; +} diff --git a/test/val/casttochar.c b/test/val/casttochar.c new file mode 100755 index 000000000..d492f6bb8 --- /dev/null +++ b/test/val/casttochar.c @@ -0,0 +1,49 @@ + +/* + !!DESCRIPTION!! Cast to char + !!ORIGIN!! Piotr Fusik + !!LICENCE!! PD +*/ + +#include +#include + +static unsigned int failures = 0; + +int f1(int i, int j) { + return (signed char) (i + 1) == j; +} + +int f2(int i, int j) { + return (unsigned char) (i + 1) == j; +} + +int f3(int i, int j) { + return (char) (i + 1) == j; +} + +int main(void) +{ + printf("f1: got :%04x ", f1(0x1234, 0x35)); + if(f1(0x1234, 0x35) == 0) { + printf("- failed"); + failures++; + } + printf("\n"); + + printf("f2: got :%04x ", f2(0x1234, 0x35)); + if(f2(0x1234, 0x35) == 0) { + printf("- failed"); + failures++; + } + printf("\n"); + + printf("f3: got :%04x ", f3(0x1234, 0x35)); + if(f3(0x1234, 0x35) == 0) { + printf("- failed"); + failures++; + } + printf("\n"); + + return failures; +}