]> granicus.if.org Git - postgis/commitdiff
First varint cunit test
authorNicklas Avén <nicklas.aven@jordogskog.no>
Wed, 29 Jan 2014 21:47:27 +0000 (21:47 +0000)
committerNicklas Avén <nicklas.aven@jordogskog.no>
Wed, 29 Jan 2014 21:47:27 +0000 (21:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12201 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 489ad686586173ab692680a71f0607b3d1da7fc3..076610e15d9d4804de0bedafdfc53021863cfcaf 100644 (file)
@@ -50,6 +50,7 @@ OBJS= \
        cu_in_geojson.o \
        cu_in_wkb.o \
        cu_in_wkt.o \
+       cu_varint.o \
        cu_tester.o 
 
 ifeq (@SFCGAL@,sfcgal)
index 1278c4c0130e818482787cbf87d399b53017b529..7cb4b1dab212bbdc17745d368521d6881c7274d9 100644 (file)
@@ -51,6 +51,7 @@ extern CU_SuiteInfo out_kml_suite;
 extern CU_SuiteInfo out_geojson_suite;
 extern CU_SuiteInfo out_svg_suite;
 extern CU_SuiteInfo out_x3d_suite;
+extern CU_SuiteInfo varint_suite;
 
 /*
 ** The main() function for setting up and running the tests.
@@ -95,6 +96,7 @@ int main(int argc, char *argv[])
                out_geojson_suite,
                out_svg_suite,
                out_x3d_suite,
+               varint_suite,
                CU_SUITE_INFO_NULL
        };
 
diff --git a/liblwgeom/cunit/cu_varint.c b/liblwgeom/cunit/cu_varint.c
new file mode 100644 (file)
index 0000000..24239f4
--- /dev/null
@@ -0,0 +1,69 @@
+/**********************************************************************
+ * $Id: cu_varint.c 6160 2013-09-21 01:28:12Z nicklas $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ *
+ * Copyright (C) 2013 Nicklas Avén
+ *
+ * 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 "CUnit/CUnit.h"
+
+#include "liblwgeom_internal.h"
+#include "liblwgeom.h"
+
+#include "lwout_twkb.c"
+#include "cu_tester.h"
+
+
+static void do_test_unsigned_varint(uint64_t nr,int expected_size, char* expected_res)
+{
+       uint8_t buf[8]; 
+       int size;
+       
+       size = u_getvarint_size(nr);
+       CU_ASSERT_EQUAL(size,expected_size);
+       u_varint_to_twkb_buf(nr, buf);
+       CU_ASSERT_STRING_EQUAL( hexbytes_from_bytes(buf,size),expected_res);    
+}
+
+static void do_test_signed_varint(uint64_t nr,int expected_size, char* expected_res)
+{
+       uint8_t buf[8]; 
+       int size;
+       
+       size = u_getvarint_size(nr);
+       CU_ASSERT_EQUAL(size,expected_size);
+       s_varint_to_twkb_buf(nr, buf);
+       CU_ASSERT_STRING_EQUAL( hexbytes_from_bytes(buf,size),expected_res);    
+}
+
+
+static void test_varint(void)
+{
+
+       do_test_unsigned_varint(1,1, "01");
+       do_test_unsigned_varint(300,2, "AC02");
+       do_test_unsigned_varint(150,2, "9601");
+       
+       do_test_signed_varint(1,1, "02");
+}
+
+
+/*
+** Used by the test harness to register the tests in this file.
+*/
+CU_TestInfo varint_tests[] =
+{
+       PG_TEST(test_varint),
+       CU_TEST_INFO_NULL
+};
+CU_SuiteInfo varint_suite = {"varint", NULL, NULL, varint_tests };