comparison test/automated/testsdl.c @ 3259:22ac66da0765

Merged Edgar's code changes from Google Summer of Code 2009
author Sam Lantinga <slouken@libsdl.org>
date Mon, 07 Sep 2009 05:06:34 +0000
parents
children 63d4517fc4ac
comparison
equal deleted inserted replaced
3258:e786366ea23b 3259:22ac66da0765
1 /*
2 * SDL test suite framework code.
3 *
4 * Written by Edgar Simo "bobbens"
5 *
6 * Released under Public Domain.
7 */
8
9
10 #include "SDL.h"
11 #include "SDL_at.h"
12
13 #include "platform/platform.h"
14 #include "rwops/rwops.h"
15 #include "surface/surface.h"
16 #include "render/render.h"
17 #include "audio/audio.h"
18
19 #include <stdio.h> /* printf */
20 #include <stdlib.h> /* exit */
21 #include <unistd.h> /* getopt */
22 #include <getopt.h> /* getopt_long */
23 #include <string.h> /* strcmp */
24
25
26 /*
27 * Tests to run.
28 */
29 static int run_manual = 0; /**< Run manual tests. */
30 /* Manual. */
31 /* Automatic. */
32 static int run_platform = 1; /**< Run platform tests. */
33 static int run_rwops = 1; /**< Run RWops tests. */
34 static int run_surface = 1; /**< Run surface tests. */
35 static int run_render = 1; /**< Run render tests. */
36 static int run_audio = 1; /**< Run audio tests. */
37
38 /*
39 * Prototypes.
40 */
41 static void print_usage( const char *name );
42 static void parse_options( int argc, char *argv[] );
43
44
45 /**
46 * @brief Displays program usage.
47 */
48 static void print_usage( const char *name )
49 {
50 printf("Usage: %s [OPTIONS]\n", name);
51 printf("Options are:\n");
52 printf(" -m, --manual enables tests that require user interaction\n");
53 printf(" --noplatform do not run the platform tests\n");
54 printf(" --norwops do not run the rwops tests\n");
55 printf(" --nosurface do not run the surface tests\n");
56 printf(" --norender do not run the render tests\n");
57 printf(" --noaudio do not run the audio tests\n");
58 printf(" -v, --verbose increases verbosity level by 1 for each -v\n");
59 printf(" -q, --quiet only displays errors\n");
60 printf(" -h, --help display this message and exit\n");
61 }
62
63
64 /**
65 * @brief Handles the options.
66 */
67 static void parse_options( int argc, char *argv[] )
68 {
69 static struct option long_options[] = {
70 { "manual", no_argument, 0, 'm' },
71 { "noplatform", no_argument, 0, 0 },
72 { "norwops", no_argument, 0, 0 },
73 { "nosurface", no_argument, 0, 0 },
74 { "norender", no_argument, 0, 0 },
75 { "noaudio", no_argument, 0, 0 },
76 { "verbose", no_argument, 0, 'v' },
77 { "quiet", no_argument, 0, 'q' },
78 { "help", no_argument, 0, 'h' },
79 {NULL,0,0,0}
80 };
81 int option_index = 0;
82 int c = 0;
83 int i;
84 const char *str;
85
86 /* Iterate over options. */
87 while ((c = getopt_long( argc, argv,
88 "vqh",
89 long_options, &option_index)) != -1) {
90
91 /* Handle options. */
92 switch (c) {
93 case 0:
94 str = long_options[option_index].name;
95 if (strcmp(str,"noplatform")==0)
96 run_platform = 0;
97 else if (strcmp(str,"norwops")==0)
98 run_rwops = 0;
99 else if (strcmp(str,"nosurface")==0)
100 run_surface = 0;
101 else if (strcmp(str,"norender")==0)
102 run_render = 0;
103 else if (strcmp(str,"noaudio")==0)
104 run_audio = 0;
105 break;
106
107 /* Manual. */
108 case 'm':
109 run_manual = 1;
110 break;
111
112 /* Verbosity. */
113 case 'v':
114 SDL_ATgeti( SDL_AT_VERBOSE, &i );
115 SDL_ATseti( SDL_AT_VERBOSE, i+1 );
116 break;
117
118 /* Quiet. */
119 case 'q':
120 SDL_ATseti( SDL_AT_QUIET, 1 );
121 break;
122
123 /* Help. */
124 case 'h':
125 print_usage( argv[0] );
126 exit(EXIT_SUCCESS);
127 }
128 }
129
130 }
131
132
133 /**
134 * @brief Main entry point.
135 */
136 int main( int argc, char *argv[] )
137 {
138 int failed;
139 int rev;
140 SDL_version ver;
141
142 /* Get options. */
143 parse_options( argc, argv );
144
145 /* Defaults. */
146 failed = 0;
147
148 /* Print some text if verbose. */
149 SDL_GetVersion( &ver );
150 rev = SDL_GetRevision();
151 SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
152 ver.major, ver.minor, ver.patch, rev );
153
154 /* Automatic tests. */
155 if (run_platform)
156 failed += test_platform();
157 if (run_rwops)
158 failed += test_rwops();
159 if (run_surface)
160 failed += test_surface();
161 if (run_render)
162 failed += test_render();
163 if (run_audio)
164 failed += test_audio();
165
166 /* Manual tests. */
167 if (run_manual) {
168 }
169
170 /* Display more information if failed. */
171 if (failed > 0) {
172 SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
173 ver.major, ver.minor, ver.patch, rev );
174 SDL_ATprintErr( "System is running %s and is %s endian\n",
175 platform_getPlatform(),
176 #ifdef SDL_LIL_ENDIAN
177 "little"
178 #else
179 "big"
180 #endif
181 );
182 }
183
184 return failed;
185 }
186