]> git.sur5r.net Git - cc65/commitdiff
two more tests 173/head
authormrdudz <mrdudz@users.noreply.github.com>
Thu, 9 Jul 2015 15:36:12 +0000 (17:36 +0200)
committermrdudz <mrdudz@users.noreply.github.com>
Thu, 9 Jul 2015 15:36:12 +0000 (17:36 +0200)
test/val/add3a.c [new file with mode: 0755]
test/val/casttochar.c [new file with mode: 0755]

diff --git a/test/val/add3a.c b/test/val/add3a.c
new file mode 100755 (executable)
index 0000000..4ca32d0
--- /dev/null
@@ -0,0 +1,73 @@
+
+/*
+  !!DESCRIPTION!! Addition tests - mostly int's
+  !!ORIGIN!!      SDCC regression tests
+  !!LICENCE!!     GPL, read COPYING.GPL
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+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 <stdint.h>
+
+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 (executable)
index 0000000..d492f6b
--- /dev/null
@@ -0,0 +1,49 @@
+
+/*
+  !!DESCRIPTION!! Cast to char
+  !!ORIGIN!!      Piotr Fusik
+  !!LICENCE!!     PD
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+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;
+}