Skip to content

Commit e98561b

Browse files
authored
Convert all sdl tests to btest_exit. NFC (#17467)
1 parent b66f170 commit e98561b

35 files changed

+218
-296
lines changed

tests/sdl2_audio_beep.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ void nextTest(void *unused = 0) {
177177
printf("All tests done. Quit.\n");
178178
#ifdef __EMSCRIPTEN__
179179
emscripten_cancel_main_loop();
180-
#ifdef REPORT_RESULT
181-
REPORT_RESULT(1);
182-
#endif
183180
#endif
184181
return;
185182
}
@@ -236,7 +233,10 @@ int main(int argc, char** argv) {
236233
SDL_Init(SDL_INIT_AUDIO);
237234

238235
nextTest();
239-
236+
237+
if (!beep)
238+
return 1;
239+
240240
#ifdef __EMSCRIPTEN__
241241
emscripten_set_main_loop(update, 60, 0);
242242
#else

tests/sdl2_canvas_size.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ int main(int argc, char *argv[])
5252

5353
SDL_DestroyWindow(window);
5454
SDL_Quit();
55-
REPORT_RESULT(1);
5655

5756
return 0;
5857
}

tests/sdl2_canvas_write.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// University of Illinois/NCSA Open Source License. Both these licenses can be
44
// found in the LICENSE file.
55

6+
#include <assert.h>
67
#include <SDL.h>
78
#include <emscripten.h>
89

@@ -32,7 +33,7 @@ void draw(SDL_Window *window, SDL_Surface *surface) {
3233
sdlError("SDL_UpdateWindowSurface");
3334
}
3435

35-
int verify(void) {
36+
void verify(void) {
3637
int res = EM_ASM_INT({
3738
var ctx = Module['canvas'].getContext('2d');
3839
var data = ctx.getImageData(0, 0, 256, 256).data;
@@ -52,7 +53,7 @@ int verify(void) {
5253
});
5354

5455
printf("%s\n", res ? "FAIL" : "PASS");
55-
return res;
56+
assert(res == 0);
5657
}
5758

5859
int main(void) {
@@ -71,7 +72,6 @@ int main(void) {
7172

7273
draw(window, surface);
7374

74-
int result = verify();
75-
REPORT_RESULT(result);
75+
verify();
76+
return 0;
7677
}
77-

tests/sdl2_custom_cursor.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ int main(int argc, char *argv[])
5050

5151
SDL_DestroyWindow(window);
5252
SDL_Quit();
53-
REPORT_RESULT(1);
5453

5554
return 0;
5655
}

tests/sdl2_gl_read.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ void Verify() {
141141
ok = ok && (data[x*4+0] == 0);
142142
ok = ok && (data[x*4+1] == 0);
143143
}
144-
int result = seen && ok;
145-
REPORT_RESULT(result);
144+
assert(seen);
145+
assert(ok);
146146
}
147147

148148
int main(int argc, char *argv[])

tests/sdl2_image.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main() {
6363

6464
int result = 0;
6565

66-
result |= testImage(renderer, SCREENSHOT_DIRNAME "/" SCREENSHOT_BASENAME); // absolute path
66+
result = testImage(renderer, SCREENSHOT_DIRNAME "/" SCREENSHOT_BASENAME); // absolute path
6767
assert(result != 0);
6868

6969
chdir(SCREENSHOT_DIRNAME);
@@ -76,8 +76,6 @@ int main() {
7676

7777
SDL_Quit();
7878

79-
REPORT_RESULT(result);
80-
81-
return 0;
79+
return result;
8280
}
8381

tests/sdl2_key.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int result = 1;
1313

1414
int EventHandler(void *userdata, SDL_Event *event) {
1515
int mod;
16-
16+
1717
switch(event->type) {
1818
case SDL_KEYUP:
1919
break;
@@ -29,9 +29,8 @@ int EventHandler(void *userdata, SDL_Event *event) {
2929
printf("b scancode\n"); result *= 23; break;
3030
}
3131
printf("unknown key: sym %d scancode %d\n", event->key.keysym.sym, event->key.keysym.scancode);
32-
REPORT_RESULT(result);
33-
emscripten_run_script("throw 'done'"); // comment this out to leave event handling active. Use the following to log DOM keys:
34-
// addEventListener('keyup', function(event) { console.log(event->keyCode) }, true)
32+
emscripten_force_exit(result); // comment this out to leave event handling active. Use the following to log DOM keys:
33+
// addEventListener('keyup', function(event) { console.log(event->keyCode) }, true)
3534
}
3635
}
3736
break;
@@ -78,6 +77,7 @@ int main(int argc, char **argv) {
7877
emscripten_run_script("keydown(66);keyup(66);"); // b
7978
emscripten_run_script("keydown(100);keyup(100);"); // trigger the end
8079

81-
return 0;
80+
emscripten_exit_with_live_runtime();
81+
return 99;
8282
}
8383

tests/sdl2_misc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
#include <emscripten.h>
1515

16-
#include "report_result.h"
17-
1816
int main(int argc, char *argv[])
1917
{
2018
SDL_Window *window;

tests/sdl2_mixer_music.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ void main2()
1414
emscripten_cancel_main_loop();
1515
Mix_FreeMusic(music);
1616
Mix_CloseAudio();
17-
#ifdef REPORT_RESULT
18-
REPORT_RESULT(1);
19-
#endif
17+
emscripten_force_exit(0);
2018
}
2119

2220
int main(int argc, char* argv[])

tests/sdl2_mouse.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <assert.h>
1111
#include <emscripten.h>
1212

13-
int result = 1;
1413
int mouse_motions = 0;
1514

1615
#define abs(x) ((x) < 0 ? -(x) : (x))
@@ -45,8 +44,7 @@ void one() {
4544
case SDL_MOUSEBUTTONDOWN: {
4645
SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event;
4746
if (m->button == 2) {
48-
REPORT_RESULT(result);
49-
emscripten_run_script("throw 'done'");
47+
emscripten_force_exit(0);
5048
}
5149
printf("button down : %d,%d %d,%d\n", m->button, m->state, m->x, m->y);
5250
#ifdef TEST_SDL_MOUSE_OFFSETS
@@ -88,7 +86,7 @@ int main() {
8886

8987
emscripten_async_call(main_2, NULL, 3000); // avoid startup delays and intermittent errors
9088

91-
return 0;
89+
return 99;
9290
}
9391

9492
void main_2(void* arg) {

0 commit comments

Comments
 (0)