aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJez Ng <me@jezng.com>2013-06-17 18:00:44 -0700
committerJez Ng <me@jezng.com>2013-06-17 18:30:43 -0700
commit83d1e40dc67587c0eee1a5103ee51cfc435aa91d (patch)
tree2cdef0c4a216a38526dd58f9d472404cdcdc27f4 /tests
parent31f73d04a0f1120746e40b7a35b5d609dbc598ab (diff)
Fix SDL color encoding.
Little-endian + RGBA means that red is located at the lowest-order bits, not the highest. The hello_world_sdl test is now portable, because we no longer write to individual bytes. We also add a test for a completely blank screen, which should be black, not red. Closes #1287, #761, #765.
Diffstat (limited to 'tests')
-rw-r--r--tests/hello_world_sdl.cpp8
-rwxr-xr-xtests/runner.py3
-rw-r--r--tests/sdl_canvas_blank.c17
-rw-r--r--tests/sdl_canvas_blank.pngbin0 -> 914 bytes
4 files changed, 23 insertions, 5 deletions
diff --git a/tests/hello_world_sdl.cpp b/tests/hello_world_sdl.cpp
index b6401995..eeaad0cd 100644
--- a/tests/hello_world_sdl.cpp
+++ b/tests/hello_world_sdl.cpp
@@ -2,7 +2,7 @@
#include <SDL/SDL.h>
-int main() {
+extern "C" int main(int argc, char** argv) {
printf("hello, world!\n");
SDL_Init(SDL_INIT_VIDEO);
@@ -11,10 +11,8 @@ int main() {
if (SDL_MUSTLOCK(screen)) 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) = (i+j)%255; // actually ignored, since this is to the screen
+ // alpha component is actually ignored, since this is to the screen
+ *((Uint32*)screen->pixels + i * 256 + j) = SDL_MapRGBA(screen->format, i, j, 255-i, (i+j) % 255);
}
}
if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
diff --git a/tests/runner.py b/tests/runner.py
index e7434479..4b8a3010 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -12735,6 +12735,9 @@ elif 'browser' in str(sys.argv):
def test_cube_explosion(self):
self.btest('cube_explosion.c', expected=['667220544', '-1543354600', '-1485258415'])
+ def test_sdl_canvas_blank(self):
+ self.btest('sdl_canvas_blank.c', reference='sdl_canvas_blank.png')
+
def test_sdl_canvas_palette(self):
self.btest('sdl_canvas_palette.c', reference='sdl_canvas_palette.png')
diff --git a/tests/sdl_canvas_blank.c b/tests/sdl_canvas_blank.c
new file mode 100644
index 00000000..0e7607a6
--- /dev/null
+++ b/tests/sdl_canvas_blank.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <SDL/SDL.h>
+
+
+int main() {
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Surface *screen = SDL_SetVideoMode(256, 256, 32, SDL_SWSURFACE);
+
+ if (SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
+ if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
+ SDL_Flip(screen);
+
+ SDL_Quit();
+
+ return 0;
+}
+
diff --git a/tests/sdl_canvas_blank.png b/tests/sdl_canvas_blank.png
new file mode 100644
index 00000000..dc5a4a26
--- /dev/null
+++ b/tests/sdl_canvas_blank.png
Binary files differ