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();
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)
*
**********************************************************************/
-#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)
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
}
/* 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);
+}
+
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.
*/
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;
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);
}
/* 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 */
#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];
rt_pixtype pixtype,
int hasnodata, double nodataval
);
+
+/* Our internal callback to register Suites with the main tester */
+typedef void (*PG_SuiteSetup)(void);