Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
173 lines (142 loc) · 3.14 KB

File metadata and controls

173 lines (142 loc) · 3.14 KB
 
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
/*
* Common code for automated test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL_at.h"
#include <stdio.h>
#include <stdarg.h>
/*
* Internal usage SDL_AT variables.
*/
static const char *at_suite_msg = NULL; /**< Testsuite message. */
static const char *at_test_msg = NULL; /**< Testcase message. */
static int at_success = 0; /**< Number of successful testcases. */
static int at_failure = 0; /**< Number of failed testcases. */
/**
* @brief Cleans up the automated testsuite state.
*/
static void SDL_ATcleanup (void)
{
at_suite_msg = NULL;
at_test_msg = NULL;
at_success = 0;
at_failure = 0;
}
/**
* @brief Begin testsuite.
*/
void SDL_ATinit( const char *suite )
{
/* Do not open twice. */
if (at_suite_msg) {
SDL_ATprint( "AT suite '%s' not closed before opening suite '%s'\n",
at_suite_msg, suite );
}
/* Must have a name. */
if (suite == NULL) {
SDL_ATprint( "AT testsuite does not have a name.\n");
}
SDL_ATcleanup();
at_suite_msg = suite;
}
/**
* @brief Finish testsuite.
*/
int SDL_ATfinish( int verbose )
{
int failed;
/* Make sure initialized. */
if (at_suite_msg == NULL) {
SDL_ATprint("Ended testcase without initializing.\n");
Jul 9, 2009
Jul 9, 2009
66
return 1;
67
68
69
70
71
72
73
}
/* Display message if verbose on failed. */
failed = at_failure;
if (verbose) {
if (at_failure > 0) {
SDL_ATprint( "%s : Failed %d out of %d testcases!\n",
Jun 20, 2009
Jun 20, 2009
74
at_suite_msg, at_failure, at_failure+at_success );
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
}
else {
SDL_ATprint( "%s : All tests successful (%d)\n",
at_suite_msg, at_success );
}
}
/* Clean up. */
SDL_ATcleanup();
/* Return failed. */
return failed;
}
/**
* @brief Begin testcase.
*/
void SDL_ATbegin( const char *testcase )
{
/* Do not open twice. */
if (at_test_msg) {
Jun 20, 2009
Jun 20, 2009
97
SDL_ATprint( "AT testcase '%s' not closed before opening testcase '%s'\n",
98
99
100
101
at_test_msg, testcase );
}
/* Must have a name. */
if (testcase == NULL) {
Jun 20, 2009
Jun 20, 2009
102
SDL_ATprint( "AT testcase does not have a name.\n");
103
104
105
106
107
108
109
110
111
112
113
114
}
at_test_msg = testcase;
}
/**
* @brief Ends the testcase with a succes or failure.
*/
static void SDL_ATendWith( int success )
{
/* Make sure initialized. */
if (at_test_msg == NULL) {
Jun 20, 2009
Jun 20, 2009
115
SDL_ATprint("Ended testcase without initializing.\n");
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
return;
}
/* Mark as success or failure. */
if (success)
at_success++;
else
at_failure++;
/* Clean up. */
at_test_msg = NULL;
}
/**
* @brief Testcase test.
*/
int SDL_ATassert( const char *msg, int condition )
{
/* Condition failed. */
if (!condition) {
Jun 20, 2009
Jun 20, 2009
137
SDL_ATprint( "%s [%s] : %s\n", at_suite_msg, at_test_msg, msg );
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
SDL_ATendWith(0);
}
return !condition;
}
/**
* @brief End testcase.
*/
void SDL_ATend (void)
{
SDL_ATendWith(1);
}
/**
* @brief Displays a message.
*/
int SDL_ATprint( const char *msg, ... )
{
va_list ap;
int ret;
/* Make sure there is something to print. */
if (msg == NULL)
Jul 9, 2009
Jul 9, 2009
163
return 0;
164
165
166
167
168
169
170
171
else {
va_start(ap, msg);
ret = vprintf(msg, ap);
va_end(ap);
}
return ret;
}