diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testautomation.c')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/testautomation.c | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testautomation.c b/src/contrib/SDL-3.2.20/test/testautomation.c new file mode 100644 index 0000000..5effc8a --- /dev/null +++ b/src/contrib/SDL-3.2.20/test/testautomation.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
3 | |||
4 | This software is provided 'as-is', without any express or implied | ||
5 | warranty. In no event will the authors be held liable for any damages | ||
6 | arising from the use of this software. | ||
7 | |||
8 | Permission is granted to anyone to use this software for any purpose, | ||
9 | including commercial applications, and to alter it and redistribute it | ||
10 | freely. | ||
11 | */ | ||
12 | |||
13 | #include <stdlib.h> | ||
14 | |||
15 | #include <SDL3/SDL.h> | ||
16 | #include <SDL3/SDL_main.h> | ||
17 | #include <SDL3/SDL_test.h> | ||
18 | |||
19 | #include "testautomation_suites.h" | ||
20 | |||
21 | static SDLTest_CommonState *state; | ||
22 | static SDLTest_TestSuiteRunner *runner; | ||
23 | |||
24 | /* All test suites */ | ||
25 | static SDLTest_TestSuiteReference *testSuites[] = { | ||
26 | &audioTestSuite, | ||
27 | &clipboardTestSuite, | ||
28 | &eventsTestSuite, | ||
29 | &guidTestSuite, | ||
30 | &hintsTestSuite, | ||
31 | &intrinsicsTestSuite, | ||
32 | &joystickTestSuite, | ||
33 | &keyboardTestSuite, | ||
34 | &logTestSuite, | ||
35 | &mainTestSuite, | ||
36 | &mathTestSuite, | ||
37 | &mouseTestSuite, | ||
38 | &pixelsTestSuite, | ||
39 | &platformTestSuite, | ||
40 | &propertiesTestSuite, | ||
41 | &rectTestSuite, | ||
42 | &renderTestSuite, | ||
43 | &iostrmTestSuite, | ||
44 | &sdltestTestSuite, | ||
45 | &stdlibTestSuite, | ||
46 | &surfaceTestSuite, | ||
47 | &timeTestSuite, | ||
48 | &timerTestSuite, | ||
49 | &videoTestSuite, | ||
50 | &blitTestSuite, | ||
51 | &subsystemsTestSuite, /* run last, not interfere with other test environment */ | ||
52 | NULL | ||
53 | }; | ||
54 | |||
55 | /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | ||
56 | static void | ||
57 | quit(int rc) | ||
58 | { | ||
59 | SDLTest_DestroyTestSuiteRunner(runner); | ||
60 | SDLTest_CommonQuit(state); | ||
61 | /* Let 'main()' return normally */ | ||
62 | if (rc != 0) { | ||
63 | exit(rc); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | int main(int argc, char *argv[]) | ||
68 | { | ||
69 | int result; | ||
70 | int i, done; | ||
71 | SDL_Event event; | ||
72 | int list = 0; | ||
73 | |||
74 | /* Initialize test framework */ | ||
75 | state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO); | ||
76 | if (!state) { | ||
77 | return 1; | ||
78 | } | ||
79 | |||
80 | /* No need of windows (or update testautomation_mouse.c:mouse_getMouseFocus() */ | ||
81 | state->num_windows = 0; | ||
82 | |||
83 | runner = SDLTest_CreateTestSuiteRunner(state, testSuites); | ||
84 | |||
85 | /* Parse commandline */ | ||
86 | for (i = 1; i < argc;) { | ||
87 | int consumed; | ||
88 | |||
89 | consumed = SDLTest_CommonArg(state, i); | ||
90 | if (consumed == 0) { | ||
91 | consumed = -1; | ||
92 | |||
93 | if (SDL_strcasecmp(argv[i], "--list") == 0) { | ||
94 | consumed = 1; | ||
95 | list = 1; | ||
96 | } | ||
97 | } | ||
98 | if (consumed < 0) { | ||
99 | static const char *options[] = { | ||
100 | "[--list]", | ||
101 | NULL }; | ||
102 | SDLTest_CommonLogUsage(state, argv[0], options); | ||
103 | quit(1); | ||
104 | } | ||
105 | |||
106 | i += consumed; | ||
107 | } | ||
108 | |||
109 | /* List all suites. */ | ||
110 | if (list) { | ||
111 | int suiteCounter; | ||
112 | for (suiteCounter = 0; testSuites[suiteCounter]; ++suiteCounter) { | ||
113 | int testCounter; | ||
114 | SDLTest_TestSuiteReference *testSuite = testSuites[suiteCounter]; | ||
115 | SDL_Log("Test suite: %s", testSuite->name); | ||
116 | for (testCounter = 0; testSuite->testCases[testCounter]; ++testCounter) { | ||
117 | const SDLTest_TestCaseReference *testCase = testSuite->testCases[testCounter]; | ||
118 | SDL_Log(" test: %s%s", testCase->name, testCase->enabled ? "" : " (disabled)"); | ||
119 | } | ||
120 | } | ||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | /* Initialize common state */ | ||
125 | if (!SDLTest_CommonInit(state)) { | ||
126 | quit(2); | ||
127 | } | ||
128 | |||
129 | /* Create the windows, initialize the renderers */ | ||
130 | for (i = 0; i < state->num_windows; ++i) { | ||
131 | SDL_Renderer *renderer = state->renderers[i]; | ||
132 | SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); | ||
133 | SDL_RenderClear(renderer); | ||
134 | } | ||
135 | |||
136 | /* Call Harness */ | ||
137 | result = SDLTest_ExecuteTestSuiteRunner(runner); | ||
138 | |||
139 | /* Empty event queue */ | ||
140 | done = 0; | ||
141 | for (i = 0; i < 100; i++) { | ||
142 | while (SDL_PollEvent(&event)) { | ||
143 | SDLTest_CommonEvent(state, &event, &done); | ||
144 | } | ||
145 | SDL_Delay(10); | ||
146 | } | ||
147 | |||
148 | /* Shutdown everything */ | ||
149 | quit(0); | ||
150 | return result; | ||
151 | } | ||