PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ main()

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

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

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