Mercurial > sdl-ios-xcode
comparison test/automated/SDL_at.c @ 3746:be037e51f080 gsoc2009_unit_tests
Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Tue, 04 Aug 2009 16:34:04 +0000 |
parents | 808fad5fb593 |
children | 9428ae743878 |
comparison
equal
deleted
inserted
replaced
3745:f0b89cf4bffc | 3746:be037e51f080 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SDL_at.h" | 10 #include "SDL_at.h" |
11 | 11 |
12 #include <stdio.h> | 12 #include <stdio.h> /* printf/fprintf */ |
13 #include <stdarg.h> | 13 #include <stdarg.h> /* va_list */ |
14 #include <string.h> /* strdup */ | |
15 #include <stdlib.h> /* free */ | |
14 | 16 |
15 | 17 |
16 /* | 18 /* |
17 * Internal usage SDL_AT variables. | 19 * Internal usage SDL_AT variables. |
18 */ | 20 */ |
19 static const char *at_suite_msg = NULL; /**< Testsuite message. */ | 21 static char *at_suite_msg = NULL; /**< Testsuite message. */ |
20 static const char *at_test_msg = NULL; /**< Testcase message. */ | 22 static char *at_test_msg = NULL; /**< Testcase message. */ |
21 static int at_success = 0; /**< Number of successful testcases. */ | 23 static int at_success = 0; /**< Number of successful testcases. */ |
22 static int at_failure = 0; /**< Number of failed testcases. */ | 24 static int at_failure = 0; /**< Number of failed testcases. */ |
23 | 25 |
24 | 26 |
25 /* | 27 /* |
32 /** | 34 /** |
33 * @brief Cleans up the automated testsuite state. | 35 * @brief Cleans up the automated testsuite state. |
34 */ | 36 */ |
35 static void SDL_ATcleanup (void) | 37 static void SDL_ATcleanup (void) |
36 { | 38 { |
37 at_suite_msg = NULL; | 39 if (at_suite_msg != NULL) |
38 at_test_msg = NULL; | 40 free(at_suite_msg); |
39 at_success = 0; | 41 at_suite_msg = NULL; |
40 at_failure = 0; | 42 if (at_test_msg != NULL) |
43 free(at_test_msg); | |
44 at_test_msg = NULL; | |
45 at_success = 0; | |
46 at_failure = 0; | |
41 } | 47 } |
42 | 48 |
43 | 49 |
44 /** | 50 /** |
45 * @brief Begin testsuite. | 51 * @brief Begin testsuite. |
54 /* Must have a name. */ | 60 /* Must have a name. */ |
55 if (suite == NULL) { | 61 if (suite == NULL) { |
56 SDL_ATprintErr( "AT testsuite does not have a name.\n"); | 62 SDL_ATprintErr( "AT testsuite does not have a name.\n"); |
57 } | 63 } |
58 SDL_ATcleanup(); | 64 SDL_ATcleanup(); |
59 at_suite_msg = suite; | 65 at_suite_msg = strdup(suite); |
60 | 66 |
61 /* Verbose message. */ | 67 /* Verbose message. */ |
62 SDL_ATprintVerbose( 2, "--+---> Started Test Suite '%s'\n", suite ); | 68 SDL_ATprintVerbose( 2, "--+---> Started Test Suite '%s'\n", at_suite_msg ); |
63 } | 69 } |
64 | 70 |
65 | 71 |
66 /** | 72 /** |
67 * @brief Finish testsuite. | 73 * @brief Finish testsuite. |
150 } | 156 } |
151 /* Must have a name. */ | 157 /* Must have a name. */ |
152 if (testcase == NULL) { | 158 if (testcase == NULL) { |
153 SDL_ATprintErr( "AT testcase does not have a name.\n"); | 159 SDL_ATprintErr( "AT testcase does not have a name.\n"); |
154 } | 160 } |
155 at_test_msg = testcase; | 161 at_test_msg = strdup(testcase); |
156 | 162 |
157 /* Verbose message. */ | 163 /* Verbose message. */ |
158 SDL_ATprintVerbose( 2, " +---> StartedTest Case '%s'\n", testcase ); | 164 SDL_ATprintVerbose( 2, " +---> StartedTest Case '%s'\n", testcase ); |
159 } | 165 } |
160 | 166 |
178 | 184 |
179 /* Verbose message. */ | 185 /* Verbose message. */ |
180 SDL_ATprintVerbose( 2, " +---- Finished Test Case '%s'\n", at_test_msg ); | 186 SDL_ATprintVerbose( 2, " +---- Finished Test Case '%s'\n", at_test_msg ); |
181 | 187 |
182 /* Clean up. */ | 188 /* Clean up. */ |
189 if (at_test_msg != NULL) | |
190 free(at_test_msg); | |
183 at_test_msg = NULL; | 191 at_test_msg = NULL; |
184 } | 192 } |
185 | 193 |
186 | 194 |
187 /** | 195 /** |