]> granicus.if.org Git - postgis/commitdiff
Update loader regression test suite to add a simple test for shp2pgsql (much as we...
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Sat, 2 Jul 2011 13:43:35 +0000 (13:43 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Sat, 2 Jul 2011 13:43:35 +0000 (13:43 +0000)
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

14 files changed:
loader/cunit/Makefile.in
loader/cunit/cu_pgsql2shp.c
loader/cunit/cu_shp2pgsql.c [new file with mode: 0644]
loader/cunit/cu_shp2pgsql.h [new file with mode: 0644]
loader/cunit/cu_tester.c
loader/cunit/cu_tester.h
loader/pgsql2shp-cli.c
loader/pgsql2shp-core.c
loader/pgsql2shp-core.h
loader/shp2pgsql-cli.c
loader/shp2pgsql-core.c
loader/shp2pgsql-core.h
loader/shp2pgsql-gui.c
loader/shpcommon.c

index 0d30c6160284f7e0b3bca77c9274b2e1474655e9..6ca57be42cbc6f9428afc0b4d5d3ea17f7f82789 100644 (file)
@@ -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@
index 3d0264e80700b6b2d92f40bfd07838916bdaffc5..5cf44c53b485950d825dc9593eec0b9222b46a72 100644 (file)
@@ -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 (file)
index 0000000..d668f1b
--- /dev/null
@@ -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 (file)
index 0000000..3a14aed
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "CUnit/Basic.h"
+
+/***********************************************************************
+** for Computational Geometry Suite
+*/
+
+/* Admin functions */
+int init_shp2pgsql_suite(void);
+int clean_shp2pgsql_suite(void);
+
+#endif /* __cu_shp2pgsql_h__ */
index 76f3f71fa5316f990c8f4ed1ca45def442c4d615..333a1e13d573cf9cb40926fdccd24914c140c608 100644 (file)
@@ -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())
        {
index d5c082ed69bd3d2fed2ee3b97cf34269d3a72766..5d6c6ff19c2dce8f04fc7996f64d36712c391e32 100644 (file)
@@ -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__ */
index 36ec5b023bbc608d822e700cc7170c4188043a34..c97383a5d2926dbd6370dcce9739f6a7d8f5bf8c 100644 (file)
@@ -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)
        {
index 985a1f31060c41a7962ac24a4e7e99af8cc13b48..7f0a69e2e9526aac231d945bf04204d2758dc376 100644 (file)
@@ -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;
index 19136d04667da7ca878d339b29e9818abdddd76c..547f917911497c0280287abec10f79813b103a34 100644 (file)
@@ -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);
index d10bdc82d6afd3d6b2250a5777cf8d3f49c9380c..d06d20bcf85064d7639e52195ba92470bd48a1d5 100644 (file)
@@ -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)
index 7a22d9f63c90a33253791f146e8fefda61b7e38d..798d6552089b603cefd37f0dbca42b0691da621c 100644 (file)
@@ -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;
index 85a90fff941240dea5088c011c56886790926bd4..2c2cf0336adf2bd34ab46c075c6ad373fce66b0c 100644 (file)
@@ -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);
index 4b8a188b8178ed8f50a755ec8a6e8277f07680b2..1da94ce3c3a324decb94bc4e3aa905bfc712f57c 100644 (file)
@@ -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;
index 0e006f39f578e6941615538b93f1b2ef7988f293..fc1e1710c5dcaae24b2c4a7e75a1b92b53071d84 100644 (file)
 #include <stdlib.h>
 #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