* support/cpp/auto-host.h: fixed warning: "__STDC__" redefined,
[fw/sdcc] / support / regression / tests / shifts.c
index 86fe18162374e939a02cdfc1b5dccef3d94b48fc..a975cdff060979b7d93aa57a4c7cc3ce872379aa 100644 (file)
@@ -2,7 +2,7 @@
 
     sign: signed, unsigned
     type: char, int, long
-    storage: static, 
+    storage: static,
     attr: volatile
 
     vals: 3
 #include <testfwk.h>
 
 void
-testShiftClasses(void)
+test1ShiftClasses(void)
 {
     {attr} {storage} {sign} {type} i, result;
 
     i = 30;
     ASSERT(i>>3 == 3);
     ASSERT(i<<2 == 120);
-    
+
     result = i;
     result >>= 2;
     ASSERT(result == 7);
@@ -30,7 +30,7 @@ testShiftClasses(void)
 }
 
 void
-testShiftRight(void)
+test2ShiftRight(void)
 {
     {attr} {storage} {type} i, result;
 
@@ -45,31 +45,27 @@ testShiftRight(void)
     ASSERT(i>>8 == -1);
     result = i;
     result >>= 3;
-    ASSERT(result == -15); 
+    ASSERT(result == -15);
 }
 
-/** PENDING: Disabled. */
-static void
-testShiftByteMultiples(void)
+void
+test3ShiftByteMultiples(void)
 {
-#if 0
-    /* PENDING */
     {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} {sign} {type} i;
     {sign} {type} result;
@@ -90,3 +86,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));
+}