diff options
author | Tyutyunkov Vyacheslav <tve@softmotions.com> | 2015-09-13 23:41:21 +0600 |
---|---|---|
committer | Tyutyunkov Vyacheslav <tve@softmotions.com> | 2015-09-13 23:41:21 +0600 |
commit | 1308e3009cec41544155b3132f06a7ba58f4c763 (patch) | |
tree | c82479a05ee2bb363b14ca4645d0050f7a86e59b | |
parent | 12de4c71f778ac1217bc9ec180b39603e2c7eff8 (diff) | |
parent | f45aaa464607dc34f1116e81171262721f4386e2 (diff) | |
download | ejdb-1308e3009cec41544155b3132f06a7ba58f4c763.tar.gz ejdb-1308e3009cec41544155b3132f06a7ba58f4c763.tar.bz2 ejdb-1308e3009cec41544155b3132f06a7ba58f4c763.zip |
Merge branch 'ticket161'
-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..09f782a 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.72851.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(); |