// class6.h namespace namespace1 { class class6 { public: void method1(const char* p1, int p2); }; } // class6.cpp /* #include #include "class6.h" namespace namespace1 { void class6::method1(const char* p1, int p2) { if ((strcmp(p1, "hello") == 0) && (p2 == 42)) { // do something } } }*/ // class6_mock.cpp /* * This file has been auto-generated by CppUTestMock v0.4. * * Contents will NOT be preserved if it is regenerated!!! * * Generation options: -x */ //#include "class6.h" #include void namespace1::class6::method1(const char* p1, int p2) { mock().actualCall("namespace1::class6::method1").onObject(this).withStringParameter("p1", p1).withIntParameter("p2", p2); } // class6_expect.hpp /* * This file has been auto-generated by CppUTestMock v0.4. * * Contents will NOT be preserved if it is regenerated!!! * * Generation options: -x */ #include //#include "class6.h" #include namespace expect { namespace namespace1$ { namespace class6$ { MockExpectedCall& method1(CppUMockGen::Parameter __object__, CppUMockGen::Parameter p1, CppUMockGen::Parameter p2, bool __return__); MockExpectedCall& method1(unsigned int __numCalls__, CppUMockGen::Parameter __object__, CppUMockGen::Parameter p1, CppUMockGen::Parameter p2, bool __return__); } } } // class6_expect.cpp /* * This file has been auto-generated by CppUTestMock v0.4. * * Contents will NOT be preserved if it is regenerated!!! * * Generation options: -x */ //#include "class6_expect.hpp" namespace expect { namespace namespace1$ { namespace class6$ { MockExpectedCall& method1(CppUMockGen::Parameter __object__, CppUMockGen::Parameter p1, CppUMockGen::Parameter p2) { bool __ignoreOtherParams__ = false; MockExpectedCall& __expectedCall__ = mock().expectOneCall("namespace1::class6::method1"); if (!__object__.isIgnored()) { __expectedCall__.onObject(const_cast(__object__.getValue())); } if (p1.isIgnored()) { __ignoreOtherParams__ = true; } else { __expectedCall__.withStringParameter("p1", p1.getValue()); } if (p2.isIgnored()) { __ignoreOtherParams__ = true; } else { __expectedCall__.withIntParameter("p2", p2.getValue()); } if (__ignoreOtherParams__) { __expectedCall__.ignoreOtherParameters(); } return __expectedCall__; } MockExpectedCall& method1(unsigned int __numCalls__, CppUMockGen::Parameter __object__, CppUMockGen::Parameter p1, CppUMockGen::Parameter p2) { bool __ignoreOtherParams__ = false; MockExpectedCall& __expectedCall__ = mock().expectNCalls(__numCalls__, "namespace1::class6::method1"); if (!__object__.isIgnored()) { __expectedCall__.onObject(const_cast(__object__.getValue())); } if (p1.isIgnored()) { __ignoreOtherParams__ = true; } else { __expectedCall__.withStringParameter("p1", p1.getValue()); } if (p2.isIgnored()) { __ignoreOtherParams__ = true; } else { __expectedCall__.withIntParameter("p2", p2.getValue()); } if (__ignoreOtherParams__) { __expectedCall__.ignoreOtherParameters(); } return __expectedCall__; } } } } void unit_under_test(const char* p1, int p2) { namespace1::class6 class6_object_instance; class6_object_instance.method1(p1, p2); } TEST_GROUP(class6) { void setup() {} void teardown() { mock().clear(); } }; TEST(class6, method1_check_object) { namespace1::class6 class6_mock; expect::namespace1$::class6$::method1(&class6_mock, "hello", 42); class6_mock.method1("hello", 42); mock().checkExpectations(); } TEST(class6, method1_ignore_object) { // The unit under test controls the lifecycle of the mock object so ignore the object parameter! expect::namespace1$::class6$::method1(CppUMockGen::IgnoreParameter::YES, "hello", 42); unit_under_test("hello", 42); // <-- EXCEPTION here! mock().checkExpectations(); } /* Failure in TEST(class6, method1_ignore_object) MockFailure: Function called on an unexpected object: namespace1::class6::method1 Actual object for call has address: <007FE96B> EXPECTED calls that DID NOT happen related to function: namespace1::class6::method1 namespace1::class6::method1 -> const char* p1: , int p2: <42> ACTUAL calls that DID happen related to function: namespace1::class6::method1 .. Errors (1 failures, 2 tests, 2 ran, 2 checks, 0 ignored, 0 filtered out, 24 ms) */