From: Nicklas Avén Date: Wed, 29 Jan 2014 21:47:27 +0000 (+0000) Subject: First varint cunit test X-Git-Tag: 2.2.0rc1~1264 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eaf91d31db82a3bec45987af52e6f986e809c9b5;p=postgis First varint cunit test git-svn-id: http://svn.osgeo.org/postgis/trunk@12201 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/Makefile.in b/liblwgeom/cunit/Makefile.in index 489ad6865..076610e15 100644 --- a/liblwgeom/cunit/Makefile.in +++ b/liblwgeom/cunit/Makefile.in @@ -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) diff --git a/liblwgeom/cunit/cu_tester.c b/liblwgeom/cunit/cu_tester.c index 1278c4c01..7cb4b1dab 100644 --- a/liblwgeom/cunit/cu_tester.c +++ b/liblwgeom/cunit/cu_tester.c @@ -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 index 000000000..24239f416 --- /dev/null +++ b/liblwgeom/cunit/cu_varint.c @@ -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 +#include +#include +#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 };