28
28
#include " CppUTest/TestHarness.h"
29
29
#include " CppUTest/TestFailure.h"
30
30
#include " CppUTest/TestOutput.h"
31
+ #include " CppUTest/PlatformSpecificFunctions.h"
31
32
32
33
TestFailure::TestFailure (Utest* test, const char * fileName, int lineNumber, const SimpleString& theMessage) :
33
34
testName_(test->getFormattedName ()), fileName_(fileName), lineNumber_(lineNumber), message_(theMessage)
@@ -73,10 +74,16 @@ SimpleString TestFailure::getMessage() const
73
74
return message_;
74
75
}
75
76
76
- EqualsFailure::EqualsFailure (Utest* test, const char * fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual) :
77
+ EqualsFailure::EqualsFailure (Utest* test, const char * fileName, int lineNumber, const char * expected, const char * actual) :
77
78
TestFailure(test, fileName, lineNumber)
78
79
{
80
+ const char * format = " expected <%s>\n\t but was <%s>" ;
81
+ message_ = StringFromFormat (format, StringFromOrNull (expected).asCharString (), StringFromOrNull (actual).asCharString ());
82
+ }
79
83
84
+ EqualsFailure::EqualsFailure (Utest* test, const char * fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual)
85
+ : TestFailure(test, fileName, lineNumber)
86
+ {
80
87
const char * format = " expected <%s>\n\t but was <%s>" ;
81
88
message_ = StringFromFormat (format, expected.asCharString (), actual.asCharString ());
82
89
}
@@ -88,3 +95,88 @@ ContainsFailure::ContainsFailure(Utest* test, const char* fileName, int lineNumb
88
95
const char * format = " actual <%s>\n\t did not contain <%s>" ;
89
96
message_ = StringFromFormat (format, actual.asCharString (), expected.asCharString ());
90
97
}
98
+
99
+ CheckFailure::CheckFailure (Utest* test, const char * fileName, int lineNumber, const SimpleString& conditionString) : TestFailure(test, fileName, lineNumber)
100
+ {
101
+ message_ = " CHECK(" ;
102
+ message_ += conditionString;
103
+ message_ += " ) failed" ;
104
+ }
105
+
106
+ FailFailure::FailFailure (Utest* test, const char * fileName, int lineNumber, const SimpleString& message) : TestFailure(test, fileName, lineNumber)
107
+ {
108
+ message_ = message;
109
+ }
110
+
111
+ LongsEqualFailure::LongsEqualFailure (Utest* test, const char * fileName, int lineNumber, long expected, long actual) : TestFailure(test, fileName, lineNumber)
112
+ {
113
+ SimpleString aDecimal = StringFrom (actual);
114
+ SimpleString aHex = HexStringFrom (actual);
115
+ SimpleString eDecimal = StringFrom (expected);
116
+ SimpleString eHex = HexStringFrom (expected);
117
+
118
+ SimpleString::padStringsToSameLength (aDecimal, eDecimal, ' ' );
119
+ SimpleString::padStringsToSameLength (aHex, eHex, ' 0' );
120
+
121
+ SimpleString actualReported = aDecimal + " 0x" + aHex;
122
+ SimpleString expectedReported = eDecimal + " 0x" + eHex;
123
+ message_ = StringFromFormat (" expected <%s>\n\t but was <%s>" , expectedReported.asCharString (), actualReported.asCharString ());
124
+ }
125
+
126
+ StringEqualFailure::StringEqualFailure (Utest* test, const char * fileName, int lineNumber, const char * expected, const char * actual) : TestFailure(test, fileName, lineNumber)
127
+ {
128
+ int failStart;
129
+ for (failStart = 0 ; actual[failStart] == expected[failStart]; failStart++)
130
+ ;
131
+
132
+ const char * error = " <!>" ;
133
+ char * message;
134
+
135
+ // cpputest_malloc is needed instead of new[] for vc6 compatibility
136
+ message = (char *)cpputest_malloc (PlatformSpecificStrLen (actual) + PlatformSpecificStrLen (error) + 10 );
137
+
138
+ int j;
139
+ for (j = 0 ; j < failStart; j++)
140
+ message[j] = actual[j];
141
+
142
+ for (int k = 0 ; k < (int )PlatformSpecificStrLen (error); j++, k++)
143
+ message[j] = error[k];
144
+
145
+ for (int i = failStart; actual[i]; i++, j++)
146
+ message[j] = actual[i];
147
+
148
+ message[j] = ' \0 ' ;
149
+
150
+ message_ = StringFromFormat (" expected <%s>\n\t but was <%s>" , expected, message);
151
+ cpputest_free (message);
152
+ }
153
+
154
+ StringEqualNoCaseFailure::StringEqualNoCaseFailure (Utest* test, const char * fileName, int lineNumber, const char * expected, const char * actual) : TestFailure(test, fileName, lineNumber)
155
+ {
156
+ int failStart;
157
+ for (failStart = 0 ; PlatformSpecificToLower (actual[failStart]) == PlatformSpecificToLower (expected[failStart]); failStart++)
158
+ ;
159
+
160
+ const char * error = " <!>" ;
161
+ char * message;
162
+
163
+ // cpputest_malloc is needed instead of new[] for vc6 compatibility
164
+ message = (char *)cpputest_malloc (PlatformSpecificStrLen (actual) + PlatformSpecificStrLen (error) + 10 );
165
+
166
+ int j;
167
+ for (j = 0 ; j < failStart; j++)
168
+ message[j] = actual[j];
169
+
170
+ for (int k = 0 ; k < (int )PlatformSpecificStrLen (error); j++, k++)
171
+ message[j] = error[k];
172
+
173
+ for (int i = failStart; actual[i]; i++, j++)
174
+ message[j] = actual[i];
175
+
176
+ message[j] = ' \0 ' ;
177
+
178
+ message_ = StringFromFormat (" expected <%s>\n\t but was <%s>" , expected, message);
179
+ cpputest_free (message);
180
+ }
181
+
182
+
0 commit comments