annotate test/automated/SDL_at.c @ 3755:e04d9c69a6fd gsoc2009_unit_tests

Updated README a bit.
author Edgar Simo <bobbens@gmail.com>
date Thu, 06 Aug 2009 17:00:07 +0000
parents f47658c8f87a
children
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
3752
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
34 /*
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
35 * Prototypes.
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
36 */
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
37 static void SDL_ATcleanup (void);
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
38 static void SDL_ATendWith( int success );
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
39 static void SDL_ATassertFailed( const char *msg );
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
40
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
41
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
42 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
43 * @brief Cleans up the automated testsuite state.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
44 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
45 static void SDL_ATcleanup (void)
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
46 {
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 at_failure = 0;
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
55 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
56
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
57
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
58 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
59 * @brief Begin testsuite.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
60 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
61 void SDL_ATinit( const char *suite )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
62 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
63 /* Do not open twice. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
64 if (at_suite_msg) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
65 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
66 at_suite_msg, suite );
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
67 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
68 /* Must have a name. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
69 if (suite == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
70 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
71 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
72 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
73 at_suite_msg = strdup(suite);
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
74
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
75 /* 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
76 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
77 }
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
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
80 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
81 * @brief Finish testsuite.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
82 */
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
83 int SDL_ATfinish (void)
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
84 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
85 int failed;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
86
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
87 /* Make sure initialized. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
88 if (at_suite_msg == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
89 SDL_ATprintErr("Ended testcase without initializing.\n");
3722
d8772964e402 Added more strict warning flags.
Edgar Simo <bobbens@gmail.com>
parents: 3713
diff changeset
90 return 1;
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
91 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
92
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
93 /* Finished without closing testcase. */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
94 if (at_test_msg) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
95 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
96 at_suite_msg, at_test_msg );
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
97 }
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
98
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
99 /* Verbose message. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
100 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
101
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
102 /* Display message if verbose on failed. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
103 failed = at_failure;
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
104 if (at_failure > 0) {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
105 SDL_ATprintErr( "%s : Failed %d out of %d testcases!\n",
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
106 at_suite_msg, at_failure, at_failure+at_success );
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
107 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
108 else {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
109 SDL_ATprint( "%s : All tests successful (%d)\n",
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
110 at_suite_msg, at_success );
3711
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 /* Clean up. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
114 SDL_ATcleanup();
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
115
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
116 /* Return failed. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
117 return failed;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
118 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
119
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
120
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
121 /**
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
122 * @brief Sets a property.
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
123 */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
124 void SDL_ATseti( int property, int value )
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
125 {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
126 switch (property) {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
127 case SDL_AT_VERBOSE:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
128 at_verbose = value;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
129 break;
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 case SDL_AT_QUIET:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
132 at_quiet = value;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
133 break;
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 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
136
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
137
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
138 /**
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
139 * @brief Gets a property.
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
140 */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
141 void SDL_ATgeti( int property, int *value )
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
142 {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
143 switch (property) {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
144 case SDL_AT_VERBOSE:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
145 *value = at_verbose;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
146 break;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
147
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
148 case SDL_AT_QUIET:
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
149 *value = at_quiet;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
150 break;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
151 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
152 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
153
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
154
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
155 /**
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
156 * @brief Begin testcase.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
157 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
158 void SDL_ATbegin( const char *testcase )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
159 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
160 /* Do not open twice. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
161 if (at_test_msg) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
162 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
163 at_test_msg, testcase );
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
164 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
165 /* Must have a name. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
166 if (testcase == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
167 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
168 }
3746
be037e51f080 Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
Edgar Simo <bobbens@gmail.com>
parents: 3741
diff changeset
169 at_test_msg = strdup(testcase);
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
170
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
171 /* Verbose message. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
172 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
173 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
174
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
175
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
176 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
177 * @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
178 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
179 static void SDL_ATendWith( int success )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
180 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
181 /* Make sure initialized. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
182 if (at_test_msg == NULL) {
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
183 SDL_ATprintErr("Ended testcase without initializing.\n");
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
184 return;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
185 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
186
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
187 /* Mark as success or failure. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
188 if (success)
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
189 at_success++;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
190 else
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
191 at_failure++;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
192
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
193 /* Verbose message. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
194 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
195
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
196 /* 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
197 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
198 free(at_test_msg);
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
199 at_test_msg = NULL;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
200 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
201
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
202
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
203 /**
3752
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
204 * @brief Display failed assert message.
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
205 */
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
206 static void SDL_ATassertFailed( const char *msg )
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
207 {
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
208 /* Print. */
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
209 SDL_ATprintErr( "Assert Failed!\n" );
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
210 SDL_ATprintErr( " %s\n", msg );
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
211 SDL_ATprintErr( " Test Case '%s'\n", at_test_msg );
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
212 SDL_ATprintErr( " Test Suite '%s'\n", at_suite_msg );
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
213 /* End. */
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
214 SDL_ATendWith(0);
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
215 }
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
216
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
217
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
218 /**
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
219 * @brief Testcase test.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
220 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
221 int SDL_ATassert( const char *msg, int condition )
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
222 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
223 /* Condition failed. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
224 if (!condition) {
3752
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
225 /* Failed message. */
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
226 SDL_ATassertFailed(msg);
3725
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
227 }
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
228 return !condition;
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
229 }
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
230
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
231
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
232 /**
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
233 * @brief Testcase test.
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
234 */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
235 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
236 {
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
237 va_list args;
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
238 char buf[256];
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
239
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
240 /* Condition failed. */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
241 if (!condition) {
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
242 /* Get message. */
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
243 va_start( args, msg );
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
244 vsnprintf( buf, sizeof(buf), msg, args );
6eca2af6a86b Added SDL_ATvassert for printf style printing.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
245 va_end( args );
3752
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
246 /* Failed message. */
f47658c8f87a Better error handling.
Edgar Simo <bobbens@gmail.com>
parents: 3748
diff changeset
247 SDL_ATassertFailed( buf );
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
248 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
249 return !condition;
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
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
252
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
253 /**
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
254 * @brief End testcase.
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
255 */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
256 void SDL_ATend (void)
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
257 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
258 SDL_ATendWith(1);
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
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 /**
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
263 * @brief Displays an error.
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
264 */
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
265 int SDL_ATprintErr( const char *msg, ... )
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
266 {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
267 va_list ap;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
268 int ret;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
269
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
270 /* Make sure there is something to print. */
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
271 if (msg == NULL)
3722
d8772964e402 Added more strict warning flags.
Edgar Simo <bobbens@gmail.com>
parents: 3713
diff changeset
272 return 0;
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
273 else {
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
274 va_start(ap, msg);
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
275 ret = vfprintf( stderr, msg, ap );
3711
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
276 va_end(ap);
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
277 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
278
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
279 return ret;
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
280 }
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
281
80839fc6b8e1 First revision of the automated test suite.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
282
3741
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 * @brief Displays a verbose message.
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
285 */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
286 int SDL_ATprintVerbose( int level, const char *msg, ... )
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 va_list ap;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
289 int ret;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
290
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
291 /* Only print if not quiet. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
292 if (at_quiet || (at_verbose < level))
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
293 return 0;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
294
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
295 /* Make sure there is something to print. */
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
296 if (msg == NULL)
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
297 return 0;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
298 else {
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
299 va_start(ap, msg);
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
300 ret = vfprintf( stdout, msg, ap );
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
301 va_end(ap);
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
302 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
303
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
304 return ret;
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
305 }
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
306
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
307
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3727
diff changeset
308