PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ main()

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

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

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