PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ main()

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

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

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

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