comparison test/automated/testsdl.c @ 3541:0c429a5fda8a

Added an automated test for rectangle routines, currently only testing line clipping. Use the Cohen-Sutherland algorithm for line clipping which uses integer math and preserves ordering of clipped points. Removed getopt() support in testsdl.c, replaced with simple argv scanning.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Dec 2009 09:22:34 +0000
parents 78db4f7ae2f3
children f638ded38b8a
comparison
equal deleted inserted replaced
3540:3ad09fdbfcb0 3541:0c429a5fda8a
10 #include "SDL.h" 10 #include "SDL.h"
11 #include "SDL_at.h" 11 #include "SDL_at.h"
12 12
13 #include "platform/platform.h" 13 #include "platform/platform.h"
14 #include "rwops/rwops.h" 14 #include "rwops/rwops.h"
15 #include "rect/rect.h"
15 #include "surface/surface.h" 16 #include "surface/surface.h"
16 #include "render/render.h" 17 #include "render/render.h"
17 #include "audio/audio.h" 18 #include "audio/audio.h"
18 19
19 #if defined(WIN32) 20 #if defined(WIN32)
39 static int run_manual = 0; /**< Run manual tests. */ 40 static int run_manual = 0; /**< Run manual tests. */
40 /* Manual. */ 41 /* Manual. */
41 /* Automatic. */ 42 /* Automatic. */
42 static int run_platform = 1; /**< Run platform tests. */ 43 static int run_platform = 1; /**< Run platform tests. */
43 static int run_rwops = 1; /**< Run RWops tests. */ 44 static int run_rwops = 1; /**< Run RWops tests. */
45 static int run_rect = 1; /**< Run rect tests. */
44 static int run_surface = 1; /**< Run surface tests. */ 46 static int run_surface = 1; /**< Run surface tests. */
45 static int run_render = 1; /**< Run render tests. */ 47 static int run_render = 1; /**< Run render tests. */
46 static int run_audio = 1; /**< Run audio tests. */ 48 static int run_audio = 1; /**< Run audio tests. */
47 49
48 /* 50 /*
53 55
54 56
55 /** 57 /**
56 * @brief Displays program usage. 58 * @brief Displays program usage.
57 */ 59 */
58 #ifdef NO_GETOPT
59 static void print_usage( const char *name )
60 {
61 }
62 #else
63 #if !defined(NO_GETOPT_LONG)
64 static void print_usage( const char *name ) 60 static void print_usage( const char *name )
65 { 61 {
66 printf("Usage: %s [OPTIONS]\n", name); 62 printf("Usage: %s [OPTIONS]\n", name);
67 printf("Options are:\n"); 63 printf("Options are:\n");
68 printf(" -m, --manual enables tests that require user interaction\n"); 64 printf(" -m, --manual enables tests that require user interaction\n");
69 printf(" -p, --noplatform do not run the platform tests\n"); 65 printf(" --noplatform do not run the platform tests\n");
70 printf(" -o, --norwops do not run the rwops tests\n"); 66 printf(" --norwops do not run the rwops tests\n");
71 printf(" -s, --nosurface do not run the surface tests\n"); 67 printf(" --norect do not run the rect tests\n");
72 printf(" -r, --norender do not run the render tests\n"); 68 printf(" --nosurface do not run the surface tests\n");
73 printf(" -a, --noaudio do not run the audio tests\n"); 69 printf(" --norender do not run the render tests\n");
70 printf(" --noaudio do not run the audio tests\n");
74 printf(" -v, --verbose increases verbosity level by 1 for each -v\n"); 71 printf(" -v, --verbose increases verbosity level by 1 for each -v\n");
75 printf(" -q, --quiet only displays errors\n"); 72 printf(" -q, --quiet only displays errors\n");
76 printf(" -h, --help display this message and exit\n"); 73 printf(" -h, --help display this message and exit\n");
77 } 74 }
78 #endif /* !NO_GETOPT_LONG */
79
80 #if defined(NO_GETOPT_LONG)
81 static void print_usage( const char *name )
82 {
83 printf("Usage: %s [OPTIONS]\n", name);
84 printf("Options are:\n");
85 printf(" -m, enables tests that require user interaction\n");
86 printf(" -p, do not run the platform tests\n");
87 printf(" -o, do not run the rwops tests\n");
88 printf(" -s, do not run the surface tests\n");
89 printf(" -r, do not run the render tests\n");
90 printf(" -a, do not run the audio tests\n");
91 printf(" -v, increases verbosity level by 1 for each -v\n");
92 printf(" -q, only displays errors\n");
93 printf(" -h, display this message and exit\n");
94 }
95 #endif /* NO_GETOPT_LONG */
96 #endif /* NO_GETOPT */
97 75
98 /** 76 /**
99 * @brief Handles the options. 77 * @brief Handles the options.
100 */ 78 */
101 #ifdef NO_GETOPT
102 static void parse_options( int argc, char *argv[] ) 79 static void parse_options( int argc, char *argv[] )
103 { 80 {
104 }
105 #else
106 #if !defined(NO_GETOPT_LONG)
107 static void parse_options( int argc, char *argv[] )
108 {
109 static struct option long_options[] = {
110 { "manual", no_argument, 0, 'm' },
111 { "noplatform", no_argument, 0, 'p' },
112 { "norwops", no_argument, 0, 'o' },
113 { "nosurface", no_argument, 0, 's' },
114 { "norender", no_argument, 0, 'r' },
115 { "noaudio", no_argument, 0, 'a' },
116 { "verbose", no_argument, 0, 'v' },
117 { "quiet", no_argument, 0, 'q' },
118 { "help", no_argument, 0, 'h' },
119 {NULL,0,0,0}
120 };
121 int option_index = 0;
122 int c = 0;
123 int i; 81 int i;
124 const char *str;
125 82
126 /* Iterate over options. */ 83 for (i = 1; i < argc; ++i) {
127 while ((c = getopt_long( argc, argv, 84 const char *arg = argv[i];
128 "mposravqh", 85 if (SDL_strcmp(arg, "-m") == 0 || SDL_strcmp(arg, "--manual") == 0) {
129 long_options, &option_index)) != -1) { 86 run_manual = 1;
87 continue;
88 }
89 if (SDL_strcmp(arg, "-v") == 0 || SDL_strcmp(arg, "--verbose") == 0) {
90 int level;
91 SDL_ATgeti( SDL_AT_VERBOSE, &level );
92 SDL_ATseti( SDL_AT_VERBOSE, level+1 );
93 continue;
94 }
95 if (SDL_strcmp(arg, "-q") == 0 || SDL_strcmp(arg, "--quiet") == 0) {
96 SDL_ATseti( SDL_AT_QUIET, 1 );
97 continue;
98 }
99 if (SDL_strcmp(arg, "--noplatform") == 0) {
100 run_platform = 0;
101 continue;
102 }
103 if (SDL_strcmp(arg, "--norwops") == 0) {
104 run_rwops = 0;
105 continue;
106 }
107 if (SDL_strcmp(arg, "--norect") == 0) {
108 run_rect = 0;
109 continue;
110 }
111 if (SDL_strcmp(arg, "--nosurface") == 0) {
112 run_surface = 0;
113 continue;
114 }
115 if (SDL_strcmp(arg, "--norender") == 0) {
116 run_render = 0;
117 continue;
118 }
119 if (SDL_strcmp(arg, "--noaudio") == 0) {
120 run_audio = 0;
121 continue;
122 }
130 123
131 /* Handle options. */ 124 /* Print help and exit! */
132 switch (c) { 125 print_usage( argv[0] );
133 case 0: 126 exit(EXIT_FAILURE);
134 str = long_options[option_index].name;
135 if (strcmp(str,"noplatform")==0)
136 run_platform = 0;
137 else if (strcmp(str,"norwops")==0)
138 run_rwops = 0;
139 else if (strcmp(str,"nosurface")==0)
140 run_surface = 0;
141 else if (strcmp(str,"norender")==0)
142 run_render = 0;
143 else if (strcmp(str,"noaudio")==0)
144 run_audio = 0;
145 break;
146
147 /* Manual. */
148 case 'm':
149 run_manual = 1;
150 break;
151
152 /* No platform. */
153 case 'p':
154 run_platform = 0;
155 break;
156
157 /* No rwops. */
158 case 'o':
159 run_rwops = 0;
160 break;
161
162 /* No surface. */
163 case 's':
164 run_surface = 0;
165 break;
166
167 /* No render. */
168 case 'r':
169 run_render = 0;
170 break;
171
172 /* No audio. */
173 case 'a':
174 run_audio = 0;
175 break;
176
177 /* Verbosity. */
178 case 'v':
179 SDL_ATgeti( SDL_AT_VERBOSE, &i );
180 SDL_ATseti( SDL_AT_VERBOSE, i+1 );
181 break;
182
183 /* Quiet. */
184 case 'q':
185 SDL_ATseti( SDL_AT_QUIET, 1 );
186 break;
187
188 /* Help. */
189 case 'h':
190 print_usage( argv[0] );
191 exit(EXIT_SUCCESS);
192 }
193 } 127 }
194 } 128 }
195 #endif /* !NO_GETOPT_LONG */
196
197 #if defined(NO_GETOPT_LONG)
198 static void parse_options( int argc, char *argv[] )
199 {
200 static char* short_options="mposravqh";
201 int c = 0;
202 int i;
203
204 /* Iterate over options. */
205 while ((c = getopt(argc, argv, short_options)) != -1) {
206 /* Handle options. */
207 switch (c) {
208 /* Manual. */
209 case 'm':
210 run_manual = 1;
211 break;
212
213 /* No platform. */
214 case 'p':
215 run_platform = 0;
216 break;
217
218 /* No rwops. */
219 case 'o':
220 run_rwops = 0;
221 break;
222
223 /* No surface. */
224 case 's':
225 run_surface = 0;
226 break;
227
228 /* No render. */
229 case 'r':
230 run_render = 0;
231 break;
232
233 /* No audio. */
234 case 'a':
235 run_audio = 0;
236 break;
237
238 /* Verbosity. */
239 case 'v':
240 SDL_ATgeti( SDL_AT_VERBOSE, &i );
241 SDL_ATseti( SDL_AT_VERBOSE, i+1 );
242 break;
243
244 /* Quiet. */
245 case 'q':
246 SDL_ATseti( SDL_AT_QUIET, 1 );
247 break;
248
249 /* Help. */
250 case 'h':
251 print_usage( argv[0] );
252 exit(EXIT_SUCCESS);
253 }
254 }
255 }
256 #endif /* NO_GETOPT_LONG */
257 #endif /* NO_GETOPT */
258 129
259 /** 130 /**
260 * @brief Main entry point. 131 * @brief Main entry point.
261 */ 132 */
262 int main( int argc, char *argv[] ) 133 int main( int argc, char *argv[] )
280 /* Automatic tests. */ 151 /* Automatic tests. */
281 if (run_platform) 152 if (run_platform)
282 failed += test_platform(); 153 failed += test_platform();
283 if (run_rwops) 154 if (run_rwops)
284 failed += test_rwops(); 155 failed += test_rwops();
156 if (run_rect)
157 failed += test_rect();
285 if (run_surface) 158 if (run_surface)
286 failed += test_surface(); 159 failed += test_surface();
287 if (run_render) 160 if (run_render)
288 failed += test_render(); 161 failed += test_render();
289 if (run_audio) 162 if (run_audio)