CppUTest
MockActualFunctionCall.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_MockActualFunctionCall_h
29 #define D_MockActualFunctionCall_h
30 
31 #include "CppUTestExt/MockFunctionCall.h"
32 #include "CppUTestExt/MockExpectedFunctionsList.h"
33 
35 class MockFailure;
36 class MockNamedValue;
37 
39 {
40 public:
41  MockActualFunctionCall(int callOrder, MockFailureReporter* reporter, const MockExpectedFunctionsList& expectations);
42  virtual ~MockActualFunctionCall();
43 
44  virtual MockFunctionCall& withName(const SimpleString& name);
45  virtual MockFunctionCall& withCallOrder(int);
46  virtual MockFunctionCall& withParameter(const SimpleString& name, int value);
47  virtual MockFunctionCall& withParameter(const SimpleString& name, double value);
48  virtual MockFunctionCall& withParameter(const SimpleString& name, const char* value);
49  virtual MockFunctionCall& withParameter(const SimpleString& name, void* value);
50  virtual MockFunctionCall& withParameterOfType(const SimpleString& type, const SimpleString& name, void* value);
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 bool isFulfilled() const;
62  virtual bool hasFailed() const;
63 
64  virtual void checkExpectations();
65 
66  virtual void setMockFailureReporter(MockFailureReporter* reporter);
67 protected:
68  virtual UtestShell* getTest() const;
69  virtual void callHasSucceeded();
70  virtual void finnalizeCallWhenFulfilled();
71  virtual void failTest(const MockFailure& failure);
72  virtual void checkActualParameter(const MockNamedValue& actualParameter);
73 
74  enum ActualCallState {
75  CALL_IN_PROGESS,
76  CALL_FAILED,
77  CALL_SUCCEED
78  };
79  virtual const char* stringFromState(ActualCallState state);
80  virtual void setState(ActualCallState state);
81  virtual void checkStateConsistency(ActualCallState oldState, ActualCallState newState);
82 
83 private:
84  int callOrder_;
85  MockFailureReporter* reporter_;
86 
87  ActualCallState state_;
88  MockExpectedFunctionCall* _fulfilledExpectation;
89 
90  MockExpectedFunctionsList unfulfilledExpectations_;
91  const MockExpectedFunctionsList& allExpectations_;
92 };
93 
94 #endif
Definition: SimpleString.h:46
Definition: Utest.h:61
Definition: MockExpectedFunctionCall.h:36
Definition: MockExpectedFunctionsList.h:34
Definition: MockFailure.h:54
Definition: MockFunctionCall.h:40
Definition: MockNamedValue.h:69
Definition: MockActualFunctionCall.h:38
Definition: MockFailure.h:39