PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ main()

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

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

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