diff --git a/libacc/tests/data/pointers2.c b/libacc/tests/data/pointers2.c new file mode 100644 index 000000000..69e402f69 --- /dev/null +++ b/libacc/tests/data/pointers2.c @@ -0,0 +1,35 @@ +// Test multiple levels of indirection + +void testsingle() { + int a = 0; + int* pa = &a; + printf("a = %d, *pa = %d\n", a, *pa); + *pa = 2; + printf("a = %d, *pa = %d\n", a, *pa); +} + +void testdouble() { + int a = 0; + int* pa = &a; + int** ppa = &pa; + printf("a = %d, *pa = %d **ppa = %d\n", a, *pa, **ppa); + **ppa = 2; + printf("a = %d, *pa = %d **ppa = %d\n", a, *pa, **ppa); +} + +void testtripple() { + int a = 0; + int* pa = &a; + int** ppa = &pa; + int*** pppa = &ppa; + printf("a = %d, *pa = %d **ppa = %d\n ***pppa = %d", a, *pa, **ppa, ***pppa); + ***pppa = 2; + printf("a = %d, *pa = %d **ppa = %d\n ***pppa = %d", a, *pa, **ppa, ***pppa); +} + +int main() { + testsingle(); + testdouble(); + testdouble(); + return 0; +} diff --git a/libacc/tests/test.py b/libacc/tests/test.py index 31b832999..f9089be2a 100644 --- a/libacc/tests/test.py +++ b/libacc/tests/test.py @@ -324,11 +324,22 @@ result: 0""", """Literals: 1 -1 0 """) - def testFilm (self): + def testFilm(self): self.compileCheck(["-R", "data/film.c"], """Executing compiled code: result: 0""", """testing... Total bad: 0 """) + + def testpointers2(self): + self.compileCheck(["-R", "data/pointers2.c"], """Executing compiled code: +result: 0""", """a = 0, *pa = 0 +a = 2, *pa = 2 +a = 0, *pa = 0 **ppa = 0 +a = 2, *pa = 2 **ppa = 2 +a = 0, *pa = 0 **ppa = 0 +a = 2, *pa = 2 **ppa = 2 +""") + if __name__ == '__main__': if not outputCanRun(): print "Many tests are expected to fail, because acc is not a 32-bit x86 Linux executable."