support/regression/tests/array.c: added, contains check for #1434401
authorfrief <frief@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 Feb 2006 11:25:58 +0000 (11:25 +0000)
committerfrief <frief@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 20 Feb 2006 11:25:58 +0000 (11:25 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4045 4a8a32a2-be11-0410-ad9d-d568d2c75423

support/regression/tests/array.c [new file with mode: 0644]

diff --git a/support/regression/tests/array.c b/support/regression/tests/array.c
new file mode 100644 (file)
index 0000000..cc07054
--- /dev/null
@@ -0,0 +1,58 @@
+/** array test
+    type: char, int
+    storage: xdata, code,
+*/
+#include <testfwk.h>
+
+#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
+# define xdata
+# define code
+#endif
+
+#define TC(x) (0x10+(x))
+#define TI(x) (0x1020+(x) + 0x100*(x))
+#define TL(x) (0x10203040+(x))
+
+const {storage} char array_const_char[4] = {TC(0), TC(1), TC(2), TC(3)};
+const {storage} int  array_const_int [4] = {TI(0), TI(1), TI(2), TI(3)};
+const {storage} long array_const_long[4] = {TL(0), TL(1), TL(2), TL(3)};
+
+char array_char[4] = {TC(0), TC(1), TC(2), TC(3)};
+int  array_int [4] = {TI(0), TI(1), TI(2), TI(3)};
+long array_long[4] = {TL(0), TL(1), TL(2), TL(3)};
+
+volatile unsigned {type} idx;
+volatile unsigned {type} idx2;
+
+void
+testArrayAccess(void)
+{
+  idx = 2;
+  
+  ASSERT(array_const_char[idx] == TC(2));
+  ASSERT(array_const_int [idx] == TI(2));
+  ASSERT(array_const_long[idx] == TL(2));
+
+  ASSERT(array_const_char[2] == TC(2));
+  ASSERT(array_const_int [2] == TI(2));
+  ASSERT(array_const_long[2] == TL(2));
+
+  ASSERT(array_char[idx] == TC(2));
+  ASSERT(array_int [idx] == TI(2));
+  ASSERT(array_long[idx] == TL(2));
+
+  ASSERT(array_char[2] == TC(2));
+  ASSERT(array_int [2] == TI(2));
+  ASSERT(array_long[2] == TL(2));
+
+  idx = 3;
+  idx2 = 1;
+
+  array_char[idx2] = array_const_char[idx] | 0x80;
+  array_int [idx2] = array_const_int [idx] | 0x8080;
+  array_long[idx2] = array_const_long[idx] | 0x80808080;
+
+  ASSERT(array_char[idx2] == TC(3) | 0x80);
+  ASSERT(array_int [idx2] == TI(3) | 0x8080);
+  ASSERT(array_long[idx2] == TL(3) | 0x80808080);
+}