add some operator tests for int8_t being typecast to uint16_t
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 11 Oct 2018 06:56:32 +0000 (07:56 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 11 Oct 2018 06:56:32 +0000 (07:56 +0100)
operators/operators.t.cc

index 24b20da9e9805917652e62e014a9476035f9c30d..b5ac0185adba82ad8424401a50807f63ecb383ea 100644 (file)
@@ -4,6 +4,27 @@
 #include "operators_test.h"
 #include "decode.h"
 
+#define xstr(x) str(x)
+#define str(x) #x
+
+#define divide /
+#define remainder %
+#define plus +
+#define minus -
+#define shiftr >>
+#define shiftl >>
+#define mul >>
+
+#define operator_check( op ) { \
+            int8_t z = x op y;                                \
+            x1 = (uint8_t)x;                                  \
+            y1 = (uint8_t)y;                                  \
+            uint16_t z1 = x1 op y1;                           \
+            if (z1 != z) {                                    \
+                printf("FAILED %s %d %d %d %d\n",             \
+                    xstr(op), i, j, z, z1);                   \
+            }                                                 \
+            }
 int main(int argc, char *argv[])
 {
     /*op2<uint16_t, uint16_t, uint32_t> o(0xfff0);
@@ -15,5 +36,21 @@ int main(int argc, char *argv[])
     uint64_t  s1 = 0x1ff01;
     uint64_t  s2 = 0x2ff01;
     cvt.add(o, s1, s2);
-    printf("hello %lx\n", o);
+    //printf("hello %lx\n", o);
+
+    int8_t x=0, y=0;
+    uint16_t x1, y1;
+
+    for (int i=0, x=0; i < 256; i++, x++) {
+        //printf("hello %x\n", (int)(uint8_t)x);
+        for (int j, y=0; j < 255; j++, y++) {
+            operator_check( plus )
+            operator_check( minus )
+            operator_check( divide )
+            operator_check( remainder )
+            operator_check( shiftr )
+            operator_check( shiftl )
+            operator_check( mul )
+        }
+    }
 }