NetBurner 3.1
TestFailure.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 
29 //
30 // Failure is a class which holds information for a specific
31 // test failure. It can be overriden for more complex failure messages
32 //
34 
35 
36 #ifndef D_TestFailure_H
37 #define D_TestFailure_H
38 
39 #include "SimpleString.h"
40 
41 class UtestShell;
42 class TestOutput;
43 
44 class TestFailure
45 {
46 
47 public:
48  TestFailure(UtestShell*, const char* fileName, int lineNumber,
49  const SimpleString& theMessage);
50  TestFailure(UtestShell*, const SimpleString& theMessage);
51  TestFailure(UtestShell*, const char* fileName, int lineNumber);
52  TestFailure(const TestFailure&);
53  virtual ~TestFailure();
54 
55  virtual SimpleString getFileName() const;
56  virtual SimpleString getTestName() const;
57  virtual SimpleString getTestNameOnly() const;
58  virtual int getFailureLineNumber() const;
59  virtual SimpleString getMessage() const;
60  virtual SimpleString getTestFileName() const;
61  virtual int getTestLineNumber() const;
62  bool isOutsideTestFile() const;
63  bool isInHelperFunction() const;
64 
65 
66 protected:
67  enum DifferenceFormat
68  {
69  DIFFERENCE_STRING, DIFFERENCE_BINARY
70  };
71 
72  SimpleString createButWasString(const SimpleString& expected, const SimpleString& actual);
73  SimpleString createDifferenceAtPosString(const SimpleString& actual, size_t position, DifferenceFormat format = DIFFERENCE_STRING);
74  SimpleString createUserText(const SimpleString& text);
75 
76  SimpleString testName_;
77  SimpleString testNameOnly_;
78  SimpleString fileName_;
79  int lineNumber_;
80  SimpleString testFileName_;
81  int testLineNumber_;
82  SimpleString message_;
83 
84  TestFailure& operator=(const TestFailure&);
85 
86 };
87 
88 class EqualsFailure: public TestFailure
89 {
90 public:
91  EqualsFailure(UtestShell*, const char* fileName, int lineNumber, const char* expected, const char* actual, const SimpleString& text);
92  EqualsFailure(UtestShell*, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual, const SimpleString& text);
93 };
94 
95 class DoublesEqualFailure: public TestFailure
96 {
97 public:
98  DoublesEqualFailure(UtestShell*, const char* fileName, int lineNumber, double expected, double actual, double threshold, const SimpleString& text);
99 };
100 
101 class CheckEqualFailure : public TestFailure
102 {
103 public:
104  CheckEqualFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual, const SimpleString& text);
105 };
106 
107 class ContainsFailure: public TestFailure
108 {
109 public:
110  ContainsFailure(UtestShell*, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual, const SimpleString& text);
111 
112 };
113 
114 class CheckFailure : public TestFailure
115 {
116 public:
117  CheckFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& checkString, const SimpleString& conditionString, const SimpleString& textString = "");
118 };
119 
120 class FailFailure : public TestFailure
121 {
122 public:
123  FailFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& message);
124 };
125 
126 class LongsEqualFailure : public TestFailure
127 {
128 public:
129  LongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, long expected, long actual, const SimpleString& text);
130 };
131 
132 class UnsignedLongsEqualFailure : public TestFailure
133 {
134 public:
135  UnsignedLongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, unsigned long expected, unsigned long actual, const SimpleString& text);
136 };
137 
138 class LongLongsEqualFailure : public TestFailure
139 {
140 public:
141  LongLongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, cpputest_longlong expected, cpputest_longlong actual, const SimpleString& text);
142 };
143 
144 class UnsignedLongLongsEqualFailure : public TestFailure
145 {
146 public:
147  UnsignedLongLongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, cpputest_ulonglong expected, cpputest_ulonglong actual, const SimpleString& text);
148 };
149 
150 class SignedBytesEqualFailure : public TestFailure
151 {
152 public:
153  SignedBytesEqualFailure (UtestShell* test, const char* fileName, int lineNumber, signed char expected, signed char actual, const SimpleString& text);
154 };
155 
156 class StringEqualFailure : public TestFailure
157 {
158 public:
159  StringEqualFailure(UtestShell* test, const char* fileName, int lineNumber, const char* expected, const char* actual, const SimpleString& text);
160 };
161 
162 class StringEqualNoCaseFailure : public TestFailure
163 {
164 public:
165  StringEqualNoCaseFailure(UtestShell* test, const char* fileName, int lineNumber, const char* expected, const char* actual, const SimpleString& text);
166 };
167 
168 class BinaryEqualFailure : public TestFailure
169 {
170 public:
171  BinaryEqualFailure(UtestShell* test, const char* fileName, int lineNumber, const unsigned char* expected, const unsigned char* actual, size_t size, const SimpleString& text);
172 };
173 
174 class BitsEqualFailure : public TestFailure
175 {
176 public:
177  BitsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, unsigned long expected, unsigned long actual, unsigned long mask, size_t byteCount, const SimpleString& text);
178 };
179 
180 class FeatureUnsupportedFailure : public TestFailure
181 {
182 public:
183  FeatureUnsupportedFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& featureName, const SimpleString& text);
184 };
185 
186 #endif