• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

Makefile.inH A D04-Sep-20212.6 KiB12087

READMEH A D04-Sep-20215.6 KiB189126

cu_algorithm.cH A D04-Sep-202156 KiB1,8291,299

cu_buildarea.cH A D04-Sep-20217.9 KiB339188

cu_bytebuffer.cH A D04-Sep-20211.1 KiB5926

cu_chaikin.cH A D04-Sep-20212.2 KiB6742

cu_clean.cH A D04-Sep-20214.8 KiB16489

cu_clip_by_rect.cH A D04-Sep-20212.7 KiB8551

cu_effectivearea.cH A D04-Sep-20212.2 KiB8048

cu_filterm.cH A D04-Sep-20212.4 KiB6544

cu_force_sfs.cH A D04-Sep-20215.8 KiB174111

cu_geodetic.cH A D04-Sep-202155.9 KiB1,6391,169

cu_geodetic_data.hH A D04-Sep-2021504.6 KiB8062

cu_geos.cH A D04-Sep-20217.4 KiB209163

cu_geos_cluster.cH A D04-Sep-202111.5 KiB385296

cu_gserialized1.cH A D04-Sep-202139.6 KiB1,290975

cu_gserialized2.cH A D04-Sep-202116.2 KiB517395

cu_homogenize.cH A D04-Sep-20219.1 KiB264160

cu_in_encoded_polyline.cH A D04-Sep-20211.8 KiB6640

cu_in_geojson.cH A D04-Sep-20216.9 KiB215148

cu_in_twkb.cH A D04-Sep-20216.6 KiB245149

cu_in_wkb.cH A D04-Sep-202110 KiB296200

cu_in_wkt.cH A D04-Sep-202111.3 KiB428297

cu_iterator.cH A D04-Sep-20217.3 KiB266202

cu_lwstroke.cH A D04-Sep-202117.8 KiB531365

cu_measures.cH A D04-Sep-202158.2 KiB1,5601,069

cu_minimum_bounding_circle.cH A D04-Sep-20212.1 KiB8654

cu_misc.cH A D04-Sep-20219.1 KiB279224

cu_node.cH A D04-Sep-20212.2 KiB7042

cu_out_encoded_polyline.cH A D04-Sep-20212.6 KiB10565

cu_out_geojson.cH A D04-Sep-20219.7 KiB310200

cu_out_gml.cH A D04-Sep-202149.8 KiB1,083717

cu_out_kml.cH A D04-Sep-20217.6 KiB247160

cu_out_svg.cH A D04-Sep-20217.8 KiB330215

cu_out_twkb.cH A D04-Sep-20218.2 KiB293156

cu_out_wkb.cH A D04-Sep-202111.1 KiB232151

cu_out_wkt.cH A D04-Sep-20218.6 KiB227172

cu_out_x3d.cH A D04-Sep-20216.1 KiB190109

cu_print.cH A D04-Sep-202112.9 KiB176135

cu_ptarray.cH A D04-Sep-202118.1 KiB637461

cu_sfcgal.cH A D04-Sep-20215.5 KiB10077

cu_split.cH A D04-Sep-20218.5 KiB281231

cu_stringbuffer.cH A D04-Sep-20211.4 KiB6333

cu_surface.cH A D04-Sep-202119.2 KiB412297

cu_surface.hH A D04-Sep-2021701 2510

cu_tester.cH A D04-Sep-20219.7 KiB330256

cu_tester.hH A D04-Sep-20212.8 KiB9563

cu_tree.cH A D04-Sep-202155.1 KiB435309

cu_triangulate.cH A D04-Sep-20213.3 KiB11874

cu_unionfind.cH A D04-Sep-20214.5 KiB175122

cu_varint.cH A D04-Sep-20217.2 KiB258146

cu_wrapx.cH A D04-Sep-20215 KiB199171

README

1TABLE OF CONTENTS
2	1. HOW TO RUN LIBLWGEOM UNIT TESTS
3	2. HOW TO ADD A SINGLE TEST
4	3. HOW TO ADD AN ENTIRE TEST SUITE
5	4. ABOUT TEST OUTPUT
6	5. HOW TO ASSERT A FAILURE
7
8
91. HOW TO RUN LIBLWGEOM UNIT TESTS
10
11NOTE: We use the CUnit test framework, so you will need to have
12      this installed before you will be able to build and run the
13      unit tests.
14
15If you have already built the rest of the code, then from the
16postgis/liblwgeom/cunit directory, run:
17
18make
19./cu_tester
20
21This will run all the tests.  To run just one suite:
22
23./cu_tester <suite name>
24
25To run just one test:
26
27./cu_tester <test name>
28
29To run selected suites or tests (will be run in the order you specify):
30
31./cu_tester <test name> <suite name> <other suite name> <other test name> <etc>
32
33Unit tests for the entire system (including both these unit tests and others
34that require postgresql to be running) can be done by running the following
35command from the top of the directory tree (postgis directory):
36
37make check
38
39
402. HOW TO ADD A SINGLE TEST
41
42To add a test to an existing suite, follow these steps:
43
442.1 Create the test:
45
46Open the cu_<suite name>.c file, and add your
47new test function.  Test functions must have the following signature:
48
49static void <test_name>(void)
50
51<test_name> must be unique among all tests.  A useful naming convention is:
52
53static void test_<suite>_<specific name>(void)
54
55Although not all existing tests follow that convention.
56
57For information on the various ASSERT macros you can use, see the CUnit
58documentation:
59
60http://cunit.sourceforge.net/doc/writing_tests.html
61
622.2 Add the test to the suite:
63
64At the bottom of the cu_<suite name>.c file, below all the test functions, you
65will find a block that looks like this (this example is from cu_print.c):
66
67/*
68** Used by the test harness to register the tests in this file.
69*/
70void print_suite_setup(void);
71void print_suite_setup(void)
72{
73      CU_pSuite suite = CU_add_suite("Print", init_print_suite, clean_print_suite);
74      PG_ADD_TEST(test_lwprint_default_format);
75      PG_ADD_TEST(test_lwprint_format_orders);
76      PG_ADD_TEST(test_lwprint_optional_format);
77};
78
79Add a new line for your test:
80
81	PG_ADD_TEST(<your test function name>);
82
83The tests will be run in the order they appear in the list.
84CU_TEST_INFO_NULL must always be the last entry.
85
862.3 Add any necessary init / cleanup code.
87
88If your test needs global data created or any other kind of init done
89before it runs, or cleanup done after it runs, add the appropriate code
90to the init_<suite name> or clean_<suite name> functions.  If the test
91suite does not seem to have these functions (they are optional), see
92below (3.3) for how to create them.
93
94Save your changes, run make, and run ./cu_tester, and your test
95should be executed.
96
97
98
993. HOW TO ADD AN ENTIRE TEST SUITE
100
101Do the following steps to create a whole new test suite (new .c file).
102
1033.1 Create the file.
104
105Create the new file (remember to add to repository as well).
106The naming convention is cu_<suite name>.c.
107
108Make sure to import:
109
110#include "CUnit/Basic.h"
111#include "cu_tester.h"
112
113Now add the file to Makefile.in.  Look for "ADD YOUR NEW TEST FILE HERE".
114Remember that you'll have to re-run "configure" (from the top directory)
115after modifying a .in file.
116
1173.2 Write the tests.
118
119Write the test functions as described in section 2.  Then at the bottom
120of the file, construct the array of tests (example taken from cu_print.c):
121
122/*
123** Used by the test harness to register the tests in this file.
124*/
125void print_suite_setup(void);
126void print_suite_setup(void)
127{
128      CU_pSuite suite = CU_add_suite("Print", init_print_suite, clean_print_suite);
129      PG_ADD_TEST(test_lwprint_default_format);
130      PG_ADD_TEST(test_lwprint_format_orders);
131      PG_ADD_TEST(test_lwprint_optional_format);
132};
133
134The naming convention is generally <suite name>_suite_setup.
135
1363.3 Construct the init / clean functions and the suite struct.
137
138Test suites can have initialization and cleanup functions to setup and
139dispose of any common or global data.  They must have the following
140signature:
141
142static int <function name>(void)
143
144The naming convention is generally:
145
146static int init_<suite name>(void)
147static int clean_<suite_name>(void)
148
1493.4 Add your suite to cu_tester.c.
150
151Edit cu_tester.c.  Search for "ADD YOUR SUITE HERE" and add new lines in
152the appropriate places, using the _suite_setup name you used in the last step.
153
154Now run make (remember to run configure first), then ./cu_tester and your
155new suite should run.
156
157
158
1594. ABOUT TEST OUTPUT
160
161CUnit does not print much about asserts that fail, just the line number
162within the appropriate file.  If you need any more detailed output, it
163is up to you to printf it.  If you discover that all the test suites
164are full of individual hacks to do this, please consolidate them into
165cu_tester.h / .c, and/or enter a trac issue suggesting an improvement.
166
167
1685. HOW TO ASSERT A FAILURE
169
170Often you may want to assert that lwerror was called, possibly verifying
171that a specific error message was generated.  There is now a way to do
172this.  The global char array "cu_error_msg" will always contain the most
173recent error from an lwerror call.  You can check it in your test function
174(either asserting its length is greater than zero, or looking for a
175specific string).  Then call cu_error_msg_reset() to clear it when you're
176done.  It is a good idea to call cu_error_msg_reset prior to your test,
177in case a previous test has generated an error that was not cleared.
178
179Example:
180
181cu_error_msg_reset();
182<do something here>
183if (strlen(cu_error_msg) > 0)
184{
185        printf("\nError: <whatever your test was> generated an error: %s\n", cu_error_msg);
186        CU_FAIL();
187        /* be nice and clean it up for the next test. */
188        cu_error_msg_reset();
189}