diff options
author | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 17:03:09 +0200 |
---|---|---|
committer | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 19:36:01 +0200 |
commit | 77bc19e22629ca314c5b5c85f2c45c7ee5e2e8e4 (patch) | |
tree | 148ef8d9b8d105fa5b7c3d632934129840d32db2 /tests | |
parent | fd27a14bc2d192ccbb3266f0f8188e5b371b1ebe (diff) |
Use do_run_from_file() for test_reinterpreted_ptrs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/test_reinterpreted_ptrs.in | 41 | ||||
-rw-r--r-- | tests/core/test_reinterpreted_ptrs.out | 1 | ||||
-rw-r--r-- | tests/test_core.py | 45 |
3 files changed, 45 insertions, 42 deletions
diff --git a/tests/core/test_reinterpreted_ptrs.in b/tests/core/test_reinterpreted_ptrs.in new file mode 100644 index 00000000..e5e257e0 --- /dev/null +++ b/tests/core/test_reinterpreted_ptrs.in @@ -0,0 +1,41 @@ + +#include <stdio.h> + +class Foo { +private: + float bar; +public: + int baz; + + Foo(): bar(0), baz(4711) {}; + + int getBar() const; +}; + +int Foo::getBar() const { + return this->bar; +}; + +const Foo *magic1 = reinterpret_cast<Foo*>(0xDEAD111F); +const Foo *magic2 = reinterpret_cast<Foo*>(0xDEAD888F); + +static void runTest() { + + const Foo *a = new Foo(); + const Foo *b = a; + + if (a->getBar() == 0) { + if (a->baz == 4712) + b = magic1; + else + b = magic2; + } + + printf("%s\n", (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); +}; + +extern "C" { + int main(int argc, char **argv) { + runTest(); + } +} diff --git a/tests/core/test_reinterpreted_ptrs.out b/tests/core/test_reinterpreted_ptrs.out new file mode 100644 index 00000000..36033502 --- /dev/null +++ b/tests/core/test_reinterpreted_ptrs.out @@ -0,0 +1 @@ +magic2
\ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index 228de112..c0612760 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4267,49 +4267,10 @@ PORT: 3979 def test_reinterpreted_ptrs(self): if self.emcc_args is None: return self.skip('needs emcc and libc') - src = r''' -#include <stdio.h> - -class Foo { -private: - float bar; -public: - int baz; - - Foo(): bar(0), baz(4711) {}; - - int getBar() const; -}; - -int Foo::getBar() const { - return this->bar; -}; - -const Foo *magic1 = reinterpret_cast<Foo*>(0xDEAD111F); -const Foo *magic2 = reinterpret_cast<Foo*>(0xDEAD888F); - -static void runTest() { - - const Foo *a = new Foo(); - const Foo *b = a; - - if (a->getBar() == 0) { - if (a->baz == 4712) - b = magic1; - else - b = magic2; - } - - printf("%s\n", (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); -}; + test_path = path_from_root('tests', 'core', 'test_reinterpreted_ptrs') + src, output = (test_path + s for s in ('.in', '.out')) -extern "C" { - int main(int argc, char **argv) { - runTest(); - } -} -''' - self.do_run(src, 'magic2') + self.do_run_from_file(src, output) def test_jansson(self): return self.skip('currently broken') |