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

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

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

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