NetBurner 3.1
MockExpectedCallsList.h
1 /*
2  * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef D_MockExpectedCallsList_h
29 #define D_MockExpectedCallsList_h
30 
31 class MockCheckedExpectedCall;
32 class MockNamedValue;
33 
34 class MockExpectedCallsList
35 {
36 
37 public:
38  MockExpectedCallsList();
39  virtual ~MockExpectedCallsList();
40  virtual void deleteAllExpectationsAndClearList();
41 
42  virtual unsigned int size() const;
43  virtual unsigned int amountOfExpectationsFor(const SimpleString& name) const;
44  virtual unsigned int amountOfUnfulfilledExpectations() const;
45  virtual bool hasUnfulfilledExpectations() const;
46  virtual bool hasFinalizedMatchingExpectations() const;
47  virtual bool hasUnmatchingExpectationsBecauseOfMissingParameters() const;
48  virtual bool hasExpectationWithName(const SimpleString& name) const;
49  virtual bool hasCallsOutOfOrder() const;
50  virtual bool isEmpty() const;
51 
52  virtual void addExpectedCall(MockCheckedExpectedCall* call);
53  virtual void addExpectations(const MockExpectedCallsList& list);
54  virtual void addExpectationsRelatedTo(const SimpleString& name, const MockExpectedCallsList& list);
55 
56  virtual void onlyKeepOutOfOrderExpectations();
57  virtual void addPotentiallyMatchingExpectations(const MockExpectedCallsList& list);
58 
59  virtual void onlyKeepExpectationsRelatedTo(const SimpleString& name);
60  virtual void onlyKeepExpectationsWithInputParameter(const MockNamedValue& parameter);
61  virtual void onlyKeepExpectationsWithInputParameterName(const SimpleString& name);
62  virtual void onlyKeepExpectationsWithOutputParameter(const MockNamedValue& parameter);
63  virtual void onlyKeepExpectationsWithOutputParameterName(const SimpleString& name);
64  virtual void onlyKeepExpectationsOnObject(const void* objectPtr);
65  virtual void onlyKeepUnmatchingExpectations();
66 
67  virtual MockCheckedExpectedCall* removeFirstFinalizedMatchingExpectation();
68  virtual MockCheckedExpectedCall* removeFirstMatchingExpectation();
69  virtual MockCheckedExpectedCall* getFirstMatchingExpectation();
70 
71  virtual void resetActualCallMatchingState();
72  virtual void callWasMade(unsigned int callOrder);
73  virtual void wasPassedToObject();
74  virtual void parameterWasPassed(const SimpleString& parameterName);
75  virtual void outputParameterWasPassed(const SimpleString& parameterName);
76 
77  virtual SimpleString unfulfilledCallsToString(const SimpleString& linePrefix = "") const;
78  virtual SimpleString fulfilledCallsToString(const SimpleString& linePrefix = "") const;
79  virtual SimpleString missingParametersToString() const;
80 
81 protected:
82  virtual void pruneEmptyNodeFromList();
83 
84  class MockExpectedCallsListNode
85  {
86  public:
87  MockCheckedExpectedCall* expectedCall_;
88 
89  MockExpectedCallsListNode* next_;
90  MockExpectedCallsListNode(MockCheckedExpectedCall* expectedCall)
91  : expectedCall_(expectedCall), next_(NULL) {}
92  };
93 
94  virtual MockExpectedCallsListNode* findNodeWithCallOrderOf(unsigned int callOrder) const;
95 private:
96  MockExpectedCallsListNode* head_;
97 
98  MockExpectedCallsList(const MockExpectedCallsList&);
99 };
100 
101 #endif
#define NULL
Definition: nm_bsp.h:76