annotate test/automated/SDL_at.c @ 3748:9428ae743878 gsoc2009_unit_tests

Have SDL_ATprint just call SDL_ATprintVerbose.
author Edgar Simo <bobbens@gmail.com>
date Tue, 04 Aug 2009 17:53:20 +0000
parents be037e51f080
children f47658c8f87a
rev   line source
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
1 /*
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
2 * Common code for automated test suite.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
3 *
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
4 * Written by Edgar Simo "bobbens"
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
5 *
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
6 * Released under Public Domain.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
7 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
8
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
9
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
10 #include "SDL_at.h"
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
11
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
12 #include <stdio.h> /* printf/fprintf */
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
13 #include <stdarg.h> /* va_list */
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
14 #include <string.h> /* strdup */
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
15 #include <stdlib.h> /* free */
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
16
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
17
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
18 /*
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
19 * Internal usage SDL_AT variables.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
20 */
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
21 static char *at_suite_msg = NULL; /**< Testsuite message. */
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
22 static char *at_test_msg = NULL; /**< Testcase message. */
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
23 static int at_success = 0; /**< Number of successful testcases. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
24 static int at_failure = 0; /**< Number of failed testcases. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
25
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
26
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
27 /*
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
28 * Global properties.
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
29 */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
30 static int at_verbose = 0; /**< Verbosity. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
31 static int at_quiet = 0; /**< Quietness. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
32
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
33
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
34 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
35 * @brief Cleans up the automated testsuite state.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
36 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
37 static void SDL_ATcleanup (void)
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
38 {
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
39 if (at_suite_msg != NULL)
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
40 free(at_suite_msg);
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
41 at_suite_msg = NULL;
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
42 if (at_test_msg != NULL)
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
43 free(at_test_msg);
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
44 at_test_msg = NULL;
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
45 at_success = 0;
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
46 at_failure = 0;
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
47 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
48
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
49
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
50 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
51 * @brief Begin testsuite.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
52 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
53 void SDL_ATinit( const char *suite )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
54 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
55 /* Do not open twice. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
56 if (at_suite_msg) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
57 SDL_ATprintErr( "AT suite '%s' not closed before opening suite '%s'\n",
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
58 at_suite_msg, suite );
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
59 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
60 /* Must have a name. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
61 if (suite == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
62 SDL_ATprintErr( "AT testsuite does not have a name.\n");
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
63 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
64 SDL_ATcleanup();
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
65 at_suite_msg = strdup(suite);
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
66
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
67 /* Verbose message. */
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
68 SDL_ATprintVerbose( 2, "--+---> Started Test Suite '%s'\n", at_suite_msg );
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
69 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
70
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
71
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
72 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
73 * @brief Finish testsuite.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
74 */
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
75 int SDL_ATfinish (void)
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
76 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
77 int failed;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
78
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
79 /* Make sure initialized. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
80 if (at_suite_msg == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
81 SDL_ATprintErr("Ended testcase without initializing.\n");
3722
d8772964e402 Added more strict warning flags.
Edgar Simo <bobbens@gmail.com>
parents: 3713
diff changeset
82 return 1;
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
83 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
84
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
85 /* Finished without closing testcase. */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
86 if (at_test_msg) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
87 SDL_ATprintErr( "AT suite '%s' finished without closing testcase '%s'\n",
3727
51900b161948 Fixed accidentle broken compile.
Edgar Simo <bobbens@gmail.com>
parents: 3725
diff changeset
88 at_suite_msg, at_test_msg );
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
89 }
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
90
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
91 /* Verbose message. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
92 SDL_ATprintVerbose( 2, "<-+---- Finished Test Suite '%s'\n", at_suite_msg );
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
93
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
94 /* Display message if verbose on failed. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
95 failed = at_failure;
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
96 if (at_failure > 0) {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
97 SDL_ATprintErr( "%s : Failed %d out of %d testcases!\n",
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
98 at_suite_msg, at_failure, at_failure+at_success );
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
99 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
100 else {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
101 SDL_ATprint( "%s : All tests successful (%d)\n",
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
102 at_suite_msg, at_success );
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
103 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
104
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
105 /* Clean up. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
106 SDL_ATcleanup();
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
107
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
108 /* Return failed. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
109 return failed;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
110 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
111
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
112
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
113 /**
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
114 * @brief Sets a property.
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
115 */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
116 void SDL_ATseti( int property, int value )
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
117 {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
118 switch (property) {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
119 case SDL_AT_VERBOSE:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
120 at_verbose = value;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
121 break;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
122
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
123 case SDL_AT_QUIET:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
124 at_quiet = value;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
125 break;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
126 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
127 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
128
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
129
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
130 /**
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
131 * @brief Gets a property.
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
132 */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
133 void SDL_ATgeti( int property, int *value )
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
134 {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
135 switch (property) {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
136 case SDL_AT_VERBOSE:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
137 *value = at_verbose;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
138 break;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
139
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
140 case SDL_AT_QUIET:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
141 *value = at_quiet;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
142 break;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
143 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
144 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
145
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
146
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
147 /**
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
148 * @brief Begin testcase.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
149 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
150 void SDL_ATbegin( const char *testcase )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
151 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
152 /* Do not open twice. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
153 if (at_test_msg) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
154 SDL_ATprintErr( "AT testcase '%s' not closed before opening testcase '%s'\n",
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
155 at_test_msg, testcase );
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
156 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
157 /* Must have a name. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
158 if (testcase == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
159 SDL_ATprintErr( "AT testcase does not have a name.\n");
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
160 }
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
161 at_test_msg = strdup(testcase);
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
162
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
163 /* Verbose message. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
164 SDL_ATprintVerbose( 2, " +---> StartedTest Case '%s'\n", testcase );
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
165 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
166
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
167
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
168 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
169 * @brief Ends the testcase with a succes or failure.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
170 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
171 static void SDL_ATendWith( int success )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
172 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
173 /* Make sure initialized. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
174 if (at_test_msg == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
175 SDL_ATprintErr("Ended testcase without initializing.\n");
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
176 return;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
177 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
178
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
179 /* Mark as success or failure. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
180 if (success)
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
181 at_success++;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
182 else
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
183 at_failure++;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
184
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
185 /* Verbose message. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
186 SDL_ATprintVerbose( 2, " +---- Finished Test Case '%s'\n", at_test_msg );
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
187
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
188 /* Clean up. */
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
189 if (at_test_msg != NULL)
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
190 free(at_test_msg);
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
191 at_test_msg = NULL;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
192 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
193
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
194
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
195 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
196 * @brief Testcase test.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
197 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
198 int SDL_ATassert( const char *msg, int condition )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
199 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
200 /* Condition failed. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
201 if (!condition) {
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
202 /* Print. */
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
203 SDL_ATprintErr( "%s [%s] : %s\n", at_suite_msg, at_test_msg, msg );
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
204 /* End. */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
205 SDL_ATendWith(0);
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
206 }
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
207 return !condition;
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
208 }
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
209
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
210
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
211 /**
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
212 * @brief Testcase test.
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
213 */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
214 int SDL_ATvassert( int condition, const char *msg, ... )
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
215 {
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
216 va_list args;
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
217 char buf[256];
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
218
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
219 /* Condition failed. */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
220 if (!condition) {
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
221 /* Get message. */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
222 va_start( args, msg );
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
223 vsnprintf( buf, sizeof(buf), msg, args );
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
224 va_end( args );
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
225 /* Print. */
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
226 SDL_ATprintErr( "%s [%s] : %s\n", at_suite_msg, at_test_msg, buf );
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
227 /* End. */
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
228 SDL_ATendWith(0);
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
229 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
230 return !condition;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
231 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
232
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
233
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
234 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
235 * @brief End testcase.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
236 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
237 void SDL_ATend (void)
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
238 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
239 SDL_ATendWith(1);
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
240 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
241
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
242
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
243 /**
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
244 * @brief Displays an error.
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
245 */
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
246 int SDL_ATprintErr( const char *msg, ... )
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
247 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
248 va_list ap;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
249 int ret;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
250
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
251 /* Make sure there is something to print. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
252 if (msg == NULL)
3722
d8772964e402 Added more strict warning flags.
Edgar Simo <bobbens@gmail.com>
parents: 3713
diff changeset
253 return 0;
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
254 else {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
255 va_start(ap, msg);
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
256 ret = vfprintf( stderr, msg, ap );
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
257 va_end(ap);
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
258 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
259
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
260 return ret;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
261 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
262
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
263
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
264 /**
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
265 * @brief Displays a verbose message.
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
266 */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
267 int SDL_ATprintVerbose( int level, const char *msg, ... )
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
268 {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
269 va_list ap;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
270 int ret;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
271
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
272 /* Only print if not quiet. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
273 if (at_quiet || (at_verbose < level))
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
274 return 0;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
275
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
276 /* Make sure there is something to print. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
277 if (msg == NULL)
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
278 return 0;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
279 else {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
280 va_start(ap, msg);
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
281 ret = vfprintf( stdout, msg, ap );
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
282 va_end(ap);
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
283 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
284
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
285 return ret;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
286 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
287
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
288
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
289