PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
liblwgeom/cunit/cu_tester.c
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 * Copyright 2008 Paul Ramsey <pramsey@cleverelephant.ca>
6 *
7 * This is free software; you can redistribute and/or modify it under
8 * the terms of the GNU General Public Licence. See the COPYING file.
9 *
10 **********************************************************************/
11
12#include <stdio.h>
13#include <string.h>
14#include "CUnit/Basic.h"
15#include "liblwgeom_internal.h"
16#include "cu_tester.h"
17#include "../postgis_config.h"
18
20
21/* Internal funcs */
22static void
23cu_errorreporter(const char *fmt, va_list ap);
24
25static void
26cu_noticereporter(const char *fmt, va_list ap);
27
28static void
29cu_debuglogger(int level, const char *fmt, va_list ap);
30
31
32/* ADD YOUR SUITE SETUP FUNCTION HERE (1 of 2) */
33extern void print_suite_setup();
34extern void algorithms_suite_setup();
35extern void boundary_suite_setup();
36extern void buildarea_suite_setup();
37extern void clean_suite_setup();
38extern void clip_by_rect_suite_setup();
39extern void force_dims_suite_setup(void);
40extern void force_sfs_suite_setup(void);
41extern void geodetic_suite_setup(void);
42extern void geos_suite_setup(void);
43extern void geos_cluster_suite_setup(void);
44extern void unionfind_suite_setup(void);
45extern void homogenize_suite_setup(void);
46extern void in_encoded_polyline_suite_setup(void);
47extern void in_geojson_suite_setup(void);
48extern void iterator_suite_setup(void);
49extern void twkb_in_suite_setup(void);
50extern void gserialized1_suite_setup(void);
51extern void gserialized2_suite_setup(void);
52extern void lwstroke_suite_setup(void);
53extern void measures_suite_setup(void);
54extern void effectivearea_suite_setup(void);
55extern void chaikin_suite_setup(void);
56extern void filterm_suite_setup(void);
58extern void misc_suite_setup(void);
59extern void node_suite_setup(void);
60extern void out_encoded_polyline_suite_setup(void);
61extern void out_geojson_suite_setup(void);
62extern void out_gml_suite_setup(void);
63extern void out_kml_suite_setup(void);
64extern void out_svg_suite_setup(void);
65extern void twkb_out_suite_setup(void);
66extern void out_x3d_suite_setup(void);
67extern void ptarray_suite_setup(void);
68#if HAVE_SFCGAL
69extern void sfcgal_suite_setup(void);
70#endif
71extern void split_suite_setup(void);
72extern void stringbuffer_suite_setup(void);
73extern void tree_suite_setup(void);
74extern void triangulate_suite_setup(void);
75extern void varint_suite_setup(void);
76extern void wkt_out_suite_setup(void);
77extern void wkb_out_suite_setup(void);
78extern void surface_suite_setup(void);
79extern void wkb_in_suite_setup(void);
80extern void wkt_in_suite_setup(void);
81extern void wrapx_suite_setup(void);
83
84
85/* AND ADD YOUR SUITE SETUP FUNCTION HERE (2 of 2) */
139
140
141#define MAX_CUNIT_MSG_LENGTH 256
142
143/*
144** The main() function for setting up and running the tests.
145** Returns a CUE_SUCCESS on successful running, another
146** CUnit error code on failure.
147*/
148int main(int argc, char *argv[])
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}
280static void
281cu_errorreporter(const char *fmt, va_list ap)
282{
283 vsnprintf (cu_error_msg, MAX_CUNIT_MSG_LENGTH, fmt, ap);
285 /*fprintf(stderr, "ERROR: %s\n", cu_error_msg);*/
286}
287
288static void
289cu_noticereporter(const char *fmt, va_list ap)
290{
291 char buf[MAX_CUNIT_MSG_LENGTH+1];
292 vsnprintf (buf, MAX_CUNIT_MSG_LENGTH, fmt, ap);
293 buf[MAX_CUNIT_MSG_LENGTH]='\0';
294 fprintf(stderr, "NOTICE: %s\n", buf);
295}
296
297static void
298cu_debuglogger(int level, const char *fmt, va_list ap)
299{
300 char buf[MAX_CUNIT_MSG_LENGTH+1];
301 vsnprintf (buf, MAX_CUNIT_MSG_LENGTH, fmt, ap);
302 buf[MAX_CUNIT_MSG_LENGTH]='\0';
303 fprintf(stderr, "DEBUG%d: %s\n", level, buf);
304}
305
306void
311
312/* Utility functions for testing */
313
314/* do_transformation_test
315 * - reads input_wkt and expected_wkt
316 * - asserts output of transfn(input) = expected
317 * - cleans up
318 */
319void
320do_fn_test(LWGEOM* (*transfn)(LWGEOM*), char *input_wkt, char *expected_wkt)
321{
322 LWGEOM* input = lwgeom_from_wkt(input_wkt, LW_PARSER_CHECK_NONE);
323 LWGEOM* expected = lwgeom_from_wkt(expected_wkt, LW_PARSER_CHECK_NONE);
324 LWGEOM* observed = transfn(input);
325
326 ASSERT_LWGEOM_EQUAL(observed, expected);
327
328 lwgeom_free(input);
329 lwgeom_free(expected);
330 lwgeom_free(observed);
331}
332
void sfcgal_suite_setup(void)
Definition cu_sfcgal.c:138
void out_x3d_suite_setup(void)
Definition cu_out_x3d.c:169
void in_encoded_polyline_suite_setup(void)
void clip_by_rect_suite_setup()
#define MAX_CUNIT_MSG_LENGTH
void out_encoded_polyline_suite_setup(void)
void geos_cluster_suite_setup(void)
void boundary_suite_setup()
void force_sfs_suite_setup(void)
void buildarea_suite_setup()
static void cu_debuglogger(int level, const char *fmt, va_list ap)
void unionfind_suite_setup(void)
void do_fn_test(LWGEOM *(*transfn)(LWGEOM *), char *input_wkt, char *expected_wkt)
void wkt_out_suite_setup(void)
Definition cu_out_wkt.c:220
void twkb_in_suite_setup(void)
Definition cu_in_twkb.c:231
void homogenize_suite_setup(void)
void misc_suite_setup(void)
void gserialized2_suite_setup(void)
void measures_suite_setup(void)
void wrapx_suite_setup(void)
Definition cu_wrapx.c:194
void cu_error_msg_reset()
PG_SuiteSetup setupfuncs[]
void iterator_suite_setup(void)
void triangulate_suite_setup(void)
void stringbuffer_suite_setup(void)
void chaikin_suite_setup(void)
Definition cu_chaikin.c:61
void split_suite_setup(void)
Definition cu_split.c:299
void clean_suite_setup()
Definition cu_clean.c:177
void tree_suite_setup(void)
Definition cu_tree.c:651
void out_gml_suite_setup(void)
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 twkb_out_suite_setup(void)
void out_svg_suite_setup(void)
Definition cu_out_svg.c:313
void geos_suite_setup(void)
Definition cu_geos.c:199
void effectivearea_suite_setup(void)
void in_geojson_suite_setup(void)
void print_suite_setup()
Definition cu_print.c:573
void wkb_in_suite_setup(void)
Definition cu_in_wkb.c:286
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
void wkb_out_suite_setup(void)
Definition cu_out_wkb.c:214
void geodetic_suite_setup(void)
void ptarray_suite_setup(void)
Definition cu_ptarray.c:840
void node_suite_setup(void)
Definition cu_node.c:86
void out_kml_suite_setup(void)
Definition cu_out_kml.c:219
void surface_suite_setup(void)
Definition cu_surface.c:404
void varint_suite_setup(void)
Definition cu_varint.c:251
void out_geojson_suite_setup(void)
void wkt_in_suite_setup(void)
Definition cu_in_wkt.c:428
void algorithms_suite_setup()
void minimum_bounding_circle_suite_setup(void)
void gserialized1_suite_setup(void)
void filterm_suite_setup(void)
Definition cu_filterm.c:59
static void cu_noticereporter(const char *fmt, va_list ap)
void force_dims_suite_setup(void)
void remove_irrelevant_points_for_view_suite_setup(void)
void lwstroke_suite_setup(void)
void(* PG_SuiteSetup)(void)
#define MAX_CUNIT_ERROR_LENGTH
#define ASSERT_LWGEOM_EQUAL(o, e)
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_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
void lwgeom_set_debuglogger(lwdebuglogger debuglogger)
Definition lwutil.c:171
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
int main(void)