MojErr MojDbQuotaTest::testErrors() { #ifdef MOJ_USE_BDB MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbBerkeleyEngine()); #elif MOJ_USE_LDB MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbLevelEngine()); #else MojRefCountedPtr<MojDbStorageEngine> engine; #endif MojAllocCheck(engine.get()); MojRefCountedPtr<MojDbTestStorageEngine> testEngine(new MojDbTestStorageEngine(engine.get())); MojAllocCheck(testEngine.get()); MojErr err = testEngine->open(MojDbTestDir); MojTestErrCheck(err); MojDb db; err = db.open(MojDbTestDir, testEngine.get()); MojTestErrCheck(err); // test that failed put does not affect quota MojInt64 quotaUsage1 = 0; err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage1); MojTestErrCheck(err); err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock); MojTestErrCheck(err); err = put(db, MojTestKind3Objects[1]); MojTestErrExpected(err, MojErrDbDeadlock); MojInt64 quotaUsage2 = 0; err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage2); MojTestErrCheck(err); MojTestAssert(quotaUsage2 == quotaUsage1); // test that failed putQuota has no effect err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock); MojTestErrCheck(err); MojObject obj; err = obj.fromJson(_T("{\"owner\":\"com.foo.boo\",\"size\":1000}")); MojErrCheck(err); err = db.putQuotas(&obj, &obj + 1); MojTestErrExpected(err, MojErrDbDeadlock); MojInt64 quotaUsage3 = 0; err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage3); MojTestErrCheck(err); MojTestAssert(quotaUsage3 == quotaUsage1); // test that failed putKind has no effect err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock); MojTestErrCheck(err); err = obj.fromJson(MojTestKind3Str2); MojTestErrCheck(err); err = db.putKind(obj); MojTestErrExpected(err, MojErrDbDeadlock); MojInt64 quotaUsage4 = 0; err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage4); MojTestErrCheck(err); MojTestAssert(quotaUsage4 == quotaUsage1); err = db.close(); MojTestErrCheck(err); return MojErrNone; }
TEST_F(QuotaTest, enforce) { MojObject obj; // put quota MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) ); MojAssertNoErr( db.putQuotas(&obj, &obj + 1) ); // make kind2 inherit from kind1 MojAssertNoErr( obj.fromJson(MojTestKind2Str3) ); MojExpectNoErr( db.putKind(obj) ); //// end of prerequisites form prev tests // set quota size to current usage MojInt64 quotaUsage1 = 0; EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) ); MojAssertNoErr( obj.putString(_T("owner"), _T("com.foo.bar")) ); MojAssertNoErr( obj.putInt(_T("size"), quotaUsage1) ); MojExpectNoErr( db.putQuotas(&obj, &obj + 1) ); MojAssertNoErr( obj.fromJson(MojTestKind1Objects[3]) ); EXPECT_EQ( MojErrDbQuotaExceeded, db.put(obj) ); // Try to delete the kind MojString kindStr; MojAssertNoErr( kindStr.assign(_T("Test:1")) ); bool found = false; EXPECT_EQ( MojErrDbKindHasSubKinds, db.delKind(kindStr, found) ) << "The delete should be failure, because it contain sub kind \"Test2:1\""; EXPECT_FALSE( found ); }
MojErr MojDbIndexTest::assertCanAnswer(const MojChar* propsJson, const MojChar* queryJson, bool result, bool indexIncludeDeleted) { MojObject propsObj; MojErr err = propsObj.fromJson(propsJson); MojTestErrCheck(err); MojObject queryObj; err = queryObj.fromJson(queryJson); MojTestErrCheck(err); MojDbIndex index(NULL, NULL); MojObject prop; MojSize i = 0; for (;;) { if(propsObj.at(i++, prop)) { err = index.addProp(prop); MojTestErrCheck(err); } else { break; } } index.incDel(indexIncludeDeleted); MojRefCountedPtr<MojDbStorageIndex> storageIndex(new TestIndex(false)); MojAllocCheck(storageIndex.get()); MojDbReq req; err = index.open(storageIndex.get(), (MojInt64) 0, req); MojTestErrCheck(err); MojDbQuery query; err = query.fromObject(queryObj); MojTestErrCheck(err); MojTestAssert(index.canAnswer(query) == result); return MojErrNone; }
MojErr MojDbPermissionTest::testAdminPermissions(MojDb& db) { MojObject permission; MojErr err = permission.fromJson(MojTestAdminPermission1); MojTestErrCheck(err); err = db.putPermissions(&permission, &permission + 1); MojTestErrCheck(err); MojDbReq reqAdmin(false); err = reqAdmin.domain(_T("com.admin")); MojTestErrCheck(err); // put kind with non-matching owner with admin role MojObject kind; err = kind.fromJson(MojTestKind1); MojTestErrCheck(err); err = db.putKind(kind, MojDb::FlagNone, reqAdmin); MojTestErrCheck(err); err = kind.fromJson(MojTestKind2); MojTestErrCheck(err); err = db.putKind(kind, MojDb::FlagNone, reqAdmin); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbDistinctTest::run() { // TODO : description, youngseung.ji MojDb db; MojErr err = db.open(MojDbTestDir); MojTestErrCheck(err); // add kind MojObject kindObj; err = kindObj.fromJson(MojDistinctKindStr); MojTestErrCheck(err); err = db.putKind(kindObj); MojTestErrCheck(err); // put test objects for (MojSize i = 0; i < sizeof(MojDistinctTestObjects) / sizeof(MojChar*); ++i) { MojObject obj; err = obj.fromJson(MojDistinctTestObjects[i]); MojTestErrCheck(err); err = db.put(obj); MojTestErrCheck(err); } // Start testing err = simpleTest(db); MojTestErrCheck(err); err = db.close(); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbPerfUpdateTest::updateKind(MojDb& db, const MojChar* kindId, const MojChar* kindJson, const MojChar* extraIdxJson, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64)) { // register all the kinds MojTime time; MojErr err = putKinds(db, time); MojTestErrCheck(err); // put objects using createFn MojObject objs; err = putObjs(db, kindId, numObjectsBeforeUpdateKind, createFn, objs); MojTestErrCheck(err); // add an index MojObject kindObj; err = kindObj.fromJson(kindJson); MojTestErrCheck(err); MojObject indexes; kindObj.get(_T("indexes"), indexes); MojTestErrCheck(err); MojObject extraIdx; err = extraIdx.fromJson(extraIdxJson); MojTestErrCheck(err); indexes.push(extraIdx); err = kindObj.put(_T("indexes"), indexes); MojTestErrCheck(err); MojTime addIndexTime; MojTime dropIndexTime; err = timeUpdateKind(db, kindJson, kindObj, addIndexTime, dropIndexTime); MojTestErrCheck(err); MojUInt64 addTime = addIndexTime.microsecs(); MojUInt64 dropTime = dropIndexTime.microsecs(); err = MojPrintF("\n -------------------- \n"); MojTestErrCheck(err); err = MojPrintF(" updating kind %s - adding index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, addTime); MojTestErrCheck(err); err = MojPrintF(" time per add/reindex: %llu microsecs\n", (addTime) / (numUpdateKindIterations)); MojTestErrCheck(err); err = MojPrintF(" updating kind %s - dropping index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, dropTime); MojTestErrCheck(err); err = MojPrintF(" time per drop: %llu microsecs", (dropTime) / (numUpdateKindIterations)); MojTestErrCheck(err); err = MojPrintF("\n\n"); MojTestErrCheck(err); MojString buf; err = buf.format("Updating kind %s - adding index %s %llu times,%s,%llu,%llu,%llu,\nUpdating kind %s - dropping index %s %llu times,%s,%llu,%llu,%llu,\n", kindId, extraIdxJson, numUpdateKindIterations, kindId, addTime, addTime/numUpdateKindIterations, addTime/(1*numUpdateKindIterations), kindId, extraIdxJson, numUpdateKindIterations, kindId, dropTime, dropTime/numUpdateKindIterations, dropTime/(1*numUpdateKindIterations)); MojTestErrCheck(err); err = fileWrite(file, buf); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbSearchTest::run() { MojDb db; MojErr err = db.open(MojDbTestDir); MojTestErrCheck(err); // add kind MojObject kindObj; err = kindObj.fromJson(MojSearchKindStr); MojTestErrCheck(err); err = db.putKind(kindObj); MojTestErrCheck(err); // put test objects for (MojSize i = 0; i < sizeof(MojSearchTestObjects) / sizeof(MojChar*); ++i) { MojObject obj; err = obj.fromJson(MojSearchTestObjects[i]); MojTestErrCheck(err); err = db.put(obj); MojTestErrCheck(err); } err = simpleTest(db); MojTestErrCheck(err); err = filterTest(db); MojTestErrCheck(err); // add kind for page test err = kindObj.fromJson(MojSearchKindStr2); MojTestErrCheck(err); err = db.putKind(kindObj); MojTestErrCheck(err); // put test objects for page test for (MojSize i = 0; i < sizeof(MojSearchTestObjects2) / sizeof(MojChar*); ++i) { MojObject obj; err = obj.fromJson(MojSearchTestObjects2[i]); MojTestErrCheck(err); err = db.put(obj); MojTestErrCheck(err); } err = pageTest(db); MojTestErrCheck(err); err = db.close(); MojTestErrCheck(err); return MojErrNone; }
MojErr testCancel() { const MojChar* echoStr = _T("{\"hello\":\"world\"}"); MojObject expectedResponse; MojErr err = formatEchoResponse(echoStr, expectedResponse); MojTestErrCheck(err); MojRefCountedPtr<MojServiceRequest> req; err = m_service.createRequest(req); MojTestErrCheck(err); int callbackCount = 2; MojRefCountedPtr<EchoMultiResponseHdlr> handler(new EchoMultiResponseHdlr(expectedResponse, ++m_pendingResponseCount, callbackCount)); MojTestAssert(handler.get()); MojObject payload; err = payload.fromJson(echoStr); MojTestErrCheck(err); err = req->send(handler->m_slot, ServiceName, _T("cancellableecho"), payload, MojServiceRequest::Unlimited); MojTestErrCheck(err); err = receiveResponses(); MojTestErrCheck(err); MojTestAssert(handler->callbacksRemaining() == 1); // still have callback registered because 1 more response is expected // cancel request handler->m_slot.cancel(); sleep(1); return MojErrNone; }
MojErr testMultiEcho() { const MojChar* echoStr = _T("{\"hello\":\"world\"}"); MojObject expectedResponse; MojErr err = formatEchoResponse(echoStr, expectedResponse); MojTestErrCheck(err); MojRefCountedPtr<MojServiceRequest> req; err = m_service.createRequest(req); MojTestErrCheck(err); m_pendingResponseCount+= multiResponseCount; MojRefCountedPtr<EchoMultiResponseHdlr> hdlr(new EchoMultiResponseHdlr(expectedResponse, m_pendingResponseCount, multiResponseCount)); MojAllocCheck(hdlr.get()); MojObject payload; err = payload.fromJson(echoStr); MojTestErrCheck(err); err = req->send(hdlr->m_slot, ServiceName, _T("multiecho"), payload, MojServiceRequest::Unlimited); MojTestErrCheck(err); err = receiveResponses(); MojTestErrCheck(err); return MojErrNone; }
MojErr MojService::CategoryHandler::addMethod(const MojChar* methodName, Callback callback, bool pub, const MojChar* schemaJson) { MojAssert(methodName && callback); MojString str; MojErr err = str.assign(methodName); MojErrCheck(err); MojRefCountedPtr<MojSchema> schema; if (schemaJson) { MojObject schemaObj; err = schemaObj.fromJson(schemaJson); MojErrCheck(err); // add implicit $activity property MojObject properties; schemaObj.get(MojSchema::PropertiesKey, properties); MojObject activityProp; err = activityProp.putBool(MojSchema::OptionalKey, true); MojErrCheck(err); err = properties.put(_T("$activity"), activityProp); MojErrCheck(err); err = schemaObj.put(MojSchema::PropertiesKey, properties); MojErrCheck(err); schema.reset(new MojSchema); MojAllocCheck(schema.get()); err = schema->fromObject(schemaObj); MojErrCheck(err); } MojAssert(!m_callbackMap.contains(str)); err = m_callbackMap.put(str, CallbackInfo(callback, schema.get(), pub)); MojErrCheck(err); return MojErrNone; }
MojErr MojDbTextTokenizerTest::check(const MojChar* text, const MojChar* tokens) { // tokenize string MojString textStr; MojErr err = textStr.assign(text); MojTestErrCheck(err); MojSet<MojDbKey> set; MojRefCountedPtr<MojDbTextTokenizer> tokenizer(new MojDbTextTokenizer); MojAllocCheck(tokenizer.get()); err = tokenizer->init(_T("en_US")); MojTestErrCheck(err); err = tokenizer->tokenize(textStr, NULL, set); MojTestErrCheck(err); // check that tokens match MojObject obj; err = obj.fromJson(tokens); MojTestErrCheck(err); MojSize objSize = obj.size(); MojSize setSize = set.size(); MojTestAssert(objSize == setSize); for (MojObject::ConstArrayIterator i = obj.arrayBegin(); i != obj.arrayEnd(); ++i) { MojDbKey key; err = key.assign(*i); MojTestErrCheck(err); MojTestAssert(set.contains(key)); } return MojErrNone; }
MojErr MojDbPermissionTest::run() { MojDb db; MojObject conf; MojErr err = conf.fromJson(MojTestConf); MojTestErrCheck(err); err = db.configure(conf); MojErrCheck(err); err = db.open(MojDbTestDir); MojTestErrCheck(err); err = testInvalidPermissions(db); MojTestErrCheck(err); err = testAdminPermissions(db); MojTestErrCheck(err); err = testKindPermissions(db); MojTestErrCheck(err); err = testObjectPermissions(db); MojTestErrCheck(err); err = db.close(); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbQuotaTest::run() { MojDb db; MojErr err = db.open(MojDbTestDir); MojTestErrCheck(err); MojObject obj; err = obj.fromJson(MojTestKind1Str1); MojTestErrCheck(err); err = db.putKind(obj); MojTestErrCheck(err); err = testUsage(db); MojTestErrCheck(err); err = testMultipleQuotas(db); MojTestErrCheck(err); err = testEnforce(db); MojTestErrCheck(err); err = db.close(); MojErrCheck(err); err = testErrors(); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbPerfUpdateTest::timeUpdateKind(MojDb& db, const MojChar* kindJson, MojObject& kindObj, MojTime& addIndexTime, MojTime& dropIndexTime) { MojTime startTime; MojTime endTime; MojObject origKindObj; MojErr err = origKindObj.fromJson(kindJson); MojTestErrCheck(err); for (MojUInt64 i = 0; i < numUpdateKindIterations; i++) { err = MojGetCurrentTime(startTime); MojTestErrCheck(err); bool found; err = kindObj.del(MojDb::RevKey, found); MojTestErrCheck(err); err = db.putKind(kindObj); MojTestErrCheck(err); err = MojGetCurrentTime(endTime); MojTestErrCheck(err); addIndexTime += (endTime - startTime); totalTestTime += (endTime - startTime); err = MojGetCurrentTime(startTime); MojTestErrCheck(err); err = origKindObj.del(MojDb::RevKey, found); MojTestErrCheck(err); err = db.putKind(origKindObj); MojTestErrCheck(err); err = MojGetCurrentTime(endTime); MojTestErrCheck(err); dropIndexTime += (endTime - startTime); totalTestTime += (endTime - startTime); } return MojErrNone; }
MojErr MojDbPermissionTest::testKindPermissions(MojDb& db) { MojObject kind; MojErr err = kind.fromJson(MojTestKind1); MojTestErrCheck(err); // new kind, mismatched owner and caller MojDbReq req(false); err = req.domain(_T("com.bar")); MojTestErrCheck(err); err = db.putKind(kind, MojDb::FlagNone, req); MojTestErrExpected(err, MojErrDbPermissionDenied); // new kind, matched owner and caller err = req.domain(_T("com.foo")); MojTestErrCheck(err); err = db.putKind(kind, MojDb::FlagNone, req); MojTestErrCheck(err); // existing kind, matched owner and caller err = db.putKind(kind, MojDb::FlagNone, req); MojTestErrCheck(err); // existing kind, mismatched owner and caller err = req.domain(_T("com.bar")); MojTestErrCheck(err); err = db.putKind(kind, MojDb::FlagNone, req); MojTestErrExpected(err, MojErrDbPermissionDenied); // delKind, mismatched owner and caller MojString id; err = id.assign(_T("PermissionTest:1")); MojTestErrCheck(err); bool found = false; err = db.delKind(id, found, MojDb::FlagNone, req); MojTestErrExpected(err, MojErrDbPermissionDenied); return MojErrNone; }
void SetUp() { MojDbCoreTest::SetUp(); // add kind MojObject obj; MojAssertNoErr( obj.fromJson(MojTestKind1Str1) ); MojAssertNoErr( db.putKind(obj) ); }
MojErr MojSchemaTest::checkValid(const MojChar* schemaJson, const MojChar* instanceJson, bool expected) { MojObject schemaObj; MojErr err = schemaObj.fromJson(schemaJson); MojTestErrCheck(err); MojSchema schema; err = schema.fromObject(schemaObj); MojTestErrCheck(err); MojObject instance; err = instance.fromJson(instanceJson); MojTestErrCheck(err); MojSchema::Result res; err = schema.validate(instance, res); MojTestErrCheck(err); MojTestAssert(res.valid() == expected); return MojErrNone; }
/** * addKind */ MojErr MojDbShardManagerTest::addKind (const MojChar* strKind, MojDb& db) { MojObject kind; MojErr err = kind.fromJson(strKind); MojErrCheck(err); err = db.putKind(kind); MojErrCheck(err); return MojErrNone; }
MojErr MojDbIndexTest::indexFromObject(MojDbIndex& index, const MojChar* json) { MojObject obj; MojErr err = obj.fromJson(json); MojErrCheck(err); err = index.fromObject(obj, MojString()); MojErrCheck(err); return MojErrNone; }
MojErr MojDbQuotaTest::put(MojDb& db, const MojChar* objJson) { MojObject obj; MojErr err = obj.fromJson(objJson); MojTestErrCheck(err); err = db.put(obj); MojErrCheck(err); return MojErrNone; }
MojErr MojDbPermissionTest::checkInvalid(const MojChar* json, MojDb& db) { MojObject permission; MojErr err = permission.fromJson(json); MojTestErrCheck(err); err = db.putPermissions(&permission, &permission+1); MojTestErrExpected(err, MojErrDbInvalidCaller); return MojErrNone; }
MojErr MojDbIndexTest::put(MojDbIndex& index, MojObject id, const MojChar* jsonNew, const MojChar* jsonOld) { MojObject newObj; MojErr err = newObj.fromJson(jsonNew); MojTestErrCheck(err); err = newObj.put(MojDb::IdKey, id); MojTestErrCheck(err); MojObject oldObj; if (jsonOld) { err = oldObj.fromJson(jsonOld); MojTestErrCheck(err); err = oldObj.put(MojDb::IdKey, id); MojTestErrCheck(err); } TestTxn txn; err = index.update(&newObj, jsonOld ? &oldObj : NULL, &txn, false); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbKindEngine::addBuiltin(const MojChar* json, MojDbReq& req) { MojLogTrace(s_log); MojAssertWriteLocked(m_db->m_schemaLock); MojObject obj; MojErr err = obj.fromJson(json); MojErrCheck(err); err = putKind(obj, req, true); MojErrCheck(err); return MojErrNone; }
MojErr MojDbSearchCacheTest::run() { MojDb db; MojErr err = db.open(MojDbTestDir); MojTestErrCheck(err); // add kind MojObject kindObj; err = kindObj.fromJson(SearchCacheKindStr); MojTestErrCheck(err); err = db.putKind(kindObj); MojTestErrCheck(err); // put test objects for (MojSize i = 0; i < sizeof(MojSearchCacheObjects) / sizeof(MojChar*); ++i) { MojObject obj; err = obj.fromJson(MojSearchCacheObjects[i]); MojTestErrCheck(err); err = db.put(obj); MojTestErrCheck(err); } err = testQueryKey(); MojTestErrCheck(err); err = operatorTest(db); MojTestErrCheck(err); /*** :: TODO :: make query scenario err = queryTest(db); MojTestErrCheck(err); ***/ err = db.close(); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbPermissionTest::putPermissions(MojDb& db) { MojDbReq reqOwner(false); MojErr err = reqOwner.domain(_T("com.foo")); MojTestErrCheck(err); MojDbReq reqGranted(false); err = reqGranted.domain("com.granted 3287"); MojTestErrCheck(err); MojDbReq reqBad(false); err = reqBad.domain("com.bad"); MojTestErrCheck(err); MojObject permission; err = permission.fromJson(MojTestPermission1); MojTestErrCheck(err); err = db.putPermissions(&permission, &permission + 1, reqBad); MojTestErrExpected(err, MojErrDbPermissionDenied); err = reqBad.abort(); MojTestErrCheck(err); err = db.putPermissions(&permission, &permission + 1, reqOwner); MojTestErrCheck(err); err = db.putPermissions(&permission, &permission + 1, reqGranted); MojTestErrExpected(err, MojErrDbPermissionDenied); err = reqGranted.abort(); MojTestErrCheck(err); err = permission.fromJson(MojTestPermissionWildcard); MojTestErrCheck(err); err = db.putPermissions(&permission, &permission + 1, reqOwner); MojTestErrCheck(err); err = permission.fromJson(MojTestPermissionWildcard2); MojTestErrCheck(err); err = db.putPermissions(&permission, &permission + 1, reqOwner); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbIndexTest::del(MojDbIndex& index, MojObject id, const MojChar* json, bool purge) { MojObject oldObj; MojErr err = oldObj.fromJson(json); MojTestErrCheck(err); err = oldObj.put(MojDb::IdKey, id); MojTestErrCheck(err); MojObject newObj = oldObj; TestTxn txn; err = newObj.put(MojDb::DelKey, true); MojTestErrCheck(err); err = index.update(purge ? NULL: &newObj, &oldObj, &txn, false); MojTestErrCheck(err); return MojErrNone; }
void SetUp() { const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); path = std::string(tempFolder) + '/' + test_info->test_case_name() + '-' + test_info->name(); // open MojAssertNoErr( db.open(path.c_str()) ); // add type MojObject obj; MojAssertNoErr( obj.fromJson(MojKindStr) ); MojAssertNoErr( db.putKind(obj) ); }
MojErr sendEcho(const MojChar* json, const MojObject& expectedResponse, const MojChar* method) { MojRefCountedPtr<EchoResponseHdlr> handler(new EchoResponseHdlr(expectedResponse, ++m_pendingResponseCount)); MojAllocCheck(handler.get()); MojRefCountedPtr<MojServiceRequest> req; MojErr err = m_service.createRequest(req); MojTestErrCheck(err); MojObject payload; err = payload.fromJson(json); MojTestErrCheck(err); err = req->send(handler->m_slot, ServiceName, method, payload); MojTestErrCheck(err); return MojErrNone; }
MojErr MojDbIndexTest::assertContains(TestIndex& ti, MojObject id, const MojChar* json) { MojObject array; MojErr err = array.fromJson(json); MojTestErrCheck(err); MojObjectWriter(writer); MojObject val; MojSize idx = 0; while (array.at(idx++, val)) { err = val.visit(writer); MojTestErrCheck(err); } err = id.visit(writer); MojTestErrCheck(err); MojDbKey key; err = key.assign(writer.buf()); MojTestErrCheck(err); err = assertContains(ti, id, key); MojTestErrCheck(err); return MojErrNone; }
ConnectionState::ConnectionStateHandler::ConnectionStateHandler(MojService* service, ConnectionState* connState) : m_connMgrSubscriptionSlot(this, &ConnectionState::ConnectionStateHandler::connectionManagerResult), m_service(service), m_connState(connState), m_receivedResponse(false) { MojLogInfo(IMServiceApp::s_log, "ConnectionStateHandler constructor"); MojRefCountedPtr<MojServiceRequest> req; MojErr err = m_service->createRequest(req); if (err) { MojLogError(IMServiceApp::s_log, _T("ConnectionStateHandler: create request failed")); } else { MojObject params; params.put("subscribe", true); params.put("start", true); params.put("detailedEvents", true); // This tells activitymanager to send us updates whenever the trigger changes const char* activityJson = "{\"name\":\"Libpurple connection watch\"," "\"description\":\"Libpurple connection watch\"," // Need immediate:true to prevent blocking other low priority activities from running "\"type\": {\"immediate\": true, \"priority\": \"low\"}," "\"requirements\":{\"internet\":true}" "}"; MojObject activity; activity.fromJson(activityJson); params.put("activity", activity); err = req->send(m_connMgrSubscriptionSlot, "com.palm.activitymanager","create", params, MojServiceRequest::Unlimited); if (err) { MojLogError(IMServiceApp::s_log, _T("ConnectionStateHandler send request failed")); } } }