]> granicus.if.org Git - postgis/commitdiff
Add simple tests to stringbuffer class (#1668)
authorSandro Santilli <strk@keybit.net>
Tue, 13 Mar 2012 17:08:59 +0000 (17:08 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 13 Mar 2012 17:08:59 +0000 (17:08 +0000)
Hopefully these fail on windows so it's easier to test.
It may take a memory debugger to really see the failure.

git-svn-id: http://svn.osgeo.org/postgis/trunk@9487 b70326c6-7e19-0410-871a-916f4a2858ee

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

index f90baf99e717cdf825f3776d1c2d6c4b5d13f34f..cf24a49e1a63341015e47c417d10049aa9d48e35 100644 (file)
@@ -32,6 +32,7 @@ OBJS= \
        cu_node.o \
        cu_libgeom.o \
        cu_split.o \
+       cu_stringbuffer.o \
        cu_homogenize.o \
        cu_out_wkt.o \
        cu_out_wkb.o \
diff --git a/liblwgeom/cunit/cu_stringbuffer.c b/liblwgeom/cunit/cu_stringbuffer.c
new file mode 100644 (file)
index 0000000..c23380d
--- /dev/null
@@ -0,0 +1,59 @@
+/**********************************************************************
+ * $Id$
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ *
+ * Copyright 2012 Sandro Santilli <strk@keybit.net>
+ *
+ * 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 "stringbuffer.h"
+#include "cu_tester.h"
+
+
+static void test_stringbuffer_append(void)
+{
+       stringbuffer_t *sb;
+       const char *str;
+
+       sb = stringbuffer_create_with_size(2);
+       stringbuffer_append(sb, "hello world");
+       str = stringbuffer_getstring(sb);
+
+       CU_ASSERT_STRING_EQUAL("hello world", str);
+}
+
+static void test_stringbuffer_aprintf(void)
+{
+       stringbuffer_t *sb;
+       const char *str;
+
+       sb = stringbuffer_create_with_size(2);
+       stringbuffer_aprintf(sb, "hello %dth world", 14);
+       str = stringbuffer_getstring(sb);
+
+       CU_ASSERT_STRING_EQUAL("hello 14th world", str);
+}
+
+
+/* TODO: add more... */
+
+/*
+** Used by the test harness to register the tests in this file.
+*/
+CU_TestInfo stringbuffer_tests[] =
+{
+       PG_TEST(test_stringbuffer_append),
+       PG_TEST(test_stringbuffer_aprintf),
+       CU_TEST_INFO_NULL
+};
+CU_SuiteInfo stringbuffer_suite = {"stringbuffer", NULL, NULL, stringbuffer_tests };
index 4aa35b47af4441b7061ce43b2175892c59df17c6..612d3be7e9480dd1e2c99ac40a949b5cde733c6f 100644 (file)
@@ -32,6 +32,7 @@ extern CU_SuiteInfo split_suite;
 extern CU_SuiteInfo geodetic_suite;
 extern CU_SuiteInfo geos_suite;
 extern CU_SuiteInfo homogenize_suite;
+extern CU_SuiteInfo stringbuffer_suite;
 extern CU_SuiteInfo surface_suite;
 extern CU_SuiteInfo out_gml_suite;
 extern CU_SuiteInfo out_kml_suite;
@@ -63,6 +64,7 @@ int main(int argc, char *argv[])
                split_suite,
                geodetic_suite,
                geos_suite,
+               stringbuffer_suite,
                surface_suite,
                homogenize_suite,
                out_gml_suite,