TEST(MockComparatorCopierTest, customTypeOutputParameterTraced) { MyTypeForTesting actualObject(676789); MyTypeForTestingCopier copier; mock().installCopier("MyTypeForTesting", copier); mock().tracing(true); mock().actualCall("someFunc").withOutputParameterOfType("MyTypeForTesting", "someParameter", &actualObject); mock().checkExpectations(); STRCMP_CONTAINS("Function name:someFunc MyTypeForTesting someParameter:", mock().getTraceOutput()); mock().removeAllComparatorsAndCopiers(); }
TEST(MockComparatorCopierTest, customObjectWithFunctionCopier) { MyTypeForTesting expectedObject(9874452); MyTypeForTesting actualObject(2034); MockFunctionCopier copier(myTypeCopy); mock().installCopier("MyTypeForTesting", copier); mock().expectOneCall("function").withOutputParameterOfTypeReturning("MyTypeForTesting", "parameterName", &expectedObject); mock().actualCall("function").withOutputParameterOfType("MyTypeForTesting", "parameterName", &actualObject); mock().checkExpectations(); CHECK_EQUAL(9874452, *(expectedObject.value)); CHECK_EQUAL(9874452, *(actualObject.value)); mock().removeAllComparatorsAndCopiers(); }
TEST(MockComparatorCopierTest, customTypeOutputParameterWithIgnoredParameters) { MyTypeForTesting expectedObject(444537909); MyTypeForTesting actualObject(98765); MyTypeForTestingCopier copier; mock().installCopier("MyTypeForTesting", copier); mock().expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "bar", &expectedObject).ignoreOtherParameters(); mock().actualCall("foo").withOutputParameterOfType("MyTypeForTesting", "bar", &actualObject).withParameter("other", 1); mock().checkExpectations(); CHECK_EQUAL(444537909, *(expectedObject.value)); CHECK_EQUAL(444537909, *(actualObject.value)); mock().removeAllComparatorsAndCopiers(); }
TEST(MockComparatorCopierTest, customTypeOutputParameterSucceeds) { MyTypeForTesting expectedObject(55); MyTypeForTesting actualObject(99); MyTypeForTestingCopier copier; mock().installCopier("MyTypeForTesting", copier); mock().expectOneCall("function").withOutputParameterOfTypeReturning("MyTypeForTesting", "parameterName", &expectedObject); mock().actualCall("function").withOutputParameterOfType("MyTypeForTesting", "parameterName", &actualObject); mock().checkExpectations(); CHECK_EQUAL(55, *(expectedObject.value)); CHECK_EQUAL(55, *(actualObject.value)); mock().removeAllComparatorsAndCopiers(); }
TEST(MockComparatorCopierTest, noCopierForCustomTypeOutputParameter) { MockFailureReporterInstaller failureReporterInstaller; MyTypeForTesting expectedObject(123464); MyTypeForTesting actualObject(8834); MockExpectedCallsListForTest expectations; expectations.addFunction("foo")->withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject); MockNoWayToCopyCustomTypeFailure expectedFailure(mockFailureTest(), "MyTypeForTesting"); mock().expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject); mock().actualCall("foo").withOutputParameterOfType("MyTypeForTesting", "output", &actualObject); mock().checkExpectations(); CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); }
TEST(MockComparatorCopierTest, unexpectedCustomTypeOutputParameter) { MockFailureReporterInstaller failureReporterInstaller; MyTypeForTesting actualObject(8834); MyTypeForTestingCopier copier; mock().installCopier("MyTypeForTesting", copier); MockExpectedCallsListForTest expectations; expectations.addFunction("foo"); MockNamedValue parameter("parameterName"); parameter.setConstObjectPointer("MyTypeForTesting", &actualObject); MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); mock().expectOneCall("foo"); mock().actualCall("foo").withOutputParameterOfType("MyTypeForTesting", "parameterName", &actualObject); mock().checkExpectations(); CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); mock().removeAllComparatorsAndCopiers(); }
TEST(MockComparatorCopierTest, customTypeOutputParameterOfWrongType) { MockFailureReporterInstaller failureReporterInstaller; MyTypeForTesting expectedObject(123464); MyTypeForTesting actualObject(75646); MyTypeForTestingCopier copier; mock().installCopier("MyTypeForTesting", copier); MockExpectedCallsListForTest expectations; expectations.addFunction("foo")->withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject); MockNamedValue parameter("output"); parameter.setObjectPointer("OtherTypeForTesting", &actualObject); MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); mock().expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject); mock().actualCall("foo").withOutputParameterOfType("OtherTypeForTesting", "output", &actualObject); mock().checkExpectations(); CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); mock().removeAllComparatorsAndCopiers(); }