diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bson/bson.c | 4 | ||||
-rw-r--r-- | src/ejdb/tests/ejdbtest2.c | 48 |
2 files changed, 48 insertions, 4 deletions
diff --git a/src/bson/bson.c b/src/bson/bson.c index 42e01eb..64069e2 100644 --- a/src/bson/bson.c +++ b/src/bson/bson.c @@ -1424,9 +1424,11 @@ int bson_append_field_from_iterator2(const char *key, const bson_iterator *from, } switch (t) { case BSON_STRING: - case BSON_SYMBOL: bson_append_string(into, key, bson_iterator_string(from)); break; + case BSON_SYMBOL: + bson_append_symbol(into, key, bson_iterator_string(from)); + break; case BSON_CODE: bson_append_code(into, key, bson_iterator_code(from)); break; diff --git a/src/ejdb/tests/ejdbtest2.c b/src/ejdb/tests/ejdbtest2.c index bbba0a6..1924732 100644 --- a/src/ejdb/tests/ejdbtest2.c +++ b/src/ejdb/tests/ejdbtest2.c @@ -6106,6 +6106,47 @@ void testTicket148(void) { tclistdel(q1res); } +void testTicket156(void) { + EJCOLL *coll = ejdbcreatecoll(jb, "ticket156", NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(coll); + + bson b; + bson_oid_t oid; + + bson_init(&b); + bson_append_int(&b, "id", 18); + bson_append_symbol(&b, "sym", "eighteen"); + bson_finish(&b); + CU_ASSERT_TRUE(ejdbsavebson(coll, &b, &oid)); + bson_destroy(&b); + + /* Verify that id=18 contain record with symbol */ + bson bsq; + bson_init_as_query(&bsq); + bson_append_int(&bsq, "id", 18); + bson_finish(&bsq); + CU_ASSERT_FALSE_FATAL(bsq.err); + + EJQ *q1 = ejdbcreatequery(jb, &bsq, NULL, 0, NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(q1); + uint32_t count; + TCLIST *q1res = ejdbqryexecute(coll, q1, &count, 0, NULL); + CU_ASSERT_EQUAL(TCLISTNUM(q1res), 1); + + void *bsdata = TCLISTVALPTR(q1res, 0); + CU_ASSERT_PTR_NOT_NULL_FATAL(bsdata); + + bson_iterator it; + bson_type bt; + BSON_ITERATOR_FROM_BUFFER(&it, bsdata); + bt = bson_find_fieldpath_value("sym", &it); + CU_ASSERT_EQUAL_FATAL(bt, BSON_SYMBOL); + CU_ASSERT_FALSE(strcmp(bson_iterator_string(&it), "eighteen")); + + bson_destroy(&bsq); + ejdbquerydel(q1); + tclistdel(q1res); +} int main() { setlocale(LC_ALL, "en_US.UTF-8"); @@ -6198,10 +6239,11 @@ int main() { (NULL == CU_add_test(pSuite, "testTicket101", testTicket101)) || (NULL == CU_add_test(pSuite, "testTicket110", testTicket110)) || (NULL == CU_add_test(pSuite, "testDistinct", testDistinct)) || - (NULL == CU_add_test(pSuite, "testSlice", testSlice)) || - (NULL == CU_add_test(pSuite, "testTicket117", testTicket117)) || + (NULL == CU_add_test(pSuite, "testSlice", testSlice)) || + (NULL == CU_add_test(pSuite, "testTicket117", testTicket117)) || (NULL == CU_add_test(pSuite, "testMetaInfo", testMetaInfo)) || - (NULL == CU_add_test(pSuite, "testTicket148", testTicket148)) + (NULL == CU_add_test(pSuite, "testTicket148", testTicket148)) || + (NULL == CU_add_test(pSuite, "testTicket156", testTicket156)) ) { CU_cleanup_registry(); return CU_get_error(); |