/usr/include/cxxtest/TestSuite.cpp is in cxxtest 4.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | /*
-------------------------------------------------------------------------
CxxTest: A lightweight C++ unit testing library.
Copyright (c) 2008 Sandia Corporation.
This software is distributed under the LGPL License v3
For more information, see the COPYING file in the top CxxTest directory.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
*/
#ifndef __cxxtest__TestSuite_cpp__
#define __cxxtest__TestSuite_cpp__
#include <cxxtest/TestSuite.h>
#if defined(_CXXTEST_HAVE_STD)
#include <fstream>
#endif
namespace CxxTest
{
//
// TestSuite members
//
TestSuite::~TestSuite() {}
void TestSuite::setUp() {}
void TestSuite::tearDown() {}
//
// Test-aborting stuff
//
static bool currentAbortTestOnFail = false;
bool abortTestOnFail()
{
return currentAbortTestOnFail;
}
void setAbortTestOnFail(bool value)
{
currentAbortTestOnFail = value;
}
void doAbortTest()
{
# if defined(_CXXTEST_HAVE_EH)
if (currentAbortTestOnFail)
{
throw AbortTest();
}
# endif // _CXXTEST_HAVE_EH
}
//
// Max dump size
//
static unsigned currentMaxDumpSize = CXXTEST_MAX_DUMP_SIZE;
unsigned maxDumpSize()
{
return currentMaxDumpSize;
}
void setMaxDumpSize(unsigned value)
{
currentMaxDumpSize = value;
}
//
// Some non-template functions
//
void doTrace(const char *file, int line, const char *message)
{
if (tracker().print_tracing)
{
tracker().trace(file, line, message);
}
}
void doWarn(const char *file, int line, const char *message)
{
tracker().warning(file, line, message);
}
# if defined(_CXXTEST_HAVE_EH)
void doSkipTest(const char* file, int line, const char* message)
{
tracker().skippedTest(file, line, message);
throw SkipTest();
# else
void doSkipTest(const char * file, int line, const char*)
{
doWarn(file, line, "Test skipping is not supported without exception handling.");
# endif
}
void doFailTest(const char * file, int line, const char * message)
{
tracker().failedTest(file, line, message);
TS_ABORT();
}
void doFailAssert(const char * file, int line,
const char * expression, const char * message)
{
if (message)
{
tracker().failedTest(file, line, message);
}
tracker().failedAssert(file, line, expression);
TS_ABORT();
}
bool sameData(const void * x, const void * y, unsigned size)
{
if (size == 0)
{
return true;
}
if (x == y)
{
return true;
}
if (!x || !y)
{
return false;
}
const char *cx = (const char *)x;
const char *cy = (const char *)y;
while (size --)
{
if (*cx++ != *cy++)
{
return false;
}
}
return true;
}
void doAssertSameData(const char * file, int line,
const char * xExpr, const void * x,
const char * yExpr, const void * y,
const char * sizeExpr, unsigned size,
const char * message)
{
if (!sameData(x, y, size))
{
if (message)
{
tracker().failedTest(file, line, message);
}
tracker().failedAssertSameData(file, line, xExpr, yExpr, sizeExpr, x, y, size);
TS_ABORT();
}
}
#if defined(_CXXTEST_HAVE_STD)
bool sameFiles(const char * file1, const char * file2, std::ostringstream & explanation)
{
std::string ppprev_line;
std::string pprev_line;
std::string prev_line;
std::string curr_line;
std::ifstream is1;
is1.open(file1);
std::ifstream is2;
is2.open(file2);
if (!is1)
{
explanation << "File '" << file1 << "' does not exist!";
return false;
}
if (!is2)
{
explanation << "File '" << file2 << "' does not exist!";
return false;
}
int nline = 1;
char c1, c2;
while (1)
{
is1.get(c1);
is2.get(c2);
if (!is1 && !is2) { return true; }
if (!is1)
{
explanation << "File '" << file1 << "' ended before file '" << file2 << "' (line " << nline << ")";
explanation << std::endl << "= " << ppprev_line << std::endl << "= " << pprev_line << std::endl << "= " << prev_line << std::endl << "< " << curr_line;
is1.get(c1);
while (is1 && (c1 != '\n'))
{
explanation << c1;
is1.get(c1);
}
explanation << std::endl;
return false;
}
if (!is2)
{
explanation << "File '" << file2 << "' ended before file '" << file1 << "' (line " << nline << ")";
explanation << std::endl << "= " << ppprev_line << std::endl << "= " << pprev_line << std::endl << "= " << prev_line << std::endl << "> " << curr_line;
is2.get(c2);
while (is2 && (c2 != '\n'))
{
explanation << c2;
is2.get(c2);
}
explanation << std::endl;
return false;
}
if (c1 != c2)
{
explanation << "Files '" << file1 << "' and '" << file2 << "' differ at line " << nline;
explanation << std::endl << "= " << ppprev_line << std::endl << "= " << pprev_line << std::endl << "= " << prev_line;
explanation << std::endl << "< " << curr_line;
is2.get(c1);
while (is1 && (c1 != '\n'))
{
explanation << c1;
is2.get(c1);
}
explanation << std::endl;
explanation << std::endl << "> " << curr_line;
is2.get(c2);
while (is2 && (c2 != '\n'))
{
explanation << c2;
is2.get(c2);
}
explanation << std::endl;
return false;
}
if (c1 == '\n')
{
ppprev_line = pprev_line;
pprev_line = prev_line;
prev_line = curr_line;
curr_line = "";
nline++;
}
else
{
curr_line += c1;
}
}
}
#endif
void doAssertSameFiles(const char * file, int line,
const char * file1, const char * file2,
const char * message)
{
#if defined(_CXXTEST_HAVE_STD)
std::ostringstream explanation;
if (!sameFiles(file1, file2, explanation))
{
if (message)
{
tracker().failedTest(file, line, message);
}
tracker().failedAssertSameFiles(file, line, file1, file2, explanation.str().c_str());
TS_ABORT();
}
#else
tracker().failedAssertSameFiles(file, line, file1, file2, "This test is only supported when --have-std is enabled");
TS_ABORT();
#endif
}
void doFailAssertThrows(const char * file, int line,
const char * expr, const char * type,
bool otherThrown,
const char * message,
const char * exception)
{
if (exception)
{
tracker().failedTest(file, line, exception);
}
if (message)
{
tracker().failedTest(file, line, message);
}
tracker().failedAssertThrows(file, line, expr, type, otherThrown);
TS_ABORT();
}
void doFailAssertThrowsNot(const char * file, int line,
const char * expression, const char * message,
const char * exception)
{
if (exception)
{
tracker().failedTest(file, line, exception);
}
if (message)
{
tracker().failedTest(file, line, message);
}
tracker().failedAssertThrowsNot(file, line, expression);
TS_ABORT();
}
}
#endif // __cxxtest__TestSuite_cpp__
|