diff options
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/tests/runner.py b/tests/runner.py index fc41c8a1..a4b396f2 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7142,6 +7142,10 @@ def process(filename): ''' self.do_run(src, 'written=0') + def test_fgetc_ungetc(self): + src = open(path_from_root('tests', 'stdio', 'test_fgetc_ungetc.c'), 'r').read() + self.do_run(src, 'success', force_c=True) + def test_fgetc_unsigned(self): if self.emcc_args is None: return self.skip('requires emcc') src = r''' @@ -9524,7 +9528,10 @@ def process(filename): c2.virtualFunc2(); Module.print('*ok*'); ''' - src = open(filename, 'a') + code = open(filename).read() + src = open(filename, 'w') + src.write('var Module = {};\n') # name Module + src.write(code) src.write(script_src_2 + '\n') src.close() @@ -11027,6 +11034,23 @@ f.close() std::string side() { return "and hello from side"; } ''', ['hello from main and hello from side\n']) + # followup to iostream test: a second linking + print 'second linking of a linking output' + open('moar.cpp', 'w').write(r''' + #include <iostream> + struct Moar { + Moar() { std::cout << "moar!" << std::endl; } + }; + Moar m; + ''') + Popen([PYTHON, EMCC, 'moar.cpp', '-o', 'moar.js', '-s', 'SIDE_MODULE=1', '-O2']).communicate() + Popen([PYTHON, EMLINK, 'together.js', 'moar.js', 'triple.js'], stdout=PIPE).communicate() + assert os.path.exists('triple.js') + for engine in JS_ENGINES: + out = run_js('triple.js', engine=engine, stderr=PIPE, full_output=True) + self.assertContained('moar!\nhello from main and hello from side\n', out) + if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) + # zlib compression library. tests function pointers in initializers and many other things test('zlib', '', open(path_from_root('tests', 'zlib', 'example.c'), 'r').read(), self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']), @@ -11223,6 +11247,45 @@ f.close() self.assertContained('libf1\nlibf2\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_stdin(self): + open('main.cpp', 'w').write(r''' +#include <stdio.h> +int main(int argc, char const *argv[]) +{ + char str[10] = {0}; + scanf("%10s", str); + printf("%s\n", str); + return 0; +} +''') + Building.emcc('main.cpp', output_filename='a.out.js') + open('in.txt', 'w').write('abc') + # node's stdin support is broken + self.assertContained('abc', Popen(listify(SPIDERMONKEY_ENGINE) + ['a.out.js'], stdin=open('in.txt'), stdout=PIPE, stderr=PIPE).communicate()[0]) + + def test_ungetc_fscanf(self): + open('main.cpp', 'w').write(r''' + #include <stdio.h> + int main(int argc, char const *argv[]) + { + char str[4] = {0}; + FILE* f = fopen("my_test.input", "r"); + if (f == NULL) { + printf("cannot open file\n"); + return -1; + } + ungetc('x', f); + ungetc('y', f); + ungetc('z', f); + fscanf(f, "%3s", str); + printf("%s\n", str); + return 0; + } + ''') + open('my_test.input', 'w').write('abc') + Building.emcc('main.cpp', ['--embed-file', 'my_test.input'], output_filename='a.out.js') + self.assertContained('zyx', Popen(listify(JS_ENGINES[0]) + ['a.out.js'], stdout=PIPE, stderr=PIPE).communicate()[0]) + def test_abspaths(self): # Includes with absolute paths are generally dangerous, things like -I/usr/.. will get to system local headers, not our portable ones. @@ -12228,6 +12291,7 @@ elif 'browser' in str(sys.argv): basename = os.path.basename(expected) shutil.copyfile(expected, os.path.join(self.get_dir(), basename)) open(os.path.join(self.get_dir(), 'reftest.js'), 'w').write(''' + var Module = eval('Module'); function doReftest() { if (doReftest.done) return; doReftest.done = true; @@ -13523,6 +13587,9 @@ Press any key to continue.''' def test_sdl_alloctext(self): self.btest('sdl_alloctext.c', expected='1', args=['-O2', '-s', 'TOTAL_MEMORY=' + str(1024*1024*8)]) + def test_sdl_surface_refcount(self): + self.btest('sdl_surface_refcount.c', expected='1') + def test_glbegin_points(self): shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) self.btest('glbegin_points.c', reference='glbegin_points.png', args=['--preload-file', 'screenshot.png']) |