CppUTest
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 
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 int getFailureLineNumber() const;
58  virtual SimpleString getMessage() const;
59  virtual SimpleString getTestFileName() const;
60  virtual int getTestLineNumber() const;
61  bool isOutsideTestFile() const;
62  bool isInHelperFunction() const;
63 
64 
65 protected:
66 
67  SimpleString createButWasString(const SimpleString& expected, const SimpleString& actual);
68  SimpleString createDifferenceAtPosString(const SimpleString& actual, size_t position);
69 
70  SimpleString testName_;
71  SimpleString fileName_;
72  int lineNumber_;
73  SimpleString testFileName_;
74  int testLineNumber_;
75  SimpleString message_;
76 
77  TestFailure& operator=(const TestFailure&);
78 
79 };
80 
82 {
83 public:
84  EqualsFailure(UtestShell*, const char* fileName, int lineNumber, const char* expected, const char* actual);
85  EqualsFailure(UtestShell*, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual);
86 };
87 
89 {
90 public:
91  DoublesEqualFailure(UtestShell*, const char* fileName, int lineNumber, double expected, double actual, double threshold);
92 };
93 
95 {
96 public:
97  CheckEqualFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual);
98 };
99 
101 {
102 public:
103  ContainsFailure(UtestShell*, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual);
104 
105 };
106 
107 class CheckFailure : public TestFailure
108 {
109 public:
110  CheckFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& checkString, const SimpleString& conditionString, const SimpleString& textString = "");
111 };
112 
113 class FailFailure : public TestFailure
114 {
115 public:
116  FailFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& message);
117 };
118 
120 {
121 public:
122  LongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, long expected, long actual);
123 };
124 
126 {
127 public:
128  StringEqualFailure(UtestShell* test, const char* fileName, int lineNumber, const char* expected, const char* actual);
129 };
130 
132 {
133 public:
134  StringEqualNoCaseFailure(UtestShell* test, const char* fileName, int lineNumber, const char* expected, const char* actual);
135 };
136 
137 #endif
Definition: TestFailure.h:125
Definition: TestFailure.h:81
Definition: TestFailure.h:100
Definition: TestFailure.h:107
Definition: SimpleString.h:46
Definition: TestFailure.h:94
Definition: TestFailure.h:44
Definition: Utest.h:61
Definition: TestFailure.h:131
Definition: TestOutput.h:44
Definition: TestFailure.h:119
Definition: TestFailure.h:113
Definition: TestFailure.h:88