import BaseHTTPServer, multiprocessing, os, shutil, subprocess, unittest
from runner import BrowserCore, path_from_root
from tools.shared import *
''' Enable this code to run in another browser than webbrowser detects as default
def run_in_other_browser(url):
execute(['yourbrowser', url])
webbrowser.open_new = run_in_other_browser
'''
class browser(BrowserCore):
@staticmethod
def audio():
print
print 'Running the browser audio tests. Make sure to listen to hear the correct results!'
print
audio_test_cases = [
'test_sdl_audio',
'test_sdl_audio_mix_channels',
'test_sdl_audio_mix',
'test_sdl_audio_quickload',
'test_openal_playback',
'test_openal_buffers',
'test_freealut'
]
return unittest.TestSuite(map(browser, audio_test_cases))
@classmethod
def setUpClass(self):
super(browser, self).setUpClass()
print
print 'Running the browser tests. Make sure the browser allows popups from localhost.'
print
def test_html(self):
# test HTML generation.
self.btest('hello_world_sdl.cpp', reference='htmltest.png',
message='You should see "hello, world!" and a colored cube.')
def test_html_source_map(self):
if 'test_html_source_map' not in str(sys.argv): return self.skip('''This test
requires manual intervention; will not be run unless explicitly requested''')
cpp_file = os.path.join(self.get_dir(), 'src.cpp')
html_file = os.path.join(self.get_dir(), 'src.html')
# browsers will try to 'guess' the corresponding original line if a
# generated line is unmapped, so if we want to make sure that our
# numbering is correct, we need to provide a couple of 'possible wrong
# answers'. thus, we add some printf calls so that the cpp file gets
# multiple mapped lines. in other words, if the program consists of a
# single 'throw' statement, browsers may just map any thrown exception to
# that line, because it will be the only mapped line.
with open(cpp_file, 'w') as f:
f.write(r'''
#include <cstdio>
int main() {
printf("Starting test\n");
try {
throw 42; // line 8
} catch (int e) { }
printf("done\n");
return 0;
}
''')
# use relative paths when calling emcc, because file:// URIs can only load
# sourceContent when the maps are relative paths
Popen([PYTHON, EMCC, 'src.cpp', '-o', 'src.html', '-g4'],
cwd=self.get_dir()).communicate()
webbrowser.open_new('file://' + html_file)
print '''
Set the debugger to pause on exceptions
You should see an exception thrown at src.cpp:7.
Press any key to continue.'''
raw_input()
def build_native_lzma(self):
lzma_native = path_from_root('third_party', 'lzma.js'