PostGIS  2.5.0dev-r@@SVN_REVISION@@
int main ( int  argc,
char *  argv[] 
)

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

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

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

Here is the call graph for this function: