CppUTest
MockExpectedFunctionCall.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_MockExpectedFunctionCall_h
29 #define D_MockExpectedFunctionCall_h
30 
31 #include "CppUTestExt/MockFunctionCall.h"
32 #include "CppUTestExt/MockNamedValue.h"
33 
34 extern SimpleString StringFrom(const MockNamedValue& parameter);
35 
37 {
38 
39 public:
41  virtual ~MockExpectedFunctionCall();
42 
43  virtual MockFunctionCall& withName(const SimpleString& name);
44  virtual MockFunctionCall& withCallOrder(int);
45  virtual MockFunctionCall& withParameter(const SimpleString& name, int value);
46  virtual MockFunctionCall& withParameter(const SimpleString& name, double value);
47  virtual MockFunctionCall& withParameter(const SimpleString& name, const char* value);
48  virtual MockFunctionCall& withParameter(const SimpleString& name, void* value);
49  virtual MockFunctionCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, void* value);
50  virtual MockFunctionCall& ignoreOtherParameters();
51 
52  virtual MockFunctionCall& andReturnValue(int value);
53  virtual MockFunctionCall& andReturnValue(double value);
54  virtual MockFunctionCall& andReturnValue(const char* value);
55  virtual MockFunctionCall& andReturnValue(void* value);
56  virtual bool hasReturnValue();
57  virtual MockNamedValue returnValue();
58 
59  virtual MockFunctionCall& onObject(void* objectPtr);
60 
61  virtual MockNamedValue getParameter(const SimpleString& name);
62  virtual SimpleString getParameterType(const SimpleString& name);
63  virtual SimpleString getParameterValueString(const SimpleString& name);
64 
65  virtual bool hasParameterWithName(const SimpleString& name);
66  virtual bool hasParameter(const MockNamedValue& parameter);
67  virtual bool relatesTo(const SimpleString& functionName);
68  virtual bool relatesToObject(void*objectPtr) const;
69 
70  virtual bool isFulfilled();
71  virtual bool isFulfilledWithoutIgnoredParameters();
72  virtual bool areParametersFulfilled();
73  virtual bool areIgnoredParametersFulfilled();
74  virtual bool isOutOfOrder() const;
75 
76  virtual void callWasMade(int callOrder);
77  virtual void parameterWasPassed(const SimpleString& name);
78  virtual void parametersWereIgnored();
79  virtual void wasPassedToObject();
80  virtual void resetExpectation();
81 
82  virtual SimpleString callToString();
83  virtual SimpleString missingParametersToString();
84 
85  enum { NOT_CALLED_YET = -1, NO_EXPECTED_CALL_ORDER = -1};
86  virtual int getCallOrder() const;
87 private:
88 
89  class MockExpectedFunctionParameter : public MockNamedValue
90  {
91  public:
92  MockExpectedFunctionParameter(const SimpleString& name);
93  void setFulfilled(bool b);
94  bool isFulfilled() const;
95 
96  private:
97  bool fulfilled_;
98  };
99 
100  MockExpectedFunctionParameter* item(MockNamedValueListNode* node);
101 
102  bool ignoreOtherParameters_;
103  bool parametersWereIgnored_;
104  int callOrder_;
105  int expectedCallOrder_;
106  bool outOfOrder_;
107  MockNamedValueList* parameters_;
108  MockNamedValue returnValue_;
109  void* objectPtr_;
110  bool wasPassedToObject_;
111 };
112 
113 #endif
Definition: MockNamedValue.h:109
Definition: SimpleString.h:46
Definition: MockExpectedFunctionCall.h:36
Definition: MockFunctionCall.h:40
Definition: MockNamedValue.h:69
Definition: MockNamedValue.h:127