diff options
author | Tyutyunkov Vyacheslav <tve@softmotions.com> | 2015-08-27 14:25:25 +0600 |
---|---|---|
committer | Tyutyunkov Vyacheslav <tve@softmotions.com> | 2015-08-27 14:25:25 +0600 |
commit | 1f92991631e1fe1bdd1724f27b79204abff3e534 (patch) | |
tree | b33b794cad181c7f6af5e397bcfe28642bd49249 | |
parent | 69d50fce49ff9e67c5e78de1b8eb9ba8413d1d97 (diff) | |
download | ejdb-1f92991631e1fe1bdd1724f27b79204abff3e534.tar.gz ejdb-1f92991631e1fe1bdd1724f27b79204abff3e534.tar.bz2 ejdb-1f92991631e1fe1bdd1724f27b79204abff3e534.zip |
#161 - fixes
-rw-r--r-- | src/bson/bson.c | 9 | ||||
-rw-r--r-- | src/ejdb/tests/ejdbtest2.c | 64 |
2 files changed, 65 insertions, 8 deletions
diff --git a/src/bson/bson.c b/src/bson/bson.c index 64069e2..b192f2d 100644 --- a/src/bson/bson.c +++ b/src/bson/bson.c @@ -1404,13 +1404,8 @@ static void bson_append_fpath_from_iterator(const char *fpath, const bson_iterat bson_append_finish_object(into); //arrays are covered also } } else { //intermediate part - if (bson_isnumstr(key, keylen)) { - nl++; - bson_append_start_array2(into, key, keylen); - } else { - nl++; - bson_append_start_object2(into, key, keylen); - } + nl++; + bson_append_start_object2(into, key, keylen); } fp = rp; } diff --git a/src/ejdb/tests/ejdbtest2.c b/src/ejdb/tests/ejdbtest2.c index 1924732..40d2f8c 100644 --- a/src/ejdb/tests/ejdbtest2.c +++ b/src/ejdb/tests/ejdbtest2.c @@ -6148,6 +6148,67 @@ void testTicket156(void) { tclistdel(q1res); } +void testTicket161(void) { + EJCOLL *coll = ejdbcreatecoll(jb, "ticket161", NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(coll); + + bson b; + bson_oid_t oid; + + bson_init(&b); + bson_append_start_object(&b, "stocks"); + bson_append_finish_object(&b); + bson_finish(&b); + CU_ASSERT_TRUE(ejdbsavebson(coll, &b, &oid)); + bson_destroy(&b); + + bson bsq; + bson_init_as_query(&bsq); + bson_append_start_object(&bsq, "$inc"); + bson_append_int(&bsq, "stocks.s72851.qty", 4); + bson_append_finish_object(&bsq); + bson_finish(&bsq); + CU_ASSERT_FALSE_FATAL(bsq.err); + + uint32_t count = ejdbupdate(coll, &bsq, 0, 0, 0, 0); + bson_destroy(&bsq); + CU_ASSERT_EQUAL(count, 1); + + bson_init_as_query(&bsq); + bson_finish(&bsq); + + EJQ *q1 = ejdbcreatequery(jb, &bsq, NULL, 0, NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(q1); + 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, sit1, sit2; + bson_type bt; + BSON_ITERATOR_FROM_BUFFER(&it, bsdata); + + while ((bt = bson_iterator_next(&it)) != BSON_EOO) { + if (bt == BSON_OBJECT) { + break; + } + } + CU_ASSERT_EQUAL_FATAL(bt, BSON_OBJECT); + + BSON_ITERATOR_SUBITERATOR(&it, &sit1); + bt = bson_iterator_next(&sit1); + CU_ASSERT_EQUAL(bt, BSON_OBJECT); + + BSON_ITERATOR_SUBITERATOR(&sit1, &sit2); + bt = bson_iterator_next(&sit2); + CU_ASSERT_TRUE(BSON_IS_NUM_TYPE(bt)); + + bson_destroy(&bsq); + ejdbquerydel(q1); + tclistdel(q1res); +} + int main() { setlocale(LC_ALL, "en_US.UTF-8"); CU_pSuite pSuite = NULL; @@ -6243,7 +6304,8 @@ int main() { (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, "testTicket156", testTicket156)) + (NULL == CU_add_test(pSuite, "testTicket156", testTicket156)) || + (NULL == CU_add_test(pSuite, "testTicket161", testTicket161)) ) { CU_cleanup_registry(); return CU_get_error(); |