From: Mark Cave-Ayland Date: Sat, 2 Jul 2011 13:43:35 +0000 (+0000) Subject: Update loader regression test suite to add a simple test for shp2pgsql (much as we... X-Git-Tag: 2.0.0alpha1~1291 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=baeeefeb22b2192e06ab3af193e98e42aef93e18;p=postgis Update loader regression test suite to add a simple test for shp2pgsql (much as we now do for pgsql2shp). Note that these tests aren't completely comprehensive and should be expanded, with the long term aim of moving the loader regression tests out of the main regression harness and into CUnit instead. git-svn-id: http://svn.osgeo.org/postgis/trunk@7551 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/loader/cunit/Makefile.in b/loader/cunit/Makefile.in index 0d30c6160..6ca57be42 100644 --- a/loader/cunit/Makefile.in +++ b/loader/cunit/Makefile.in @@ -42,6 +42,7 @@ LDFLAGS = -lm $(GETTEXT_LDFLAGS) $(PGSQL_FE_LDFLAGS) $(ICONV_LDFLAGS) $(CUNIT_LD # Object files OBJS= \ cu_pgsql2shp.o \ + cu_shp2pgsql.o \ cu_tester.o LOADER_OBJS= \ @@ -50,7 +51,8 @@ LOADER_OBJS= \ ../getopt.o \ ../shpcommon.o \ ../safileio.o \ - ../pgsql2shp-core.o + ../pgsql2shp-core.o \ + ../shp2pgsql-core.o # We test this variable later to see if we're building the GUI gtk_build = @GTK_BUILD@ diff --git a/loader/cunit/cu_pgsql2shp.c b/loader/cunit/cu_pgsql2shp.c index 3d0264e80..5cf44c53b 100644 --- a/loader/cunit/cu_pgsql2shp.c +++ b/loader/cunit/cu_pgsql2shp.c @@ -18,8 +18,8 @@ void test_ShpDumperCreate(void); void test_ShpDumperDestroy(void); -SHPDUMPERCONFIG *config; -SHPDUMPERSTATE *state; +SHPDUMPERCONFIG *dumper_config; +SHPDUMPERSTATE *dumper_state; /* ** Called from test harness to register the tests in this file. @@ -65,14 +65,14 @@ int clean_pgsql2shp_suite(void) void test_ShpDumperCreate(void) { - config = (SHPDUMPERCONFIG*)calloc(1, sizeof(SHPDUMPERCONFIG)); - set_config_defaults(config); - state = ShpDumperCreate(config); - CU_ASSERT_PTR_NOT_NULL(state); - CU_ASSERT_EQUAL(state->config->fetchsize, 100); + dumper_config = (SHPDUMPERCONFIG*)calloc(1, sizeof(SHPDUMPERCONFIG)); + set_dumper_config_defaults(dumper_config); + dumper_state = ShpDumperCreate(dumper_config); + CU_ASSERT_PTR_NOT_NULL(dumper_state); + CU_ASSERT_EQUAL(dumper_state->config->fetchsize, 100); } void test_ShpDumperDestroy(void) { - ShpDumperDestroy(state); + ShpDumperDestroy(dumper_state); } diff --git a/loader/cunit/cu_shp2pgsql.c b/loader/cunit/cu_shp2pgsql.c new file mode 100644 index 000000000..d668f1b4d --- /dev/null +++ b/loader/cunit/cu_shp2pgsql.c @@ -0,0 +1,78 @@ +/********************************************************************** + * $Id: cu_shp2pgsql.c 5674 2010-06-03 02:04:15Z mleslie $ + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * Copyright 2010 LISAsoft Pty Ltd + * + * This is free software; you can redistribute and/or modify it under + * the terms of the GNU General Public Licence. See the COPYING file. + * + **********************************************************************/ + +#include "cu_shp2pgsql.h" +#include "cu_tester.h" +#include "../shp2pgsql-core.h" + +/* Test functions */ +void test_ShpLoaderCreate(void); +void test_ShpLoaderDestroy(void); + +SHPLOADERCONFIG *loader_config; +SHPLOADERSTATE *loader_state; + +/* +** Called from test harness to register the tests in this file. +*/ +CU_pSuite register_shp2pgsql_suite(void) +{ + CU_pSuite pSuite; + pSuite = CU_add_suite("Shapefile Loader File shp2pgsql Test", init_shp2pgsql_suite, clean_shp2pgsql_suite); + if (NULL == pSuite) + { + CU_cleanup_registry(); + return NULL; + } + + if ( + (NULL == CU_add_test(pSuite, "test_ShpLoaderCreate()", test_ShpLoaderCreate)) || + (NULL == CU_add_test(pSuite, "test_ShpLoaderDestroy()", test_ShpLoaderDestroy)) + ) + { + CU_cleanup_registry(); + return NULL; + } + return pSuite; +} + +/* +** The suite initialization function. +** Create any re-used objects. +*/ +int init_shp2pgsql_suite(void) +{ + return 0; +} + +/* +** The suite cleanup function. +** Frees any global objects. +*/ +int clean_shp2pgsql_suite(void) +{ + return 0; +} + +void test_ShpLoaderCreate(void) +{ + loader_config = (SHPLOADERCONFIG*)calloc(1, sizeof(SHPLOADERCONFIG)); + set_loader_config_defaults(loader_config); + loader_state = ShpLoaderCreate(loader_config); + CU_ASSERT_PTR_NOT_NULL(loader_state); + CU_ASSERT_STRING_EQUAL(loader_state->config->encoding, ENCODING_DEFAULT); +} + +void test_ShpLoaderDestroy(void) +{ + ShpLoaderDestroy(loader_state); +} diff --git a/loader/cunit/cu_shp2pgsql.h b/loader/cunit/cu_shp2pgsql.h new file mode 100644 index 000000000..3a14aed08 --- /dev/null +++ b/loader/cunit/cu_shp2pgsql.h @@ -0,0 +1,28 @@ +/********************************************************************** + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * Copyright 2010 LISAsoft Pty Ltd + * + * This is free software; you can redistribute and/or modify it under + * the terms of the GNU General Public Licence. See the COPYING file. + * + **********************************************************************/ + +#ifndef __cu_shp2pgsql_h__ +#define __cu_shp2pgsql_h__ + +#include +#include +#include +#include "CUnit/Basic.h" + +/*********************************************************************** +** for Computational Geometry Suite +*/ + +/* Admin functions */ +int init_shp2pgsql_suite(void); +int clean_shp2pgsql_suite(void); + +#endif /* __cu_shp2pgsql_h__ */ diff --git a/loader/cunit/cu_tester.c b/loader/cunit/cu_tester.c index 76f3f71fa..333a1e13d 100644 --- a/loader/cunit/cu_tester.c +++ b/loader/cunit/cu_tester.c @@ -35,7 +35,14 @@ int main() return CU_get_error(); } #endif - + + /* Add the shp2pgsql test suite */ + if (NULL == register_shp2pgsql_suite()) + { + CU_cleanup_registry(); + return CU_get_error(); + } + /* Add the pgsql2shp test suite */ if (NULL == register_pgsql2shp_suite()) { diff --git a/loader/cunit/cu_tester.h b/loader/cunit/cu_tester.h index d5c082ed6..5d6c6ff19 100644 --- a/loader/cunit/cu_tester.h +++ b/loader/cunit/cu_tester.h @@ -15,6 +15,7 @@ #define __cu_tester_h__ CU_pSuite register_list_suite(void); +CU_pSuite register_shp2pgsql_suite(void); CU_pSuite register_pgsql2shp_suite(void); #endif /* __cu_tester_h__ */ diff --git a/loader/pgsql2shp-cli.c b/loader/pgsql2shp-cli.c index 36ec5b023..c97383a5d 100644 --- a/loader/pgsql2shp-cli.c +++ b/loader/pgsql2shp-cli.c @@ -67,7 +67,7 @@ main(int argc, char **argv) /* Parse command line options and set configuration */ config = malloc(sizeof(SHPDUMPERCONFIG)); - set_config_defaults(config); + set_dumper_config_defaults(config); while ((c = pgis_getopt(argc, argv, "bf:h:du:p:P:g:rkm:")) != EOF) { diff --git a/loader/pgsql2shp-core.c b/loader/pgsql2shp-core.c index 985a1f310..7f0a69e2e 100644 --- a/loader/pgsql2shp-core.c +++ b/loader/pgsql2shp-core.c @@ -81,13 +81,6 @@ static const char * goodDBFValue(const char *in, char fieldType); char *convert_bytes_to_hex(uchar *ewkb, size_t size); -/* liblwgeom allocator callback - install the defaults (malloc/free/stdout/stderr) */ -void lwgeom_init_allocators() -{ - lwgeom_install_default_allocators(); -} - - static SHPObject * create_point(SHPDUMPERSTATE *state, LWPOINT *lwpoint) { @@ -1126,7 +1119,7 @@ getTableInfo(SHPDUMPERSTATE *state) /* Default configuration settings */ void -set_config_defaults(SHPDUMPERCONFIG *config) +set_dumper_config_defaults(SHPDUMPERCONFIG *config) { config->conn = malloc(sizeof(SHPCONNECTIONCONFIG)); config->conn->host = NULL; diff --git a/loader/pgsql2shp-core.h b/loader/pgsql2shp-core.h index 19136d046..547f91791 100644 --- a/loader/pgsql2shp-core.h +++ b/loader/pgsql2shp-core.h @@ -201,7 +201,7 @@ typedef struct shp_dumper_state /* Externally accessible functions */ -void set_config_defaults(SHPDUMPERCONFIG *config); +void set_dumper_config_defaults(SHPDUMPERCONFIG *config); char *shapetypename(int num); SHPDUMPERSTATE *ShpDumperCreate(SHPDUMPERCONFIG *config); diff --git a/loader/shp2pgsql-cli.c b/loader/shp2pgsql-cli.c index d10bdc82d..d06d20bcf 100644 --- a/loader/shp2pgsql-cli.c +++ b/loader/shp2pgsql-cli.c @@ -83,7 +83,7 @@ main (int argc, char **argv) /* Parse command line options and set configuration */ config = malloc(sizeof(SHPLOADERCONFIG)); - set_config_defaults(config); + set_loader_config_defaults(config); /* Keep the flag list alphabetic so it's easy to see what's left. */ while ((c = pgis_getopt(argc, argv, "acdeg:iknpr:s:wDGIN:ST:W:X:")) != EOF) diff --git a/loader/shp2pgsql-core.c b/loader/shp2pgsql-core.c index 7a22d9f63..798d65520 100644 --- a/loader/shp2pgsql-core.c +++ b/loader/shp2pgsql-core.c @@ -30,13 +30,6 @@ typedef struct struct_ring } Ring; -/* liblwgeom allocator callback - install the defaults (malloc/free/stdout/stderr) */ -void lwgeom_init_allocators() -{ - lwgeom_install_default_allocators(); -} - - /* * Internal functions */ @@ -750,7 +743,7 @@ strtolower(char *s) /* Default configuration settings */ void -set_config_defaults(SHPLOADERCONFIG *config) +set_loader_config_defaults(SHPLOADERCONFIG *config) { config->opt = 'c'; config->table = NULL; diff --git a/loader/shp2pgsql-core.h b/loader/shp2pgsql-core.h index 85a90fff9..2c2cf0336 100644 --- a/loader/shp2pgsql-core.h +++ b/loader/shp2pgsql-core.h @@ -222,7 +222,7 @@ typedef struct shp_loader_state /* Externally accessible functions */ void strtolower(char *s); void vasbappend(stringbuffer_t *sb, char *fmt, ... ); -void set_config_defaults(SHPLOADERCONFIG *config); +void set_loader_config_defaults(SHPLOADERCONFIG *config); SHPLOADERSTATE *ShpLoaderCreate(SHPLOADERCONFIG *config); int ShpLoaderOpenShape(SHPLOADERSTATE *state); diff --git a/loader/shp2pgsql-gui.c b/loader/shp2pgsql-gui.c index 4b8a188b8..1da94ce3c 100644 --- a/loader/shp2pgsql-gui.c +++ b/loader/shp2pgsql-gui.c @@ -2491,7 +2491,7 @@ main(int argc, char *argv[]) /* Parse command line options and set configuration */ config = malloc(sizeof(SHPLOADERCONFIG)); - set_config_defaults(config); + set_loader_config_defaults(config); /* Here we override any defaults for the GUI */ config->createindex = 1; diff --git a/loader/shpcommon.c b/loader/shpcommon.c index 0e006f39f..fc1e1710c 100644 --- a/loader/shpcommon.c +++ b/loader/shpcommon.c @@ -15,6 +15,14 @@ #include #include "shpcommon.h" + +/* liblwgeom allocator callback - install the defaults (malloc/free/stdout/stderr) */ +void lwgeom_init_allocators() +{ + lwgeom_install_default_allocators(); +} + + /** * Escape strings that are to be used as part of a PostgreSQL connection string. If no * characters require escaping, simply return the input pointer. Otherwise return a