diff options
author | Anton Adamansky <adamansky@gmail.com> | 2015-04-27 22:10:35 +0600 |
---|---|---|
committer | Anton Adamansky <adamansky@gmail.com> | 2015-04-27 22:10:35 +0600 |
commit | 639eabfa667e8a9f6b3286bbd973cb2ca21822c7 (patch) | |
tree | 107e3e4246fe354035cd8450b861b615edb11e69 /src | |
parent | 9569994013da9b4969a2fa90adee484accf1c70a (diff) | |
download | ejdb-639eabfa667e8a9f6b3286bbd973cb2ca21822c7.tar.gz ejdb-639eabfa667e8a9f6b3286bbd973cb2ca21822c7.tar.bz2 ejdb-639eabfa667e8a9f6b3286bbd973cb2ca21822c7.zip |
Fixed #135
Diffstat (limited to 'src')
-rw-r--r-- | src/bson/bson.c | 2 | ||||
-rw-r--r-- | src/bson/bson.h | 4 | ||||
-rw-r--r-- | src/ejdb/tests/ejdbtest4.c | 30 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/bson/bson.c b/src/bson/bson.c index 771596f..2f8e02e 100644 --- a/src/bson/bson.c +++ b/src/bson/bson.c @@ -2513,7 +2513,7 @@ static int _bson2json(_BSON2JSONCTX *ctx, bson_iterator *it, bool array) { break; case BSON_DOUBLE: { - tcxstrprintf(out, "%llf", bson_iterator_double(it)); + tcxstrprintf(out, "%lf", bson_iterator_double(it)); break; } case BSON_STRING: diff --git a/src/bson/bson.h b/src/bson/bson.h index a741336..3de71e7 100644 --- a/src/bson/bson.h +++ b/src/bson/bson.h @@ -1213,6 +1213,10 @@ EJDB_EXPORT int bson_merge_array_sets(const void *mbuf, const void *inbuf, bool /** * Convert BSON into JSON buffer. + * + * A caller should free an allocated `*buf` + * if value of `*buf` is not `NULL` after function completion. + * * @param src BSON data * @param buf Allocated buffer with resulting JSON data * @param sp JSON data length will be stored into diff --git a/src/ejdb/tests/ejdbtest4.c b/src/ejdb/tests/ejdbtest4.c index a71a669..5018fc3 100644 --- a/src/ejdb/tests/ejdbtest4.c +++ b/src/ejdb/tests/ejdbtest4.c @@ -13,7 +13,7 @@ static void eprint(EJDB *jb, int line, const char *func) { line, func, ecode, ejdberrmsg(ecode)); } -void testTicket53() { +void testTicket53(void) { EJDB *jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_53", JBOWRITER | JBOCREAT)); ejdbclose(jb); @@ -31,7 +31,7 @@ void testTicket53() { ejdbdel(jb); } -void testBSONExportImport() { +void testBSONExportImport(void) { EJDB *jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT | JBOTRUNC)); EJCOLL *coll = ejdbcreatecoll(jb, "col1", NULL); @@ -164,7 +164,7 @@ void testBSONExportImport() { tclistdel(cnames); } -void testBSONExportImport2() { +void testBSONExportImport2(void) { EJDB *jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT | JBOTRUNC)); EJCOLL *coll = ejdbcreatecoll(jb, "col1", NULL); @@ -330,6 +330,25 @@ void testBSONExportImport2() { bson_del(nmeta); } + +void testTicket135(void) { + bson bo_test; + bson_init(&bo_test); + bson_append_int(&bo_test, "myInt", 10); + bson_append_double(&bo_test, "myDouble", -50.0); + bson_finish(&bo_test); + + char* buf = NULL; + int lenght = 0; + bson2json(bson_data(&bo_test), &buf, &lenght); + CU_ASSERT_PTR_NOT_NULL_FATAL(buf); + CU_ASSERT_PTR_NOT_NULL(strstr(buf, "\"myInt\" : 10")); + CU_ASSERT_PTR_NOT_NULL(strstr(buf, "\"myDouble\" : -50.000000")); + bson_destroy(&bo_test); + TCFREE(buf); +} + + int init_suite(void) { return 0; } @@ -347,7 +366,7 @@ int main() { return CU_get_error(); /* Add a suite to the registry */ - pSuite = CU_add_suite("t4", init_suite, clean_suite); + pSuite = CU_add_suite("ejdbtest1", init_suite, clean_suite); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); @@ -357,7 +376,8 @@ int main() { if ( (NULL == CU_add_test(pSuite, "testTicket53", testTicket53)) || (NULL == CU_add_test(pSuite, "testBSONExportImport", testBSONExportImport)) || - (NULL == CU_add_test(pSuite, "testBSONExportImport2", testBSONExportImport2)) + (NULL == CU_add_test(pSuite, "testBSONExportImport2", testBSONExportImport2)) || + (NULL == CU_add_test(pSuite, "testTicket135", testTicket135)) ) { CU_cleanup_registry(); return CU_get_error(); |