* src/SDCCast.c (createIvalType, createIvalStruct, createIvalArray,
[fw/sdcc] / support / regression / tests / zeropad.c
index 299be534f478e8a8954ce82e488b03beae2788ac..24576a899adf241b2cbe74f19396751325d4a118 100644 (file)
@@ -1,15 +1,23 @@
 /** Zeropad tests.
 
-    storage: idata, xdata, code,
+    storage: auto, idata, pdata, xdata, code,
 */
 #ifndef STORAGE
+#define STORAGE_{storage}
 #define STORAGE {storage}
 #endif
 
-#if defined __GNUC__
-  #define FLEXARRAY (__GNUC__ >= 3)
+#if defined (__GNUC__) && defined (__alpha__) && (__GNUC__ < 3)
+  /* since g fails on GCC 2.95.4 on alpha... */
+  #define FLEXARRAY 0
+  #define TEST_G    0
+#elif defined (STORAGE_auto)
+  /* only static flexible arrays are allowed */
+  #define FLEXARRAY 0
+  #define TEST_G    1
 #else
   #define FLEXARRAY 1
+  #define TEST_G    1
 #endif
 
 #include <testfwk.h>
 typedef unsigned int size_t;
 #define offsetof(s,m)   (size_t)&(((s *)0)->m)
 
-#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
-# define idata
-# define xdata
-# define code
+#if defined (STORAGE_auto)
+  void Zeropad(void)
+  {
+#endif //STORAGE_auto
+
+const char *string1 = "\x00\x01";
+const char string2[] = "\x00\x01";
+
+#ifndef PORT_HOST
+#pragma disable_warning 147 //no warning about excess initializers (W_EXCESS_INITIALIZERS)
+#pragma disable_warning  85 //no warning about unreferenced variables (W_NO_REFERENCE)
+//array will be truncated but warning will be suppressed
+//if truncation is incorrect, other ASSERTs will fail with high probability
+char STORAGE trunc[2] = {'a', 'b', 'c'};
 #endif
 
 char STORAGE array[5] = {'a', 'b', 'c'};
 
-struct w {
-  char a;
-  int  b;
-} STORAGE g[3] = {
-  {'x', 1},
-  {'y'},
-  {'z', 3}
-};
+#if TEST_G
+  struct w {
+    char a;
+    int  b;
+  } STORAGE g[3] = {
+    {'x', 1},
+    {'y'},
+    {'z', 3}
+  };
+#endif
 
 struct x {
   short a;
@@ -56,16 +76,25 @@ struct y STORAGE incompletestruct = {
 };
 #endif
 
-void
-testZeropad(void)
+#if !defined (STORAGE_auto)
+void Zeropad(void)
 {
+#endif //STORAGE_auto
+
+  ASSERT(string1[0] == '\x00');
+  ASSERT(string1[1] == '\x01');
+  ASSERT(string2[0] == '\x00');
+  ASSERT(string2[1] == '\x01');
+
   ASSERT(array[2] == 'c');
   ASSERT(array[4] == 0);
 
+#if TEST_G
   ASSERT(g[1].a == 'y');
   ASSERT(g[1].b == 0);
   ASSERT(g[2].a == 'z');
   ASSERT(g[2].b == 3);
+#endif
 
   ASSERT(teststruct[0].b[1] ==  2);
   ASSERT(teststruct[0].b[5] ==  0);
@@ -86,4 +115,23 @@ testZeropad(void)
   ASSERT(sizeof(incompletestruct) == offsetof(struct y, b));
   ASSERT(sizeof(incompletestruct) == offsetof(struct x, b));
 #endif
+
+#if defined (STORAGE_auto)
+  array[4] = 1;
+#if TEST_G
+  g[1].b = 1;
+#endif
+  teststruct[0].b[5] = 1;
+  teststruct[4].b[9] = 1;
+#endif //STORAGE_auto
+}
+
+void
+testZeropad(void)
+{
+  Zeropad();
+
+#if defined (STORAGE_auto)
+  Zeropad(); //test reinitialization
+#endif //STORAGE_auto
 }