]> granicus.if.org Git - postgis/commitdiff
preliminary cunit tests for x3d output functions
authorRegina Obe <lr@pcorp.us>
Mon, 11 Apr 2011 16:14:29 +0000 (16:14 +0000)
committerRegina Obe <lr@pcorp.us>
Mon, 11 Apr 2011 16:14:29 +0000 (16:14 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7016 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/Makefile.in
liblwgeom/cunit/cu_out_x3d.c [new file with mode: 0644]
liblwgeom/cunit/cu_tester.c

index 9201eb859f499583cb29f3b86cc7e72b0342ece3..51824f5edfecbc262d709b7eb4312267f7b4a080 100644 (file)
@@ -33,6 +33,7 @@ OBJS= \
        cu_out_kml.o \
        cu_out_geojson.o \
        cu_out_svg.o \
+       cu_out_x3d.o \
        cu_in_wkb.o \
        cu_in_wkt.o \
        cu_tester.o 
diff --git a/liblwgeom/cunit/cu_out_x3d.c b/liblwgeom/cunit/cu_out_x3d.c
new file mode 100644 (file)
index 0000000..20e8318
--- /dev/null
@@ -0,0 +1,151 @@
+/**********************************************************************
+ * $Id: cu_out_geojson.c 6212 2010-11-30 20:11:13Z pramsey $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2010 Olivier Courtin <olivier.courtin@oslandia.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "CUnit/Basic.h"
+
+#include "liblwgeom_internal.h"
+#include "cu_tester.h"
+
+static void do_x3d3_test(char * in, char * out, char * srs, int precision)
+{
+       LWGEOM *g;
+       char * h;
+
+       g = lwgeom_from_ewkt(in, PARSER_CHECK_NONE);
+       h = lwgeom_to_x3d3(g, srs, precision, 0, "");
+
+       if (strcmp(h, out))
+               fprintf(stderr, "\nIn:   %s\nOut:  %s\nTheo: %s\n", in, h, out);
+
+       CU_ASSERT_STRING_EQUAL(h, out);
+
+       lwgeom_free(g);
+       lwfree(h);
+}
+
+
+static void do_x3d3_unsupported(char * in, char * out)
+{
+       LWGEOM *g;
+       char *h;
+
+       g = lwgeom_from_ewkt(in, PARSER_CHECK_NONE);
+       h = lwgeom_to_x3d3(g, NULL, 0, 0, "");
+
+       if (strcmp(cu_error_msg, out))
+               fprintf(stderr, "\nIn:   %s\nOut:  %s\nTheo: %s\n",
+                       in, cu_error_msg, out);
+
+       CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
+       cu_error_msg_reset();
+
+       lwfree(h);
+       lwgeom_free(g);
+}
+
+
+static void out_x3d3_test_precision(void)
+{
+       /* 0 precision, i.e a round */
+       do_x3d3_test(
+           "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
+           "1 1 2",
+           NULL, 0);
+
+       /* 3 digits precision */
+       do_x3d3_test(
+           "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
+           "1.111 1.111 2.111",
+           NULL, 3);
+
+       /* 9 digits precision */
+       do_x3d3_test(
+           "POINT(1.2345678901234 1.2345678901234 4.123456789001)",
+           "1.23456789 1.23456789 4.123456789",
+           NULL, 9);
+
+       /* huge data */
+       do_x3d3_test(
+           "POINT(1E300 -105E-153 4E300)'",
+           "1e+300 -0 4e+300",
+           NULL, 0);
+}
+
+static void out_x3d3_test_geoms(void)
+{
+       /* Linestring */
+       do_x3d3_test(
+           "LINESTRING(0 1 5,2 3 6,4 5 7)",
+           "<LineSet  vertexCount='3'><Coordinate point='0 1 5 2 3 6 4 5 7' /></LineSet>",
+           NULL, 0);
+
+       /* TODO: Fix Polygon */
+       /** do_x3d3_test(
+           "POLYGON((0 1 5,2 3 5,4 5 5,0 1 5))",
+           "0 1 5 2 3 5 4 5 5",
+           NULL, 0); **/
+
+       /* TODO: Polygon - with internal ring - the answer is clearly wrong */
+       /** do_x3d3_test(
+           "POLYGON((0 1 3,2 3 3,4 5 3,0 1 3),(6 7 3,8 9 3,10 11 3,6 7 3))",
+           "0 1 3 2 3 3 4 5 36 7 3 8 9 3 10 11 3 ",
+           NULL, 0); **/
+
+       /* Multiline */
+       do_x3d3_test(
+           "MULTILINESTRING Z((0 1 1,2 3 4,4 5 5),(6 7 5,8 9 8,10 11 5))",
+           "<IndexedLineSet  coordIndex='0 1 2 -1 3 4 5'><Coordinate point='0 1 1 2 3 4 4 5 5 6 7 5 8 9 8 10 11 5 ' /></IndexedLineSet>",
+           NULL, 0);
+
+       /* MultiPolygon */
+       do_x3d3_test(
+           "MULTIPOLYGON(((0 1 1,2 3 1,4 5 1,0 1 1)),((6 7 1,8 9 1,10 11 1,6 7 1)))",
+           "<IndexedFaceSet  coordIndex='0 1 2 -1 3 4 5'><Coordinate point='0 1 1 2 3 1 4 5 1 6 7 1 8 9 1 10 11 1 ' /></IndexedFaceSet>",
+           NULL, 0);
+
+       /* TODO: returns garbage at moment correctly implement GeometryCollection -- */
+       /** do_x3d3_test(
+           "GEOMETRYCOLLECTION(POINT(0 1 3),LINESTRING(2 3 3,4 5 3))",
+           "",
+           NULL, 0); **/
+
+       /* TODO:  Implement Empty GeometryCollection correctly or throw a not-implemented */
+       /** do_x3d3_test(
+           "GEOMETRYCOLLECTION EMPTY",
+           "",
+           NULL, 0); **/
+
+       /* CircularString */
+       do_x3d3_unsupported(
+           "CIRCULARSTRING(-2 0 1,0 2 1,2 0 1,0 2 1,2 4 1)",
+           "lwgeom_to_x3d3: 'CircularString' geometry type not supported");
+
+       /* CompoundString */
+       do_x3d3_unsupported(
+           "COMPOUNDCURVE(CIRCULARSTRING(0 0 1,1 1 1,1 0 1),(1 0 1,0 1 1))",
+           "lwgeom_to_x3d3: 'CompoundString' geometry type not supported");
+
+}
+
+/*
+** Used by test harness to register the tests in this file.
+*/
+CU_TestInfo out_x3d_tests[] =
+{
+       PG_TEST(out_x3d3_test_precision),
+       PG_TEST(out_x3d3_test_geoms),
+       CU_TEST_INFO_NULL
+};
+CU_SuiteInfo out_x3d_suite = {"X3D Out Suite",  NULL,  NULL, out_x3d_tests};
index 83d659f2d568bdc4f7d5c1510c5ea7e32edb4c13..ae32cadf416bdb12397959f6cc38df7ebbf554f2 100644 (file)
@@ -34,6 +34,7 @@ extern CU_SuiteInfo out_gml_suite;
 extern CU_SuiteInfo out_kml_suite;
 extern CU_SuiteInfo out_geojson_suite;
 extern CU_SuiteInfo out_svg_suite;
+extern CU_SuiteInfo out_x3d_suite;
 
 /*
 ** The main() function for setting up and running the tests.
@@ -62,6 +63,7 @@ int main(int argc, char *argv[])
                out_kml_suite,
                out_geojson_suite,
                out_svg_suite,
+               out_x3d_suite,
                CU_SUITE_INFO_NULL
        };