PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ main()

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

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

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