NetBurner 3.1
MockFailure.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 
29 #ifndef D_MockFailure_h
30 #define D_MockFailure_h
31 
32 #include "CppUTest/TestFailure.h"
33 
34 class MockExpectedCallsList;
35 class MockCheckedActualCall;
36 class MockNamedValue;
37 class MockFailure;
38 
39 class MockFailureReporter
40 {
41 protected:
42  bool crashOnFailure_;
43 public:
44  MockFailureReporter() : crashOnFailure_(false){}
45  virtual ~MockFailureReporter() {}
46 
47  virtual void failTest(const MockFailure& failure);
48  virtual UtestShell* getTestToFail();
49 
50  virtual void crashOnFailure(bool shouldCrash) { crashOnFailure_ = shouldCrash; }
51 };
52 
53 class MockFailure : public TestFailure
54 {
55 public:
56  MockFailure(UtestShell* test);
57  virtual ~MockFailure(){}
58 protected:
59  void addExpectationsAndCallHistory(const MockExpectedCallsList& expectations);
60  void addExpectationsAndCallHistoryRelatedTo(const SimpleString& function, const MockExpectedCallsList& expectations);
61 };
62 
63 class MockExpectedCallsDidntHappenFailure : public MockFailure
64 {
65 public:
66  MockExpectedCallsDidntHappenFailure(UtestShell* test, const MockExpectedCallsList& expectations);
67 };
68 
69 class MockUnexpectedCallHappenedFailure : public MockFailure
70 {
71 public:
72  MockUnexpectedCallHappenedFailure(UtestShell* test, const SimpleString& name, const MockExpectedCallsList& expectations);
73 };
74 
75 class MockCallOrderFailure : public MockFailure
76 {
77 public:
78  MockCallOrderFailure(UtestShell* test, const MockExpectedCallsList& expectations);
79 };
80 
81 class MockUnexpectedInputParameterFailure : public MockFailure
82 {
83 public:
84  MockUnexpectedInputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter, const MockExpectedCallsList& expectations);
85 };
86 
87 class MockUnexpectedOutputParameterFailure : public MockFailure
88 {
89 public:
90  MockUnexpectedOutputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter, const MockExpectedCallsList& expectations);
91 };
92 
93 class MockExpectedParameterDidntHappenFailure : public MockFailure
94 {
95 public:
96  MockExpectedParameterDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations);
97 };
98 
99 class MockNoWayToCompareCustomTypeFailure : public MockFailure
100 {
101 public:
102  MockNoWayToCompareCustomTypeFailure(UtestShell* test, const SimpleString& typeName);
103 };
104 
105 class MockNoWayToCopyCustomTypeFailure : public MockFailure
106 {
107 public:
108  MockNoWayToCopyCustomTypeFailure(UtestShell* test, const SimpleString& typeName);
109 };
110 
111 class MockUnexpectedObjectFailure : public MockFailure
112 {
113 public:
114  MockUnexpectedObjectFailure(UtestShell* test, const SimpleString& functionName, const void* expected, const MockExpectedCallsList& expectations);
115 };
116 
117 class MockExpectedObjectDidntHappenFailure : public MockFailure
118 {
119 public:
120  MockExpectedObjectDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations);
121 };
122 
123 #endif