diff --git a/CppUTest.dsp b/CppUTest.dsp
index f13f8216e..b20538dd0 100644
--- a/CppUTest.dsp
+++ b/CppUTest.dsp
@@ -106,6 +106,10 @@ SOURCE=.\src\CppUTestExt\MockActualCall.cpp"
# End Source File
# Begin Source File
+SOURCE=.\src\CppUTestExt\MockActualCallsQueue.cpp"
+# End Source File
+# Begin Source File
+
SOURCE=.\src\CppUTestExt\MockExpectedCall.cpp"
# End Source File
# Begin Source File
@@ -242,6 +246,10 @@ SOURCE=.\include\CppUTestExt\MockCheckedActualCall.h
# End Source File
# Begin Source File
+SOURCE=.\include\CppUTestExt\MockActualCallsQueue.h
+# End Source File
+# Begin Source File
+
SOURCE=.\include\CppUTestExt\MockCheckedExpectedCall.h
# End Source File
# Begin Source File
diff --git a/CppUTest.vcproj b/CppUTest.vcproj
index c0edc3813..b2202f31d 100644
--- a/CppUTest.vcproj
+++ b/CppUTest.vcproj
@@ -384,6 +384,28 @@
/>
+
+
+
+
+
+
+
+
@@ -927,6 +949,10 @@
RelativePath=".\include\CppUTestExt\MockActualCall.h"
>
+
+
diff --git a/CppUTest.vcxproj b/CppUTest.vcxproj
index 16e718e85..54e8a2db2 100644
--- a/CppUTest.vcxproj
+++ b/CppUTest.vcxproj
@@ -117,6 +117,7 @@
+
@@ -159,6 +160,7 @@
+
diff --git a/Makefile.am b/Makefile.am
index 30803d2ea..666a2ca5a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -95,6 +95,7 @@ lib_libCppUTestExt_a_SOURCES = \
src/CppUTestExt/MemoryReporterPlugin.cpp \
src/CppUTestExt/MemoryReportFormatter.cpp \
src/CppUTestExt/MockActualCall.cpp \
+ src/CppUTestExt/MockActualCallsQueue.cpp \
src/CppUTestExt/MockExpectedCall.cpp \
src/CppUTestExt/MockExpectedCallsList.cpp \
src/CppUTestExt/MockFailure.cpp \
@@ -118,6 +119,7 @@ include_cpputestext_HEADERS = \
include/CppUTestExt/MockActualCall.h \
include/CppUTestExt/MockCheckedActualCall.h \
include/CppUTestExt/MockCheckedExpectedCall.h \
+ include/CppUTestExt/MockActualCallsQueue.h \
include/CppUTestExt/MockExpectedCall.h \
include/CppUTestExt/MockExpectedCallsList.h \
include/CppUTestExt/MockFailure.h \
@@ -192,6 +194,7 @@ CppUTestExtTests_SOURCES = \
tests/CppUTestExt/MockComparatorCopierTest.cpp \
tests/CppUTestExt/MockExpectedCallTest.cpp \
tests/CppUTestExt/ExpectedFunctionsListTest.cpp \
+ tests/CppUTestExt/ActualCallsQueueTest.cpp \
tests/CppUTestExt/MockFailureReporterForTest.cpp \
tests/CppUTestExt/MockFailureTest.cpp \
tests/CppUTestExt/MockHierarchyTest.cpp \
diff --git a/include/CppUTest/SimpleString.h b/include/CppUTest/SimpleString.h
index c8bbcb5eb..1c64f81b2 100644
--- a/include/CppUTest/SimpleString.h
+++ b/include/CppUTest/SimpleString.h
@@ -173,8 +173,9 @@ SimpleString BracketsFormattedHexStringFrom(cpputest_longlong value);
SimpleString BracketsFormattedHexStringFrom(cpputest_ulonglong value);
SimpleString BracketsFormattedHexStringFrom(signed char value);
SimpleString BracketsFormattedHexString(SimpleString hexString);
-
-
+SimpleString AppendStringOnANewLine(const SimpleString& inputString, const SimpleString& stringToAppend,
+ const SimpleString& linePrefix = "");
+SimpleString ReplaceWithTextNoneWhenEmpty(const SimpleString& inputString, const SimpleString& linePrefix);
#if CPPUTEST_USE_STD_CPP_LIB
diff --git a/include/CppUTestExt/MockActualCall.h b/include/CppUTestExt/MockActualCall.h
index 496a499a0..badd7b5e1 100644
--- a/include/CppUTestExt/MockActualCall.h
+++ b/include/CppUTestExt/MockActualCall.h
@@ -42,7 +42,6 @@ class MockActualCall
virtual ~MockActualCall();
virtual MockActualCall& withName(const SimpleString& name)=0;
- virtual MockActualCall& withCallOrder(int callOrder)=0;
MockActualCall& withParameter(const SimpleString& name, bool value) { return withBoolParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, int value) { return withIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, unsigned int value) { return withUnsignedIntParameter(name, value); }
diff --git a/include/CppUTestExt/MockActualCallsQueue.h b/include/CppUTestExt/MockActualCallsQueue.h
new file mode 100644
index 000000000..16568b8af
--- /dev/null
+++ b/include/CppUTestExt/MockActualCallsQueue.h
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2016, Jesus Gonzalez
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef D_MockActualCallsQueue_h
+#define D_MockActualCallsQueue_h
+
+class MockCheckedActualCall;
+class SimpleString;
+
+/**
+ * This class implements a FIFO queue of MockCheckedActualCall calls.
+ *
+ * @note The queue can be created as owner of its stored calls or not. If the queue is the owner, then the ownership of the calls added
+ * to the queue is transferred to the queue, and therefore it's responsible for managing their life cycle (i.e. deleting them).
+ *
+ * @note The queue has a size limit. When the queue reaches its maximum size, adding new calls on the back will remove calls from the front.
+ */
+class MockActualCallsQueue
+{
+
+public:
+ /**
+ * Constructor.
+ *
+ * Creates an empty queue.
+ *
+ * @param owner [in] Indicates if the ownership of the calls added to the queue shall be transferred to the queue
+ * @param maxSize [in] Maximum size for the queue
+ */
+ MockActualCallsQueue(bool owner, unsigned int maxSize = (unsigned int) -1);
+
+ /**
+ * Destructor.
+ *
+ * Discards all items, and if the queue is the owner of the calls, then deletes their associated calls.
+ */
+ virtual ~MockActualCallsQueue();
+
+ /**
+ * Returns the number of calls stored in the queue.
+ *
+ * @return Size of the queue
+ */
+ virtual unsigned int size() const;
+
+ /**
+ * Checks if the queue is empty.
+ *
+ * @return @c true if the queue is empty, @c false otherwise
+ */
+ virtual bool isEmpty() const;
+
+ /**
+ * Clears the queue, discarding all items, and if the queue is the owner of its calls, then also deleting their associated calls.
+ */
+ virtual void clear();
+
+ /**
+ * Appends the call to the back of the queue.
+ *
+ * @note If the queue is the owner of its calls, then it becomes the owner of the passed object.
+ *
+ * @note If the queue is at its size limit, then the first item is discarded, and if the queue is the owner of its calls, then the
+ * associated call is also deleted.
+ *
+ * @param call [in] Pointer to the call to be appended
+ */
+ virtual void pushBack(MockCheckedActualCall* call);
+
+ /**
+ * Removes a call from the front of the queue, and returns it.
+ *
+ * @note If the queue is the owner of its calls, then the caller becomes the owner of the returned object.
+ *
+ * @return Pointer to the call that was in front of the queue, or NULL if the queue was empty
+ */
+ virtual MockCheckedActualCall* popFront();
+
+ /**
+ * Appends all the calls from @c otherQueue to the back of this queue.
+ *
+ * @note If this queue is the owner of calls, then it becomes the owner all the calls from @c otherQueue. This means that either
+ * this queue shall not be owner of calls, or that it's owner of calls and the calls from @c otherQueue do not have an owner
+ * yet (i.e. @c otherQueue is not owner of calls).
+ *
+ * @param otherQueue [in] Another queue
+ */
+ virtual void pushBackAll(const MockActualCallsQueue& otherQueue);
+
+ /**
+ * Gets the maximum size for the queue.
+ * @return Maximum size
+ */
+ virtual unsigned int getMaxSize();
+
+ /**
+ * Sets the maximum size for the queue.
+ *
+ * @note If the current size is greater than @c maxSize, then calls are removed in order from the front of the queue until the
+ * current size is equal to the maximum size.
+ *
+ * @param maxSize [in] Maximum size
+ */
+ virtual void setMaxSize(unsigned int maxSize);
+
+ /**
+ * Returns a string representation of the queue as a list with the description of all its stored calls, each on a new line.
+ *
+ * @param linePrefix String to be added before each individual call description
+ * @return String representation of the queue
+ */
+ virtual SimpleString toString(const SimpleString& linePrefix) const;
+
+ /**
+ * Returns a string representation of the queue as a list with the description of its stored calls for function @c functionName,
+ * each on a new line.
+ *
+ * @param functionName Name of the function to be filtered through
+ * @param linePrefix String to be added before each individual call description
+ * @return String representation of the queue
+ */
+ virtual SimpleString toStringFilterByFunction(const SimpleString& functionName, const SimpleString& linePrefix) const;
+
+protected:
+ class MockActualCallsQueueNode
+ {
+ public:
+ MockCheckedActualCall* call_;
+
+ MockActualCallsQueueNode* next_;
+ MockActualCallsQueueNode(MockCheckedActualCall* call) : call_(call), next_(NULL) {}
+ };
+
+private:
+ MockActualCallsQueueNode* head_;
+ MockActualCallsQueueNode* tail_;
+
+ unsigned int currentSize_;
+ unsigned int maxSize_;
+
+ bool owner_;
+
+ virtual void deleteFromFront();
+};
+
+#endif
diff --git a/include/CppUTestExt/MockCheckedActualCall.h b/include/CppUTestExt/MockCheckedActualCall.h
index f4606cf17..e66fc76c5 100644
--- a/include/CppUTestExt/MockCheckedActualCall.h
+++ b/include/CppUTestExt/MockCheckedActualCall.h
@@ -31,14 +31,15 @@
#include "CppUTestExt/MockActualCall.h"
#include "CppUTestExt/MockExpectedCallsList.h"
+class MockSupport;
+
class MockCheckedActualCall : public MockActualCall
{
public:
- MockCheckedActualCall(int callOrder, MockFailureReporter* reporter, const MockExpectedCallsList& expectations);
+ MockCheckedActualCall(unsigned int callOrder, MockFailureReporter* reporter, const MockSupport& mockSupport);
virtual ~MockCheckedActualCall();
virtual MockActualCall& withName(const SimpleString& name) _override;
- virtual MockActualCall& withCallOrder(int) _override;
virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) _override;
virtual MockActualCall& withIntParameter(const SimpleString& name, int value) _override;
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
@@ -95,17 +96,21 @@ class MockCheckedActualCall : public MockActualCall
virtual void checkExpectations();
virtual void setMockFailureReporter(MockFailureReporter* reporter);
+
+ virtual SimpleString toString() const;
+
+ const SimpleString& getName() const;
+
protected:
void setName(const SimpleString& name);
- SimpleString getName() const;
virtual UtestShell* getTest() const;
virtual void callHasSucceeded();
virtual void finalizeOutputParameters(MockCheckedExpectedCall* call);
- virtual void finalizeCallWhenFulfilled();
+ virtual void finalizeCallWhenMatchIsFound();
virtual void failTest(const MockFailure& failure);
virtual void checkInputParameter(const MockNamedValue& actualParameter);
virtual void checkOutputParameter(const MockNamedValue& outputParameter);
- virtual void callIsInProgress();
+ virtual void discardCurrentlyMatchingExpectations();
enum ActualCallState {
CALL_IN_PROGRESS,
@@ -114,16 +119,21 @@ class MockCheckedActualCall : public MockActualCall
};
virtual void setState(ActualCallState state);
+ virtual const SimpleString& getScopeName() const;
+
+ void setMatchingExpectedCall(MockCheckedExpectedCall* call);
+
private:
SimpleString functionName_;
- int callOrder_;
+ unsigned int callOrder_;
MockFailureReporter* reporter_;
ActualCallState state_;
- MockCheckedExpectedCall* fulfilledExpectation_;
+ bool expectationsChecked_;
+ MockCheckedExpectedCall* matchingExpectation_;
- MockExpectedCallsList unfulfilledExpectations_;
- const MockExpectedCallsList& allExpectations_;
+ MockExpectedCallsList potentiallyMatchingExpectations_;
+ const MockSupport& mockSupport_;
class MockOutputParametersListNode
{
@@ -150,7 +160,6 @@ class MockActualCallTrace : public MockActualCall
virtual ~MockActualCallTrace();
virtual MockActualCall& withName(const SimpleString& name) _override;
- virtual MockActualCall& withCallOrder(int) _override;
virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) _override;
virtual MockActualCall& withIntParameter(const SimpleString& name, int value) _override;
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
@@ -201,6 +210,8 @@ class MockActualCallTrace : public MockActualCall
virtual MockActualCall& onObject(const void* objectPtr) _override;
+ MockActualCall& withCallOrder(unsigned int callOrder);
+
const char* getTraceOutput();
void clear();
static MockActualCallTrace& instance();
@@ -215,7 +226,6 @@ class MockIgnoredActualCall: public MockActualCall
{
public:
virtual MockActualCall& withName(const SimpleString&) _override { return *this;}
- virtual MockActualCall& withCallOrder(int) _override { return *this; }
virtual MockActualCall& withBoolParameter(const SimpleString&, bool) _override { return *this; }
virtual MockActualCall& withIntParameter(const SimpleString&, int) _override { return *this; }
virtual MockActualCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override { return *this; }
diff --git a/include/CppUTestExt/MockCheckedExpectedCall.h b/include/CppUTestExt/MockCheckedExpectedCall.h
index e3f3725af..e0f19435e 100644
--- a/include/CppUTestExt/MockCheckedExpectedCall.h
+++ b/include/CppUTestExt/MockCheckedExpectedCall.h
@@ -35,11 +35,11 @@ class MockCheckedExpectedCall : public MockExpectedCall
{
public:
- MockCheckedExpectedCall();
+ MockCheckedExpectedCall(unsigned int minCalls, unsigned int maxCalls);
virtual ~MockCheckedExpectedCall();
virtual MockExpectedCall& withName(const SimpleString& name) _override;
- virtual MockExpectedCall& withCallOrder(int callOrder) _override;
+ virtual MockExpectedCall& withCallOrder(unsigned int initialCallOrder, unsigned int finalCallOrder) _override;
virtual MockExpectedCall& withBoolParameter(const SimpleString& name, bool value) _override;
virtual MockExpectedCall& withIntParameter(const SimpleString& name, int value) _override;
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
@@ -74,7 +74,7 @@ class MockCheckedExpectedCall : public MockExpectedCall
virtual MockNamedValue getInputParameter(const SimpleString& name);
virtual MockNamedValue getOutputParameter(const SimpleString& name);
virtual SimpleString getInputParameterType(const SimpleString& name);
- virtual SimpleString getInputParameterValueString(const SimpleString& name);
+ virtual SimpleString getInputParameterValueString(const SimpleString& name) const;
virtual bool hasInputParameterWithName(const SimpleString& name);
virtual bool hasInputParameter(const MockNamedValue& parameter);
@@ -84,27 +84,30 @@ class MockCheckedExpectedCall : public MockExpectedCall
virtual bool relatesToObject(const void* objectPtr) const;
virtual bool isFulfilled();
- virtual bool isFulfilledWithoutIgnoredParameters();
- virtual bool areParametersFulfilled();
- virtual bool areIgnoredParametersFulfilled();
+ virtual bool canMatchActualCalls();
+ virtual bool isMatchingActualCallAndFinalized();
+ virtual bool isMatchingActualCall();
+ virtual bool areParametersMatchingActualCall();
virtual bool isOutOfOrder() const;
- virtual void callWasMade(int callOrder);
+ virtual void callWasMade(unsigned int callOrder);
virtual void inputParameterWasPassed(const SimpleString& name);
virtual void outputParameterWasPassed(const SimpleString& name);
- virtual void parametersWereIgnored();
+ virtual void finalizeActualCallMatch();
virtual void wasPassedToObject();
- virtual void resetExpectation();
+ virtual void resetActualCallMatchingState();
- virtual SimpleString callToString();
+ virtual SimpleString callToString(bool asActualCall) const;
virtual SimpleString missingParametersToString();
- enum { NOT_CALLED_YET = -1, NO_EXPECTED_CALL_ORDER = -1};
- virtual int getCallOrder() const;
+ enum { NO_EXPECTED_CALL_ORDER = 0 };
+
+ virtual unsigned int getActualCallsFulfilled() const;
+
+ const SimpleString& getName() const;
protected:
void setName(const SimpleString& name);
- SimpleString getName() const;
private:
SimpleString functionName_;
@@ -113,69 +116,28 @@ class MockCheckedExpectedCall : public MockExpectedCall
{
public:
MockExpectedFunctionParameter(const SimpleString& name);
- void setFulfilled(bool b);
- bool isFulfilled() const;
+ void setMatchesActualCall(bool b);
+ bool isMatchingActualCall() const;
private:
- bool fulfilled_;
+ bool matchesActualCall_;
};
MockExpectedFunctionParameter* item(MockNamedValueListNode* node);
bool ignoreOtherParameters_;
- bool parametersWereIgnored_;
- int callOrder_;
- int expectedCallOrder_;
+ bool isActualCallMatchFinalized_;
+ unsigned int initialExpectedCallOrder_;
+ unsigned int finalExpectedCallOrder_;
bool outOfOrder_;
MockNamedValueList* inputParameters_;
MockNamedValueList* outputParameters_;
MockNamedValue returnValue_;
void* objectPtr_;
bool wasPassedToObject_;
-};
-
-struct MockExpectedCallCompositeNode;
-class MockExpectedCallComposite : public MockExpectedCall
-{
-public:
- MockExpectedCallComposite();
- virtual ~MockExpectedCallComposite();
-
- virtual MockExpectedCall& withName(const SimpleString& name) _override;
- virtual MockExpectedCall& withCallOrder(int callOrder) _override;
- virtual MockExpectedCall& withBoolParameter(const SimpleString& name, bool value) _override;
- virtual MockExpectedCall& withIntParameter(const SimpleString& name, int value) _override;
- virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
- virtual MockExpectedCall& withLongIntParameter(const SimpleString& name, long int value) _override;
- virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override;
- virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value) _override;
- virtual MockExpectedCall& withStringParameter(const SimpleString& name, const char* value) _override;
- virtual MockExpectedCall& withConstPointerParameter(const SimpleString& name, const void* value) _override;
- virtual MockExpectedCall& withPointerParameter(const SimpleString& name, void* value) _override;
- virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) _override;
- virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) _override;
- virtual MockExpectedCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value) _override;
- virtual MockExpectedCall& withOutputParameterReturning(const SimpleString& name, const void* value, size_t size) _override;
- virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString& typeName, const SimpleString& name, const void* value) _override;
- virtual MockExpectedCall& ignoreOtherParameters() _override;
-
- virtual MockExpectedCall& andReturnValue(bool value) _override;
- virtual MockExpectedCall& andReturnValue(int value) _override;
- virtual MockExpectedCall& andReturnValue(unsigned int value) _override;
- virtual MockExpectedCall& andReturnValue(long int value) _override;
- virtual MockExpectedCall& andReturnValue(unsigned long int value) _override;
- virtual MockExpectedCall& andReturnValue(double value) _override;
- virtual MockExpectedCall& andReturnValue(const char* value) _override;
- virtual MockExpectedCall& andReturnValue(void* value) _override;
- virtual MockExpectedCall& andReturnValue(const void* value) _override;
- virtual MockExpectedCall& andReturnValue(void (*value)()) _override;
-
- virtual MockExpectedCall& onObject(void* objectPtr) _override;
-
- virtual void add(MockExpectedCall& call);
- virtual void clear();
-private:
- MockExpectedCallCompositeNode* head_;
+ unsigned int actualCalls_;
+ unsigned int minCalls_;
+ unsigned int maxCalls_;
};
class MockIgnoredExpectedCall: public MockExpectedCall
@@ -183,7 +145,7 @@ class MockIgnoredExpectedCall: public MockExpectedCall
public:
virtual MockExpectedCall& withName(const SimpleString&) _override { return *this;}
- virtual MockExpectedCall& withCallOrder(int) _override { return *this; }
+ virtual MockExpectedCall& withCallOrder(unsigned int, unsigned int) _override { return *this; }
virtual MockExpectedCall& withBoolParameter(const SimpleString&, bool) _override { return *this; }
virtual MockExpectedCall& withIntParameter(const SimpleString&, int) _override { return *this; }
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override{ return *this; }
diff --git a/include/CppUTestExt/MockExpectedCall.h b/include/CppUTestExt/MockExpectedCall.h
index 73120e7f1..5efd6ed8b 100644
--- a/include/CppUTestExt/MockExpectedCall.h
+++ b/include/CppUTestExt/MockExpectedCall.h
@@ -39,7 +39,7 @@ class MockExpectedCall
virtual ~MockExpectedCall();
virtual MockExpectedCall& withName(const SimpleString& name)=0;
- virtual MockExpectedCall& withCallOrder(int)=0;
+ virtual MockExpectedCall& withCallOrder(unsigned int, unsigned int)=0;
MockExpectedCall& withParameter(const SimpleString& name, bool value) { return withBoolParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, int value) { return withIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, unsigned int value) { return withUnsignedIntParameter(name, value); }
diff --git a/include/CppUTestExt/MockExpectedCallsList.h b/include/CppUTestExt/MockExpectedCallsList.h
index 115192dd8..01b8792ce 100644
--- a/include/CppUTestExt/MockExpectedCallsList.h
+++ b/include/CppUTestExt/MockExpectedCallsList.h
@@ -39,11 +39,12 @@ class MockExpectedCallsList
virtual ~MockExpectedCallsList();
virtual void deleteAllExpectationsAndClearList();
- virtual int size() const;
- virtual int amountOfExpectationsFor(const SimpleString& name) const;
- virtual int amountOfUnfulfilledExpectations() const;
+ virtual unsigned int size() const;
+ virtual unsigned int amountOfActualCallsFulfilledFor(const SimpleString& name) const;
+ virtual unsigned int amountOfUnfulfilledExpectations() const;
virtual bool hasUnfulfilledExpectations() const;
- virtual bool hasUnfulfilledExpectationsBecauseOfMissingParameters() const;
+ virtual bool hasFinalizedMatchingExpectations() const;
+ virtual bool hasUnmatchingExpectationsBecauseOfMissingParameters() const;
virtual bool hasExpectationWithName(const SimpleString& name) const;
virtual bool hasCallsOutOfOrder() const;
virtual bool isEmpty() const;
@@ -53,7 +54,7 @@ class MockExpectedCallsList
virtual void addExpectationsRelatedTo(const SimpleString& name, const MockExpectedCallsList& list);
virtual void onlyKeepOutOfOrderExpectations();
- virtual void addUnfulfilledExpectations(const MockExpectedCallsList& list);
+ virtual void addPotentiallyMatchingExpectations(const MockExpectedCallsList& list);
virtual void onlyKeepExpectationsRelatedTo(const SimpleString& name);
virtual void onlyKeepExpectationsWithInputParameter(const MockNamedValue& parameter);
@@ -61,21 +62,20 @@ class MockExpectedCallsList
virtual void onlyKeepExpectationsWithOutputParameter(const MockNamedValue& parameter);
virtual void onlyKeepExpectationsWithOutputParameterName(const SimpleString& name);
virtual void onlyKeepExpectationsOnObject(const void* objectPtr);
- virtual void onlyKeepUnfulfilledExpectations();
+ virtual void onlyKeepUnmatchingExpectations();
- virtual MockCheckedExpectedCall* removeOneFulfilledExpectation();
- virtual MockCheckedExpectedCall* removeOneFulfilledExpectationWithIgnoredParameters();
- virtual MockCheckedExpectedCall* getOneFulfilledExpectationWithIgnoredParameters();
+ virtual MockCheckedExpectedCall* removeFirstFinalizedMatchingExpectation();
+ virtual MockCheckedExpectedCall* removeFirstMatchingExpectation();
+ virtual MockCheckedExpectedCall* getFirstMatchingExpectation();
- virtual void resetExpectations();
- virtual void callWasMade(int callOrder);
+ virtual void resetActualCallMatchingState();
virtual void wasPassedToObject();
virtual void parameterWasPassed(const SimpleString& parameterName);
virtual void outputParameterWasPassed(const SimpleString& parameterName);
virtual SimpleString unfulfilledCallsToString(const SimpleString& linePrefix = "") const;
virtual SimpleString fulfilledCallsToString(const SimpleString& linePrefix = "") const;
- virtual SimpleString missingParametersToString() const;
+ virtual SimpleString missingParametersToString(const SimpleString& linePrefix = "") const;
protected:
virtual void pruneEmptyNodeFromList();
@@ -90,7 +90,6 @@ class MockExpectedCallsList
: expectedCall_(expectedCall), next_(NULL) {}
};
- virtual MockExpectedCallsListNode* findNodeWithCallOrderOf(int callOrder) const;
private:
MockExpectedCallsListNode* head_;
diff --git a/include/CppUTestExt/MockFailure.h b/include/CppUTestExt/MockFailure.h
index 8cfdced74..ee625cd92 100644
--- a/include/CppUTestExt/MockFailure.h
+++ b/include/CppUTestExt/MockFailure.h
@@ -32,6 +32,7 @@
#include "CppUTest/TestFailure.h"
class MockExpectedCallsList;
+class MockActualCallsQueue;
class MockCheckedActualCall;
class MockNamedValue;
class MockFailure;
@@ -56,44 +57,50 @@ class MockFailure : public TestFailure
MockFailure(UtestShell* test);
virtual ~MockFailure(){}
protected:
- void addExpectationsAndCallHistory(const MockExpectedCallsList& expectations);
- void addExpectationsAndCallHistoryRelatedTo(const SimpleString& function, const MockExpectedCallsList& expectations);
+ void addExpectationsAndCallHistory(const MockExpectedCallsList& expectedCalls, const MockActualCallsQueue& actualCalls);
+ void addExpectationsAndCallHistoryRelatedTo(const SimpleString& function, const MockExpectedCallsList& expectedCalls,
+ const MockActualCallsQueue& actualCalls);
};
-class MockExpectedCallsDidntHappenFailure : public MockFailure
+class MockExpectedCallsNotFulfilledFailure : public MockFailure
{
public:
- MockExpectedCallsDidntHappenFailure(UtestShell* test, const MockExpectedCallsList& expectations);
+ MockExpectedCallsNotFulfilledFailure(UtestShell* test, const MockExpectedCallsList& expectations,
+ const MockActualCallsQueue& actualCalls);
};
class MockUnexpectedCallHappenedFailure : public MockFailure
{
public:
- MockUnexpectedCallHappenedFailure(UtestShell* test, const SimpleString& name, const MockExpectedCallsList& expectations);
+ MockUnexpectedCallHappenedFailure(UtestShell* test, const SimpleString& name, const MockExpectedCallsList& expectations,
+ const MockActualCallsQueue& actualCalls);
};
class MockCallOrderFailure : public MockFailure
{
public:
- MockCallOrderFailure(UtestShell* test, const MockExpectedCallsList& expectations);
+ MockCallOrderFailure(UtestShell* test, const MockExpectedCallsList& expectations, const MockActualCallsQueue& actualCalls);
};
class MockUnexpectedInputParameterFailure : public MockFailure
{
public:
- MockUnexpectedInputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter, const MockExpectedCallsList& expectations);
+ MockUnexpectedInputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter,
+ const MockExpectedCallsList& expectations, const MockActualCallsQueue& actualCalls);
};
class MockUnexpectedOutputParameterFailure : public MockFailure
{
public:
- MockUnexpectedOutputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter, const MockExpectedCallsList& expectations);
+ MockUnexpectedOutputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter,
+ const MockExpectedCallsList& expectations, const MockActualCallsQueue& actualCalls);
};
class MockExpectedParameterDidntHappenFailure : public MockFailure
{
public:
- MockExpectedParameterDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations);
+ MockExpectedParameterDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations,
+ const MockActualCallsQueue& actualCalls);
};
class MockNoWayToCompareCustomTypeFailure : public MockFailure
@@ -111,13 +118,22 @@ class MockNoWayToCopyCustomTypeFailure : public MockFailure
class MockUnexpectedObjectFailure : public MockFailure
{
public:
- MockUnexpectedObjectFailure(UtestShell* test, const SimpleString& functionName, const void* expected, const MockExpectedCallsList& expectations);
+ MockUnexpectedObjectFailure(UtestShell* test, const SimpleString& functionName, const void* expected,
+ const MockExpectedCallsList& expectations, const MockActualCallsQueue& actualCalls);
};
class MockExpectedObjectDidntHappenFailure : public MockFailure
{
public:
- MockExpectedObjectDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations);
+ MockExpectedObjectDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations,
+ const MockActualCallsQueue& actualCalls);
+};
+
+class MockStrictOrderingIncompatibleWithOptionalCallsFailure : public MockFailure
+{
+public:
+ MockStrictOrderingIncompatibleWithOptionalCallsFailure(UtestShell* test, const SimpleString& functionName, unsigned int minCalls, unsigned int maxCalls);
+ virtual ~MockStrictOrderingIncompatibleWithOptionalCallsFailure(){}
};
#endif
diff --git a/include/CppUTestExt/MockSupport.h b/include/CppUTestExt/MockSupport.h
index e58bf2a57..c5b49716c 100755
--- a/include/CppUTestExt/MockSupport.h
+++ b/include/CppUTestExt/MockSupport.h
@@ -32,6 +32,7 @@
#include "CppUTestExt/MockCheckedActualCall.h"
#include "CppUTestExt/MockCheckedExpectedCall.h"
#include "CppUTestExt/MockExpectedCallsList.h"
+#include "CppUTestExt/MockActualCallsQueue.h"
class UtestShell;
class MockSupport;
@@ -48,7 +49,13 @@ class MockSupport
virtual void strictOrder();
virtual MockExpectedCall& expectOneCall(const SimpleString& functionName);
virtual void expectNoCall(const SimpleString& functionName);
- virtual MockExpectedCall& expectNCalls(int amount, const SimpleString& functionName);
+ virtual MockExpectedCall& expectNCalls(unsigned int amount, const SimpleString& functionName);
+ virtual MockExpectedCall& expectAtLeastOneCall(const SimpleString& functionName);
+ virtual MockExpectedCall& expectAtLeastNCalls(unsigned int amount, const SimpleString& functionName);
+ virtual MockExpectedCall& expectAtMostOneCall(const SimpleString& functionName);
+ virtual MockExpectedCall& expectAtMostNCalls(unsigned int amount, const SimpleString& functionName);
+ virtual MockExpectedCall& expectAnyCalls(const SimpleString& functionName);
+ virtual MockExpectedCall& expectRangeOfCalls(unsigned int minCalls, unsigned int maxCalls, const SimpleString& functionName);
virtual MockActualCall& actualCall(const SimpleString& functionName);
virtual bool hasReturnValue();
virtual MockNamedValue returnValue();
@@ -97,6 +104,7 @@ class MockSupport
virtual void enable();
virtual void tracing(bool enabled);
virtual void ignoreOtherCalls();
+ virtual void setMaxCallLogSize(unsigned int maxSize);
virtual void checkExpectations();
virtual bool expectedCallsLeft();
@@ -117,46 +125,54 @@ class MockSupport
virtual void installComparatorsAndCopiers(const MockNamedValueComparatorsAndCopiersRepository& repository);
virtual void removeAllComparatorsAndCopiers();
+ virtual const MockExpectedCallsList& getExpectedCalls() const;
+ virtual const MockActualCallsQueue& getActualCalls() const;
+
+ const SimpleString& getName() const;
+
protected:
MockSupport* clone(const SimpleString& mockName);
- virtual MockCheckedActualCall *createActualFunctionCall();
+ virtual MockCheckedActualCall *createActualCall();
virtual void failTest(MockFailure& failure);
void countCheck();
private:
- int callOrder_;
- int expectedCallOrder_;
+ unsigned int actualCallOrder_;
+ unsigned int expectedCallOrder_;
bool strictOrdering_;
MockFailureReporter *activeReporter_;
MockFailureReporter *standardReporter_;
MockFailureReporter defaultReporter_;
MockExpectedCallsList expectations_;
- MockExpectedCallsList unExpectations_;
bool ignoreOtherCalls_;
bool enabled_;
- MockCheckedActualCall *lastActualFunctionCall_;
- MockExpectedCallComposite compositeCalls_;
+ MockCheckedActualCall *currentActualCall_;
MockNamedValueComparatorsAndCopiersRepository comparatorsAndCopiersRepository_;
MockNamedValueList data_;
const SimpleString mockName_;
-
+ MockActualCallsQueue actualCalls_;
bool tracing_;
- void checkExpectationsOfLastCall();
- bool wasLastCallFulfilled();
- void failTestWithUnexpectedCalls();
+ void checkExpectationsOfLastActualCall();
+ void checkExpectationsOfLastActualCallsInAllScopes();
+ bool isLastActualCallFulfilled();
+ bool shallFailWithExpectedCallsNotFulfilled();
+
+ void failTestWithExpectedCallsNotFulfilled();
void failTestWithOutOfOrderCalls();
+ void failTestWithStrictOrderingIncompatibleWithOptionalCalls();
MockNamedValue* retrieveDataFromStore(const SimpleString& name);
MockSupport* getMockSupport(MockNamedValueListNode* node);
- bool hasntExpectationWithName(const SimpleString& functionName);
- bool hasntUnexpectationWithName(const SimpleString& functionName);
- bool hasCallsOutOfOrder();
+ bool callIsIgnored(const SimpleString& functionName);
+ bool hasCallsOutOfOrderInAnyScope();
SimpleString appendScopeToName(const SimpleString& functionName);
+ void addExpectedCallsForAllScopes(MockExpectedCallsList& expectedCalls);
+ void addActualCallsForAllScopes(MockActualCallsQueue& expectedCalls);
};
#endif
diff --git a/include/CppUTestExt/MockSupport_c.h b/include/CppUTestExt/MockSupport_c.h
index 0706d5472..902ce5f47 100644
--- a/include/CppUTestExt/MockSupport_c.h
+++ b/include/CppUTestExt/MockSupport_c.h
@@ -150,7 +150,13 @@ struct SMockSupport_c
void (*strictOrder)(void);
MockExpectedCall_c* (*expectOneCall)(const char* name);
void (*expectNoCall)(const char* name);
- MockExpectedCall_c* (*expectNCalls)(int number, const char* name);
+ MockExpectedCall_c* (*expectNCalls)(unsigned int number, const char* name);
+ MockExpectedCall_c* (*expectAtLeastOneCall)(const char* name);
+ MockExpectedCall_c* (*expectAtLeastNCalls)(unsigned int amount, const char* name);
+ MockExpectedCall_c* (*expectAtMostOneCall)(const char* name);
+ MockExpectedCall_c* (*expectAtMostNCalls)(unsigned int amount, const char* name);
+ MockExpectedCall_c* (*expectAnyCalls)(const char* name);
+ MockExpectedCall_c* (*expectRangeOfCalls)(unsigned int minCalls, unsigned int maxCalls, const char* name);
MockActualCall_c* (*actualCall)(const char* name);
int (*hasReturnValue)(void);
MockValue_c (*returnValue)(void);
@@ -189,6 +195,7 @@ struct SMockSupport_c
void (*disable)(void);
void (*enable)(void);
void (*ignoreOtherCalls)(void);
+ void (*setMaxCallLogSize)(unsigned int maxSize);
void (*checkExpectations)(void);
int (*expectedCallsLeft)(void);
diff --git a/platforms/Dos/sources.mk b/platforms/Dos/sources.mk
index 0c44762e0..62730c1a8 100644
--- a/platforms/Dos/sources.mk
+++ b/platforms/Dos/sources.mk
@@ -34,6 +34,7 @@ CPPUX_OBJECTS := \
$(CPPUTEST_HOME)/src/CppUTestExt/OrderedTest.o \
$(CPPUTEST_HOME)/src/CppUTestExt/MemoryReportFormatter.o \
$(CPPUTEST_HOME)/src/CppUTestExt/MockExpectedCallsList.o \
+ $(CPPUTEST_HOME)/src/CppUTestExt/MockActualCallsQueue.o \
$(CPPUTEST_HOME)/src/CppUTestExt/MockSupport.o \
CPPU1_OBJECTS := \
@@ -107,13 +108,14 @@ CPPU6_OBJECTS := \
$(CPPUTEST_HOME)/tests/CppUTestExt/AllTests.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/MockFailureReporterForTest.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/ExpectedFunctionsListTest.o \
+ $(CPPUTEST_HOME)/tests/CppUTestExt/ActualCallsQueueTest.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/MockCallTest.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/MockComparatorCopierTest.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/MockHierarchyTest.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/MockParameterTest.o \
$(CPPUTEST_HOME)/tests/TestUTestStringMacro.o \
- CPPU7_OBJECTS := \
+CPPU7_OBJECTS := \
$(CPPUTEST_HOME)/tests/CppUTestExt/AllTests.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/MockFailureReporterForTest.o \
$(CPPUTEST_HOME)/tests/CppUTestExt/IEEE754PluginTest.o \
diff --git a/src/CppUTest/SimpleString.cpp b/src/CppUTest/SimpleString.cpp
index 6932d0b54..9853fd98d 100644
--- a/src/CppUTest/SimpleString.cpp
+++ b/src/CppUTest/SimpleString.cpp
@@ -808,6 +808,25 @@ SimpleString StringFromOrdinalNumber(unsigned int number)
return StringFromFormat("%u%s", number, suffix);
}
+SimpleString AppendStringOnANewLine(const SimpleString& inputString, const SimpleString& stringToAppend, const SimpleString& linePrefix)
+{
+ SimpleString str = inputString;
+ if (!str.isEmpty()) str += "\n";
+ str += linePrefix;
+ str += stringToAppend;
+ return str;
+}
+
+SimpleString ReplaceWithTextNoneWhenEmpty(const SimpleString& inputString, const SimpleString& linePrefix)
+{
+ SimpleString str = inputString;
+ if (str == "") {
+ str += linePrefix;
+ str += "";
+ }
+ return str;
+}
+
SimpleStringCollection::SimpleStringCollection()
{
collection_ = 0;
diff --git a/src/CppUTestExt/CMakeLists.txt b/src/CppUTestExt/CMakeLists.txt
index 749be7a9e..c29b59bb0 100644
--- a/src/CppUTestExt/CMakeLists.txt
+++ b/src/CppUTestExt/CMakeLists.txt
@@ -12,6 +12,7 @@ set(CppUTestExt_src
OrderedTest.cpp
MemoryReportFormatter.cpp
MockExpectedCallsList.cpp
+ MockActualCallsQueue.cpp
MockSupport.cpp
)
@@ -34,6 +35,7 @@ set(CppUTestExt_headers
${CppUTestRootDirectory}/include/CppUTestExt/GTestConvertor.h
${CppUTestRootDirectory}/include/CppUTestExt/MockActualCall.h
${CppUTestRootDirectory}/include/CppUTestExt/MockCheckedActualCall.h
+ ${CppUTestRootDirectory}/include/CppUTestExt/MockActualCallsQueue.h
${CppUTestRootDirectory}/include/CppUTestExt/MockNamedValue.h
${CppUTestRootDirectory}/include/CppUTestExt/MockSupport.h
)
diff --git a/src/CppUTestExt/MockActualCall.cpp b/src/CppUTestExt/MockActualCall.cpp
index a7644dc53..d97974128 100644
--- a/src/CppUTestExt/MockActualCall.cpp
+++ b/src/CppUTestExt/MockActualCall.cpp
@@ -30,6 +30,7 @@
#include "CppUTestExt/MockCheckedExpectedCall.h"
#include "CppUTestExt/MockFailure.h"
#include "CppUTest/PlatformSpecificFunctions.h"
+#include "CppUTestExt/MockSupport.h"
MockActualCall::MockActualCall()
{
@@ -44,15 +45,15 @@ void MockCheckedActualCall::setName(const SimpleString& name)
functionName_ = name;
}
-SimpleString MockCheckedActualCall::getName() const
+const SimpleString& MockCheckedActualCall::getName() const
{
return functionName_;
}
-MockCheckedActualCall::MockCheckedActualCall(int callOrder, MockFailureReporter* reporter, const MockExpectedCallsList& allExpectations)
- : callOrder_(callOrder), reporter_(reporter), state_(CALL_SUCCEED), fulfilledExpectation_(NULL), allExpectations_(allExpectations), outputParameterExpectations_(NULL)
+MockCheckedActualCall::MockCheckedActualCall(unsigned int callOrder, MockFailureReporter* reporter, const MockSupport& mockSupport)
+ : callOrder_(callOrder), reporter_(reporter), state_(CALL_SUCCEED), expectationsChecked_(false), matchingExpectation_(NULL), mockSupport_(mockSupport), outputParameterExpectations_(NULL)
{
- unfulfilledExpectations_.addUnfulfilledExpectations(allExpectations);
+ potentiallyMatchingExpectations_.addPotentiallyMatchingExpectations(mockSupport.getExpectedCalls());
}
MockCheckedActualCall::~MockCheckedActualCall()
@@ -103,19 +104,19 @@ void MockCheckedActualCall::finalizeOutputParameters(MockCheckedExpectedCall* ex
}
}
-void MockCheckedActualCall::finalizeCallWhenFulfilled()
+void MockCheckedActualCall::finalizeCallWhenMatchIsFound()
{
- // Expectations that don't ignore parameters have higher fulfillment preference than those that ignore parameters
+ // Expectations that don't ignore parameters have higher fulfillment preference than those that ignore parameters
- fulfilledExpectation_ = unfulfilledExpectations_.removeOneFulfilledExpectation();
- if (fulfilledExpectation_) {
- finalizeOutputParameters(fulfilledExpectation_);
+ matchingExpectation_ = potentiallyMatchingExpectations_.removeFirstFinalizedMatchingExpectation();
+ if (matchingExpectation_) {
+ finalizeOutputParameters(matchingExpectation_);
callHasSucceeded();
} else {
- MockCheckedExpectedCall* fulfilledExpectationWithIgnoredParameters = unfulfilledExpectations_.getOneFulfilledExpectationWithIgnoredParameters();
- if (fulfilledExpectationWithIgnoredParameters) {
- finalizeOutputParameters(fulfilledExpectationWithIgnoredParameters);
- }
+ MockCheckedExpectedCall* matchingExpectationWithIgnoredParameters = potentiallyMatchingExpectations_.getFirstMatchingExpectation();
+ if (matchingExpectationWithIgnoredParameters) {
+ finalizeOutputParameters(matchingExpectationWithIgnoredParameters);
+ }
}
}
@@ -124,38 +125,30 @@ void MockCheckedActualCall::callHasSucceeded()
setState(CALL_SUCCEED);
}
-void MockCheckedActualCall::callIsInProgress()
+void MockCheckedActualCall::discardCurrentlyMatchingExpectations()
{
- setState(CALL_IN_PROGRESS);
- if (fulfilledExpectation_)
+ if (matchingExpectation_)
{
- fulfilledExpectation_->resetExpectation();
- fulfilledExpectation_ = NULL;
+ matchingExpectation_->resetActualCallMatchingState();
+ matchingExpectation_ = NULL;
}
- unfulfilledExpectations_.onlyKeepUnfulfilledExpectations();
+ potentiallyMatchingExpectations_.onlyKeepUnmatchingExpectations();
}
MockActualCall& MockCheckedActualCall::withName(const SimpleString& name)
{
setName(name);
- callIsInProgress();
+ setState(CALL_IN_PROGRESS);
- unfulfilledExpectations_.onlyKeepExpectationsRelatedTo(name);
- if (unfulfilledExpectations_.isEmpty()) {
- MockUnexpectedCallHappenedFailure failure(getTest(), name, allExpectations_);
+ potentiallyMatchingExpectations_.onlyKeepExpectationsRelatedTo(name);
+ if (potentiallyMatchingExpectations_.isEmpty()) {
+ MockUnexpectedCallHappenedFailure failure(getTest(), name, mockSupport_.getExpectedCalls(), mockSupport_.getActualCalls());
failTest(failure);
return *this;
}
- unfulfilledExpectations_.callWasMade(callOrder_);
-
- finalizeCallWhenFulfilled();
-
- return *this;
-}
+ finalizeCallWhenMatchIsFound();
-MockActualCall& MockCheckedActualCall::withCallOrder(int)
-{
return *this;
}
@@ -166,18 +159,20 @@ void MockCheckedActualCall::checkInputParameter(const MockNamedValue& actualPara
return;
}
- callIsInProgress();
+ setState(CALL_IN_PROGRESS);
+ discardCurrentlyMatchingExpectations();
- unfulfilledExpectations_.onlyKeepExpectationsWithInputParameter(actualParameter);
+ potentiallyMatchingExpectations_.onlyKeepExpectationsWithInputParameter(actualParameter);
- if (unfulfilledExpectations_.isEmpty()) {
- MockUnexpectedInputParameterFailure failure(getTest(), getName(), actualParameter, allExpectations_);
+ if (potentiallyMatchingExpectations_.isEmpty()) {
+ MockUnexpectedInputParameterFailure failure(getTest(), getName(), actualParameter, mockSupport_.getExpectedCalls(),
+ mockSupport_.getActualCalls());
failTest(failure);
return;
}
- unfulfilledExpectations_.parameterWasPassed(actualParameter.getName());
- finalizeCallWhenFulfilled();
+ potentiallyMatchingExpectations_.parameterWasPassed(actualParameter.getName());
+ finalizeCallWhenMatchIsFound();
}
void MockCheckedActualCall::checkOutputParameter(const MockNamedValue& outputParameter)
@@ -187,18 +182,20 @@ void MockCheckedActualCall::checkOutputParameter(const MockNamedValue& outputPar
return;
}
- callIsInProgress();
+ setState(CALL_IN_PROGRESS);
+ discardCurrentlyMatchingExpectations();
- unfulfilledExpectations_.onlyKeepExpectationsWithOutputParameter(outputParameter);
+ potentiallyMatchingExpectations_.onlyKeepExpectationsWithOutputParameter(outputParameter);
- if (unfulfilledExpectations_.isEmpty()) {
- MockUnexpectedOutputParameterFailure failure(getTest(), getName(), outputParameter, allExpectations_);
+ if (potentiallyMatchingExpectations_.isEmpty()) {
+ MockUnexpectedOutputParameterFailure failure(getTest(), getName(), outputParameter, mockSupport_.getExpectedCalls(),
+ mockSupport_.getActualCalls());
failTest(failure);
return;
}
- unfulfilledExpectations_.outputParameterWasPassed(outputParameter.getName());
- finalizeCallWhenFulfilled();
+ potentiallyMatchingExpectations_.outputParameterWasPassed(outputParameter.getName());
+ finalizeCallWhenMatchIsFound();
}
MockActualCall& MockCheckedActualCall::withBoolParameter(const SimpleString& name, bool value)
@@ -337,28 +334,41 @@ bool MockCheckedActualCall::hasFailed() const
void MockCheckedActualCall::checkExpectations()
{
+ if(expectationsChecked_)
+ {
+ return;
+ }
+
+ expectationsChecked_ = true;
+
if (state_ != CALL_IN_PROGRESS)
{
- unfulfilledExpectations_.resetExpectations();
+ if(state_ == CALL_SUCCEED)
+ {
+ matchingExpectation_->callWasMade(callOrder_);
+ }
+ potentiallyMatchingExpectations_.resetActualCallMatchingState();
return;
}
- if (! unfulfilledExpectations_.hasUnfulfilledExpectations())
- FAIL("Actual call is in progress. Checking expectations. But no unfulfilled expectations. Cannot happen.") // LCOV_EXCL_LINE
+ if (potentiallyMatchingExpectations_.hasFinalizedMatchingExpectations())
+ FAIL("Actual call is in progress, but there are finalized matching expectations when checking expectations. This cannot happen.") // LCOV_EXCL_LINE
- fulfilledExpectation_ = unfulfilledExpectations_.removeOneFulfilledExpectationWithIgnoredParameters();
- if (fulfilledExpectation_) {
+ matchingExpectation_ = potentiallyMatchingExpectations_.removeFirstMatchingExpectation();
+ if (matchingExpectation_) {
+ matchingExpectation_->finalizeActualCallMatch();
callHasSucceeded();
- unfulfilledExpectations_.resetExpectations();
+ matchingExpectation_->callWasMade(callOrder_);
+ potentiallyMatchingExpectations_.resetActualCallMatchingState();
return;
}
- if (unfulfilledExpectations_.hasUnfulfilledExpectationsBecauseOfMissingParameters()) {
- MockExpectedParameterDidntHappenFailure failure(getTest(), getName(), allExpectations_);
+ if (potentiallyMatchingExpectations_.hasUnmatchingExpectationsBecauseOfMissingParameters()) {
+ MockExpectedParameterDidntHappenFailure failure(getTest(), getName(), mockSupport_.getExpectedCalls(), mockSupport_.getActualCalls());
failTest(failure);
}
else {
- MockExpectedObjectDidntHappenFailure failure(getTest(), getName(), allExpectations_);
+ MockExpectedObjectDidntHappenFailure failure(getTest(), getName(), mockSupport_.getExpectedCalls(), mockSupport_.getActualCalls());
failTest(failure);
}
}
@@ -371,8 +381,8 @@ void MockCheckedActualCall::setState(ActualCallState state)
MockNamedValue MockCheckedActualCall::returnValue()
{
checkExpectations();
- if (fulfilledExpectation_)
- return fulfilledExpectation_->returnValue();
+ if (matchingExpectation_)
+ return matchingExpectation_->returnValue();
return MockNamedValue("no return value");
}
@@ -513,19 +523,25 @@ bool MockCheckedActualCall::hasReturnValue()
MockActualCall& MockCheckedActualCall::onObject(const void* objectPtr)
{
- callIsInProgress();
+ if(hasFailed())
+ {
+ return *this;
+ }
- unfulfilledExpectations_.onlyKeepExpectationsOnObject(objectPtr);
+ setState(CALL_IN_PROGRESS);
+ discardCurrentlyMatchingExpectations();
+
+ potentiallyMatchingExpectations_.onlyKeepExpectationsOnObject(objectPtr);
- if (unfulfilledExpectations_.isEmpty()) {
- MockUnexpectedObjectFailure failure(getTest(), getName(), objectPtr, allExpectations_);
+ if (potentiallyMatchingExpectations_.isEmpty()) {
+ MockUnexpectedObjectFailure failure(getTest(), getName(), objectPtr, mockSupport_.getExpectedCalls(), mockSupport_.getActualCalls());
failTest(failure);
return *this;
}
- unfulfilledExpectations_.wasPassedToObject();
+ potentiallyMatchingExpectations_.wasPassedToObject();
+ finalizeCallWhenMatchIsFound();
- finalizeCallWhenFulfilled();
return *this;
}
@@ -554,6 +570,36 @@ void MockCheckedActualCall::cleanUpOutputParameterList()
}
}
+const SimpleString& MockCheckedActualCall::getScopeName() const
+{
+ return mockSupport_.getName();
+}
+
+SimpleString MockCheckedActualCall::toString() const
+{
+ SimpleString str;
+ const SimpleString& scopeName = getScopeName();
+
+ if (scopeName.isEmpty()) {
+ str += StringFromFormat("(%u) ", callOrder_);
+ } else {
+ str += StringFromFormat("(%s::%u) ", scopeName.asCharString(), callOrder_);
+ }
+
+ if (matchingExpectation_) {
+ str += matchingExpectation_->callToString(true);
+ } else {
+ str += functionName_;
+ str += " (NOT matching any expected call)";
+ }
+
+ return str;
+}
+
+void MockCheckedActualCall::setMatchingExpectedCall(MockCheckedExpectedCall* call)
+{
+ matchingExpectation_ = call;
+}
MockActualCallTrace::MockActualCallTrace()
{
@@ -565,18 +611,11 @@ MockActualCallTrace::~MockActualCallTrace()
MockActualCall& MockActualCallTrace::withName(const SimpleString& name)
{
- traceBuffer_ += "\nFunction name:";
+ traceBuffer_ += " Function name:";
traceBuffer_ += name;
return *this;
}
-MockActualCall& MockActualCallTrace::withCallOrder(int callOrder)
-{
- traceBuffer_ += " withCallOrder:";
- traceBuffer_ += StringFrom(callOrder);
- return *this;
-}
-
void MockActualCallTrace::addParameterName(const SimpleString& name)
{
traceBuffer_ += " ";
@@ -584,6 +623,14 @@ void MockActualCallTrace::addParameterName(const SimpleString& name)
traceBuffer_ += ":";
}
+MockActualCall& MockActualCallTrace::withCallOrder(unsigned int callOrder)
+{
+ traceBuffer_ += "\n";
+ traceBuffer_ += StringFrom(callOrder);
+ traceBuffer_ += " >";
+ return *this;
+}
+
MockActualCall& MockActualCallTrace::withBoolParameter(const SimpleString& name, bool value)
{
addParameterName(name);
diff --git a/src/CppUTestExt/MockActualCallsQueue.cpp b/src/CppUTestExt/MockActualCallsQueue.cpp
new file mode 100644
index 000000000..372bb45c9
--- /dev/null
+++ b/src/CppUTestExt/MockActualCallsQueue.cpp
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2016, Jesus Gonzalez
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "CppUTest/TestHarness.h"
+#include "CppUTestExt/MockActualCallsQueue.h"
+#include "CppUTestExt/MockCheckedActualCall.h"
+#include "CppUTest/SimpleString.h"
+
+MockActualCallsQueue::MockActualCallsQueue(bool owner, unsigned int maxSize)
+: head_(NULL), tail_(NULL), currentSize_(0), maxSize_(maxSize), owner_(owner)
+{
+}
+
+MockActualCallsQueue::~MockActualCallsQueue()
+{
+ clear();
+}
+
+unsigned int MockActualCallsQueue::size() const
+{
+ return currentSize_;
+}
+
+bool MockActualCallsQueue::isEmpty() const
+{
+ return currentSize_ == 0;
+}
+
+void MockActualCallsQueue::pushBack(MockCheckedActualCall* call)
+{
+ MockActualCallsQueueNode* newCall = new MockActualCallsQueueNode(call);
+
+ if (currentSize_ >= maxSize_) {
+ deleteFromFront();
+ }
+
+ if (tail_ == NULL) {
+ head_ = newCall;
+ } else {
+ tail_->next_ = newCall;
+ }
+ tail_ = newCall;
+ currentSize_++;
+}
+
+MockCheckedActualCall* MockActualCallsQueue::popFront()
+{
+ MockCheckedActualCall* actualCall = NULL;
+
+ if (head_) {
+ MockActualCallsQueueNode* next = head_->next_;
+ actualCall = head_->call_;
+ delete head_;
+ currentSize_--;
+ head_ = next;
+ if (!head_) {
+ tail_ = NULL;
+ }
+ }
+
+ return actualCall;
+}
+
+void MockActualCallsQueue::clear()
+{
+ while (head_) {
+ MockActualCallsQueueNode* next = head_->next_;
+ if (owner_) {
+ delete head_->call_;
+ }
+ delete head_;
+ head_ = next;
+ }
+ tail_ = NULL;
+ currentSize_ = 0;
+}
+
+void MockActualCallsQueue::pushBackAll(const MockActualCallsQueue& otherQueue)
+{
+ for (MockActualCallsQueueNode* p = otherQueue.head_; p; p = p->next_) {
+ pushBack(p->call_);
+ }
+}
+
+unsigned int MockActualCallsQueue::getMaxSize()
+{
+ return maxSize_;
+}
+
+void MockActualCallsQueue::setMaxSize(unsigned int maxSize)
+{
+ maxSize_ = maxSize;
+ while(currentSize_ > maxSize_) {
+ deleteFromFront();
+ }
+}
+
+void MockActualCallsQueue::deleteFromFront()
+{
+ MockCheckedActualCall* frontCall = popFront();
+ if (owner_) {
+ delete frontCall;
+ }
+}
+
+SimpleString MockActualCallsQueue::toString(const SimpleString& linePrefix) const
+{
+ SimpleString str;
+ for (MockActualCallsQueueNode* p = head_; p; p = p->next_) {
+ str = AppendStringOnANewLine(str, p->call_->toString(), linePrefix);
+ }
+ return ReplaceWithTextNoneWhenEmpty(str, linePrefix);
+}
+
+SimpleString MockActualCallsQueue::toStringFilterByFunction(const SimpleString& functionName, const SimpleString& linePrefix) const
+{
+ SimpleString str;
+ for (MockActualCallsQueueNode* p = head_; p; p = p->next_) {
+ if (p->call_->getName() == functionName) {
+ str = AppendStringOnANewLine(str, p->call_->toString(), linePrefix);
+ }
+ }
+ return ReplaceWithTextNoneWhenEmpty(str, linePrefix);
+}
+
diff --git a/src/CppUTestExt/MockExpectedCall.cpp b/src/CppUTestExt/MockExpectedCall.cpp
index e9f3c96d0..65c4b4b5a 100644
--- a/src/CppUTestExt/MockExpectedCall.cpp
+++ b/src/CppUTestExt/MockExpectedCall.cpp
@@ -46,13 +46,16 @@ void MockCheckedExpectedCall::setName(const SimpleString& name)
functionName_ = name;
}
-SimpleString MockCheckedExpectedCall::getName() const
+const SimpleString& MockCheckedExpectedCall::getName() const
{
return functionName_;
}
-MockCheckedExpectedCall::MockCheckedExpectedCall()
- : ignoreOtherParameters_(false), parametersWereIgnored_(false), callOrder_(0), expectedCallOrder_(NO_EXPECTED_CALL_ORDER), outOfOrder_(true), returnValue_(""), objectPtr_(NULL), wasPassedToObject_(true)
+MockCheckedExpectedCall::MockCheckedExpectedCall(unsigned int minCalls, unsigned int maxCalls)
+ : ignoreOtherParameters_(false), isActualCallMatchFinalized_(false),
+ initialExpectedCallOrder_(NO_EXPECTED_CALL_ORDER), finalExpectedCallOrder_(NO_EXPECTED_CALL_ORDER),
+ outOfOrder_(false), returnValue_(""), objectPtr_(NULL), wasPassedToObject_(true),
+ actualCalls_(0), minCalls_(minCalls), maxCalls_(maxCalls)
{
inputParameters_ = new MockNamedValueList();
outputParameters_ = new MockNamedValueList();
@@ -69,7 +72,6 @@ MockCheckedExpectedCall::~MockCheckedExpectedCall()
MockExpectedCall& MockCheckedExpectedCall::withName(const SimpleString& name)
{
setName(name);
- callOrder_ = NOT_CALLED_YET;
return *this;
}
@@ -216,25 +218,18 @@ MockNamedValue MockCheckedExpectedCall::getOutputParameter(const SimpleString& n
return (p) ? *p : MockNamedValue("");
}
-bool MockCheckedExpectedCall::areParametersFulfilled()
+bool MockCheckedExpectedCall::areParametersMatchingActualCall()
{
MockNamedValueListNode* p;
for (p = inputParameters_->begin(); p; p = p->next())
- if (! item(p)->isFulfilled())
+ if (! item(p)->isMatchingActualCall())
return false;
for (p = outputParameters_->begin(); p; p = p->next())
- if (! item(p)->isFulfilled())
+ if (! item(p)->isMatchingActualCall())
return false;
return true;
}
-bool MockCheckedExpectedCall::areIgnoredParametersFulfilled()
-{
- if (ignoreOtherParameters_)
- return parametersWereIgnored_;
- return true;
-}
-
MockExpectedCall& MockCheckedExpectedCall::ignoreOtherParameters()
{
ignoreOtherParameters_ = true;
@@ -243,29 +238,39 @@ MockExpectedCall& MockCheckedExpectedCall::ignoreOtherParameters()
bool MockCheckedExpectedCall::isFulfilled()
{
- return isFulfilledWithoutIgnoredParameters() && areIgnoredParametersFulfilled();
+ return (actualCalls_ >= minCalls_) && (actualCalls_ <= maxCalls_);
+}
+
+bool MockCheckedExpectedCall::canMatchActualCalls()
+{
+ return (actualCalls_ < maxCalls_);
}
-bool MockCheckedExpectedCall::isFulfilledWithoutIgnoredParameters()
+bool MockCheckedExpectedCall::isMatchingActualCallAndFinalized()
{
- return callOrder_ != NOT_CALLED_YET && areParametersFulfilled() && wasPassedToObject_;
+ return isMatchingActualCall() && (!ignoreOtherParameters_ || isActualCallMatchFinalized_);
}
+bool MockCheckedExpectedCall::isMatchingActualCall()
+{
+ return areParametersMatchingActualCall() && wasPassedToObject_;
+}
-void MockCheckedExpectedCall::callWasMade(int callOrder)
+void MockCheckedExpectedCall::callWasMade(unsigned int callOrder)
{
- callOrder_ = callOrder;
- if (expectedCallOrder_ == NO_EXPECTED_CALL_ORDER)
- outOfOrder_ = false;
- else if (callOrder_ == expectedCallOrder_)
- outOfOrder_ = false;
- else
+ actualCalls_++;
+
+ if ( (initialExpectedCallOrder_ != NO_EXPECTED_CALL_ORDER) &&
+ ((callOrder < initialExpectedCallOrder_) || (callOrder > finalExpectedCallOrder_)) ) {
outOfOrder_ = true;
+ }
+
+ resetActualCallMatchingState();
}
-void MockCheckedExpectedCall::parametersWereIgnored()
+void MockCheckedExpectedCall::finalizeActualCallMatch()
{
- parametersWereIgnored_ = true;
+ isActualCallMatchFinalized_ = true;
}
@@ -274,23 +279,24 @@ void MockCheckedExpectedCall::wasPassedToObject()
wasPassedToObject_ = true;
}
-void MockCheckedExpectedCall::resetExpectation()
+void MockCheckedExpectedCall::resetActualCallMatchingState()
{
- callOrder_ = NOT_CALLED_YET;
wasPassedToObject_ = (objectPtr_ == NULL);
+ isActualCallMatchFinalized_ = false;
+
MockNamedValueListNode* p;
for (p = inputParameters_->begin(); p; p = p->next())
- item(p)->setFulfilled(false);
+ item(p)->setMatchesActualCall(false);
for (p = outputParameters_->begin(); p; p = p->next())
- item(p)->setFulfilled(false);
+ item(p)->setMatchesActualCall(false);
}
void MockCheckedExpectedCall::inputParameterWasPassed(const SimpleString& name)
{
for (MockNamedValueListNode* p = inputParameters_->begin(); p; p = p->next()) {
if (p->getName() == name)
- item(p)->setFulfilled(true);
+ item(p)->setMatchesActualCall(true);
}
}
@@ -298,11 +304,11 @@ void MockCheckedExpectedCall::outputParameterWasPassed(const SimpleString& name)
{
for (MockNamedValueListNode* p = outputParameters_->begin(); p; p = p->next()) {
if (p->getName() == name)
- item(p)->setFulfilled(true);
+ item(p)->setMatchesActualCall(true);
}
}
-SimpleString MockCheckedExpectedCall::getInputParameterValueString(const SimpleString& name)
+SimpleString MockCheckedExpectedCall::getInputParameterValueString(const SimpleString& name) const
{
MockNamedValue * p = inputParameters_->getValueByName(name);
return (p) ? StringFrom(*p) : "failed";
@@ -320,7 +326,7 @@ bool MockCheckedExpectedCall::hasOutputParameter(const MockNamedValue& parameter
return (p) ? p->compatibleForCopying(parameter) : ignoreOtherParameters_;
}
-SimpleString MockCheckedExpectedCall::callToString()
+SimpleString MockCheckedExpectedCall::callToString(bool asActualCall) const
{
SimpleString str;
if (objectPtr_)
@@ -328,34 +334,61 @@ SimpleString MockCheckedExpectedCall::callToString()
str += getName();
str += " -> ";
- if (expectedCallOrder_ != NO_EXPECTED_CALL_ORDER) {
- str += StringFromFormat("expected call order: <%d> -> ", expectedCallOrder_);
+
+ if (initialExpectedCallOrder_ != NO_EXPECTED_CALL_ORDER) {
+ if (initialExpectedCallOrder_ == finalExpectedCallOrder_) {
+ str += StringFromFormat("expected call order: <%u> -> ", initialExpectedCallOrder_);
+ } else {
+ str += StringFromFormat("expected calls order: <%u..%u> -> ", initialExpectedCallOrder_, finalExpectedCallOrder_);
+ }
}
if (inputParameters_->begin() == NULL && outputParameters_->begin() == NULL) {
str += (ignoreOtherParameters_) ? "all parameters ignored" : "no parameters";
- return str;
}
+ else
+ {
+ MockNamedValueListNode* p;
- MockNamedValueListNode* p;
+ for (p = inputParameters_->begin(); p; p = p->next()) {
+ str += StringFromFormat("%s %s: <%s>", p->getType().asCharString(), p->getName().asCharString(), getInputParameterValueString(p->getName()).asCharString());
+ if (p->next()) str += ", ";
+ }
- for (p = inputParameters_->begin(); p; p = p->next()) {
- str += StringFromFormat("%s %s: <%s>", p->getType().asCharString(), p->getName().asCharString(), getInputParameterValueString(p->getName()).asCharString());
- if (p->next()) str += ", ";
- }
+ if (inputParameters_->begin() && outputParameters_->begin())
+ {
+ str += ", ";
+ }
- if (inputParameters_->begin() && outputParameters_->begin())
- {
- str += ", ";
+ for (p = outputParameters_->begin(); p; p = p->next()) {
+ str += StringFromFormat("%s %s:
+
+
+
+
+
+
+
+
diff --git a/tests/AllTests.vcxproj b/tests/AllTests.vcxproj
index d48f39e46..2ed38d2c3 100644
--- a/tests/AllTests.vcxproj
+++ b/tests/AllTests.vcxproj
@@ -140,6 +140,7 @@
+
diff --git a/tests/CppUTestExt/ActualCallsQueueTest.cpp b/tests/CppUTestExt/ActualCallsQueueTest.cpp
new file mode 100644
index 000000000..e7ac6a9aa
--- /dev/null
+++ b/tests/CppUTestExt/ActualCallsQueueTest.cpp
@@ -0,0 +1,363 @@
+/*
+ * Copyright (c) 2016, Jesus Gonzalez
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "CppUTest/TestHarness.h"
+#include "CppUTestExt/MockActualCallsQueue.h"
+#include "CppUTestExt/MockCheckedActualCall.h"
+#include "CppUTestExt/MockFailure.h"
+#include "MockFailureReporterForTest.h"
+
+TEST_GROUP(MockActualCallsQueue)
+{
+ MockSupport testMock;
+
+ void teardown()
+ {
+ CHECK_NO_MOCK_FAILURE();
+ testMock.clear();
+ }
+};
+
+TEST(MockActualCallsQueue, emptyQueue)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+ CHECK_TRUE(actualCalls->isEmpty());
+ LONGS_EQUAL(0, actualCalls->size());
+ LONGS_EQUAL((unsigned int)-1, actualCalls->getMaxSize());
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, pushBack_Owner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+
+ actualCalls->pushBack(call1);
+ CHECK_FALSE(actualCalls->isEmpty());
+ LONGS_EQUAL(1, actualCalls->size());
+
+ actualCalls->pushBack(call2);
+ LONGS_EQUAL(2, actualCalls->size());
+
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, pushBack_NotOwner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(false);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+
+ actualCalls->pushBack(call1);
+ CHECK_FALSE(actualCalls->isEmpty());
+ LONGS_EQUAL(1, actualCalls->size());
+
+ actualCalls->pushBack(call2);
+ LONGS_EQUAL(2, actualCalls->size());
+
+ delete actualCalls;
+ delete call1;
+ delete call2;
+}
+
+TEST(MockActualCallsQueue, pushBack_MaxSizeReached_Owner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true, 2);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ MockCheckedActualCall* call3 = new MockCheckedActualCall(3, NULL, testMock);
+
+ actualCalls->pushBack(call1);
+ CHECK_FALSE(actualCalls->isEmpty());
+ LONGS_EQUAL(1, actualCalls->size());
+
+ actualCalls->pushBack(call2);
+ LONGS_EQUAL(2, actualCalls->size());
+
+ actualCalls->pushBack(call3);
+ LONGS_EQUAL(2, actualCalls->size());
+
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, pushBack_MaxSizeReached_NotOwner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(false, 2);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ MockCheckedActualCall* call3 = new MockCheckedActualCall(3, NULL, testMock);
+
+ actualCalls->pushBack(call1);
+ CHECK_FALSE(actualCalls->isEmpty());
+ LONGS_EQUAL(1, actualCalls->size());
+
+ actualCalls->pushBack(call2);
+ LONGS_EQUAL(2, actualCalls->size());
+
+ delete actualCalls;
+ delete call1;
+ delete call2;
+ delete call3;
+}
+
+TEST(MockActualCallsQueue, clear_Owner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ actualCalls->pushBack(call1);
+ actualCalls->pushBack(call2);
+
+ actualCalls->clear();
+ CHECK_TRUE(actualCalls->isEmpty());
+ LONGS_EQUAL(0, actualCalls->size());
+
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, clear_NotOwner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(false);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ actualCalls->pushBack(call1);
+ actualCalls->pushBack(call2);
+
+ actualCalls->clear();
+ CHECK_TRUE(actualCalls->isEmpty());
+ LONGS_EQUAL(0, actualCalls->size());
+
+ delete actualCalls;
+ delete call1;
+ delete call2;
+}
+
+TEST(MockActualCallsQueue, popFront_Owner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ actualCalls->pushBack(call1);
+ actualCalls->pushBack(call2);
+
+ MockCheckedActualCall* returnedCall = actualCalls->popFront();
+ LONGS_EQUAL(1, actualCalls->size());
+ POINTERS_EQUAL(call1, returnedCall);
+
+ delete actualCalls;
+ delete call1;
+}
+
+TEST(MockActualCallsQueue, popFront_NotOwner)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(false);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ actualCalls->pushBack(call1);
+ actualCalls->pushBack(call2);
+
+ MockCheckedActualCall* returnedCall = actualCalls->popFront();
+ LONGS_EQUAL(1, actualCalls->size());
+ POINTERS_EQUAL(call1, returnedCall);
+
+ returnedCall = actualCalls->popFront();
+ LONGS_EQUAL(0, actualCalls->size());
+ CHECK_TRUE(actualCalls->isEmpty());
+ POINTERS_EQUAL(call2, returnedCall);
+
+ delete actualCalls;
+ delete call1;
+ delete call2;
+}
+
+TEST(MockActualCallsQueue, popFront_OnEmptyList)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(false);
+
+ MockCheckedActualCall* returnedCall = actualCalls->popFront();
+ LONGS_EQUAL(0, actualCalls->size());
+ CHECK_TRUE(actualCalls->isEmpty());
+ POINTERS_EQUAL(NULL, returnedCall);
+
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, pushBackAll_Empty)
+{
+ MockActualCallsQueue* actualCalls1 = new MockActualCallsQueue(false);
+ MockActualCallsQueue* actualCalls2 = new MockActualCallsQueue(false);
+
+ actualCalls2->pushBackAll(actualCalls1);
+ CHECK_TRUE(actualCalls2->isEmpty());
+ LONGS_EQUAL(0, actualCalls2->size());
+
+ delete actualCalls1;
+ delete actualCalls2;
+}
+
+TEST(MockActualCallsQueue, pushBackAll_NotEmpty_FromNotOwner)
+{
+ MockActualCallsQueue* actualCalls1 = new MockActualCallsQueue(false);
+ MockActualCallsQueue* actualCalls2 = new MockActualCallsQueue(false);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ actualCalls1->pushBack(call1);
+ actualCalls1->pushBack(call2);
+
+ actualCalls2->pushBackAll(*actualCalls1);
+ CHECK_FALSE(actualCalls2->isEmpty());
+ LONGS_EQUAL(2, actualCalls2->size());
+
+ delete actualCalls1;
+ delete actualCalls2;
+ delete call1;
+ delete call2;
+}
+
+TEST(MockActualCallsQueue, pushBackAll_NotEmpty_FromOwner)
+{
+ MockActualCallsQueue* actualCalls1 = new MockActualCallsQueue(true);
+ MockActualCallsQueue* actualCalls2 = new MockActualCallsQueue(false);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ actualCalls1->pushBack(call1);
+ actualCalls1->pushBack(call2);
+
+ actualCalls2->pushBackAll(*actualCalls1);
+ CHECK_FALSE(actualCalls2->isEmpty());
+ LONGS_EQUAL(2, actualCalls2->size());
+
+ delete actualCalls2;
+ delete actualCalls1;
+}
+
+TEST(MockActualCallsQueue, setMaxSize_GreaterThanCurrent)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(false, 2);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ actualCalls->pushBack(call1);
+ actualCalls->pushBack(call2);
+
+ LONGS_EQUAL(2, actualCalls->size());
+ actualCalls->setMaxSize(5);
+ LONGS_EQUAL(2, actualCalls->size());
+
+ delete actualCalls;
+ delete call1;
+ delete call2;
+}
+
+TEST(MockActualCallsQueue, setMaxSize_LowerThanCurrent)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(false);
+ MockCheckedActualCall* call1 = new MockCheckedActualCall(1, NULL, testMock);
+ MockCheckedActualCall* call2 = new MockCheckedActualCall(2, NULL, testMock);
+ MockCheckedActualCall* call3 = new MockCheckedActualCall(3, NULL, testMock);
+ actualCalls->pushBack(call1);
+ actualCalls->pushBack(call2);
+ actualCalls->pushBack(call3);
+
+ LONGS_EQUAL(3, actualCalls->size());
+ actualCalls->setMaxSize(2);
+ LONGS_EQUAL(2, actualCalls->size());
+
+ MockCheckedActualCall* returnedCall = actualCalls->popFront();
+ LONGS_EQUAL(1, actualCalls->size());
+ POINTERS_EQUAL(call2, returnedCall);
+
+ delete actualCalls;
+ delete call1;
+ delete call2;
+ delete call3;
+}
+
+TEST(MockActualCallsQueue, callToString_Empty)
+{
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+
+ STRCMP_EQUAL("###", actualCalls->toString("###").asCharString());
+
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, callToString_NotEmpty)
+{
+ MockCheckedExpectedCall expectedCall1(1, 1);
+ expectedCall1.withName("foo");
+ MockCheckedExpectedCall expectedCall2(1, 1);
+ expectedCall2.withName("bar");
+
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+ MockCheckedActualCall* actualCall1 = new MockCheckedActualCallForTest(1, "", &expectedCall1);
+ MockCheckedActualCall* actualCall2 = new MockCheckedActualCallForTest(2, "", &expectedCall2);
+ actualCalls->pushBack(actualCall1);
+ actualCalls->pushBack(actualCall2);
+
+ SimpleString expectedString = StringFromFormat("$\t%s\n$\t%s", actualCall1->toString().asCharString(), actualCall2->toString().asCharString());
+ STRCMP_EQUAL(expectedString.asCharString(), actualCalls->toString("$\t").asCharString());
+
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, toStringFilterByFunction_NoMatches)
+{
+ MockCheckedExpectedCall expectedCall1(1, 1);
+ expectedCall1.withName("foo");
+ MockCheckedExpectedCall expectedCall2(1, 1);
+ expectedCall2.withName("bar");
+
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+ MockCheckedActualCall* actualCall1 = new MockCheckedActualCallForTest(1, "", &expectedCall1);
+ MockCheckedActualCall* actualCall2 = new MockCheckedActualCallForTest(2, "", &expectedCall2);
+ actualCalls->pushBack(actualCall1);
+ actualCalls->pushBack(actualCall2);
+
+ STRCMP_EQUAL("[@]", actualCalls->toStringFilterByFunction("foobar", "[@]").asCharString());
+
+ delete actualCalls;
+}
+
+TEST(MockActualCallsQueue, toStringFilterByFunction_WithMatches)
+{
+ MockCheckedExpectedCall expectedCall1(1, 1);
+ expectedCall1.withName("foo");
+ MockCheckedExpectedCall expectedCall2(1, 1);
+ expectedCall2.withName("bar");
+
+ MockActualCallsQueue* actualCalls = new MockActualCallsQueue(true);
+ MockCheckedActualCall* actualCall1 = new MockCheckedActualCallForTest(1, "", &expectedCall1);
+ MockCheckedActualCall* actualCall2 = new MockCheckedActualCallForTest(2, "", &expectedCall2);
+ actualCalls->pushBack(actualCall1);
+ actualCalls->pushBack(actualCall2);
+
+ SimpleString expectedString = StringFromFormat("\t~ %s", actualCall1->toString().asCharString());
+ STRCMP_EQUAL(expectedString.asCharString(), actualCalls->toStringFilterByFunction("foo", "\t~ ").asCharString());
+
+ delete actualCalls;
+}
diff --git a/tests/CppUTestExt/CMakeLists.txt b/tests/CppUTestExt/CMakeLists.txt
index 8039a3b52..63dae8f6c 100644
--- a/tests/CppUTestExt/CMakeLists.txt
+++ b/tests/CppUTestExt/CMakeLists.txt
@@ -14,6 +14,7 @@ set(CppUTestExtTests_src
MockComparatorCopierTest.cpp
MockExpectedCallTest.cpp
ExpectedFunctionsListTest.cpp
+ ActualCallsQueueTest.cpp
MockFailureReporterForTest.cpp
MockFailureTest.cpp
MockHierarchyTest.cpp
diff --git a/tests/CppUTestExt/ExpectedFunctionsListTest.cpp b/tests/CppUTestExt/ExpectedFunctionsListTest.cpp
index da0ec90aa..89382cac9 100644
--- a/tests/CppUTestExt/ExpectedFunctionsListTest.cpp
+++ b/tests/CppUTestExt/ExpectedFunctionsListTest.cpp
@@ -41,10 +41,10 @@ TEST_GROUP(MockExpectedCallsList)
void setup()
{
list = new MockExpectedCallsList;
- call1 = new MockCheckedExpectedCall;
- call2 = new MockCheckedExpectedCall;
- call3 = new MockCheckedExpectedCall;
- call4 = new MockCheckedExpectedCall;
+ call1 = new MockCheckedExpectedCall(1, 1);
+ call2 = new MockCheckedExpectedCall(1, 1);
+ call3 = new MockCheckedExpectedCall(1, 1);
+ call4 = new MockCheckedExpectedCall(1, 1);
call1->withName("foo");
call2->withName("bar");
call3->withName("boo");
@@ -63,7 +63,7 @@ TEST_GROUP(MockExpectedCallsList)
TEST(MockExpectedCallsList, emptyList)
{
CHECK(! list->hasUnfulfilledExpectations());
- CHECK(list->size() == list->amountOfUnfulfilledExpectations());
+ CHECK(! list->hasFinalizedMatchingExpectations());
LONGS_EQUAL(0, list->size());
}
@@ -74,7 +74,7 @@ TEST(MockExpectedCallsList, addingCalls)
LONGS_EQUAL(2, list->size());
}
-TEST(MockExpectedCallsList, listWithFulfilledExpectationHasNoUnfillfilledOnes)
+TEST(MockExpectedCallsList, listWithFulfilledExpectationHasNoUnfulfilledOnes)
{
call1->callWasMade(1);
call2->callWasMade(2);
@@ -85,8 +85,8 @@ TEST(MockExpectedCallsList, listWithFulfilledExpectationHasNoUnfillfilledOnes)
TEST(MockExpectedCallsList, listWithFulfilledExpectationButOutOfOrder)
{
- call1->withCallOrder(1);
- call2->withCallOrder(2);
+ call1->withCallOrder(1, 1);
+ call2->withCallOrder(2, 2);
list->addExpectedCall(call1);
list->addExpectedCall(call2);
call2->callWasMade(1);
@@ -107,22 +107,20 @@ TEST(MockExpectedCallsList, listWithUnFulfilledExpectationHasNoUnfillfilledOnes)
TEST(MockExpectedCallsList, deleteAllExpectationsAndClearList)
{
- list->addExpectedCall(new MockCheckedExpectedCall);
- list->addExpectedCall(new MockCheckedExpectedCall);
+ list->addExpectedCall(new MockCheckedExpectedCall(1, 1));
+ list->addExpectedCall(new MockCheckedExpectedCall(1, 1));
list->deleteAllExpectationsAndClearList();
}
-TEST(MockExpectedCallsList, onlyKeepUnfulfilledExpectations)
+TEST(MockExpectedCallsList, onlyKeepUnmatchingExpectations)
{
call1->withName("relate");
call2->withName("unrelate");
- call3->withName("relate");
- call2->callWasMade(1);
- call3->callWasMade(2);
+ call3->withName("relate").withParameter("param",1);
list->addExpectedCall(call1);
list->addExpectedCall(call2);
list->addExpectedCall(call3);
- list->onlyKeepUnfulfilledExpectations();
+ list->onlyKeepUnmatchingExpectations();
LONGS_EQUAL(1, list->size());
}
@@ -200,38 +198,43 @@ TEST(MockExpectedCallsList, onlyKeepExpectationsWithInputParameter)
LONGS_EQUAL(2, list->size());
}
-TEST(MockExpectedCallsList, addUnfilfilledExpectationsWithEmptyList)
+TEST(MockExpectedCallsList, addPotentiallyMatchingExpectationsWithEmptyList)
{
MockExpectedCallsList newList;
- newList.addUnfulfilledExpectations(*list);
+ newList.addPotentiallyMatchingExpectations(*list);
LONGS_EQUAL(0, newList.size());
}
-TEST(MockExpectedCallsList, addUnfilfilledExpectationsMultipleUnfulfilledExpectations)
+TEST(MockExpectedCallsList, addPotentiallyMatchingExpectationsMultipleUnmatchedExpectations)
{
call2->callWasMade(1);
list->addExpectedCall(call1);
list->addExpectedCall(call2);
list->addExpectedCall(call3);
MockExpectedCallsList newList;
- newList.addUnfulfilledExpectations(*list);
+ newList.addPotentiallyMatchingExpectations(*list);
LONGS_EQUAL(2, newList.size());
}
-TEST(MockExpectedCallsList, amountOfExpectationsFor)
+TEST(MockExpectedCallsList, amountOfActualCallsFulfilledFor)
{
call1->withName("foo");
call2->withName("bar");
+ call1->callWasMade(1);
+ call2->callWasMade(2);
list->addExpectedCall(call1);
list->addExpectedCall(call2);
- LONGS_EQUAL(1, list->amountOfExpectationsFor("bar"));
+ LONGS_EQUAL(1, list->amountOfActualCallsFulfilledFor("bar"));
}
-TEST(MockExpectedCallsList, amountOfExpectationsForHasNone)
+TEST(MockExpectedCallsList, amountOfActualCallsFulfilledForHasNone)
{
call1->withName("foo");
+ call2->withName("bar");
+ call1->callWasMade(1);
list->addExpectedCall(call1);
- LONGS_EQUAL(0, list->amountOfExpectationsFor("bar"));
+ list->addExpectedCall(call2);
+ LONGS_EQUAL(0, list->amountOfActualCallsFulfilledFor("bar"));
}
TEST(MockExpectedCallsList, callToStringForUnfulfilledFunctions)
@@ -246,7 +249,7 @@ TEST(MockExpectedCallsList, callToStringForUnfulfilledFunctions)
list->addExpectedCall(call3);
SimpleString expectedString;
- expectedString = StringFromFormat("%s\n%s", call1->callToString().asCharString(), call2->callToString().asCharString());
+ expectedString = StringFromFormat("%s\n%s", call1->callToString(false).asCharString(), call2->callToString(false).asCharString());
STRCMP_EQUAL(expectedString.asCharString(), list->unfulfilledCallsToString().asCharString());
}
@@ -262,21 +265,31 @@ TEST(MockExpectedCallsList, callToStringForFulfilledFunctions)
list->addExpectedCall(call2);
SimpleString expectedString;
- expectedString = StringFromFormat("%s\n%s", call2->callToString().asCharString(), call1->callToString().asCharString());
+ expectedString = StringFromFormat("%s\n%s", call1->callToString(false).asCharString(), call2->callToString(false).asCharString());
STRCMP_EQUAL(expectedString.asCharString(), list->fulfilledCallsToString().asCharString());
}
-TEST(MockExpectedCallsList, removeOneFulfilledExpectationFromEmptyList)
+TEST(MockExpectedCallsList, removeOneFinalizedMatchingExpectationFromEmptyList)
{
- POINTERS_EQUAL(NULL, list->removeOneFulfilledExpectation());
+ POINTERS_EQUAL(NULL, list->removeFirstFinalizedMatchingExpectation());
}
-TEST(MockExpectedCallsList, getOneFulfilledExpectationWithIgnoredParametersFromEmptyList)
+TEST(MockExpectedCallsList, getOneMatchingExpectationFromEmptyList)
{
- POINTERS_EQUAL(NULL, list->getOneFulfilledExpectationWithIgnoredParameters());
+ POINTERS_EQUAL(NULL, list->getFirstMatchingExpectation());
}
TEST(MockExpectedCallsList, toStringOnEmptyList)
{
STRCMP_EQUAL("", list->unfulfilledCallsToString().asCharString());
}
+
+TEST(MockExpectedCallsList, hasFinalizedMatchingExpectations)
+{
+ call1->ignoreOtherParameters();
+ list->addExpectedCall(call1);
+ CHECK(! list->hasFinalizedMatchingExpectations());
+
+ call1->finalizeActualCallMatch();
+ CHECK(list->hasFinalizedMatchingExpectations());
+}
diff --git a/tests/CppUTestExt/MockActualCallTest.cpp b/tests/CppUTestExt/MockActualCallTest.cpp
index b60c099a3..783ee1c01 100644
--- a/tests/CppUTestExt/MockActualCallTest.cpp
+++ b/tests/CppUTestExt/MockActualCallTest.cpp
@@ -34,108 +34,154 @@
TEST_GROUP(MockCheckedActualCall)
{
- MockExpectedCallsList* emptyList;
- MockExpectedCallsList* list;
MockFailureReporter* reporter;
+ MockSupport* testMock;
void setup()
{
- emptyList = new MockExpectedCallsList;
- list = new MockExpectedCallsList;
+ testMock = new MockSupport();
reporter = MockFailureReporterForTest::getReporter();
}
void teardown()
{
CHECK_NO_MOCK_FAILURE();
- delete emptyList;
- delete list;
+ testMock->clear();
+ delete testMock;
}
};
TEST(MockCheckedActualCall, unExpectedCall)
{
- MockCheckedActualCall actualCall(1, reporter, *emptyList);
+ MockCheckedActualCall actualCall(1, reporter, *testMock);
actualCall.withName("unexpected");
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "unexpected", *list);
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "unexpected", testMock->getExpectedCalls(), testMock->getActualCalls());
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
-TEST(MockCheckedActualCall, unExpectedCallWithAParameter)
+TEST(MockCheckedActualCall, unExpectedCallWithAnInputParameter)
{
- MockCheckedActualCall actualCall(1, reporter, *emptyList);
+ MockCheckedActualCall actualCall(1, reporter, *testMock);
actualCall.withName("unexpected").withParameter("bar", 0);
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "unexpected", *list);
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "unexpected", testMock->getExpectedCalls(), testMock->getActualCalls());
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+
+ CHECK(actualCall.hasFailed()); // Checks that withParameter() doesn't "reset" call state
}
TEST(MockCheckedActualCall, unExpectedCallWithAnOutputParameter)
{
- MockCheckedActualCall actualCall(1, reporter, *emptyList);
+ MockCheckedActualCall actualCall(1, reporter, *testMock);
actualCall.withName("unexpected").withOutputParameter("bar", (void*)0);
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "unexpected", *list);
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "unexpected", testMock->getExpectedCalls(), testMock->getActualCalls());
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+
+ CHECK(actualCall.hasFailed()); // Checks that withOutputParameter() doesn't "reset" call state
+}
+
+TEST(MockCheckedActualCall, unExpectedCallOnObject)
+{
+ int object;
+
+ MockCheckedActualCall actualCall(1, reporter, *testMock);
+ actualCall.withName("unexpected").onObject(&object);
+
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "unexpected", testMock->getExpectedCalls(), testMock->getActualCalls());
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+
+ CHECK(actualCall.hasFailed()); // Checks that onObject() doesn't "reset" call state
}
TEST(MockCheckedActualCall, actualCallWithNoReturnValueAndMeaninglessCallOrderForCoverage)
{
- MockCheckedActualCall actualCall(1, reporter, *emptyList);
- actualCall.withName("noreturn").withCallOrder(0).returnValue();
+ MockCheckedActualCall actualCall(1, reporter, *testMock);
+ actualCall.withName("noreturn").returnValue();
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "noreturn", *list);
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "noreturn", testMock->getExpectedCalls(), testMock->getActualCalls());
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
TEST(MockCheckedActualCall, unExpectedParameterName)
{
- MockCheckedExpectedCall call1;
- call1.withName("func");
- list->addExpectedCall(&call1);
+ testMock->expectOneCall("func");
- MockCheckedActualCall actualCall(1, reporter, *list);
+ MockCheckedActualCall actualCall(1, reporter, *testMock);
actualCall.withName("func").withParameter("integer", 1);
MockNamedValue parameter("integer");
parameter.setValue(1);
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "func", parameter, *list);
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "func", parameter, testMock->getExpectedCalls(), testMock->getActualCalls());
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
TEST(MockCheckedActualCall, multipleSameFunctionsExpectingAndHappenGradually)
{
- MockCheckedExpectedCall* call1 = new MockCheckedExpectedCall();
- MockCheckedExpectedCall* call2 = new MockCheckedExpectedCall();
- call1->withName("func");
- call2->withName("func");
- list->addExpectedCall(call1);
- list->addExpectedCall(call2);
+ testMock->expectOneCall("func");
+ testMock->expectOneCall("func");
- LONGS_EQUAL(2, list->amountOfUnfulfilledExpectations());
+ LONGS_EQUAL(2, testMock->getExpectedCalls().amountOfUnfulfilledExpectations());
- MockCheckedActualCall actualCall1(1, reporter, *list);
+ MockCheckedActualCall actualCall1(1, reporter, *testMock);
actualCall1.withName("func");
actualCall1.checkExpectations();
- LONGS_EQUAL(1, list->amountOfUnfulfilledExpectations());
+ LONGS_EQUAL(1, testMock->getExpectedCalls().amountOfUnfulfilledExpectations());
- MockCheckedActualCall actualCall2(2, reporter, *list);
+ MockCheckedActualCall actualCall2(2, reporter, *testMock);
actualCall2.withName("func");
actualCall2.checkExpectations();
- LONGS_EQUAL(0, list->amountOfUnfulfilledExpectations());
+ LONGS_EQUAL(0, testMock->getExpectedCalls().amountOfUnfulfilledExpectations());
+}
+
+TEST(MockCheckedActualCall, toString_NotMatchingExpectedCall)
+{
+ mock().expectOneCall("foo").withParameter("bar", 1);
- list->deleteAllExpectationsAndClearList();
+ MockCheckedActualCall actualCall(10, reporter, mock());
+ actualCall.withName("foo");
+
+ STRCMP_EQUAL("(10) foo (NOT matching any expected call)", actualCall.toString().asCharString());
+
+ mock().clear();
+}
+
+TEST(MockCheckedActualCall, toString_NoScope)
+{
+ void* object = (void*) 0xAA;
+ MockCheckedExpectedCall& expectedCall = (MockCheckedExpectedCall&) mock().expectOneCall("foo");
+ expectedCall.onObject(object).withParameter("bar", 5);
+
+ MockCheckedActualCall actualCall(99, reporter, mock());
+ actualCall.withName("foo").onObject(object).withParameter("bar", 5);
+
+ SimpleString expectedString = StringFromFormat("(99) %s", expectedCall.callToString(true).asCharString());
+ STRCMP_EQUAL(expectedString.asCharString(), actualCall.toString().asCharString());
+
+ mock().clear();
+}
+
+TEST(MockCheckedActualCall, toString_WithScope)
+{
+ MockCheckedExpectedCall& expectedCall = (MockCheckedExpectedCall&) mock("bar").expectOneCall("foo");
+
+ MockCheckedActualCall actualCall(7765, reporter, mock("bar"));
+ actualCall.withName("bar::foo");
+
+ SimpleString expectedString = StringFromFormat("(bar::7765) %s", expectedCall.callToString(true).asCharString());
+ STRCMP_EQUAL(expectedString.asCharString(), actualCall.toString().asCharString());
+
+ mock().clear();
}
TEST(MockCheckedActualCall, MockIgnoredActualCallWorksAsItShould)
{
MockIgnoredActualCall actual;
actual.withName("func");
- actual.withCallOrder(1);
CHECK(false == actual.returnBoolValue());
CHECK(false == actual.returnBoolValueOrDefault(true));
@@ -168,8 +214,8 @@ TEST(MockCheckedActualCall, remainderOfMockActualCallTraceWorksAsItShould)
const unsigned char mem_buffer[] = { 0xFE, 0x15 };
void (*function_value)() = (void (*)())0xDEAD;
MockActualCallTrace actual;
- actual.withName("func");
actual.withCallOrder(1);
+ actual.withName("func");
actual.onObject(&value);
actual.withBoolParameter("bool", true);
@@ -182,8 +228,7 @@ TEST(MockCheckedActualCall, remainderOfMockActualCallTraceWorksAsItShould)
actual.withMemoryBufferParameter("mem_buffer", mem_buffer, sizeof(mem_buffer));
actual.withParameterOfType("int", "named_type", &const_value);
- SimpleString expectedString("\nFunction name:func");
- expectedString += " withCallOrder:1";
+ SimpleString expectedString("\n1 > Function name:func");
expectedString += " onObject:0x";
expectedString += HexStringFrom(&value);
expectedString += " bool:true";
diff --git a/tests/CppUTestExt/MockCallTest.cpp b/tests/CppUTestExt/MockCallTest.cpp
index 44f3f7829..3b583ed4b 100644
--- a/tests/CppUTestExt/MockCallTest.cpp
+++ b/tests/CppUTestExt/MockCallTest.cpp
@@ -49,27 +49,47 @@ TEST(MockCallTest, checkExpectationsDoesntFail)
mock().checkExpectations();
}
-TEST(MockCallTest, exceptACallThatHappens)
+TEST(MockCallTest, expectASingleCallThatHappens)
{
mock().expectOneCall("func");
- mock().actualCall("func");
+ MockCheckedActualCall& actualCall = (MockCheckedActualCall&) mock().actualCall("func");
+ actualCall.checkExpectations();
CHECK(! mock().expectedCallsLeft());
}
-TEST(MockCallTest, exceptACallInceasesExpectedCallsLeft)
+TEST(MockCallTest, expectASingleCallThatDoesntHappen)
{
mock().expectOneCall("func");
CHECK(mock().expectedCallsLeft());
mock().clear();
}
+TEST(MockCallTest, expectAMultiCallThatHappensTheMinimumTimes)
+{
+ mock().expectRangeOfCalls(2, 4, "func");
+ mock().actualCall("func");
+ MockCheckedActualCall& actualCall = (MockCheckedActualCall&) mock().actualCall("func");
+ actualCall.checkExpectations();
+ CHECK(! mock().expectedCallsLeft());
+}
+
+TEST(MockCallTest, expectAMultiCallThatDoesntHappenTheMinimumTimes)
+{
+ mock().expectRangeOfCalls(2, 4, "func");
+ MockCheckedActualCall& actualCall = (MockCheckedActualCall&) mock().actualCall("func");
+ actualCall.checkExpectations();
+ CHECK(mock().expectedCallsLeft());
+ mock().clear();
+}
+
TEST(MockCallTest, checkExpectationsClearsTheExpectations)
{
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest expectations;
expectations.addFunction("foobar");
- MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectations, actualCalls);
mock().expectOneCall("foobar");
mock().checkExpectations();
@@ -85,7 +105,8 @@ TEST(MockCallTest, expectOneCallInScopeButNotHappen)
MockExpectedCallsListForTest expectations;
expectations.addFunction("scope::foobar");
- MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectations, actualCalls);
mock("scope").expectOneCall("foobar");
mock().checkExpectations();
@@ -99,7 +120,8 @@ TEST(MockCallTest, unexpectedCallHappened)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest emptyExpectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "func", emptyExpectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "func", emptyExpectations, actualCalls);
mock().actualCall("func");
@@ -111,7 +133,8 @@ TEST(MockCallTest, unexpectedScopeCallHappened)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest emptyExpectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "scope::func", emptyExpectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "scope::func", emptyExpectations, actualCalls);
mock("scope").actualCall("func");
@@ -123,7 +146,8 @@ TEST(MockCallTest, expectOneCallInOneScopeButActualCallInAnotherScope)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest emptyExpectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "class::foo", emptyExpectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "class::foo", emptyExpectations, actualCalls);
mock("scope").expectOneCall("foo");
mock("class").actualCall("foo");
@@ -137,7 +161,8 @@ TEST(MockCallTest, expectOneCallInScopeButActualCallInGlobal)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest emptyExpectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", emptyExpectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", emptyExpectations, actualCalls);
mock("scope").expectOneCall("foo");
mock().actualCall("foo");
@@ -147,7 +172,7 @@ TEST(MockCallTest, expectOneCallInScopeButActualCallInGlobal)
}
-TEST(MockCallTest, expectMultipleCallsThatHappen)
+TEST(MockCallTest, expectMultipleSingleCallsThatHappen)
{
mock().expectOneCall("foo");
mock().expectOneCall("foo");
@@ -160,10 +185,15 @@ TEST(MockCallTest, expectOneCallHoweverMultipleHappened)
{
MockFailureReporterInstaller failureReporterInstaller;
- MockExpectedCallsListForTest expectations;
- expectations.addFunction("foo")->callWasMade(1);
- expectations.addFunction("foo")->callWasMade(2);
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", expectations);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+ actualCalls.addCall(2, expectedCall2);
+
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", expectedCalls, actualCalls);
mock().expectOneCall("foo");
mock().expectOneCall("foo");
@@ -179,7 +209,9 @@ TEST(MockCallTest, expectNoCallThatHappened)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest expectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations);
+ expectations.addFunction(0, 0, "lazy");
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations, actualCalls);
mock().expectNoCall("lazy");
mock().actualCall("lazy");
@@ -191,9 +223,14 @@ TEST(MockCallTest, expectNoCallDoesntInfluenceExpectOneCall)
{
MockFailureReporterInstaller failureReporterInstaller;
- MockExpectedCallsListForTest expectations;
- expectations.addFunction("influence", MockCheckedExpectedCall::NO_EXPECTED_CALL_ORDER)->callWasMade(1);
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations);
+ MockExpectedCallsListForTest expectedCalls;
+ expectedCalls.addFunction(0, 0, "lazy");
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("influence");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall2);
+
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectedCalls, actualCalls);
mock().expectNoCall("lazy");
mock().expectOneCall("influence");
@@ -208,7 +245,9 @@ TEST(MockCallTest, expectNoCallOnlyFailureOnceWhenMultipleHappened)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest expectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations);
+ expectations.addFunction(0, 0, "lazy");
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations, actualCalls);
mock().expectNoCall("lazy");
mock().actualCall("lazy");
@@ -221,7 +260,9 @@ TEST(MockCallTest, ignoreOtherCallsExceptForTheUnExpectedOne)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest expectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations);
+ expectations.addFunction(0, 0, "lazy");
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations, actualCalls);
mock().expectNoCall("lazy");
mock().ignoreOtherCalls();
@@ -239,7 +280,9 @@ TEST(MockCallTest, expectNoCallInScopeThatHappened)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest expectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "scope::lazy", expectations);
+ expectations.addFunction(0, 0, "scope::lazy");
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "scope::lazy", expectations, actualCalls);
mock("scope").expectNoCall("lazy");
mock("scope").actualCall("lazy");
@@ -252,7 +295,8 @@ TEST(MockCallTest, expectNoCallInScopeButActualCallInAnotherScope)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest expectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "scope2::lazy", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "scope2::lazy", expectations, actualCalls);
mock("scope1").expectNoCall("lazy");
mock("scope2").actualCall("lazy");
@@ -265,7 +309,8 @@ TEST(MockCallTest, expectNoCallInScopeButActualCallInGlobal)
MockFailureReporterInstaller failureReporterInstaller;
MockExpectedCallsListForTest expectations;
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "lazy", expectations, actualCalls);
mock("scope1").expectNoCall("lazy");
mock().actualCall("lazy");
@@ -275,20 +320,32 @@ TEST(MockCallTest, expectNoCallInScopeButActualCallInGlobal)
TEST(MockCallTest, ignoreOtherCallsExceptForTheExpectedOne)
{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCalls;
+ expectedCalls.addFunction("foo");
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectedCalls, actualCalls);
+
mock().expectOneCall("foo");
mock().ignoreOtherCalls();
- mock().actualCall("bar").withParameter("foo", 1);;
+ mock().actualCall("bar").withParameter("foo", 1);
+ mock().checkExpectations();
- mock().clear();
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
TEST(MockCallTest, ignoreOtherCallsDoesntIgnoreMultipleCallsOfTheSameFunction)
{
MockFailureReporterInstaller failureReporterInstaller;
- MockExpectedCallsListForTest expectations;
- expectations.addFunction("foo")->callWasMade(1);
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", expectations);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "foo", expectedCalls, actualCalls);
mock().expectOneCall("foo");
mock().ignoreOtherCalls();
@@ -305,7 +362,8 @@ TEST(MockCallTest, ignoreOtherStillFailsIfExpectedOneDidntHappen)
MockExpectedCallsListForTest expectations;
expectations.addFunction("foo");
- MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectations, actualCalls);
mock().expectOneCall("foo");
mock().ignoreOtherCalls();
@@ -355,11 +413,12 @@ TEST(MockCallTest, OnObjectFails)
void* objectPtr2 = (void*) 0x002;
MockExpectedCallsListForTest expectations;
expectations.addFunction("boo")->onObject(objectPtr);
+ MockActualCallsQueueForTest actualCalls;
mock().expectOneCall("boo").onObject(objectPtr);
mock().actualCall("boo").onObject(objectPtr2);
- MockUnexpectedObjectFailure expectedFailure(mockFailureTest(), "boo", objectPtr2, expectations);
+ MockUnexpectedObjectFailure expectedFailure(mockFailureTest(), "boo", objectPtr2, expectations, actualCalls);
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
@@ -371,35 +430,305 @@ TEST(MockCallTest, OnObjectExpectedButNotCalled)
MockExpectedCallsListForTest expectations;
expectations.addFunction("boo")->onObject(objectPtr);
expectations.addFunction("boo")->onObject(objectPtr);
+ MockActualCallsQueueForTest actualCalls;
mock().expectOneCall("boo").onObject(objectPtr);
mock().expectOneCall("boo").onObject(objectPtr);
mock().actualCall("boo");
mock().actualCall("boo");
- MockExpectedObjectDidntHappenFailure expectedFailure(mockFailureTest(), "boo", expectations);
+ MockExpectedObjectDidntHappenFailure expectedFailure(mockFailureTest(), "boo", expectations, actualCalls);
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
mock().checkExpectations();
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
-TEST(MockCallTest, expectMultipleCalls)
+TEST(MockCallTest, expectNCalls_Fulfilled)
+{
+ mock().expectNCalls(2, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtLeastOneCall_Fulfilled_Minimum)
+{
+ mock().expectAtLeastOneCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtLeastOneCall_Fulfilled_MoreThanMinimum)
+{
+ mock().expectAtLeastOneCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtLeastNCalls_Fulfilled_Minimum)
+{
+ mock().expectAtLeastNCalls(3, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtLeastNCalls_Fulfilled_MoreThanMinimum)
+{
+ mock().expectAtLeastNCalls(3, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtMostOneCall_Fulfilled_Minimum)
+{
+ mock().expectAtMostOneCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtMostOneCall_Fulfilled_Maximum)
+{
+ mock().expectAtMostOneCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtMostNCalls_Fulfilled_Minimum)
+{
+ mock().expectAtMostNCalls(2, "boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtMostNCalls_Fulfilled_BetweenMinAndMax)
+{
+ mock().expectAtMostNCalls(2, "boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAtMostNCalls_Fulfilled_Maximum)
+{
+ mock().expectAtMostNCalls(2, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAnyCalls_Fulfilled_Minimum)
+{
+ mock().expectAnyCalls("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectAnyCalls_Fulfilled_MoreThanMinimum)
+{
+ mock().expectAnyCalls("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectRangeOfCalls_Fulfilled_Minimum)
+{
+ mock().expectRangeOfCalls(2, 6, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectRangeOfCalls_Fulfilled_BetweenMinAndMax)
+{
+ mock().expectRangeOfCalls(2, 6, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectRangeOfCalls_Fulfilled_Maximum)
+{
+ mock().expectRangeOfCalls(2, 6, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+}
+
+TEST(MockCallTest, expectNCalls_NotFulfilled)
{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction(2, 2, "boo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectedCalls, actualCalls);
+
mock().expectNCalls(2, "boo");
mock().actualCall("boo");
+ mock().checkExpectations();
+
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockCallTest, expectAtLeastOneCall_NotFulfilled)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectations;
+ expectations.addFunction(1, (unsigned int)-1, "boo");
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectations, actualCalls);
+
+ mock().expectAtLeastOneCall("boo");
+ mock().checkExpectations();
+
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockCallTest, expectAtLeastNCalls_NotFulfilled)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction(3, (unsigned int)-1, "boo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+ actualCalls.addCall(2, expectedCall1);
+
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectedCalls, actualCalls);
+
+ mock().expectAtLeastNCalls(3, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockCallTest, expectAtMostOneCall_NotFulfilled)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction(0, 1, "boo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "boo", expectedCalls, actualCalls);
+
+ mock().expectAtMostOneCall("boo");
+ mock().actualCall("boo");
mock().actualCall("boo");
mock().checkExpectations();
+
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockCallTest, expectAtMostNCalls_NotFulfilled)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction(0, 3, "boo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+ actualCalls.addCall(2, expectedCall1);
+ actualCalls.addCall(3, expectedCall1);
+
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "boo", expectedCalls, actualCalls);
+
+ mock().expectAtMostNCalls(3, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockCallTest, expectRangeOfCalls_NotFulfilled_BelowMinimum)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction(2, 3, "boo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectedCalls, actualCalls);
+
+ mock().expectRangeOfCalls(2, 3, "boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockCallTest, expectRangeOfCalls_NotFulfilled_AboveMaximum)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction(2, 3, "boo");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+ actualCalls.addCall(2, expectedCall1);
+ actualCalls.addCall(3, expectedCall1);
+
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "boo", expectedCalls, actualCalls);
+
+ mock().expectRangeOfCalls(2, 3, "boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().checkExpectations();
+
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockCallTest, expectedCallsNotFulfilledMatchBeforeFulfilledOnes)
+{
+ mock().expectAtLeastOneCall("foo");
+ mock().expectAtLeastNCalls(2, "foo");
+
+ mock().actualCall("foo");
+ mock().actualCall("foo");
+ mock().actualCall("foo");
+
+ mock().checkExpectations();
}
TEST(MockCallTest, shouldntFailTwice)
{
MockFailureReporterInstaller failureReporterInstaller;
+ mock().strictOrder();
mock().expectOneCall("foo");
+ mock().expectOneCall("boo");
+ mock().actualCall("boo");
mock().actualCall("bar");
mock().checkExpectations();
CHECK(!MockFailureReporterForTest::getReporter()->mockFailureString.contains("bar"));
+ CHECK(MockFailureReporterForTest::getReporter()->mockFailureString.contains("boo"));
}
TEST(MockCallTest, shouldReturnDefaultWhenThereIsntAnythingToReturn)
@@ -429,6 +758,6 @@ TEST(MockCallTest, mockExpectationShouldIncreaseNumberOfChecks)
TestTestingFixture fixture;
fixture.setTestFunction(mocksAreCountedAsChecksTestFunction_);
fixture.runAllTests();
- LONGS_EQUAL(5, fixture.getCheckCount());
+ LONGS_EQUAL(3, fixture.getCheckCount());
}
diff --git a/tests/CppUTestExt/MockComparatorCopierTest.cpp b/tests/CppUTestExt/MockComparatorCopierTest.cpp
index 0b83a6811..877adf89b 100644
--- a/tests/CppUTestExt/MockComparatorCopierTest.cpp
+++ b/tests/CppUTestExt/MockComparatorCopierTest.cpp
@@ -149,7 +149,8 @@ TEST(MockComparatorCopierTest, customObjectWithFunctionComparatorThatFailsCovers
MockExpectedCallsListForTest expectations;
expectations.addFunction("function")->withParameterOfType("MyTypeForTesting", "parameterName", &object);
- MockExpectedCallsDidntHappenFailure failure(UtestShell::getCurrent(), expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure failure(UtestShell::getCurrent(), expectations, actualCalls);
mock().expectOneCall("function").withParameterOfType("MyTypeForTesting", "parameterName", &object);
mock().checkExpectations();
@@ -184,7 +185,8 @@ TEST(MockComparatorCopierTest, noActualCallForCustomTypeOutputParameter)
MockExpectedCallsListForTest expectations;
expectations.addFunction("foo")->withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
- MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectations, actualCalls);
mock().expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
mock().checkExpectations();
@@ -206,7 +208,8 @@ TEST(MockComparatorCopierTest, unexpectedCustomTypeOutputParameter)
expectations.addFunction("foo");
MockNamedValue parameter("parameterName");
parameter.setObjectPointer("MyTypeForTesting", &actualObject);
- MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo");
mock().actualCall("foo").withOutputParameterOfType("MyTypeForTesting", "parameterName", &actualObject);
@@ -227,7 +230,8 @@ TEST(MockComparatorCopierTest, customTypeOutputParameterMissing)
MockExpectedCallsListForTest expectations;
expectations.addFunction("foo")->withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
- MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations, actualCalls);
mock().expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
mock().actualCall("foo");
@@ -251,7 +255,8 @@ TEST(MockComparatorCopierTest, customTypeOutputParameterOfWrongType)
expectations.addFunction("foo")->withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
MockNamedValue parameter("output");
parameter.setObjectPointer("OtherTypeForTesting", &actualObject);
- MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withOutputParameterOfTypeReturning("MyTypeForTesting", "output", &expectedObject);
mock().actualCall("foo").withOutputParameterOfType("OtherTypeForTesting", "output", &actualObject);
diff --git a/tests/CppUTestExt/MockExpectedCallTest.cpp b/tests/CppUTestExt/MockExpectedCallTest.cpp
index 7c1a73670..379e35d4b 100644
--- a/tests/CppUTestExt/MockExpectedCallTest.cpp
+++ b/tests/CppUTestExt/MockExpectedCallTest.cpp
@@ -155,7 +155,8 @@ TEST_GROUP(MockExpectedCall)
MockCheckedExpectedCall* call;
void setup()
{
- call = new MockCheckedExpectedCall;
+ call = new MockCheckedExpectedCall(1, 1);
+ call->withName("funcName");
}
void teardown()
{
@@ -173,103 +174,128 @@ TEST(MockExpectedCall, callWithoutParameterSetOrNotFound)
TEST(MockExpectedCall, callWithUnsignedIntegerParameter)
{
- const SimpleString name = "unsigned integer";
- unsigned int value = 777;
- call->withParameter(name, value);
- STRCMP_EQUAL("unsigned int", call->getInputParameterType(name).asCharString());
- LONGS_EQUAL(value, call->getInputParameter(name).getUnsignedIntValue());
- CHECK(call->hasInputParameterWithName(name));
+ const SimpleString paramName = "paramName";
+ unsigned int value = 356;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("unsigned int", call->getInputParameterType(paramName).asCharString());
+ LONGS_EQUAL(value, call->getInputParameter(paramName).getUnsignedIntValue());
+ CHECK(call->hasInputParameterWithName(paramName));
+ STRCMP_EQUAL("funcName -> unsigned int paramName: <356 (0x164)>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithIntegerParameter)
{
- call->withParameter("integer", 1);
- STRCMP_EQUAL("int", call->getInputParameterType("integer").asCharString());
- LONGS_EQUAL(1, call->getInputParameter("integer").getIntValue());
- CHECK(call->hasInputParameterWithName("integer"));
+ const SimpleString paramName = "paramName";
+ int value = 2;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("int", call->getInputParameterType(paramName).asCharString());
+ LONGS_EQUAL(value, call->getInputParameter(paramName).getIntValue());
+ CHECK(call->hasInputParameterWithName(paramName));
+ STRCMP_EQUAL("funcName -> int paramName: <2 (0x2)>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithBooleanParameter)
{
- call->withParameter("boolean", true);
- STRCMP_EQUAL("bool", call->getInputParameterType("boolean").asCharString());
- CHECK_EQUAL(true, call->getInputParameter("boolean").getBoolValue());
- CHECK(call->hasInputParameterWithName("boolean"));
+ const SimpleString paramName = "paramName";
+ bool value = true;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("bool", call->getInputParameterType(paramName).asCharString());
+ CHECK_EQUAL(value, call->getInputParameter(paramName).getBoolValue());
+ CHECK(call->hasInputParameterWithName(paramName));
+ STRCMP_EQUAL("funcName -> bool paramName: ", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithUnsignedLongIntegerParameter)
{
- const SimpleString name = "unsigned long integer";
- unsigned long value = 777;
- call->withParameter(name, value);
- STRCMP_EQUAL("unsigned long int", call->getInputParameterType(name).asCharString());
- LONGS_EQUAL(value, call->getInputParameter(name).getUnsignedLongIntValue());
- CHECK(call->hasInputParameterWithName(name));
+ const SimpleString paramName = "paramName";
+ unsigned long value = 888;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("unsigned long int", call->getInputParameterType(paramName).asCharString());
+ LONGS_EQUAL(value, call->getInputParameter(paramName).getUnsignedLongIntValue());
+ CHECK(call->hasInputParameterWithName(paramName));
+ STRCMP_EQUAL("funcName -> unsigned long int paramName: <888 (0x378)>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithLongIntegerParameter)
{
- const SimpleString name = "long integer";
+ const SimpleString paramName = "paramName";
long value = 777;
- call->withParameter(name, value);
- STRCMP_EQUAL("long int", call->getInputParameterType(name).asCharString());
- LONGS_EQUAL(value, call->getInputParameter(name).getLongIntValue());
- CHECK(call->hasInputParameterWithName(name));
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("long int", call->getInputParameterType(paramName).asCharString());
+ LONGS_EQUAL(value, call->getInputParameter(paramName).getLongIntValue());
+ CHECK(call->hasInputParameterWithName(paramName));
+ STRCMP_EQUAL("funcName -> long int paramName: <777 (0x309)>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithDoubleParameter)
{
- call->withParameter("double", 1.2);
- STRCMP_EQUAL("double", call->getInputParameterType("double").asCharString());
- DOUBLES_EQUAL(1.2, call->getInputParameter("double").getDoubleValue(), 0.05);
+ const SimpleString paramName = "paramName";
+ double value = 1.2;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("double", call->getInputParameterType(paramName).asCharString());
+ DOUBLES_EQUAL(value, call->getInputParameter(paramName).getDoubleValue(), 0.05);
+ STRCMP_EQUAL("funcName -> double paramName: <1.2>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithStringParameter)
{
- call->withParameter("string", "hello world");
- STRCMP_EQUAL("const char*", call->getInputParameterType("string").asCharString());
- STRCMP_EQUAL("hello world", call->getInputParameter("string").getStringValue());
+ const SimpleString paramName = "paramName";
+ const char* value = "hello world";
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("const char*", call->getInputParameterType(paramName).asCharString());
+ STRCMP_EQUAL(value, call->getInputParameter(paramName).getStringValue());
+ STRCMP_EQUAL("funcName -> const char* paramName: ", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithPointerParameter)
{
- void* ptr = (void*) 0x123;
- call->withParameter("pointer", ptr);
- STRCMP_EQUAL("void*", call->getInputParameterType("pointer").asCharString());
- POINTERS_EQUAL(ptr, call->getInputParameter("pointer").getPointerValue());
+ const SimpleString paramName = "paramName";
+ void* value = (void*) 0x123;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("void*", call->getInputParameterType(paramName).asCharString());
+ POINTERS_EQUAL(value, call->getInputParameter(paramName).getPointerValue());
+ STRCMP_EQUAL("funcName -> void* paramName: <0x123>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithConstPointerParameter)
{
- const void* ptr = (const void*) 0x345;
- call->withParameter("constPointer", ptr);
- STRCMP_EQUAL("const void*", call->getInputParameterType("constPointer").asCharString());
- POINTERS_EQUAL(ptr, call->getInputParameter("constPointer").getConstPointerValue());
+ const SimpleString paramName = "paramName";
+ const void* value = (const void*) 0x345;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("const void*", call->getInputParameterType(paramName).asCharString());
+ POINTERS_EQUAL(value, call->getInputParameter(paramName).getConstPointerValue());
+ STRCMP_EQUAL("funcName -> const void* paramName: <0x345>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithFunctionPointerParameter)
{
- void (*ptr)() = (void (*)()) 0x123;
- call->withParameter("functionPointer", ptr);
- STRCMP_EQUAL("void (*)()", call->getInputParameterType("functionPointer").asCharString());
- FUNCTIONPOINTERS_EQUAL(ptr, call->getInputParameter("functionPointer").getFunctionPointerValue());
+ const SimpleString paramName = "paramName";
+ void (*value)() = (void (*)()) 0xdead;
+ call->withParameter(paramName, value);
+ STRCMP_EQUAL("void (*)()", call->getInputParameterType(paramName).asCharString());
+ FUNCTIONPOINTERS_EQUAL(value, call->getInputParameter(paramName).getFunctionPointerValue());
+ STRCMP_EQUAL("funcName -> void (*)() paramName: <0xdead>", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithMemoryBuffer)
{
- const unsigned char mem_buffer[] = { 0x12, 0xFE, 0xA1 };
- call->withParameter("memoryBuffer", mem_buffer, sizeof(mem_buffer));
- STRCMP_EQUAL("const unsigned char*", call->getInputParameterType("memoryBuffer").asCharString());
- POINTERS_EQUAL( (void*) mem_buffer, (void*) call->getInputParameter("memoryBuffer").getMemoryBuffer() );
- LONGS_EQUAL(sizeof(mem_buffer), call->getInputParameter("memoryBuffer").getSize());
+ const SimpleString paramName = "paramName";
+ const unsigned char value[] = { 0x12, 0xFE, 0xA1 };
+ call->withParameter(paramName, value, sizeof(value));
+ STRCMP_EQUAL("const unsigned char*", call->getInputParameterType(paramName).asCharString());
+ POINTERS_EQUAL( (void*) value, (void*) call->getInputParameter(paramName).getMemoryBuffer() );
+ LONGS_EQUAL(sizeof(value), call->getInputParameter(paramName).getSize());
+ STRCMP_EQUAL("funcName -> const unsigned char* paramName: ", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithObjectParameter)
{
- void* ptr = (void*) 0x123;
- call->withParameterOfType("class", "object", ptr);
- POINTERS_EQUAL(ptr, call->getInputParameter("object").getObjectPointer());
- STRCMP_EQUAL("class", call->getInputParameterType("object").asCharString());
+ const SimpleString paramName = "paramName";
+ void* value = (void*) 0x123;
+ call->withParameterOfType("ClassName", paramName, value);
+ POINTERS_EQUAL(value, call->getInputParameter(paramName).getObjectPointer());
+ STRCMP_EQUAL("ClassName", call->getInputParameterType(paramName).asCharString());
+ STRCMP_EQUAL("funcName -> ClassName paramName: ", call->callToString(true).asCharString());
}
TEST(MockExpectedCall, callWithObjectParameterUnequalComparison)
@@ -385,58 +411,131 @@ TEST(MockExpectedCall, callWithThreeDifferentParameter)
DOUBLES_EQUAL(0.12, call->getInputParameter("double").getDoubleValue(), 0.05);
}
-TEST(MockExpectedCall, withoutANameItsFulfilled)
+TEST(MockExpectedCall, singleCallNotMadeIsNotFulfilledButCanMatchActualCalls)
{
- CHECK(call->isFulfilled());
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ CHECK(!expectedCall.isFulfilled());
+ CHECK(expectedCall.canMatchActualCalls());
}
-TEST(MockExpectedCall, withANameItsNotFulfilled)
+TEST(MockExpectedCall, singleCallMadeIsFulFilledAndCannotMatchActualCalls)
{
- call->withName("name");
- CHECK(!call->isFulfilled());
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.callWasMade(1);
+ CHECK(expectedCall.isFulfilled());
+ CHECK(!expectedCall.canMatchActualCalls());
}
-TEST(MockExpectedCall, afterSettingCallFulfilledItsFulFilled)
+TEST(MockExpectedCall, multiCallNotMadeIsNotFulfilledButCanMatchActualCalls)
{
- call->withName("name");
- call->callWasMade(1);
- CHECK(call->isFulfilled());
+ MockCheckedExpectedCall expectedCall(2, 3);
+ expectedCall.withName("name");
+ CHECK(!expectedCall.isFulfilled());
+ CHECK(expectedCall.canMatchActualCalls());
}
-TEST(MockExpectedCall, calledButNotWithParameterIsNotFulFilled)
+TEST(MockExpectedCall, multiCallNotMadeMinimumTimesIsNotFulfilledButCanMatchActualCalls)
{
- call->withName("name").withParameter("para", 1);
- call->callWasMade(1);
- CHECK(!call->isFulfilled());
+ MockCheckedExpectedCall expectedCall(2, 3);
+ expectedCall.withName("name");
+ expectedCall.callWasMade(1);
+ CHECK(!expectedCall.isFulfilled());
+ CHECK(expectedCall.canMatchActualCalls());
}
-TEST(MockExpectedCall, calledAndParametersAreFulfilled)
+TEST(MockExpectedCall, multiCallMadeMinimumTimesIsFulfilledAndCanMatchActualCalls)
{
- call->withName("name").withParameter("para", 1);
- call->callWasMade(1);
- call->inputParameterWasPassed("para");
- CHECK(call->isFulfilled());
+ MockCheckedExpectedCall expectedCall(2, 3);
+ expectedCall.withName("name");
+ expectedCall.callWasMade(1);
+ expectedCall.callWasMade(2);
+ CHECK(expectedCall.isFulfilled());
+ CHECK(expectedCall.canMatchActualCalls());
}
-TEST(MockExpectedCall, calledButNotAllParametersAreFulfilled)
+TEST(MockExpectedCall, multiCallsMadeMaximumTimesIsFulfilledAndCannotMatchActualCalls)
{
- call->withName("name").withParameter("para", 1).withParameter("two", 2);
- call->callWasMade(1);
- call->inputParameterWasPassed("para");
- CHECK(!call->isFulfilled());
+ MockCheckedExpectedCall expectedCall(2, 3);
+ expectedCall.withName("name");
+ expectedCall.callWasMade(1);
+ expectedCall.callWasMade(2);
+ expectedCall.callWasMade(3);
+ CHECK(expectedCall.isFulfilled());
+ CHECK(!expectedCall.canMatchActualCalls());
}
-TEST(MockExpectedCall, toStringForNoParameters)
+TEST(MockExpectedCall, multiCallsMadeMoreThanMaximumTimesIsNotFulfilledAndCannotMatchActualCalls)
{
- call->withName("name");
- STRCMP_EQUAL("name -> no parameters", call->callToString().asCharString());
+ MockCheckedExpectedCall expectedCall(2, 3);
+ expectedCall.withName("name");
+ expectedCall.callWasMade(1);
+ expectedCall.callWasMade(2);
+ expectedCall.callWasMade(3);
+ expectedCall.callWasMade(4);
+ CHECK(!expectedCall.isFulfilled());
+ CHECK(!expectedCall.canMatchActualCalls());
+}
+
+TEST(MockExpectedCall, callsWithoutParameterAlwaysMatch)
+{
+ MockCheckedExpectedCall expectedCall(1, 1);
+ CHECK(expectedCall.isMatchingActualCall());
+}
+
+TEST(MockExpectedCall, callsWithParameterNotFulfilledDontMatch)
+{
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withParameter("para", 1);
+ CHECK(!expectedCall.isMatchingActualCall());
+}
+
+TEST(MockExpectedCall, callsWithParameterFulfilledDoMatch)
+{
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withParameter("para", 1);
+ expectedCall.inputParameterWasPassed("para");
+ CHECK(expectedCall.isMatchingActualCall());
+}
+
+TEST(MockExpectedCall, callsWithSomeParametersNotFulfilledDontMatch)
+{
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withParameter("para", 1).withParameter("two", 2);
+ expectedCall.inputParameterWasPassed("para");
+ CHECK(!expectedCall.isMatchingActualCall());
+}
+
+TEST(MockExpectedCall, toStringForNoParametersSingleCallNotCalled)
+{
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ STRCMP_EQUAL("name -> no parameters (expected 1 call, but was called 0 times)", expectedCall.callToString(false).asCharString());
+}
+
+TEST(MockExpectedCall, toStringForNoParametersMultiCallCalledLessThanMinimum)
+{
+ MockCheckedExpectedCall expectedCall(2, 2);
+ expectedCall.withName("name");
+ expectedCall.callWasMade(1);
+ STRCMP_EQUAL("name -> no parameters (expected 2 calls, but was called 1 time)", expectedCall.callToString(false).asCharString());
+}
+
+TEST(MockExpectedCall, toStringForNoParametersMultiCallCalledMinimum)
+{
+ MockCheckedExpectedCall expectedCall(2, 3);
+ expectedCall.withName("name");
+ expectedCall.callWasMade(1);
+ expectedCall.callWasMade(2);
+ STRCMP_EQUAL("name -> no parameters (called 2 times)", expectedCall.callToString(false).asCharString());
}
TEST(MockExpectedCall, toStringForIgnoredParameters)
{
- call->withName("name");
- call->ignoreOtherParameters();
- STRCMP_EQUAL("name -> all parameters ignored", call->callToString().asCharString());
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ expectedCall.ignoreOtherParameters();
+ STRCMP_EQUAL("name -> all parameters ignored (expected 1 call, but was called 0 times)", expectedCall.callToString(false).asCharString());
}
TEST(MockExpectedCall, toStringForMultipleInputParameters)
@@ -444,11 +543,14 @@ TEST(MockExpectedCall, toStringForMultipleInputParameters)
int int_value = 10;
unsigned int uint_value = 7;
- call->withName("name");
- call->withParameter("string", "value");
- call->withParameter("integer", int_value);
- call->withParameter("unsigned-integer", uint_value);
- STRCMP_EQUAL("name -> const char* string: , int integer: <10 (0xa)>, unsigned int unsigned-integer: <7 (0x7)>", call->callToString().asCharString());
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ expectedCall.withParameter("string", "value");
+ expectedCall.withParameter("integer", int_value);
+ expectedCall.withParameter("unsigned-integer", uint_value);
+ expectedCall.callWasMade(1);
+ STRCMP_EQUAL("name -> const char* string: , int integer: <10 (0xa)>, unsigned int unsigned-integer: <7 (0x7)> "
+ "(called 1 time)", expectedCall.callToString(false).asCharString());
}
TEST(MockExpectedCall, toStringForMultipleInputAndOutputParameters)
@@ -457,58 +559,116 @@ TEST(MockExpectedCall, toStringForMultipleInputAndOutputParameters)
unsigned int uint_value = 7;
unsigned char buffer_value[3];
- call->withName("name");
- call->withParameter("string", "value");
- call->withParameter("integer", int_value);
- call->withParameter("unsigned-integer", uint_value);
- call->withOutputParameterReturning("buffer", buffer_value, sizeof(buffer_value));
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ expectedCall.withParameter("string", "value");
+ expectedCall.withParameter("integer", int_value);
+ expectedCall.withParameter("unsigned-integer", uint_value);
+ expectedCall.withOutputParameterReturning("buffer", buffer_value, sizeof(buffer_value));
+ expectedCall.callWasMade(1);
STRCMP_EQUAL("name -> const char* string: , int integer: <10 (0xa)>, unsigned int unsigned-integer: <7 (0x7)>, "
- "const void* buffer: ", call->callToString().asCharString());
+ "const void* buffer: (called 1 time)", expectedCall.callToString(false).asCharString());
}
TEST(MockExpectedCall, toStringForMultipleOutputParameters)
{
unsigned char buffer_value[3];
- call->withName("name");
- call->withOutputParameterReturning("buffer1", buffer_value, sizeof(buffer_value));
- call->withOutputParameterReturning("buffer2", buffer_value, sizeof(buffer_value));
- STRCMP_EQUAL("name -> const void* buffer1: , const void* buffer2: ", call->callToString().asCharString());
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ expectedCall.withOutputParameterReturning("buffer1", buffer_value, sizeof(buffer_value));
+ expectedCall.withOutputParameterReturning("buffer2", buffer_value, sizeof(buffer_value));
+ expectedCall.callWasMade(1);
+ STRCMP_EQUAL("name -> const void* buffer1: , const void* buffer2: (called 1 time)", expectedCall.callToString(false).asCharString());
}
TEST(MockExpectedCall, toStringForParameterAndIgnored)
{
- call->withName("name");
- call->withParameter("string", "value");
- call->ignoreOtherParameters();
- STRCMP_EQUAL("name -> const char* string: , other parameters are ignored", call->callToString().asCharString());
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ expectedCall.withParameter("string", "value");
+ expectedCall.ignoreOtherParameters();
+ expectedCall.callWasMade(1);
+ STRCMP_EQUAL("name -> const char* string: , other parameters are ignored (called 1 time)", expectedCall.callToString(false).asCharString());
}
-TEST(MockExpectedCall, toStringForCallOrder)
+TEST(MockExpectedCall, toStringForCallOrderSingle)
{
- call->withName("name");
- call->withCallOrder(2);
- STRCMP_EQUAL("name -> expected call order: <2> -> no parameters", call->callToString().asCharString());
+ MockCheckedExpectedCall expectedCall(1, 1);
+ expectedCall.withName("name");
+ expectedCall.withCallOrder(2, 2);
+ expectedCall.callWasMade(1);
+ STRCMP_EQUAL("name -> expected call order: <2> -> no parameters (called 1 time)", expectedCall.callToString(false).asCharString());
+}
+
+TEST(MockExpectedCall, toStringForCallOrderMultiple)
+{
+ MockCheckedExpectedCall expectedCall(5, 5);
+ expectedCall.withName("name");
+ expectedCall.withCallOrder(5, 9);
+ expectedCall.callWasMade(5);
+ expectedCall.callWasMade(6);
+ expectedCall.callWasMade(7);
+ expectedCall.callWasMade(8);
+ expectedCall.callWasMade(9);
+ STRCMP_EQUAL("name -> expected calls order: <5..9> -> no parameters (called 5 times)", expectedCall.callToString(false).asCharString());
}
-TEST(MockExpectedCall, callOrderIsNotFulfilledWithWrongOrder)
+TEST(MockExpectedCall, callOrderIsFulfilledButWithWrongOrderSingle)
{
call->withName("name");
- call->withCallOrder(2);
+ call->withCallOrder(2, 2);
call->callWasMade(1);
CHECK(call->isFulfilled());
CHECK(call->isOutOfOrder());
}
-TEST(MockExpectedCall, callOrderIsFulfilled)
+TEST(MockExpectedCall, callOrderIsFulfilledButWithWrongOrderMultipleTooEarly)
+{
+ MockCheckedExpectedCall expectedCall(3, 3);
+ expectedCall.withName("name");
+ expectedCall.withCallOrder(10, 12);
+ expectedCall.callWasMade(9);
+ expectedCall.callWasMade(10);
+ expectedCall.callWasMade(11);
+ CHECK(expectedCall.isFulfilled());
+ CHECK(expectedCall.isOutOfOrder());
+}
+
+TEST(MockExpectedCall, callOrderIsFulfilledButWithWrongOrderMultipleTooLate)
+{
+ MockCheckedExpectedCall expectedCall(3, 3);
+ expectedCall.withName("name");
+ expectedCall.withCallOrder(10, 12);
+ expectedCall.callWasMade(11);
+ expectedCall.callWasMade(12);
+ expectedCall.callWasMade(13);
+ CHECK(expectedCall.isFulfilled());
+ CHECK(expectedCall.isOutOfOrder());
+}
+
+TEST(MockExpectedCall, callOrderIsFulfilledSingle)
{
call->withName("name");
- call->withCallOrder(1);
+ call->withCallOrder(1, 1);
call->callWasMade(1);
CHECK(call->isFulfilled());
CHECK_FALSE(call->isOutOfOrder());
}
+TEST(MockExpectedCall, callOrderIsFulfilledMultiple)
+{
+ MockCheckedExpectedCall expectedCall(4, 4);
+ expectedCall.withName("name");
+ expectedCall.withCallOrder(150, 153);
+ expectedCall.callWasMade(150);
+ expectedCall.callWasMade(151);
+ expectedCall.callWasMade(152);
+ expectedCall.callWasMade(153);
+ CHECK(expectedCall.isFulfilled());
+ CHECK_FALSE(expectedCall.isOutOfOrder());
+}
+
TEST(MockExpectedCall, hasOutputParameter)
{
const int value = 1;
@@ -553,180 +713,6 @@ TEST(MockExpectedCall, hasNoOutputParameterOfTypeDifferentType)
CHECK_FALSE(call->hasOutputParameter(foo));
}
-static MockExpectedCallComposite composite;
-
-TEST_GROUP(MockExpectedCallComposite)
-{
- MockCheckedExpectedCall call;
-
- void setup() _override
- {
- composite.add(call);
- composite.withName("name");
- }
-
- void teardown() _override
- {
- CHECK_NO_MOCK_FAILURE();
- composite.clear();
- }
-};
-
-TEST(MockExpectedCallComposite, hasBoolParameter)
-{
- composite.withParameter("param", true);
- STRCMP_EQUAL("name -> bool param: ", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasLongIntParameter)
-{
- composite.withParameter("param", (long int) 1);
- STRCMP_EQUAL("name -> long int param: <1 (0x1)>", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasUnsignedLongIntParameter)
-{
- composite.withParameter("param", (unsigned long int) 5);
- STRCMP_EQUAL("name -> unsigned long int param: <5 (0x5)>", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasPointerParameter)
-{
- composite.withParameter("param", (void*) 0);
- STRCMP_EQUAL("name -> void* param: <0x0>", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasConstPointerParameter)
-{
- composite.withParameter("param", (const void*) 0);
- STRCMP_EQUAL("name -> const void* param: <0x0>", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasFunctionPointerParameter)
-{
- composite.withParameter("param", (void (*)()) 0);
- STRCMP_EQUAL("name -> void (*)() param: <0x0>", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasMemoryBufferParameter)
-{
- const unsigned char mem_buffer[] = { 0x89, 0xFE, 0x15 };
- composite.withParameter("param", mem_buffer, sizeof(mem_buffer));
- STRCMP_EQUAL("name -> const unsigned char* param: ", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasParameterOfType)
-{
- composite.withParameterOfType("type", "param", (const void*) 0);
- STRCMP_EQUAL("name -> type param: ", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasOutputParameterReturning)
-{
- composite.withOutputParameterReturning("out", (const void*) 0, 1);
- STRCMP_EQUAL("name -> const void* out: ", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasOutputParameterOfTypeReturning)
-{
- composite.withOutputParameterOfTypeReturning("type", "out", (const void*) 0);
- STRCMP_EQUAL("name -> type out: ", call.callToString().asCharString());
-}
-
-TEST(MockExpectedCallComposite, hasBoolReturnValue)
-{
- composite.andReturnValue(true);
- STRCMP_EQUAL("bool", call.returnValue().getType().asCharString());
- CHECK_EQUAL(true, call.returnValue().getBoolValue());
-}
-
-TEST(MockExpectedCallComposite, hasUnsignedIntReturnValue)
-{
- composite.andReturnValue((unsigned int) 2);
- STRCMP_EQUAL("unsigned int", call.returnValue().getType().asCharString());
- LONGS_EQUAL(2, call.returnValue().getUnsignedIntValue());
-}
-
-TEST(MockExpectedCallComposite, hasIntReturnValue)
-{
- composite.andReturnValue((int) -5);
- STRCMP_EQUAL("int", call.returnValue().getType().asCharString());
- LONGS_EQUAL(-5, call.returnValue().getIntValue());
-}
-
-TEST(MockExpectedCallComposite, hasLongIntReturnValue)
-{
- composite.andReturnValue((long int) -17);
- STRCMP_EQUAL("long int", call.returnValue().getType().asCharString());
- LONGS_EQUAL(-17, call.returnValue().getLongIntValue());
-}
-
-TEST(MockExpectedCallComposite, hasUnsignedLongIntReturnValue)
-{
- composite.andReturnValue((unsigned long int) 6);
- STRCMP_EQUAL("unsigned long int", call.returnValue().getType().asCharString());
- LONGS_EQUAL(6, call.returnValue().getUnsignedLongIntValue());
-}
-
-TEST(MockExpectedCallComposite, hasDoubleReturnValue)
-{
- composite.andReturnValue((double) 3.005);
- STRCMP_EQUAL("double", call.returnValue().getType().asCharString());
- DOUBLES_EQUAL(3.005, call.returnValue().getDoubleValue(), 0.0001);
-}
-
-TEST(MockExpectedCallComposite, hasStringReturnValue)
-{
- composite.andReturnValue("hello");
- STRCMP_EQUAL("const char*", call.returnValue().getType().asCharString());
- STRCMP_EQUAL("hello", call.returnValue().getStringValue());
-}
-
-TEST(MockExpectedCallComposite, hasPointerReturnValue)
-{
- composite.andReturnValue((void*) 0);
- STRCMP_EQUAL("void*", call.returnValue().getType().asCharString());
- POINTERS_EQUAL((void*) 0, call.returnValue().getPointerValue());
-}
-
-TEST(MockExpectedCallComposite, hasConstPointerReturnValue)
-{
- composite.andReturnValue((const void*) 0);
- STRCMP_EQUAL("const void*", call.returnValue().getType().asCharString());
- POINTERS_EQUAL((const void*) 0, call.returnValue().getConstPointerValue());
-}
-
-TEST(MockExpectedCallComposite, hasFunctionPointerReturnValue)
-{
- composite.andReturnValue((void(*)()) 0);
- STRCMP_EQUAL("void (*)()", call.returnValue().getType().asCharString());
- FUNCTIONPOINTERS_EQUAL((void(*)()) 0, call.returnValue().getFunctionPointerValue());
-}
-
-TEST(MockExpectedCallComposite, isOnObject)
-{
- composite.onObject(&composite);
- SimpleString info("(object address: ");
- info += StringFromFormat("%p", (void*) &composite);
- info += ")::name -> no parameters";
- STRCMP_EQUAL(info.asCharString(), call.callToString().asCharString());
-}
-
-#include "CppUTest/TestTestingFixture.h"
-
-static void withCallOrderNotSupportedFailMethod_(void)
-{
- composite.withCallOrder(5);
-} // LCOV_EXCL_LINE
-
-TEST(MockExpectedCallComposite, doesNotSupportCallOrder)
-{
- TestTestingFixture fixture;
- fixture.setTestFunction(&withCallOrderNotSupportedFailMethod_);
- fixture.runAllTests();
- fixture.assertPrintContains("withCallOrder not supported for CompositeCalls");
-}
-
TEST_GROUP(MockIgnoredExpectedCall)
{
MockIgnoredExpectedCall ignored;
@@ -735,7 +721,7 @@ TEST_GROUP(MockIgnoredExpectedCall)
TEST(MockIgnoredExpectedCall, worksAsItShould)
{
ignored.withName("func");
- ignored.withCallOrder(1);
+ ignored.withCallOrder(1, 1);
ignored.onObject((void*) 0);
ignored.withBoolParameter("umm", true);
ignored.withIntParameter("bla", (int) 1);
diff --git a/tests/CppUTestExt/MockFailureReporterForTest.cpp b/tests/CppUTestExt/MockFailureReporterForTest.cpp
index 4e0b0cfb6..154cdebc5 100644
--- a/tests/CppUTestExt/MockFailureReporterForTest.cpp
+++ b/tests/CppUTestExt/MockFailureReporterForTest.cpp
@@ -98,17 +98,56 @@ MockExpectedCallsListForTest::~MockExpectedCallsListForTest()
MockCheckedExpectedCall* MockExpectedCallsListForTest::addFunction(const SimpleString& name)
{
- MockCheckedExpectedCall* newCall = new MockCheckedExpectedCall;
+ MockCheckedExpectedCall* newCall = new MockCheckedExpectedCall(1, 1);
newCall->withName(name);
addExpectedCall(newCall);
return newCall;
}
-MockCheckedExpectedCall* MockExpectedCallsListForTest::addFunction(const SimpleString& name, int order)
+MockCheckedExpectedCall* MockExpectedCallsListForTest::addFunction(unsigned int minCalls, unsigned int maxCalls, const SimpleString& name)
+{
+ MockCheckedExpectedCall* newCall = new MockCheckedExpectedCall(minCalls, maxCalls);
+ newCall->withName(name);
+ addExpectedCall(newCall);
+ return newCall;
+}
+
+MockCheckedExpectedCall* MockExpectedCallsListForTest::addFunction(const SimpleString& name, unsigned int order)
{
MockCheckedExpectedCall* newCall = addFunction(name);
- newCall->withCallOrder(order);
+ newCall->withCallOrder(order, order);
return newCall;
}
+static MockSupport testMockSupport;
+
+MockCheckedActualCallForTest::MockCheckedActualCallForTest(unsigned int callOrder, const SimpleString& scopeName, MockCheckedExpectedCall* matchingCall)
+: MockCheckedActualCall(callOrder, NULL, testMockSupport), scopeName_(scopeName)
+{
+ setName(matchingCall->getName());
+ setMatchingExpectedCall(matchingCall);
+}
+
+const SimpleString& MockCheckedActualCallForTest::getScopeName() const
+{
+ return scopeName_;
+}
+
+MockActualCallsQueueForTest::MockActualCallsQueueForTest() : MockActualCallsQueue(true)
+{
+}
+
+MockCheckedActualCall* MockActualCallsQueueForTest::addCall(unsigned int callOrder, MockCheckedExpectedCall* matchingCall)
+{
+ return addCall(callOrder, "", matchingCall);
+}
+
+MockCheckedActualCall* MockActualCallsQueueForTest::addCall(unsigned int callOrder, const SimpleString& mockScope, MockCheckedExpectedCall* matchingCall)
+{
+ MockCheckedActualCallForTest* newCall = new MockCheckedActualCallForTest(callOrder, mockScope, matchingCall);
+ matchingCall->finalizeActualCallMatch();
+ matchingCall->callWasMade(callOrder);
+ pushBack(newCall);
+ return newCall;
+}
diff --git a/tests/CppUTestExt/MockFailureReporterForTest.h b/tests/CppUTestExt/MockFailureReporterForTest.h
index bbc58e793..27b2313ca 100644
--- a/tests/CppUTestExt/MockFailureReporterForTest.h
+++ b/tests/CppUTestExt/MockFailureReporterForTest.h
@@ -60,7 +60,26 @@ class MockExpectedCallsListForTest : public MockExpectedCallsList
public:
~MockExpectedCallsListForTest();
MockCheckedExpectedCall* addFunction(const SimpleString& name);
- MockCheckedExpectedCall* addFunction(const SimpleString& name, int order);
+ MockCheckedExpectedCall* addFunction(unsigned int minCalls, unsigned int maxCalls, const SimpleString& name);
+ MockCheckedExpectedCall* addFunction(const SimpleString& name, unsigned int order);
+};
+
+class MockCheckedActualCallForTest : public MockCheckedActualCall
+{
+public:
+ MockCheckedActualCallForTest(unsigned int callOrder, const SimpleString& scopeName, MockCheckedExpectedCall* matchingCall);
+ virtual const SimpleString& getScopeName() const _override;
+
+private:
+ SimpleString scopeName_;
+};
+
+class MockActualCallsQueueForTest : public MockActualCallsQueue
+{
+public:
+ MockActualCallsQueueForTest();
+ MockCheckedActualCall* addCall(unsigned int callOrder, MockCheckedExpectedCall* matchingCall);
+ MockCheckedActualCall* addCall(unsigned int callOrder, const SimpleString& mockScope, MockCheckedExpectedCall* matchingCall);
};
#endif
diff --git a/tests/CppUTestExt/MockFailureTest.cpp b/tests/CppUTestExt/MockFailureTest.cpp
index d1356515f..dae206d03 100644
--- a/tests/CppUTestExt/MockFailureTest.cpp
+++ b/tests/CppUTestExt/MockFailureTest.cpp
@@ -33,47 +33,22 @@
TEST_GROUP(MockFailureTest)
{
- MockFailureReporter reporter;
-
- MockExpectedCallsList *list;
- MockCheckedExpectedCall* call1;
- MockCheckedExpectedCall* call2;
- MockCheckedExpectedCall* call3;
-
- void setup ()
- {
- list = new MockExpectedCallsList;
- call1 = new MockCheckedExpectedCall;
- call2 = new MockCheckedExpectedCall;
- call3 = new MockCheckedExpectedCall;
- }
void teardown ()
{
- delete list;
- delete call1;
- delete call2;
- delete call3;
CHECK_NO_MOCK_FAILURE();
}
- void addAllToList()
- {
- list->addExpectedCall(call1);
- list->addExpectedCall(call2);
- list->addExpectedCall(call3);
- }
void checkUnexpectedNthCallMessage(unsigned int count, const char* expectedOrdinal)
{
- MockExpectedCallsList callList;
- MockCheckedExpectedCall expCall;
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall = expectedCalls.addFunction(count-1, count-1, "bar");
- expCall.withName("bar");
+ MockActualCallsQueueForTest actualCalls;
for (unsigned int i = 0; i < (count - 1); i++) {
- expCall.callWasMade(1);
- callList.addExpectedCall(&expCall);
+ actualCalls.addCall(i, expectedCall);
}
- MockUnexpectedCallHappenedFailure failure(UtestShell::getCurrent(), "bar", callList);
+ MockUnexpectedCallHappenedFailure failure(UtestShell::getCurrent(), "bar", expectedCalls, actualCalls);
SimpleString expectedMessage = StringFromFormat("Mock Failure: Unexpected additional (%s) call to function: bar\n\tEXPECTED", expectedOrdinal);
STRCMP_CONTAINS(expectedMessage.asCharString(), failure.getMessage().asCharString());
@@ -88,29 +63,38 @@ TEST(MockFailureTest, noErrorFailureSomethingGoneWrong)
TEST(MockFailureTest, unexpectedCallHappened)
{
- MockUnexpectedCallHappenedFailure failure(UtestShell::getCurrent(), "foobar", *list);
+ MockExpectedCallsListForTest expectedCalls;
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure failure(UtestShell::getCurrent(), "foobar", expectedCalls, actualCalls);
STRCMP_EQUAL("Mock Failure: Unexpected call to function: foobar\n"
- "\tEXPECTED calls that did NOT happen:\n"
+ "\tEXPECTED calls that WERE NOT fulfilled:\n"
+ "\t\t\n"
+ "\tEXPECTED calls that WERE fulfilled:\n"
"\t\t\n"
- "\tACTUAL calls that did happen (in call order):\n"
+ "\tACTUAL calls that were expected (in call order):\n"
"\t\t", failure.getMessage().asCharString());
}
TEST(MockFailureTest, expectedCallDidNotHappen)
{
- call1->withName("foobar");
- call2->withName("world").withParameter("boo", 2).withParameter("hello", "world");
- call3->withName("haphaphap");
- call3->callWasMade(1);
- addAllToList();
-
- MockExpectedCallsDidntHappenFailure failure(UtestShell::getCurrent(), *list);
- STRCMP_EQUAL("Mock Failure: Expected call did not happen.\n"
- "\tEXPECTED calls that did NOT happen:\n"
- "\t\tfoobar -> no parameters\n"
- "\t\tworld -> int boo: <2 (0x2)>, const char* hello: \n"
- "\tACTUAL calls that did happen (in call order):\n"
- "\t\thaphaphap -> no parameters", failure.getMessage().asCharString());
+ MockExpectedCallsListForTest expectedCalls;
+ expectedCalls.addFunction("foobar");
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("world");
+ expectedCall2->withParameter("boo", 2).withParameter("hello", "world");
+ MockCheckedExpectedCall* expectedCall3 = expectedCalls.addFunction("haphaphap");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall3);
+
+ MockExpectedCallsNotFulfilledFailure failure(UtestShell::getCurrent(), expectedCalls, actualCalls);
+ STRCMP_EQUAL("Mock Failure: Expected call WAS NOT fulfilled.\n"
+ "\tEXPECTED calls that WERE NOT fulfilled:\n"
+ "\t\tfoobar -> no parameters (expected 1 call, but was called 0 times)\n"
+ "\t\tworld -> int boo: <2 (0x2)>, const char* hello: (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled:\n"
+ "\t\thaphaphap -> no parameters (called 1 time)\n"
+ "\tACTUAL calls that were expected (in call order):\n"
+ "\t\t(1) haphaphap -> no parameters", failure.getMessage().asCharString());
}
TEST(MockFailureTest, MockUnexpectedNthAdditionalCallFailure)
@@ -129,20 +113,27 @@ TEST(MockFailureTest, MockUnexpectedNthAdditionalCallFailure)
TEST(MockFailureTest, MockUnexpectedInputParameterFailure)
{
- call1->withName("foo").withParameter("boo", 2);
- call2->withName("foo").withParameter("boo", 3.3);
- call3->withName("unrelated");
- addAllToList();
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ expectedCall1->withParameter("boo", 2);
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->withParameter("boo", 3.3);
+ MockCheckedExpectedCall* expectedCall3 = expectedCalls.addFunction("unrelated");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall3);
MockNamedValue actualParameter("bar");
actualParameter.setValue(2);
- MockUnexpectedInputParameterFailure failure(UtestShell::getCurrent(), "foo", actualParameter, *list);
+ MockUnexpectedInputParameterFailure failure(UtestShell::getCurrent(), "foo", actualParameter, expectedCalls, actualCalls);
STRCMP_EQUAL("Mock Failure: Unexpected parameter name to function \"foo\": bar\n"
- "\tEXPECTED calls that DID NOT happen related to function: foo\n"
- "\t\tfoo -> int boo: <2 (0x2)>\n"
- "\t\tfoo -> double boo: <3.3>\n"
- "\tACTUAL calls that DID happen related to function: foo\n"
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\tfoo -> int boo: <2 (0x2)> (expected 1 call, but was called 0 times)\n"
+ "\t\tfoo -> double boo: <3.3> (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\t\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
"\t\t\n"
"\tACTUAL unexpected parameter passed to function: foo\n"
"\t\tint bar: <2 (0x2)>", failure.getMessage().asCharString());
@@ -152,20 +143,26 @@ TEST(MockFailureTest, MockUnexpectedOutputParameterFailure)
{
int out1;
int out2;
- call1->withName("foo").withOutputParameterReturning("boo", &out1, sizeof(out1));
- call2->withName("foo").withOutputParameterReturning("boo", &out2, sizeof(out2));
- call3->withName("unrelated");
- addAllToList();
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ expectedCall1->withOutputParameterReturning("boo", &out1, sizeof(out1));
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->withOutputParameterReturning("boo", &out2, sizeof(out2));
+ expectedCalls.addFunction("unrelated");
+
+ MockActualCallsQueueForTest actualCalls;
MockNamedValue actualParameter("bar");
actualParameter.setValue((void *)0x123);
- MockUnexpectedOutputParameterFailure failure(UtestShell::getCurrent(), "foo", actualParameter, *list);
+ MockUnexpectedOutputParameterFailure failure(UtestShell::getCurrent(), "foo", actualParameter, expectedCalls, actualCalls);
STRCMP_EQUAL("Mock Failure: Unexpected output parameter name to function \"foo\": bar\n"
- "\tEXPECTED calls that DID NOT happen related to function: foo\n"
- "\t\tfoo -> const void* boo: \n"
- "\t\tfoo -> const void* boo: \n"
- "\tACTUAL calls that DID happen related to function: foo\n"
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\tfoo -> const void* boo: (expected 1 call, but was called 0 times)\n"
+ "\t\tfoo -> const void* boo: (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\t\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
"\t\t\n"
"\tACTUAL unexpected output parameter passed to function: foo\n"
"\t\tvoid* bar", failure.getMessage().asCharString());
@@ -173,45 +170,139 @@ TEST(MockFailureTest, MockUnexpectedOutputParameterFailure)
TEST(MockFailureTest, MockUnexpectedParameterValueFailure)
{
- call1->withName("foo").withParameter("boo", 2);
- call2->withName("foo").withParameter("boo", 10);
- call3->withName("unrelated");
- addAllToList();
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ expectedCall1->withParameter("boo", 2);
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->withParameter("boo", 10);
+ expectedCalls.addFunction("unrelated");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
MockNamedValue actualParameter("boo");
actualParameter.setValue(20);
- MockUnexpectedInputParameterFailure failure(UtestShell::getCurrent(), "foo", actualParameter, *list);
+ MockUnexpectedInputParameterFailure failure(UtestShell::getCurrent(), "foo", actualParameter, expectedCalls, actualCalls);
STRCMP_EQUAL("Mock Failure: Unexpected parameter value to parameter \"boo\" to function \"foo\": <20 (0x14)>\n"
- "\tEXPECTED calls that DID NOT happen related to function: foo\n"
- "\t\tfoo -> int boo: <2 (0x2)>\n"
- "\t\tfoo -> int boo: <10 (0xa)>\n"
- "\tACTUAL calls that DID happen related to function: foo\n"
- "\t\t\n"
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\tfoo -> int boo: <10 (0xa)> (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\tfoo -> int boo: <2 (0x2)> (called 1 time)\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
+ "\t\t(1) foo -> int boo: <2 (0x2)>\n"
"\tACTUAL unexpected parameter passed to function: foo\n"
"\t\tint boo: <20 (0x14)>", failure.getMessage().asCharString());
}
-TEST(MockFailureTest, MockExpectedParameterDidntHappenFailure)
+TEST(MockFailureTest, MockExpectedParameterDidntHappenFailure_AllParametersMissing)
{
- call1->withName("foo").withParameter("bar", 2).withParameter("boo", "str");
- call2->withName("foo").withParameter("bar", 10).withParameter("boo", "bleh");
- call2->callWasMade(1);
- call2->inputParameterWasPassed("bar");
- call2->inputParameterWasPassed("boo");
- call3->withName("unrelated");
- addAllToList();
-
- MockExpectedParameterDidntHappenFailure failure(UtestShell::getCurrent(), "foo", *list);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ expectedCall1->withParameter("bar", 2).withParameter("boo", "str");
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->withParameter("bar", 10).withParameter("boo", "bleh");
+ MockCheckedExpectedCall* expectedCall3 = expectedCalls.addFunction("unrelated");
+ MockCheckedExpectedCall* expectedCall4 = expectedCalls.addFunction("foo");
+ expectedCall4->withParameter("bar", 10).withParameter("boo", "blih");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall4);
+ actualCalls.addCall(2, expectedCall3);
+ actualCalls.addCall(3, expectedCall2);
+
+ MockExpectedParameterDidntHappenFailure failure(UtestShell::getCurrent(), "foo", expectedCalls, actualCalls);
STRCMP_EQUAL("Mock Failure: Expected parameter for function \"foo\" did not happen.\n"
- "\tEXPECTED calls that DID NOT happen related to function: foo\n"
- "\t\tfoo -> int bar: <2 (0x2)>, const char* boo: \n"
- "\tACTUAL calls that DID happen related to function: foo\n"
- "\t\tfoo -> int bar: <10 (0xa)>, const char* boo: \n"
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\tfoo -> int bar: <2 (0x2)>, const char* boo: (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\tfoo -> int bar: <10 (0xa)>, const char* boo: (called 1 time)\n"
+ "\t\tfoo -> int bar: <10 (0xa)>, const char* boo: (called 1 time)\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
+ "\t\t(1) foo -> int bar: <10 (0xa)>, const char* boo: \n"
+ "\t\t(3) foo -> int bar: <10 (0xa)>, const char* boo: \n"
"\tMISSING parameters that didn't happen:\n"
"\t\tint bar, const char* boo", failure.getMessage().asCharString());
}
+TEST(MockFailureTest, MockExpectedParameterDidntHappenFailure_SomeParametersMissing)
+{
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ expectedCall1->withParameter("bar", 2).withParameter("boo", "str1");
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->withParameter("bar", 10).withParameter("boo", "bleh");
+ MockCheckedExpectedCall* expectedCall3 = expectedCalls.addFunction("unrelated");
+ MockCheckedExpectedCall* expectedCall4 = expectedCalls.addFunction("foo");
+ expectedCall4->withParameter("bar", 10).withParameter("boo", "blih");
+ MockCheckedExpectedCall* expectedCall5 = expectedCalls.addFunction("foo");
+ expectedCall5->withParameter("bar", 2).withParameter("baa", "str2");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall4);
+ actualCalls.addCall(2, expectedCall3);
+ actualCalls.addCall(3, expectedCall2);
+
+ expectedCall1->inputParameterWasPassed("bar");
+ expectedCall5->inputParameterWasPassed("bar");
+
+ MockExpectedParameterDidntHappenFailure failure(UtestShell::getCurrent(), "foo", expectedCalls, actualCalls);
+ STRCMP_EQUAL("Mock Failure: Expected parameter for function \"foo\" did not happen.\n"
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\tfoo -> int bar: <2 (0x2)>, const char* boo: (expected 1 call, but was called 0 times)\n"
+ "\t\tfoo -> int bar: <2 (0x2)>, const char* baa: (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\tfoo -> int bar: <10 (0xa)>, const char* boo: (called 1 time)\n"
+ "\t\tfoo -> int bar: <10 (0xa)>, const char* boo: (called 1 time)\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
+ "\t\t(1) foo -> int bar: <10 (0xa)>, const char* boo: \n"
+ "\t\t(3) foo -> int bar: <10 (0xa)>, const char* boo: \n"
+ "\tMISSING parameters that didn't happen:\n"
+ "\t\tconst char* boo\n"
+ "\t\tconst char* baa", failure.getMessage().asCharString());
+}
+
+TEST(MockFailureTest, MockExpectedParameterDidntHappenFailure_WithOptionalCalls)
+{
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction(2, 3, "foo");
+ expectedCall1->withParameter("bar", 2).withParameter("boo", "str1");
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->withParameter("bar", 10).withParameter("boo", "bleh");
+ MockCheckedExpectedCall* expectedCall3 = expectedCalls.addFunction("unrelated");
+ MockCheckedExpectedCall* expectedCall4 = expectedCalls.addFunction("foo");
+ expectedCall4->withParameter("bar", 10).withParameter("boo", "blih");
+ MockCheckedExpectedCall* expectedCall5 = expectedCalls.addFunction("foo");
+ expectedCall5->withParameter("bar", 2).withParameter("baa", "str2");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+ actualCalls.addCall(2, expectedCall4);
+ actualCalls.addCall(3, expectedCall3);
+ actualCalls.addCall(4, expectedCall2);
+ actualCalls.addCall(5, expectedCall1);
+
+ expectedCall1->inputParameterWasPassed("bar");
+ expectedCall5->inputParameterWasPassed("bar");
+
+ MockExpectedParameterDidntHappenFailure failure(UtestShell::getCurrent(), "foo", expectedCalls, actualCalls);
+ STRCMP_EQUAL("Mock Failure: Expected parameter for function \"foo\" did not happen.\n"
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\tfoo -> int bar: <2 (0x2)>, const char* baa: (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\tfoo -> int bar: <2 (0x2)>, const char* boo: (called 2 times)\n"
+ "\t\tfoo -> int bar: <10 (0xa)>, const char* boo: (called 1 time)\n"
+ "\t\tfoo -> int bar: <10 (0xa)>, const char* boo: (called 1 time)\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
+ "\t\t(1) foo -> int bar: <2 (0x2)>, const char* boo: \n"
+ "\t\t(2) foo -> int bar: <10 (0xa)>, const char* boo: \n"
+ "\t\t(4) foo -> int bar: <10 (0xa)>, const char* boo: \n"
+ "\t\t(5) foo -> int bar: <2 (0x2)>, const char* boo: \n"
+ "\tMISSING parameters that didn't happen:\n"
+ "\t\tconst char* boo\n"
+ "\t\tconst char* baa", failure.getMessage().asCharString());
+}
+
TEST(MockFailureTest, MockNoWayToCompareCustomTypeFailure)
{
MockNoWayToCompareCustomTypeFailure failure(UtestShell::getCurrent(), "myType");
@@ -220,39 +311,49 @@ TEST(MockFailureTest, MockNoWayToCompareCustomTypeFailure)
TEST(MockFailureTest, MockUnexpectedObjectFailure)
{
- call1->withName("foo").onObject((void*) 0x02);
- call2->withName("foo").onObject((void*) 0x03);
- call2->callWasMade(1);
- call2->wasPassedToObject();
- call3->withName("unrelated");
- addAllToList();
-
- MockUnexpectedObjectFailure failure(UtestShell::getCurrent(), "foo", (void*)0x1, *list);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ expectedCall1->onObject((void*) 0x02);
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->onObject((void*) 0x03);
+ expectedCalls.addFunction("unrelated");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall2);
+
+ MockUnexpectedObjectFailure failure(UtestShell::getCurrent(), "foo", (void*)0x1, expectedCalls, actualCalls);
STRCMP_EQUAL(StringFromFormat (
"MockFailure: Function called on an unexpected object: foo\n"
"\tActual object for call has address: <%p>\n"
- "\tEXPECTED calls that DID NOT happen related to function: foo\n"
- "\t\t(object address: %p)::foo -> no parameters\n"
- "\tACTUAL calls that DID happen related to function: foo\n"
- "\t\t(object address: %p)::foo -> no parameters",
- (void*) 0x01, (void*) 0x02, (void*) 0x03).asCharString(), failure.getMessage().asCharString());
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\t(object address: %p)::foo -> no parameters (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\t(object address: %p)::foo -> no parameters (called 1 time)\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
+ "\t\t(1) (object address: %p)::foo -> no parameters",
+ (void*) 0x01, (void*) 0x02, (void*) 0x03, (void*) 0x03).asCharString(), failure.getMessage().asCharString());
}
TEST(MockFailureTest, MockExpectedObjectDidntHappenFailure)
{
- call1->withName("foo").onObject((void*) 0x02);
- call2->withName("foo").onObject((void*) 0x03);
- call2->callWasMade(1);
- call2->wasPassedToObject();
- call3->withName("unrelated");
- addAllToList();
-
- MockExpectedObjectDidntHappenFailure failure(UtestShell::getCurrent(), "foo", *list);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo");
+ expectedCall1->onObject((void*) 0x02);
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo");
+ expectedCall2->onObject((void*) 0x03);
+ expectedCalls.addFunction("unrelated");
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall2);
+
+ MockExpectedObjectDidntHappenFailure failure(UtestShell::getCurrent(), "foo", expectedCalls, actualCalls);
STRCMP_EQUAL(StringFromFormat(
"Mock Failure: Expected call on object for function \"foo\" but it did not happen.\n"
- "\tEXPECTED calls that DID NOT happen related to function: foo\n"
- "\t\t(object address: %p)::foo -> no parameters\n"
- "\tACTUAL calls that DID happen related to function: foo\n"
- "\t\t(object address: %p)::foo -> no parameters",
- (void*) 0x2, (void*) 0x3).asCharString(), failure.getMessage().asCharString());
+ "\tEXPECTED calls that WERE NOT fulfilled related to function: foo\n"
+ "\t\t(object address: %p)::foo -> no parameters (expected 1 call, but was called 0 times)\n"
+ "\tEXPECTED calls that WERE fulfilled related to function: foo\n"
+ "\t\t(object address: %p)::foo -> no parameters (called 1 time)\n"
+ "\tACTUAL calls that were expected (in call order) for function: foo\n"
+ "\t\t(1) (object address: %p)::foo -> no parameters",
+ (void*) 0x2, (void*) 0x3, (void*) 0x3).asCharString(), failure.getMessage().asCharString());
}
diff --git a/tests/CppUTestExt/MockHierarchyTest.cpp b/tests/CppUTestExt/MockHierarchyTest.cpp
index 800ec74dc..620ea6479 100644
--- a/tests/CppUTestExt/MockHierarchyTest.cpp
+++ b/tests/CppUTestExt/MockHierarchyTest.cpp
@@ -96,7 +96,8 @@ TEST(MockHierarchyTest, checkExpectationsWorksHierarchically)
MockExpectedCallsListForTest expectations;
expectations.addFunction("first::foobar");
expectations.addFunction("second::helloworld");
- MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectations, actualCalls);
mock("first").expectOneCall("foobar");
mock("second").expectOneCall("helloworld");
@@ -128,7 +129,8 @@ TEST(MockHierarchyTest, checkExpectationsWorksHierarchicallyForLastCallNotFinish
MockExpectedCallsListForTest expectations;
expectations.addFunction("first::foobar")->withParameter("boo", 1);
- MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "first::foobar", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "first::foobar", expectations, actualCalls);
mock("first").expectOneCall("foobar").withParameter("boo", 1);
mock("first").actualCall("foobar");
@@ -144,7 +146,8 @@ TEST(MockHierarchyTest, reporterIsInheritedInHierarchicalMocks)
mock("differentScope").actualCall("foobar");
- MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "differentScope::foobar", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedCallHappenedFailure expectedFailure(mockFailureTest(), "differentScope::foobar", expectations, actualCalls);
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
}
diff --git a/tests/CppUTestExt/MockParameterTest.cpp b/tests/CppUTestExt/MockParameterTest.cpp
index bd9cf0062..aa192f045 100644
--- a/tests/CppUTestExt/MockParameterTest.cpp
+++ b/tests/CppUTestExt/MockParameterTest.cpp
@@ -136,7 +136,8 @@ TEST(MockParameterTest, longAndUnsignedLongWithSameBitRepresentationShouldNotBeT
expectations.addFunction("foo")->withParameter("parameter", (long)-1);
MockNamedValue parameter("parameter");
parameter.setValue((unsigned long)-1);
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", (long)-1);
mock().actualCall("foo").withParameter("parameter", (unsigned long)-1);
@@ -152,7 +153,8 @@ TEST(MockParameterTest, unsignedLongAndLongWithSameBitRepresentationShouldnotBeT
expectations.addFunction("foo")->withParameter("parameter", (unsigned long)-1);
MockNamedValue parameter("parameter");
parameter.setValue((long)-1);
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", (unsigned long)-1);
mock().actualCall("foo").withParameter("parameter", (long)-1);
@@ -220,7 +222,8 @@ TEST(MockParameterTest, expectOneMemBufferParameterAndValueFailsDueToContents)
expectations.addFunction("foo")->withParameter("parameter", memBuffer1, sizeof(memBuffer1));
MockNamedValue parameter("parameter");
parameter.setMemoryBuffer( memBuffer2, sizeof(memBuffer2) );
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", memBuffer1, sizeof(memBuffer1));
mock().actualCall("foo").withParameter("parameter", memBuffer2, sizeof(memBuffer2));
@@ -239,7 +242,8 @@ TEST(MockParameterTest, expectOneMemBufferParameterAndValueFailsDueToSize)
expectations.addFunction("foo")->withParameter("parameter", memBuffer1, sizeof(memBuffer1));
MockNamedValue parameter("parameter");
parameter.setMemoryBuffer( memBuffer2, sizeof(memBuffer2) );
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", memBuffer1, sizeof(memBuffer1));
mock().actualCall("foo").withParameter("parameter", memBuffer2, sizeof(memBuffer2));
@@ -255,7 +259,8 @@ TEST(MockParameterTest, expectOneStringParameterAndValueFails)
expectations.addFunction("foo")->withParameter("parameter", "string");
MockNamedValue parameter("parameter");
parameter.setValue("different");
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", "string");
mock().actualCall("foo").withParameter("parameter", "different");
@@ -272,7 +277,8 @@ TEST(MockParameterTest, expectOneUnsignedIntegerParameterAndFailsDueToParameterN
expectations.addFunction("foo")->withParameter("parameter", value);
MockNamedValue parameter("different");
parameter.setValue(value);
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", value);
mock().actualCall("foo").withParameter("different", value);
@@ -288,7 +294,8 @@ TEST(MockParameterTest, expectOneIntegerParameterAndFailsDueToParameterName)
expectations.addFunction("foo")->withParameter("parameter", 10);
MockNamedValue parameter("different");
parameter.setValue(10);
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", 10);
mock().actualCall("foo").withParameter("different", 10);
@@ -306,7 +313,8 @@ TEST(MockParameterTest, expectOneUnsignedIntegerParameterAndFailsDueToValue)
expectations.addFunction("foo")->withParameter("parameter", expected_value);
MockNamedValue parameter("parameter");
parameter.setValue(actual_value);
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", expected_value);
mock().actualCall("foo").withParameter("parameter", actual_value);
@@ -322,7 +330,8 @@ TEST(MockParameterTest, expectOneIntegerParameterAndFailsDueToValue)
expectations.addFunction("foo")->withParameter("parameter", 10);
MockNamedValue parameter("parameter");
parameter.setValue(8);
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", 10);
mock().actualCall("foo").withParameter("parameter", 8);
@@ -338,7 +347,8 @@ TEST(MockParameterTest, expectOneIntegerParameterAndFailsDueToTypes)
expectations.addFunction("foo")->withParameter("parameter", 10);
MockNamedValue parameter("parameter");
parameter.setValue("heh");
- MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().expectOneCall("foo").withParameter("parameter", 10);
mock().actualCall("foo").withParameter("parameter", "heh");
@@ -383,7 +393,8 @@ TEST(MockParameterTest, calledWithoutParameters)
MockExpectedCallsListForTest expectations;
expectations.addFunction("foo")->withParameter("p1", 1);
- MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations, actualCalls);
mock().expectOneCall("foo").withParameter("p1", 1);
mock().actualCall("foo");
@@ -414,7 +425,8 @@ TEST(MockParameterTest, ignoreOtherParametersButExpectedParameterDidntHappen)
MockExpectedCallsListForTest expectations;
expectations.addFunction("foo")->withParameter("p1", 1).ignoreOtherParameters();
- MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations, actualCalls);
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters();
mock().actualCall("foo").withParameter("p2", 2).withParameter("p3", 3).withParameter("p4", 4);
@@ -438,14 +450,16 @@ 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);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("boo");
+ expectedCall1->ignoreOtherParameters();
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("boo");
+ expectedCall2->ignoreOtherParameters();
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectedCalls, actualCalls);
mock().expectOneCall("boo").ignoreOtherParameters();
mock().expectOneCall("boo").ignoreOtherParameters();
@@ -461,7 +475,8 @@ TEST(MockParameterTest, newCallStartsWhileNotAllParametersWerePassed)
MockExpectedCallsListForTest expectations;
expectations.addFunction("foo")->withParameter("p1", 1);
- MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations, actualCalls);
mock().expectOneCall("foo").withParameter("p1", 1);
mock().actualCall("foo");
@@ -492,7 +507,8 @@ TEST(MockParameterTest, noActualCallForOutputParameter)
mock().expectOneCall("foo").withOutputParameterReturning("output", &output, sizeof(output));
expectations.addFunction("foo")->withOutputParameterReturning("output", &output, sizeof(output));
- MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(mockFailureTest(), expectations, actualCalls);
mock().checkExpectations();
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
@@ -510,7 +526,8 @@ TEST(MockParameterTest, unexpectedOutputParameter)
expectations.addFunction("foo");
MockNamedValue parameter("parameterName");
parameter.setValue(¶m);
- MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations, actualCalls);
mock().checkExpectations();
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
@@ -526,7 +543,8 @@ TEST(MockParameterTest, outputParameterMissing)
mock().actualCall("foo");
expectations.addFunction("foo")->withOutputParameterReturning("output", &output, sizeof(output));
- MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations, actualCalls);
mock().checkExpectations();
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
diff --git a/tests/CppUTestExt/MockPluginTest.cpp b/tests/CppUTestExt/MockPluginTest.cpp
index ae1739b86..0ded4a75e 100644
--- a/tests/CppUTestExt/MockPluginTest.cpp
+++ b/tests/CppUTestExt/MockPluginTest.cpp
@@ -59,7 +59,8 @@ TEST(MockPlugin, checkExpectationsAndClearAtEnd)
MockExpectedCallsListForTest expectations;
expectations.addFunction("foobar");
- MockExpectedCallsDidntHappenFailure expectedFailure(test, expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedCallsNotFulfilledFailure expectedFailure(test, expectations, actualCalls);
mock().expectOneCall("foobar");
@@ -76,7 +77,8 @@ TEST(MockPlugin, checkExpectationsWorksAlsoWithHierachicalObjects)
MockExpectedCallsListForTest expectations;
expectations.addFunction("differentScope::foobar")->onObject((void*) 1);
- MockExpectedObjectDidntHappenFailure expectedFailure(test, "differentScope::foobar", expectations);
+ MockActualCallsQueueForTest actualCalls;
+ MockExpectedObjectDidntHappenFailure expectedFailure(test, "differentScope::foobar", expectations, actualCalls);
mock("differentScope").expectOneCall("foobar").onObject((void*) 1);
mock("differentScope").actualCall("foobar");
diff --git a/tests/CppUTestExt/MockStrictOrderTest.cpp b/tests/CppUTestExt/MockStrictOrderTest.cpp
index 41fe96d9d..cf4e79f61 100644
--- a/tests/CppUTestExt/MockStrictOrderTest.cpp
+++ b/tests/CppUTestExt/MockStrictOrderTest.cpp
@@ -50,7 +50,7 @@ TEST(MockStrictOrderTest, OrderObserved)
TEST(MockStrictOrderTest, someOrderObserved)
{
- mock().expectOneCall("foo3").withCallOrder(3);
+ mock().expectOneCall("foo3").withCallOrder(3, 3);
mock().expectOneCall("foo1");
mock().expectOneCall("foo2");
mock().actualCall("foo2");
@@ -63,14 +63,20 @@ TEST(MockStrictOrderTest, someOrderObserved)
TEST(MockStrictOrderTest, orderViolated)
{
MockFailureReporterInstaller failureReporterInstaller;
- mock().strictOrder();
- MockExpectedCallsListForTest expectations;
- expectations.addFunction("foo1", 1)->callWasMade(1);
- expectations.addFunction("foo1", 2)->callWasMade(3);
- expectations.addFunction("foo2", 3)->callWasMade(2);
- MockCallOrderFailure expectedFailure(mockFailureTest(), expectations);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("foo1", 1);
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("foo1", 2);
+ MockCheckedExpectedCall* expectedCall3 = expectedCalls.addFunction("foo2", 3);
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, expectedCall1);
+ actualCalls.addCall(2, expectedCall3);
+ actualCalls.addCall(3, expectedCall2);
+
+ MockCallOrderFailure expectedFailure(mockFailureTest(), expectedCalls, actualCalls);
+ mock().strictOrder();
mock().expectOneCall("foo1");
mock().expectOneCall("foo1");
mock().expectOneCall("foo2");
@@ -85,14 +91,23 @@ TEST(MockStrictOrderTest, orderViolated)
TEST(MockStrictOrderTest, orderViolatedWorksHierarchically)
{
MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCallsReported;
+ MockExpectedCallsListForTest expectedCallsNotReported;
+ MockCheckedExpectedCall* expectedCall1 = expectedCallsNotReported.addFunction("bla::foo1", 1);
+ MockCheckedExpectedCall* expectedCall2 = expectedCallsReported.addFunction("foo::foo1", 1);
+ MockCheckedExpectedCall* expectedCall3 = expectedCallsReported.addFunction("foo::foo2", 2);
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, "bla", expectedCall1);
+ actualCalls.addCall(1, "foo", expectedCall3);
+ actualCalls.addCall(2, "foo", expectedCall2);
+
+ MockCallOrderFailure expectedFailure(mockFailureTest(), expectedCallsReported, actualCalls);
+
mock().strictOrder();
mock("bla").strictOrder();
- MockExpectedCallsListForTest expectations;
- expectations.addFunction("foo::foo1", 1)->callWasMade(2);
- expectations.addFunction("foo::foo2", 2)->callWasMade(1);
- MockCallOrderFailure expectedFailure(mockFailureTest(), expectations);
-
mock("bla").expectOneCall("foo1");
mock("foo").expectOneCall("foo1");
mock("foo").expectOneCall("foo2");
@@ -108,14 +123,23 @@ TEST(MockStrictOrderTest, orderViolatedWorksHierarchically)
TEST(MockStrictOrderTest, orderViolatedWorksWithExtraUnexpectedCall)
{
MockFailureReporterInstaller failureReporterInstaller;
+
+ MockExpectedCallsListForTest expectedCallsReported;
+ MockExpectedCallsListForTest expectedCallsNotReported;
+ MockCheckedExpectedCall* expectedCall1 = expectedCallsNotReported.addFunction("bla::foo1", 1);
+ MockCheckedExpectedCall* expectedCall2 = expectedCallsReported.addFunction("foo::foo1", 1);
+ MockCheckedExpectedCall* expectedCall3 = expectedCallsReported.addFunction("foo::foo2", 2);
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, "bla", expectedCall1);
+ actualCalls.addCall(1, "foo", expectedCall3);
+ actualCalls.addCall(2, "foo", expectedCall2);
+
+ MockCallOrderFailure expectedFailure(mockFailureTest(), expectedCallsReported, actualCalls);
+
mock().strictOrder();
mock("bla").strictOrder();
- mock().ignoreOtherCalls();
-
- MockExpectedCallsListForTest expectations;
- expectations.addFunction("foo::foo1", 1)->callWasMade(2);
- expectations.addFunction("foo::foo2", 2)->callWasMade(1);
- MockCallOrderFailure expectedFailure(mockFailureTest(), expectations);
+ mock().ignoreOtherCalls();
mock("bla").expectOneCall("foo1");
mock("foo").expectOneCall("foo1");
@@ -123,9 +147,9 @@ TEST(MockStrictOrderTest, orderViolatedWorksWithExtraUnexpectedCall)
mock("bla").actualCall("foo1");
mock("foo").actualCall("foo2");
- mock("foo").actualCall("unexpected1");
+ mock("foo").actualCall("unexpected1");
mock("foo").actualCall("foo1");
- mock("foo").actualCall("unexpected2");
+ mock("foo").actualCall("unexpected2");
mock().checkExpectations();
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
@@ -136,10 +160,15 @@ TEST(MockStrictOrderTest, orderViolatedWithinAScope)
MockFailureReporterInstaller failureReporterInstaller;
mock().strictOrder();
- MockExpectedCallsListForTest expectations;
- expectations.addFunction("scope::foo1", 1)->callWasMade(2);
- expectations.addFunction("scope::foo2", 2)->callWasMade(1);
- MockCallOrderFailure expectedFailure(mockFailureTest(), expectations);
+ MockExpectedCallsListForTest expectedCalls;
+ MockCheckedExpectedCall* expectedCall1 = expectedCalls.addFunction("scope::foo1", 1);
+ MockCheckedExpectedCall* expectedCall2 = expectedCalls.addFunction("scope::foo2", 2);
+
+ MockActualCallsQueueForTest actualCalls;
+ actualCalls.addCall(1, "scope", expectedCall2);
+ actualCalls.addCall(2, "scope", expectedCall1);
+
+ MockCallOrderFailure expectedFailure(mockFailureTest(), expectedCalls, actualCalls);
mock("scope").expectOneCall("foo1");
mock("scope").expectOneCall("foo2");
@@ -185,11 +214,37 @@ TEST(MockStrictOrderTest, orderUsingNCalls)
mock().expectOneCall("foo1");
mock().expectNCalls(2, "foo2");
mock().expectOneCall("foo1");
+ mock().expectNCalls(3, "foo2");
+
mock().actualCall("foo1");
mock().actualCall("foo2");
mock().actualCall("foo2");
mock().actualCall("foo1");
+ mock().actualCall("foo2");
+ mock().actualCall("foo2");
+ mock().actualCall("foo2");
mock().checkExpectations();
}
+TEST(MockStrictOrderTest, orderUsingOptionalCalls)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ mock().strictOrder();
+ mock().expectRangeOfCalls(0, 1, "foo");
+
+ MockStrictOrderingIncompatibleWithOptionalCallsFailure expectedFailure(mockFailureTest(), "foo", 0, 1);
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
+
+TEST(MockStrictOrderTest, orderUsingOptionalCallsOnScope)
+{
+ MockFailureReporterInstaller failureReporterInstaller;
+
+ mock("bar").strictOrder();
+ mock("bar").expectRangeOfCalls(5, 11, "foo");
+
+ MockStrictOrderingIncompatibleWithOptionalCallsFailure expectedFailure(mockFailureTest(), "bar::foo", 5, 11);
+ CHECK_EXPECTED_MOCK_FAILURE(expectedFailure);
+}
diff --git a/tests/CppUTestExt/MockSupportTest.cpp b/tests/CppUTestExt/MockSupportTest.cpp
index 4c616dd5d..e99a19319 100644
--- a/tests/CppUTestExt/MockSupportTest.cpp
+++ b/tests/CppUTestExt/MockSupportTest.cpp
@@ -146,6 +146,43 @@ TEST(MockSupportTest, tracing)
STRCMP_CONTAINS("foo", mock().getTraceOutput());
}
+TEST(MockSupportTest, setMaxCallLogSize)
+{
+ mock("bii").setMaxCallLogSize(10);
+ mock().setMaxCallLogSize(2);
+ mock("foo").setMaxCallLogSize(3);
+
+ mock().expectAnyCalls("boo");
+ mock("foo").expectAnyCalls("baa");
+ mock("bar").expectAnyCalls("buu");
+ mock("bii").expectAnyCalls("bee");
+
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock().actualCall("boo");
+ mock("foo").actualCall("baa");
+ mock("foo").actualCall("baa");
+ mock("foo").actualCall("baa");
+ mock("foo").actualCall("baa");
+ mock("foo").actualCall("baa");
+ mock("foo").actualCall("baa");
+ mock("foo").actualCall("baa");
+ mock("bar").actualCall("buu");
+ mock("bar").actualCall("buu");
+ mock("bar").actualCall("buu");
+ mock("bar").actualCall("buu");
+ mock("bar").actualCall("buu");
+ mock("bii").actualCall("bee");
+ mock("bii").actualCall("bee");
+ mock("bii").actualCall("bee");
+ mock("bii").actualCall("bee");
+
+ LONGS_EQUAL(2, mock().getActualCalls().size())
+ LONGS_EQUAL(3, mock("foo").getActualCalls().size())
+ LONGS_EQUAL(2, mock("bar").getActualCalls().size())
+ LONGS_EQUAL(2, mock("bii").getActualCalls().size())
+}
+
TEST(MockSupportTest, tracingWorksHierarchically)
{
mock("scope").tracing(true);
@@ -166,8 +203,9 @@ TEST_GROUP(MockSupportTestWithFixture)
static void CHECK_EXPECTED_MOCK_FAILURE_LOCATION_failedTestMethod_()
{
- MockExpectedCallsList list;
- MockUnexpectedCallHappenedFailure expectedFailure(UtestShell::getCurrent(), "unexpected", list);
+ MockExpectedCallsList expectedCalls;
+ MockActualCallsQueue actualCalls(false);
+ MockUnexpectedCallHappenedFailure expectedFailure(UtestShell::getCurrent(), "unexpected", expectedCalls, actualCalls);
mock().actualCall("boo");
CHECK_EXPECTED_MOCK_FAILURE_LOCATION(expectedFailure, "file", 1);
}
diff --git a/tests/CppUTestExt/MockSupport_cTest.cpp b/tests/CppUTestExt/MockSupport_cTest.cpp
index 5188857f3..e22a7855b 100644
--- a/tests/CppUTestExt/MockSupport_cTest.cpp
+++ b/tests/CppUTestExt/MockSupport_cTest.cpp
@@ -92,6 +92,52 @@ TEST(MockSupport_c, expectNoCall)
mock_c()->checkExpectations();
}
+TEST(MockSupport_c, expectAtLeastOneCallFulfilled)
+{
+ mock_c()->expectAtLeastOneCall("boo");
+ mock_c()->actualCall("boo");
+ mock_c()->checkExpectations();
+}
+
+TEST(MockSupport_c, expectAtLeastNCallsFulfilled)
+{
+ mock_c()->expectAtLeastNCalls(2, "boo");
+ mock_c()->actualCall("boo");
+ mock_c()->actualCall("boo");
+ mock_c()->checkExpectations();
+}
+
+TEST(MockSupport_c, expectAtMostOneCallFulfilled)
+{
+ mock_c()->expectAtMostOneCall("boo");
+ mock_c()->checkExpectations();
+}
+
+TEST(MockSupport_c, expectAtMostNCallsFulfilled)
+{
+ mock_c()->expectAtMostNCalls(4, "boo");
+ mock_c()->actualCall("boo");
+ mock_c()->actualCall("boo");
+ mock_c()->actualCall("boo");
+ mock_c()->actualCall("boo");
+ mock_c()->checkExpectations();
+}
+
+TEST(MockSupport_c, expectAnyCallsFulfilled)
+{
+ mock_c()->expectAnyCalls("boo");
+ mock_c()->checkExpectations();
+}
+
+TEST(MockSupport_c, expectRangeOfCallsFulfilled)
+{
+ mock_c()->expectRangeOfCalls(2, 4, "boo");
+ mock_c()->actualCall("boo");
+ mock_c()->actualCall("boo");
+ mock_c()->actualCall("boo");
+ mock_c()->checkExpectations();
+}
+
TEST(MockSupport_c, expectAndActualParameters)
{
mock_c()->expectOneCall("boo")->withIntParameters("integer", 1)->withDoubleParameters("double", 1.0)->
@@ -650,3 +696,23 @@ TEST(MockSupport_c, ignoreOtherCalls)
mock_c()->actualCall("bar");
mock_c()->checkExpectations();
}
+
+static void failingUnexpectedCallWithActualCallLogLimited_()
+{
+ mock_c()->setMaxCallLogSize(2);
+ mock_c()->expectAnyCalls("foo");
+ mock_c()->actualCall("foo");
+ mock_c()->actualCall("foo");
+ mock_c()->actualCall("foo");
+ mock_c()->actualCall("bar");
+} // LCOV_EXCL_LINE
+
+TEST(MockSupport_c, setMaxCallLogSize)
+{
+ TestTestingFixture fixture;
+ fixture.runTestWithMethod(failingUnexpectedCallWithActualCallLogLimited_);
+ fixture.assertPrintContains("ACTUAL calls that were expected (in call order):\n"
+ "\t\t(2) foo -> no parameters\n"
+ "\t\t(3) foo -> no parameters");
+}
+