Beispiel #1
0
MojErr MojSignalTest::test3()
{
	// one handler fire
	MojRefCountedPtr<TestSource> source(new TestSource);
	MojAllocCheck(source.get());
	MojRefCountedPtr<TestHandler> handler1(new TestHandler);
	MojAllocCheck(handler1.get());
	source->add3Slot(handler1->m_slot3);
	MojTestAssert(handler1->refCount() == 2);
	source->fire3(200, "hello", 1.0);
	MojTestAssert(handler1->m_handle3Count == 1);
	MojTestAssert(handler1->m_lastInt == 200 && handler1->m_lastDouble == 1.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello"));
	MojTestAssert(handler1->refCount() == 1);
	source->fire3(200, "hello", 1.0);
	MojTestAssert(handler1->m_handle3Count == 1);
	// two handlers
	MojRefCountedPtr<TestHandler> handler2(new TestHandler);
	MojAllocCheck(handler2.get());
	source->add3Slot(handler1->m_slot3);
	source->add3Slot(handler2->m_slot3);
	source->fire3(201, "hello2", 2.0);
	MojTestAssert(handler1->m_lastInt == 201 && handler1->m_lastDouble == 2.0);
	MojTestAssert(handler2->m_lastInt == 201 && handler2->m_lastDouble == 2.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello2"));
	// cancel
	source->add3Slot(handler1->m_slot3);
	source->add3Slot(handler2->m_slot3);
	MojTestAssert(source->m_numCancels == 0);
	handler1->m_slot3.cancel();
	source->fire3(202, "hello3", 3.0);
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 201 && handler1->m_lastDouble == 2.0);
	MojTestAssert(handler2->m_lastInt == 202 && handler2->m_lastDouble == 3.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello3"));
	// cancel from callback
	source->add3Slot(handler1->m_slot3Cancel);
	source->add3Slot(handler2->m_slot3);
	source->fire3(203, "hello4", 4.0);
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 203 && handler1->m_lastDouble == 4.0);
	MojTestAssert(handler2->m_lastInt == 203 && handler2->m_lastDouble == 4.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello4"));
	source->add3Slot(handler2->m_slot3);
	source->fire3(204, "hello5", 5.0);
	MojTestAssert(handler1->m_lastInt == 203 && handler1->m_lastDouble == 4.0);
	MojTestAssert(handler2->m_lastInt == 204 && handler2->m_lastDouble == 5.0);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello5"));

	return MojErrNone;
}
Beispiel #2
0
MojErr MojSignalTest::test2()
{
	// one handler fire
	MojRefCountedPtr<TestSource> source(new TestSource);
	MojAllocCheck(source.get());
	MojRefCountedPtr<TestHandler> handler1(new TestHandler);
	MojAllocCheck(handler1.get());
	source->add2Slot(handler1->m_slot2);
	MojTestAssert(handler1->refCount() == 2);
	source->fire2(200, "hello");
	MojTestAssert(handler1->m_handle2Count == 1);
	MojTestAssert(handler1->m_lastInt == 200);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello"));
	MojTestAssert(handler1->refCount() == 1);
	source->fire2(200, "hello");
	MojTestAssert(handler1->m_handle2Count == 1);
	// two handlers
	MojRefCountedPtr<TestHandler> handler2(new TestHandler);
	MojAllocCheck(handler2.get());
	source->add2Slot(handler1->m_slot2);
	source->add2Slot(handler2->m_slot2);
	source->fire2(201, "hello2");
	MojTestAssert(handler1->m_lastInt == 201);
	MojTestAssert(handler2->m_lastInt == 201);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello2"));
	// cancel
	source->add2Slot(handler1->m_slot2);
	source->add2Slot(handler2->m_slot2);
	MojTestAssert(source->m_numCancels == 0);
	handler1->m_slot2.cancel();
	source->fire2(202, "hello3");
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 201);
	MojTestAssert(handler2->m_lastInt == 202);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello2"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello3"));
	// cancel from callback
	source->add2Slot(handler2->m_slot2);
	source->add2Slot(handler1->m_slot2Cancel);
	source->fire2(203, "hello4");
	MojTestAssert(source->m_numCancels == 1);
	MojTestAssert(handler1->m_lastInt == 203);
	MojTestAssert(handler2->m_lastInt == 203);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello4"));
	source->add2Slot(handler2->m_slot2);
	source->fire2(204, "hello5");
	MojTestAssert(handler1->m_lastInt == 203);
	MojTestAssert(handler2->m_lastInt == 204);
	MojTestAssert(!MojStrCmp(handler1->m_lastStr, "hello4"));
	MojTestAssert(!MojStrCmp(handler2->m_lastStr, "hello5"));

	return MojErrNone;
}
Beispiel #3
0
MojErr MojDbQuery::stringToOp(const MojChar* str, CompOp& opOut)
{
	for (const StrOp* op = s_ops; op->m_str != NULL; ++op) {
		if (MojStrCmp(op->m_str, str) == 0) {
			opOut = op->m_op;
			return MojErrNone;
		}
	}
	MojErrThrow(MojErrDbInvalidQueryOp);
}
Beispiel #4
0
MojErr MojLogger::levelFromString(const MojChar* str, Level& levelOut)
{
	MojAssertNoLog(str);

	for (int i = 0; i <= LevelMax; ++i) {
		if (!MojStrCmp(str, s_levelNames[i])) {
			levelOut = (Level) i;
			return MojErrNone;
		}
	}
	MojErrThrowMsg(MojErrLogLevelNotFound, _T("log: level not found: '%s'"), str);
}