diff --git a/lib/cunit/Makefile b/lib/cunit/Makefile index d6615a3..84c173a 100644 --- a/lib/cunit/Makefile +++ b/lib/cunit/Makefile @@ -11,7 +11,8 @@ OBJS = \ cu_tester.o \ cu_pc_schema.o \ cu_pc_point.o \ - cu_pc_patch.o + cu_pc_patch.o \ + cu_pc_patch_ght.o # Build the unit tester all: $(EXE) diff --git a/lib/cunit/cu_pc_patch_ght.c b/lib/cunit/cu_pc_patch_ght.c new file mode 100644 index 0000000..72f57c1 --- /dev/null +++ b/lib/cunit/cu_pc_patch_ght.c @@ -0,0 +1,101 @@ +/*********************************************************************** +* cu_pc_schema.c +* +* Testing for the schema API functions +* +* Portions Copyright (c) 2012, OpenGeo +* +***********************************************************************/ + +#include "CUnit/Basic.h" +#include "cu_tester.h" + +/* GLOBALS ************************************************************/ + +static PCSCHEMA *simpleschema = NULL; +static const char *simplexmlfile = "data/simple-schema-fine.xml"; + +/* Setup/teardown for this suite */ +static int +init_suite(void) +{ + char *xmlstr = file_to_str(simplexmlfile); + int rv = pc_schema_from_xml(xmlstr, &simpleschema); + pcfree(xmlstr); + if ( rv == PC_FAILURE ) return 1; + + return 0; +} + +static int +clean_suite(void) +{ + pc_schema_free(simpleschema); + return 0; +} + +/* TESTS **************************************************************/ + +#ifdef HAVE_LIBGHT + +static void +test_patch_ght() +{ + PCPOINT *pt; + int i; + int npts = 100; + PCPOINTLIST *pl1, *pl2; + PCPATCH_GHT *pag; + PCPATCH_UNCOMPRESSED *pu; + + pl1 = pc_pointlist_make(npts); + + for ( i = 0; i < npts; i++ ) + { + pt = pc_point_make(simpleschema); + pc_point_set_double_by_name(pt, "x", 45 + i*0.000004); + pc_point_set_double_by_name(pt, "y", 45 + i*0.000001666); + pc_point_set_double_by_name(pt, "Z", 10 + i*0.34); + pc_point_set_double_by_name(pt, "intensity", 10); + pc_pointlist_add_point(pl1, pt); + } + + pag = pc_patch_ght_from_pointlist(pl1); + pu = pc_patch_uncompressed_from_ght(pag); + CU_ASSERT_EQUAL(npts, pag->npoints); + CU_ASSERT_EQUAL(npts, pu->npoints); + + CU_ASSERT_DOUBLE_EQUAL(pag->xmax, 45.0004, 0.0001); + CU_ASSERT_DOUBLE_EQUAL(pag->ymax, 45.000165, 0.000001); + + // pl2 = pc_pointlist_from_uncompressed(pu); + // for ( i = 0; i < npts; i++ ) + // { + // PCPOINT *pt = pc_pointlist_get_point(pl2, i); + // double x, y, z, ints; + // pc_point_get_double_by_name(pt, "x", &x); + // pc_point_get_double_by_name(pt, "y", &y); + // pc_point_get_double_by_name(pt, "Z", &z); + // pc_point_get_double_by_name(pt, "intensity", &ints); + // printf("(%g %g %g) %g\n", x, y, z, ints); + // } + // pc_pointlist_free(pl2); + + pc_patch_uncompressed_free(pu); + pc_patch_ght_free(pag); + pc_pointlist_free(pl1); +} + + +#endif /* HAVE_LIBGHT */ + +/* REGISTER ***********************************************************/ + +CU_TestInfo ght_tests[] = { +#ifdef HAVE_LIBGHT + PC_TEST(test_patch_ght), +#endif + CU_TEST_INFO_NULL +}; + +CU_SuiteInfo ght_suite = {"ght", init_suite, clean_suite, ght_tests}; diff --git a/lib/cunit/cu_tester.c b/lib/cunit/cu_tester.c index d557e36..349fdce 100644 --- a/lib/cunit/cu_tester.c +++ b/lib/cunit/cu_tester.c @@ -16,6 +16,7 @@ extern CU_SuiteInfo schema_suite; extern CU_SuiteInfo patch_suite; extern CU_SuiteInfo point_suite; +extern CU_SuiteInfo ght_suite; /* ** The main() function for setting up and running the tests. @@ -30,6 +31,7 @@ int main(int argc, char *argv[]) schema_suite, patch_suite, point_suite, + ght_suite, CU_SUITE_INFO_NULL }; diff --git a/lib/cunit/data/simple-schema-fine.xml b/lib/cunit/data/simple-schema-fine.xml new file mode 100644 index 0000000..50e6918 --- /dev/null +++ b/lib/cunit/data/simple-schema-fine.xml @@ -0,0 +1,45 @@ + + + + 1 + 4 + X coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. + X + int32_t + 0.000001 + + + 2 + 4 + Y coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. + Y + int32_t + 0.000001 + + + 3 + 4 + Z coordinate as a long integer. You must use the scale and offset information of the header to determine the double value. + Z + int32_t + 0.01 + + + 4 + 2 + The intensity value is the integer representation of the pulse return magnitude. This value is optional and system specific. However, it should always be included if available. + Intensity + uint16_t + 1 + + + dimensional + + + + + + + 4326 + + diff --git a/lib/pc_api.h b/lib/pc_api.h index 0a69283..b836786 100644 --- a/lib/pc_api.h +++ b/lib/pc_api.h @@ -220,10 +220,6 @@ void pc_set_handlers(pc_allocator allocator, pc_reallocator reallocator, pc_deallocator deallocator, pc_message_handler error_handler, pc_message_handler info_handler, pc_message_handler warning_handler); -void pc_set_ght_handlers(pc_allocator allocator, pc_reallocator reallocator, - pc_deallocator deallocator, pc_message_handler error_handler, - pc_message_handler info_handler, pc_message_handler warning_handler); - /** Set program to use system memory allocators and messaging */ void pc_install_default_handlers(void); diff --git a/lib/pc_mem.c b/lib/pc_mem.c index 150eacd..c92bc2b 100644 --- a/lib/pc_mem.c +++ b/lib/pc_mem.c @@ -88,8 +88,15 @@ void pc_install_default_handlers(void) pc_context.realloc = default_reallocator; pc_context.free = default_freeor; pc_context.err = default_error_handler; - pc_context.warn = default_warn_handler; pc_context.info = default_info_handler; + pc_context.warn = default_warn_handler; + +#ifdef HAVE_LIBGHT + ght_set_handlers((void *)default_allocator, (void *)default_reallocator, + (void *)default_freeor, (void *)default_error_handler, + (void *)default_info_handler, (void *)default_warn_handler); +#endif + } void pc_set_handlers(pc_allocator allocator, pc_reallocator reallocator, @@ -102,18 +109,15 @@ void pc_set_handlers(pc_allocator allocator, pc_reallocator reallocator, pc_context.err = error_handler; pc_context.warn = warn_handler; pc_context.info = info_handler; -} - -void pc_set_ght_handlers(pc_allocator allocator, pc_reallocator reallocator, - pc_deallocator deallocator, pc_message_handler error_handler, - pc_message_handler info_handler, pc_message_handler warn_handler) -{ + #ifdef HAVE_LIBGHT - ght_set_handlers((void *)allocator, (void *)reallocator, - (void *)deallocator, (void *)error_handler, + ght_set_handlers((void *)allocator, (void *)reallocator, + (void *)deallocator, (void *)error_handler, (void *)info_handler, (void *)warn_handler); #endif + return; + } diff --git a/pgsql/pc_pgsql.c b/pgsql/pc_pgsql.c index 01e4506..c8173e8 100644 --- a/pgsql/pc_pgsql.c +++ b/pgsql/pc_pgsql.c @@ -104,10 +104,6 @@ _PG_init(void) pgsql_free, pgsql_error, pgsql_info, pgsql_warn); - /* This will just no-op if LibGHT is not present */ - pc_set_ght_handlers(pgsql_alloc, pgsql_realloc, - pgsql_free, pgsql_error, - pgsql_info, pgsql_warn); } /* Module unload callback */