postgis/liblwgeom/cunit
2022-07-24 00:16:04 -04:00
..
cu_algorithm.c XMeans: remove the machinery and reduce to just max_radius argument 2021-06-23 13:29:32 +03:00
cu_boundary.c Merge and format lwgeom_boundary tests 2021-08-28 19:17:04 +03:00
cu_buildarea.c Fix my email address 2016-07-04 15:45:56 +00:00
cu_bytebuffer.c Remove trailing blanks from .c files 2017-09-17 20:59:20 +00:00
cu_chaikin.c Fix file header cu_chaikin.c 2018-03-23 14:56:46 +00:00
cu_clean.c Fix expected result to include SRID 2020-12-21 12:49:42 +01:00
cu_clip_by_rect.c ST_ClipByBox2D: Do not throw when the geometry is invalid 2019-01-30 19:13:47 +00:00
cu_effectivearea.c Use fixed width integers. 2018-01-12 13:34:32 +00:00
cu_filterm.c Add function ST_FilterByM #4056 2018-03-23 14:11:53 +00:00
cu_force_dims.c Optional value params for Force3D*, Force4D functions 2020-01-14 19:58:55 +01:00
cu_force_sfs.c Remove trailing blanks from .c files 2017-09-17 20:59:20 +00:00
cu_geodetic_data.h Remove the many and unloved $Id$ tags that clutter the code base 2015-05-13 18:13:18 +00:00
cu_geodetic.c For edge_distance_to_point test, do not check that candidate point is on the target plane: we already know it is because we deliberately constructed it to be there. References #4835 2022-06-30 12:12:23 -07:00
cu_geos_cluster.c Support new Proj6 API 2019-02-22 21:36:27 +00:00
cu_geos.c Expand POSTGIS_GEOS_VERSION from 39 to 30900 (zero padded minor/patch) so that GEOS 3.10 and future friends do not break things by accident. Closes #4899 2021-04-23 11:44:29 -07:00
cu_gserialized1.c Speed up ST_X, ST_Y, ST_Z and ST_M 2019-07-12 16:03:58 +00:00
cu_gserialized2.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_homogenize.c Remove the many and unloved $Id$ tags that clutter the code base 2015-05-13 18:13:18 +00:00
cu_in_encoded_polyline.c Remove spaces and capital letters from suite names 2015-02-19 16:35:54 +00:00
cu_in_geojson.c Allow empty geometry to round-trip JSON format, references #4895 2021-07-30 12:34:59 -07:00
cu_in_twkb.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_in_wkb.c Throw error when fed WKB with malformed Oracle type numbers 2020-08-31 20:56:55 -07:00
cu_in_wkt.c Accept 'Nan' coordinates in WKT input, to allow for round-tripping of oddball bad geometry. 2021-02-17 16:55:31 -08:00
cu_iterator.c add LWPOINTITERATOR (closes #3366) 2015-11-18 13:05:32 +00:00
cu_lwstroke.c Avoid final point duplicates for circle stroking 2019-01-18 20:41:13 +00:00
cu_measures.c MultiPoint WKT writer: use parentheses in sub-members in WKT_ISO format 2022-04-09 16:15:29 +02:00
cu_minimum_bounding_circle.c Clean up the formatting of last commit. 2022-07-24 00:16:04 -04:00
cu_misc.c ST_StartPoint support any geometry 2021-08-23 15:46:24 +03:00
cu_node.c Use finishGEOS to remove valgrind noise in unit tests 2020-07-28 13:06:06 +02:00
cu_out_encoded_polyline.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_out_geojson.c Use the shortest representation when printing doubles 2020-07-28 13:18:38 +02:00
cu_out_gml.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_out_kml.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_out_svg.c Use the shortest representation when printing doubles 2020-07-28 13:18:38 +02:00
cu_out_twkb.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_out_wkb.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_out_wkt.c MultiPoint WKT writer: use parentheses in sub-members in WKT_ISO format 2022-04-09 16:15:29 +02:00
cu_out_x3d.c Use the shortest representation when printing doubles 2020-07-28 13:18:38 +02:00
cu_print.c Disable INFINITY rountrip tests 2020-08-18 09:34:31 +02:00
cu_ptarray.c Use ASSERT_DOUBLE_EQUAL_TOLERANCE to have obtained results showed 2022-02-28 21:48:39 +01:00
cu_sfcgal.c [format] clang-format files touched in SFCGAL relayout 2018-11-30 18:00:34 +00:00
cu_split.c Fix infinite loop in lwline_split_by_point_to 2022-05-17 17:09:12 +02:00
cu_stringbuffer.c Fix my email address 2016-07-04 15:45:56 +00:00
cu_surface.c Revert incorrect "Optimize varlena returning functions" 2020-04-28 19:13:38 +02:00
cu_surface.h Remove the many and unloved $Id$ tags that clutter the code base 2015-05-13 18:13:18 +00:00
cu_tester.c Merge and format lwgeom_boundary tests 2021-08-28 19:17:04 +03:00
cu_tester.h Fix ASSERT_DOUBLE_EQUAL_TOLERANCE 2021-09-29 22:50:18 +02:00
cu_tree.c Change point-in-cone routine to be more tolerant 2019-01-11 21:07:17 +00:00
cu_triangulate.c Use finishGEOS to remove valgrind noise in unit tests 2020-07-28 13:06:06 +02:00
cu_unionfind.c Use fixed width integers. 2018-01-12 13:34:32 +00:00
cu_varint.c Fix undefined behaviour in zigzag with negative inputs 2017-10-10 16:59:34 +00:00
cu_wrapx.c Remove more memory leaks from tests 2020-08-13 13:13:11 -07:00
Makefile.in Steps toward supporting out-of-tree builds 2022-01-20 13:04:58 +01:00
README Drop svn references from revision reading script and docs 2019-10-30 10:00:12 +01:00

TABLE OF CONTENTS
	1. HOW TO RUN LIBLWGEOM UNIT TESTS
	2. HOW TO ADD A SINGLE TEST
	3. HOW TO ADD AN ENTIRE TEST SUITE
	4. ABOUT TEST OUTPUT
	5. HOW TO ASSERT A FAILURE


1. HOW TO RUN LIBLWGEOM UNIT TESTS

NOTE: We use the CUnit test framework, so you will need to have
      this installed before you will be able to build and run the
      unit tests.

If you have already built the rest of the code, then from the
postgis/liblwgeom/cunit directory, run:

make
./cu_tester

This will run all the tests.  To run just one suite:

./cu_tester <suite name>

To run just one test:

./cu_tester <test name>

To run selected suites or tests (will be run in the order you specify):

./cu_tester <test name> <suite name> <other suite name> <other test name> <etc>

Unit tests for the entire system (including both these unit tests and others
that require postgresql to be running) can be done by running the following
command from the top of the directory tree (postgis directory):

make check


2. HOW TO ADD A SINGLE TEST

To add a test to an existing suite, follow these steps:

2.1 Create the test:

Open the cu_<suite name>.c file, and add your
new test function.  Test functions must have the following signature:

static void <test_name>(void)

<test_name> must be unique among all tests.  A useful naming convention is:

static void test_<suite>_<specific name>(void)

Although not all existing tests follow that convention.

For information on the various ASSERT macros you can use, see the CUnit
documentation:

http://cunit.sourceforge.net/doc/writing_tests.html

2.2 Add the test to the suite:

At the bottom of the cu_<suite name>.c file, below all the test functions, you
will find a block that looks like this (this example is from cu_print.c):

/*
** Used by the test harness to register the tests in this file.
*/
void print_suite_setup(void);
void print_suite_setup(void)
{
      CU_pSuite suite = CU_add_suite("Print", init_print_suite, clean_print_suite);
      PG_ADD_TEST(test_lwprint_default_format);
      PG_ADD_TEST(test_lwprint_format_orders);
      PG_ADD_TEST(test_lwprint_optional_format);
};

Add a new line for your test:

	PG_ADD_TEST(<your test function name>);

The tests will be run in the order they appear in the list.
CU_TEST_INFO_NULL must always be the last entry.

2.3 Add any necessary init / cleanup code.

If your test needs global data created or any other kind of init done
before it runs, or cleanup done after it runs, add the appropriate code
to the init_<suite name> or clean_<suite name> functions.  If the test
suite does not seem to have these functions (they are optional), see
below (3.3) for how to create them.

Save your changes, run make, and run ./cu_tester, and your test
should be executed.



3. HOW TO ADD AN ENTIRE TEST SUITE

Do the following steps to create a whole new test suite (new .c file).

3.1 Create the file.

Create the new file (remember to add to repository as well).
The naming convention is cu_<suite name>.c.

Make sure to import:

#include "CUnit/Basic.h"
#include "cu_tester.h"

Now add the file to Makefile.in.  Look for "ADD YOUR NEW TEST FILE HERE".
Remember that you'll have to re-run "configure" (from the top directory)
after modifying a .in file.

3.2 Write the tests.

Write the test functions as described in section 2.  Then at the bottom
of the file, construct the array of tests (example taken from cu_print.c):

/*
** Used by the test harness to register the tests in this file.
*/
void print_suite_setup(void);
void print_suite_setup(void)
{
      CU_pSuite suite = CU_add_suite("Print", init_print_suite, clean_print_suite);
      PG_ADD_TEST(test_lwprint_default_format);
      PG_ADD_TEST(test_lwprint_format_orders);
      PG_ADD_TEST(test_lwprint_optional_format);
};

The naming convention is generally <suite name>_suite_setup.

3.3 Construct the init / clean functions and the suite struct.

Test suites can have initialization and cleanup functions to setup and
dispose of any common or global data.  They must have the following
signature:

static int <function name>(void)

The naming convention is generally:

static int init_<suite name>(void)
static int clean_<suite_name>(void)

3.4 Add your suite to cu_tester.c.

Edit cu_tester.c.  Search for "ADD YOUR SUITE HERE" and add new lines in
the appropriate places, using the _suite_setup name you used in the last step.

Now run make (remember to run configure first), then ./cu_tester and your
new suite should run.



4. ABOUT TEST OUTPUT

CUnit does not print much about asserts that fail, just the line number
within the appropriate file.  If you need any more detailed output, it
is up to you to printf it.  If you discover that all the test suites
are full of individual hacks to do this, please consolidate them into
cu_tester.h / .c, and/or enter a trac issue suggesting an improvement.


5. HOW TO ASSERT A FAILURE

Often you may want to assert that lwerror was called, possibly verifying
that a specific error message was generated.  There is now a way to do
this.  The global char array "cu_error_msg" will always contain the most
recent error from an lwerror call.  You can check it in your test function
(either asserting its length is greater than zero, or looking for a
specific string).  Then call cu_error_msg_reset() to clear it when you're
done.  It is a good idea to call cu_error_msg_reset prior to your test,
in case a previous test has generated an error that was not cleared.

Example:

cu_error_msg_reset();
<do something here>
if (strlen(cu_error_msg) > 0)
{
        printf("\nError: <whatever your test was> generated an error: %s\n", cu_error_msg);
        CU_FAIL();
        /* be nice and clean it up for the next test. */
        cu_error_msg_reset();
}