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

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

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

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

Here is the call graph for this function: