当前位置: 首页>>代码示例>>C++>>正文


C++ Mock::get方法代码示例

本文整理汇总了C++中Mock::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Mock::get方法的具体用法?C++ Mock::get怎么用?C++ Mock::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main ()
{
    using namespace fakeit;
    const mqmx::queue_id_type defQID = 10;
    const mqmx::message_id_type defMID = 10;

    Mock<mqmx::message_queue::listener> mock;
    Fake (Method (mock, notify));
    {
	mqmx::message_queue queue (defQID);
	mqmx::message::upointer_type msg;

	mqmx::status_code retCode = queue.set_listener (mock.get ());
	assert (mqmx::ExitStatus::Success == retCode);

	/* test for double insert */
	retCode = queue.set_listener (mock.get ());
	assert (mqmx::ExitStatus::AlreadyExist == retCode);

	retCode = queue.enqueue<mqmx::message> (defMID);
	assert (mqmx::ExitStatus::Success == retCode);

	Verify (Method (mock, notify).Using (
		    defQID, &queue, mqmx::message_queue::notification_flag::data))
	    .Once ();
    }
    Verify (Method (mock, notify).Using (
		defQID, nullptr, mqmx::message_queue::notification_flag::closed))
	.Once ();
    VerifyNoOtherInvocations (mock);
    return 0;
}
开发者ID:o-peregudov,项目名称:mqmx,代码行数:32,代码来源:message_queue_listener_data_and_closed.cpp

示例2: main

int main ()
{
    using namespace fakeit;
    const mqmx::queue_id_type defQIDa = 10;
    const mqmx::queue_id_type defQIDb = 20;
    const mqmx::message_id_type defMIDa = 10;
    const mqmx::message_id_type defMIDb = 20;

    Mock<mqmx::message_queue::listener> mock;
    Fake (Method (mock, notify));

    mqmx::message_queue aqueue (defQIDa);
    mqmx::message_queue bqueue (defQIDb);

    mqmx::message::upointer_type msg;
    mqmx::status_code retCode = mqmx::ExitStatus::Success;

    retCode = aqueue.set_listener (mock.get ());
    assert (mqmx::ExitStatus::Success == retCode);

    retCode = bqueue.set_listener (mock.get ());
    assert (mqmx::ExitStatus::Success == retCode);

    retCode = aqueue.enqueue<mqmx::message> (defMIDa);
    retCode = bqueue.enqueue<mqmx::message> (defMIDb);

    Verify (Method (mock, notify).Using (
                defQIDa, &aqueue, mqmx::message_queue::notification_flag::data))
        .Once ();
    Verify (Method (mock, notify).Using (
                defQIDb, &bqueue, mqmx::message_queue::notification_flag::data))
        .Once ();
    bqueue = std::move (aqueue);

    Verify (Method (mock, notify).Using (
                defQIDa, &aqueue, mqmx::message_queue::notification_flag::detached))
        .Once ();
    Verify (Method (mock, notify).Using (
                defQIDb, &bqueue, mqmx::message_queue::notification_flag::detached))
        .Once ();

    msg = aqueue.pop (); /* message should be moved to the new queue */
    assert (nullptr == msg.get ());

    msg = bqueue.pop (); /* message should be moved from the original queue */
    assert (nullptr != msg.get ());
    assert (defQIDa == msg->get_qid ());
    assert (defMIDa == msg->get_mid ());

    VerifyNoOtherInvocations (mock);
    return 0;
}
开发者ID:o-peregudov,项目名称:mqmx,代码行数:52,代码来源:message_queue_listener_detached_because_of_move_assignment.cpp

示例3: TestConstParameters

		void TestConstParameters()
		{
			Mock<ConstVolatileParameters> mock;
			Fake(Method(mock,func1));
			ConstVolatileParameters& i = mock.get();
			ASSERT_EQUAL(0, i.func1(1,std::string()));
		}
开发者ID:AbdelghaniDr,项目名称:FakeIt,代码行数:7,代码来源:remove_const_volatile_tests.cpp

示例4: dynamic_cast_to_same_type__with_concrete_type

	void dynamic_cast_to_same_type__with_concrete_type()
	{
		Mock<ConcreteType> mockDemo;
		ConcreteType* mockDemoPtr = &mockDemo.get();
		ConcreteType* mockDemoPtr2 = dynamic_cast<ConcreteType*>(mockDemoPtr);
		ASSERT_EQUAL(mockDemoPtr, mockDemoPtr2);
	}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:7,代码来源:type_info_tests.cpp

示例5: dynamic_cast_to_same_type__with_abstract_type

	void dynamic_cast_to_same_type__with_abstract_type()
	{
		Mock<TopLeft> mock;
		TopLeft* ptr = &mock.get();
		TopLeft* ptr2 = dynamic_cast<TopLeft*>(ptr);
		ASSERT_EQUAL(ptr, ptr2);
	}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:7,代码来源:type_info_tests.cpp

示例6: foo

    void foo()
    {
        Mock<Derived> mock;

        When(Method(mock, methodA)).AlwaysReturn();

        Derived& derived = mock.get();

        struct DoNotDelete { void operator()(Derived* p) const { } };
        std::shared_ptr<Derived> derivedSPtr = std::shared_ptr<Derived>(&derived, DoNotDelete());

        //This version works #1
        //shared_ptr<Derived> derivedSPtr(new Derived());

        std::set<std::shared_ptr<Base>> set;

        set.insert(derivedSPtr);

        for (auto item : set)
        {
            std::shared_ptr<Base> b1 = item;
            b1->methodA();

            std::shared_ptr<Derived> d1 = std::dynamic_pointer_cast<Derived>(b1);
            //Next line fails.
            //d1 is always null for the mocked version. If a real Derived object is used like the line commented out above #1 it works fine.

            d1->methodA();
        }

    }
开发者ID:hartness,项目名称:FakeIt,代码行数:31,代码来源:miscellaneous_tests.cpp

示例7: can_stub_method_after_reset

 void can_stub_method_after_reset() {
   Mock<foo_bar> mock;
   mock.Reset();
   When(Method(mock, bar)).Return(42);
   ASSERT_EQUAL(mock.get().bar(), 42);
   Verify(Method(mock, bar)).Once();
 }
开发者ID:hartness,项目名称:FakeIt,代码行数:7,代码来源:miscellaneous_tests.cpp

示例8: pass_mock_by_ref

 void pass_mock_by_ref()
 {
     Mock<Change> mock;
     Change* change = &mock.get();
     When(Method(mock, change)).AlwaysReturn();
     change->change(1, 2, 3);
     assertChanged(mock, 1, 2, 3);
 }
开发者ID:hartness,项目名称:FakeIt,代码行数:8,代码来源:miscellaneous_tests.cpp

示例9: production_shared_ptr_mock_used_in_invocation

	void production_shared_ptr_mock_used_in_invocation() {
		Mock<ISomeInterface3> mock;
		std::shared_ptr<ISomeInterface3> pMockInstance(&mock.get());
		fakeit::Fake(Dtor(mock));
		fakeit::Fake(Method(mock, methodWithSomeSharedPointer));
		pMockInstance->methodWithSomeSharedPointer(pMockInstance);
		pMockInstance = nullptr;
	}
开发者ID:eranpeer,项目名称:FakeIt,代码行数:8,代码来源:default_behaviore_tests.cpp

示例10: ReturnByReference_ReturnReferenceToDefaultConstructedObject

	void ReturnByReference_ReturnReferenceToDefaultConstructedObject() {
		Mock<ReferenceFunctions> mock;
		Fake(Method(mock,scalarFunc));
		Fake(Method(mock,stringFunc));
		ReferenceFunctions& i = mock.get();
		ASSERT_EQUAL(0, i.scalarFunc());
		ASSERT_EQUAL(std::string(), i.stringFunc());
	}
开发者ID:CoderGeoff,项目名称:BankingKataCplusplus,代码行数:8,代码来源:default_behaviore_tests.cpp

示例11: GroupTestFixture

    GroupTestFixture()
    {

        Mock<NodeBase> mockNode;

        NodeBase& node1 = mockNode.get();
        NodeBase& node2 = mockNode.get();
        NodeBase& node3 = mockNode.get();
        NodeBase& node4 = mockNode.get();

        nodeGroupOne.AddMember(1, &node1);
        nodeGroupOne.AddMember(2, &node2);
        nodeGroupOne.AddMember(3, &node3);

        nodeGroupTwo.AddMember(3, &node3);
        nodeGroupTwo.AddMember(4, &node4);
    }
开发者ID:nutofem,项目名称:nuto,代码行数:17,代码来源:Group.cpp

示例12: DefaultBeaviorOfVoidFunctionsIsToDoNothing

	void DefaultBeaviorOfVoidFunctionsIsToDoNothing() {
		Mock<VoidFunctions> mock;
		Fake(Method(mock,proc1));
		Fake(Method(mock,proc2));
		VoidFunctions& i = mock.get();
		i.proc1();
		i.proc2(1);
	}
开发者ID:CoderGeoff,项目名称:BankingKataCplusplus,代码行数:8,代码来源:default_behaviore_tests.cpp

示例13: args

TEST_F(LuaExpressionTests,WriteToEmailTagFromLuaExpression)
{
	string fromAddr = "fromAddr";
	string strreceivers = "receiver1;receiver2";
	string subject = "subject";
	string body = "test body";

	Mock<IWriteToDevice> deviceWriterMock;
	ValueChangedEventArgs args(NULL);
	When(Method(deviceWriterMock,WriteToDevice).Using(Any<ValueChangedEventArgs>())).AlwaysReturn();

	Mock<IEmailSender> emailSenderMock;
	When(Method(emailSenderMock,Send)).AlwaysReturn();
	IEmailSender* emailSender = &emailSenderMock.get();

	Mock<IDirectory> directoryMock;
	When(Method(directoryMock,Exists)).AlwaysReturn(true);

	Mock<IFile> fileMock;
	When(Method(fileMock,Delete)).AlwaysReturn();
	When(Method(fileMock,getexepath)).AlwaysReturn("exepath");

	string luascript = StringBuilder::Format("email = '%s'",body.c_str());
	When(Method(fileMock,ReadWholeFile)).AlwaysReturn(luascript);
	When(Method(fileMock,Exists).Using("exepath/Expressions/expressionName.lua")).Return(false,true);

	Mock<IExpressionRuntime> expressionRuntimeMock;
	When(Method(expressionRuntimeMock,Add)).AlwaysReturn();

	Mock<IHisDevFactory> factoryMock;
	When(Method(factoryMock,GetFile)).AlwaysReturn(&fileMock.get());
	When(Method(factoryMock,GetDirectory)).AlwaysReturn(&directoryMock.get());
	When(Method(factoryMock,GetEmailSender)).AlwaysReturn(emailSender);
	IHisDevFactory* factory = &factoryMock.get();

	Mock<IModbusProvider> modbusProviderMock;
	IModbusProvider* modbusProvider = &modbusProviderMock.get();
	HisDevVirtual* virtualDev = new HisDevVirtual(factory);
	HisDevices devices("fileName",modbusProvider);
	devices.Add(virtualDev);
	HisDevValueEmail* emailValue = new HisDevValueEmail(&deviceWriterMock.get(), factory);
	emailValue->SetFromAddr(fromAddr);
	emailValue->SetReceivers(strreceivers);
	emailValue->SetAddressName("email");
	emailValue->SetName(subject);
	virtualDev->Add(emailValue);
	HisDevFolder folder("folderName",factory);
	HisDevValueId* valueId = new HisDevValueId(emailValue,factory);
	folder.Add(valueId);
	LuaExpression expression(&folder,&devices,"expressionName",&expressionRuntimeMock.get(),factory);
	expression.SetExpression("");
	expression.SetRunning(true);
	expression.Evaluate();
	Verify(Method(emailSenderMock,Send).Using(fromAddr,strreceivers,subject,body));
}
开发者ID:jlola,项目名称:homeis,代码行数:55,代码来源:LuaExpressionTests.cpp

示例14: check_no_more_invocations_exception

	void check_no_more_invocations_exception() {
		Mock<SomeInterface> mock;
		try {
			Fake(Method(mock,foo));
			mock.get().foo(1);
			mock.get().foo(2);
			Verify(Method(mock,foo).Using(1));
			VerifyNoOtherInvocations(Method(mock,foo));
		} catch (NoMoreInvocationsVerificationException&) {
//			ASSERT_EQUAL(VerificationType::NoMoreInvocations, e.verificationType());
//			ASSERT_EQUAL(2, e.allIvocations().size());
//			ASSERT_EQUAL(1, e.unverifedIvocations().size());
		}
	}
开发者ID:AbdelghaniDr,项目名称:FakeIt,代码行数:14,代码来源:verification_errors_tests.cpp

示例15: format_UnmatchedMethodCallEvent

	void format_UnmatchedMethodCallEvent() {
		Mock<SomeInterface> mock;
		Fake(Method(mock,func).Using(3));
		SomeInterface &i = mock.get();
		try {
			i.func(1);
			FAIL();
		}
		catch (UnexpectedMethodCallException& e)
		{
			std::string expectedMsg{"Unexpected method invocation: mock.func(1)\n  Could not find Any recorded behavior to support this method call."};
			std::string actual{to_string(e)};
			ASSERT_EQUAL(expectedMsg, actual);
		}
	}
开发者ID:AbdelghaniDr,项目名称:FakeIt,代码行数:15,代码来源:default_event_formatting_tests.cpp


注:本文中的Mock::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。