RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 01-Oct-2014 23:01:14 Branch: rpm-5_4 Handle: 2014100121011301 Added files: (Branch: rpm-5_4) rpm/tests/bson test-value.c Modified files: (Branch: rpm-5_4) rpm/tests/bson Makefile.am TestSuite.c test-bson.c test-libbson.c test-oid.c test-string.c test-writer.c Log: - bson: upgrade to 1.0.1 Summary: Revision Changes Path 1.1.2.2 +1 -0 rpm/tests/bson/Makefile.am 1.1.2.2 +2 -29 rpm/tests/bson/TestSuite.c 1.1.2.2 +85 -1 rpm/tests/bson/test-bson.c 1.1.2.2 +2 -0 rpm/tests/bson/test-libbson.c 1.1.2.2 +0 -10 rpm/tests/bson/test-oid.c 1.1.2.2 +2 -0 rpm/tests/bson/test-string.c 1.1.2.1 +95 -0 rpm/tests/bson/test-value.c 1.1.2.2 +45 -4 rpm/tests/bson/test-writer.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/tests/bson/Makefile.am ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 Makefile.am --- rpm/tests/bson/Makefile.am 30 Sep 2014 21:41:56 -0000 1.1.2.1 +++ rpm/tests/bson/Makefile.am 1 Oct 2014 21:01:13 -0000 1.1.2.2 @@ -118,6 +118,7 @@ test-reader.c \ test-string.c \ test-utf8.c \ + test-value.c \ test-writer.c \ test-bcon-basic.c \ test-bcon-extract.c @@ . patch -p0 <<'@@ .' Index: rpm/tests/bson/TestSuite.c ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 TestSuite.c --- rpm/tests/bson/TestSuite.c 30 Sep 2014 21:41:56 -0000 1.1.2.1 +++ rpm/tests/bson/TestSuite.c 1 Oct 2014 21:01:13 -0000 1.1.2.2 @@ -15,42 +15,15 @@ */ #include "system.h" +#include <stdarg.h> -# include <inttypes.h> - -#if defined(__APPLE__) -# include <mach/mach_time.h> -#endif - -#ifdef DYING #include <assert.h> -#include <fcntl.h> -#include <stdarg.h> +# include <inttypes.h> #if defined(__APPLE__) # include <mach/mach_time.h> #endif -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#if !defined(_WIN32) -# include <sys/types.h> -# include <inttypes.h> -# include <sys/utsname.h> -# include <sys/wait.h> -# include <unistd.h> -# include <sys/time.h> -#else -# include <windows.h> -#endif - -#if defined(BSON_HAVE_CLOCK_GETTIME) -# include <time.h> -# include <sys/time.h> -#endif -#endif /* DYING */ - #include <bson.h> #include "TestSuite.h" @@ . patch -p0 <<'@@ .' Index: rpm/tests/bson/test-bson.c ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 test-bson.c --- rpm/tests/bson/test-bson.c 30 Sep 2014 21:41:59 -0000 1.1.2.1 +++ rpm/tests/bson/test-bson.c 1 Oct 2014 21:01:13 -0000 1.1.2.2 @@ -14,16 +14,19 @@ * limitations under the License. */ + #include "system.h" +#include <assert.h> #include <bson.h> + #include "bson-tests.h" #include "TestSuite.h" #include "debug.h" #ifndef BINARY_DIR -# define BINARY_DIR "tests/binary" +# define BINARY_DIR "binary" #endif @@ -830,6 +833,45 @@ static void +test_bson_new_from_buffer (void) +{ + bson_t * b; + uint8_t * buf = bson_malloc0(5); + size_t len = 5; + uint32_t len_le = BSON_UINT32_TO_LE(5); + + memcpy(buf, &len_le, 4); + + b = bson_new_from_buffer(&buf, &len, bson_realloc_ctx, NULL); + + assert(b->flags & BSON_FLAG_NO_FREE); + assert(len == 5); + assert(b->len == 5); + + bson_append_utf8(b, "hello", -1, "world", -1); + + assert(len == 32); + assert(b->len == 22); + + bson_destroy(b); + + bson_free(buf); + + buf = NULL; + len = 0; + + b = bson_new_from_buffer(&buf, &len, bson_realloc_ctx, NULL); + + assert(b->flags & BSON_FLAG_NO_FREE); + assert(len == 5); + assert(b->len == 5); + + bson_destroy(b); + bson_free(buf); +} + + +static void test_bson_utf8_key (void) { uint32_t length; @@ -1242,10 +1284,51 @@ } +static void +test_bson_destroy_with_steal (void) +{ + bson_t *b1; + bson_t b2; + uint32_t len = 0; + uint8_t *data; + int i; + + b1 = bson_new (); + for (i = 0; i < 100; i++) { + BSON_APPEND_INT32 (b1, "some-key", i); + } + + data = bson_destroy_with_steal (b1, true, &len); + assert (data); + assert (len == 1405); + bson_free (data); + data = NULL; + + bson_init (&b2); + len = 0; + for (i = 0; i < 100; i++) { + BSON_APPEND_INT32 (&b2, "some-key", i); + } + assert (!bson_destroy_with_steal (&b2, false, &len)); + assert (len == 1405); + + bson_init (&b2); + assert (!bson_destroy_with_steal (&b2, false, NULL)); + + bson_init (&b2); + data = bson_destroy_with_steal (&b2, true, &len); + assert (data); + assert (len == 5); + bson_free (data); + data = NULL; +} + + void test_bson_install (TestSuite *suite) { TestSuite_Add (suite, "/bson/new", test_bson_new); + TestSuite_Add (suite, "/bson/new_from_buffer", test_bson_new_from_buffer); TestSuite_Add (suite, "/bson/init", test_bson_init); TestSuite_Add (suite, "/bson/init_static", test_bson_init_static); TestSuite_Add (suite, "/bson/basic", test_bson_alloc); @@ -1292,4 +1375,5 @@ TestSuite_Add (suite, "/bson/reinit", test_bson_reinit); TestSuite_Add (suite, "/bson/macros", test_bson_macros); TestSuite_Add (suite, "/bson/clear", test_bson_clear); + TestSuite_Add (suite, "/bson/destroy_with_steal", test_bson_destroy_with_steal); } @@ . patch -p0 <<'@@ .' Index: rpm/tests/bson/test-libbson.c ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 test-libbson.c --- rpm/tests/bson/test-libbson.c 30 Sep 2014 21:41:59 -0000 1.1.2.1 +++ rpm/tests/bson/test-libbson.c 1 Oct 2014 21:01:13 -0000 1.1.2.2 @@ -18,6 +18,7 @@ extern void test_reader_install (TestSuite *suite); extern void test_string_install (TestSuite *suite); extern void test_utf8_install (TestSuite *suite); +extern void test_value_install (TestSuite *suite); extern void test_writer_install (TestSuite *suite); @@ -43,6 +44,7 @@ test_reader_install (&suite); test_string_install (&suite); test_utf8_install (&suite); + test_value_install (&suite); test_writer_install (&suite); ret = TestSuite_Run (&suite); @@ . patch -p0 <<'@@ .' Index: rpm/tests/bson/test-oid.c ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 test-oid.c --- rpm/tests/bson/test-oid.c 30 Sep 2014 21:41:59 -0000 1.1.2.1 +++ rpm/tests/bson/test-oid.c 1 Oct 2014 21:01:14 -0000 1.1.2.2 @@ -16,16 +16,6 @@ #include "system.h" -#ifdef DYING -#include <assert.h> -#include <bson.h> -#define BSON_INSIDE -#include "bson-thread-private.h" -#undef BSON_INSIDE -#include <fcntl.h> -#include <time.h> -#endif - #include "bson-tests.h" #include "TestSuite.h" @@ . patch -p0 <<'@@ .' Index: rpm/tests/bson/test-string.c ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 test-string.c --- rpm/tests/bson/test-string.c 30 Sep 2014 21:41:59 -0000 1.1.2.1 +++ rpm/tests/bson/test-string.c 1 Oct 2014 21:01:14 -0000 1.1.2.2 @@ -16,6 +16,7 @@ #include "system.h" +#include <assert.h> #include <bson.h> #include "bson-tests.h" @@ -23,6 +24,7 @@ #include "debug.h" + static void test_bson_string_new (void) { @@ . patch -p0 <<'@@ .' Index: rpm/tests/bson/test-value.c ============================================================================ $ cvs diff -u -r0 -r1.1.2.1 test-value.c --- /dev/null 2014-10-01 23:01:01.000000000 +0200 +++ test-value.c 2014-10-01 23:01:14.496300556 +0200 @@ -0,0 +1,95 @@ +/* + * Copyright 2014 MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "system.h" + +#include <bcon.h> +#include <bson.h> + +#include "TestSuite.h" + +#include "debug.h" + + +static void +test_value_basic (void) +{ + static const uint8_t raw[16] = { 0 }; + const bson_value_t *value; + bson_value_t copy; + bson_iter_t iter; + bson_oid_t oid; + bson_t other = BSON_INITIALIZER; + bson_t *doc; + bson_t sub = BSON_INITIALIZER; + bool r; + int i; + + bson_oid_init (&oid, NULL); + + doc = BCON_NEW ("double", BCON_DOUBLE (123.4), + "utf8", "this is my string", + "document", BCON_DOCUMENT (&sub), + "array", BCON_DOCUMENT (&sub), + "binary", BCON_BIN (BSON_SUBTYPE_BINARY, raw, sizeof raw), + "undefined", BCON_UNDEFINED, + "oid", BCON_OID (&oid), + "bool", BCON_BOOL (true), + "datetime", BCON_DATE_TIME (12345678), + "null", BCON_NULL, + "regex", BCON_REGEX ("^hello", "i"), + "dbpointer", BCON_DBPOINTER ("test.test", &oid), + "code", BCON_CODE ("var a = function() {}"), + "symbol", BCON_SYMBOL ("my_symbol"), + "codewscope", BCON_CODEWSCOPE ("var a = 1;", &sub), + "int32", BCON_INT32 (1234), + "timestamp", BCON_TIMESTAMP (1234, 4567), + "int64", BCON_INT32 (4321), + "maxkey", BCON_MAXKEY, + "minkey", BCON_MINKEY); + + r = bson_iter_init (&iter, doc); + assert (r); + + for (i = 0; i < 20; i++) { + r = bson_iter_next (&iter); + assert (r); + + value = bson_iter_value (&iter); + assert (value); + + bson_value_copy (value, ©); + + r = bson_append_value (&other, bson_iter_key (&iter), -1, ©); + assert (r); + + bson_value_destroy (©); + } + + r = bson_iter_next (&iter); + assert (!r); + + bson_destroy (doc); + bson_destroy (&other); +} + + +void +test_value_install (TestSuite *suite) +{ + TestSuite_Add (suite, "/bson/value/basic", test_value_basic); +} @@ . patch -p0 <<'@@ .' Index: rpm/tests/bson/test-writer.c ============================================================================ $ cvs diff -u -r1.1.2.1 -r1.1.2.2 test-writer.c --- rpm/tests/bson/test-writer.c 30 Sep 2014 21:41:59 -0000 1.1.2.1 +++ rpm/tests/bson/test-writer.c 1 Oct 2014 21:01:14 -0000 1.1.2.2 @@ -14,13 +14,53 @@ * limitations under the License. */ + #include "system.h" +#include <assert.h> + #include "bson-tests.h" #include "TestSuite.h" #include "debug.h" + +static void * +test_bson_writer_custom_realloc_helper (void *mem, + size_t num_bytes, + void *ctx) +{ + int * x = (int *)ctx; + + *x = *x + 1; + return bson_realloc(mem, num_bytes); +} + +static void +test_bson_writer_custom_realloc (void) +{ + bson_writer_t *writer; + uint8_t *buf = bson_malloc(0); + size_t buflen = 0; + bson_t *b; + int x = 0; + + writer = bson_writer_new(&buf, &buflen, 0, test_bson_writer_custom_realloc_helper, &x); + + assert(bson_writer_begin(writer, &b)); + + assert(bson_append_utf8(b, "hello", -1, "world", -1)); + + bson_writer_end(writer); + + bson_writer_destroy(writer); + + assert_cmpint(x, >, 0); + + bson_free(buf); +} + + static void test_bson_writer_shared_buffer (void) { @@ -36,7 +76,7 @@ int j = 0; int n_docs = 10000; - writer = bson_writer_new(&buf, &buflen, 0, bson_realloc); + writer = bson_writer_new(&buf, &buflen, 0, bson_realloc_ctx, NULL); for (i = 0; i < n_docs; i++) { assert(bson_writer_begin(writer, &b)); @@ -78,7 +118,7 @@ int r; int i; - writer = bson_writer_new(&buf, &len, 0, bson_realloc); + writer = bson_writer_new(&buf, &len, 0, bson_realloc_ctx, NULL); for (i = 0; i < 5; i++) { assert(bson_writer_begin(writer, &b)); bson_writer_end(writer); @@ -101,7 +141,7 @@ int r; int i; - writer = bson_writer_new(&buf, &buflen, 0, NULL); + writer = bson_writer_new(&buf, &buflen, 0, NULL, NULL); for (i=0; i<6; i++) { assert(bson_writer_begin(writer, &b)); bson_writer_end(writer); @@ -127,7 +167,7 @@ int r; int i; - writer = bson_writer_new(&buf, &buflen, 0, NULL); + writer = bson_writer_new(&buf, &buflen, 0, NULL, NULL); for (i=0; i<5; i++) { assert(bson_writer_begin(writer, &b)); bson_writer_end(writer); @@ -147,6 +187,7 @@ void test_writer_install (TestSuite *suite) { + TestSuite_Add (suite, "/bson/writer/custom_realloc", test_bson_writer_custom_realloc); TestSuite_Add (suite, "/bson/writer/shared_buffer", test_bson_writer_shared_buffer); TestSuite_Add (suite, "/bson/writer/empty_sequence", test_bson_writer_empty_sequence); TestSuite_Add (suite, "/bson/writer/null_realloc", test_bson_writer_null_realloc); @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org