This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
testautomation.c
129 lines (110 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "SDL.h"
#include "SDL_test.h"
20
#include "testautomation_suites.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
static SDLTest_CommonState *state;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDLTest_CommonQuit(state);
exit(rc);
}
int
main(int argc, char *argv[])
{
int result;
36
37
38
int testIterations = 1;
Uint64 userExecKey = 0;
char *userRunSeed = NULL;
39
char *filter = NULL;
40
41
int i, done;
SDL_Event event;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return 1;
}
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
consumed = -1;
56
if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
57
if (argv[i + 1]) {
58
59
testIterations = SDL_atoi(argv[i + 1]);
if (testIterations < 1) testIterations = 1;
60
consumed = 2;
63
64
else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
if (argv[i + 1]) {
65
SDL_sscanf(argv[i + 1], "%llu", (long long unsigned int *)&userExecKey);
66
consumed = 2;
69
70
71
72
73
else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
if (argv[i + 1]) {
userRunSeed = SDL_strdup(argv[i + 1]);
consumed = 2;
}
75
76
77
78
79
else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
if (argv[i + 1]) {
filter = SDL_strdup(argv[i + 1]);
consumed = 2;
}
81
82
83
}
if (consumed < 0) {
fprintf(stderr,
84
"Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
85
86
87
argv[0], SDLTest_CommonUsage(state));
quit(1);
}
89
90
91
i += consumed;
}
92
/* Initialize common state */
93
94
95
96
97
98
99
100
101
102
103
104
if (!SDLTest_CommonInit(state)) {
quit(2);
}
/* Create the windows, initialize the renderers */
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
}
/* Call Harness */
105
result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
107
/* Empty event queue */
108
109
110
111
112
113
114
115
done = 0;
for (i=0; i<100; i++) {
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
}
SDL_Delay(10);
}
116
117
118
119
/* Clean up */
if (userRunSeed != NULL) {
SDL_free(userRunSeed);
}
120
121
122
if (filter != NULL) {
SDL_free(filter);
}
124
/* Shutdown everything */
125
quit(result);
126
127
128
129
return(result);
}
/* vi: set ts=4 sw=4 expandtab: */