diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/hello_world.js | 3 | ||||
-rw-r--r-- | tests/hello_world_sdl.cpp | 29 | ||||
-rw-r--r-- | tests/runner.py | 14 |
3 files changed, 45 insertions, 1 deletions
diff --git a/tests/hello_world.js b/tests/hello_world.js index 3fd19d53..530f5d4c 100644 --- a/tests/hello_world.js +++ b/tests/hello_world.js @@ -43,6 +43,9 @@ if (ENVIRONMENT_IS_NODE) { printErr = function(x) { console.log(x); }; + if (typeof print === 'undefined') { + print = printErr; + } read = function(url) { var xhr = new XMLHttpRequest(); diff --git a/tests/hello_world_sdl.cpp b/tests/hello_world_sdl.cpp new file mode 100644 index 00000000..a317c0c5 --- /dev/null +++ b/tests/hello_world_sdl.cpp @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <SDL/SDL.h> + + +int main() { + printf("hello, world!\n"); + + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(256, 256, 32, SDL_SWSURFACE); + + SDL_LockSurface(screen); + for (int i = 0; i < 256; i++) { + for (int j = 0; j < 256; j++) { + *((char*)screen->pixels + i*256*4 + j*4 + 0) = i; + *((char*)screen->pixels + i*256*4 + j*4 + 1) = j; + *((char*)screen->pixels + i*256*4 + j*4 + 2) = 255-i; + *((char*)screen->pixels + i*256*4 + j*4 + 3) = 255; + } + } + SDL_UnlockSurface(screen); + SDL_Flip(screen); + + printf("you should see a colored cube."); + + // SDL_Quit(); // Don't call SDL_Quit so that the canvas is not cleared + + return 0; +} + diff --git a/tests/runner.py b/tests/runner.py index e8564585..ef99a7b1 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -12,7 +12,7 @@ will use 4 processes. To install nose do something like ''' from subprocess import Popen, PIPE, STDOUT -import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, tempfile, re, difflib +import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, tempfile, re, difflib, webbrowser # Setup @@ -4963,6 +4963,18 @@ JavaScript in the final linking stage of building. # TODO: when ready, switch tools/shared building to use emcc over emmaken # TODO: add shebang to generated .js files, using JS_ENGINES[0]? #!/usr/bin/python etc + # Finally, test HTML generation. (Coincidentally we also test that compiling a .cpp works in EMCC here.) + clear() + output = Popen([EMCC, path_from_root('tests', 'hello_world_sdl.cpp'), '-o', 'something.html'], stdout=PIPE, stderr=PIPE).communicate(input) + assert len(output[0]) == 0, output[0] + assert os.path.exists('something.html'), output + webbrowser.open_new(os.path.join(self.get_dir(), 'something.html')) + print 'A web browser window should have opened a page containing the results of a part of this test.' + print 'You need to manually look at the page to see that it works ok: You should see "hello, world!" and a colored cube.' + print '(sleeping for a bit to keep the directory alive for the web browser..)' + time.sleep(5) + print '(moving on..)' + def test_eliminator(self): input = open(path_from_root('tools', 'eliminator', 'eliminator-test.js')).read() expected = open(path_from_root('tools', 'eliminator', 'eliminator-test-output.js')).read() |