aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/test_reinterpreted_ptrs.in41
-rw-r--r--tests/core/test_reinterpreted_ptrs.out1
-rw-r--r--tests/test_core.py45
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')