diff options
author | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 11:52:27 +0200 |
---|---|---|
committer | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 19:35:54 +0200 |
commit | b647d9d786873add910bb2477a0f0f8f40abd9e0 (patch) | |
tree | 91db140c67745a93a4c10cabd230b99d31c9fdb2 | |
parent | f45fab9e459a39b06383f3029078c7977f21aa8b (diff) |
Use do_run_from_file() for test_funcptr
-rw-r--r-- | tests/core/test_funcptr.in | 35 | ||||
-rw-r--r-- | tests/core/test_funcptr.out | 3 | ||||
-rw-r--r-- | tests/test_core.py | 38 |
3 files changed, 41 insertions, 35 deletions
diff --git a/tests/core/test_funcptr.in b/tests/core/test_funcptr.in new file mode 100644 index 00000000..8328924a --- /dev/null +++ b/tests/core/test_funcptr.in @@ -0,0 +1,35 @@ + + #include <stdio.h> + int calc1() { return 26; } + int calc2() { return 90; } + typedef int (*fp_t)(); + + fp_t globally1 = calc1; + fp_t globally2 = calc2; + + int nothing(const char *str) { return 0; } + + int main() + { + fp_t fp = calc1; + void *vp = (void*)fp; + fp_t fpb = (fp_t)vp; + fp_t fp2 = calc2; + void *vp2 = (void*)fp2; + fp_t fpb2 = (fp_t)vp2; + printf("*%d,%d,%d,%d,%d,%d*\n", fp(), fpb(), fp2(), fpb2(), globally1(), globally2()); + + fp_t t = calc1; + printf("*%d,%d", t == calc1, t == calc2); + t = calc2; + printf(",%d,%d*\n", t == calc1, t == calc2); + + int (*other)(const char *str); + other = nothing; + other("*hello!*"); + other = puts; + other("*goodbye!*"); + + return 0; + } +
\ No newline at end of file diff --git a/tests/core/test_funcptr.out b/tests/core/test_funcptr.out new file mode 100644 index 00000000..d6d3366a --- /dev/null +++ b/tests/core/test_funcptr.out @@ -0,0 +1,3 @@ +*26,26,90,90,26,90* +*1,0,0,1* +*goodbye!*
\ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index f6852b0a..e155d053 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1520,42 +1520,10 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output) def test_funcptr(self): - src = ''' - #include <stdio.h> - int calc1() { return 26; } - int calc2() { return 90; } - typedef int (*fp_t)(); - - fp_t globally1 = calc1; - fp_t globally2 = calc2; - - int nothing(const char *str) { return 0; } - - int main() - { - fp_t fp = calc1; - void *vp = (void*)fp; - fp_t fpb = (fp_t)vp; - fp_t fp2 = calc2; - void *vp2 = (void*)fp2; - fp_t fpb2 = (fp_t)vp2; - printf("*%d,%d,%d,%d,%d,%d*\\n", fp(), fpb(), fp2(), fpb2(), globally1(), globally2()); - - fp_t t = calc1; - printf("*%d,%d", t == calc1, t == calc2); - t = calc2; - printf(",%d,%d*\\n", t == calc1, t == calc2); - - int (*other)(const char *str); - other = nothing; - other("*hello!*"); - other = puts; - other("*goodbye!*"); + test_path = path_from_root('tests', 'core', 'test_funcptr') + src, output = (test_path + s for s in ('.in', '.out')) - return 0; - } - ''' - self.do_run(src, '*26,26,90,90,26,90*\n*1,0,0,1*\n*goodbye!*') + self.do_run_from_file(src, output) def test_mathfuncptr(self): src = ''' |