This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
testsdl.c
145 lines (121 loc) · 3.41 KB
/
testsdl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* SDL test suite framework code.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL_at.h"
#include "platform/platform.h"
#include "rwops/rwops.h"
#include "surface/surface.h"
#include "render/render.h"
#include <stdio.h> /* printf */
#include <stdlib.h> /* exit */
#include <unistd.h> /* getopt */
#include <getopt.h> /* getopt_long */
#include <string.h> /* strcmp */
/*
* Tests to run.
*/
static int run_manual = 0; /**< Run manual tests. */
/* Manual. */
/* Automatic. */
static int run_platform = 1; /**< Run platform tests. */
static int run_rwops = 1; /**< Run RWops tests. */
static int run_surface = 1; /**< Run surface tests. */
static int run_render = 1; /**< Run render tests. */
/*
* Prototypes.
*/
static void print_usage( const char *name );
static void parse_options( int argc, char *argv[] );
/**
* @brief Displays program usage.
*/
static void print_usage( const char *name )
{
printf("Usage: %s [OPTIONS]\n", name);
printf("Options are:\n");
printf(" --manual enables tests that require user interaction\n");
printf(" --noplatform do not run the platform tests\n");
printf(" --norwops do not run the rwops tests\n");
printf(" --nosurface do not run the surface tests\n");
printf(" --norender do not run the render tests\n");
printf(" -v, --verbose increases verbosity level by 1 for each -v\n");
printf(" -q, --quiet only displays errors\n");
printf(" -h, --help display this message and exit\n");
}
/**
* @brief Handles the options.
*/
static void parse_options( int argc, char *argv[] )
{
static struct option long_options[] = {
{ "manual", no_argument, 0, 0 },
{ "noplatform", no_argument, 0, 0 },
{ "norwops", no_argument, 0, 0 },
{ "nosurface", no_argument, 0, 0 },
{ "norender", no_argument, 0, 0 },
{ "verbose", no_argument, 0, 'v' },
{ "quiet", no_argument, 0, 'q' },
{ "help", no_argument, 0, 'h' },
{NULL,0,0,0}
};
int option_index = 0;
int c = 0;
int i;
const char *str;
/* Iterate over options. */
while ((c = getopt_long( argc, argv,
"vqh",
long_options, &option_index)) != -1) {
/* Handle options. */
switch (c) {
case 0:
str = long_options[option_index].name;
if (strcmp(str,"noplatform")==0)
run_platform = 0;
else if (strcmp(str,"norwops")==0)
run_rwops = 0;
else if (strcmp(str,"nosurface")==0)
run_surface = 0;
else if (strcmp(str,"norender")==0)
run_render = 0;
break;
/* Verbosity. */
case 'v':
SDL_ATgeti( SDL_AT_VERBOSE, &i );
SDL_ATseti( SDL_AT_VERBOSE, i+1 );
break;
/* Quiet. */
case 'q':
SDL_ATseti( SDL_AT_QUIET, 1 );
break;
/* Help. */
case 'h':
print_usage( argv[0] );
exit(EXIT_SUCCESS);
}
}
}
/**
* @brief Main entry point.
*/
int main( int argc, char *argv[] )
{
parse_options( argc, argv );
/* Automatic tests. */
if (run_platform)
test_platform();
if (run_rwops)
test_rwops();
if (run_surface)
test_surface();
if (run_render)
test_render();
/* Manual tests. */
if (run_manual) {
}
return 0;
}