TEST_F(IncreaseThirstTest, Execute_SetTimerIfNoTimerSet) { ON_CALL(mOwner, hasAttribute("IncreaseThirst.timer")) .WillByDefault(Return(false)); IncreaseThirst increaseThirst(mWorld, mOwner, 1); EXPECT_CALL(mOwner, addAttribute(std::string("IncreaseThirst.timer"), _)) .Times(1); increaseThirst.execute(0); }
TEST(chatpresenter, test_postingsms) { Poco::SharedPtr<MockChatService> m(new MockChatService); Mvp::Presenter::TextChatPresenter presenter(m.get()); Poco::SharedPtr<MockChatView> v(new MockChatView()); EXPECT_CALL(*v, initialize()); ON_CALL(*m, getParticipants()) .WillByDefault(Return(contacts)); ON_CALL(*m, messageHistory(_)) .WillByDefault(Return(messages)); EXPECT_CALL(*m, chatName()); EXPECT_CALL(*v, setChatTitle(_)); EXPECT_CALL(*m, messageHistory(_)); EXPECT_CALL(*m, isConsumer()); EXPECT_CALL(*v, enableControls(_)); EXPECT_CALL(*v, showLeaveAction(_)); EXPECT_CALL(*m, getParticipants()); EXPECT_CALL(*v, setParticipants(_)); presenter.setView(v.get()); EXPECT_CALL(*v, showView()); presenter.showView(); EXPECT_CALL(*v, setSmsMode(true)); v->triggerToggleMode(); EXPECT_CALL(*m, postSMS(_)); v->triggerPostMessage(); EXPECT_CALL(*v, reportMessageStatus( Mvp::View::AbstractChatView::SmsDelivered, _)); m->triggerSmsDelivered(); EXPECT_CALL(*v, reportMessageStatus( Mvp::View::AbstractChatView::MiscError, _)); m->triggerSmsError(); }
void testOneShotAttributeSubscription(const T& expectedValue, SubscribeTo subscribeTo, ChangeAttribute setAttribute, const std::string& attributeName) { MockSubscriptionListenerOneType<T>* mockListener = new MockSubscriptionListenerOneType<T>(); // Use a semaphore to count and wait on calls to the mock listener ON_CALL(*mockListener, onReceive(Eq(expectedValue))) .WillByDefault(ReleaseSemaphore(&semaphore)); std::shared_ptr<ISubscriptionListener<T>> subscriptionListener( mockListener); std::shared_ptr<tests::DefaulttestProvider> testProvider(new tests::DefaulttestProvider()); runtime1->registerProvider<tests::testProvider>(domainName, testProvider); //This wait is necessary, because registerProvider is async, and a lookup could occur // before the register has finished. std::this_thread::sleep_for(std::chrono::milliseconds(registerProviderWait)); (*testProvider.*setAttribute)(expectedValue, [](){}, [](const joynr::exceptions::ProviderRuntimeException&) {}); ProxyBuilder<tests::testProxy>* testProxyBuilder = runtime2->createProxyBuilder<tests::testProxy>(domainName); DiscoveryQos discoveryQos; discoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); discoveryQos.setDiscoveryTimeout(1000); discoveryQos.setRetryInterval(250); std::int64_t qosRoundTripTTL = 500; // Send a message and expect to get a result tests::testProxy* testProxy = testProxyBuilder ->setMessagingQos(MessagingQos(qosRoundTripTTL)) ->setCached(false) ->setDiscoveryQos(discoveryQos) ->build(); std::int64_t minInterval_ms = 50; OnChangeSubscriptionQos subscriptionQos( 500000, // validity_ms minInterval_ms); // minInterval_ms subscribeTo(testProxy, subscriptionListener, subscriptionQos); waitForAttributeSubscriptionArrivedAtProvider(testProvider, attributeName); // Wait for a subscription message to arrive ASSERT_TRUE(semaphore.waitFor(std::chrono::seconds(3))); delete testProxyBuilder; delete testProxy; }
/* **************************************************************************** * * utInit - unit test init * */ void utInit(void) { #ifdef UT_DEBUG ++noOfInits; printf("**************** IN utInit (%d inits, %d exits)\n", noOfInits, noOfExits); #endif notifierMock = new NotifierMock(); if (notifierMock == NULL) { fprintf(stderr, "error allocating NotifierMock: %s\n", strerror(errno)); exit(1); } setNotifier(notifierMock); timerMock = new TimerMock(); if (timerMock == NULL) { fprintf(stderr, "error allocating TimerMock: %s\n", strerror(errno)); exit(1); } ON_CALL(*timerMock, getCurrentTime()).WillByDefault(Return(1360232700)); setTimer(timerMock); startTime = getCurrentTime(); statisticsTime = getCurrentTime(); setupDatabase(); #ifdef UT_DEBUG printf("**************** FROM utInit (%d inits, %d exits)\n", noOfInits, noOfExits); #endif // // URI parameters used for unit testing // Default mime type for notifications: application/xml // uriParams[URI_PARAM_NOTIFY_FORMAT] = "XML"; uriParams[URI_PARAM_PAGINATION_OFFSET] = DEFAULT_PAGINATION_OFFSET; uriParams[URI_PARAM_PAGINATION_LIMIT] = DEFAULT_PAGINATION_LIMIT; uriParams[URI_PARAM_PAGINATION_DETAILS] = DEFAULT_PAGINATION_DETAILS; uriParams[URI_PARAM_NOT_EXIST] = ""; // FIXME P7: we need this to implement "restriction-based" filters // // Resetting servicePathVector // servicePathVector.clear(); // Init subs cache (this initialization is overriden in test that use csubs) mongoSubCacheInit(); }
void testGutterLines_getTheOnlyLine_getsTheLine() { auto expected = new NiceMock<LineMock>(); NiceMock<FakeFactory> factory; ON_CALL(factory, createLeftGutterLine()).WillByDefault(Return(expected)); RZQtIDELeftGutterWidgetLines lines(factory); lines.append(); auto actual = lines.getLine(1); QCOMPARE(actual, expected); }
TEST_F(CreateFigureFixture, shouldCreateFigure4WhenCreate) { // Given ON_CALL(niceRandom, generate()).WillByDefault(Return(3)); CCreateFigure createFigure(&niceRandom, size); // When CFigurePtr spFigure = createFigure.create(); // Then ASSERT_EQ(4, spFigure->elem.size()); EXPECT_EQ(QPoint(size/2 - 1, 0), spFigure->elem[0].pos()); EXPECT_EQ(QPoint(size/2, 0), spFigure->elem[1].pos()); EXPECT_EQ(QPoint(size/2, 1), spFigure->elem[2].pos()); EXPECT_EQ(QPoint(size/2, 2), spFigure->elem[3].pos()); }
TEST_F(FigureMoveFixture, shouldNotMoveLeftFigureWhenMoveLeft) { // Given ON_CALL(niceTetris, testPos(_)).WillByDefault(Return(false)); CFigureMove figureMove(&niceTetris); // When bool ret = figureMove.left(spFigure.data()); // Then ASSERT_FALSE(ret); ASSERT_EQ(elem0.pos(), spFigure->elem[0].pos()); ASSERT_EQ(elem1.pos(), spFigure->elem[1].pos()); ASSERT_EQ(elem2.pos(), spFigure->elem[2].pos()); ASSERT_EQ(elem3.pos(), spFigure->elem[3].pos()); }
TEST_F(FigureMoveFixture, shouldMoveLeftFigureWhenMoveLeft) { // Given ON_CALL(niceTetris, testPos(_)).WillByDefault(Return(true)); CFigureMove figureMove(&niceTetris); // When bool ret = figureMove.left(spFigure.data()); // Then ASSERT_TRUE(ret); ASSERT_EQ(left(elem0), spFigure->elem[0].pos()); ASSERT_EQ(left(elem1), spFigure->elem[1].pos()); ASSERT_EQ(left(elem2), spFigure->elem[2].pos()); ASSERT_EQ(left(elem3), spFigure->elem[3].pos()); }
TEST_F(InterpreterWithChatbotTest, test_fallback_reply_on_edges) { UserDefinedCommandMock *userDefinedCommandMock = new NiceMock<UserDefinedCommandMock>(); Chatbot::UserDefinedActionHandler::SharedPtr userDefinedActionHandler(userDefinedCommandMock); SingleSessionChatbot chatbot(m_chatbotModel, userDefinedActionHandler); ON_CALL(*userDefinedCommandMock, execute(_, _, _)).WillByDefault(Invoke(pushVariables)); std::vector<std::string> reply1 = chatbot.treatMessage("Je veux un Coca et deux Hein"); std::vector<std::string> reply2 = chatbot.treatMessage("Bob!"); std::vector<std::string> reply3 = chatbot.treatMessage("Blabla"); EXPECT_THAT(reply1, ElementsAre("Je n'ai pas compris votre demande")); EXPECT_THAT(reply2, ElementsAre("Que puis-je vous offrir ?")); EXPECT_THAT(reply3, ElementsAre("Soyez le plus précis possible")); }
TEST_F(InterpreterWithChatbotTest, test_full_scenario) { UserDefinedCommandMock *userDefinedCommandMock = new NiceMock<UserDefinedCommandMock>(); Chatbot::UserDefinedActionHandler::SharedPtr userDefinedActionHandler(userDefinedCommandMock); SingleSessionChatbot chatbot(m_chatbotModel, userDefinedActionHandler); ON_CALL(*userDefinedCommandMock, execute(_, _, _)).WillByDefault(Invoke(pushVariables)); std::vector<std::string> reply1 = chatbot.treatMessage("Bob!"); std::vector<std::string> reply2 = chatbot.treatMessage("Je veux un Coca et deux Hein"); std::vector<std::string> reply3 = chatbot.treatMessage("Rien"); EXPECT_THAT(reply1, ElementsAre("Que puis-je vous offrir ?")); EXPECT_THAT(reply2, ElementsAre("Vous-voulez quelque chose d'autre ?")); EXPECT_THAT(reply3, ElementsAre("Veuillez récupérer vos consommations au bar. Vous devrez payer 10.5€.")); }
MockTimer::MockTimer() { ON_CALL(*this, start(_)).WillByDefault(Assign(&m_isStarted, true)); }
// Actual allocation is done by an instance of real allocator, // which is specified by the template parameter. TestAllocator() : real(createAllocator<T>()) { // We use 'ON_CALL' and 'WillByDefault' here to specify the // default actions (call in to the real allocator). This allows // the tests to leverage the 'DoDefault' action. // However, 'ON_CALL' results in a "Uninteresting mock function // call" warning unless each test puts expectations in place. // As a result, we also use 'EXPECT_CALL' and 'WillRepeatedly' // to get the best of both worlds: the ability to use 'DoDefault' // and no warnings when expectations are not explicit. ON_CALL(*this, initialize(_, _, _)) .WillByDefault(InvokeInitialize(this)); EXPECT_CALL(*this, initialize(_, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, recover(_, _)) .WillByDefault(InvokeRecover(this)); EXPECT_CALL(*this, recover(_, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, addFramework(_, _, _, _, _)) .WillByDefault(InvokeAddFramework(this)); EXPECT_CALL(*this, addFramework(_, _, _, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, removeFramework(_)) .WillByDefault(InvokeRemoveFramework(this)); EXPECT_CALL(*this, removeFramework(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, activateFramework(_)) .WillByDefault(InvokeActivateFramework(this)); EXPECT_CALL(*this, activateFramework(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, deactivateFramework(_)) .WillByDefault(InvokeDeactivateFramework(this)); EXPECT_CALL(*this, deactivateFramework(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateFramework(_, _, _)) .WillByDefault(InvokeUpdateFramework(this)); EXPECT_CALL(*this, updateFramework(_, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, addSlave(_, _, _, _, _, _)) .WillByDefault(InvokeAddSlave(this)); EXPECT_CALL(*this, addSlave(_, _, _, _, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, removeSlave(_)) .WillByDefault(InvokeRemoveSlave(this)); EXPECT_CALL(*this, removeSlave(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateSlave(_, _, _, _)) .WillByDefault(InvokeUpdateSlave(this)); EXPECT_CALL(*this, updateSlave(_, _, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, addResourceProvider(_, _, _)) .WillByDefault(InvokeAddResourceProvider(this)); EXPECT_CALL(*this, addResourceProvider(_, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, activateSlave(_)) .WillByDefault(InvokeActivateSlave(this)); EXPECT_CALL(*this, activateSlave(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, deactivateSlave(_)) .WillByDefault(InvokeDeactivateSlave(this)); EXPECT_CALL(*this, deactivateSlave(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateWhitelist(_)) .WillByDefault(InvokeUpdateWhitelist(this)); EXPECT_CALL(*this, updateWhitelist(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, requestResources(_, _)) .WillByDefault(InvokeRequestResources(this)); EXPECT_CALL(*this, requestResources(_, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateAllocation(_, _, _, _)) .WillByDefault(InvokeUpdateAllocation(this)); EXPECT_CALL(*this, updateAllocation(_, _, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateAvailable(_, _)) .WillByDefault(InvokeUpdateAvailable(this)); EXPECT_CALL(*this, updateAvailable(_, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateUnavailability(_, _)) .WillByDefault(InvokeUpdateUnavailability(this)); EXPECT_CALL(*this, updateUnavailability(_, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateInverseOffer(_, _, _, _, _)) .WillByDefault(InvokeUpdateInverseOffer(this)); EXPECT_CALL(*this, updateInverseOffer(_, _, _, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, getInverseOfferStatuses()) .WillByDefault(InvokeGetInverseOfferStatuses(this)); EXPECT_CALL(*this, getInverseOfferStatuses()) .WillRepeatedly(DoDefault()); ON_CALL(*this, recoverResources(_, _, _, _)) .WillByDefault(InvokeRecoverResources(this)); EXPECT_CALL(*this, recoverResources(_, _, _, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, suppressOffers(_, _)) .WillByDefault(InvokeSuppressOffers(this)); EXPECT_CALL(*this, suppressOffers(_, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, reviveOffers(_, _)) .WillByDefault(InvokeReviveOffers(this)); EXPECT_CALL(*this, reviveOffers(_, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, setQuota(_, _)) .WillByDefault(InvokeSetQuota(this)); EXPECT_CALL(*this, setQuota(_, _)) .WillRepeatedly(DoDefault()); ON_CALL(*this, removeQuota(_)) .WillByDefault(InvokeRemoveQuota(this)); EXPECT_CALL(*this, removeQuota(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, updateWeights(_)) .WillByDefault(InvokeUpdateWeights(this)); EXPECT_CALL(*this, updateWeights(_)) .WillRepeatedly(DoDefault()); ON_CALL(*this, pause()) .WillByDefault(InvokePause(this)); EXPECT_CALL(*this, pause()) .WillRepeatedly(DoDefault()); ON_CALL(*this, resume()) .WillByDefault(InvokeResume(this)); EXPECT_CALL(*this, resume()) .WillRepeatedly(DoDefault()); }
void MockYubikoOtpKeyView::setupDefaultOnCallHandlers() { BOOST_LOG_NAMED_SCOPE("MockYubikoOtpKeyView::setupDefaultOnCallHandlers"); ON_CALL(*this,getEdtPrivateId()).WillByDefault( ReturnRef(itsMockEdtPrivateId)); ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtPrivateId()).WillByDefault( ReturnRef(itsMockEdtPrivateId)); ON_CALL(*this,getEdtSecretKey()).WillByDefault( ReturnRef(itsMockEdtSecretKey)); ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtSecretKey()).WillByDefault( ReturnRef(itsMockEdtSecretKey)); ON_CALL(*this,getEdtPublicId()).WillByDefault( ReturnRef(itsMockEdtPublicId)); ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtPublicId()).WillByDefault( ReturnRef(itsMockEdtPublicId)); ON_CALL(*this,getEdtDescription()).WillByDefault( ReturnRef(itsMockEdtDescription)); ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtDescription()).WillByDefault( ReturnRef(itsMockEdtDescription)); ON_CALL(*this,getSbxPublicIdLen()).WillByDefault( ReturnRef(itsMockSbxPublicIdLen)); ON_CALL((const MockYubikoOtpKeyView&)(*this),getSbxPublicIdLen()).WillByDefault( ReturnRef(itsMockSbxPublicIdLen)); ON_CALL(*this,getBtnSave()).WillByDefault(ReturnRef(itsMockBtnSave)); ON_CALL(*this,getEdtSysUser()).WillByDefault( ReturnRef(itsMockEdtSysUser)); ON_CALL((const MockYubikoOtpKeyView&)(*this),getEdtSysUser()).WillByDefault( ReturnRef(itsMockEdtSysUser)); ON_CALL(*this,getBtnSelectSysUser()).WillByDefault( ReturnRef(itsMockBtnSelectSysUser)); ON_CALL(*this,getBtnGenPrivateId()).WillByDefault( ReturnRef(itsMockBtnGenPrivateId)); ON_CALL(*this,getBtnGenPublicId()).WillByDefault( ReturnRef(itsMockBtnGenPublicId)); ON_CALL(*this,getBtnGenSecretKey()).WillByDefault( ReturnRef(itsMockBtnGenSecretKey)); }