TEST(MockCallTest, expectOneCallInScopeButActualCallInGlobal)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest emptyExpectations;
    MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", emptyExpectations);

    mock("scope").expectOneCall("foo");
    mock().actualCall("foo");

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
    mock().clear();
}
Ejemplo n.º 2
0
TEST(MockCallTest, checkExpectationsClearsTheExpectations)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foobar");
    MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);

    mock().expectOneCall("foobar");
    mock().checkExpectations();

    CHECK(! mock().expectedCallsLeft());
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 3
0
TEST(MockCallTest, ignoreOtherStillFailsIfExpectedOneDidntHappen)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo");
    MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);

    mock().expectOneCall("foo");
    mock().ignoreOtherCalls();
    mock().checkExpectations();

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 4
0
TEST(MockParameterTest, newCallStartsWhileNotAllParametersWerePassed)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withParameter("p1", 1);
    MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);

    mock().expectOneCall("foo").withParameter("p1", 1);
    mock().actualCall("foo");
    mock().actualCall("foo").withParameter("p1", 1);;

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 5
0
TEST(MockParameterTest, noActualCallForOutputParameter)
{
    MockFailureReporterInstaller failureReporterInstaller;

    int output;
    MockExpectedCallsListForTest expectations;
    mock().expectOneCall("foo").withOutputParameterReturning("output", &output, sizeof(output));

    expectations.addFunction("foo")->withOutputParameterReturning("output", &output, sizeof(output));
    MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);

    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 6
0
TEST(MockParameterTest, ignoreOtherParametersButExpectedParameterDidntHappen)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withParameter("p1", 1).ignoreOtherParameters();
    MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);

    mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters();
    mock().actualCall("foo").withParameter("p2", 2).withParameter("p3", 3).withParameter("p4", 4);

    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 7
0
TEST(MockHierarchyTest, checkExpectationsWorksHierarchicallyForLastCallNotFinished)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foobar")->withParameter("boo", 1);
    MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foobar", expectations);

    mock("first").expectOneCall("foobar").withParameter("boo", 1);
    mock("first").actualCall("foobar");

    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 8
0
TEST(MockParameterTest, calledWithoutParameters)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withParameter("p1", 1);
    MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);

    mock().expectOneCall("foo").withParameter("p1", 1);
    mock().actualCall("foo");

    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 9
0
TEST(MockCallTest, OnObjectFails)
{
    MockFailureReporterInstaller failureReporterInstaller;

    void* objectPtr = (void*) 0x001;
    void* objectPtr2 = (void*) 0x002;
    MockExpectedCallsListForTest expectations;
    expectations.addFunction("boo")->onObject(objectPtr);

    mock().expectOneCall("boo").onObject(objectPtr);
    mock().actualCall("boo").onObject(objectPtr2);

    MockUnexpectedObjectFailure expectedFailure(mockFailureTest(), "boo", objectPtr2, expectations);
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 10
0
TEST(MockHierarchyTest, checkExpectationsWorksHierarchically)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foobar");
    expectations.addFunction("helloworld");
    MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);

    mock("first").expectOneCall("foobar");
    mock("second").expectOneCall("helloworld");

    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 11
0
TEST(MockCallTest, expectOneCallInScopeButNotHappen)
{

    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("scope::foobar");
    MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);

    mock("scope").expectOneCall("foobar");
    mock().checkExpectations();

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);

}
Ejemplo n.º 12
0
TEST(MockParameterTest, expectOneIntegerParameterAndFailsDueToTypes)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withParameter("parameter", 10);
    MockNamedValue parameter("parameter");
    parameter.setValue("heh");
    MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);

    mock().expectOneCall("foo").withParameter("parameter", 10);
    mock().actualCall("foo").withParameter("parameter", "heh");

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 13
0
TEST(MockCallTest, expectNoCallDoesntInfluenceExpectOneCall)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("influence", MockCheckedExpectedCall::NO_EXPECTED_CALL_ORDER)->callWasMade(1);
    MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations);

    mock().expectNoCall("lazy");
    mock().expectOneCall("influence");
    mock().actualCall("influence");
    mock().actualCall("lazy");

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 14
0
TEST(MockParameterTest, unsignedLongAndLongWithSameBitRepresentationShouldnotBeTreatedAsEqual)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withParameter("parameter", (unsigned long)-1);
    MockNamedValue parameter("parameter");
    parameter.setValue((long)-1);
    MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);

    mock().expectOneCall("foo").withParameter("parameter", (unsigned long)-1);
    mock().actualCall("foo").withParameter("parameter", (long)-1);

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 15
0
TEST(MockComparatorCopierTest, removingCopiersWorksHierachically)
{
    MockFailureReporterInstaller failureReporterInstaller;
    MyTypeForTesting object(1);

    MyTypeForTestingCopier copier;

    mock("scope").installCopier("MyTypeForTesting", copier);
    mock().removeAllComparatorsAndCopiers();
    mock("scope").expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "bar", &object);
    mock("scope").actualCall("foo").withOutputParameterOfType("MyTypeForTesting", "bar", &object);

    MockNoWayToCopyCustomTypeFailure expectedFailure(mockFailureTest(), "MyTypeForTesting");
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 16
0
TEST(MockParameterTest, expectOneUnsignedIntegerParameterAndFailsDueToParameterName)
{
    MockFailureReporterInstaller failureReporterInstaller;

    unsigned int value = 7;
    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withParameter("parameter", value);
    MockNamedValue parameter("different");
    parameter.setValue(value);
    MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);

    mock().expectOneCall("foo").withParameter("parameter", value);
    mock().actualCall("foo").withParameter("different", value);

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 17
0
TEST(MockCallTest, ignoreOtherCallsDoesntIgnoreMultipleCallsOfTheSameFunction)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->callWasMade(1);
    MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", expectations);

    mock().expectOneCall("foo");
    mock().ignoreOtherCalls();
    mock().actualCall("bar");
    mock().actualCall("foo");
    mock().actualCall("foo");

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 18
0
TEST(MockCallTest, ignoreOtherCallsExceptForTheUnExpectedOne)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations);

    mock().expectNoCall("lazy");
    mock().ignoreOtherCalls();
    mock().actualCall("bar").withParameter("foo", 1);
    mock().actualCall("bar1").withParameter("foo", 1);
    mock().actualCall("bar2").withParameter("foo", 1);
    mock().actualCall("lazy");

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 19
0
TEST(MockParameterTest, unexpectedOutputParameter)
{
    MockFailureReporterInstaller failureReporterInstaller;

    int param;
    MockExpectedCallsListForTest expectations;
    mock().expectOneCall("foo");
    mock().actualCall("foo").withOutputParameter("parameterName", &param);

    expectations.addFunction("foo");
    MockNamedValue parameter("parameterName");
    parameter.setValue(&param);
    MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);

    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 20
0
TEST(MockCallTest, expectOneCallHoweverMultipleHappened)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->callWasMade(1);
    expectations.addFunction("foo")->callWasMade(2);
    MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", expectations);

    mock().expectOneCall("foo");
    mock().expectOneCall("foo");
    mock().actualCall("foo");
    mock().actualCall("foo");
    mock().actualCall("foo");

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 21
0
TEST(MockParameterTest, expectOneMemBufferParameterAndValueFailsDueToContents)
{
    MockFailureReporterInstaller failureReporterInstaller;

    unsigned char memBuffer1[] = { 0x12, 0x15, 0xFF };
    unsigned char memBuffer2[] = { 0x12, 0x05, 0xFF };
    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withParameter("parameter", memBuffer1, sizeof(memBuffer1));
    MockNamedValue parameter("parameter");
    parameter.setMemoryBuffer( memBuffer2, sizeof(memBuffer2) );
    MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);

    mock().expectOneCall("foo").withParameter("parameter", memBuffer1, sizeof(memBuffer1));
    mock().actualCall("foo").withParameter("parameter", memBuffer2, sizeof(memBuffer2));

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 22
0
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);
}
Ejemplo n.º 23
0
TEST(MockStrictOrderTest, orderViolatedWithinAScope)
{
    MockFailureReporterInstaller failureReporterInstaller;
    mock().strictOrder();

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo1", 1)->callWasMade(2);
    expectations.addFunction("foo2", 2)->callWasMade(1);
    MockCallOrderFailure expectedFailure(mockFailureTest(), expectations);

    mock("scope").expectOneCall("foo1");
    mock("scope").expectOneCall("foo2");
    mock("scope").actualCall("foo2");
    mock("scope").actualCall("foo1");

    mock("scope").checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 24
0
TEST(MockComparatorCopierTest, noActualCallForCustomTypeOutputParameter)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MyTypeForTesting expectedObject(1);
    MyTypeForTestingCopier copier;
    mock().installCopier("MyTypeForTesting", copier);

    MockExpectedCallsListForTest expectations;
    expectations.addFunction("foo")->withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
    MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);

    mock().expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
    mock().checkExpectations();

    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);

    mock().removeAllComparatorsAndCopiers();
}
Ejemplo n.º 25
0
TEST(MockCallTest, OnObjectExpectedButNotCalled)
{
    MockFailureReporterInstaller failureReporterInstaller;

    void* objectPtr = (void*) 0x001;
    MockExpectedCallsListForTest expectations;
    expectations.addFunction("boo")->onObject(objectPtr);
    expectations.addFunction("boo")->onObject(objectPtr);

    mock().expectOneCall("boo").onObject(objectPtr);
    mock().expectOneCall("boo").onObject(objectPtr);
    mock().actualCall("boo");
    mock().actualCall("boo");

    MockExpectedObjectDidntHappenFailure expectedFailure(mockFailureTest(), "boo", expectations);
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 26
0
TEST(MockParameterTest, ignoreOtherParametersMultipleCallsButOneDidntHappen)
{
    MockFailureReporterInstaller failureReporterInstaller;

    MockExpectedCallsListForTest expectations;
    MockCheckedExpectedCall* call = expectations.addFunction("boo");
    call->ignoreOtherParameters();
    call->callWasMade(1);
    call->parametersWereIgnored();
    call->ignoreOtherParameters();
    expectations.addFunction("boo")->ignoreOtherParameters();
    MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);

    mock().expectOneCall("boo").ignoreOtherParameters();
    mock().expectOneCall("boo").ignoreOtherParameters();
    mock().actualCall("boo");

    mock().checkExpectations();
    CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
Ejemplo n.º 27
0
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();
}