diff options
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index 8d1f0674..a55b5ff5 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7883,6 +7883,189 @@ elif 'browser' in str(sys.argv): finally: os.chdir(cwd) + def test_split(self): + # test HTML generation. + self.reftest(path_from_root('tests', 'htmltest.png')) + output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_sdl.cpp'), '-o', 'something.js', '--split', '100']).communicate() + assert os.path.exists(os.path.join(self.get_dir(), 'something.js')), 'must be side js' + assert os.path.exists(os.path.join(self.get_dir(), 'something_functions.js')), 'must be side js' + assert os.path.exists(os.path.join(self.get_dir(), 'something.include.html')), 'must be side js' + + open(os.path.join(self.get_dir(), 'something.html'), 'w').write(''' + + <!doctype html> + <html lang="en-us"> + <head> + <meta charset="utf-8"> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title>Emscripten-Generated Code</title> + <style> + .emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; } + canvas.emscripten { border: 1px solid black; } + textarea.emscripten { font-family: monospace; width: 80%; } + div.emscripten { text-align: center; } + </style> + </head> + <body> + <hr/> + <div class="emscripten" id="status">Downloading...</div> + <div class="emscripten"> + <progress value="0" max="100" id="progress" hidden=1></progress> + </div> + <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas> + <hr/> + <div class="emscripten"><input type="button" value="fullscreen" onclick="Module.requestFullScreen()"></div> + <hr/> + <textarea class="emscripten" id="output" rows="8"></textarea> + <hr> + <script type='text/javascript'> + // connect to canvas + var Module = { + preRun: [], + postRun: [], + print: (function() { + var element = document.getElementById('output'); + element.value = ''; // clear browser cache + return function(text) { + // These replacements are necessary if you render to raw HTML + //text = text.replace(/&/g, "&"); + //text = text.replace(/</g, "<"); + //text = text.replace(/>/g, ">"); + //text = text.replace('\\n', '<br>', 'g'); + element.value += text + "\\n"; + element.scrollTop = 99999; // focus on bottom + }; + })(), + printErr: function(text) { + if (0) { // XXX disabled for safety typeof dump == 'function') { + dump(text + '\\n'); // fast, straight to the real console + } else { + console.log(text); + } + }, + canvas: document.getElementById('canvas'), + setStatus: function(text) { + if (Module.setStatus.interval) clearInterval(Module.setStatus.interval); + var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); + var statusElement = document.getElementById('status'); + var progressElement = document.getElementById('progress'); + if (m) { + text = m[1]; + progressElement.value = parseInt(m[2])*100; + progressElement.max = parseInt(m[4])*100; + progressElement.hidden = false; + } else { + progressElement.value = null; + progressElement.max = null; + progressElement.hidden = true; + } + statusElement.innerHTML = text; + }, + totalDependencies: 0, + monitorRunDependencies: function(left) { + this.totalDependencies = Math.max(this.totalDependencies, left); + Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); + } + }; + Module.setStatus('Downloading...'); + </script>''' + open(os.path.join(self.get_dir(), 'something.include.html')).read() + ''' + </body> + </html> + ''') + + self.run_browser('something.html', 'You should see "hello, world!" and a colored cube.', '/report_result?0') + + def test_split_in_source_filenames(self): + self.reftest(path_from_root('tests', 'htmltest.png')) + output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_sdl.cpp'), '-o', 'something.js', '-g', '--split', '100']).communicate() + assert os.path.exists(os.path.join(self.get_dir(), 'something.js')), 'must be side js' + assert os.path.exists(self.get_dir() + '/something/' + path_from_root('tests', 'hello_world_sdl.cpp.js')), 'must be side js' + assert os.path.exists(os.path.join(self.get_dir(), 'something.include.html')), 'must be side js' + + open(os.path.join(self.get_dir(), 'something.html'), 'w').write(''' + + <!doctype html> + <html lang="en-us"> + <head> + <meta charset="utf-8"> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title>Emscripten-Generated Code</title> + <style> + .emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; } + canvas.emscripten { border: 1px solid black; } + textarea.emscripten { font-family: monospace; width: 80%; } + div.emscripten { text-align: center; } + </style> + </head> + <body> + <hr/> + <div class="emscripten" id="status">Downloading...</div> + <div class="emscripten"> + <progress value="0" max="100" id="progress" hidden=1></progress> + </div> + <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas> + <hr/> + <div class="emscripten"><input type="button" value="fullscreen" onclick="Module.requestFullScreen()"></div> + <hr/> + <textarea class="emscripten" id="output" rows="8"></textarea> + <hr> + <script type='text/javascript'> + // connect to canvas + var Module = { + preRun: [], + postRun: [], + print: (function() { + var element = document.getElementById('output'); + element.value = ''; // clear browser cache + return function(text) { + // These replacements are necessary if you render to raw HTML + //text = text.replace(/&/g, "&"); + //text = text.replace(/</g, "<"); + //text = text.replace(/>/g, ">"); + //text = text.replace('\\n', '<br>', 'g'); + element.value += text + "\\n"; + element.scrollTop = 99999; // focus on bottom + }; + })(), + printErr: function(text) { + if (0) { // XXX disabled for safety typeof dump == 'function') { + dump(text + '\\n'); // fast, straight to the real console + } else { + console.log(text); + } + }, + canvas: document.getElementById('canvas'), + setStatus: function(text) { + if (Module.setStatus.interval) clearInterval(Module.setStatus.interval); + var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); + var statusElement = document.getElementById('status'); + var progressElement = document.getElementById('progress'); + if (m) { + text = m[1]; + progressElement.value = parseInt(m[2])*100; + progressElement.max = parseInt(m[4])*100; + progressElement.hidden = false; + } else { + progressElement.value = null; + progressElement.max = null; + progressElement.hidden = true; + } + statusElement.innerHTML = text; + }, + totalDependencies: 0, + monitorRunDependencies: function(left) { + this.totalDependencies = Math.max(this.totalDependencies, left); + Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); + } + }; + Module.setStatus('Downloading...'); + </script>''' + open(os.path.join(self.get_dir(), 'something.include.html')).read() + ''' + </body> + </html> + ''') + + self.run_browser('something.html', 'You should see "hello, world!" and a colored cube.', '/report_result?0') + def test_compression(self): open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(self.with_report_result(r''' #include <stdio.h> |