int main() { #ifndef BOOST_NO_EXCEPTIONS try { #endif double v0; alps::SimpleXMLHandler<double> handler0("VALUE0", v0); double v1; alps::SimpleXMLHandler<double> handler1("VALUE1", v1, "value"); alps::CompositeXMLHandler handler("TEST"); handler.add_handler(handler0); handler.add_handler(handler1); alps::XMLParser parser(handler); parser.parse(std::cin); std::cout << v0 << std::endl << v1 << std::endl; #ifndef BOOST_NO_EXCEPTIONS } catch (std::exception& exp) { std::cerr << exp.what() << std::endl; std::abort(); } #endif return 0; }
int main() { flinter::Logger::SetFilter(flinter::Logger::kLevelVerbose); signals_ignore(SIGPIPE); Handler handler1("1"); Handler handler2("2"); flinter::EasyServer s; g_server = &s; if (!s.Listen(5566, &handler1)) { return EXIT_FAILURE; } if (!s.Listen(5567, &handler2)) { return EXIT_FAILURE; } if (!s.Initialize(3, 7)) { return EXIT_FAILURE; } msleep(10000); s.Shutdown(); return EXIT_SUCCESS; }
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; }
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; }
MojErr MojSignalTest::test1() { // one handler fire MojRefCountedPtr<TestSource> source(new TestSource); MojAllocCheck(source.get()); MojRefCountedPtr<TestHandler> handler1(new TestHandler); MojAllocCheck(handler1.get()); source->add1Slot(handler1->m_slot1); MojTestAssert(handler1->refCount() == 2); source->fire1(200); MojTestAssert(handler1->m_handle1Count == 1); MojTestAssert(handler1->m_lastInt == 200); MojTestAssert(handler1->refCount() == 1); source->fire1(200); MojTestAssert(handler1->m_handle1Count == 1); // two handlers MojRefCountedPtr<TestHandler> handler2(new TestHandler); MojAllocCheck(handler2.get()); source->add1Slot(handler1->m_slot1); source->add1Slot(handler2->m_slot1); source->fire1(201); MojTestAssert(handler1->m_lastInt == 201); MojTestAssert(handler2->m_lastInt == 201); // cancel source->add1Slot(handler1->m_slot1); source->add1Slot(handler2->m_slot1); MojTestAssert(source->m_numCancels == 0); handler1->m_slot1.cancel(); source->fire1(202); MojTestAssert(source->m_numCancels == 1); MojTestAssert(handler1->m_lastInt == 201); MojTestAssert(handler2->m_lastInt == 202); // cancel from callback source->add1Slot(handler1->m_slot1Cancel); source->add1Slot(handler2->m_slot1); source->fire1(203); MojTestAssert(source->m_numCancels == 1); MojTestAssert(handler1->m_lastInt == 203); MojTestAssert(handler2->m_lastInt == 203); source->add1Slot(handler2->m_slot1); source->fire1(204); MojTestAssert(handler1->m_lastInt == 203); MojTestAssert(handler2->m_lastInt == 204); return MojErrNone; }
// Listing 3 code/ch12 int ACE_TMAIN (int, ACE_TCHAR *[]) { HA_Device_Repository rep; ACE_Thread_Mutex rep_mutex; //FUZZ: disable check_for_lack_ACE_OS ACE_Condition<ACE_Thread_Mutex> wait (rep_mutex); //FUZZ: enable check_for_lack_ACE_OS HA_CommandHandler handler1 (rep, wait, rep_mutex); HA_CommandHandler handler2 (rep, wait, rep_mutex); handler1.activate (); handler2.activate (); handler1.wait (); handler2.wait (); return 0; }
void UT_LifeTimerKeySequenceHandler::t_keySequenceValidator() { // life timer feature enabled scenario EXPECT(CRepository, Get) .willOnce(invoke(this, setLifeTimerData)) .returns(KErrNone); expect("KeySequenceHandler::setKeySequenceValidator") .with(QRegExp::escape(KCodeLifeTimer)); QScopedPointer<LifeTimerKeySequenceHandler> handler1( new LifeTimerKeySequenceHandler()); QVERIFY(verify()); // life timer feature not enabled scenario EXPECT(CRepository, Get).returns(KErrNotFound); expect("KeySequenceHandler::setKeySequenceValidator").times(0); QScopedPointer<LifeTimerKeySequenceHandler> handler2( new LifeTimerKeySequenceHandler()); QVERIFY(verify()); }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // static methods // --------------------------------------------------------------------------- void NIImporter_DlrNavteq::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) { // check whether the option is set (properly) if (!oc.isSet("dlr-navteq-prefix")) { return; } time_t csTime; time(&csTime); // parse file(s) LineReader lr; // load nodes std::map<std::string, PositionVector> myGeoms; PROGRESS_BEGIN_MESSAGE("Loading nodes"); std::string file = oc.getString("dlr-navteq-prefix") + "_nodes_unsplitted.txt"; NodesHandler handler1(nb.getNodeCont(), file, myGeoms); if (!lr.setFile(file)) { throw ProcessError("The file '" + file + "' could not be opened."); } lr.readAll(handler1); PROGRESS_DONE_MESSAGE(); // load street names if given and wished std::map<std::string, std::string> streetNames; // nameID : name if (oc.getBool("output.street-names")) { file = oc.getString("dlr-navteq-prefix") + "_names.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading Street Names"); NamesHandler handler4(file, streetNames); lr.readAll(handler4); PROGRESS_DONE_MESSAGE(); } else { WRITE_WARNING("Output will not contain street names because the file '" + file + "' was not found"); } } // load edges PROGRESS_BEGIN_MESSAGE("Loading edges"); file = oc.getString("dlr-navteq-prefix") + "_links_unsplitted.txt"; // parse the file EdgesHandler handler2(nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(), file, myGeoms, streetNames); if (!lr.setFile(file)) { throw ProcessError("The file '" + file + "' could not be opened."); } lr.readAll(handler2); nb.getEdgeCont().recheckLaneSpread(); PROGRESS_DONE_MESSAGE(); // load traffic lights if given file = oc.getString("dlr-navteq-prefix") + "_traffic_signals.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading traffic lights"); TrafficlightsHandler handler3(nb.getNodeCont(), nb.getTLLogicCont(), nb.getEdgeCont(), file); lr.readAll(handler3); PROGRESS_DONE_MESSAGE(); } // load prohibited manoeuvres if given file = oc.getString("dlr-navteq-prefix") + "_prohibited_manoeuvres.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading prohibited manoeuvres"); ProhibitionHandler handler6(nb.getEdgeCont(), file, csTime); lr.readAll(handler6); PROGRESS_DONE_MESSAGE(); } // load connected lanes if given file = oc.getString("dlr-navteq-prefix") + "_connected_lanes.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading connected lanes"); ConnectedLanesHandler handler7(nb.getEdgeCont()); lr.readAll(handler7); PROGRESS_DONE_MESSAGE(); } // load time restrictions if given file = oc.getString("dlr-navteq-prefix") + "_links_timerestrictions.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading time restrictions"); if (!oc.isDefault("construction-date")) { csTime = readDate(oc.getString("construction-date")); } TimeRestrictionsHandler handler5(nb.getEdgeCont(), nb.getDistrictCont(), csTime); lr.readAll(handler5); handler5.printSummary(); PROGRESS_DONE_MESSAGE(); } }
MojErr MojSignalTest::test0() { // one handler fire MojRefCountedPtr<TestSource> source(new TestSource); MojAllocCheck(source.get()); MojRefCountedPtr<TestHandler> handler1(new TestHandler); MojAllocCheck(handler1.get()); source->add0Slot(handler1->m_slot0); MojTestAssert(handler1->refCount() == 2); source->call0(); MojTestAssert(handler1->m_handle0Count == 1); MojTestAssert(handler1->refCount() == 2); source->fire0(); MojTestAssert(handler1->m_handle0Count == 2); MojTestAssert(handler1->refCount() == 1); source->fire0(); MojTestAssert(handler1->m_handle0Count == 2); source->call0(); MojTestAssert(handler1->m_handle0Count == 2); // two handlers MojRefCountedPtr<TestHandler> handler2(new TestHandler); MojAllocCheck(handler2.get()); source->add0Slot(handler1->m_slot0); source->add0Slot(handler2->m_slot0); source->call0(); MojTestAssert(handler1->m_handle0Count == 3); MojTestAssert(handler2->m_handle0Count == 1); source->fire0(); MojTestAssert(handler1->m_handle0Count == 4); MojTestAssert(handler2->m_handle0Count == 2); // cancel source->add0Slot(handler1->m_slot0); source->add0Slot(handler2->m_slot0); MojTestAssert(source->m_numCancels == 0); handler1->m_slot0.cancel(); source->fire0(); MojTestAssert(source->m_numCancels == 1); MojTestAssert(handler1->m_handle0Count == 4); MojTestAssert(handler2->m_handle0Count == 3); // cancel from callback source->add0Slot(handler1->m_slot0Cancel); source->add0Slot(handler2->m_slot0); source->fire0(); MojTestAssert(source->m_numCancels == 1); MojTestAssert(handler1->m_handle0Count == 5); MojTestAssert(handler2->m_handle0Count == 4); source->add0Slot(handler2->m_slot0); source->fire0(); MojTestAssert(handler1->m_handle0Count == 5); MojTestAssert(handler2->m_handle0Count == 5); // cancel from callback with call source->add0Slot(handler1->m_slot0Cancel); source->add0Slot(handler2->m_slot0); source->call0(); MojTestAssert(source->m_numCancels == 2); MojTestAssert(handler1->m_handle0Count == 6); MojTestAssert(handler2->m_handle0Count == 6); source->call0(); MojTestAssert(handler1->m_handle0Count == 6); MojTestAssert(handler2->m_handle0Count == 7); return MojErrNone; }