Debian Codegraph @

test/testautomation.c

raw
1 /*
2 Copyright (C) 1997-2026 Sam Lantinga <[email protected]>
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 #include <stdio.h>
15 #include <time.h>
16
17 #include "SDL.h"
18 #include "SDL_test.h"
19
20 #include "testautomation_suites.h"
21
22 static SDLTest_CommonState *state;
23
24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
25 static void
26 quit(int rc)
27 {
28 SDLTest_CommonQuit(state);
29 exit(rc);
30 }
31
32 int main(int argc, char *argv[])
33 {
34 int result;
35 int testIterations = 1;
36 Uint64 userExecKey = 0;
37 char *userRunSeed = NULL;
38 char *filter = NULL;
39 int i, done;
40 SDL_Event event;
41
42 /* Initialize test framework */
43 state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
44 if (!state) {
45 return 1;
46 }
47
48 /* No need of windows (or update testautomation_mouse.c:mouse_getMouseFocus() */
49 state->num_windows = 0;
50
51 /* Parse commandline */
52 for (i = 1; i < argc;) {
53 int consumed;
54
55 consumed = SDLTest_CommonArg(state, i);
56 if (consumed == 0) {
57 consumed = -1;
58 if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
59 if (argv[i + 1]) {
60 testIterations = SDL_atoi(argv[i + 1]);
61 if (testIterations < 1) {
62 testIterations = 1;
63 }
64 consumed = 2;
65 }
66 } else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
67 if (argv[i + 1]) {
68 (void)SDL_sscanf(argv[i + 1], "%" SDL_PRIu64, &userExecKey);
69 consumed = 2;
70 }
71 } else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
72 if (argv[i + 1]) {
73 userRunSeed = SDL_strdup(argv[i + 1]);
74 consumed = 2;
75 }
76 } else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
77 if (argv[i + 1]) {
78 filter = SDL_strdup(argv[i + 1]);
79 consumed = 2;
80 }
81 }
82 }
83 if (consumed < 0) {
84 static const char *options[] = { "[--iterations #]", "[--execKey #]", "[--seed string]", "[--filter suite_name|test_name]", NULL };
85 SDLTest_CommonLogUsage(state, argv[0], options);
86 quit(1);
87 }
88
89 i += consumed;
90 }
91
92 /* Initialize common state */
93 if (!SDLTest_CommonInit(state)) {
94 quit(2);
95 }
96
97 /* Create the windows, initialize the renderers */
98 for (i = 0; i < state->num_windows; ++i) {
99 SDL_Renderer *renderer = state->renderers[i];
100 SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
101 SDL_RenderClear(renderer);
102 }
103
104 /* Call Harness */
105 result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations);
106
107 /* Empty event queue */
108 done = 0;
109 for (i = 0; i < 100; i++) {
110 while (SDL_PollEvent(&event)) {
111 SDLTest_CommonEvent(state, &event, &done);
112 }
113 SDL_Delay(10);
114 }
115
116 /* Clean up */
117 SDL_free(userRunSeed);
118 SDL_free(filter);
119
120 /* Shutdown everything */
121 quit(result);
122 return result;
123 }
124
125 /* vi: set ts=4 sw=4 expandtab: */