本文整理汇总了C++中Mock类的典型用法代码示例。如果您正苦于以下问题:C++ Mock类的具体用法?C++ Mock怎么用?C++ Mock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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;
}
示例3: TEST
/**
* The called method accepts lambda arguments, and invokes these arguments to
* decide whether the call matches.
*/
TEST(MockValidator, validationBuilder_called_ignore_lambda)
{
const int INT_VALUE = 17;
const bool BOOL_VALUE = true;
struct DummyType { };
Mock<DummyType> dummyMock;
MockValidator<void, int, bool> dummyFunc;
//no invocations have occurred
ASSERT_EQ(0, dummyMock.invocations().size());
//the validator DOES NOT match this invocation
ASSERT_FALSE(
dummyFunc.validationBuilder(dummyMock).called(INT_VALUE, BOOL_VALUE));
//add an invocation
dummyFunc.addInvocation(dummyMock, INT_VALUE, BOOL_VALUE);
//there is now an invocation in the mock
ASSERT_EQ(1, dummyMock.invocations().size());
//the validator matches these arguments
ASSERT_TRUE(
dummyFunc.validationBuilder(dummyMock).called([](int x) -> bool { return x > 5; }, Ignore()));
}
示例4: TestConstParameters
void TestConstParameters()
{
Mock<ConstVolatileParameters> mock;
Fake(Method(mock,func1));
ConstVolatileParameters& i = mock.get();
ASSERT_EQUAL(0, i.func1(1,std::string()));
}
示例5: 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);
}
示例6: 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);
}
示例7: 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();
}
}
示例8: main
int
main(int argc, char** argv)
{
Test test("DUNE::Utils::StateMachine");
Mock o;
struct
{
const char* string;
int count;
} testcases[] =
{
{"LST_STLS_STSLLLLLL", 0},
{"STS_STLS_LSTS_LSTL", 1},
{"LSTS_STLS_LSTS_LST", 2},
{"SLSTSSLLSTSLSTSLLL", 3}
};
for (unsigned i = 0; i < sizeof(testcases) / sizeof(testcases[0]); i++)
{
test.boolean(testcases[i].string, o.count(testcases[i].string) == testcases[i].count);
}
return 0;
}
示例9: 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);
}
示例10: DefaultBeaviorOfVoidFunctionsIsToDoNothing
void DefaultBeaviorOfVoidFunctionsIsToDoNothing() {
Mock<VoidFunctions> mock;
Fake(Method(mock,proc1));
Fake(Method(mock,proc2));
VoidFunctions& i = mock.get();
i.proc1();
i.proc2(1);
}
示例11: 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;
}
示例12: 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());
}
示例13: TEST
TEST(ThreadTest, Run)
{
Mock mock;
ASSERT_EQ(0, mock.timesCalled);
mock.Start();
mock.mutex.Lock();
ASSERT_EQ(0, mock.timesCalled);
mock.mutex.Unlock();
mock.Join();
ASSERT_EQ(1, mock.timesCalled);
}
示例14: 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
示例15: 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());
}
}