PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ main()

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

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

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

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