From: Paul Ramsey Date: Wed, 18 Feb 2015 22:56:28 +0000 (+0000) Subject: #3041, Cunit 2.1-3 breaks testing X-Git-Tag: 2.2.0rc1~660 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af14a2ebfb96a0dbce552ea29bcf9ae367a7fa73;p=postgis #3041, Cunit 2.1-3 breaks testing Renovate the raster cunit as well git-svn-id: http://svn.osgeo.org/postgis/trunk@13238 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_tester.c b/liblwgeom/cunit/cu_tester.c index 408009e37..e801f5af0 100644 --- a/liblwgeom/cunit/cu_tester.c +++ b/liblwgeom/cunit/cu_tester.c @@ -113,11 +113,12 @@ int main(int argc, char *argv[]) CU_pTestRegistry registry; int num_run; int num_failed; + PG_SuiteSetup *setupfunc = setupfuncs; - /* install the custom error handler */ + /* Install the custom error handler */ lwgeom_set_handlers(0, 0, 0, cu_errorreporter, 0); - /* initialize the CUnit test registry */ + /* Initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) { errCode = CU_get_error(); @@ -125,21 +126,13 @@ int main(int argc, char *argv[]) return errCode; } - PG_SuiteSetup *setupfunc = setupfuncs; + /* Register all the test suites. */ while ( *setupfunc ) { (*setupfunc)(); setupfunc++; } - /* Register all the test suites. */ - // if (CUE_SUCCESS != CU_register_suites(suites)) - // { - // errCode = CU_get_error(); - // printf(" Error attempting to register test suites: %d. See CUError.h for error code list.\n", errCode); - // return errCode; - // } - /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); if (argc <= 1) diff --git a/liblwgeom/cunit/cu_tester.h b/liblwgeom/cunit/cu_tester.h index b926764a0..242bef74f 100644 --- a/liblwgeom/cunit/cu_tester.h +++ b/liblwgeom/cunit/cu_tester.h @@ -9,8 +9,6 @@ * **********************************************************************/ -#define PG_TEST(test_func) { #test_func, test_func } - #define MAX_CUNIT_ERROR_LENGTH 512 #define PG_ADD_TEST(suite, testfunc) CU_add_test(suite, #testfunc, testfunc) diff --git a/raster/test/cunit/cu_band_basics.c b/raster/test/cunit/cu_band_basics.c index 45ada1fa0..72b6b841b 100644 --- a/raster/test/cunit/cu_band_basics.c +++ b/raster/test/cunit/cu_band_basics.c @@ -1253,20 +1253,22 @@ static void test_band_get_pixel_line() { } /* register tests */ -CU_TestInfo band_basics_tests[] = { - PG_TEST(test_band_metadata), - PG_TEST(test_band_pixtype_1BB), - PG_TEST(test_band_pixtype_2BUI), - PG_TEST(test_band_pixtype_4BUI), - PG_TEST(test_band_pixtype_8BUI), - PG_TEST(test_band_pixtype_8BSI), - PG_TEST(test_band_pixtype_16BUI), - PG_TEST(test_band_pixtype_16BSI), - PG_TEST(test_band_pixtype_32BUI), - PG_TEST(test_band_pixtype_32BSI), - PG_TEST(test_band_pixtype_32BF), - PG_TEST(test_band_pixtype_64BF), - PG_TEST(test_band_get_pixel_line), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo band_basics_suite = {"band_basics", NULL, NULL, band_basics_tests}; +void band_basics_suite_setup(void); +void band_basics_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("band_basics", NULL, NULL); + PG_ADD_TEST(suite, test_band_metadata); + PG_ADD_TEST(suite, test_band_pixtype_1BB); + PG_ADD_TEST(suite, test_band_pixtype_2BUI); + PG_ADD_TEST(suite, test_band_pixtype_4BUI); + PG_ADD_TEST(suite, test_band_pixtype_8BUI); + PG_ADD_TEST(suite, test_band_pixtype_8BSI); + PG_ADD_TEST(suite, test_band_pixtype_16BUI); + PG_ADD_TEST(suite, test_band_pixtype_16BSI); + PG_ADD_TEST(suite, test_band_pixtype_32BUI); + PG_ADD_TEST(suite, test_band_pixtype_32BSI); + PG_ADD_TEST(suite, test_band_pixtype_32BF); + PG_ADD_TEST(suite, test_band_pixtype_64BF); + PG_ADD_TEST(suite, test_band_get_pixel_line); +} + diff --git a/raster/test/cunit/cu_band_misc.c b/raster/test/cunit/cu_band_misc.c index a599db388..6eee0dcb2 100644 --- a/raster/test/cunit/cu_band_misc.c +++ b/raster/test/cunit/cu_band_misc.c @@ -579,10 +579,12 @@ static void test_pixel_set_to_array(){ } /* register tests */ -CU_TestInfo band_misc_tests[] = { - PG_TEST(test_band_get_nearest_pixel), - PG_TEST(test_band_get_pixel_of_value), - PG_TEST(test_pixel_set_to_array), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo band_misc_suite = {"band_misc", NULL, NULL, band_misc_tests}; +void band_misc_suite_setup(void); +void band_misc_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("band_misc", NULL, NULL); + PG_ADD_TEST(suite, test_band_get_nearest_pixel); + PG_ADD_TEST(suite, test_band_get_pixel_of_value); + PG_ADD_TEST(suite, test_pixel_set_to_array); +} + diff --git a/raster/test/cunit/cu_band_stats.c b/raster/test/cunit/cu_band_stats.c index cd8ef8395..cf1534987 100644 --- a/raster/test/cunit/cu_band_stats.c +++ b/raster/test/cunit/cu_band_stats.c @@ -267,9 +267,11 @@ static void test_band_value_count() { } /* register tests */ -CU_TestInfo band_stats_tests[] = { - PG_TEST(test_band_stats), - PG_TEST(test_band_value_count), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo band_stats_suite = {"band_stats", NULL, NULL, band_stats_tests}; +void band_stats_suite_setup(void); +void band_stats_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("band_stats", NULL, NULL); + PG_ADD_TEST(suite, test_band_stats); + PG_ADD_TEST(suite, test_band_value_count); +} + diff --git a/raster/test/cunit/cu_gdal.c b/raster/test/cunit/cu_gdal.c index 657c71aa2..d6554cfbc 100644 --- a/raster/test/cunit/cu_gdal.c +++ b/raster/test/cunit/cu_gdal.c @@ -644,14 +644,16 @@ static void test_gdal_warp() { } /* register tests */ -CU_TestInfo gdal_tests[] = { - PG_TEST(test_gdal_configured), - PG_TEST(test_gdal_drivers), - PG_TEST(test_gdal_rasterize), - PG_TEST(test_gdal_polygonize), - PG_TEST(test_raster_to_gdal), - PG_TEST(test_gdal_to_raster), - PG_TEST(test_gdal_warp), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo gdal_suite = {"gdal", NULL, NULL, gdal_tests}; +void gdal_suite_setup(void); +void gdal_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("gdal", NULL, NULL); + PG_ADD_TEST(suite, test_gdal_configured); + PG_ADD_TEST(suite, test_gdal_drivers); + PG_ADD_TEST(suite, test_gdal_rasterize); + PG_ADD_TEST(suite, test_gdal_polygonize); + PG_ADD_TEST(suite, test_raster_to_gdal); + PG_ADD_TEST(suite, test_gdal_to_raster); + PG_ADD_TEST(suite, test_gdal_warp); +} + diff --git a/raster/test/cunit/cu_mapalgebra.c b/raster/test/cunit/cu_mapalgebra.c index 77ec8243f..e87b6c20d 100644 --- a/raster/test/cunit/cu_mapalgebra.c +++ b/raster/test/cunit/cu_mapalgebra.c @@ -1184,10 +1184,12 @@ static void test_raster_colormap() { } /* register tests */ -CU_TestInfo mapalgebra_tests[] = { - PG_TEST(test_raster_iterator), - PG_TEST(test_band_reclass), - PG_TEST(test_raster_colormap), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo mapalgebra_suite = {"mapalgebra", NULL, NULL, mapalgebra_tests}; +void mapalgebra_suite_setup(void); +void mapalgebra_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("mapalgebra", NULL, NULL); + PG_ADD_TEST(suite, test_raster_iterator); + PG_ADD_TEST(suite, test_band_reclass); + PG_ADD_TEST(suite, test_raster_colormap); +} + diff --git a/raster/test/cunit/cu_misc.c b/raster/test/cunit/cu_misc.c index 8993f5ef0..55790729d 100644 --- a/raster/test/cunit/cu_misc.c +++ b/raster/test/cunit/cu_misc.c @@ -143,10 +143,12 @@ static void test_util_gdal_open() { } /* register tests */ -CU_TestInfo misc_tests[] = { - PG_TEST(test_rgb_to_hsv), - PG_TEST(test_hsv_to_rgb), - PG_TEST(test_util_gdal_open), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo misc_suite = {"misc", NULL, NULL, misc_tests}; +void misc_suite_setup(void); +void misc_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("misc", NULL, NULL); + PG_ADD_TEST(suite, test_rgb_to_hsv); + PG_ADD_TEST(suite, test_hsv_to_rgb); + PG_ADD_TEST(suite, test_util_gdal_open); +} + diff --git a/raster/test/cunit/cu_pixtype.c b/raster/test/cunit/cu_pixtype.c index d7d11b613..45333a35e 100644 --- a/raster/test/cunit/cu_pixtype.c +++ b/raster/test/cunit/cu_pixtype.c @@ -228,13 +228,15 @@ static void test_pixtype_compare_clamped_values() { } /* register tests */ -CU_TestInfo pixtype_tests[] = { - PG_TEST(test_pixtype_size), - PG_TEST(test_pixtype_alignment), - PG_TEST(test_pixtype_name), - PG_TEST(test_pixtype_index_from_name), - PG_TEST(test_pixtype_get_min_value), - PG_TEST(test_pixtype_compare_clamped_values), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo pixtype_suite = {"pixtype", NULL, NULL, pixtype_tests}; +void pixtype_suite_setup(void); +void pixtype_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("pixtype", NULL, NULL); + PG_ADD_TEST(suite, test_pixtype_size); + PG_ADD_TEST(suite, test_pixtype_alignment); + PG_ADD_TEST(suite, test_pixtype_name); + PG_ADD_TEST(suite, test_pixtype_index_from_name); + PG_ADD_TEST(suite, test_pixtype_get_min_value); + PG_ADD_TEST(suite, test_pixtype_compare_clamped_values); +} + diff --git a/raster/test/cunit/cu_raster_basics.c b/raster/test/cunit/cu_raster_basics.c index 4a600c81d..98d640a1a 100644 --- a/raster/test/cunit/cu_raster_basics.c +++ b/raster/test/cunit/cu_raster_basics.c @@ -205,13 +205,15 @@ static void test_raster_replace_band() { } /* register tests */ -CU_TestInfo raster_basics_tests[] = { - PG_TEST(test_raster_new), - PG_TEST(test_raster_empty), - PG_TEST(test_raster_metadata), - PG_TEST(test_raster_clone), - PG_TEST(test_raster_from_band), - PG_TEST(test_raster_replace_band), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo raster_basics_suite = {"raster_basics", NULL, NULL, raster_basics_tests}; +void raster_basics_suite_setup(void); +void raster_basics_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("raster_basics", NULL, NULL); + PG_ADD_TEST(suite, test_raster_new); + PG_ADD_TEST(suite, test_raster_empty); + PG_ADD_TEST(suite, test_raster_metadata); + PG_ADD_TEST(suite, test_raster_clone); + PG_ADD_TEST(suite, test_raster_from_band); + PG_ADD_TEST(suite, test_raster_replace_band); +} + diff --git a/raster/test/cunit/cu_raster_geometry.c b/raster/test/cunit/cu_raster_geometry.c index 7ab31ae5b..d1309f361 100644 --- a/raster/test/cunit/cu_raster_geometry.c +++ b/raster/test/cunit/cu_raster_geometry.c @@ -572,13 +572,15 @@ static void test_raster_pixel_as_polygon() { } /* register tests */ -CU_TestInfo raster_geometry_tests[] = { - PG_TEST(test_raster_envelope), - PG_TEST(test_raster_envelope_geom), - PG_TEST(test_raster_convex_hull), - PG_TEST(test_raster_surface), - PG_TEST(test_raster_perimeter), - PG_TEST(test_raster_pixel_as_polygon), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo raster_geometry_suite = {"raster_geometry", NULL, NULL, raster_geometry_tests}; +void raster_geometry_suite_setup(void); +void raster_geometry_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("raster_geometry", NULL, NULL); + PG_ADD_TEST(suite, test_raster_envelope); + PG_ADD_TEST(suite, test_raster_envelope_geom); + PG_ADD_TEST(suite, test_raster_convex_hull); + PG_ADD_TEST(suite, test_raster_surface); + PG_ADD_TEST(suite, test_raster_perimeter); + PG_ADD_TEST(suite, test_raster_pixel_as_polygon); +} + diff --git a/raster/test/cunit/cu_raster_misc.c b/raster/test/cunit/cu_raster_misc.c index 458ecb5b4..705c3e441 100644 --- a/raster/test/cunit/cu_raster_misc.c +++ b/raster/test/cunit/cu_raster_misc.c @@ -205,11 +205,13 @@ static void test_raster_compute_skewed_raster() { } /* register tests */ -CU_TestInfo raster_misc_tests[] = { - PG_TEST(test_raster_cell_to_geopoint), - PG_TEST(test_raster_geopoint_to_cell), - PG_TEST(test_raster_from_two_rasters), - PG_TEST(test_raster_compute_skewed_raster), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo raster_misc_suite = {"raster_misc", NULL, NULL, raster_misc_tests}; +void raster_misc_suite_setup(void); +void raster_misc_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("raster_misc", NULL, NULL); + PG_ADD_TEST(suite, test_raster_cell_to_geopoint); + PG_ADD_TEST(suite, test_raster_geopoint_to_cell); + PG_ADD_TEST(suite, test_raster_from_two_rasters); + PG_ADD_TEST(suite, test_raster_compute_skewed_raster); +} + diff --git a/raster/test/cunit/cu_raster_wkb.c b/raster/test/cunit/cu_raster_wkb.c index 72bf9e724..0533632ca 100644 --- a/raster/test/cunit/cu_raster_wkb.c +++ b/raster/test/cunit/cu_raster_wkb.c @@ -809,8 +809,10 @@ static void test_raster_wkb() { } /* register tests */ -CU_TestInfo raster_wkb_tests[] = { - PG_TEST(test_raster_wkb), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo raster_wkb_suite = {"raster_wkb", NULL, NULL, raster_wkb_tests}; +void raster_wkb_suite_setup(void); +void raster_wkb_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("raster_wkb", NULL, NULL); + PG_ADD_TEST(suite, test_raster_wkb); +} + diff --git a/raster/test/cunit/cu_spatial_relationship.c b/raster/test/cunit/cu_spatial_relationship.c index 342f72287..f99e78b01 100644 --- a/raster/test/cunit/cu_spatial_relationship.c +++ b/raster/test/cunit/cu_spatial_relationship.c @@ -4779,17 +4779,19 @@ static void test_raster_same_alignment() { } /* register tests */ -CU_TestInfo spatial_relationship_tests[] = { - PG_TEST(test_raster_geos_overlaps), - PG_TEST(test_raster_geos_touches), - PG_TEST(test_raster_geos_contains), - PG_TEST(test_raster_geos_contains_properly), - PG_TEST(test_raster_geos_covers), - PG_TEST(test_raster_geos_covered_by), - PG_TEST(test_raster_within_distance), - PG_TEST(test_raster_fully_within_distance), - PG_TEST(test_raster_intersects), - PG_TEST(test_raster_same_alignment), - CU_TEST_INFO_NULL -}; -CU_SuiteInfo spatial_relationship_suite = {"spatial_relationship", NULL, NULL, spatial_relationship_tests}; +void spatial_relationship_suite_setup(void); +void spatial_relationship_suite_setup(void) +{ + CU_pSuite suite = CU_add_suite("spatial_relationship", NULL, NULL); + PG_ADD_TEST(suite, test_raster_geos_overlaps); + PG_ADD_TEST(suite, test_raster_geos_touches); + PG_ADD_TEST(suite, test_raster_geos_contains); + PG_ADD_TEST(suite, test_raster_geos_contains_properly); + PG_ADD_TEST(suite, test_raster_geos_covers); + PG_ADD_TEST(suite, test_raster_geos_covered_by); + PG_ADD_TEST(suite, test_raster_within_distance); + PG_ADD_TEST(suite, test_raster_fully_within_distance); + PG_ADD_TEST(suite, test_raster_intersects); + PG_ADD_TEST(suite, test_raster_same_alignment); +} + diff --git a/raster/test/cunit/cu_tester.c b/raster/test/cunit/cu_tester.c index c57d9a998..eb67af02b 100644 --- a/raster/test/cunit/cu_tester.c +++ b/raster/test/cunit/cu_tester.c @@ -19,19 +19,38 @@ static void cu_error_reporter(const char *fmt, va_list ap); -/* ADD YOUR SUITE HERE (1 of 2) */ -extern CU_SuiteInfo pixtype_suite; -extern CU_SuiteInfo raster_basics_suite; -extern CU_SuiteInfo band_basics_suite; -extern CU_SuiteInfo raster_wkb_suite; -extern CU_SuiteInfo gdal_suite; -extern CU_SuiteInfo raster_geometry_suite; -extern CU_SuiteInfo raster_misc_suite; -extern CU_SuiteInfo band_stats_suite; -extern CU_SuiteInfo band_misc_suite; -extern CU_SuiteInfo mapalgebra_suite; -extern CU_SuiteInfo spatial_relationship_suite; -extern CU_SuiteInfo misc_suite; +/* ADD YOUR SUITE SETUP FUNCTION HERE (1 of 2) */ +extern void pixtype_suite_setup(void); +extern void raster_basics_suite_setup(void); +extern void band_basics_suite_setup(void); +extern void raster_wkb_suite_setup(void); +extern void gdal_suite_setup(void); +extern void raster_geometry_suite_setup(void); +extern void raster_misc_suite_setup(void); +extern void band_stats_suite_setup(void); +extern void band_misc_suite_setup(void); +extern void mapalgebra_suite_setup(void); +extern void spatial_relationship_suite_setup(void); +extern void misc_suite_setup(void); + +/* AND ADD YOUR SUITE SETUP FUNCTION HERE (2 of 2) */ +PG_SuiteSetup setupfuncs[] = +{ + pixtype_suite_setup, + raster_basics_suite_setup, + band_basics_suite_setup, + raster_wkb_suite_setup, + gdal_suite_setup, + raster_geometry_suite_setup, + raster_misc_suite_setup, + band_stats_suite_setup, + band_misc_suite_setup, + mapalgebra_suite_setup, + spatial_relationship_suite_setup, + misc_suite_setup, + NULL +}; + /* ** The main() function for setting up and running the tests. @@ -40,24 +59,6 @@ extern CU_SuiteInfo misc_suite; */ int main(int argc, char *argv[]) { - /* ADD YOUR SUITE HERE (2 of 2) */ - CU_SuiteInfo suites[] = - { - pixtype_suite, - raster_basics_suite, - band_basics_suite, - raster_wkb_suite, - gdal_suite, - raster_geometry_suite, - raster_misc_suite, - band_stats_suite, - band_misc_suite, - spatial_relationship_suite, - mapalgebra_suite, - misc_suite, - CU_SUITE_INFO_NULL - }; - int index; char *suite_name; CU_pSuite suite_to_run; @@ -67,6 +68,7 @@ int main(int argc, char *argv[]) CU_pTestRegistry registry; int num_run; int num_failed; + PG_SuiteSetup *setupfunc = setupfuncs; /* install the custom error handler */ lwgeom_set_handlers(0, 0, 0, cu_error_reporter, 0); @@ -80,11 +82,10 @@ int main(int argc, char *argv[]) } /* Register all the test suites. */ - if (CUE_SUCCESS != CU_register_suites(suites)) + while ( *setupfunc ) { - errCode = CU_get_error(); - printf(" Error attempting to register test suites: %d. See CUError.h for error code list.\n", errCode); - return errCode; + (*setupfunc)(); + setupfunc++; } /* Run all tests using the CUnit Basic interface */ diff --git a/raster/test/cunit/cu_tester.h b/raster/test/cunit/cu_tester.h index fdd44bc1c..7c8f9bbce 100644 --- a/raster/test/cunit/cu_tester.h +++ b/raster/test/cunit/cu_tester.h @@ -14,9 +14,10 @@ #include "../../../postgis_config.h" #include "../../raster_config.h" -#define PG_TEST(test_func) { #test_func, test_func } #define MAX_CUNIT_MSG_LENGTH 512 +#define PG_ADD_TEST(suite, testfunc) CU_add_test(suite, #testfunc, testfunc) + /* Contains the most recent error message generated by rterror. */ char cu_error_msg[MAX_CUNIT_MSG_LENGTH+1]; @@ -32,3 +33,6 @@ rt_band cu_add_band( rt_pixtype pixtype, int hasnodata, double nodataval ); + +/* Our internal callback to register Suites with the main tester */ +typedef void (*PG_SuiteSetup)(void);