From aae95db4ebb70b80d83b97cefe754dd5836bc25c Mon Sep 17 00:00:00 2001 From: Albert Choy Date: Wed, 15 Apr 2015 14:06:24 -0500 Subject: #129 query BSON_SYMBOL like BSON_STRING Fix query handling to use BSON_IS_STRING_TYPE() to check for both string and symbols. --- src/ejdb/ejdb.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ejdb/ejdb.c b/src/ejdb/ejdb.c index 5eabbfc..a3d363a 100644 --- a/src/ejdb/ejdb.c +++ b/src/ejdb/ejdb.c @@ -1794,10 +1794,11 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, int sp; const char *fval; + // Feature #129: Handle BSON_SYMBOL like BSON_STRING #define _FETCHSTRFVAL() \ do { \ - fvalsz = (bt == BSON_STRING) ? bson_iterator_string_len(it) : 1; \ - fval = (bt == BSON_STRING) ? bson_iterator_string(it) : ""; \ + fvalsz = (BSON_IS_STRING_TYPE(bt)) ? bson_iterator_string_len(it) : 1; \ + fval = (BSON_IS_STRING_TYPE(bt)) ? bson_iterator_string(it) : ""; \ if (bt == BSON_OID) { \ bson_oid_to_string(bson_iterator_oid(it), oidbuf); \ fvalsz = 25; \ @@ -1824,7 +1825,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, switch (qf->tcop) { case TDBQCSTREQ: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1842,7 +1843,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, } case TDBQCSTRINC: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1860,7 +1861,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, } case TDBQCSTRBW: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1878,7 +1879,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, } case TDBQCSTREW: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1898,7 +1899,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1918,7 +1919,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1938,7 +1939,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1986,7 +1987,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { + if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); -- cgit v1.2.3 From ffb802d4adcd05d4bec74f5c9b22af3fe429bd40 Mon Sep 17 00:00:00 2001 From: Albert Choy Date: Wed, 15 Apr 2015 15:01:12 -0500 Subject: Test queries 29-31 for #129 Test feature of symbol object matching --- src/ejdb/tests/ejdbtest2.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/ejdb/tests/ejdbtest2.c b/src/ejdb/tests/ejdbtest2.c index ffaed5f..a35b619 100644 --- a/src/ejdb/tests/ejdbtest2.c +++ b/src/ejdb/tests/ejdbtest2.c @@ -63,6 +63,7 @@ void testAddData(void) { bson_append_finish_object(&a1); bson_append_finish_array(&a1); //EOF complexarr CU_ASSERT_FALSE_FATAL(a1.err); + bson_append_symbol(&a1, "symbol_info", "apple"); bson_finish(&a1); ejdbsavebson(ccoll, &a1, &oid); bson_destroy(&a1); @@ -100,6 +101,7 @@ void testAddData(void) { bson_append_long(&a1, "1", 556667); bson_append_double(&a1, "2", 77676.22); bson_append_finish_array(&a1); + bson_append_symbol(&a1, "symbol_info", "application"); bson_finish(&a1); CU_ASSERT_FALSE_FATAL(a1.err); @@ -122,6 +124,7 @@ void testAddData(void) { bson_append_long(&a1, "1", 222334); bson_append_double(&a1, "2", 77676.22); bson_append_finish_array(&a1); + bson_append_symbol(&a1, "symbol_info", "bison"); bson_finish(&a1); CU_ASSERT_FALSE_FATAL(a1.err); @@ -2602,6 +2605,96 @@ void testQuery28(void) { // $gte: 64 bit number ejdbquerydel(q1); } +void testQuery29(void) { + // #129: Test $begin Query with Symbols + EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); + + bson bsq1; + bson_init_as_query(&bsq1); + bson_append_start_object(&bsq1, "symbol_info"); + bson_append_symbol(&bsq1, "$begin", "app"); + bson_finish(&bsq1); + CU_ASSERT_FALSE_FATAL(bsq1.err); + + EJQ *q1 = ejdbcreatequery(jb, &bsq1, NULL, 0, NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(q1); + + uint32_t count = 0; + TCXSTR *log = tcxstrnew(); + TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); + //fprintf(stderr, "%s", TCXSTRPTR(log)); + + CU_ASSERT_EQUAL(count, 2); // should match symbol_info: apple, application + CU_ASSERT_TRUE(TCLISTNUM(q1res) == 2); + + bson_destroy(&bsq1); + tclistdel(q1res); + tcxstrdel(log); + ejdbquerydel(q1); +} + +void testQuery30(void) { + // #129: Test equal with Symbols + EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); + + bson bsq1; + bson_init_as_query(&bsq1); + bson_append_symbol(&bsq1, "symbol_info", "bison"); + bson_finish(&bsq1); + CU_ASSERT_FALSE_FATAL(bsq1.err); + + EJQ *q1 = ejdbcreatequery(jb, &bsq1, NULL, 0, NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(q1); + + uint32_t count = 0; + TCXSTR *log = tcxstrnew(); + TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); + //fprintf(stderr, "%s", TCXSTRPTR(log)); + + CU_ASSERT_EQUAL(count, 1); // should match symbol_info: bison + CU_ASSERT_TRUE(TCLISTNUM(q1res) == 1); + + bson_destroy(&bsq1); + tclistdel(q1res); + tcxstrdel(log); + ejdbquerydel(q1); +} + +void testQuery31(void) { + // #129: Test $in array Query with Symbols + EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); + + bson bsq1; + bson_init_as_query(&bsq1); + bson_append_start_object(&bsq1, "symbol_info"); + bson_append_start_array(&bsq1, "$in"); + bson_append_symbol(&bsq1, "0", "apple"); + bson_append_symbol(&bsq1, "1", "bison"); + bson_append_finish_array(&bsq1); + bson_append_finish_object(&bsq1); + bson_finish(&bsq1); + CU_ASSERT_FALSE_FATAL(bsq1.err); + + EJQ *q1 = ejdbcreatequery(jb, &bsq1, NULL, 0, NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(q1); + + uint32_t count = 0; + TCXSTR *log = tcxstrnew(); + TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); + //fprintf(stderr, "%s", TCXSTRPTR(log)); + + CU_ASSERT_EQUAL(count, 2); // should match symbol_info: apple, bison + CU_ASSERT_TRUE(TCLISTNUM(q1res) == 2); + + bson_destroy(&bsq1); + tclistdel(q1res); + tcxstrdel(log); + ejdbquerydel(q1); +} + void testOIDSMatching(void) { //OID matching EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); @@ -5772,6 +5865,9 @@ int main() { (NULL == CU_add_test(pSuite, "testQuery26", testQuery26)) || (NULL == CU_add_test(pSuite, "testQuery27", testQuery27)) || (NULL == CU_add_test(pSuite, "testQuery28", testQuery28)) || + (NULL == CU_add_test(pSuite, "testQuery29", testQuery29)) || + (NULL == CU_add_test(pSuite, "testQuery30", testQuery30)) || + (NULL == CU_add_test(pSuite, "testQuery31", testQuery31)) || (NULL == CU_add_test(pSuite, "testOIDSMatching", testOIDSMatching)) || (NULL == CU_add_test(pSuite, "testEmptyFieldIndex", testEmptyFieldIndex)) || (NULL == CU_add_test(pSuite, "testICaseIndex", testICaseIndex)) || -- cgit v1.2.3 From 380fd1b57e1be2d25d3750e2b029b6c05b60189f Mon Sep 17 00:00:00 2001 From: Albert Choy Date: Wed, 15 Apr 2015 16:21:42 -0500 Subject: #129 --- src/ejdb/tests/ejdbtest2.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ejdb/tests/ejdbtest2.c b/src/ejdb/tests/ejdbtest2.c index a35b619..43e050d 100644 --- a/src/ejdb/tests/ejdbtest2.c +++ b/src/ejdb/tests/ejdbtest2.c @@ -2576,6 +2576,7 @@ void testQuery28(void) { // $gte: 64 bit number bson_init_as_query(&bsq1); bson_append_start_object(&bsq1, "longscore"); bson_append_long(&bsq1, "$gte", int64value); + bson_append_finish_object(&bsq1); bson_finish(&bsq1); CU_ASSERT_FALSE_FATAL(bsq1.err); @@ -2614,6 +2615,7 @@ void testQuery29(void) { bson_init_as_query(&bsq1); bson_append_start_object(&bsq1, "symbol_info"); bson_append_symbol(&bsq1, "$begin", "app"); + bson_append_finish_object(&bsq1); bson_finish(&bsq1); CU_ASSERT_FALSE_FATAL(bsq1.err); @@ -2623,7 +2625,8 @@ void testQuery29(void) { uint32_t count = 0; TCXSTR *log = tcxstrnew(); TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); - //fprintf(stderr, "%s", TCXSTRPTR(log)); + fprintf(stderr, "%s", TCXSTRPTR(log)); + fprintf(stderr, "RESULT count=%d\n", count); CU_ASSERT_EQUAL(count, 2); // should match symbol_info: apple, application CU_ASSERT_TRUE(TCLISTNUM(q1res) == 2); @@ -2651,7 +2654,8 @@ void testQuery30(void) { uint32_t count = 0; TCXSTR *log = tcxstrnew(); TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); - //fprintf(stderr, "%s", TCXSTRPTR(log)); + fprintf(stderr, "%s", TCXSTRPTR(log)); + fprintf(stderr, "RESULT count=%d\n", count); CU_ASSERT_EQUAL(count, 1); // should match symbol_info: bison CU_ASSERT_TRUE(TCLISTNUM(q1res) == 1); @@ -2684,7 +2688,8 @@ void testQuery31(void) { uint32_t count = 0; TCXSTR *log = tcxstrnew(); TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); - //fprintf(stderr, "%s", TCXSTRPTR(log)); + fprintf(stderr, "%s", TCXSTRPTR(log)); + fprintf(stderr, "RESULT count=%d\n", count); CU_ASSERT_EQUAL(count, 2); // should match symbol_info: apple, bison CU_ASSERT_TRUE(TCLISTNUM(q1res) == 2); -- cgit v1.2.3 From 9bc632d250c0606573448a3717916bfa00e641cc Mon Sep 17 00:00:00 2001 From: Albert Choy Date: Wed, 15 Apr 2015 16:45:50 -0500 Subject: #129 Symbols must match case sensitive --- src/bson/bson.h | 2 +- src/ejdb/ejdb.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bson/bson.h b/src/bson/bson.h index de5aab7..a741336 100644 --- a/src/bson/bson.h +++ b/src/bson/bson.h @@ -32,7 +32,7 @@ #include "tcutil.h" #define BSON_IS_NUM_TYPE(atype) (atype == BSON_INT || atype == BSON_LONG || atype == BSON_DOUBLE) -#define BSON_IS_STRING_TYPE(atype) (atype == BSON_STRING || atype == BSON_SYMBOL) +#define BSON_IS_STRING_TYPE(atype) ((atype) == BSON_STRING || (atype) == BSON_SYMBOL) EJDB_EXTERN_C_START diff --git a/src/ejdb/ejdb.c b/src/ejdb/ejdb.c index a3d363a..d568a57 100644 --- a/src/ejdb/ejdb.c +++ b/src/ejdb/ejdb.c @@ -1825,7 +1825,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, switch (qf->tcop) { case TDBQCSTREQ: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1843,7 +1843,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, } case TDBQCSTRINC: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1861,7 +1861,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, } case TDBQCSTRBW: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1879,7 +1879,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, } case TDBQCSTREW: { _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1899,7 +1899,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1919,7 +1919,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1939,7 +1939,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); @@ -1987,7 +1987,7 @@ static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays, TCLIST *tokens = qf->exprlist; assert(tokens); _FETCHSTRFVAL(); - if ((qf->flags & EJCONDICASE) && (BSON_IS_STRING_TYPE(bt))) { + if ((qf->flags & EJCONDICASE) && (bt == BSON_STRING)) { cbufstrlen = tcicaseformat(fval, fvalsz - 1, sbuf, JBSTRINOPBUFFERSZ, &cbuf); if (cbufstrlen < 0) { _ejdbsetecode(qf->jb, cbufstrlen, __FILE__, __LINE__, __func__); -- cgit v1.2.3 From c65659713f7fd5648dd327a64aff791e831c7bc4 Mon Sep 17 00:00:00 2001 From: Albert Choy Date: Wed, 15 Apr 2015 18:52:12 -0400 Subject: Use proper testing, query as string for symbols --- src/ejdb/tests/ejdbtest2.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/ejdb/tests/ejdbtest2.c b/src/ejdb/tests/ejdbtest2.c index 43e050d..beea331 100644 --- a/src/ejdb/tests/ejdbtest2.c +++ b/src/ejdb/tests/ejdbtest2.c @@ -63,7 +63,7 @@ void testAddData(void) { bson_append_finish_object(&a1); bson_append_finish_array(&a1); //EOF complexarr CU_ASSERT_FALSE_FATAL(a1.err); - bson_append_symbol(&a1, "symbol_info", "apple"); + bson_append_symbol(&a1, "symbol", "apple"); bson_finish(&a1); ejdbsavebson(ccoll, &a1, &oid); bson_destroy(&a1); @@ -101,7 +101,7 @@ void testAddData(void) { bson_append_long(&a1, "1", 556667); bson_append_double(&a1, "2", 77676.22); bson_append_finish_array(&a1); - bson_append_symbol(&a1, "symbol_info", "application"); + bson_append_symbol(&a1, "symbol", "application"); bson_finish(&a1); CU_ASSERT_FALSE_FATAL(a1.err); @@ -124,7 +124,7 @@ void testAddData(void) { bson_append_long(&a1, "1", 222334); bson_append_double(&a1, "2", 77676.22); bson_append_finish_array(&a1); - bson_append_symbol(&a1, "symbol_info", "bison"); + bson_append_symbol(&a1, "symbol", "bison"); bson_finish(&a1); CU_ASSERT_FALSE_FATAL(a1.err); @@ -2613,8 +2613,8 @@ void testQuery29(void) { bson bsq1; bson_init_as_query(&bsq1); - bson_append_start_object(&bsq1, "symbol_info"); - bson_append_symbol(&bsq1, "$begin", "app"); + bson_append_start_object(&bsq1, "symbol"); + bson_append_string(&bsq1, "$begin", "app"); bson_append_finish_object(&bsq1); bson_finish(&bsq1); CU_ASSERT_FALSE_FATAL(bsq1.err); @@ -2625,12 +2625,16 @@ void testQuery29(void) { uint32_t count = 0; TCXSTR *log = tcxstrnew(); TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); - fprintf(stderr, "%s", TCXSTRPTR(log)); - fprintf(stderr, "RESULT count=%d\n", count); + //fprintf(stderr, "%s", TCXSTRPTR(log)); CU_ASSERT_EQUAL(count, 2); // should match symbol_info: apple, application CU_ASSERT_TRUE(TCLISTNUM(q1res) == 2); + for (int i = 0; i < TCLISTNUM(q1res); ++i) { + if (i == 0) CU_ASSERT_FALSE(bson_compare_string("apple", TCLISTVALPTR(q1res, i), "symbol")); + if (i == 1) CU_ASSERT_FALSE(bson_compare_string("application", TCLISTVALPTR(q1res, i), "symbol")); + } + bson_destroy(&bsq1); tclistdel(q1res); tcxstrdel(log); @@ -2644,7 +2648,7 @@ void testQuery30(void) { bson bsq1; bson_init_as_query(&bsq1); - bson_append_symbol(&bsq1, "symbol_info", "bison"); + bson_append_string(&bsq1, "symbol", "bison"); bson_finish(&bsq1); CU_ASSERT_FALSE_FATAL(bsq1.err); @@ -2654,12 +2658,15 @@ void testQuery30(void) { uint32_t count = 0; TCXSTR *log = tcxstrnew(); TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); - fprintf(stderr, "%s", TCXSTRPTR(log)); - fprintf(stderr, "RESULT count=%d\n", count); + //fprintf(stderr, "%s", TCXSTRPTR(log)); CU_ASSERT_EQUAL(count, 1); // should match symbol_info: bison CU_ASSERT_TRUE(TCLISTNUM(q1res) == 1); + for (int i = 0; i < TCLISTNUM(q1res); ++i) { + if (i == 0) CU_ASSERT_FALSE(bson_compare_string("bison", TCLISTVALPTR(q1res, i), "symbol")); + } + bson_destroy(&bsq1); tclistdel(q1res); tcxstrdel(log); @@ -2673,13 +2680,13 @@ void testQuery31(void) { bson bsq1; bson_init_as_query(&bsq1); - bson_append_start_object(&bsq1, "symbol_info"); + bson_append_start_object(&bsq1, "symbol"); bson_append_start_array(&bsq1, "$in"); - bson_append_symbol(&bsq1, "0", "apple"); - bson_append_symbol(&bsq1, "1", "bison"); + bson_append_string(&bsq1, "0", "apple"); + bson_append_string(&bsq1, "1", "bison"); bson_append_finish_array(&bsq1); bson_append_finish_object(&bsq1); - bson_finish(&bsq1); + bson_finish(&bsq1); CU_ASSERT_FALSE_FATAL(bsq1.err); EJQ *q1 = ejdbcreatequery(jb, &bsq1, NULL, 0, NULL); @@ -2688,12 +2695,16 @@ void testQuery31(void) { uint32_t count = 0; TCXSTR *log = tcxstrnew(); TCLIST *q1res = ejdbqryexecute(contacts, q1, &count, 0, log); - fprintf(stderr, "%s", TCXSTRPTR(log)); - fprintf(stderr, "RESULT count=%d\n", count); + //fprintf(stderr, "%s", TCXSTRPTR(log)); CU_ASSERT_EQUAL(count, 2); // should match symbol_info: apple, bison CU_ASSERT_TRUE(TCLISTNUM(q1res) == 2); + for (int i = 0; i < TCLISTNUM(q1res); ++i) { + if (i == 0) CU_ASSERT_FALSE(bson_compare_string("apple", TCLISTVALPTR(q1res, i), "symbol")); + if (i == 1) CU_ASSERT_FALSE(bson_compare_string("bison", TCLISTVALPTR(q1res, i), "symbol")); + } + bson_destroy(&bsq1); tclistdel(q1res); tcxstrdel(log); -- cgit v1.2.3