aboutsummaryrefslogtreecommitdiff
path: root/tests/runner.py
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-07-06 16:37:28 +0300
committermax99x <max99x@gmail.com>2011-07-06 16:37:28 +0300
commitdedb83b9e15591893e1b30220c721e447518f5d9 (patch)
tree87068307ade1fbcff662fcef5e943d944f4f7374 /tests/runner.py
parent13ac46b2c9be4aa17319c450a15ed96b71e091d7 (diff)
parente84f1845f1a96ecfda4f1ffc0ba2052dc7c8c86d (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'tests/runner.py')
-rw-r--r--tests/runner.py45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 88a79c73..beef1823 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -29,6 +29,7 @@ NAMESPACER = path_from_root('tools', 'namespacer.py')
EMMAKEN = path_from_root('tools', 'emmaken.py')
AUTODEBUGGER = path_from_root('tools', 'autodebugger.py')
DFE = path_from_root('tools', 'dead_function_eliminator.py')
+BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py')
# Global cache for tests (we have multiple TestCase instances; this object lets them share data)
@@ -1645,7 +1646,6 @@ if 'benchmark' not in sys.argv:
expected = open(path_from_root('tests', 'time', 'output.txt'), 'r').read()
self.do_test(src, expected)
-
def test_statics(self):
# static initializers save i16 but load i8 for some reason
global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g']
@@ -2565,7 +2565,7 @@ if 'benchmark' not in sys.argv:
### Integration tests
def test_scriptaclass(self):
- src = '''
+ header = '''
struct ScriptMe {
int value;
ScriptMe(int val);
@@ -2574,10 +2574,20 @@ if 'benchmark' not in sys.argv:
// as a library)
void mulVal(int mul);
};
+ '''
+ header_filename = os.path.join(self.get_dir(), 'header.h')
+ open(header_filename, 'w').write(header)
+
+ src = '''
+ #include "header.h"
+
ScriptMe::ScriptMe(int val) : value(val) { }
int ScriptMe::getVal() { return value; }
void ScriptMe::mulVal(int mul) { value *= mul; }
'''
+
+ # Way 1: use demangler and namespacer
+
script_src = '''
var sme = Module._.ScriptMe.__new__(83); // malloc(sizeof(ScriptMe)), ScriptMe::ScriptMe(sme, 83) / new ScriptMe(83) (at addr sme)
Module._.ScriptMe.mulVal(sme, 2); // ScriptMe::mulVal(sme, 2) sme.mulVal(2)
@@ -2596,6 +2606,37 @@ if 'benchmark' not in sys.argv:
open(filename, 'w').write(src)
self.do_test(src, '*166*\n*ok*', post_build=post)
+ # Way 2: use CppHeaderParser
+
+ basename = os.path.join(self.get_dir(), 'bindingtest')
+ Popen(['python', BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=STDOUT).communicate()[0]
+
+ src = '''
+ #include "header.h"
+
+ ScriptMe::ScriptMe(int val) : value(val) { }
+ int ScriptMe::getVal() { return value; }
+ void ScriptMe::mulVal(int mul) { value *= mul; }
+
+ #include "bindingtest.c"
+ '''
+
+ script_src_2 = '''
+ var sme = new ScriptMe(83);
+ sme.mulVal(2);
+ print('*' + sme.getVal() + '*');
+ print('*ok*');
+ '''
+
+ def post2(filename):
+ src = open(filename, 'r').read().replace(
+ '// {{MODULE_ADDITIONS}',
+ '''load('bindingtest.js')''' + '\n\n' + script_src_2 + '\n\n' +
+ '// {{MODULE_ADDITIONS}'
+ )
+ open(filename, 'w').write(src)
+ self.do_test(src, '*166*\n*ok*', post_build=post2)
+
### Tests for tools
def test_safe_heap(self):