本文整理汇总了C++中MojObject::fromJson方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::fromJson方法的具体用法?C++ MojObject::fromJson怎么用?C++ MojObject::fromJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojObject
的用法示例。
在下文中一共展示了MojObject::fromJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testErrors
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;
}
示例2: MojAssertNoErr
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 );
}
示例3: assertCanAnswer
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;
}
示例4: testAdminPermissions
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;
}
示例5: run
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;
}
示例6: updateKind
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;
}
示例7: run
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;
}
示例8: testCancel
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;
}
示例9: testMultiEcho
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;
}
示例10: CallbackInfo
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;
}
示例11: check
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;
}
示例12: run
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;
}
示例13: run
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;
}
示例14: timeUpdateKind
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;
}
示例15: testKindPermissions
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;
}