PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 145 of file liblwgeom/cunit/cu_tester.c.

146{
147 int index;
148 char *suite_name;
149 CU_pSuite suite_to_run;
150 char *test_name;
151 CU_pTest test_to_run = NULL;
152 CU_ErrorCode errCode = 0;
153 CU_pTestRegistry registry;
154 int num_run;
155 int num_failed;
156 PG_SuiteSetup *setupfunc = setupfuncs;
157
158 /* Install the custom error handler */
161
162 /* Initialize the CUnit test registry */
163 if (CUE_SUCCESS != CU_initialize_registry())
164 {
165 errCode = CU_get_error();
166 printf(" Error attempting to initialize registry: %d. See CUError.h for error code list.\n", errCode);
167 return errCode;
168 }
169
170 /* Register all the test suites. */
171 while ( *setupfunc )
172 {
173 (*setupfunc)();
174 setupfunc++;
175 }
176
177 /* Run all tests using the CUnit Basic interface */
178 CU_basic_set_mode(CU_BRM_VERBOSE);
179 if (argc <= 1)
180 {
181 errCode = CU_basic_run_tests();
182 }
183 else
184 {
185 /* NOTE: The cunit functions used here (CU_get_registry, CU_get_suite_by_name, and CU_get_test_by_name) are
186 * listed with the following warning: "Internal CUnit system functions. Should not be routinely called by users."
187 * However, there didn't seem to be any other way to get tests by name, so we're calling them. */
188 registry = CU_get_registry();
189 for (index = 1; index < argc; index++)
190 {
191 suite_name = argv[index];
192 test_name = NULL;
193 suite_to_run = CU_get_suite_by_name(suite_name, registry);
194 if (NULL == suite_to_run)
195 {
196 /* See if it's a test name instead of a suite name. */
197 suite_to_run = registry->pSuite;
198 while (suite_to_run != NULL)
199 {
200 test_to_run = CU_get_test_by_name(suite_name, suite_to_run);
201 if (test_to_run != NULL)
202 {
203 /* It was a test name. */
204 test_name = suite_name;
205 suite_name = suite_to_run->pName;
206 break;
207 }
208 suite_to_run = suite_to_run->pNext;
209 }
210 }
211 if (suite_to_run == NULL)
212 {
213 printf("\n'%s' does not appear to be either a suite name or a test name.\n\n", suite_name);
214 }
215 else
216 {
217 if (test_name != NULL && test_to_run != NULL)
218 {
219 /* Run only this test. */
220 printf("\nRunning test '%s' in suite '%s'.\n", test_name, suite_name);
221 /* This should be CU_basic_run_test, but that method is broken, see:
222 * https://sourceforge.net/tracker/?func=detail&aid=2851925&group_id=32992&atid=407088
223 * This one doesn't output anything for success, so we have to do it manually. */
224 errCode = CU_run_test(suite_to_run, test_to_run);
225 if (errCode != CUE_SUCCESS)
226 {
227 printf(" Error attempting to run tests: %d. See CUError.h for error code list.\n", errCode);
228 }
229 else
230 {
231 num_run = CU_get_number_of_asserts();
232 num_failed = CU_get_number_of_failures();
233 printf("\n %s - asserts - %3d passed, %3d failed, %3d total.\n\n",
234 (0 == num_failed ? "PASSED" : "FAILED"), (num_run - num_failed), num_failed, num_run);
235 }
236 }
237 else
238 {
239 /* Run all the tests in the suite. */
240 printf("\nRunning all tests in suite '%s'.\n", suite_name);
241 /* This should be CU_basic_run_suite, but that method is broken, see:
242 * https://sourceforge.net/tracker/?func=detail&aid=2851925&group_id=32992&atid=407088
243 * This one doesn't output anything for success, so we have to do it manually. */
244 errCode = CU_run_suite(suite_to_run);
245 if (errCode != CUE_SUCCESS)
246 {
247 printf(" Error attempting to run tests: %d. See CUError.h for error code list.\n", errCode);
248 }
249 else
250 {
251 num_run = CU_get_number_of_tests_run();
252 num_failed = CU_get_number_of_tests_failed();
253 printf("\n %s - tests - %3d passed, %3d failed, %3d total.\n",
254 (0 == num_failed ? "PASSED" : "FAILED"), (num_run - num_failed), num_failed, num_run);
255 num_run = CU_get_number_of_asserts();
256 num_failed = CU_get_number_of_failures();
257 printf(" - asserts - %3d passed, %3d failed, %3d total.\n\n",
258 (num_run - num_failed), num_failed, num_run);
259 }
260 }
261 }
262 }
263 /* Presumably if the CU_basic_run_[test|suite] functions worked, we wouldn't have to do this. */
264 CU_basic_show_failures(CU_get_failure_list());
265 printf("\n\n"); /* basic_show_failures leaves off line breaks. */
266 }
267 num_failed = CU_get_number_of_failures();
268 CU_cleanup_registry();
269 return num_failed;
270}
static void cu_debuglogger(int level, const char *fmt, va_list ap)
PG_SuiteSetup setupfuncs[]
static void cu_errorreporter(const char *fmt, va_list ap)
CUnit error handler Log message in a global var instead of printing in stderr.
static void cu_noticereporter(const char *fmt, va_list ap)
void(* PG_SuiteSetup)(void)
void(*) typedef void(*) voi lwgeom_set_handlers)(lwallocator allocator, lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, lwreporter noticereporter)
Install custom memory management and error handling functions you want your application to use.
void lwgeom_set_debuglogger(lwdebuglogger debuglogger)
Definition lwutil.c:171

References cu_debuglogger(), cu_errorreporter(), cu_noticereporter(), lwgeom_set_debuglogger(), and setupfuncs.

Here is the call graph for this function: