static void test_write_concern_basic (void) { mongoc_write_concern_t *write_concern; const bson_t *b; bson_iter_t iter; write_concern = mongoc_write_concern_new(); /* * Test defaults. */ assert(write_concern); assert(!mongoc_write_concern_get_fsync(write_concern)); assert(!mongoc_write_concern_get_journal(write_concern)); assert(mongoc_write_concern_get_w(write_concern) == MONGOC_WRITE_CONCERN_W_DEFAULT); assert(!mongoc_write_concern_get_wtimeout(write_concern)); assert(!mongoc_write_concern_get_wmajority(write_concern)); mongoc_write_concern_set_fsync(write_concern, TRUE); assert(mongoc_write_concern_get_fsync(write_concern)); mongoc_write_concern_set_fsync(write_concern, FALSE); assert(!mongoc_write_concern_get_fsync(write_concern)); mongoc_write_concern_set_journal(write_concern, TRUE); assert(mongoc_write_concern_get_journal(write_concern)); mongoc_write_concern_set_journal(write_concern, FALSE); assert(!mongoc_write_concern_get_journal(write_concern)); /* * Test changes to w. */ mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_MAJORITY); assert(mongoc_write_concern_get_wmajority(write_concern)); mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_DEFAULT); assert(!mongoc_write_concern_get_wmajority(write_concern)); mongoc_write_concern_set_wmajority(write_concern, 1000); assert(mongoc_write_concern_get_wmajority(write_concern)); assert(mongoc_write_concern_get_wtimeout(write_concern) == 1000); mongoc_write_concern_set_wtimeout(write_concern, 0); assert(!mongoc_write_concern_get_wtimeout(write_concern)); mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_DEFAULT); assert(mongoc_write_concern_get_w(write_concern) == MONGOC_WRITE_CONCERN_W_DEFAULT); mongoc_write_concern_set_w(write_concern, 3); assert(mongoc_write_concern_get_w(write_concern) == 3); /* * Check generated bson. */ mongoc_write_concern_set_fsync(write_concern, TRUE); mongoc_write_concern_set_journal(write_concern, TRUE); b = _mongoc_write_concern_freeze(write_concern); assert(bson_iter_init_find(&iter, b, "fsync") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter)); assert(bson_iter_init_find(&iter, b, "j") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter)); assert(bson_iter_init_find(&iter, b, "w") && BSON_ITER_HOLDS_INT32(&iter) && bson_iter_int32(&iter) == 3); assert(b); mongoc_write_concern_destroy(write_concern); }
Array HHVM_METHOD(MongoDBDriverWriteConcern, __debugInfo) { MongoDBDriverWriteConcernData* data = Native::data<MongoDBDriverWriteConcernData>(this_); const char *wtag = mongoc_write_concern_get_wtag(data->m_write_concern); const int32_t w = mongoc_write_concern_get_w(data->m_write_concern); Array retval = Array::Create(); if (wtag) { retval.set(s_MongoDriverWriteConcern_w, (char*)wtag); } else if (mongoc_write_concern_get_wmajority(data->m_write_concern)) { retval.set(s_MongoDriverWriteConcern_w, "majority"); } else if (w != MONGOC_WRITE_CONCERN_W_DEFAULT) { retval.set(s_MongoDriverWriteConcern_w, w); } retval.set(s_MongoDriverWriteConcern_wmajority, mongoc_write_concern_get_wmajority(data->m_write_concern)); retval.set(s_MongoDriverWriteConcern_wtimeout, mongoc_write_concern_get_wtimeout(data->m_write_concern)); if (data->m_write_concern->fsync_ != MONGOC_WRITE_CONCERN_FSYNC_DEFAULT) { retval.set(s_MongoDriverWriteConcern_fsync, mongoc_write_concern_get_fsync(data->m_write_concern)); } else { retval.set(s_MongoDriverWriteConcern_fsync, Variant()); } if (data->m_write_concern->journal != MONGOC_WRITE_CONCERN_JOURNAL_DEFAULT) { retval.set(s_MongoDriverWriteConcern_journal, mongoc_write_concern_get_journal(data->m_write_concern)); } else { retval.set(s_MongoDriverWriteConcern_journal, Variant()); } return retval; }
static void test_write_concern_basic (void) { mongoc_write_concern_t *write_concern; const bson_t *gle; const bson_t *bson; bson_iter_t iter; write_concern = mongoc_write_concern_new(); BEGIN_IGNORE_DEPRECATIONS; /* * Test defaults. */ ASSERT(write_concern); ASSERT(!mongoc_write_concern_get_fsync(write_concern)); ASSERT(!mongoc_write_concern_get_journal(write_concern)); ASSERT(mongoc_write_concern_get_w(write_concern) == MONGOC_WRITE_CONCERN_W_DEFAULT); ASSERT(!mongoc_write_concern_get_wtimeout(write_concern)); ASSERT(!mongoc_write_concern_get_wmajority(write_concern)); mongoc_write_concern_set_fsync(write_concern, true); ASSERT(mongoc_write_concern_get_fsync(write_concern)); mongoc_write_concern_set_fsync(write_concern, false); ASSERT(!mongoc_write_concern_get_fsync(write_concern)); mongoc_write_concern_set_journal(write_concern, true); ASSERT(mongoc_write_concern_get_journal(write_concern)); mongoc_write_concern_set_journal(write_concern, false); ASSERT(!mongoc_write_concern_get_journal(write_concern)); /* * Test changes to w. */ mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_MAJORITY); ASSERT(mongoc_write_concern_get_wmajority(write_concern)); mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_DEFAULT); ASSERT(!mongoc_write_concern_get_wmajority(write_concern)); mongoc_write_concern_set_wmajority(write_concern, 1000); ASSERT(mongoc_write_concern_get_wmajority(write_concern)); ASSERT(mongoc_write_concern_get_wtimeout(write_concern) == 1000); mongoc_write_concern_set_wtimeout(write_concern, 0); ASSERT(!mongoc_write_concern_get_wtimeout(write_concern)); mongoc_write_concern_set_w(write_concern, MONGOC_WRITE_CONCERN_W_DEFAULT); ASSERT(mongoc_write_concern_get_w(write_concern) == MONGOC_WRITE_CONCERN_W_DEFAULT); mongoc_write_concern_set_w(write_concern, 3); ASSERT(mongoc_write_concern_get_w(write_concern) == 3); /* * Check generated bson. */ mongoc_write_concern_set_fsync(write_concern, true); mongoc_write_concern_set_journal(write_concern, true); gle = _mongoc_write_concern_get_gle(write_concern); ASSERT(bson_iter_init_find(&iter, gle, "getlasterror") && BSON_ITER_HOLDS_INT32(&iter) && bson_iter_int32(&iter) == 1); ASSERT(bson_iter_init_find(&iter, gle, "fsync") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter)); ASSERT(bson_iter_init_find(&iter, gle, "j") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter)); ASSERT(bson_iter_init_find(&iter, gle, "w") && BSON_ITER_HOLDS_INT32(&iter) && bson_iter_int32(&iter) == 3); ASSERT(gle); bson = _mongoc_write_concern_get_bson(write_concern); ASSERT(!bson_iter_init_find(&iter, bson, "getlasterror")); ASSERT(bson_iter_init_find(&iter, bson, "fsync") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter)); ASSERT(bson_iter_init_find(&iter, bson, "j") && BSON_ITER_HOLDS_BOOL(&iter) && bson_iter_bool(&iter)); ASSERT(bson_iter_init_find(&iter, bson, "w") && BSON_ITER_HOLDS_INT32(&iter) && bson_iter_int32(&iter) == 3); ASSERT(bson); mongoc_write_concern_destroy(write_concern); END_IGNORE_DEPRECATIONS; }