From: Sandro Santilli Date: Tue, 13 Mar 2012 17:08:59 +0000 (+0000) Subject: Add simple tests to stringbuffer class (#1668) X-Git-Tag: 2.0.0beta3~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=082d160615ff890b62ba3c78d33a7ce36fee26fa;p=postgis Add simple tests to stringbuffer class (#1668) 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 --- diff --git a/liblwgeom/cunit/Makefile.in b/liblwgeom/cunit/Makefile.in index f90baf99e..cf24a49e1 100644 --- a/liblwgeom/cunit/Makefile.in +++ b/liblwgeom/cunit/Makefile.in @@ -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 index 000000000..c23380d25 --- /dev/null +++ b/liblwgeom/cunit/cu_stringbuffer.c @@ -0,0 +1,59 @@ +/********************************************************************** + * $Id$ + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * + * Copyright 2012 Sandro Santilli + * + * 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 +#include +#include +#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 }; diff --git a/liblwgeom/cunit/cu_tester.c b/liblwgeom/cunit/cu_tester.c index 4aa35b47a..612d3be7e 100644 --- a/liblwgeom/cunit/cu_tester.c +++ b/liblwgeom/cunit/cu_tester.c @@ -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,