* src/z80/gen.c: fixed bug #1294691: nested ifs make compiler crash;
[fw/sdcc] / support / regression / tests / shifts.c
index 8d0eb33c4288e3c54d3bd885b393884f96f065d5..0eb607f91a808f4cf007377efca0e50fc71baf35 100644 (file)
@@ -1,6 +1,8 @@
 /** Tests covering the shift operators.
+    disabled for pic16
 
-    type: char, int
+    sign: signed, unsigned
+    type: char, int, long
     storage: static, 
     attr: volatile
 
 */
 #include <testfwk.h>
 
-static void
-testShiftClasses(void)
+void
+test1ShiftClasses(void)
 {
-    {attr} {storage} {type} i, result;
+    {attr} {storage} {sign} {type} i, result;
 
     i = 30;
     ASSERT(i>>3 == 3);
@@ -28,30 +30,46 @@ testShiftClasses(void)
     ASSERT(result == 120);
 }
 
-/** PENDING: Disabled. */
-static void
-testShiftByteMultiples(void)
+void
+test2ShiftRight(void)
+{
+    {attr} {storage} {type} i, result;
+
+    i = -120;
+    ASSERT(i>>1 == -60);
+    ASSERT(i>>2 == -30);
+    ASSERT(i>>3 == -15);
+    ASSERT(i>>4 == -8);
+    ASSERT(i>>5 == -4);
+    ASSERT(i>>6 == -2);
+    ASSERT(i>>7 == -1);
+    ASSERT(i>>8 == -1);
+    result = i;
+    result >>= 3;
+    ASSERT(result == -15); 
+}
+
+void
+test3ShiftByteMultiples(void)
 {
-#if 1
     {attr} {storage} {type} i;
 
     i = ({type}){vals};
-    ASSERT(i>>8  == (({type}){vals} >> 8));
-    ASSERT(i>>16 == (({type}){vals} >> 16));
-    ASSERT(i>>24 == (({type}){vals} >> 24));
+    ASSERT(i>>8  == ({type})({vals} >> 8));
+    ASSERT(i>>16 == ({type})({vals} >> 16));
+    ASSERT(i>>24 == ({type})({vals} >> 24));
 
     i = ({type}){vals};
-    ASSERT(i<<8  == (({type}){vals} << 8));;
-    ASSERT(i<<16 == (({type}){vals} << 16));
-    ASSERT(i<<24 == (({type}){vals} << 24));
-#endif
+    ASSERT( ({type})(i<<8)  ==  ({type})({vals} << 8));;
+    ASSERT((({type}) i<<16) == (({type}) {vals} << 16));
+    ASSERT((({type}) i<<24) == (({type}) {vals} << 24));
 }
 
-static void
-testShiftOne(void)
+void
+test4ShiftOne(void)
 {
-    {attr} {storage} {type} i;
-    {type} result;
+    {attr} {storage} {sign} {type} i;
+    {sign} {type} result;
 
     i = ({type}){vals};
 
@@ -69,3 +87,24 @@ testShiftOne(void)
     result <<= 1;
     ASSERT(result == ({type})(({type}){vals} << 1));
 }
+
+static {type} ShiftLeftByParam ({type} count)
+{
+    {attr} {storage} {type} i;
+    i = ({type}){vals};
+    return (i << count);
+}
+
+static {type} ShiftRightByParam ({type} count)
+{
+    {attr} {storage} {type} i;
+    i = ({type}){vals};
+    return (i >> count);
+}
+
+void
+testShiftByParam(void)
+{
+    ASSERT(ShiftLeftByParam(2)  == ({type})({vals} << 2));
+    ASSERT(ShiftRightByParam(2) == ({type})({vals} >> 2));
+}