mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
recommit the cxxtest headers
This commit is contained in:
parent
af2005f41a
commit
11fb80ceaf
83
third-party/cxxtest/cxxtest/Descriptions.cpp
vendored
Normal file
83
third-party/cxxtest/cxxtest/Descriptions.cpp
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__Descriptions_cpp__
|
||||
#define __cxxtest__Descriptions_cpp__
|
||||
|
||||
#include <cxxtest/Descriptions.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
TestDescription::~TestDescription() {}
|
||||
SuiteDescription::~SuiteDescription() {}
|
||||
WorldDescription::~WorldDescription() {}
|
||||
|
||||
//
|
||||
// Convert total tests to string
|
||||
//
|
||||
#ifndef _CXXTEST_FACTOR
|
||||
char *WorldDescription::strTotalTests(char *s) const
|
||||
{
|
||||
numberToString(numTotalTests(), s);
|
||||
return s;
|
||||
}
|
||||
#else // _CXXTEST_FACTOR
|
||||
char *WorldDescription::strTotalTests(char *s) const
|
||||
{
|
||||
char *p = numberToString(numTotalTests(), s);
|
||||
|
||||
if (numTotalTests() <= 1)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
unsigned n = numTotalTests();
|
||||
unsigned numFactors = 0;
|
||||
|
||||
for (unsigned factor = 2; (factor * factor) <= n; factor += (factor == 2) ? 1 : 2)
|
||||
{
|
||||
unsigned power;
|
||||
|
||||
for (power = 0; (n % factor) == 0; n /= factor)
|
||||
{
|
||||
++ power;
|
||||
}
|
||||
|
||||
if (!power)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
p = numberToString(factor, copyString(p, (numFactors == 0) ? " = " : " * "));
|
||||
if (power > 1)
|
||||
{
|
||||
p = numberToString(power, copyString(p, "^"));
|
||||
}
|
||||
++ numFactors;
|
||||
}
|
||||
|
||||
if (n > 1)
|
||||
{
|
||||
if (!numFactors)
|
||||
{
|
||||
copyString(p, tracker().failedTests() ? " :(" : tracker().warnings() ? " :|" : " :)");
|
||||
}
|
||||
else
|
||||
{
|
||||
numberToString(n, copyString(p, " * "));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
#endif // _CXXTEST_FACTOR
|
||||
}
|
||||
|
||||
#endif // __cxxtest__Descriptions_cpp__
|
91
third-party/cxxtest/cxxtest/Descriptions.h
vendored
Normal file
91
third-party/cxxtest/cxxtest/Descriptions.h
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__Descriptions_h__
|
||||
#define __cxxtest__Descriptions_h__
|
||||
|
||||
//
|
||||
// TestDescription, SuiteDescription and WorldDescription
|
||||
// hold information about tests so they can be run and reported.
|
||||
//
|
||||
|
||||
#include <cxxtest/LinkedList.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class TestSuite;
|
||||
|
||||
class TestDescription : public Link
|
||||
{
|
||||
public:
|
||||
virtual ~TestDescription();
|
||||
|
||||
virtual const char *file() const = 0;
|
||||
virtual int line() const = 0;
|
||||
virtual const char *testName() const = 0;
|
||||
virtual const char *suiteName() const = 0;
|
||||
|
||||
virtual void run() = 0;
|
||||
virtual bool setUp() = 0;
|
||||
virtual bool tearDown() = 0;
|
||||
|
||||
virtual const TestDescription *next() const = 0;
|
||||
virtual TestDescription *next() = 0;
|
||||
};
|
||||
|
||||
class SuiteDescription : public Link
|
||||
{
|
||||
public:
|
||||
virtual ~SuiteDescription();
|
||||
|
||||
virtual const char *file() const = 0;
|
||||
virtual int line() const = 0;
|
||||
virtual const char *suiteName() const = 0;
|
||||
virtual TestSuite *suite() const = 0;
|
||||
|
||||
virtual unsigned numTests() const = 0;
|
||||
virtual const TestDescription &testDescription(unsigned /*i*/) const = 0;
|
||||
|
||||
virtual TestDescription *firstTest() = 0;
|
||||
virtual const TestDescription *firstTest() const = 0;
|
||||
virtual SuiteDescription *next() = 0;
|
||||
virtual const SuiteDescription *next() const = 0;
|
||||
|
||||
virtual void activateAllTests() = 0;
|
||||
virtual bool leaveOnly(const char * /*testName*/) = 0;
|
||||
|
||||
virtual bool setUp() = 0;
|
||||
virtual bool tearDown() = 0;
|
||||
};
|
||||
|
||||
class WorldDescription : public Link
|
||||
{
|
||||
public:
|
||||
virtual ~WorldDescription();
|
||||
|
||||
virtual const char *worldName() const { return "cxxtest"; }
|
||||
virtual unsigned numSuites(void) const = 0;
|
||||
virtual unsigned numTotalTests(void) const = 0;
|
||||
virtual const SuiteDescription &suiteDescription(unsigned /*i*/) const = 0;
|
||||
|
||||
enum { MAX_STRLEN_TOTAL_TESTS = 32 };
|
||||
char *strTotalTests(char * /*buffer*/) const;
|
||||
|
||||
virtual SuiteDescription *firstSuite() = 0;
|
||||
virtual const SuiteDescription *firstSuite() const = 0;
|
||||
|
||||
virtual void activateAllTests() = 0;
|
||||
virtual bool leaveOnly(const char * /*suiteName*/, const char * /*testName*/ = 0) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__Descriptions_h__
|
||||
|
60
third-party/cxxtest/cxxtest/DummyDescriptions.cpp
vendored
Normal file
60
third-party/cxxtest/cxxtest/DummyDescriptions.cpp
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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.
|
||||
-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <cxxtest/DummyDescriptions.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
DummyTestDescription::DummyTestDescription() {}
|
||||
|
||||
const char *DummyTestDescription::file() const { return "<no file>"; }
|
||||
int DummyTestDescription::line() const { return 0; }
|
||||
const char *DummyTestDescription::testName() const { return "<no test>"; }
|
||||
const char *DummyTestDescription::suiteName() const { return "<no suite>"; }
|
||||
bool DummyTestDescription::setUp() { return true;}
|
||||
void DummyTestDescription::run() {}
|
||||
bool DummyTestDescription::tearDown() { return true;}
|
||||
|
||||
TestDescription *DummyTestDescription::next() { return 0; }
|
||||
const TestDescription *DummyTestDescription::next() const { return 0; }
|
||||
|
||||
DummySuiteDescription::DummySuiteDescription() : _test() {}
|
||||
|
||||
const char *DummySuiteDescription::file() const { return "<no file>"; }
|
||||
int DummySuiteDescription::line() const { return 0; }
|
||||
const char *DummySuiteDescription::suiteName() const { return "<no suite>"; }
|
||||
TestSuite *DummySuiteDescription::suite() const { return 0; }
|
||||
unsigned DummySuiteDescription::numTests() const { return 0; }
|
||||
const TestDescription &DummySuiteDescription::testDescription(unsigned) const { return _test; }
|
||||
SuiteDescription *DummySuiteDescription::next() { return 0; }
|
||||
TestDescription *DummySuiteDescription::firstTest() { return 0; }
|
||||
const SuiteDescription *DummySuiteDescription::next() const { return 0; }
|
||||
const TestDescription *DummySuiteDescription::firstTest() const { return 0; }
|
||||
void DummySuiteDescription::activateAllTests() {}
|
||||
bool DummySuiteDescription::leaveOnly(const char * /*testName*/) { return false; }
|
||||
|
||||
bool DummySuiteDescription::setUp() { return true;}
|
||||
bool DummySuiteDescription::tearDown() { return true;}
|
||||
|
||||
DummyWorldDescription::DummyWorldDescription() : _suite() {}
|
||||
|
||||
unsigned DummyWorldDescription::numSuites(void) const { return 0; }
|
||||
unsigned DummyWorldDescription::numTotalTests(void) const { return 0; }
|
||||
const SuiteDescription &DummyWorldDescription::suiteDescription(unsigned) const { return _suite; }
|
||||
SuiteDescription *DummyWorldDescription::firstSuite() { return 0; }
|
||||
const SuiteDescription *DummyWorldDescription::firstSuite() const { return 0; }
|
||||
void DummyWorldDescription::activateAllTests() {}
|
||||
bool DummyWorldDescription::leaveOnly(const char * /*suiteName*/, const char * /*testName*/) { return false; }
|
||||
|
||||
bool DummyWorldDescription::setUp() { return true;}
|
||||
bool DummyWorldDescription::tearDown() { return true;}
|
||||
}
|
||||
|
87
third-party/cxxtest/cxxtest/DummyDescriptions.h
vendored
Normal file
87
third-party/cxxtest/cxxtest/DummyDescriptions.h
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__DummyDescriptions_h__
|
||||
#define __cxxtest__DummyDescriptions_h__
|
||||
|
||||
//
|
||||
// DummyTestDescription, DummySuiteDescription and DummyWorldDescription
|
||||
//
|
||||
|
||||
#include <cxxtest/Descriptions.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class DummyTestDescription : public TestDescription
|
||||
{
|
||||
public:
|
||||
DummyTestDescription();
|
||||
|
||||
const char *file() const;
|
||||
int line() const;
|
||||
const char *testName() const;
|
||||
const char *suiteName() const;
|
||||
bool setUp();
|
||||
void run();
|
||||
bool tearDown();
|
||||
|
||||
TestDescription *next();
|
||||
const TestDescription *next() const;
|
||||
};
|
||||
|
||||
class DummySuiteDescription : public SuiteDescription
|
||||
{
|
||||
public:
|
||||
DummySuiteDescription();
|
||||
|
||||
const char *file() const;
|
||||
int line() const;
|
||||
const char *suiteName() const;
|
||||
TestSuite *suite() const;
|
||||
unsigned numTests() const;
|
||||
const TestDescription &testDescription(unsigned) const;
|
||||
SuiteDescription *next();
|
||||
TestDescription *firstTest();
|
||||
const SuiteDescription *next() const;
|
||||
const TestDescription *firstTest() const;
|
||||
void activateAllTests();
|
||||
bool leaveOnly(const char * /*testName*/);
|
||||
|
||||
bool setUp();
|
||||
bool tearDown();
|
||||
|
||||
private:
|
||||
DummyTestDescription _test;
|
||||
};
|
||||
|
||||
class DummyWorldDescription : public WorldDescription
|
||||
{
|
||||
public:
|
||||
DummyWorldDescription();
|
||||
|
||||
unsigned numSuites(void) const;
|
||||
unsigned numTotalTests(void) const;
|
||||
const SuiteDescription &suiteDescription(unsigned) const;
|
||||
SuiteDescription *firstSuite();
|
||||
const SuiteDescription *firstSuite() const;
|
||||
void activateAllTests();
|
||||
bool leaveOnly(const char * /*suiteName*/, const char * /*testName*/ = 0);
|
||||
|
||||
bool setUp();
|
||||
bool tearDown();
|
||||
|
||||
private:
|
||||
DummySuiteDescription _suite;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__DummyDescriptions_h__
|
||||
|
347
third-party/cxxtest/cxxtest/ErrorFormatter.h
vendored
Normal file
347
third-party/cxxtest/cxxtest/ErrorFormatter.h
vendored
Normal file
|
@ -0,0 +1,347 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__ErrorFormatter_h__
|
||||
#define __cxxtest__ErrorFormatter_h__
|
||||
|
||||
//
|
||||
// The ErrorFormatter is a TestListener that
|
||||
// prints reports of the errors to an output
|
||||
// stream. Since we cannot rely on the standard
|
||||
// iostreams, this header defines a base class
|
||||
// analogout to std::ostream.
|
||||
//
|
||||
|
||||
#include <cxxtest/TestRunner.h>
|
||||
#include <cxxtest/TestListener.h>
|
||||
#include <cxxtest/TestTracker.h>
|
||||
#include <cxxtest/ValueTraits.h>
|
||||
#include <cstdio>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class OutputStream
|
||||
{
|
||||
public:
|
||||
virtual ~OutputStream() {}
|
||||
virtual void flush() {};
|
||||
virtual OutputStream &operator<<(unsigned /*number*/) { return *this; }
|
||||
virtual OutputStream &operator<<(const char * /*string*/) { return *this; }
|
||||
|
||||
typedef void (*Manipulator)(OutputStream &);
|
||||
|
||||
virtual OutputStream &operator<<(Manipulator m) { m(*this); return *this; }
|
||||
static void endl(OutputStream &o) { (o << "\n").flush(); }
|
||||
};
|
||||
|
||||
class ErrorFormatter : public TestListener
|
||||
{
|
||||
public:
|
||||
ErrorFormatter(OutputStream *o, const char *preLine = ":", const char *postLine = "",
|
||||
const char *errorString = "Error",
|
||||
const char *warningString = "Warning") :
|
||||
_dotting(true),
|
||||
_reported(false),
|
||||
_o(o),
|
||||
_preLine(preLine),
|
||||
_postLine(postLine),
|
||||
_errorString(errorString),
|
||||
_warningString(warningString)
|
||||
{
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
TestRunner::runAllTests(*this);
|
||||
return tracker().failedTests();
|
||||
}
|
||||
|
||||
void enterWorld(const WorldDescription& desc)
|
||||
{
|
||||
(*_o) << "Running " << desc.worldName() << " tests (" << totalTests << ")";
|
||||
_o->flush();
|
||||
_dotting = true;
|
||||
_reported = false;
|
||||
}
|
||||
|
||||
static void totalTests(OutputStream &o)
|
||||
{
|
||||
char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
|
||||
const WorldDescription &wd = tracker().world();
|
||||
o << wd.strTotalTests(s) << (wd.numTotalTests() == 1 ? " test" : " tests");
|
||||
}
|
||||
|
||||
void enterSuite(const SuiteDescription &)
|
||||
{
|
||||
_reported = false;
|
||||
}
|
||||
|
||||
void enterTest(const TestDescription &)
|
||||
{
|
||||
_reported = false;
|
||||
}
|
||||
|
||||
void leaveTest(const TestDescription &)
|
||||
{
|
||||
if (tracker().testSkipped())
|
||||
{
|
||||
(*_o) << "s";
|
||||
_o->flush();
|
||||
fflush(stdout);
|
||||
_dotting = true;
|
||||
}
|
||||
else if (!tracker().testFailed())
|
||||
{
|
||||
(*_o) << ".";
|
||||
_o->flush();
|
||||
fflush(stdout);
|
||||
_dotting = true;
|
||||
}
|
||||
}
|
||||
|
||||
void leaveWorld(const WorldDescription &desc)
|
||||
{
|
||||
if (!tracker().failedTests())
|
||||
{
|
||||
(*_o) << "OK!" << endl;
|
||||
return;
|
||||
}
|
||||
newLine();
|
||||
(*_o) << "Failed " << tracker().failedTests() << " and Skipped " << tracker().skippedTests() << " of " << totalTests << endl;
|
||||
unsigned numPassed = desc.numTotalTests() - tracker().failedTests() - tracker().skippedTests();
|
||||
unsigned numTotal = desc.numTotalTests() - tracker().skippedTests();
|
||||
if (numTotal == 0)
|
||||
{
|
||||
(*_o) << "Success rate: 100%" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*_o) << "Success rate: " << (unsigned)(numPassed * 100.0 / numTotal) << "%" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void trace(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << "Trace: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void warning(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << _warningString << ": " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void skippedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
if(expression && strlen(expression) > 0)
|
||||
stop(file, line) << _warningString << ": Test skipped: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void failedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Test failed: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void failedAssert(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Assertion failed: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void failedAssertEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected (" <<
|
||||
xStr << " == " << yStr << "), found (" <<
|
||||
x << " != " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertSameData(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *sizeStr, const void *x,
|
||||
const void *y, unsigned size)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected " << sizeStr << " (" << size << ") bytes to be equal at (" <<
|
||||
xStr << ") and (" << yStr << "), found:" << endl;
|
||||
dump(x, size);
|
||||
(*_o) << " differs from" << endl;
|
||||
dump(y, size);
|
||||
}
|
||||
|
||||
void failedAssertSameFiles(const char* file, int line,
|
||||
const char*, const char*,
|
||||
const char* explanation
|
||||
)
|
||||
{
|
||||
stop(file, line) << _errorString << ": " << explanation << endl;
|
||||
}
|
||||
|
||||
void failedAssertDelta(const char *file, int line,
|
||||
const char *xStr, const char *yStr, const char *dStr,
|
||||
const char *x, const char *y, const char *d)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected (" <<
|
||||
xStr << " == " << yStr << ") up to " << dStr << " (" << d << "), found (" <<
|
||||
x << " != " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertDiffers(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *value)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected (" <<
|
||||
xStr << " != " << yStr << "), found (" <<
|
||||
value << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertLessThan(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected (" <<
|
||||
xStr << " < " << yStr << "), found (" <<
|
||||
x << " >= " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertLessThanEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected (" <<
|
||||
xStr << " <= " << yStr << "), found (" <<
|
||||
x << " > " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertRelation(const char *file, int line,
|
||||
const char *relation, const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected " << relation << "( " <<
|
||||
xStr << ", " << yStr << " ), found !" << relation << "( " << x << ", " << y << " )" << endl;
|
||||
}
|
||||
|
||||
void failedAssertPredicate(const char *file, int line,
|
||||
const char *predicate, const char *xStr, const char *x)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected " << predicate << "( " <<
|
||||
xStr << " ), found !" << predicate << "( " << x << " )" << endl;
|
||||
}
|
||||
|
||||
void failedAssertThrows(const char *file, int line,
|
||||
const char *expression, const char *type,
|
||||
bool otherThrown)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected (" << expression << ") to throw (" <<
|
||||
type << ") but it " << (otherThrown ? "threw something else" : "didn't throw") <<
|
||||
endl;
|
||||
}
|
||||
|
||||
void failedAssertThrowsNot(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << _errorString << ": Expected (" << expression << ") not to throw, but it did" <<
|
||||
endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
OutputStream *outputStream() const
|
||||
{
|
||||
return _o;
|
||||
}
|
||||
|
||||
private:
|
||||
ErrorFormatter(const ErrorFormatter &);
|
||||
ErrorFormatter &operator=(const ErrorFormatter &);
|
||||
|
||||
OutputStream &stop(const char *file, int line)
|
||||
{
|
||||
newLine();
|
||||
reportTest();
|
||||
return (*_o) << file << _preLine << line << _postLine << ": ";
|
||||
}
|
||||
|
||||
void newLine(void)
|
||||
{
|
||||
if (_dotting)
|
||||
{
|
||||
(*_o) << endl;
|
||||
_dotting = false;
|
||||
}
|
||||
}
|
||||
|
||||
void reportTest(void)
|
||||
{
|
||||
if (_reported)
|
||||
{
|
||||
return;
|
||||
}
|
||||
(*_o) << "In " << tracker().suite().suiteName() << "::" << tracker().test().testName() << ":" << endl;
|
||||
_reported = true;
|
||||
}
|
||||
|
||||
void dump(const void *buffer, unsigned size)
|
||||
{
|
||||
if (!buffer)
|
||||
{
|
||||
dumpNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
dumpBuffer(buffer, size);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpNull()
|
||||
{
|
||||
(*_o) << " (null)" << endl;
|
||||
}
|
||||
|
||||
void dumpBuffer(const void *buffer, unsigned size)
|
||||
{
|
||||
unsigned dumpSize = size;
|
||||
if (maxDumpSize() && dumpSize > maxDumpSize())
|
||||
{
|
||||
dumpSize = maxDumpSize();
|
||||
}
|
||||
|
||||
const unsigned char *p = (const unsigned char *)buffer;
|
||||
(*_o) << " { ";
|
||||
for (unsigned i = 0; i < dumpSize; ++ i)
|
||||
{
|
||||
(*_o) << byteToHex(*p++) << " ";
|
||||
}
|
||||
if (dumpSize < size)
|
||||
{
|
||||
(*_o) << "... ";
|
||||
}
|
||||
(*_o) << "}" << endl;
|
||||
}
|
||||
|
||||
static void endl(OutputStream &o)
|
||||
{
|
||||
OutputStream::endl(o);
|
||||
}
|
||||
|
||||
bool _dotting;
|
||||
bool _reported;
|
||||
OutputStream *_o;
|
||||
const char *_preLine;
|
||||
const char *_postLine;
|
||||
const char *_errorString;
|
||||
const char *_warningString;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__ErrorFormatter_h__
|
||||
|
68
third-party/cxxtest/cxxtest/ErrorPrinter.h
vendored
Normal file
68
third-party/cxxtest/cxxtest/ErrorPrinter.h
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__ErrorPrinter_h__
|
||||
#define __cxxtest__ErrorPrinter_h__
|
||||
|
||||
//
|
||||
// The ErrorPrinter is a simple TestListener that
|
||||
// just prints "OK" if everything goes well, otherwise
|
||||
// reports the error in the format of compiler messages.
|
||||
// The ErrorPrinter uses std::cout
|
||||
//
|
||||
|
||||
#include <cxxtest/Flags.h>
|
||||
|
||||
#ifndef _CXXTEST_HAVE_STD
|
||||
# define _CXXTEST_HAVE_STD
|
||||
#endif // _CXXTEST_HAVE_STD
|
||||
|
||||
#include <cxxtest/ErrorFormatter.h>
|
||||
#include <cxxtest/StdValueTraits.h>
|
||||
|
||||
#ifdef _CXXTEST_OLD_STD
|
||||
# include <iostream.h>
|
||||
#else // !_CXXTEST_OLD_STD
|
||||
# include <iostream>
|
||||
#endif // _CXXTEST_OLD_STD
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class ErrorPrinter : public ErrorFormatter
|
||||
{
|
||||
public:
|
||||
ErrorPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char *preLine = ":", const char *postLine = "",
|
||||
const char *errorString = "Error",
|
||||
const char *warningString = "Warning") :
|
||||
ErrorFormatter(new Adapter(o), preLine, postLine, errorString, warningString) {}
|
||||
virtual ~ErrorPrinter() { delete outputStream(); }
|
||||
|
||||
private:
|
||||
class Adapter : public OutputStream
|
||||
{
|
||||
CXXTEST_STD(ostream) &_o;
|
||||
public:
|
||||
Adapter(CXXTEST_STD(ostream) &o) : _o(o) {}
|
||||
void flush() { _o.flush(); }
|
||||
OutputStream &operator<<(const char *s) { _o << s; return *this; }
|
||||
OutputStream &operator<<(Manipulator m) { return OutputStream::operator<<(m); }
|
||||
OutputStream &operator<<(unsigned i)
|
||||
{
|
||||
char s[1 + 3 * sizeof(unsigned)];
|
||||
numberToString(i, s);
|
||||
_o << s;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__ErrorPrinter_h__
|
154
third-party/cxxtest/cxxtest/Flags.h
vendored
Normal file
154
third-party/cxxtest/cxxtest/Flags.h
vendored
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__Flags_h__
|
||||
#define __cxxtest__Flags_h__
|
||||
|
||||
//
|
||||
// These are the flags that control CxxTest
|
||||
//
|
||||
|
||||
#if !defined(CXXTEST_FLAGS)
|
||||
# define CXXTEST_FLAGS
|
||||
#endif // !CXXTEST_FLAGS
|
||||
|
||||
#if defined(CXXTEST_HAVE_EH) && !defined(_CXXTEST_HAVE_EH)
|
||||
# define _CXXTEST_HAVE_EH
|
||||
#endif // CXXTEST_HAVE_EH
|
||||
|
||||
#if defined(CXXTEST_HAVE_STD) && !defined(_CXXTEST_HAVE_STD)
|
||||
# define _CXXTEST_HAVE_STD
|
||||
#endif // CXXTEST_HAVE_STD
|
||||
|
||||
#if defined(CXXTEST_OLD_TEMPLATE_SYNTAX) && !defined(_CXXTEST_OLD_TEMPLATE_SYNTAX)
|
||||
# define _CXXTEST_OLD_TEMPLATE_SYNTAX
|
||||
#endif // CXXTEST_OLD_TEMPLATE_SYNTAX
|
||||
|
||||
#if defined(CXXTEST_OLD_STD) && !defined(_CXXTEST_OLD_STD)
|
||||
# define _CXXTEST_OLD_STD
|
||||
#endif // CXXTEST_OLD_STD
|
||||
|
||||
#if defined(CXXTEST_ABORT_TEST_ON_FAIL) && !defined(_CXXTEST_ABORT_TEST_ON_FAIL)
|
||||
# define _CXXTEST_ABORT_TEST_ON_FAIL
|
||||
#endif // CXXTEST_ABORT_TEST_ON_FAIL
|
||||
|
||||
#if defined(CXXTEST_NO_COPY_CONST) && !defined(_CXXTEST_NO_COPY_CONST)
|
||||
# define _CXXTEST_NO_COPY_CONST
|
||||
#endif // CXXTEST_NO_COPY_CONST
|
||||
|
||||
#if defined(CXXTEST_FACTOR) && !defined(_CXXTEST_FACTOR)
|
||||
# define _CXXTEST_FACTOR
|
||||
#endif // CXXTEST_FACTOR
|
||||
|
||||
#if defined(CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION) && !defined(_CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION)
|
||||
# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
#endif // CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
|
||||
#if defined(CXXTEST_LONGLONG)
|
||||
# if defined(_CXXTEST_LONGLONG)
|
||||
# undef _CXXTEST_LONGLONG
|
||||
# endif
|
||||
# define _CXXTEST_LONGLONG CXXTEST_LONGLONG
|
||||
#endif // CXXTEST_LONGLONG
|
||||
|
||||
#ifndef CXXTEST_MAX_DUMP_SIZE
|
||||
# define CXXTEST_MAX_DUMP_SIZE 0
|
||||
#endif // CXXTEST_MAX_DUMP_SIZE
|
||||
|
||||
#if defined(_CXXTEST_ABORT_TEST_ON_FAIL) && !defined(CXXTEST_DEFAULT_ABORT)
|
||||
# define CXXTEST_DEFAULT_ABORT true
|
||||
#endif // _CXXTEST_ABORT_TEST_ON_FAIL && !CXXTEST_DEFAULT_ABORT
|
||||
|
||||
#if !defined(CXXTEST_DEFAULT_ABORT)
|
||||
# define CXXTEST_DEFAULT_ABORT false
|
||||
#endif // !CXXTEST_DEFAULT_ABORT
|
||||
|
||||
#if defined(_CXXTEST_ABORT_TEST_ON_FAIL) && !defined(_CXXTEST_HAVE_EH)
|
||||
# warning "CXXTEST_ABORT_TEST_ON_FAIL is meaningless without CXXTEST_HAVE_EH"
|
||||
# undef _CXXTEST_ABORT_TEST_ON_FAIL
|
||||
#endif // _CXXTEST_ABORT_TEST_ON_FAIL && !_CXXTEST_HAVE_EH
|
||||
|
||||
//
|
||||
// Some minimal per-compiler configuration to allow us to compile
|
||||
//
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# if __BORLANDC__ <= 0x520 // Borland C++ 5.2 or earlier
|
||||
# ifndef _CXXTEST_OLD_STD
|
||||
# define _CXXTEST_OLD_STD
|
||||
# endif
|
||||
# ifndef _CXXTEST_OLD_TEMPLATE_SYNTAX
|
||||
# define _CXXTEST_OLD_TEMPLATE_SYNTAX
|
||||
# endif
|
||||
# endif
|
||||
# if __BORLANDC__ >= 0x540 // C++ Builder 4.0 or later
|
||||
# ifndef _CXXTEST_NO_COPY_CONST
|
||||
# define _CXXTEST_NO_COPY_CONST
|
||||
# endif
|
||||
# ifndef _CXXTEST_LONGLONG
|
||||
# define _CXXTEST_LONGLONG __int64
|
||||
# endif
|
||||
# endif
|
||||
#endif // __BORLANDC__
|
||||
|
||||
#ifdef _MSC_VER // Visual C++
|
||||
# ifndef _CXXTEST_LONGLONG
|
||||
# define _CXXTEST_LONGLONG __int64
|
||||
# endif
|
||||
# if (_MSC_VER >= 0x51E)
|
||||
# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# endif
|
||||
# endif
|
||||
# pragma warning( disable : 4127 )
|
||||
# pragma warning( disable : 4290 )
|
||||
# pragma warning( disable : 4511 )
|
||||
# pragma warning( disable : 4512 )
|
||||
# pragma warning( disable : 4514 )
|
||||
#endif // _MSC_VER
|
||||
|
||||
#ifdef __GNUC__
|
||||
# if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 9)
|
||||
# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# endif
|
||||
# endif
|
||||
# if defined(__LONG_LONG_MAX__) && !defined(__cplusplus)
|
||||
# define _CXXTEST_LONGLONG long long
|
||||
# endif
|
||||
#endif // __GNUC__
|
||||
|
||||
#ifdef __DMC__ // Digital Mars
|
||||
# ifndef _CXXTEST_OLD_STD
|
||||
# define _CXXTEST_OLD_STD
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __SUNPRO_CC // Sun Studio C++
|
||||
# if __SUNPRO_CC >= 0x510
|
||||
# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __xlC__ // IBM XL C/C++
|
||||
// Partial specialization may be supported before 7.0.0.3, but it is
|
||||
// definitely supported after.
|
||||
# if __xlC__ >= 0x0700
|
||||
# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // __cxxtest__Flags_h__
|
||||
|
34
third-party/cxxtest/cxxtest/GlobalFixture.cpp
vendored
Normal file
34
third-party/cxxtest/cxxtest/GlobalFixture.cpp
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__GlobalFixture_cpp__
|
||||
#define __cxxtest__GlobalFixture_cpp__
|
||||
|
||||
#include <cxxtest/GlobalFixture.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
bool GlobalFixture::setUpWorld() { return true; }
|
||||
bool GlobalFixture::tearDownWorld() { return true; }
|
||||
bool GlobalFixture::setUp() { return true; }
|
||||
bool GlobalFixture::tearDown() { return true; }
|
||||
|
||||
GlobalFixture::GlobalFixture() { attach(_list); }
|
||||
GlobalFixture::~GlobalFixture() { detach(_list); }
|
||||
|
||||
GlobalFixture *GlobalFixture::firstGlobalFixture() { return (GlobalFixture *)_list.head(); }
|
||||
GlobalFixture *GlobalFixture::lastGlobalFixture() { return (GlobalFixture *)_list.tail(); }
|
||||
GlobalFixture *GlobalFixture::nextGlobalFixture() { return (GlobalFixture *)next(); }
|
||||
GlobalFixture *GlobalFixture::prevGlobalFixture() { return (GlobalFixture *)prev(); }
|
||||
}
|
||||
|
||||
#endif // __cxxtest__GlobalFixture_cpp__
|
||||
|
41
third-party/cxxtest/cxxtest/GlobalFixture.h
vendored
Normal file
41
third-party/cxxtest/cxxtest/GlobalFixture.h
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__GlobalFixture_h__
|
||||
#define __cxxtest__GlobalFixture_h__
|
||||
|
||||
#include <cxxtest/LinkedList.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class GlobalFixture : public Link
|
||||
{
|
||||
public:
|
||||
virtual bool setUpWorld();
|
||||
virtual bool tearDownWorld();
|
||||
virtual bool setUp();
|
||||
virtual bool tearDown();
|
||||
|
||||
GlobalFixture();
|
||||
virtual ~GlobalFixture();
|
||||
|
||||
static GlobalFixture *firstGlobalFixture();
|
||||
static GlobalFixture *lastGlobalFixture();
|
||||
GlobalFixture *nextGlobalFixture();
|
||||
GlobalFixture *prevGlobalFixture();
|
||||
|
||||
private:
|
||||
static List _list;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__GlobalFixture_h__
|
||||
|
199
third-party/cxxtest/cxxtest/Gui.h
vendored
Normal file
199
third-party/cxxtest/cxxtest/Gui.h
vendored
Normal file
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__GUI_H
|
||||
#define __CXXTEST__GUI_H
|
||||
|
||||
//
|
||||
// GuiListener is a simple base class for the differes GUIs
|
||||
// GuiTuiRunner<GuiT, TuiT> combines a GUI with a text-mode error formatter
|
||||
//
|
||||
|
||||
#include <cxxtest/TeeListener.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class GuiListener : public TestListener
|
||||
{
|
||||
public:
|
||||
GuiListener() : _state(GREEN_BAR) {}
|
||||
virtual ~GuiListener() {}
|
||||
|
||||
virtual void runGui(int &argc, char **argv, TestListener &listener)
|
||||
{
|
||||
enterGui(argc, argv);
|
||||
TestRunner::runAllTests(listener);
|
||||
leaveGui();
|
||||
}
|
||||
|
||||
virtual void enterGui(int & /*argc*/, char ** /*argv*/) {}
|
||||
virtual void leaveGui() {}
|
||||
|
||||
//
|
||||
// The easy way is to implement these functions:
|
||||
//
|
||||
virtual void guiEnterWorld(unsigned /*numTotalTests*/) {}
|
||||
virtual void guiEnterSuite(const char * /*suiteName*/) {}
|
||||
virtual void guiEnterTest(const char * /*suiteName*/, const char * /*testName*/) {}
|
||||
virtual void yellowBar() {}
|
||||
virtual void redBar() {}
|
||||
|
||||
//
|
||||
// The hard way is this:
|
||||
//
|
||||
void enterWorld(const WorldDescription &d) { guiEnterWorld(d.numTotalTests()); }
|
||||
void enterSuite(const SuiteDescription &d) { guiEnterSuite(d.suiteName()); }
|
||||
void enterTest(const TestDescription &d) { guiEnterTest(d.suiteName(), d.testName()); }
|
||||
void leaveTest(const TestDescription &) {}
|
||||
void leaveSuite(const SuiteDescription &) {}
|
||||
void leaveWorld(const WorldDescription &) {}
|
||||
|
||||
void warning(const char * /*file*/, int /*line*/, const char * /*expression*/)
|
||||
{
|
||||
yellowBarSafe();
|
||||
}
|
||||
|
||||
void skippedTest(const char * /*file*/, int /*line*/, const char * /*expression*/)
|
||||
{
|
||||
yellowBarSafe();
|
||||
}
|
||||
|
||||
void failedTest(const char * /*file*/, int /*line*/, const char * /*expression*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssert(const char * /*file*/, int /*line*/, const char * /*expression*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertEquals(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertSameData(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*sizeStr*/, const void * /*x*/,
|
||||
const void * /*y*/, unsigned /*size*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertDelta(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/, const char * /*dStr*/,
|
||||
const char * /*x*/, const char * /*y*/, const char * /*d*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertDiffers(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*value*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertLessThan(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertLessThanEquals(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertPredicate(const char * /*file*/, int /*line*/,
|
||||
const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertRelation(const char * /*file*/, int /*line*/,
|
||||
const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertThrows(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/, const char * /*type*/,
|
||||
bool /*otherThrown*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
void failedAssertThrowsNot(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/)
|
||||
{
|
||||
redBarSafe();
|
||||
}
|
||||
|
||||
protected:
|
||||
void yellowBarSafe()
|
||||
{
|
||||
if (_state < YELLOW_BAR)
|
||||
{
|
||||
yellowBar();
|
||||
_state = YELLOW_BAR;
|
||||
}
|
||||
}
|
||||
|
||||
void redBarSafe()
|
||||
{
|
||||
if (_state < RED_BAR)
|
||||
{
|
||||
redBar();
|
||||
_state = RED_BAR;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
enum { GREEN_BAR, YELLOW_BAR, RED_BAR } _state;
|
||||
};
|
||||
|
||||
template<class GuiT, class TuiT>
|
||||
class GuiTuiRunner : public TeeListener
|
||||
{
|
||||
int* _argc;
|
||||
char **_argv;
|
||||
GuiT _gui;
|
||||
TuiT _tui;
|
||||
|
||||
public:
|
||||
GuiTuiRunner() : _argc(0), _argv(0) {}
|
||||
|
||||
void process_commandline(int& argc, char** argv)
|
||||
{
|
||||
_argc = &argc;
|
||||
_argv = argv;
|
||||
setFirst(_gui);
|
||||
setSecond(_tui);
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
_gui.runGui(*_argc, _argv, *this);
|
||||
return tracker().failedTests();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //__CXXTEST__GUI_H
|
||||
|
221
third-party/cxxtest/cxxtest/LinkedList.cpp
vendored
Normal file
221
third-party/cxxtest/cxxtest/LinkedList.cpp
vendored
Normal file
|
@ -0,0 +1,221 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__LinkedList_cpp__
|
||||
#define __cxxtest__LinkedList_cpp__
|
||||
|
||||
#include <cxxtest/LinkedList.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
List GlobalFixture::_list = { 0, 0 };
|
||||
List RealSuiteDescription::_suites = { 0, 0 };
|
||||
|
||||
void List::initialize()
|
||||
{
|
||||
_head = _tail = 0;
|
||||
}
|
||||
|
||||
Link *List::head()
|
||||
{
|
||||
Link *l = _head;
|
||||
while (l && !l->active())
|
||||
{
|
||||
l = l->next();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
const Link *List::head() const
|
||||
{
|
||||
Link *l = _head;
|
||||
while (l && !l->active())
|
||||
{
|
||||
l = l->next();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
Link *List::tail()
|
||||
{
|
||||
Link *l = _tail;
|
||||
while (l && !l->active())
|
||||
{
|
||||
l = l->prev();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
const Link *List::tail() const
|
||||
{
|
||||
Link *l = _tail;
|
||||
while (l && !l->active())
|
||||
{
|
||||
l = l->prev();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
bool List::empty() const
|
||||
{
|
||||
return (_head == 0);
|
||||
}
|
||||
|
||||
unsigned List::size() const
|
||||
{
|
||||
unsigned count = 0;
|
||||
for (const Link *l = head(); l != 0; l = l->next())
|
||||
{
|
||||
++ count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
Link *List::nth(unsigned n)
|
||||
{
|
||||
Link *l = head();
|
||||
while (n --)
|
||||
{
|
||||
l = l->next();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
void List::activateAll()
|
||||
{
|
||||
for (Link *l = _head; l != 0; l = l->justNext())
|
||||
{
|
||||
l->setActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void List::leaveOnly(const Link &link)
|
||||
{
|
||||
for (Link *l = head(); l != 0; l = l->next())
|
||||
{
|
||||
if (l != &link)
|
||||
{
|
||||
l->setActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Link::Link() :
|
||||
_next(0),
|
||||
_prev(0),
|
||||
_active(true)
|
||||
{
|
||||
}
|
||||
|
||||
Link::~Link()
|
||||
{
|
||||
}
|
||||
|
||||
bool Link::active() const
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
|
||||
void Link::setActive(bool value)
|
||||
{
|
||||
_active = value;
|
||||
}
|
||||
|
||||
Link * Link::justNext()
|
||||
{
|
||||
return _next;
|
||||
}
|
||||
|
||||
Link * Link::justPrev()
|
||||
{
|
||||
return _prev;
|
||||
}
|
||||
|
||||
Link * Link::next()
|
||||
{
|
||||
Link *l = _next;
|
||||
while (l && !l->_active)
|
||||
{
|
||||
l = l->_next;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
Link * Link::prev()
|
||||
{
|
||||
Link *l = _prev;
|
||||
while (l && !l->_active)
|
||||
{
|
||||
l = l->_prev;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
const Link * Link::next() const
|
||||
{
|
||||
Link *l = _next;
|
||||
while (l && !l->_active)
|
||||
{
|
||||
l = l->_next;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
const Link * Link::prev() const
|
||||
{
|
||||
Link *l = _prev;
|
||||
while (l && !l->_active)
|
||||
{
|
||||
l = l->_prev;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
void Link::attach(List &l)
|
||||
{
|
||||
if (l._tail)
|
||||
{
|
||||
l._tail->_next = this;
|
||||
}
|
||||
|
||||
_prev = l._tail;
|
||||
_next = 0;
|
||||
|
||||
if (l._head == 0)
|
||||
{
|
||||
l._head = this;
|
||||
}
|
||||
l._tail = this;
|
||||
}
|
||||
|
||||
void Link::detach(List &l)
|
||||
{
|
||||
if (_prev)
|
||||
{
|
||||
_prev->_next = _next;
|
||||
}
|
||||
else
|
||||
{
|
||||
l._head = _next;
|
||||
}
|
||||
|
||||
if (_next)
|
||||
{
|
||||
_next->_prev = _prev;
|
||||
}
|
||||
else
|
||||
{
|
||||
l._tail = _prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __cxxtest__LinkedList_cpp__
|
73
third-party/cxxtest/cxxtest/LinkedList.h
vendored
Normal file
73
third-party/cxxtest/cxxtest/LinkedList.h
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__LinkedList_h__
|
||||
#define __cxxtest__LinkedList_h__
|
||||
|
||||
#include <cxxtest/Flags.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
struct List;
|
||||
class Link;
|
||||
|
||||
struct List
|
||||
{
|
||||
Link *_head;
|
||||
Link *_tail;
|
||||
|
||||
void initialize();
|
||||
|
||||
Link *head();
|
||||
const Link *head() const;
|
||||
Link *tail();
|
||||
const Link *tail() const;
|
||||
|
||||
bool empty() const;
|
||||
unsigned size() const;
|
||||
Link *nth(unsigned n);
|
||||
|
||||
void activateAll();
|
||||
void leaveOnly(const Link &link);
|
||||
};
|
||||
|
||||
class Link
|
||||
{
|
||||
public:
|
||||
Link();
|
||||
virtual ~Link();
|
||||
|
||||
bool active() const;
|
||||
void setActive(bool value = true);
|
||||
|
||||
Link *justNext();
|
||||
Link *justPrev();
|
||||
|
||||
Link *next();
|
||||
Link *prev();
|
||||
const Link *next() const;
|
||||
const Link *prev() const;
|
||||
|
||||
void attach(List &l);
|
||||
void detach(List &l);
|
||||
|
||||
private:
|
||||
Link *_next;
|
||||
Link *_prev;
|
||||
bool _active;
|
||||
|
||||
Link(const Link &);
|
||||
Link &operator=(const Link &);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__LinkedList_h__
|
||||
|
40
third-party/cxxtest/cxxtest/MSVCErrorPrinter.h
vendored
Normal file
40
third-party/cxxtest/cxxtest/MSVCErrorPrinter.h
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__MSVCErrorPrinter_h__
|
||||
#define __cxxtest__MSVCErrorPrinter_h__
|
||||
|
||||
//
|
||||
// The MSVCErrorPrinter is identical to the ErrorPrinter, except it
|
||||
// prints the line number and error/warning strings in a format
|
||||
// consistent with that generated by Microsoft's compiler.
|
||||
//
|
||||
// Strict error parsers (e.g. QtCreator's) expect each error to be
|
||||
// followed by a proper-looking error code, so give them one to make
|
||||
// them work. Same for warnings.
|
||||
//
|
||||
// C2999 : "Unknown error" from Visual Studio 6, no longer used.
|
||||
// C4999 : "Unknown warning" from Visual Studio 6, no longer used.
|
||||
//
|
||||
|
||||
#include <cxxtest/ErrorPrinter.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class MSVCErrorPrinter : public ErrorPrinter
|
||||
{
|
||||
public:
|
||||
MSVCErrorPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout))
|
||||
: ErrorPrinter(o, "(", ") ", "error C2999", "warning C4999") {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__MSVCErrorPrinter_h__
|
380
third-party/cxxtest/cxxtest/Mock.h
vendored
Normal file
380
third-party/cxxtest/cxxtest/Mock.h
vendored
Normal file
|
@ -0,0 +1,380 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__Mock_h__
|
||||
#define __cxxtest__Mock_h__
|
||||
|
||||
namespace dummy_mock_ns {}
|
||||
|
||||
//
|
||||
// The default namespace is T::
|
||||
//
|
||||
#ifndef CXXTEST_MOCK_NAMESPACE
|
||||
# define CXXTEST_MOCK_NAMESPACE T
|
||||
#endif // CXXTEST_MOCK_NAMESPACE
|
||||
|
||||
//
|
||||
// MockTraits: What to return when no mock object has been created
|
||||
//
|
||||
#define __CXXTEST_MOCK__TRAITS \
|
||||
namespace CXXTEST_MOCK_NAMESPACE \
|
||||
{ \
|
||||
template<class T> \
|
||||
class MockTraits \
|
||||
{ \
|
||||
public: \
|
||||
static T defaultValue() { return 0; } \
|
||||
}; \
|
||||
}
|
||||
|
||||
//
|
||||
// extern "C" when needed
|
||||
//
|
||||
#ifdef __cplusplus
|
||||
# define CXXTEST_EXTERN_C extern "C"
|
||||
#else
|
||||
# define CXXTEST_EXTERN_C
|
||||
#endif // __cplusplus
|
||||
|
||||
//
|
||||
// Prototypes: For "normal" headers
|
||||
//
|
||||
#define __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { TYPE NAME ARGS; }
|
||||
|
||||
#define __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__PROTOTYPE( MOCK, void, NAME, ARGS, REAL, CALL )
|
||||
|
||||
#define __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
TYPE REAL ARGS;
|
||||
|
||||
#define __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__PROTOTYPE( MOCK, void, NAME, ARGS, REAL, CALL )
|
||||
|
||||
//
|
||||
// Class declarations: For test files
|
||||
//
|
||||
#define __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { \
|
||||
class Base_##MOCK : public CxxTest::Link \
|
||||
{ \
|
||||
public: \
|
||||
Base_##MOCK(); \
|
||||
~Base_##MOCK(); \
|
||||
bool setUp(); \
|
||||
bool tearDown(); \
|
||||
\
|
||||
static Base_##MOCK ¤t(); \
|
||||
\
|
||||
virtual TYPE NAME ARGS = 0; \
|
||||
\
|
||||
private: \
|
||||
static CxxTest::List _list; \
|
||||
}; \
|
||||
\
|
||||
class Real_##MOCK : public Base_##MOCK \
|
||||
{ \
|
||||
public: \
|
||||
TYPE NAME ARGS; \
|
||||
}; \
|
||||
\
|
||||
class _Unimplemented_##MOCK : public Base_##MOCK \
|
||||
{ \
|
||||
public: \
|
||||
TYPE NAME ARGS; \
|
||||
}; \
|
||||
}
|
||||
|
||||
#define __CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__CLASS_DECLARATION( MOCK, void, NAME, ARGS, REAL, CALL )
|
||||
|
||||
#define __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { \
|
||||
class Base_##MOCK : public CxxTest::Link \
|
||||
{ \
|
||||
public: \
|
||||
Base_##MOCK(); \
|
||||
~Base_##MOCK(); \
|
||||
bool setUp(); \
|
||||
bool tearDown(); \
|
||||
\
|
||||
static Base_##MOCK ¤t(); \
|
||||
\
|
||||
virtual TYPE NAME ARGS = 0; \
|
||||
\
|
||||
private: \
|
||||
static CxxTest::List _list; \
|
||||
}; \
|
||||
\
|
||||
class _Unimplemented_##MOCK : public Base_##MOCK \
|
||||
{ \
|
||||
public: \
|
||||
TYPE NAME ARGS; \
|
||||
}; \
|
||||
}
|
||||
|
||||
#define __CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, void, NAME, ARGS, REAL, CALL )
|
||||
|
||||
//
|
||||
// Class implementation: For test source files
|
||||
//
|
||||
#define __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { \
|
||||
\
|
||||
CxxTest::List Base_##MOCK::_list = { 0, 0 }; \
|
||||
\
|
||||
Base_##MOCK::Base_##MOCK() { attach( _list ); } \
|
||||
Base_##MOCK::~Base_##MOCK() { detach( _list ); } \
|
||||
bool Base_##MOCK::setUp() { return true; } \
|
||||
bool Base_##MOCK::tearDown() { return true; } \
|
||||
\
|
||||
Base_##MOCK &Base_##MOCK::current() \
|
||||
{ \
|
||||
if ( _list.empty() ) { \
|
||||
static _Unimplemented_##MOCK unimplemented; \
|
||||
} \
|
||||
return *(Base_##MOCK *)_list.tail(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define __CXXTEST_MOCK__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { \
|
||||
TYPE Real_##MOCK::NAME ARGS \
|
||||
{ \
|
||||
return REAL CALL; \
|
||||
} \
|
||||
\
|
||||
TYPE _Unimplemented_##MOCK::NAME ARGS \
|
||||
{ \
|
||||
while ( false ) {\
|
||||
return NAME CALL; \
|
||||
} \
|
||||
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
|
||||
return MockTraits<TYPE>::defaultValue(); \
|
||||
} \
|
||||
\
|
||||
TYPE NAME ARGS \
|
||||
{ \
|
||||
return Base_##MOCK::current().NAME CALL; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define __CXXTEST_MOCK_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { \
|
||||
void Real_##MOCK::NAME ARGS \
|
||||
{ \
|
||||
REAL CALL; \
|
||||
} \
|
||||
\
|
||||
void _Unimplemented_##MOCK::NAME ARGS \
|
||||
{ \
|
||||
while ( false ) { \
|
||||
NAME CALL; \
|
||||
} \
|
||||
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
|
||||
} \
|
||||
\
|
||||
void NAME ARGS \
|
||||
{ \
|
||||
Base_##MOCK::current().NAME CALL; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define __CXXTEST_SUPPLY__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { \
|
||||
TYPE _Unimplemented_##MOCK::NAME ARGS \
|
||||
{ \
|
||||
while ( false ) { \
|
||||
return NAME CALL; \
|
||||
} \
|
||||
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
|
||||
return MockTraits<TYPE>::defaultValue(); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
TYPE REAL ARGS \
|
||||
{ \
|
||||
return CXXTEST_MOCK_NAMESPACE::Base_##MOCK::current().NAME CALL; \
|
||||
}
|
||||
|
||||
#define __CXXTEST_SUPPLY_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { \
|
||||
void _Unimplemented_##MOCK::NAME ARGS \
|
||||
{ \
|
||||
while ( false ) { \
|
||||
NAME CALL; \
|
||||
} \
|
||||
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
void REAL ARGS \
|
||||
{ \
|
||||
CXXTEST_MOCK_NAMESPACE::Base_##MOCK::current().NAME CALL; \
|
||||
} \
|
||||
|
||||
//
|
||||
// Error for calling mock function w/o object
|
||||
//
|
||||
#define __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ) \
|
||||
TS_FAIL( CXXTEST_MOCK_NAMESPACE_STR #NAME #ARGS " called with no " \
|
||||
CXXTEST_MOCK_NAMESPACE_STR "Base_" #NAME " object" ); \
|
||||
|
||||
#define CXXTEST_MOCK_NAMESPACE_STR __CXXTEST_STR(CXXTEST_MOCK_NAMESPACE) "::"
|
||||
#define __CXXTEST_STR(X) __CXXTEST_XSTR(X)
|
||||
#define __CXXTEST_XSTR(X) #X
|
||||
|
||||
#if defined(CXXTEST_MOCK_TEST_SOURCE_FILE)
|
||||
//
|
||||
// Test source file: Prototypes, class declarations and implementation
|
||||
//
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
__CXXTEST_MOCK__TRAITS
|
||||
|
||||
#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#elif defined(CXXTEST_FLAGS) || defined(CXXTEST_RUNNING)
|
||||
//
|
||||
// Test file other than source: Prototypes and class declarations
|
||||
//
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
__CXXTEST_MOCK__TRAITS;
|
||||
|
||||
#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#elif defined(CXXTEST_MOCK_REAL_SOURCE_FILE)
|
||||
//
|
||||
// Real source file: "Real" implementations
|
||||
//
|
||||
#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { TYPE NAME ARGS { return REAL CALL; } } using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE { void NAME ARGS { REAL CALL; } } using namespace dummy_mock_ns
|
||||
|
||||
#else
|
||||
//
|
||||
// Ordinary header file: Just prototypes
|
||||
//
|
||||
|
||||
#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
__CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
using namespace dummy_mock_ns
|
||||
|
||||
#endif // Ordinary header file
|
||||
|
||||
//
|
||||
// How to supply extern "C" functions
|
||||
//
|
||||
#define CXXTEST_SUPPLY_C( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
CXXTEST_EXTERN_C __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
|
||||
CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL )
|
||||
|
||||
#define CXXTEST_SUPPLY_VOID_C( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
CXXTEST_EXTERN_C __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
|
||||
CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL )
|
||||
|
||||
//
|
||||
// Usually we mean the global namespace
|
||||
//
|
||||
#define CXXTEST_MOCK_GLOBAL( TYPE, NAME, ARGS, CALL ) \
|
||||
CXXTEST_MOCK( NAME, TYPE, NAME, ARGS, ::NAME, CALL )
|
||||
|
||||
#define CXXTEST_MOCK_VOID_GLOBAL( NAME, ARGS, CALL ) \
|
||||
CXXTEST_MOCK_VOID( NAME, NAME, ARGS, ::NAME, CALL )
|
||||
|
||||
#define CXXTEST_SUPPLY_GLOBAL( TYPE, NAME, ARGS, CALL ) \
|
||||
CXXTEST_SUPPLY( NAME, TYPE, NAME, ARGS, NAME, CALL )
|
||||
|
||||
#define CXXTEST_SUPPLY_VOID_GLOBAL( NAME, ARGS, CALL ) \
|
||||
CXXTEST_SUPPLY_VOID( NAME, NAME, ARGS, NAME, CALL )
|
||||
|
||||
#define CXXTEST_SUPPLY_GLOBAL_C( TYPE, NAME, ARGS, CALL ) \
|
||||
CXXTEST_SUPPLY_C( NAME, TYPE, NAME, ARGS, NAME, CALL )
|
||||
|
||||
#define CXXTEST_SUPPLY_VOID_GLOBAL_C( NAME, ARGS, CALL ) \
|
||||
CXXTEST_SUPPLY_VOID_C( NAME, NAME, ARGS, NAME, CALL )
|
||||
|
||||
//
|
||||
// What to return when no mock object has been created.
|
||||
// The default value of 0 usually works, but some cases may need this.
|
||||
//
|
||||
#define CXXTEST_MOCK_DEFAULT_VALUE( TYPE, VALUE ) \
|
||||
namespace CXXTEST_MOCK_NAMESPACE \
|
||||
{ \
|
||||
template<> \
|
||||
class MockTraits<TYPE> \
|
||||
{ \
|
||||
public: \
|
||||
static TYPE defaultValue() { return VALUE; } \
|
||||
}; \
|
||||
} using namespace dummy_mock_ns
|
||||
|
||||
#endif // __cxxtest__Mock_h__
|
32
third-party/cxxtest/cxxtest/ParenPrinter.h
vendored
Normal file
32
third-party/cxxtest/cxxtest/ParenPrinter.h
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__ParenPrinter_h__
|
||||
#define __cxxtest__ParenPrinter_h__
|
||||
|
||||
//
|
||||
// The ParenPrinter is identical to the ErrorPrinter, except it
|
||||
// prints the line number in a format expected by some compilers
|
||||
// (notably, MSVC).
|
||||
//
|
||||
|
||||
#include <cxxtest/ErrorPrinter.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class ParenPrinter : public ErrorPrinter
|
||||
{
|
||||
public:
|
||||
ParenPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout)) : ErrorPrinter(o, "(", ")") {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__ParenPrinter_h__
|
306
third-party/cxxtest/cxxtest/QtGui.h
vendored
Normal file
306
third-party/cxxtest/cxxtest/QtGui.h
vendored
Normal file
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__QtGui_h__
|
||||
#define __cxxtest__QtGui_h__
|
||||
|
||||
//
|
||||
// The QtGui displays a simple progress bar using the Qt Toolkit. It
|
||||
// has been tested with versions 2.x and 3.x.
|
||||
//
|
||||
// Apart from normal Qt command-line arguments, it accepts the following options:
|
||||
// -minimized Start minimized, pop up on error
|
||||
// -keep Don't close the window at the end
|
||||
// -title TITLE Set the window caption
|
||||
//
|
||||
// If both are -minimized and -keep specified, GUI will only keep the
|
||||
// window if it's in focus.
|
||||
//
|
||||
|
||||
#include <cxxtest/Gui.h>
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qglobal.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlayout.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qprogressbar.h>
|
||||
#include <qstatusbar.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class QtGui : public GuiListener
|
||||
{
|
||||
public:
|
||||
void enterGui(int &argc, char **argv)
|
||||
{
|
||||
parseCommandLine(argc, argv);
|
||||
createApplication(argc, argv);
|
||||
}
|
||||
|
||||
void enterWorld(const WorldDescription &wd)
|
||||
{
|
||||
createWindow(wd);
|
||||
processEvents();
|
||||
}
|
||||
|
||||
void guiEnterSuite(const char *suiteName)
|
||||
{
|
||||
showSuiteName(suiteName);
|
||||
}
|
||||
|
||||
void guiEnterTest(const char *suiteName, const char *testName)
|
||||
{
|
||||
setCaption(suiteName, testName);
|
||||
advanceProgressBar();
|
||||
showTestName(testName);
|
||||
showTestsDone(_progressBar->progress());
|
||||
processEvents();
|
||||
}
|
||||
|
||||
void yellowBar()
|
||||
{
|
||||
setColor(255, 255, 0);
|
||||
setIcon(QMessageBox::Warning);
|
||||
getTotalTests();
|
||||
processEvents();
|
||||
}
|
||||
|
||||
void redBar()
|
||||
{
|
||||
if (_startMinimized && _mainWindow->isMinimized())
|
||||
{
|
||||
showNormal();
|
||||
}
|
||||
setColor(255, 0, 0);
|
||||
setIcon(QMessageBox::Critical);
|
||||
getTotalTests();
|
||||
processEvents();
|
||||
}
|
||||
|
||||
void leaveGui()
|
||||
{
|
||||
if (keep())
|
||||
{
|
||||
showSummary();
|
||||
_application->exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
_mainWindow->close(true);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QString _title;
|
||||
bool _startMinimized, _keep;
|
||||
unsigned _numTotalTests;
|
||||
QString _strTotalTests;
|
||||
QApplication *_application;
|
||||
QWidget *_mainWindow;
|
||||
QVBoxLayout *_layout;
|
||||
QProgressBar *_progressBar;
|
||||
QStatusBar *_statusBar;
|
||||
QLabel *_suiteName, *_testName, *_testsDone;
|
||||
|
||||
void parseCommandLine(int argc, char **argv)
|
||||
{
|
||||
_startMinimized = _keep = false;
|
||||
_title = argv[0];
|
||||
|
||||
for (int i = 1; i < argc; ++ i)
|
||||
{
|
||||
QString arg(argv[i]);
|
||||
if (arg == "-minimized")
|
||||
{
|
||||
_startMinimized = true;
|
||||
}
|
||||
else if (arg == "-keep")
|
||||
{
|
||||
_keep = true;
|
||||
}
|
||||
else if (arg == "-title" && (i + 1 < argc))
|
||||
{
|
||||
_title = argv[++i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createApplication(int &argc, char **argv)
|
||||
{
|
||||
_application = new QApplication(argc, argv);
|
||||
}
|
||||
|
||||
void createWindow(const WorldDescription &wd)
|
||||
{
|
||||
getTotalTests(wd);
|
||||
createMainWindow();
|
||||
createProgressBar();
|
||||
createStatusBar();
|
||||
setMainWidget();
|
||||
if (_startMinimized)
|
||||
{
|
||||
showMinimized();
|
||||
}
|
||||
else
|
||||
{
|
||||
showNormal();
|
||||
}
|
||||
}
|
||||
|
||||
void getTotalTests()
|
||||
{
|
||||
getTotalTests(tracker().world());
|
||||
}
|
||||
|
||||
void getTotalTests(const WorldDescription &wd)
|
||||
{
|
||||
_numTotalTests = wd.numTotalTests();
|
||||
char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
|
||||
_strTotalTests = wd.strTotalTests(s);
|
||||
}
|
||||
|
||||
void createMainWindow()
|
||||
{
|
||||
_mainWindow = new QWidget();
|
||||
_layout = new QVBoxLayout(_mainWindow);
|
||||
}
|
||||
|
||||
void createProgressBar()
|
||||
{
|
||||
_layout->addWidget(_progressBar = new QProgressBar(_numTotalTests, _mainWindow));
|
||||
_progressBar->setProgress(0);
|
||||
setColor(0, 255, 0);
|
||||
setIcon(QMessageBox::Information);
|
||||
}
|
||||
|
||||
void createStatusBar()
|
||||
{
|
||||
_layout->addWidget(_statusBar = new QStatusBar(_mainWindow));
|
||||
_statusBar->addWidget(_suiteName = new QLabel(_statusBar), 2);
|
||||
_statusBar->addWidget(_testName = new QLabel(_statusBar), 4);
|
||||
_statusBar->addWidget(_testsDone = new QLabel(_statusBar), 1);
|
||||
}
|
||||
|
||||
void setMainWidget()
|
||||
{
|
||||
_application->setMainWidget(_mainWindow);
|
||||
}
|
||||
|
||||
void showMinimized()
|
||||
{
|
||||
_mainWindow->showMinimized();
|
||||
}
|
||||
|
||||
void showNormal()
|
||||
{
|
||||
_mainWindow->showNormal();
|
||||
centerWindow();
|
||||
}
|
||||
|
||||
void setCaption(const QString &suiteName, const QString &testName)
|
||||
{
|
||||
_mainWindow->setCaption(_title + " - " + suiteName + "::" + testName + "()");
|
||||
}
|
||||
|
||||
void showSuiteName(const QString &suiteName)
|
||||
{
|
||||
_suiteName->setText("class " + suiteName);
|
||||
}
|
||||
|
||||
void advanceProgressBar()
|
||||
{
|
||||
_progressBar->setProgress(_progressBar->progress() + 1);
|
||||
}
|
||||
|
||||
void showTestName(const QString &testName)
|
||||
{
|
||||
_testName->setText(testName + "()");
|
||||
}
|
||||
|
||||
void showTestsDone(unsigned testsDone)
|
||||
{
|
||||
_testsDone->setText(asString(testsDone) + " of " + _strTotalTests);
|
||||
}
|
||||
|
||||
static QString asString(unsigned n)
|
||||
{
|
||||
return QString::number(n);
|
||||
}
|
||||
|
||||
void setColor(int r, int g, int b)
|
||||
{
|
||||
QPalette palette = _progressBar->palette();
|
||||
palette.setColor(QColorGroup::Highlight, QColor(r, g, b));
|
||||
_progressBar->setPalette(palette);
|
||||
}
|
||||
|
||||
void setIcon(QMessageBox::Icon icon)
|
||||
{
|
||||
#if QT_VERSION >= 0x030000
|
||||
_mainWindow->setIcon(QMessageBox::standardIcon(icon));
|
||||
#else // Qt version < 3.0.0
|
||||
_mainWindow->setIcon(QMessageBox::standardIcon(icon, QApplication::style().guiStyle()));
|
||||
#endif // QT_VERSION
|
||||
}
|
||||
|
||||
void processEvents()
|
||||
{
|
||||
_application->processEvents();
|
||||
}
|
||||
|
||||
void centerWindow()
|
||||
{
|
||||
QWidget *desktop = QApplication::desktop();
|
||||
int xCenter = desktop->x() + (desktop->width() / 2);
|
||||
int yCenter = desktop->y() + (desktop->height() / 2);
|
||||
|
||||
int windowWidth = (desktop->width() * 4) / 5;
|
||||
int windowHeight = _mainWindow->height();
|
||||
_mainWindow->setGeometry(xCenter - (windowWidth / 2), yCenter - (windowHeight / 2), windowWidth, windowHeight);
|
||||
}
|
||||
|
||||
bool keep()
|
||||
{
|
||||
if (!_keep)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!_startMinimized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return (_mainWindow == _application->activeWindow());
|
||||
}
|
||||
|
||||
void showSummary()
|
||||
{
|
||||
QString summary = _strTotalTests + (_numTotalTests == 1 ? " test" : " tests");
|
||||
if (tracker().failedTests())
|
||||
{
|
||||
summary = "Failed " + asString(tracker().failedTests()) + " of " + summary;
|
||||
}
|
||||
else
|
||||
{
|
||||
summary = summary + " passed";
|
||||
}
|
||||
|
||||
_mainWindow->setCaption(_title + " - " + summary);
|
||||
|
||||
_statusBar->removeWidget(_suiteName);
|
||||
_statusBar->removeWidget(_testName);
|
||||
_testsDone->setText(summary);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__QtGui_h__
|
361
third-party/cxxtest/cxxtest/RealDescriptions.cpp
vendored
Normal file
361
third-party/cxxtest/cxxtest/RealDescriptions.cpp
vendored
Normal file
|
@ -0,0 +1,361 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__RealDescriptions_cpp__
|
||||
#define __cxxtest__RealDescriptions_cpp__
|
||||
|
||||
//
|
||||
// NOTE: If an error occur during world construction/deletion, CxxTest cannot
|
||||
// know where the error originated.
|
||||
//
|
||||
|
||||
#include <cxxtest/RealDescriptions.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
RealTestDescription::RealTestDescription()
|
||||
{
|
||||
}
|
||||
|
||||
RealTestDescription::RealTestDescription(List &argList,
|
||||
SuiteDescription &argSuite,
|
||||
unsigned argLine,
|
||||
const char *argTestName)
|
||||
{
|
||||
initialize(argList, argSuite, argLine, argTestName);
|
||||
}
|
||||
|
||||
void RealTestDescription::initialize(List &argList,
|
||||
SuiteDescription &argSuite,
|
||||
unsigned argLine,
|
||||
const char *argTestName)
|
||||
{
|
||||
_suite = &argSuite;
|
||||
_line = argLine;
|
||||
_testName = argTestName;
|
||||
attach(argList);
|
||||
}
|
||||
|
||||
bool RealTestDescription::setUp()
|
||||
{
|
||||
if (!suite())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture())
|
||||
{
|
||||
bool ok;
|
||||
_TS_TRY { ok = gf->setUp(); }
|
||||
_TS_LAST_CATCH( { ok = false; });
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
doFailTest(file(), line(), "Error in GlobalFixture::setUp()");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_TS_TRY
|
||||
{
|
||||
bool ok = false;
|
||||
_TSM_ASSERT_THROWS_NOTHING(file(), line(), "Exception thrown from setUp()", suite()->setUp(); ok = true);
|
||||
if (ok == false) { return ok; }
|
||||
}
|
||||
_TS_CATCH_ABORT( { return false; })
|
||||
_TS_CATCH_SKIPPED( { return false; });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RealTestDescription::tearDown()
|
||||
{
|
||||
if (!suite())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_TS_TRY
|
||||
{
|
||||
_TSM_ASSERT_THROWS_NOTHING(file(), line(), "Exception thrown from tearDown()", suite()->tearDown());
|
||||
}
|
||||
_TS_CATCH_ABORT( { return false; })
|
||||
_TS_CATCH_SKIPPED( { return false; });
|
||||
|
||||
for (GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture())
|
||||
{
|
||||
bool ok;
|
||||
_TS_TRY { ok = gf->tearDown(); }
|
||||
_TS_LAST_CATCH( { ok = false; });
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
doFailTest(file(), line(), "Error in GlobalFixture::tearDown()");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *RealTestDescription::file() const { return _suite->file(); }
|
||||
int RealTestDescription::line() const { return _line; }
|
||||
const char *RealTestDescription::testName() const { return _testName; }
|
||||
const char *RealTestDescription::suiteName() const { return _suite->suiteName(); }
|
||||
|
||||
TestDescription *RealTestDescription::next() { return (RealTestDescription *)Link::next(); }
|
||||
const TestDescription *RealTestDescription::next() const { return (const RealTestDescription *)Link::next(); }
|
||||
|
||||
TestSuite *RealTestDescription::suite() const { return _suite->suite(); }
|
||||
|
||||
void RealTestDescription::run()
|
||||
{
|
||||
_TS_TRY { runTest(); }
|
||||
_TS_CATCH_ABORT( {})
|
||||
_TS_CATCH_SKIPPED( {})
|
||||
___TSM_CATCH(file(), line(), "Exception thrown from test");
|
||||
}
|
||||
|
||||
RealSuiteDescription::RealSuiteDescription() {}
|
||||
RealSuiteDescription::RealSuiteDescription(const char *argFile,
|
||||
unsigned argLine,
|
||||
const char *argSuiteName,
|
||||
List &argTests)
|
||||
{
|
||||
initialize(argFile, argLine, argSuiteName, argTests);
|
||||
}
|
||||
|
||||
void RealSuiteDescription::initialize(const char *argFile,
|
||||
unsigned argLine,
|
||||
const char *argSuiteName,
|
||||
List &argTests)
|
||||
{
|
||||
_file = argFile;
|
||||
_line = argLine;
|
||||
_suiteName = argSuiteName;
|
||||
_tests = &argTests;
|
||||
|
||||
attach(_suites);
|
||||
}
|
||||
|
||||
const char *RealSuiteDescription::file() const { return _file; }
|
||||
int RealSuiteDescription::line() const { return _line; }
|
||||
const char *RealSuiteDescription::suiteName() const { return _suiteName; }
|
||||
|
||||
TestDescription *RealSuiteDescription::firstTest() { return (RealTestDescription *)_tests->head(); }
|
||||
const TestDescription *RealSuiteDescription::firstTest() const { return (const RealTestDescription *)_tests->head(); }
|
||||
SuiteDescription *RealSuiteDescription::next() { return (RealSuiteDescription *)Link::next(); }
|
||||
const SuiteDescription *RealSuiteDescription::next() const { return (const RealSuiteDescription *)Link::next(); }
|
||||
|
||||
unsigned RealSuiteDescription::numTests() const { return _tests->size(); }
|
||||
|
||||
const TestDescription &RealSuiteDescription::testDescription(unsigned i) const
|
||||
{
|
||||
return *(RealTestDescription *)_tests->nth(i);
|
||||
}
|
||||
|
||||
void RealSuiteDescription::activateAllTests()
|
||||
{
|
||||
_tests->activateAll();
|
||||
}
|
||||
|
||||
bool RealSuiteDescription::leaveOnly(const char *testName)
|
||||
{
|
||||
for (TestDescription *td = firstTest(); td != 0; td = td->next())
|
||||
{
|
||||
if (stringsEqual(td->testName(), testName))
|
||||
{
|
||||
_tests->leaveOnly(*td);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
StaticSuiteDescription::StaticSuiteDescription() {}
|
||||
StaticSuiteDescription::StaticSuiteDescription(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, TestSuite &argSuite,
|
||||
List &argTests) :
|
||||
RealSuiteDescription(argFile, argLine, argSuiteName, argTests)
|
||||
{
|
||||
doInitialize(argSuite);
|
||||
}
|
||||
|
||||
void StaticSuiteDescription::initialize(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, TestSuite &argSuite,
|
||||
List &argTests)
|
||||
{
|
||||
RealSuiteDescription::initialize(argFile, argLine, argSuiteName, argTests);
|
||||
doInitialize(argSuite);
|
||||
}
|
||||
|
||||
void StaticSuiteDescription::doInitialize(TestSuite &argSuite)
|
||||
{
|
||||
_suite = &argSuite;
|
||||
}
|
||||
|
||||
TestSuite *StaticSuiteDescription::suite() const
|
||||
{
|
||||
return _suite;
|
||||
}
|
||||
|
||||
bool StaticSuiteDescription::setUp() { return true; }
|
||||
bool StaticSuiteDescription::tearDown() { return true; }
|
||||
|
||||
CommonDynamicSuiteDescription::CommonDynamicSuiteDescription() {}
|
||||
CommonDynamicSuiteDescription::CommonDynamicSuiteDescription(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, List &argTests,
|
||||
unsigned argCreateLine, unsigned argDestroyLine) :
|
||||
RealSuiteDescription(argFile, argLine, argSuiteName, argTests)
|
||||
{
|
||||
doInitialize(argCreateLine, argDestroyLine);
|
||||
}
|
||||
|
||||
void CommonDynamicSuiteDescription::initialize(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, List &argTests,
|
||||
unsigned argCreateLine, unsigned argDestroyLine)
|
||||
{
|
||||
RealSuiteDescription::initialize(argFile, argLine, argSuiteName, argTests);
|
||||
doInitialize(argCreateLine, argDestroyLine);
|
||||
}
|
||||
|
||||
void CommonDynamicSuiteDescription::doInitialize(unsigned argCreateLine, unsigned argDestroyLine)
|
||||
{
|
||||
_createLine = argCreateLine;
|
||||
_destroyLine = argDestroyLine;
|
||||
}
|
||||
|
||||
List &RealWorldDescription::suites()
|
||||
{
|
||||
return RealSuiteDescription::_suites;
|
||||
}
|
||||
|
||||
unsigned RealWorldDescription::numSuites(void) const
|
||||
{
|
||||
return suites().size();
|
||||
}
|
||||
|
||||
unsigned RealWorldDescription::numTotalTests(void) const
|
||||
{
|
||||
unsigned count = 0;
|
||||
for (const SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next())
|
||||
{
|
||||
count += sd->numTests();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
SuiteDescription *RealWorldDescription::firstSuite()
|
||||
{
|
||||
return (RealSuiteDescription *)suites().head();
|
||||
}
|
||||
|
||||
const SuiteDescription *RealWorldDescription::firstSuite() const
|
||||
{
|
||||
return (const RealSuiteDescription *)suites().head();
|
||||
}
|
||||
|
||||
const SuiteDescription &RealWorldDescription::suiteDescription(unsigned i) const
|
||||
{
|
||||
return *(const RealSuiteDescription *)suites().nth(i);
|
||||
}
|
||||
|
||||
void RealWorldDescription::activateAllTests()
|
||||
{
|
||||
suites().activateAll();
|
||||
for (SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next())
|
||||
{
|
||||
sd->activateAllTests();
|
||||
}
|
||||
}
|
||||
|
||||
bool RealWorldDescription::leaveOnly(const char *suiteName, const char *testName)
|
||||
{
|
||||
for (SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next())
|
||||
{
|
||||
if (stringsEqual(sd->suiteName(), suiteName))
|
||||
{
|
||||
if (testName)
|
||||
{
|
||||
if (!sd->leaveOnly(testName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
suites().leaveOnly(*sd);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RealWorldDescription::setUp()
|
||||
{
|
||||
for (GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture())
|
||||
{
|
||||
bool ok;
|
||||
_TS_TRY
|
||||
{
|
||||
ok = gf->setUpWorld();
|
||||
if (tracker().testFailed())
|
||||
{
|
||||
tracker().initialize();
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
_TS_LAST_CATCH( { ok = false; });
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
reportError("Error setting up world");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RealWorldDescription::tearDown()
|
||||
{
|
||||
for (GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture())
|
||||
{
|
||||
bool ok;
|
||||
_TS_TRY { ok = gf->tearDownWorld(); }
|
||||
_TS_LAST_CATCH( { ok = false; });
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
reportError("Error tearing down world");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RealWorldDescription::reportError(const char *message)
|
||||
{
|
||||
doWarn(__FILE__, 5, message);
|
||||
}
|
||||
|
||||
void activateAllTests()
|
||||
{
|
||||
RealWorldDescription().activateAllTests();
|
||||
}
|
||||
|
||||
bool leaveOnly(const char *suiteName, const char *testName)
|
||||
{
|
||||
return RealWorldDescription().leaveOnly(suiteName, testName);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __cxxtest__RealDescriptions_cpp__
|
||||
|
243
third-party/cxxtest/cxxtest/RealDescriptions.h
vendored
Normal file
243
third-party/cxxtest/cxxtest/RealDescriptions.h
vendored
Normal file
|
@ -0,0 +1,243 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__RealDescriptions_h__
|
||||
#define __cxxtest__RealDescriptions_h__
|
||||
|
||||
//
|
||||
// The "real" description classes
|
||||
//
|
||||
|
||||
#include <cxxtest/Descriptions.h>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <cxxtest/GlobalFixture.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class RealTestDescription : public TestDescription
|
||||
{
|
||||
public:
|
||||
RealTestDescription();
|
||||
RealTestDescription(List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName);
|
||||
void initialize(List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName);
|
||||
|
||||
const char *file() const;
|
||||
int line() const;
|
||||
const char *testName() const;
|
||||
const char *suiteName() const;
|
||||
|
||||
TestDescription *next();
|
||||
const TestDescription *next() const;
|
||||
|
||||
TestSuite *suite() const;
|
||||
|
||||
bool setUp();
|
||||
void run();
|
||||
bool tearDown();
|
||||
|
||||
private:
|
||||
RealTestDescription(const RealTestDescription &);
|
||||
RealTestDescription &operator=(const RealTestDescription &);
|
||||
|
||||
virtual void runTest() = 0;
|
||||
|
||||
SuiteDescription *_suite;
|
||||
int _line;
|
||||
const char *_testName;
|
||||
};
|
||||
|
||||
class RealSuiteDescription : public SuiteDescription
|
||||
{
|
||||
public:
|
||||
RealSuiteDescription();
|
||||
RealSuiteDescription(const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests);
|
||||
|
||||
void initialize(const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests);
|
||||
|
||||
const char *file() const;
|
||||
int line() const;
|
||||
const char *suiteName() const;
|
||||
|
||||
TestDescription *firstTest();
|
||||
const TestDescription *firstTest() const;
|
||||
SuiteDescription *next();
|
||||
const SuiteDescription *next() const;
|
||||
|
||||
unsigned numTests() const;
|
||||
const TestDescription &testDescription(unsigned i) const;
|
||||
|
||||
void activateAllTests();
|
||||
bool leaveOnly(const char *testName);
|
||||
|
||||
private:
|
||||
RealSuiteDescription(const RealSuiteDescription &);
|
||||
RealSuiteDescription &operator=(const RealSuiteDescription &);
|
||||
|
||||
const char *_file;
|
||||
int _line;
|
||||
const char *_suiteName;
|
||||
List *_tests;
|
||||
|
||||
static List _suites;
|
||||
friend class RealWorldDescription;
|
||||
};
|
||||
|
||||
class StaticSuiteDescription : public RealSuiteDescription
|
||||
{
|
||||
public:
|
||||
StaticSuiteDescription();
|
||||
StaticSuiteDescription(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, TestSuite &argSuite,
|
||||
List &argTests);
|
||||
|
||||
void initialize(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, TestSuite &argSuite,
|
||||
List &argTests);
|
||||
TestSuite *suite() const;
|
||||
|
||||
bool setUp();
|
||||
bool tearDown();
|
||||
|
||||
private:
|
||||
StaticSuiteDescription(const StaticSuiteDescription &);
|
||||
StaticSuiteDescription &operator=(const StaticSuiteDescription &);
|
||||
|
||||
void doInitialize(TestSuite &argSuite);
|
||||
|
||||
TestSuite *_suite;
|
||||
};
|
||||
|
||||
class CommonDynamicSuiteDescription : public RealSuiteDescription
|
||||
{
|
||||
public:
|
||||
CommonDynamicSuiteDescription();
|
||||
CommonDynamicSuiteDescription(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, List &argTests,
|
||||
unsigned argCreateLine, unsigned argDestroyLine);
|
||||
|
||||
void initialize(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, List &argTests,
|
||||
unsigned argCreateLine, unsigned argDestroyLine);
|
||||
|
||||
protected:
|
||||
unsigned _createLine, _destroyLine;
|
||||
|
||||
private:
|
||||
void doInitialize(unsigned argCreateLine, unsigned argDestroyLine);
|
||||
};
|
||||
|
||||
template<class S>
|
||||
class DynamicSuiteDescription : public CommonDynamicSuiteDescription
|
||||
{
|
||||
public:
|
||||
DynamicSuiteDescription() {}
|
||||
DynamicSuiteDescription(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, List &argTests,
|
||||
S *&argSuite, unsigned argCreateLine,
|
||||
unsigned argDestroyLine) :
|
||||
CommonDynamicSuiteDescription(argFile, argLine, argSuiteName, argTests, argCreateLine, argDestroyLine)
|
||||
{
|
||||
_suite = &argSuite;
|
||||
}
|
||||
|
||||
void initialize(const char *argFile, unsigned argLine,
|
||||
const char *argSuiteName, List &argTests,
|
||||
S *&argSuite, unsigned argCreateLine,
|
||||
unsigned argDestroyLine)
|
||||
{
|
||||
CommonDynamicSuiteDescription::initialize(argFile, argLine,
|
||||
argSuiteName, argTests,
|
||||
argCreateLine, argDestroyLine);
|
||||
_suite = &argSuite;
|
||||
}
|
||||
|
||||
TestSuite *suite() const { return realSuite(); }
|
||||
|
||||
bool setUp();
|
||||
bool tearDown();
|
||||
|
||||
private:
|
||||
S *realSuite() const { return *_suite; }
|
||||
void setSuite(S *s) { *_suite = s; }
|
||||
|
||||
void createSuite()
|
||||
{
|
||||
setSuite(S::createSuite());
|
||||
}
|
||||
|
||||
void destroySuite()
|
||||
{
|
||||
S *s = realSuite();
|
||||
setSuite(0);
|
||||
S::destroySuite(s);
|
||||
}
|
||||
|
||||
S **_suite;
|
||||
};
|
||||
|
||||
template<class S>
|
||||
bool DynamicSuiteDescription<S>::setUp()
|
||||
{
|
||||
_TS_TRY
|
||||
{
|
||||
_TSM_ASSERT_THROWS_NOTHING(file(), _createLine, "Exception thrown from createSuite()", createSuite());
|
||||
_TSM_ASSERT(file(), _createLine, "createSuite() failed", suite() != 0);
|
||||
}
|
||||
_TS_CATCH_ABORT( { return false; })
|
||||
_TS_CATCH_SKIPPED( { return false; });
|
||||
|
||||
return (suite() != 0);
|
||||
}
|
||||
|
||||
template<class S>
|
||||
bool DynamicSuiteDescription<S>::tearDown()
|
||||
{
|
||||
if (!_suite)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_TS_TRY
|
||||
{
|
||||
_TSM_ASSERT_THROWS_NOTHING(file(), _destroyLine, "destroySuite() failed", destroySuite());
|
||||
}
|
||||
_TS_CATCH_ABORT( { return false; })
|
||||
_TS_CATCH_SKIPPED( { return false; });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class RealWorldDescription : public WorldDescription
|
||||
{
|
||||
public:
|
||||
static List &suites();
|
||||
const char *worldName() const { return _worldName;}
|
||||
unsigned numSuites(void) const;
|
||||
unsigned numTotalTests(void) const;
|
||||
SuiteDescription *firstSuite();
|
||||
const SuiteDescription *firstSuite() const;
|
||||
const SuiteDescription &suiteDescription(unsigned i) const;
|
||||
void activateAllTests();
|
||||
bool leaveOnly(const char *suiteName, const char *testName = 0);
|
||||
|
||||
bool setUp();
|
||||
bool tearDown();
|
||||
static void reportError(const char *message);
|
||||
|
||||
static const char *_worldName;
|
||||
};
|
||||
|
||||
void activateAllTests();
|
||||
bool leaveOnly(const char *suiteName, const char *testName = 0);
|
||||
}
|
||||
|
||||
#endif // __cxxtest__RealDescriptions_h__
|
||||
|
29
third-party/cxxtest/cxxtest/Root.cpp
vendored
Normal file
29
third-party/cxxtest/cxxtest/Root.cpp
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__Root_cpp__
|
||||
#define __cxxtest__Root_cpp__
|
||||
|
||||
//
|
||||
// This file holds the "root" of CxxTest, i.e.
|
||||
// the parts that must be in a source file file.
|
||||
//
|
||||
|
||||
#include <cxxtest/ValueTraits.cpp>
|
||||
#include <cxxtest/Descriptions.cpp>
|
||||
#include <cxxtest/DummyDescriptions.cpp>
|
||||
#include <cxxtest/GlobalFixture.cpp>
|
||||
#include <cxxtest/LinkedList.cpp>
|
||||
#include <cxxtest/RealDescriptions.cpp>
|
||||
#include <cxxtest/TestSuite.cpp>
|
||||
#include <cxxtest/TestTracker.cpp>
|
||||
|
||||
#endif // __cxxtest__Root_cpp__
|
18
third-party/cxxtest/cxxtest/SelfTest.h
vendored
Normal file
18
third-party/cxxtest/cxxtest/SelfTest.h
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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_SelfTest_h__
|
||||
#define __cxxtest_SelfTest_h__
|
||||
|
||||
#define CXXTEST_SUITE(name)
|
||||
#define CXXTEST_CODE(member)
|
||||
|
||||
#endif // __cxxtest_SelfTest_h__
|
36
third-party/cxxtest/cxxtest/StdHeaders.h
vendored
Normal file
36
third-party/cxxtest/cxxtest/StdHeaders.h
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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_StdHeaders_h__
|
||||
#define __cxxtest_StdHeaders_h__
|
||||
|
||||
//
|
||||
// This file basically #includes the STL headers.
|
||||
// It exists to support warning level 4 in Visual C++
|
||||
//
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning( push, 1 )
|
||||
#endif // _MSC_VER
|
||||
|
||||
#include <complex>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning( pop )
|
||||
#endif // _MSC_VER
|
||||
|
||||
#endif // __cxxtest_StdHeaders_h__
|
70
third-party/cxxtest/cxxtest/StdTestSuite.h
vendored
Normal file
70
third-party/cxxtest/cxxtest/StdTestSuite.h
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__StdTestSuite_h__
|
||||
#define __cxxtest__StdTestSuite_h__
|
||||
|
||||
//
|
||||
// This provides explicit partial specializations for STL-based
|
||||
// TestSuite comparison functions
|
||||
//
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
|
||||
#ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
|
||||
template<class X, class Y, class D>
|
||||
struct delta<std::vector<X>, std::vector<Y>, D>
|
||||
{
|
||||
static bool test(std::vector<X> x, std::vector<Y> y, D d)
|
||||
{
|
||||
if (x.size() != y.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < x.size(); ++i)
|
||||
if (! delta<X, Y, D>::test(x[i], y[i], d))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class X, class Y, class D>
|
||||
struct delta<std::list<X>, std::list<Y>, D>
|
||||
{
|
||||
static bool test(std::list<X> x, std::list<Y> y, D d)
|
||||
{
|
||||
typename std::list<X>::const_iterator x_it = x.begin();
|
||||
typename std::list<Y>::const_iterator y_it = y.begin();
|
||||
for (; x_it != x.end(); ++x_it, ++y_it)
|
||||
{
|
||||
if (y_it == y.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (! delta<X, Y, D>::test(*x_it, *y_it, d))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return y_it == y.end();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace CxxTest
|
||||
|
||||
#endif // __cxxtest__StdTestSuite_h__
|
||||
|
303
third-party/cxxtest/cxxtest/StdValueTraits.h
vendored
Normal file
303
third-party/cxxtest/cxxtest/StdValueTraits.h
vendored
Normal file
|
@ -0,0 +1,303 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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_StdValueTraits_h__
|
||||
#define __cxxtest_StdValueTraits_h__
|
||||
|
||||
//
|
||||
// This file defines ValueTraits for std:: stuff.
|
||||
// It is #included by <cxxtest/ValueTraits.h> if you
|
||||
// define CXXTEST_HAVE_STD
|
||||
//
|
||||
|
||||
#include <cxxtest/ValueTraits.h>
|
||||
#include <cxxtest/StdHeaders.h>
|
||||
|
||||
#ifdef _CXXTEST_OLD_STD
|
||||
# define CXXTEST_STD(x) x
|
||||
#else // !_CXXTEST_OLD_STD
|
||||
# define CXXTEST_STD(x) std::x
|
||||
#endif // _CXXTEST_OLD_STD
|
||||
|
||||
#ifndef CXXTEST_USER_VALUE_TRAITS
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
//
|
||||
// NOTE: This should have been
|
||||
// template<class Char, class Traits, class Allocator>
|
||||
// class ValueTraits< std::basic_string<Char, Traits, Allocator> > {};
|
||||
// But MSVC doesn't support it (yet).
|
||||
//
|
||||
|
||||
//
|
||||
// If we have std::string, we might as well use it
|
||||
//
|
||||
class StdTraitsBase
|
||||
{
|
||||
public:
|
||||
StdTraitsBase &operator<<(const CXXTEST_STD(string) &s) { _s += s; return *this; }
|
||||
const char *asString() const { return _s.c_str(); }
|
||||
|
||||
private:
|
||||
CXXTEST_STD(string) _s;
|
||||
};
|
||||
|
||||
//
|
||||
// std::string
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const CXXTEST_STD(string)> : public StdTraitsBase
|
||||
{
|
||||
static bool mb_partial(char ch)
|
||||
{
|
||||
return !!(ch & 0x80);
|
||||
}
|
||||
static bool mb_start(char ch)
|
||||
{
|
||||
return (ch & 0xC0) == 0xC0;
|
||||
}
|
||||
static size_t mb_length(char ch)
|
||||
{
|
||||
size_t numBytes = 1;
|
||||
while ((ch & (1 << (7 - numBytes))) && numBytes < 6)
|
||||
{
|
||||
++numBytes;
|
||||
}
|
||||
return numBytes;
|
||||
}
|
||||
static bool is_mb(const CXXTEST_STD(string) &s, unsigned i)
|
||||
{
|
||||
if (!mb_start(s[i]) || i + mb_length(s[i]) > s.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (size_t len = mb_length(s[i]); len > 0; -- len, ++ i)
|
||||
{
|
||||
if (!mb_partial(s[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(string) &s)
|
||||
{
|
||||
*this << "\"";
|
||||
for (unsigned i = 0; i < s.length(); ++ i)
|
||||
{
|
||||
if (is_mb(s, i))
|
||||
{
|
||||
for (size_t len = mb_length(s[i]); len > 0; -- len, ++ i)
|
||||
{
|
||||
char c[2] = { s[i], '\0' };
|
||||
*this << c;
|
||||
}
|
||||
-- i;
|
||||
}
|
||||
else
|
||||
{
|
||||
char c[sizeof("\\xXX")];
|
||||
charToString(s[i], c);
|
||||
*this << c;
|
||||
}
|
||||
}
|
||||
*this << "\"";
|
||||
}
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(CXXTEST_STD(string));
|
||||
|
||||
#ifndef _CXXTEST_OLD_STD
|
||||
//
|
||||
// std::wstring
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const CXXTEST_STD(basic_string<wchar_t>)> : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(basic_string<wchar_t>) &s)
|
||||
{
|
||||
*this << "L\"";
|
||||
for (unsigned i = 0; i < s.length(); ++ i)
|
||||
{
|
||||
char c[sizeof("\\x12345678")];
|
||||
charToString((unsigned long)s[i], c);
|
||||
*this << c;
|
||||
}
|
||||
*this << "\"";
|
||||
}
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(CXXTEST_STD(basic_string<wchar_t>));
|
||||
#endif // _CXXTEST_OLD_STD
|
||||
|
||||
//
|
||||
// Convert a range defined by iterators to a string
|
||||
// This is useful for almost all STL containers
|
||||
//
|
||||
template<class Stream, class Iterator>
|
||||
void dumpRange(Stream &s, Iterator first, Iterator last)
|
||||
{
|
||||
if (first == last)
|
||||
{
|
||||
s << "{}";
|
||||
return;
|
||||
}
|
||||
|
||||
s << "{ ";
|
||||
while (first != last)
|
||||
{
|
||||
s << TS_AS_STRING(*first);
|
||||
if (++ first != last)
|
||||
{
|
||||
s << ", ";
|
||||
}
|
||||
}
|
||||
s << " }";
|
||||
}
|
||||
|
||||
#ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
//
|
||||
// std::pair
|
||||
//
|
||||
template<class First, class Second>
|
||||
class ValueTraits< CXXTEST_STD(pair)<First, Second> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(pair)<First, Second> &p)
|
||||
{
|
||||
*this << "<" << TS_AS_STRING(p.first) << ", " << TS_AS_STRING(p.second) << ">";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::vector
|
||||
//
|
||||
template<class Element>
|
||||
class ValueTraits< CXXTEST_STD(vector)<Element> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(vector)<Element> &v)
|
||||
{
|
||||
dumpRange(*this, v.begin(), v.end());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::list
|
||||
//
|
||||
template<class Element>
|
||||
class ValueTraits< CXXTEST_STD(list)<Element> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(list)<Element> &l)
|
||||
{
|
||||
dumpRange(*this, l.begin(), l.end());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::set
|
||||
//
|
||||
template<class Element>
|
||||
class ValueTraits< CXXTEST_STD(set)<Element> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(set)<Element> &s)
|
||||
{
|
||||
dumpRange(*this, s.begin(), s.end());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::map
|
||||
//
|
||||
template<class Key, class Value>
|
||||
class ValueTraits< CXXTEST_STD(map)<Key, Value> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(map)<Key, Value> &m)
|
||||
{
|
||||
dumpRange(*this, m.begin(), m.end());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::deque
|
||||
//
|
||||
template<class Element>
|
||||
class ValueTraits< CXXTEST_STD(deque)<Element> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(deque)<Element> &d)
|
||||
{
|
||||
dumpRange(*this, d.begin(), d.end());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::multiset
|
||||
//
|
||||
template<class Element>
|
||||
class ValueTraits< CXXTEST_STD(multiset)<Element> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(multiset)<Element> &ms)
|
||||
{
|
||||
dumpRange(*this, ms.begin(), ms.end());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::multimap
|
||||
//
|
||||
template<class Key, class Value>
|
||||
class ValueTraits< CXXTEST_STD(multimap)<Key, Value> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(multimap)<Key, Value> &mm)
|
||||
{
|
||||
dumpRange(*this, mm.begin(), mm.end());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// std::complex
|
||||
//
|
||||
template<class Number>
|
||||
class ValueTraits< CXXTEST_STD(complex)<Number> > : public StdTraitsBase
|
||||
{
|
||||
public:
|
||||
ValueTraits(const CXXTEST_STD(complex)<Number> &c)
|
||||
{
|
||||
if (!c.imag())
|
||||
{
|
||||
*this << TS_AS_STRING(c.real());
|
||||
}
|
||||
else if (!c.real())
|
||||
{
|
||||
*this << "(" << TS_AS_STRING(c.imag()) << " * i)";
|
||||
}
|
||||
else
|
||||
{
|
||||
*this << "(" << TS_AS_STRING(c.real()) << " + " << TS_AS_STRING(c.imag()) << " * i)";
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif // _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
|
||||
}
|
||||
|
||||
#endif // CXXTEST_USER_VALUE_TRAITS
|
||||
|
||||
#endif // __cxxtest_StdValueTraits_h__
|
52
third-party/cxxtest/cxxtest/StdioFilePrinter.h
vendored
Normal file
52
third-party/cxxtest/cxxtest/StdioFilePrinter.h
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__StdioFilePrinter_h__
|
||||
#define __cxxtest__StdioFilePrinter_h__
|
||||
|
||||
//
|
||||
// The StdioFilePrinter is a simple TestListener that
|
||||
// just prints "OK" if everything goes well, otherwise
|
||||
// reports the error in the format of compiler messages.
|
||||
// This class uses <stdio.h>, i.e. FILE * and fprintf().
|
||||
//
|
||||
|
||||
#include <cxxtest/ErrorFormatter.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class StdioFilePrinter : public ErrorFormatter
|
||||
{
|
||||
public:
|
||||
StdioFilePrinter(FILE *o, const char *preLine = ":", const char *postLine = "") :
|
||||
ErrorFormatter(new Adapter(o), preLine, postLine) {}
|
||||
virtual ~StdioFilePrinter() { delete outputStream(); }
|
||||
|
||||
private:
|
||||
class Adapter : public OutputStream
|
||||
{
|
||||
Adapter(const Adapter &);
|
||||
Adapter &operator=(const Adapter &);
|
||||
|
||||
FILE *_o;
|
||||
|
||||
public:
|
||||
Adapter(FILE *o) : _o(o) {}
|
||||
void flush() { fflush(_o); }
|
||||
OutputStream &operator<<(unsigned i) { fprintf(_o, "%u", i); return *this; }
|
||||
OutputStream &operator<<(const char *s) { fputs(s, _o); return *this; }
|
||||
OutputStream &operator<<(Manipulator m) { return OutputStream::operator<<(m); }
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__StdioFilePrinter_h__
|
33
third-party/cxxtest/cxxtest/StdioPrinter.h
vendored
Normal file
33
third-party/cxxtest/cxxtest/StdioPrinter.h
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__StdioPrinter_h__
|
||||
#define __cxxtest__StdioPrinter_h__
|
||||
|
||||
//
|
||||
// The StdioPrinter is an StdioFilePrinter which defaults to stdout.
|
||||
// This should have been called StdOutPrinter or something, but the name
|
||||
// has been historically used.
|
||||
//
|
||||
|
||||
#include <cxxtest/StdioFilePrinter.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class StdioPrinter : public StdioFilePrinter
|
||||
{
|
||||
public:
|
||||
StdioPrinter(FILE *o = stdout, const char *preLine = ":", const char *postLine = "") :
|
||||
StdioFilePrinter(o, preLine, postLine) {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__StdioPrinter_h__
|
205
third-party/cxxtest/cxxtest/TeeListener.h
vendored
Normal file
205
third-party/cxxtest/cxxtest/TeeListener.h
vendored
Normal file
|
@ -0,0 +1,205 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__TeeListener_h__
|
||||
#define __cxxtest__TeeListener_h__
|
||||
|
||||
//
|
||||
// A TeeListener notifies two "regular" TestListeners
|
||||
//
|
||||
|
||||
#include <cxxtest/TestListener.h>
|
||||
#include <cxxtest/TestListener.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class TeeListener : public TestListener
|
||||
{
|
||||
public:
|
||||
TeeListener()
|
||||
{
|
||||
setFirst(_dummy);
|
||||
setSecond(_dummy);
|
||||
}
|
||||
|
||||
virtual ~TeeListener()
|
||||
{
|
||||
}
|
||||
|
||||
void setFirst(TestListener &first)
|
||||
{
|
||||
_first = &first;
|
||||
}
|
||||
|
||||
void setSecond(TestListener &second)
|
||||
{
|
||||
_second = &second;
|
||||
}
|
||||
|
||||
void enterWorld(const WorldDescription &d)
|
||||
{
|
||||
_first->enterWorld(d);
|
||||
_second->enterWorld(d);
|
||||
}
|
||||
|
||||
void enterSuite(const SuiteDescription &d)
|
||||
{
|
||||
_first->enterSuite(d);
|
||||
_second->enterSuite(d);
|
||||
}
|
||||
|
||||
void enterTest(const TestDescription &d)
|
||||
{
|
||||
_first->enterTest(d);
|
||||
_second->enterTest(d);
|
||||
}
|
||||
|
||||
void trace(const char *file, int line, const char *expression)
|
||||
{
|
||||
_first->trace(file, line, expression);
|
||||
_second->trace(file, line, expression);
|
||||
}
|
||||
|
||||
void warning(const char *file, int line, const char *expression)
|
||||
{
|
||||
_first->warning(file, line, expression);
|
||||
_second->warning(file, line, expression);
|
||||
}
|
||||
|
||||
void skippedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
_first->skippedTest(file, line, expression);
|
||||
_second->skippedTest(file, line, expression);
|
||||
}
|
||||
|
||||
void failedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
_first->failedTest(file, line, expression);
|
||||
_second->failedTest(file, line, expression);
|
||||
}
|
||||
|
||||
void failedAssert(const char *file, int line, const char *expression)
|
||||
{
|
||||
_first->failedAssert(file, line, expression);
|
||||
_second->failedAssert(file, line, expression);
|
||||
}
|
||||
|
||||
void failedAssertEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
_first->failedAssertEquals(file, line, xStr, yStr, x, y);
|
||||
_second->failedAssertEquals(file, line, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void failedAssertSameData(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *sizeStr, const void *x,
|
||||
const void *y, unsigned size)
|
||||
{
|
||||
_first->failedAssertSameData(file, line, xStr, yStr, sizeStr, x, y, size);
|
||||
_second->failedAssertSameData(file, line, xStr, yStr, sizeStr, x, y, size);
|
||||
}
|
||||
|
||||
void failedAssertSameFiles(const char* file, int line, const char* file1, const char* file2, const char* explanation)
|
||||
{
|
||||
_first->failedAssertSameFiles(file, line, file1, file2, explanation);
|
||||
_second->failedAssertSameFiles(file, line, file1, file2, explanation);
|
||||
}
|
||||
|
||||
void failedAssertDelta(const char *file, int line,
|
||||
const char *xStr, const char *yStr, const char *dStr,
|
||||
const char *x, const char *y, const char *d)
|
||||
{
|
||||
_first->failedAssertDelta(file, line, xStr, yStr, dStr, x, y, d);
|
||||
_second->failedAssertDelta(file, line, xStr, yStr, dStr, x, y, d);
|
||||
}
|
||||
|
||||
void failedAssertDiffers(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *value)
|
||||
{
|
||||
_first->failedAssertDiffers(file, line, xStr, yStr, value);
|
||||
_second->failedAssertDiffers(file, line, xStr, yStr, value);
|
||||
}
|
||||
|
||||
void failedAssertLessThan(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
_first->failedAssertLessThan(file, line, xStr, yStr, x, y);
|
||||
_second->failedAssertLessThan(file, line, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void failedAssertLessThanEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
_first->failedAssertLessThanEquals(file, line, xStr, yStr, x, y);
|
||||
_second->failedAssertLessThanEquals(file, line, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void failedAssertPredicate(const char *file, int line,
|
||||
const char *predicate, const char *xStr, const char *x)
|
||||
{
|
||||
_first->failedAssertPredicate(file, line, predicate, xStr, x);
|
||||
_second->failedAssertPredicate(file, line, predicate, xStr, x);
|
||||
}
|
||||
|
||||
void failedAssertRelation(const char *file, int line,
|
||||
const char *relation, const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
_first->failedAssertRelation(file, line, relation, xStr, yStr, x, y);
|
||||
_second->failedAssertRelation(file, line, relation, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void failedAssertThrows(const char *file, int line,
|
||||
const char *expression, const char *type,
|
||||
bool otherThrown)
|
||||
{
|
||||
_first->failedAssertThrows(file, line, expression, type, otherThrown);
|
||||
_second->failedAssertThrows(file, line, expression, type, otherThrown);
|
||||
}
|
||||
|
||||
void failedAssertThrowsNot(const char *file, int line,
|
||||
const char *expression)
|
||||
{
|
||||
_first->failedAssertThrowsNot(file, line, expression);
|
||||
_second->failedAssertThrowsNot(file, line, expression);
|
||||
}
|
||||
|
||||
void leaveTest(const TestDescription &d)
|
||||
{
|
||||
_first->leaveTest(d);
|
||||
_second->leaveTest(d);
|
||||
}
|
||||
|
||||
void leaveSuite(const SuiteDescription &d)
|
||||
{
|
||||
_first->leaveSuite(d);
|
||||
_second->leaveSuite(d);
|
||||
}
|
||||
|
||||
void leaveWorld(const WorldDescription &d)
|
||||
{
|
||||
_first->leaveWorld(d);
|
||||
_second->leaveWorld(d);
|
||||
}
|
||||
|
||||
private:
|
||||
TestListener *_first, *_second;
|
||||
TestListener _dummy;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // __cxxtest__TeeListener_h__
|
87
third-party/cxxtest/cxxtest/TestListener.h
vendored
Normal file
87
third-party/cxxtest/cxxtest/TestListener.h
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__TestListener_h__
|
||||
#define __cxxtest__TestListener_h__
|
||||
|
||||
//
|
||||
// TestListener is the base class for all "listeners",
|
||||
// i.e. classes that receive notifications of the
|
||||
// testing process.
|
||||
//
|
||||
// The names of the parameters are in comments to avoid
|
||||
// "unused parameter" warnings.
|
||||
//
|
||||
|
||||
#include <cxxtest/Descriptions.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class TestListener
|
||||
{
|
||||
public:
|
||||
TestListener() {}
|
||||
virtual ~TestListener() {}
|
||||
virtual void process_commandline(int& /*argc*/, char** /*argv*/) {}
|
||||
|
||||
virtual void enterWorld(const WorldDescription & /*desc*/) {}
|
||||
virtual void enterSuite(const SuiteDescription & /*desc*/) {}
|
||||
virtual void enterTest(const TestDescription & /*desc*/) {}
|
||||
virtual void trace(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/) {}
|
||||
virtual void warning(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/) {}
|
||||
virtual void skippedTest(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/) {}
|
||||
virtual void failedTest(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/) {}
|
||||
virtual void failedAssert(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/) {}
|
||||
virtual void failedAssertEquals(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/) {}
|
||||
virtual void failedAssertSameData(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*sizeStr*/, const void * /*x*/,
|
||||
const void * /*y*/, unsigned /*size*/) {}
|
||||
virtual void failedAssertDelta(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*dStr*/, const char * /*x*/,
|
||||
const char * /*y*/, const char * /*d*/) {}
|
||||
virtual void failedAssertDiffers(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*value*/) {}
|
||||
virtual void failedAssertLessThan(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/) {}
|
||||
virtual void failedAssertLessThanEquals(const char * /*file*/, int /*line*/,
|
||||
const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/) {}
|
||||
virtual void failedAssertPredicate(const char * /*file*/, int /*line*/,
|
||||
const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/) {}
|
||||
virtual void failedAssertRelation(const char * /*file*/, int /*line*/,
|
||||
const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/,
|
||||
const char * /*x*/, const char * /*y*/) {}
|
||||
virtual void failedAssertThrows(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/, const char * /*type*/,
|
||||
bool /*otherThrown*/) {}
|
||||
virtual void failedAssertThrowsNot(const char * /*file*/, int /*line*/,
|
||||
const char * /*expression*/) {}
|
||||
virtual void failedAssertSameFiles(const char* /*file*/, int /*line*/,
|
||||
const char* , const char*, const char*) {}
|
||||
virtual void leaveTest(const TestDescription & /*desc*/) {}
|
||||
virtual void leaveSuite(const SuiteDescription & /*desc*/) {}
|
||||
virtual void leaveWorld(const WorldDescription & /*desc*/) {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__TestListener_h__
|
||||
|
133
third-party/cxxtest/cxxtest/TestMain.h
vendored
Normal file
133
third-party/cxxtest/cxxtest/TestMain.h
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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 __CxxTestMain_h
|
||||
#define __CxxTestMain_h
|
||||
|
||||
#include <cxxtest/TestTracker.h>
|
||||
#include <cxxtest/Flags.h>
|
||||
|
||||
#ifndef _CXXTEST_HAVE_STD
|
||||
# define _CXXTEST_HAVE_STD
|
||||
#endif // _CXXTEST_HAVE_STD
|
||||
|
||||
#include <cxxtest/StdValueTraits.h>
|
||||
|
||||
#if defined(_CXXTEST_HAVE_STD)
|
||||
#ifdef _CXXTEST_OLD_STD
|
||||
# include <iostream.h>
|
||||
# include <string.h>
|
||||
#else // !_CXXTEST_OLD_STD
|
||||
# include <iostream>
|
||||
# include <cstring>
|
||||
#endif // _CXXTEST_OLD_STD
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
|
||||
inline void print_help(const char* name)
|
||||
{
|
||||
CXXTEST_STD(cerr) << name << " <suitename>" << CXXTEST_STD(endl);
|
||||
CXXTEST_STD(cerr) << name << " <suitename> <testname>" << CXXTEST_STD(endl);
|
||||
CXXTEST_STD(cerr) << name << " -h" << CXXTEST_STD(endl);
|
||||
CXXTEST_STD(cerr) << name << " --help" << CXXTEST_STD(endl);
|
||||
CXXTEST_STD(cerr) << name << " --help-tests" << CXXTEST_STD(endl);
|
||||
CXXTEST_STD(cerr) << name << " -v Enable tracing output." << CXXTEST_STD(endl);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
template <class TesterT>
|
||||
int Main(TesterT& tmp, int argc, char* argv[])
|
||||
{
|
||||
//
|
||||
// Parse the command-line arguments. The default behavior is to run all tests
|
||||
//
|
||||
// This is a primitive parser, but I'm not sure what sort of portable
|
||||
// parser should be used in cxxtest.
|
||||
//
|
||||
|
||||
#if defined(_CXXTEST_HAVE_STD)
|
||||
//
|
||||
// Print command-line syntax
|
||||
//
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if ((CXXTEST_STD(strcmp)(argv[i], "-h") == 0) || (CXXTEST_STD(strcmp)(argv[i], "--help") == 0))
|
||||
{
|
||||
print_help(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
else if ((CXXTEST_STD(strcmp)(argv[1], "--help-tests") == 0))
|
||||
{
|
||||
CXXTEST_STD(cout) << "Suite/Test Names" << CXXTEST_STD(endl);
|
||||
CXXTEST_STD(cout) << "---------------------------------------------------------------------------" << CXXTEST_STD(endl);
|
||||
for (SuiteDescription *sd = RealWorldDescription().firstSuite(); sd; sd = sd->next())
|
||||
for (TestDescription *td = sd->firstTest(); td; td = td->next())
|
||||
{
|
||||
CXXTEST_STD(cout) << td->suiteName() << " " << td->testName() << CXXTEST_STD(endl);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Process command-line options here.
|
||||
//
|
||||
while ((argc > 1) && (argv[1][0] == '-'))
|
||||
{
|
||||
if (CXXTEST_STD(strcmp)(argv[1], "-v") == 0)
|
||||
{
|
||||
tracker().print_tracing = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CXXTEST_STD(cerr) << "ERROR: unknown option '" << argv[1] << "'" << CXXTEST_STD(endl);
|
||||
return -1;
|
||||
}
|
||||
for (int i = 1; i < (argc - 1); i++)
|
||||
{
|
||||
argv[i] = argv[i + 1];
|
||||
}
|
||||
argc--;
|
||||
}
|
||||
|
||||
//
|
||||
// Run experiments
|
||||
//
|
||||
bool status = false;
|
||||
if ((argc == 2) && (argv[1][0] != '-'))
|
||||
{
|
||||
status = leaveOnly(argv[1]);
|
||||
if (!status)
|
||||
{
|
||||
CXXTEST_STD(cerr) << "ERROR: unknown suite '" << argv[1] << "'" << CXXTEST_STD(endl);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if ((argc == 3) && (argv[1][0] != '-'))
|
||||
{
|
||||
status = leaveOnly(argv[1], argv[2]);
|
||||
if (!status)
|
||||
{
|
||||
CXXTEST_STD(cerr) << "ERROR: unknown test '" << argv[1] << "::" << argv[2] << "'" << CXXTEST_STD(endl);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tmp.process_commandline(argc, argv);
|
||||
return tmp.run();
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
154
third-party/cxxtest/cxxtest/TestRunner.h
vendored
Normal file
154
third-party/cxxtest/cxxtest/TestRunner.h
vendored
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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_TestRunner_h__
|
||||
#define __cxxtest_TestRunner_h__
|
||||
|
||||
//
|
||||
// TestRunner is the class that runs all the tests.
|
||||
// To use it, create an object that implements the TestListener
|
||||
// interface and call TestRunner::runAllTests( myListener );
|
||||
//
|
||||
|
||||
#include <cxxtest/TestListener.h>
|
||||
#include <cxxtest/RealDescriptions.h>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <cxxtest/TestTracker.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class TestRunner
|
||||
{
|
||||
public:
|
||||
|
||||
static void setListener(TestListener* listener)
|
||||
{
|
||||
tracker().setListener(listener);
|
||||
}
|
||||
|
||||
static void runAllTests(TestListener &listener)
|
||||
{
|
||||
tracker().setListener(&listener);
|
||||
_TS_TRY { TestRunner().runWorld(); }
|
||||
_TS_LAST_CATCH( { tracker().failedTest(__FILE__, __LINE__, "Exception thrown from world"); });
|
||||
tracker().setListener(0);
|
||||
}
|
||||
|
||||
static void runAllTests(TestListener *listener)
|
||||
{
|
||||
if (listener)
|
||||
{
|
||||
listener->warning(__FILE__, __LINE__, "Deprecated; Use runAllTests( TestListener & )");
|
||||
runAllTests(*listener);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void runWorld()
|
||||
{
|
||||
RealWorldDescription wd;
|
||||
WorldGuard sg;
|
||||
|
||||
tracker().enterWorld(wd);
|
||||
if (wd.setUp())
|
||||
{
|
||||
for (SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next())
|
||||
{
|
||||
if (sd->active())
|
||||
{
|
||||
runSuite(*sd);
|
||||
}
|
||||
}
|
||||
|
||||
wd.tearDown();
|
||||
}
|
||||
tracker().leaveWorld(wd);
|
||||
}
|
||||
|
||||
void runSuite(SuiteDescription &sd)
|
||||
{
|
||||
StateGuard sg;
|
||||
|
||||
tracker().enterSuite(sd);
|
||||
if (sd.setUp())
|
||||
{
|
||||
for (TestDescription *td = sd.firstTest(); td; td = td->next())
|
||||
{
|
||||
if (td->active())
|
||||
{
|
||||
runTest(*td);
|
||||
}
|
||||
}
|
||||
|
||||
sd.tearDown();
|
||||
}
|
||||
tracker().leaveSuite(sd);
|
||||
}
|
||||
|
||||
void runTest(TestDescription &td)
|
||||
{
|
||||
StateGuard sg;
|
||||
|
||||
tracker().enterTest(td);
|
||||
if (td.setUp())
|
||||
{
|
||||
td.run();
|
||||
td.tearDown();
|
||||
}
|
||||
tracker().leaveTest(td);
|
||||
}
|
||||
|
||||
class StateGuard
|
||||
{
|
||||
#ifdef _CXXTEST_HAVE_EH
|
||||
bool _abortTestOnFail;
|
||||
#endif // _CXXTEST_HAVE_EH
|
||||
unsigned _maxDumpSize;
|
||||
|
||||
public:
|
||||
StateGuard()
|
||||
{
|
||||
#ifdef _CXXTEST_HAVE_EH
|
||||
_abortTestOnFail = abortTestOnFail();
|
||||
#endif // _CXXTEST_HAVE_EH
|
||||
_maxDumpSize = maxDumpSize();
|
||||
}
|
||||
|
||||
~StateGuard()
|
||||
{
|
||||
#ifdef _CXXTEST_HAVE_EH
|
||||
setAbortTestOnFail(_abortTestOnFail);
|
||||
#endif // _CXXTEST_HAVE_EH
|
||||
setMaxDumpSize(_maxDumpSize);
|
||||
}
|
||||
};
|
||||
|
||||
class WorldGuard : public StateGuard
|
||||
{
|
||||
public:
|
||||
WorldGuard() : StateGuard()
|
||||
{
|
||||
#ifdef _CXXTEST_HAVE_EH
|
||||
setAbortTestOnFail(CXXTEST_DEFAULT_ABORT);
|
||||
#endif // _CXXTEST_HAVE_EH
|
||||
setMaxDumpSize(CXXTEST_MAX_DUMP_SIZE);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// For --no-static-init
|
||||
//
|
||||
void initialize();
|
||||
}
|
||||
|
||||
|
||||
#endif // __cxxtest_TestRunner_h__
|
317
third-party/cxxtest/cxxtest/TestSuite.cpp
vendored
Normal file
317
third-party/cxxtest/cxxtest/TestSuite.cpp
vendored
Normal file
|
@ -0,0 +1,317 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__
|
||||
|
732
third-party/cxxtest/cxxtest/TestSuite.h
vendored
Normal file
732
third-party/cxxtest/cxxtest/TestSuite.h
vendored
Normal file
|
@ -0,0 +1,732 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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_h__
|
||||
#define __cxxtest__TestSuite_h__
|
||||
|
||||
//
|
||||
// class TestSuite is the base class for all test suites.
|
||||
// To define a test suite, derive from this class and add
|
||||
// member functions called void test*();
|
||||
//
|
||||
|
||||
#include <cxxtest/Flags.h>
|
||||
#include <cxxtest/TestTracker.h>
|
||||
#include <cxxtest/Descriptions.h>
|
||||
#include <cxxtest/ValueTraits.h>
|
||||
#include <cxxtest/StdValueTraits.h>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
|
||||
#if defined(_CXXTEST_HAVE_STD)
|
||||
# include <stdexcept>
|
||||
#endif // _CXXTEST_HAVE_STD
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class TestSuite
|
||||
{
|
||||
public:
|
||||
virtual ~TestSuite();
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
};
|
||||
|
||||
class AbortTest {};
|
||||
class SkipTest {};
|
||||
void doAbortTest();
|
||||
# define TS_ABORT() CxxTest::doAbortTest()
|
||||
|
||||
bool abortTestOnFail();
|
||||
void setAbortTestOnFail(bool value = CXXTEST_DEFAULT_ABORT);
|
||||
|
||||
unsigned maxDumpSize();
|
||||
void setMaxDumpSize(unsigned value = CXXTEST_MAX_DUMP_SIZE);
|
||||
|
||||
void doTrace(const char *file, int line, const char *message);
|
||||
void doWarn(const char *file, int line, const char *message);
|
||||
void doSkipTest(const char *file, int line, const char *message);
|
||||
void doFailTest(const char *file, int line, const char *message);
|
||||
void doFailAssert(const char *file, int line, const char *expression, const char *message);
|
||||
|
||||
template<class X, class Y>
|
||||
struct equals
|
||||
{
|
||||
static bool test(X x, Y y)
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct equals<const char*, const char*>
|
||||
{
|
||||
static bool test(const char *x, const char *y)
|
||||
{
|
||||
if ((x != 0) && (y != 0))
|
||||
{
|
||||
return (CXXTEST_STD(strcmp(x, y)) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct equals<char*, char*>
|
||||
{
|
||||
static bool test(char *x, char *y)
|
||||
{
|
||||
if ((x != 0) && (y != 0))
|
||||
{
|
||||
return (CXXTEST_STD(strcmp(x, y)) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct equals<const char*, char*>
|
||||
{
|
||||
static bool test(const char *x, char *y)
|
||||
{
|
||||
if ((x != 0) && (y != 0))
|
||||
{
|
||||
return (CXXTEST_STD(strcmp(x, y)) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct equals<char*, const char*>
|
||||
{
|
||||
static bool test(char *x, const char *y)
|
||||
{
|
||||
if ((x != 0) && (y != 0))
|
||||
{
|
||||
return (CXXTEST_STD(strcmp(x, y)) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (x == y);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class X, class Y>
|
||||
void doAssertEquals(const char *file, int line,
|
||||
const char *xExpr, X x,
|
||||
const char *yExpr, Y y,
|
||||
const char *message)
|
||||
{
|
||||
if (!equals<X, Y>::test(x, y))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
tracker().failedTest(file, line, message);
|
||||
}
|
||||
tracker().failedAssertEquals(file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y));
|
||||
TS_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
bool sameData(const void *x, const void *y, unsigned size);
|
||||
|
||||
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 defined(_CXXTEST_HAVE_STD)
|
||||
bool sameFiles(const char* file1, const char* file2, std::ostringstream& explanation);
|
||||
//#endif
|
||||
|
||||
template<class X, class Y>
|
||||
struct differs
|
||||
{
|
||||
static bool test(X x, Y y)
|
||||
{
|
||||
return !(x == y);
|
||||
}
|
||||
};
|
||||
|
||||
template<class X, class Y>
|
||||
void doAssertDiffers(const char *file, int line,
|
||||
const char *xExpr, X x,
|
||||
const char *yExpr, Y y,
|
||||
const char *message)
|
||||
{
|
||||
if (!differs<X, Y>::test(x, y))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
tracker().failedTest(file, line, message);
|
||||
}
|
||||
tracker().failedAssertDiffers(file, line, xExpr, yExpr, TS_AS_STRING(x));
|
||||
TS_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
template<class X, class Y>
|
||||
struct lessThan
|
||||
{
|
||||
static bool test(X x, Y y)
|
||||
{
|
||||
return (x < y);
|
||||
}
|
||||
};
|
||||
|
||||
template<class X, class Y>
|
||||
void doAssertLessThan(const char *file, int line,
|
||||
const char *xExpr, X x,
|
||||
const char *yExpr, Y y,
|
||||
const char *message)
|
||||
{
|
||||
if (!lessThan<X, Y>::test(x, y))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
tracker().failedTest(file, line, message);
|
||||
}
|
||||
tracker().failedAssertLessThan(file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y));
|
||||
TS_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
template<class X, class Y>
|
||||
struct lessThanEquals
|
||||
{
|
||||
static bool test(X x, Y y)
|
||||
{
|
||||
return (x <= y);
|
||||
}
|
||||
};
|
||||
|
||||
template<class X, class Y>
|
||||
void doAssertLessThanEquals(const char *file, int line,
|
||||
const char *xExpr, X x,
|
||||
const char *yExpr, Y y,
|
||||
const char *message)
|
||||
{
|
||||
if (!lessThanEquals<X, Y>::test(x, y))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
tracker().failedTest(file, line, message);
|
||||
}
|
||||
tracker().failedAssertLessThanEquals(file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y));
|
||||
TS_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
template<class X, class P>
|
||||
void doAssertPredicate(const char *file, int line,
|
||||
const char *pExpr, const P &p,
|
||||
const char *xExpr, X x,
|
||||
const char *message)
|
||||
{
|
||||
if (!p(x))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
tracker().failedTest(file, line, message);
|
||||
}
|
||||
tracker().failedAssertPredicate(file, line, pExpr, xExpr, TS_AS_STRING(x));
|
||||
TS_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
template<class X, class Y, class R>
|
||||
void doAssertRelation(const char *file, int line,
|
||||
const char *rExpr, const R &r,
|
||||
const char *xExpr, X x,
|
||||
const char *yExpr, Y y,
|
||||
const char *message)
|
||||
{
|
||||
if (!r(x, y))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
tracker().failedTest(file, line, message);
|
||||
}
|
||||
tracker().failedAssertRelation(file, line, rExpr, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y));
|
||||
TS_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
// An indirection template so the compiler can determine what type
|
||||
// "X +/- D" should be
|
||||
template<class X, class Y>
|
||||
bool delta_le_helper(X x, Y y)
|
||||
{
|
||||
return lessThanEquals<X, Y>::test(x, y);
|
||||
}
|
||||
|
||||
template<class X, class Y, class D>
|
||||
struct delta
|
||||
{
|
||||
static bool test(X x, Y y, D d)
|
||||
{
|
||||
return delta_le_helper(x, y + d) && delta_le_helper(y, x + d);
|
||||
//(y >= x - d) && (y <= x + d));
|
||||
}
|
||||
};
|
||||
|
||||
template<class X, class Y, class D>
|
||||
void doAssertDelta(const char *file, int line,
|
||||
const char *xExpr, X x,
|
||||
const char *yExpr, Y y,
|
||||
const char *dExpr, D d,
|
||||
const char *message)
|
||||
{
|
||||
if (!delta<X, Y, D>::test(x, y, d))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
tracker().failedTest(file, line, message);
|
||||
}
|
||||
|
||||
tracker().failedAssertDelta(file, line, xExpr, yExpr, dExpr,
|
||||
TS_AS_STRING(x), TS_AS_STRING(y), TS_AS_STRING(d));
|
||||
TS_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
void doFailAssertThrows(const char *file, int line,
|
||||
const char *expr, const char *type,
|
||||
bool otherThrown,
|
||||
const char *message,
|
||||
const char *exception = 0);
|
||||
|
||||
void doFailAssertThrowsNot(const char *file, int line,
|
||||
const char *expression, const char *message,
|
||||
const char *exception = 0);
|
||||
|
||||
void doAssertSameFiles(const char* file, int line,
|
||||
const char* file1, const char* file2,
|
||||
const char* message);
|
||||
|
||||
# ifdef _CXXTEST_HAVE_EH
|
||||
# define _TS_TRY try
|
||||
# define _TS_CATCH_TYPE(t, b) catch t b
|
||||
# define _TS_CATCH_ABORT(b) _TS_CATCH_TYPE( (const CxxTest::AbortTest &), b )
|
||||
# define _TS_CATCH_SKIPPED(b) _TS_CATCH_TYPE( (const CxxTest::SkipTest &), b )
|
||||
# define _TS_LAST_CATCH(b) _TS_CATCH_TYPE( (...), b )
|
||||
# define _TSM_LAST_CATCH(f,l,m) _TS_LAST_CATCH( { (CxxTest::tracker()).failedTest(f,l,m); } )
|
||||
# ifdef _CXXTEST_HAVE_STD
|
||||
# define _TS_CATCH_STD(e,b) _TS_CATCH_TYPE( (const std::exception& e), b )
|
||||
# else // !_CXXTEST_HAVE_STD
|
||||
# define _TS_CATCH_STD(e,b)
|
||||
# endif // _CXXTEST_HAVE_STD
|
||||
# define ___TSM_CATCH(f,l,m) \
|
||||
_TS_CATCH_STD(e, { (CxxTest::tracker()).failedTest(f,l,e.what()); }) \
|
||||
_TSM_LAST_CATCH(f,l,m)
|
||||
# define __TSM_CATCH(f,l,m) \
|
||||
_TS_CATCH_ABORT( { throw; } ) \
|
||||
___TSM_CATCH(f,l,m)
|
||||
# define __TS_CATCH(f,l) __TSM_CATCH(f,l,"Unhandled exception")
|
||||
# define _TS_CATCH __TS_CATCH(__FILE__,__LINE__)
|
||||
# else // !_CXXTEST_HAVE_EH
|
||||
# define _TS_TRY
|
||||
# define ___TSM_CATCH(f,l,m)
|
||||
# define __TSM_CATCH(f,l,m)
|
||||
# define __TS_CATCH(f,l)
|
||||
# define _TS_CATCH
|
||||
# define _TS_CATCH_TYPE(t, b)
|
||||
# define _TS_LAST_CATCH(b)
|
||||
# define _TS_CATCH_STD(e,b)
|
||||
# define _TS_CATCH_ABORT(b)
|
||||
# define _TS_CATCH_SKIPPED(b)
|
||||
# endif // _CXXTEST_HAVE_EH
|
||||
|
||||
// TS_TRACE
|
||||
# define _TS_TRACE(f,l,e) CxxTest::doTrace( (f), (l), TS_AS_STRING(e) )
|
||||
# define TS_TRACE(e) _TS_TRACE( __FILE__, __LINE__, e )
|
||||
|
||||
// TS_WARN
|
||||
# define _TS_WARN(f,l,e) CxxTest::doWarn( (f), (l), TS_AS_STRING(e) )
|
||||
# define TS_WARN(e) _TS_WARN( __FILE__, __LINE__, e )
|
||||
|
||||
// TS_SKIP
|
||||
# define _TS_SKIP(f,l,e) CxxTest::doSkipTest( (f), (l), TS_AS_STRING(e) )
|
||||
# define TS_SKIP(e) _TS_SKIP( __FILE__, __LINE__, e )
|
||||
|
||||
// TS_FAIL
|
||||
# define _TS_FAIL(f,l,e) CxxTest::doFailTest( (f), (l), TS_AS_STRING(e) )
|
||||
# define TS_FAIL(e) _TS_FAIL( __FILE__, __LINE__, e )
|
||||
|
||||
// TS_ASSERT
|
||||
# define ___ETS_ASSERT(f,l,e,m) { if ( !(e) ) { CxxTest::doFailAssert( (f), (l), #e, (m) ); } }
|
||||
# define ___TS_ASSERT(f,l,e,m) { _TS_TRY { ___ETS_ASSERT(f,l,e,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT(f,l,e) ___ETS_ASSERT(f,l,e,0)
|
||||
# define _TS_ASSERT(f,l,e) ___TS_ASSERT(f,l,e,0)
|
||||
|
||||
# define ETS_ASSERT(e) _ETS_ASSERT(__FILE__,__LINE__,e)
|
||||
# define TS_ASSERT(e) _TS_ASSERT(__FILE__,__LINE__,e)
|
||||
|
||||
# define _ETSM_ASSERT(f,l,m,e) ___ETS_ASSERT(f,l,e,TS_AS_STRING(m) )
|
||||
# define _TSM_ASSERT(f,l,m,e) ___TS_ASSERT(f,l,e,TS_AS_STRING(m) )
|
||||
|
||||
# define ETSM_ASSERT(m,e) _ETSM_ASSERT(__FILE__,__LINE__,m,e)
|
||||
# define TSM_ASSERT(m,e) _TSM_ASSERT(__FILE__,__LINE__,m,e)
|
||||
|
||||
// TS_ASSERT_EQUALS
|
||||
# define ___ETS_ASSERT_EQUALS(f,l,x,y,m) CxxTest::doAssertEquals( (f), (l), #x, (x), #y, (y), (m) )
|
||||
# define ___TS_ASSERT_EQUALS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_EQUALS(f,l,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,0)
|
||||
# define _TS_ASSERT_EQUALS(f,l,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,0)
|
||||
|
||||
# define ETS_ASSERT_EQUALS(x,y) _ETS_ASSERT_EQUALS(__FILE__,__LINE__,x,y)
|
||||
# define TS_ASSERT_EQUALS(x,y) _TS_ASSERT_EQUALS(__FILE__,__LINE__,x,y)
|
||||
|
||||
# define _ETSM_ASSERT_EQUALS(f,l,m,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_EQUALS(f,l,m,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_EQUALS(m,x,y) _ETSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y)
|
||||
# define TSM_ASSERT_EQUALS(m,x,y) _TSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y)
|
||||
|
||||
// Special foating point values support
|
||||
# define ETS_ASSERT_IS_NAN(x) _ETS_ASSERT(__FILE__,__LINE__,isnan(x))
|
||||
# define TS_ASSERT_IS_NAN(x) _TS_ASSERT(__FILE__,__LINE__,isnan(x))
|
||||
|
||||
# define ETSM_ASSERT_IS_NAN(m,x) _ETSM_ASSERT(__FILE__,__LINE__,m,isnan(x))
|
||||
# define TSM_ASSERT_IS_NAN(m,x) _TSM_ASSERT(__FILE__,__LINE__,m,isnan(x))
|
||||
|
||||
# define ETS_ASSERT_IS_INFINITE(x) _ETS_ASSERT(__FILE__,__LINE__,isinf(x))
|
||||
# define TS_ASSERT_IS_INFINITE(x) _TS_ASSERT(__FILE__,__LINE__,isinf(x))
|
||||
|
||||
# define ETSM_ASSERT_IS_INFINITE(m,x) _ETSM_ASSERT(__FILE__,__LINE__,m,isinf(x))
|
||||
# define TSM_ASSERT_IS_INFINITE(m,x) _TSM_ASSERT(__FILE__,__LINE__,m,isinf(x))
|
||||
|
||||
// TS_ASSERT_SAME_DATA
|
||||
# define ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m) CxxTest::doAssertSameData( (f), (l), #x, (x), #y, (y), #s, (s), (m) )
|
||||
# define ___TS_ASSERT_SAME_DATA(f,l,x,y,s,m) { _TS_TRY { ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_SAME_DATA(f,l,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,0)
|
||||
# define _TS_ASSERT_SAME_DATA(f,l,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,0)
|
||||
|
||||
# define ETS_ASSERT_SAME_DATA(x,y,s) _ETS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s)
|
||||
# define TS_ASSERT_SAME_DATA(x,y,s) _TS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s)
|
||||
|
||||
# define _ETSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_SAME_DATA(m,x,y,s) _ETSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s)
|
||||
# define TSM_ASSERT_SAME_DATA(m,x,y,s) _TSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s)
|
||||
|
||||
// TS_ASSERT_DIFFERS
|
||||
# define ___ETS_ASSERT_DIFFERS(f,l,x,y,m) CxxTest::doAssertDiffers( (f), (l), #x, (x), #y, (y), (m) )
|
||||
# define ___TS_ASSERT_DIFFERS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_DIFFERS(f,l,x,y,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_DIFFERS(f,l,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,0)
|
||||
# define _TS_ASSERT_DIFFERS(f,l,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,0)
|
||||
|
||||
# define ETS_ASSERT_DIFFERS(x,y) _ETS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y)
|
||||
# define TS_ASSERT_DIFFERS(x,y) _TS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y)
|
||||
|
||||
# define _ETSM_ASSERT_DIFFERS(f,l,m,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_DIFFERS(f,l,m,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_DIFFERS(m,x,y) _ETSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y)
|
||||
# define TSM_ASSERT_DIFFERS(m,x,y) _TSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y)
|
||||
|
||||
// TS_ASSERT_LESS_THAN
|
||||
# define ___ETS_ASSERT_LESS_THAN(f,l,x,y,m) CxxTest::doAssertLessThan( (f), (l), #x, (x), #y, (y), (m) )
|
||||
# define ___TS_ASSERT_LESS_THAN(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_LESS_THAN(f,l,x,y,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_LESS_THAN(f,l,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,0)
|
||||
# define _TS_ASSERT_LESS_THAN(f,l,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,0)
|
||||
|
||||
# define ETS_ASSERT_LESS_THAN(x,y) _ETS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y)
|
||||
# define TS_ASSERT_LESS_THAN(x,y) _TS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y)
|
||||
|
||||
# define _ETSM_ASSERT_LESS_THAN(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_LESS_THAN(f,l,m,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_LESS_THAN(m,x,y) _ETSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y)
|
||||
# define TSM_ASSERT_LESS_THAN(m,x,y) _TSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y)
|
||||
|
||||
// TS_ASSERT_LESS_THAN_EQUALS
|
||||
# define ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
|
||||
CxxTest::doAssertLessThanEquals( (f), (l), #x, (x), #y, (y), (m) )
|
||||
# define ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
|
||||
{ _TS_TRY { ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
|
||||
# define _TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
|
||||
|
||||
# define ETS_ASSERT_LESS_THAN_EQUALS(x,y) _ETS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y)
|
||||
# define TS_ASSERT_LESS_THAN_EQUALS(x,y) _TS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y)
|
||||
|
||||
# define _ETSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _ETSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y)
|
||||
# define TSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _TSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y)
|
||||
|
||||
// TS_ASSERT_PREDICATE
|
||||
# define ___ETS_ASSERT_PREDICATE(f,l,p,x,m) \
|
||||
CxxTest::doAssertPredicate( (f), (l), #p, p(), #x, (x), (m) )
|
||||
# define ___TS_ASSERT_PREDICATE(f,l,p,x,m) \
|
||||
{ _TS_TRY { ___ETS_ASSERT_PREDICATE(f,l,p,x,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_PREDICATE(f,l,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,0)
|
||||
# define _TS_ASSERT_PREDICATE(f,l,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,0)
|
||||
|
||||
# define ETS_ASSERT_PREDICATE(p,x) _ETS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x)
|
||||
# define TS_ASSERT_PREDICATE(p,x) _TS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x)
|
||||
|
||||
# define _ETSM_ASSERT_PREDICATE(f,l,m,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_PREDICATE(f,l,m,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_PREDICATE(m,p,x) _ETSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x)
|
||||
# define TSM_ASSERT_PREDICATE(m,p,x) _TSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x)
|
||||
|
||||
// TS_ASSERT_RELATION
|
||||
# define ___ETS_ASSERT_RELATION(f,l,r,x,y,m) \
|
||||
CxxTest::doAssertRelation( (f), (l), #r, r(), #x, (x), #y, (y), (m) )
|
||||
# define ___TS_ASSERT_RELATION(f,l,r,x,y,m) \
|
||||
{ _TS_TRY { ___ETS_ASSERT_RELATION(f,l,r,x,y,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_RELATION(f,l,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,0)
|
||||
# define _TS_ASSERT_RELATION(f,l,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,0)
|
||||
|
||||
# define ETS_ASSERT_RELATION(r,x,y) _ETS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y)
|
||||
# define TS_ASSERT_RELATION(r,x,y) _TS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y)
|
||||
|
||||
# define _ETSM_ASSERT_RELATION(f,l,m,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_RELATION(f,l,m,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_RELATION(m,r,x,y) _ETSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y)
|
||||
# define TSM_ASSERT_RELATION(m,r,x,y) _TSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y)
|
||||
|
||||
// TS_ASSERT_DELTA
|
||||
# define ___ETS_ASSERT_DELTA(f,l,x,y,d,m) CxxTest::doAssertDelta( (f), (l), #x, (x), #y, (y), #d, (d), (m) )
|
||||
# define ___TS_ASSERT_DELTA(f,l,x,y,d,m) { _TS_TRY { ___ETS_ASSERT_DELTA(f,l,x,y,d,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_DELTA(f,l,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,0)
|
||||
# define _TS_ASSERT_DELTA(f,l,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,0)
|
||||
|
||||
# define ETS_ASSERT_DELTA(x,y,d) _ETS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d)
|
||||
# define TS_ASSERT_DELTA(x,y,d) _TS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d)
|
||||
|
||||
# define _ETSM_ASSERT_DELTA(f,l,m,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_DELTA(f,l,m,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_DELTA(m,x,y,d) _ETSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d)
|
||||
# define TSM_ASSERT_DELTA(m,x,y,d) _TSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d)
|
||||
|
||||
// TS_ASSERT_SAME_FILES
|
||||
# define ___ETS_ASSERT_SAME_FILES(f,l,x,y,m) CxxTest::doAssertSameFiles( (f), (l), (x), (y), (m) )
|
||||
# define ___TS_ASSERT_SAME_FILES(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_SAME_FILES(f,l,x,y,m); } __TS_CATCH(f,l) }
|
||||
|
||||
# define _ETS_ASSERT_SAME_FILES(f,l,x,y) ___ETS_ASSERT_SAME_FILES(f,l,x,y,0)
|
||||
# define _TS_ASSERT_SAME_FILES(f,l,x,y) ___TS_ASSERT_SAME_FILES(f,l,x,y,0)
|
||||
|
||||
# define ETS_ASSERT_SAME_FILES(x,y) _ETS_ASSERT_SAME_FILES(__FILE__,__LINE__,x,y)
|
||||
# define TS_ASSERT_SAME_FILES(x,y) _TS_ASSERT_SAME_FILES(__FILE__,__LINE__,x,y)
|
||||
|
||||
# define _ETSM_ASSERT_SAME_FILES(f,l,m,x,y) ___ETS_ASSERT_SAME_FILES(f,l,x,y,TS_AS_STRING(m))
|
||||
# define _TSM_ASSERT_SAME_FILES(f,l,m,x,y) ___TS_ASSERT_SAME_FILES(f,l,x,y,TS_AS_STRING(m))
|
||||
|
||||
# define ETSM_ASSERT_SAME_FILES(m,x,y) _ETSM_ASSERT_SAME_FILES(__FILE__,__LINE__,m,x,y)
|
||||
# define TSM_ASSERT_SAME_FILES(m,x,y) _TSM_ASSERT_SAME_FILES(__FILE__,__LINE__,m,x,y)
|
||||
|
||||
|
||||
// TS_ASSERT_THROWS
|
||||
# define ___TS_ASSERT_THROWS(f,l,e,t,m) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,(void)0,m)
|
||||
|
||||
# define _TS_ASSERT_THROWS(f,l,e,t) ___TS_ASSERT_THROWS(f,l,e,t,0)
|
||||
# define TS_ASSERT_THROWS(e,t) _TS_ASSERT_THROWS(__FILE__,__LINE__,e,t)
|
||||
|
||||
# define _TSM_ASSERT_THROWS(f,l,m,e,t) ___TS_ASSERT_THROWS(f,l,e,t,TS_AS_STRING(m))
|
||||
# define TSM_ASSERT_THROWS(m,e,t) _TSM_ASSERT_THROWS(__FILE__,__LINE__,m,e,t)
|
||||
|
||||
// TS_ASSERT_THROWS_ASSERT
|
||||
# define ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,m) { \
|
||||
bool _ts_threw_expected = false, _ts_threw_else = false; \
|
||||
_TS_TRY { try{ e; } _TS_CATCH_TYPE( (t), { a; _ts_threw_expected = true; } ) } \
|
||||
_TS_CATCH_ABORT( { throw; } ) \
|
||||
_TS_CATCH_STD( ex, { _ts_threw_expected = true; CxxTest::doFailAssertThrows((f), (l), #e, #t, true, (m), ex.what() ); } ) \
|
||||
_TS_LAST_CATCH( { _ts_threw_else = true; } ) \
|
||||
if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m), 0 ); } }
|
||||
|
||||
# define _TS_ASSERT_THROWS_ASSERT(f,l,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,0)
|
||||
# define TS_ASSERT_THROWS_ASSERT(e,t,a) _TS_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,e,t,a)
|
||||
|
||||
# define _TSM_ASSERT_THROWS_ASSERT(f,l,m,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,TS_AS_STRING(m))
|
||||
# define TSM_ASSERT_THROWS_ASSERT(m,e,t,a) _TSM_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,m,e,t,a)
|
||||
|
||||
// TS_ASSERT_THROWS_EQUALS
|
||||
# define TS_ASSERT_THROWS_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_EQUALS(x,y))
|
||||
# define TSM_ASSERT_THROWS_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_EQUALS(m,x,y))
|
||||
|
||||
// Special foating point values support
|
||||
# define TS_ASSERT_THROWS_IS_NAN(e,t,x) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_IS_NAN(x))
|
||||
# define TSM_ASSERT_THROWS_IS_NAN(m,e,t,x) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_IS_NAN(m,x))
|
||||
|
||||
# define TS_ASSERT_THROWS_IS_INFINITE(e,t,x) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_IS_INFINITE(x))
|
||||
# define TSM_ASSERT_THROWS_IS_INFINITE(m,e,t,x) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_IS_INFINITE(m,x))
|
||||
|
||||
// TS_ASSERT_THROWS_DIFFERS
|
||||
# define TS_ASSERT_THROWS_DIFFERS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DIFFERS(x,y))
|
||||
# define TSM_ASSERT_THROWS_DIFFERS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DIFFERS(m,x,y))
|
||||
|
||||
// TS_ASSERT_THROWS_DELTA
|
||||
# define TS_ASSERT_THROWS_DELTA(e,t,x,y,d) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DELTA(x,y,d))
|
||||
# define TSM_ASSERT_THROWS_DELTA(m,e,t,x,y,d) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DELTA(m,x,y,d))
|
||||
|
||||
// TS_ASSERT_THROWS_SAME_DATA
|
||||
# define TS_ASSERT_THROWS_SAME_DATA(e,t,x,y,s) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_SAME_DATA(x,y,s))
|
||||
# define TSM_ASSERT_THROWS_SAME_DATA(m,e,t,x,y,s) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_SAME_DATA(m,x,y,s))
|
||||
|
||||
// TS_ASSERT_THROWS_LESS_THAN
|
||||
# define TS_ASSERT_THROWS_LESS_THAN(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN(x,y))
|
||||
# define TSM_ASSERT_THROWS_LESS_THAN(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN(m,x,y))
|
||||
|
||||
// TS_ASSERT_THROWS_LESS_THAN_EQUALS
|
||||
# define TS_ASSERT_THROWS_LESS_THAN_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN_EQUALS(x,y))
|
||||
# define TSM_ASSERT_THROWS_LESS_THAN_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN_EQUALS(m,x,y))
|
||||
|
||||
// TS_ASSERT_THROWS_PREDICATE
|
||||
# define TS_ASSERT_THROWS_PREDICATE(e,t,p,v) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_PREDICATE(p,v))
|
||||
# define TSM_ASSERT_THROWS_PREDICATE(m,e,t,p,v) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_PREDICATE(m,p,v))
|
||||
|
||||
// TS_ASSERT_THROWS_RELATION
|
||||
# define TS_ASSERT_THROWS_RELATION(e,t,r,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_RELATION(r,x,y))
|
||||
# define TSM_ASSERT_THROWS_RELATION(m,e,t,r,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_RELATION(m,r,x,y))
|
||||
|
||||
// TS_ASSERT_THROWS_ANYTHING
|
||||
# define ___TS_ASSERT_THROWS_ANYTHING(f,l,e,m) { \
|
||||
bool _ts_threw = false; \
|
||||
_TS_TRY { e; } \
|
||||
_TS_LAST_CATCH( { _ts_threw = true; } ) \
|
||||
if ( !_ts_threw ) { CxxTest::doFailAssertThrows( (f), (l), #e, "...", false, (m) ); } }
|
||||
|
||||
# define _TS_ASSERT_THROWS_ANYTHING(f,l,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,0)
|
||||
# define TS_ASSERT_THROWS_ANYTHING(e) _TS_ASSERT_THROWS_ANYTHING(__FILE__, __LINE__, e)
|
||||
|
||||
# define _TSM_ASSERT_THROWS_ANYTHING(f,l,m,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,TS_AS_STRING(m))
|
||||
# define TSM_ASSERT_THROWS_ANYTHING(m,e) _TSM_ASSERT_THROWS_ANYTHING(__FILE__,__LINE__,m,e)
|
||||
|
||||
// TS_ASSERT_THROWS_NOTHING
|
||||
# define ___TS_ASSERT_THROWS_NOTHING(f,l,e,m) { \
|
||||
_TS_TRY { e; } \
|
||||
_TS_CATCH_ABORT( { throw; } ) \
|
||||
_TS_CATCH_STD(ex, { CxxTest::doFailAssertThrowsNot( (f), (l), #e, (m), ex.what() ); } ) \
|
||||
_TS_LAST_CATCH( { CxxTest::doFailAssertThrowsNot( (f), (l), #e, (m), 0 ); } ) }
|
||||
|
||||
# define _TS_ASSERT_THROWS_NOTHING(f,l,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,0)
|
||||
# define TS_ASSERT_THROWS_NOTHING(e) _TS_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,e)
|
||||
|
||||
# define _TSM_ASSERT_THROWS_NOTHING(f,l,m,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,TS_AS_STRING(m))
|
||||
# define TSM_ASSERT_THROWS_NOTHING(m,e) _TSM_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,m,e)
|
||||
|
||||
|
||||
//
|
||||
// This takes care of "signed <-> unsigned" warnings
|
||||
//
|
||||
# define CXXTEST_COMPARISONS(CXXTEST_X, CXXTEST_Y, CXXTEST_T) \
|
||||
template<> struct equals<CXXTEST_X,CXXTEST_Y> { \
|
||||
static bool test(CXXTEST_X x,CXXTEST_Y y) { \
|
||||
return equals<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }; \
|
||||
template<> struct equals<CXXTEST_Y,CXXTEST_X> { \
|
||||
static bool test(CXXTEST_Y x,CXXTEST_X y) { \
|
||||
return equals<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }; \
|
||||
template<> struct differs<CXXTEST_X,CXXTEST_Y> { \
|
||||
static bool test(CXXTEST_X x,CXXTEST_Y y) { \
|
||||
return differs<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }; \
|
||||
template<> struct differs<CXXTEST_Y,CXXTEST_X> { \
|
||||
static bool test(CXXTEST_Y x,CXXTEST_X y) { \
|
||||
return differs<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }; \
|
||||
template<> struct lessThan<CXXTEST_X,CXXTEST_Y> { \
|
||||
static bool test(CXXTEST_X x,CXXTEST_Y y) { \
|
||||
return lessThan<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }; \
|
||||
template<> struct lessThan<CXXTEST_Y,CXXTEST_X> { \
|
||||
static bool test(CXXTEST_Y x,CXXTEST_X y) { \
|
||||
return lessThan<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }; \
|
||||
template<> struct lessThanEquals<CXXTEST_X,CXXTEST_Y> { \
|
||||
static bool test(CXXTEST_X x,CXXTEST_Y y) { \
|
||||
return lessThanEquals<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }; \
|
||||
template<> struct lessThanEquals<CXXTEST_Y,CXXTEST_X> { \
|
||||
static bool test(CXXTEST_Y x,CXXTEST_X y) { \
|
||||
return lessThanEquals<CXXTEST_T,CXXTEST_T>::test((CXXTEST_T)x,(CXXTEST_T)y); } }
|
||||
#if 0
|
||||
// These specializations are not needed because delta makes use of
|
||||
// CxxTest::lessThanEquals for the actual comparison
|
||||
template<class D> struct delta<CXXTEST_X, CXXTEST_Y, D>
|
||||
{
|
||||
\
|
||||
static bool test(CXXTEST_X x, CXXTEST_Y y, D d)
|
||||
{
|
||||
\
|
||||
return delta<CXXTEST_T, CXXTEST_T, D>::test((CXXTEST_T)x, (CXXTEST_T)y, d);
|
||||
}
|
||||
}; \
|
||||
template<class D> struct delta<CXXTEST_Y, CXXTEST_X, D>
|
||||
{
|
||||
\
|
||||
static bool test(CXXTEST_Y x, CXXTEST_X y, D d)
|
||||
{
|
||||
\
|
||||
return delta<CXXTEST_T, CXXTEST_T, D>::test((CXXTEST_T)x, (CXXTEST_T)y, d);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
# define CXXTEST_INTEGRAL(CXXTEST_T) \
|
||||
CXXTEST_COMPARISONS( signed CXXTEST_T, unsigned CXXTEST_T, unsigned CXXTEST_T )
|
||||
|
||||
CXXTEST_INTEGRAL(char);
|
||||
CXXTEST_INTEGRAL(short);
|
||||
CXXTEST_INTEGRAL(int);
|
||||
CXXTEST_INTEGRAL(long);
|
||||
# ifdef _CXXTEST_LONGLONG
|
||||
CXXTEST_INTEGRAL(_CXXTEST_LONGLONG);
|
||||
# endif // _CXXTEST_LONGLONG
|
||||
|
||||
# define CXXTEST_SMALL_BIG(CXXTEST_SMALL, CXXTEST_BIG) \
|
||||
CXXTEST_COMPARISONS( signed CXXTEST_SMALL, unsigned CXXTEST_BIG, unsigned CXXTEST_BIG ); \
|
||||
CXXTEST_COMPARISONS( signed CXXTEST_BIG, unsigned CXXTEST_SMALL, unsigned CXXTEST_BIG )
|
||||
|
||||
CXXTEST_SMALL_BIG(char, short);
|
||||
CXXTEST_SMALL_BIG(char, int);
|
||||
CXXTEST_SMALL_BIG(short, int);
|
||||
CXXTEST_SMALL_BIG(char, long);
|
||||
CXXTEST_SMALL_BIG(short, long);
|
||||
CXXTEST_SMALL_BIG(int, long);
|
||||
|
||||
# ifdef _CXXTEST_LONGLONG
|
||||
CXXTEST_SMALL_BIG(char, _CXXTEST_LONGLONG);
|
||||
CXXTEST_SMALL_BIG(short, _CXXTEST_LONGLONG);
|
||||
CXXTEST_SMALL_BIG(int, _CXXTEST_LONGLONG);
|
||||
CXXTEST_SMALL_BIG(long, _CXXTEST_LONGLONG);
|
||||
# endif // _CXXTEST_LONGLONG
|
||||
}
|
||||
|
||||
#ifdef _CXXTEST_HAVE_STD
|
||||
# include <cxxtest/StdTestSuite.h>
|
||||
#endif // _CXXTEST_HAVE_STD
|
||||
|
||||
#endif // __cxxtest__TestSuite_h__
|
||||
|
288
third-party/cxxtest/cxxtest/TestTracker.cpp
vendored
Normal file
288
third-party/cxxtest/cxxtest/TestTracker.cpp
vendored
Normal file
|
@ -0,0 +1,288 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__TestTracker_cpp__
|
||||
#define __cxxtest__TestTracker_cpp__
|
||||
|
||||
#include <cxxtest/TestTracker.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
bool TestTracker::_created = false;
|
||||
bool TestTracker::print_tracing = false;
|
||||
|
||||
TestTracker::TestTracker()
|
||||
{
|
||||
if (!_created)
|
||||
{
|
||||
initialize();
|
||||
setListener(0);
|
||||
_created = true;
|
||||
}
|
||||
}
|
||||
|
||||
TestTracker::~TestTracker()
|
||||
{
|
||||
}
|
||||
|
||||
TestTracker & TestTracker::tracker()
|
||||
{
|
||||
static TestTracker theTracker;
|
||||
return theTracker;
|
||||
}
|
||||
|
||||
void TestTracker::initialize()
|
||||
{
|
||||
_warnings = 0;
|
||||
_skippedTests = 0;
|
||||
_testSkipped = false;
|
||||
_failedTests = 0;
|
||||
_testFailedAsserts = 0;
|
||||
_suiteFailedTests = 0;
|
||||
_failedSuites = 0;
|
||||
_world = 0;
|
||||
_suite = 0;
|
||||
_test = 0;
|
||||
}
|
||||
|
||||
const TestDescription *TestTracker::fixTest(const TestDescription *d) const
|
||||
{
|
||||
return d ? d : &dummyTest();
|
||||
}
|
||||
|
||||
const SuiteDescription *TestTracker::fixSuite(const SuiteDescription *d) const
|
||||
{
|
||||
return d ? d : &dummySuite();
|
||||
}
|
||||
|
||||
const WorldDescription *TestTracker::fixWorld(const WorldDescription *d) const
|
||||
{
|
||||
return d ? d : &dummyWorld();
|
||||
}
|
||||
|
||||
const TestDescription &TestTracker::dummyTest() const
|
||||
{
|
||||
return dummySuite().testDescription(0);
|
||||
}
|
||||
|
||||
const SuiteDescription &TestTracker::dummySuite() const
|
||||
{
|
||||
return dummyWorld().suiteDescription(0);
|
||||
}
|
||||
|
||||
const WorldDescription &TestTracker::dummyWorld() const
|
||||
{
|
||||
return _dummyWorld;
|
||||
}
|
||||
|
||||
void TestTracker::setListener(TestListener *l)
|
||||
{
|
||||
_l = l ? l : &_dummyListener;
|
||||
}
|
||||
|
||||
void TestTracker::enterWorld(const WorldDescription &wd)
|
||||
{
|
||||
setWorld(&wd);
|
||||
_warnings = _skippedTests = _failedTests = _testFailedAsserts = _suiteFailedTests = _failedSuites = 0;
|
||||
_testSkipped = false;
|
||||
_l->enterWorld(wd);
|
||||
}
|
||||
|
||||
void TestTracker::enterSuite(const SuiteDescription &sd)
|
||||
{
|
||||
setSuite(&sd);
|
||||
_testFailedAsserts = _suiteFailedTests = 0;
|
||||
_testSkipped = false;
|
||||
_l->enterSuite(sd);
|
||||
}
|
||||
|
||||
void TestTracker::enterTest(const TestDescription &td)
|
||||
{
|
||||
setTest(&td);
|
||||
_testFailedAsserts = false;
|
||||
_testSkipped = false;
|
||||
_l->enterTest(td);
|
||||
}
|
||||
|
||||
void TestTracker::leaveTest(const TestDescription &td)
|
||||
{
|
||||
_l->leaveTest(td);
|
||||
setTest(0);
|
||||
}
|
||||
|
||||
void TestTracker::leaveSuite(const SuiteDescription &sd)
|
||||
{
|
||||
_l->leaveSuite(sd);
|
||||
setSuite(0);
|
||||
}
|
||||
|
||||
void TestTracker::leaveWorld(const WorldDescription &wd)
|
||||
{
|
||||
_l->leaveWorld(wd);
|
||||
setWorld(0);
|
||||
}
|
||||
|
||||
void TestTracker::trace(const char *file, int line, const char *expression)
|
||||
{
|
||||
_l->trace(file, line, expression);
|
||||
}
|
||||
|
||||
void TestTracker::warning(const char *file, int line, const char *expression)
|
||||
{
|
||||
countWarning();
|
||||
_l->warning(file, line, expression);
|
||||
}
|
||||
|
||||
void TestTracker::skippedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
countSkipped();
|
||||
_testSkipped = true;
|
||||
_l->skippedTest(file, line, expression);
|
||||
}
|
||||
|
||||
void TestTracker::failedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedTest(file, line, expression);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssert(const char *file, int line, const char *expression)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssert(file, line, expression);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertEquals(file, line, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertSameData(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *sizeStr, const void *x,
|
||||
const void *y, unsigned size)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertSameData(file, line, xStr, yStr, sizeStr, x, y, size);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertDelta(const char *file, int line,
|
||||
const char *xStr, const char *yStr, const char *dStr,
|
||||
const char *x, const char *y, const char *d)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertDelta(file, line, xStr, yStr, dStr, x, y, d);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertDiffers(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *value)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertDiffers(file, line, xStr, yStr, value);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertLessThan(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertLessThan(file, line, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertLessThanEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertLessThanEquals(file, line, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertPredicate(const char *file, int line,
|
||||
const char *predicate, const char *xStr, const char *x)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertPredicate(file, line, predicate, xStr, x);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertRelation(const char *file, int line,
|
||||
const char *relation, const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertRelation(file, line, relation, xStr, yStr, x, y);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertThrows(const char *file, int line,
|
||||
const char *expression, const char *type,
|
||||
bool otherThrown)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertThrows(file, line, expression, type, otherThrown);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertThrowsNot(const char *file, int line, const char *expression)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertThrowsNot(file, line, expression);
|
||||
}
|
||||
|
||||
void TestTracker::failedAssertSameFiles(const char *file, int line, const char *file1, const char* file2, const char* explanation)
|
||||
{
|
||||
countFailure();
|
||||
_l->failedAssertSameFiles(file, line, file1, file2, explanation);
|
||||
}
|
||||
|
||||
void TestTracker::setWorld(const WorldDescription *w)
|
||||
{
|
||||
_world = fixWorld(w);
|
||||
setSuite(0);
|
||||
}
|
||||
|
||||
void TestTracker::setSuite(const SuiteDescription *s)
|
||||
{
|
||||
_suite = fixSuite(s);
|
||||
setTest(0);
|
||||
}
|
||||
|
||||
void TestTracker::setTest(const TestDescription *t)
|
||||
{
|
||||
_test = fixTest(t);
|
||||
}
|
||||
|
||||
void TestTracker::countWarning()
|
||||
{
|
||||
++ _warnings;
|
||||
}
|
||||
|
||||
void TestTracker::countSkipped()
|
||||
{
|
||||
++ _skippedTests;
|
||||
}
|
||||
|
||||
void TestTracker::countFailure()
|
||||
{
|
||||
if (++ _testFailedAsserts == 1)
|
||||
{
|
||||
++ _failedTests;
|
||||
if (++ _suiteFailedTests == 1)
|
||||
{
|
||||
++ _failedSuites;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __cxxtest__TestTracker_cpp__
|
||||
|
134
third-party/cxxtest/cxxtest/TestTracker.h
vendored
Normal file
134
third-party/cxxtest/cxxtest/TestTracker.h
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__TestTracker_h__
|
||||
#define __cxxtest__TestTracker_h__
|
||||
|
||||
//
|
||||
// The TestTracker tracks running tests
|
||||
// The actual work is done in CountingListenerProxy,
|
||||
// but this way avoids cyclic references TestListener<->CountingListenerProxy
|
||||
//
|
||||
|
||||
#include <cxxtest/TestListener.h>
|
||||
#include <cxxtest/DummyDescriptions.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class TestListener;
|
||||
|
||||
class TestTracker : public TestListener
|
||||
{
|
||||
public:
|
||||
virtual ~TestTracker();
|
||||
|
||||
static TestTracker &tracker();
|
||||
static bool print_tracing;
|
||||
|
||||
const TestDescription *fixTest(const TestDescription *d) const;
|
||||
const SuiteDescription *fixSuite(const SuiteDescription *d) const;
|
||||
const WorldDescription *fixWorld(const WorldDescription *d) const;
|
||||
|
||||
const TestDescription &test() const { return *_test; }
|
||||
const SuiteDescription &suite() const { return *_suite; }
|
||||
const WorldDescription &world() const { return *_world; }
|
||||
|
||||
bool testSkipped() const { return _testSkipped; }
|
||||
bool testFailed() const { return (testFailedAsserts() > 0); }
|
||||
bool suiteFailed() const { return (suiteFailedTests() > 0); }
|
||||
bool worldFailed() const { return (failedSuites() > 0); }
|
||||
|
||||
unsigned warnings() const { return _warnings; }
|
||||
unsigned skippedTests() const { return _skippedTests; }
|
||||
unsigned failedTests() const { return _failedTests; }
|
||||
unsigned testFailedAsserts() const { return _testFailedAsserts; }
|
||||
unsigned suiteFailedTests() const { return _suiteFailedTests; }
|
||||
unsigned failedSuites() const { return _failedSuites; }
|
||||
|
||||
void enterWorld(const WorldDescription &wd);
|
||||
void enterSuite(const SuiteDescription &sd);
|
||||
void enterTest(const TestDescription &td);
|
||||
void leaveTest(const TestDescription &td);
|
||||
void leaveSuite(const SuiteDescription &sd);
|
||||
void leaveWorld(const WorldDescription &wd);
|
||||
void trace(const char *file, int line, const char *expression);
|
||||
void warning(const char *file, int line, const char *expression);
|
||||
void skippedTest(const char *file, int line, const char *expression);
|
||||
void failedTest(const char *file, int line, const char *expression);
|
||||
void failedAssert(const char *file, int line, const char *expression);
|
||||
void failedAssertEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y);
|
||||
void failedAssertSameData(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *sizeStr, const void *x,
|
||||
const void *y, unsigned size);
|
||||
void failedAssertDelta(const char *file, int line,
|
||||
const char *xStr, const char *yStr, const char *dStr,
|
||||
const char *x, const char *y, const char *d);
|
||||
void failedAssertDiffers(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *value);
|
||||
void failedAssertLessThan(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y);
|
||||
void failedAssertLessThanEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y);
|
||||
void failedAssertPredicate(const char *file, int line,
|
||||
const char *predicate, const char *xStr, const char *x);
|
||||
void failedAssertRelation(const char *file, int line,
|
||||
const char *relation, const char *xStr, const char *yStr,
|
||||
const char *x, const char *y);
|
||||
void failedAssertThrows(const char *file, int line,
|
||||
const char *expression, const char *type,
|
||||
bool otherThrown);
|
||||
void failedAssertThrowsNot(const char *file, int line, const char *expression);
|
||||
void failedAssertSameFiles(const char* file, int line, const char* file1, const char* file2, const char* explanation);
|
||||
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
TestTracker(const TestTracker &);
|
||||
TestTracker &operator=(const TestTracker &);
|
||||
|
||||
static bool _created;
|
||||
TestListener _dummyListener;
|
||||
DummyWorldDescription _dummyWorld;
|
||||
bool _testSkipped;
|
||||
unsigned _warnings, _skippedTests, _failedTests, _testFailedAsserts, _suiteFailedTests, _failedSuites;
|
||||
TestListener *_l;
|
||||
const WorldDescription *_world;
|
||||
const SuiteDescription *_suite;
|
||||
const TestDescription *_test;
|
||||
|
||||
const TestDescription &dummyTest() const;
|
||||
const SuiteDescription &dummySuite() const;
|
||||
const WorldDescription &dummyWorld() const;
|
||||
|
||||
void setWorld(const WorldDescription *w);
|
||||
void setSuite(const SuiteDescription *s);
|
||||
void setTest(const TestDescription *t);
|
||||
void countWarning();
|
||||
void countFailure();
|
||||
void countSkipped();
|
||||
|
||||
friend class TestRunner;
|
||||
|
||||
TestTracker();
|
||||
void setListener(TestListener *l);
|
||||
};
|
||||
|
||||
inline TestTracker &tracker() { return TestTracker::tracker(); }
|
||||
}
|
||||
|
||||
#endif // __cxxtest__TestTracker_h__
|
||||
|
195
third-party/cxxtest/cxxtest/ValueTraits.cpp
vendored
Normal file
195
third-party/cxxtest/cxxtest/ValueTraits.cpp
vendored
Normal file
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__ValueTraits_cpp__
|
||||
#define __cxxtest__ValueTraits_cpp__
|
||||
|
||||
#include <cxxtest/ValueTraits.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
//
|
||||
// Non-inline functions from ValueTraits.h
|
||||
//
|
||||
|
||||
char digitToChar(unsigned digit)
|
||||
{
|
||||
if (digit < 10)
|
||||
{
|
||||
return (char)('0' + digit);
|
||||
}
|
||||
if (digit <= 10 + 'Z' - 'A')
|
||||
{
|
||||
return (char)('A' + digit - 10);
|
||||
}
|
||||
return '?';
|
||||
}
|
||||
|
||||
const char *byteToHex(unsigned char byte)
|
||||
{
|
||||
static char asHex[3];
|
||||
asHex[0] = digitToChar(byte >> 4);
|
||||
asHex[1] = digitToChar(byte & 0x0F);
|
||||
asHex[2] = '\0';
|
||||
return asHex;
|
||||
}
|
||||
|
||||
char *copyString(char *dst, const char *src)
|
||||
{
|
||||
while ((*dst = *src) != '\0')
|
||||
{
|
||||
++ dst;
|
||||
++ src;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
bool stringsEqual(const char *s1, const char *s2)
|
||||
{
|
||||
char c;
|
||||
while ((c = *s1++) == *s2++)
|
||||
{
|
||||
if (c == '\0')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
char *charToString(unsigned long c, char *s)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\\': return copyString(s, "\\\\");
|
||||
case '\"': return copyString(s, "\\\"");
|
||||
case '\'': return copyString(s, "\\\'");
|
||||
case '\0': return copyString(s, "\\0");
|
||||
case '\a': return copyString(s, "\\a");
|
||||
case '\b': return copyString(s, "\\b");
|
||||
case '\n': return copyString(s, "\\n");
|
||||
case '\r': return copyString(s, "\\r");
|
||||
case '\t': return copyString(s, "\\t");
|
||||
}
|
||||
if (c >= 32 && c <= 127)
|
||||
{
|
||||
s[0] = (char)c;
|
||||
s[1] = '\0';
|
||||
return s + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
s[0] = '\\';
|
||||
s[1] = 'x';
|
||||
if (c < 0x10)
|
||||
{
|
||||
s[2] = '0';
|
||||
++ s;
|
||||
}
|
||||
return numberToString(c, s + 2, 16UL);
|
||||
}
|
||||
}
|
||||
|
||||
char *charToString(char c, char *s)
|
||||
{
|
||||
return charToString((unsigned long)(unsigned char)c, s);
|
||||
}
|
||||
|
||||
char *bytesToString(const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s)
|
||||
{
|
||||
bool truncate = (numBytes > maxBytes);
|
||||
if (truncate)
|
||||
{
|
||||
numBytes = maxBytes;
|
||||
}
|
||||
|
||||
s = copyString(s, "{ ");
|
||||
for (unsigned i = 0; i < numBytes; ++ i, ++ bytes)
|
||||
{
|
||||
s = copyString(copyString(s, byteToHex(*bytes)), " ");
|
||||
}
|
||||
if (truncate)
|
||||
{
|
||||
s = copyString(s, "...");
|
||||
}
|
||||
return copyString(s, " }");
|
||||
}
|
||||
|
||||
#ifndef CXXTEST_USER_VALUE_TRAITS
|
||||
unsigned ValueTraits<const double>::requiredDigitsOnLeft(double t)
|
||||
{
|
||||
unsigned digits = 1;
|
||||
for (t = (t < 0.0) ? -t : t; t > 1.0; t /= BASE)
|
||||
{
|
||||
++ digits;
|
||||
}
|
||||
return digits;
|
||||
}
|
||||
|
||||
char *ValueTraits<const double>::doNegative(double &t)
|
||||
{
|
||||
if (t >= 0)
|
||||
{
|
||||
return _asString;
|
||||
}
|
||||
_asString[0] = '-';
|
||||
t = -t;
|
||||
return _asString + 1;
|
||||
}
|
||||
|
||||
void ValueTraits<const double>::hugeNumber(double t)
|
||||
{
|
||||
char *s = doNegative(t);
|
||||
s = doubleToString(t, s, 0, 1);
|
||||
s = copyString(s, ".");
|
||||
s = doubleToString(t, s, 1, DIGITS_ON_RIGHT);
|
||||
s = copyString(s, "E");
|
||||
s = numberToString(requiredDigitsOnLeft(t) - 1, s);
|
||||
}
|
||||
|
||||
void ValueTraits<const double>::normalNumber(double t)
|
||||
{
|
||||
char *s = doNegative(t);
|
||||
s = doubleToString(t, s);
|
||||
s = copyString(s, ".");
|
||||
for (unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i)
|
||||
{
|
||||
s = numberToString((unsigned)(t *= BASE) % BASE, s);
|
||||
}
|
||||
}
|
||||
|
||||
void ValueTraits<const double>::nonFiniteNumber(double t)
|
||||
{
|
||||
char *s = _asString;
|
||||
if (t != t)
|
||||
{
|
||||
s = copyString(s, "nan");
|
||||
}
|
||||
//else if ( t == 1.0/0.0 )
|
||||
else if (t >= HUGE_VAL)
|
||||
{
|
||||
s = copyString(s, "-inf");
|
||||
}
|
||||
else if (t <= -HUGE_VAL)
|
||||
{
|
||||
//else if ( t == -1.0/0.0 )
|
||||
s = copyString(s, "inf");
|
||||
}
|
||||
}
|
||||
|
||||
char *ValueTraits<const double>::doubleToString(double t, char *s, unsigned skip, unsigned max)
|
||||
{
|
||||
return numberToString<double>(t, s, BASE, skip, max);
|
||||
}
|
||||
#endif // !CXXTEST_USER_VALUE_TRAITS
|
||||
}
|
||||
|
||||
#endif // __cxxtest__ValueTraits_cpp__
|
435
third-party/cxxtest/cxxtest/ValueTraits.h
vendored
Normal file
435
third-party/cxxtest/cxxtest/ValueTraits.h
vendored
Normal file
|
@ -0,0 +1,435 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__ValueTraits_h__
|
||||
#define __cxxtest__ValueTraits_h__
|
||||
|
||||
//
|
||||
// ValueTraits are used by CxxTest to convert arbitrary
|
||||
// values used in TS_ASSERT_EQUALS() to a string representation.
|
||||
//
|
||||
// This header file contains value traits for builtin integral types.
|
||||
// To declare value traits for new types you should instantiate the class
|
||||
// ValueTraits<YourClass>.
|
||||
//
|
||||
|
||||
#include <cxxtest/Flags.h>
|
||||
|
||||
#ifdef _CXXTEST_OLD_TEMPLATE_SYNTAX
|
||||
# define CXXTEST_TEMPLATE_INSTANTIATION
|
||||
#else // !_CXXTEST_OLD_TEMPLATE_SYNTAX
|
||||
# define CXXTEST_TEMPLATE_INSTANTIATION template<>
|
||||
#endif // _CXXTEST_OLD_TEMPLATE_SYNTAX
|
||||
|
||||
#ifdef _CXXTEST_HAVE_STD
|
||||
#include <cmath>
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
//
|
||||
// This is how we use the value traits
|
||||
//
|
||||
# define TS_AS_STRING(x) CxxTest::traits(x).asString()
|
||||
|
||||
//
|
||||
// Char representation of a digit
|
||||
//
|
||||
char digitToChar(unsigned digit);
|
||||
|
||||
//
|
||||
// Convert byte value to hex digits
|
||||
// Returns pointer to internal buffer
|
||||
//
|
||||
const char *byteToHex(unsigned char byte);
|
||||
|
||||
//
|
||||
// Convert byte values to string
|
||||
// Returns one past the copied data
|
||||
//
|
||||
char *bytesToString(const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s);
|
||||
|
||||
//
|
||||
// Copy a string.
|
||||
// Returns one past the end of the destination string
|
||||
// Remember -- we can't use the standard library!
|
||||
//
|
||||
char *copyString(char *dst, const char *src);
|
||||
|
||||
//
|
||||
// Compare two strings.
|
||||
// Remember -- we can't use the standard library!
|
||||
//
|
||||
bool stringsEqual(const char *s1, const char *s2);
|
||||
|
||||
//
|
||||
// Represent a character value as a string
|
||||
// Returns one past the end of the string
|
||||
// This will be the actual char if printable or '\xXXXX' otherwise
|
||||
//
|
||||
char *charToString(unsigned long c, char *s);
|
||||
|
||||
//
|
||||
// Prevent problems with negative (signed char)s
|
||||
//
|
||||
char *charToString(char c, char *s);
|
||||
|
||||
//
|
||||
// The default ValueTraits class dumps up to 8 bytes as hex values
|
||||
//
|
||||
template <class T>
|
||||
class ValueTraits
|
||||
{
|
||||
enum { MAX_BYTES = 8 };
|
||||
char _asString[sizeof("{ ") + sizeof("XX ") * MAX_BYTES + sizeof("... }")];
|
||||
|
||||
public:
|
||||
ValueTraits(const T &t) { bytesToString((const unsigned char *)&t, sizeof(T), MAX_BYTES, _asString); }
|
||||
const char *asString(void) const { return _asString; }
|
||||
};
|
||||
|
||||
//
|
||||
// traits( T t )
|
||||
// Creates an object of type ValueTraits<T>
|
||||
//
|
||||
template <class T>
|
||||
inline ValueTraits<T> traits(T t)
|
||||
{
|
||||
return ValueTraits<T>(t);
|
||||
}
|
||||
|
||||
//
|
||||
// You can duplicate the implementation of an existing ValueTraits
|
||||
//
|
||||
# define CXXTEST_COPY_TRAITS(CXXTEST_NEW_CLASS, CXXTEST_OLD_CLASS) \
|
||||
CXXTEST_TEMPLATE_INSTANTIATION \
|
||||
class ValueTraits< CXXTEST_NEW_CLASS > \
|
||||
{ \
|
||||
ValueTraits< CXXTEST_OLD_CLASS > _old; \
|
||||
public: \
|
||||
ValueTraits( CXXTEST_NEW_CLASS n ) : _old( (CXXTEST_OLD_CLASS)n ) {} \
|
||||
const char *asString( void ) const { return _old.asString(); } \
|
||||
}
|
||||
|
||||
//
|
||||
// Certain compilers need separate declarations for T and const T
|
||||
//
|
||||
# ifdef _CXXTEST_NO_COPY_CONST
|
||||
# define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS)
|
||||
# else // !_CXXTEST_NO_COPY_CONST
|
||||
# define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS) CXXTEST_COPY_TRAITS(CXXTEST_CLASS, const CXXTEST_CLASS)
|
||||
# endif // _CXXTEST_NO_COPY_CONST
|
||||
|
||||
//
|
||||
// Avoid compiler warnings about unsigned types always >= 0
|
||||
//
|
||||
template<class N> inline bool negative(N n) { return n < 0; }
|
||||
template<class N> inline N abs(N n) { return negative(n) ? -n : n; }
|
||||
|
||||
# define CXXTEST_NON_NEGATIVE(Type) \
|
||||
CXXTEST_TEMPLATE_INSTANTIATION \
|
||||
inline bool negative<Type>( Type ) { return false; } \
|
||||
CXXTEST_TEMPLATE_INSTANTIATION \
|
||||
inline Type abs<Type>( Type value ) { return value; }
|
||||
|
||||
CXXTEST_NON_NEGATIVE(bool)
|
||||
CXXTEST_NON_NEGATIVE(unsigned char)
|
||||
CXXTEST_NON_NEGATIVE(unsigned short int)
|
||||
CXXTEST_NON_NEGATIVE(unsigned int)
|
||||
CXXTEST_NON_NEGATIVE(unsigned long int)
|
||||
# ifdef _CXXTEST_LONGLONG
|
||||
CXXTEST_NON_NEGATIVE(unsigned _CXXTEST_LONGLONG)
|
||||
# endif // _CXXTEST_LONGLONG
|
||||
|
||||
//
|
||||
// Represent (integral) number as a string
|
||||
// Returns one past the end of the string
|
||||
// Remember -- we can't use the standard library!
|
||||
//
|
||||
template<class N>
|
||||
char *numberToString(N n, char *s,
|
||||
N base = 10,
|
||||
unsigned skipDigits = 0,
|
||||
unsigned maxDigits = (unsigned) - 1)
|
||||
{
|
||||
if (negative(n))
|
||||
{
|
||||
*s++ = '-';
|
||||
n = abs(n);
|
||||
}
|
||||
|
||||
N digit = 1;
|
||||
while (digit <= (n / base))
|
||||
{
|
||||
digit *= base;
|
||||
}
|
||||
N digitValue;
|
||||
for (; digit >= 1 && skipDigits; n -= digit * digitValue, digit /= base, -- skipDigits)
|
||||
{
|
||||
digitValue = (unsigned)(n / digit);
|
||||
}
|
||||
for (; digit >= 1 && maxDigits; n -= digit * digitValue, digit /= base, -- maxDigits)
|
||||
{
|
||||
*s++ = digitToChar((unsigned)(digitValue = (unsigned)(n / digit)));
|
||||
}
|
||||
|
||||
*s = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
//
|
||||
// All the specific ValueTraits follow.
|
||||
// You can #define CXXTEST_USER_VALUE_TRAITS if you don't want them
|
||||
//
|
||||
|
||||
#ifndef CXXTEST_USER_VALUE_TRAITS
|
||||
//
|
||||
// ValueTraits: const char * const &
|
||||
// This is used for printing strings, as in TS_FAIL( "Message" )
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const char * const &>
|
||||
{
|
||||
ValueTraits &operator=(const ValueTraits &);
|
||||
const char *_asString;
|
||||
|
||||
public:
|
||||
ValueTraits(const char * const &value) : _asString(value) {}
|
||||
ValueTraits(const ValueTraits &other) : _asString(other._asString) {}
|
||||
const char *asString(void) const { return _asString; }
|
||||
#if 0
|
||||
const char *asString(void) const
|
||||
{
|
||||
std::string tmp(1, '"');
|
||||
for (char const* src = _asString; src && *src; ++src)
|
||||
{
|
||||
switch (*src)
|
||||
{
|
||||
case '\\': tmp += "\\\\"; break;
|
||||
case '\n': tmp += "\\n"; break;
|
||||
case '\r': tmp += "\\r"; break;
|
||||
case '\t': tmp += "\\t"; break;
|
||||
case '"': tmp += "\\\""; break;
|
||||
default: tmp += *src; break;
|
||||
}
|
||||
}
|
||||
tmp += '"';
|
||||
|
||||
char* res = new char[tmp.size() + 1];
|
||||
return strcpy(res, tmp.c_str());
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
CXXTEST_COPY_TRAITS(const char *, const char * const &);
|
||||
CXXTEST_COPY_TRAITS(char *, const char * const &);
|
||||
|
||||
//
|
||||
// ValueTraits: bool
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const bool>
|
||||
{
|
||||
bool _value;
|
||||
|
||||
public:
|
||||
ValueTraits(const bool value) : _value(value) {}
|
||||
const char *asString(void) const { return _value ? "true" : "false"; }
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(bool);
|
||||
|
||||
# ifdef _CXXTEST_LONGLONG
|
||||
//
|
||||
// ValueTraits: signed long long
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const signed _CXXTEST_LONGLONG>
|
||||
{
|
||||
typedef _CXXTEST_LONGLONG T;
|
||||
char _asString[2 + 3 * sizeof(T)];
|
||||
public:
|
||||
ValueTraits(T t) { numberToString<T>(t, _asString); }
|
||||
const char *asString(void) const { return _asString; }
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(signed _CXXTEST_LONGLONG);
|
||||
|
||||
//
|
||||
// ValueTraits: unsigned long long
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const unsigned _CXXTEST_LONGLONG>
|
||||
{
|
||||
typedef unsigned _CXXTEST_LONGLONG T;
|
||||
char _asString[1 + 3 * sizeof(T)];
|
||||
public:
|
||||
ValueTraits(T t) { numberToString<T>(t, _asString); }
|
||||
const char *asString(void) const { return _asString; }
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(unsigned _CXXTEST_LONGLONG);
|
||||
# endif // _CXXTEST_LONGLONG
|
||||
|
||||
//
|
||||
// ValueTraits: signed long
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const signed long int>
|
||||
{
|
||||
typedef signed long int T;
|
||||
char _asString[2 + 3 * sizeof(T)];
|
||||
public:
|
||||
ValueTraits(T t) { numberToString<T>(t, _asString); }
|
||||
const char *asString(void) const { return _asString; }
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(signed long int);
|
||||
|
||||
//
|
||||
// ValueTraits: unsigned long
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const unsigned long int>
|
||||
{
|
||||
typedef unsigned long int T;
|
||||
char _asString[1 + 3 * sizeof(T)];
|
||||
public:
|
||||
ValueTraits(T t) { numberToString<T>(t, _asString); }
|
||||
const char *asString(void) const { return _asString; }
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(unsigned long int);
|
||||
|
||||
//
|
||||
// All decimals are the same as the long version
|
||||
//
|
||||
|
||||
CXXTEST_COPY_TRAITS(const signed int, const signed long int);
|
||||
CXXTEST_COPY_TRAITS(const unsigned int, const unsigned long int);
|
||||
CXXTEST_COPY_TRAITS(const signed short int, const signed long int);
|
||||
CXXTEST_COPY_TRAITS(const unsigned short int, const unsigned long int);
|
||||
CXXTEST_COPY_TRAITS(const unsigned char, const unsigned long int);
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(signed int);
|
||||
CXXTEST_COPY_CONST_TRAITS(unsigned int);
|
||||
CXXTEST_COPY_CONST_TRAITS(signed short int);
|
||||
CXXTEST_COPY_CONST_TRAITS(unsigned short int);
|
||||
CXXTEST_COPY_CONST_TRAITS(unsigned char);
|
||||
|
||||
//
|
||||
// ValueTraits: char
|
||||
// Returns 'x' for printable chars, '\x??' for others
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const char>
|
||||
{
|
||||
char _asString[sizeof("'\\xXX'")];
|
||||
public:
|
||||
ValueTraits(char c) { copyString(charToString(c, copyString(_asString, "'")), "'"); }
|
||||
const char *asString(void) const { return _asString; }
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(char);
|
||||
|
||||
//
|
||||
// ValueTraits: signed char
|
||||
// Same as char, some compilers need it
|
||||
//
|
||||
CXXTEST_COPY_TRAITS(const signed char, const char);
|
||||
CXXTEST_COPY_CONST_TRAITS(signed char);
|
||||
|
||||
//
|
||||
// ValueTraits: double
|
||||
//
|
||||
CXXTEST_TEMPLATE_INSTANTIATION
|
||||
class ValueTraits<const double>
|
||||
{
|
||||
public:
|
||||
ValueTraits(double t)
|
||||
{
|
||||
if ((t != t) || (t >= HUGE_VAL) || (t == -HUGE_VAL))
|
||||
{
|
||||
nonFiniteNumber(t);
|
||||
}
|
||||
else if (requiredDigitsOnLeft(t) > MAX_DIGITS_ON_LEFT)
|
||||
{
|
||||
hugeNumber(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
normalNumber(t);
|
||||
}
|
||||
}
|
||||
|
||||
const char *asString(void) const { return _asString; }
|
||||
|
||||
private:
|
||||
enum { MAX_DIGITS_ON_LEFT = 24, DIGITS_ON_RIGHT = 4, BASE = 10 };
|
||||
char _asString[1 + MAX_DIGITS_ON_LEFT + 1 + DIGITS_ON_RIGHT + 1];
|
||||
|
||||
static unsigned requiredDigitsOnLeft(double t);
|
||||
char *doNegative(double &t);
|
||||
void hugeNumber(double t);
|
||||
void normalNumber(double t);
|
||||
void nonFiniteNumber(double t);
|
||||
char *doubleToString(double t, char *s, unsigned skip = 0, unsigned max = (unsigned) - 1);
|
||||
};
|
||||
|
||||
CXXTEST_COPY_CONST_TRAITS(double);
|
||||
|
||||
//
|
||||
// ValueTraits: float
|
||||
//
|
||||
CXXTEST_COPY_TRAITS(const float, const double);
|
||||
CXXTEST_COPY_CONST_TRAITS(float);
|
||||
#endif // !CXXTEST_USER_VALUE_TRAITS
|
||||
}
|
||||
|
||||
#ifdef _CXXTEST_HAVE_STD
|
||||
# include <cxxtest/StdValueTraits.h>
|
||||
#endif // _CXXTEST_HAVE_STD
|
||||
|
||||
namespace dummy_enum_ns {}
|
||||
|
||||
//
|
||||
// CXXTEST_ENUM_TRAITS
|
||||
//
|
||||
#define CXXTEST_ENUM_TRAITS( TYPE, VALUES ) \
|
||||
namespace CxxTest \
|
||||
{ \
|
||||
CXXTEST_TEMPLATE_INSTANTIATION \
|
||||
class ValueTraits<TYPE> \
|
||||
{ \
|
||||
TYPE _value; \
|
||||
char _fallback[sizeof("(" #TYPE ")") + 3 * sizeof(TYPE)]; \
|
||||
public: \
|
||||
ValueTraits( TYPE value ) { \
|
||||
_value = value; \
|
||||
numberToString<unsigned long int>( _value, copyString( _fallback, "(" #TYPE ")" ) ); \
|
||||
} \
|
||||
const char *asString( void ) const \
|
||||
{ \
|
||||
switch ( _value ) \
|
||||
{ \
|
||||
VALUES \
|
||||
default: return _fallback; \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
} using namespace dummy_enum_ns
|
||||
|
||||
#define CXXTEST_ENUM_MEMBER( MEMBER ) \
|
||||
case MEMBER: return #MEMBER;
|
||||
|
||||
#endif // __cxxtest__ValueTraits_h__
|
572
third-party/cxxtest/cxxtest/Win32Gui.h
vendored
Normal file
572
third-party/cxxtest/cxxtest/Win32Gui.h
vendored
Normal file
|
@ -0,0 +1,572 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__Win32Gui_h__
|
||||
#define __cxxtest__Win32Gui_h__
|
||||
|
||||
//
|
||||
// The Win32Gui displays a simple progress bar using the Win32 API.
|
||||
//
|
||||
// It accepts the following command line options:
|
||||
// -minimized Start minimized, pop up on error
|
||||
// -keep Don't close the window at the end
|
||||
// -title TITLE Set the window caption
|
||||
//
|
||||
// If both -minimized and -keep are specified, GUI will only keep the
|
||||
// window if it's in focus.
|
||||
//
|
||||
// N.B. If you're wondering why this class doesn't use any standard
|
||||
// library or STL (<string> would have been nice) it's because it only
|
||||
// uses "straight" Win32 API.
|
||||
//
|
||||
|
||||
#include <cxxtest/Gui.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class Win32Gui : public GuiListener
|
||||
{
|
||||
public:
|
||||
void enterGui(int &argc, char **argv)
|
||||
{
|
||||
parseCommandLine(argc, argv);
|
||||
}
|
||||
|
||||
void enterWorld(const WorldDescription &wd)
|
||||
{
|
||||
getTotalTests(wd);
|
||||
_testsDone = 0;
|
||||
startGuiThread();
|
||||
}
|
||||
|
||||
void guiEnterSuite(const char *suiteName)
|
||||
{
|
||||
showSuiteName(suiteName);
|
||||
reset(_suiteStart);
|
||||
}
|
||||
|
||||
void guiEnterTest(const char *suiteName, const char *testName)
|
||||
{
|
||||
++ _testsDone;
|
||||
setTestCaption(suiteName, testName);
|
||||
showTestName(testName);
|
||||
showTestsDone();
|
||||
progressBarMessage(PBM_STEPIT);
|
||||
reset(_testStart);
|
||||
}
|
||||
|
||||
void yellowBar()
|
||||
{
|
||||
setColor(255, 255, 0);
|
||||
setIcon(IDI_WARNING);
|
||||
getTotalTests();
|
||||
}
|
||||
|
||||
void redBar()
|
||||
{
|
||||
if (_startMinimized)
|
||||
{
|
||||
showMainWindow(SW_SHOWNORMAL);
|
||||
}
|
||||
setColor(255, 0, 0);
|
||||
setIcon(IDI_ERROR);
|
||||
getTotalTests();
|
||||
}
|
||||
|
||||
void leaveGui()
|
||||
{
|
||||
if (keep())
|
||||
{
|
||||
showSummary();
|
||||
WaitForSingleObject(_gui, INFINITE);
|
||||
}
|
||||
DestroyWindow(_mainWindow);
|
||||
}
|
||||
|
||||
private:
|
||||
const char *_title;
|
||||
bool _startMinimized, _keep;
|
||||
HANDLE _gui;
|
||||
WNDCLASSEX _windowClass;
|
||||
HWND _mainWindow, _progressBar, _statusBar;
|
||||
HANDLE _canStartTests;
|
||||
unsigned _numTotalTests, _testsDone;
|
||||
char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
|
||||
enum
|
||||
{
|
||||
STATUS_SUITE_NAME, STATUS_SUITE_TIME,
|
||||
STATUS_TEST_NAME, STATUS_TEST_TIME,
|
||||
STATUS_TESTS_DONE, STATUS_WORLD_TIME,
|
||||
STATUS_TOTAL_PARTS
|
||||
};
|
||||
int _statusWidths[STATUS_TOTAL_PARTS];
|
||||
unsigned _statusOffsets[STATUS_TOTAL_PARTS];
|
||||
unsigned _statusTotal;
|
||||
char _statusTestsDone[sizeof("1000000000 of (100%)") + WorldDescription::MAX_STRLEN_TOTAL_TESTS];
|
||||
DWORD _worldStart, _suiteStart, _testStart;
|
||||
char _timeString[sizeof("00:00:00")];
|
||||
|
||||
void parseCommandLine(int argc, char **argv)
|
||||
{
|
||||
_startMinimized = _keep = false;
|
||||
_title = argv[0];
|
||||
|
||||
for (int i = 1; i < argc; ++ i)
|
||||
{
|
||||
if (!lstrcmpA(argv[i], "-minimized"))
|
||||
{
|
||||
_startMinimized = true;
|
||||
}
|
||||
else if (!lstrcmpA(argv[i], "-keep"))
|
||||
{
|
||||
_keep = true;
|
||||
}
|
||||
else if (!lstrcmpA(argv[i], "-title") && (i + 1 < argc))
|
||||
{
|
||||
_title = argv[++i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void getTotalTests()
|
||||
{
|
||||
getTotalTests(tracker().world());
|
||||
}
|
||||
|
||||
void getTotalTests(const WorldDescription &wd)
|
||||
{
|
||||
_numTotalTests = wd.numTotalTests();
|
||||
wd.strTotalTests(_strTotalTests);
|
||||
}
|
||||
|
||||
void startGuiThread()
|
||||
{
|
||||
_canStartTests = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
DWORD threadId;
|
||||
_gui = CreateThread(NULL, 0, &(Win32Gui::guiThread), (LPVOID)this, 0, &threadId);
|
||||
WaitForSingleObject(_canStartTests, INFINITE);
|
||||
}
|
||||
|
||||
static DWORD WINAPI guiThread(LPVOID parameter)
|
||||
{
|
||||
((Win32Gui *)parameter)->gui();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gui()
|
||||
{
|
||||
registerWindowClass();
|
||||
createMainWindow();
|
||||
initCommonControls();
|
||||
createProgressBar();
|
||||
createStatusBar();
|
||||
centerMainWindow();
|
||||
showMainWindow();
|
||||
startTimer();
|
||||
startTests();
|
||||
|
||||
messageLoop();
|
||||
}
|
||||
|
||||
void registerWindowClass()
|
||||
{
|
||||
_windowClass.cbSize = sizeof(_windowClass);
|
||||
_windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
_windowClass.lpfnWndProc = &(Win32Gui::windowProcedure);
|
||||
_windowClass.cbClsExtra = 0;
|
||||
_windowClass.cbWndExtra = sizeof(LONG);
|
||||
_windowClass.hInstance = (HINSTANCE)NULL;
|
||||
_windowClass.hIcon = (HICON)NULL;
|
||||
_windowClass.hCursor = (HCURSOR)NULL;
|
||||
_windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
_windowClass.lpszMenuName = NULL;
|
||||
_windowClass.lpszClassName = TEXT("CxxTest Window Class");
|
||||
_windowClass.hIconSm = (HICON)NULL;
|
||||
|
||||
RegisterClassEx(&_windowClass);
|
||||
}
|
||||
|
||||
void createMainWindow()
|
||||
{
|
||||
_mainWindow = createWindow(_windowClass.lpszClassName, WS_OVERLAPPEDWINDOW);
|
||||
}
|
||||
|
||||
void initCommonControls()
|
||||
{
|
||||
HMODULE dll = LoadLibraryA("comctl32.dll");
|
||||
if (!dll) { return; }
|
||||
|
||||
typedef void (WINAPI * FUNC)(void);
|
||||
FUNC func = (FUNC)GetProcAddress(dll, "InitCommonControls");
|
||||
if (!func) { return; }
|
||||
func();
|
||||
}
|
||||
|
||||
void createProgressBar()
|
||||
{
|
||||
_progressBar = createWindow(PROGRESS_CLASS, WS_CHILD | WS_VISIBLE | PBS_SMOOTH, _mainWindow);
|
||||
|
||||
#ifdef PBM_SETRANGE32
|
||||
progressBarMessage(PBM_SETRANGE32, 0, _numTotalTests);
|
||||
#else // No PBM_SETRANGE32, use PBM_SETRANGE
|
||||
progressBarMessage(PBM_SETRANGE, 0, MAKELPARAM(0, (WORD)_numTotalTests));
|
||||
#endif // PBM_SETRANGE32
|
||||
progressBarMessage(PBM_SETPOS, 0);
|
||||
progressBarMessage(PBM_SETSTEP, 1);
|
||||
greenBar();
|
||||
UpdateWindow(_progressBar);
|
||||
}
|
||||
|
||||
void createStatusBar()
|
||||
{
|
||||
_statusBar = createWindow(STATUSCLASSNAME, WS_CHILD | WS_VISIBLE, _mainWindow);
|
||||
setRatios(4, 1, 3, 1, 3, 1);
|
||||
}
|
||||
|
||||
void setRatios(unsigned suiteNameRatio, unsigned suiteTimeRatio,
|
||||
unsigned testNameRatio, unsigned testTimeRatio,
|
||||
unsigned testsDoneRatio, unsigned worldTimeRatio)
|
||||
{
|
||||
_statusTotal = 0;
|
||||
_statusOffsets[STATUS_SUITE_NAME] = (_statusTotal += suiteNameRatio);
|
||||
_statusOffsets[STATUS_SUITE_TIME] = (_statusTotal += suiteTimeRatio);
|
||||
_statusOffsets[STATUS_TEST_NAME] = (_statusTotal += testNameRatio);
|
||||
_statusOffsets[STATUS_TEST_TIME] = (_statusTotal += testTimeRatio);
|
||||
_statusOffsets[STATUS_TESTS_DONE] = (_statusTotal += testsDoneRatio);
|
||||
_statusOffsets[STATUS_WORLD_TIME] = (_statusTotal += worldTimeRatio);
|
||||
}
|
||||
|
||||
HWND createWindow(LPCTSTR className, DWORD style, HWND parent = (HWND)NULL)
|
||||
{
|
||||
return CreateWindow(className, NULL, style, 0, 0, 0, 0, parent,
|
||||
(HMENU)NULL, (HINSTANCE)NULL, (LPVOID)this);
|
||||
}
|
||||
|
||||
void progressBarMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
|
||||
{
|
||||
SendMessage(_progressBar, message, wParam, lParam);
|
||||
}
|
||||
|
||||
void centerMainWindow()
|
||||
{
|
||||
RECT screen;
|
||||
getScreenArea(screen);
|
||||
|
||||
LONG screenWidth = screen.right - screen.left;
|
||||
LONG screenHeight = screen.bottom - screen.top;
|
||||
|
||||
LONG xCenter = (screen.right + screen.left) / 2;
|
||||
LONG yCenter = (screen.bottom + screen.top) / 2;
|
||||
|
||||
LONG windowWidth = (screenWidth * 4) / 5;
|
||||
LONG windowHeight = screenHeight / 10;
|
||||
LONG minimumHeight = 2 * (GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME));
|
||||
if (windowHeight < minimumHeight)
|
||||
{
|
||||
windowHeight = minimumHeight;
|
||||
}
|
||||
|
||||
SetWindowPos(_mainWindow, HWND_TOP,
|
||||
xCenter - (windowWidth / 2), yCenter - (windowHeight / 2),
|
||||
windowWidth, windowHeight, 0);
|
||||
}
|
||||
|
||||
void getScreenArea(RECT &area)
|
||||
{
|
||||
if (!getScreenAreaWithoutTaskbar(area))
|
||||
{
|
||||
getWholeScreenArea(area);
|
||||
}
|
||||
}
|
||||
|
||||
bool getScreenAreaWithoutTaskbar(RECT &area)
|
||||
{
|
||||
return (SystemParametersInfo(SPI_GETWORKAREA, sizeof(RECT), &area, 0) != 0);
|
||||
}
|
||||
|
||||
void getWholeScreenArea(RECT &area)
|
||||
{
|
||||
area.left = area.top = 0;
|
||||
area.right = GetSystemMetrics(SM_CXSCREEN);
|
||||
area.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
||||
|
||||
void showMainWindow()
|
||||
{
|
||||
showMainWindow(_startMinimized ? SW_MINIMIZE : SW_SHOWNORMAL);
|
||||
UpdateWindow(_mainWindow);
|
||||
}
|
||||
|
||||
void showMainWindow(int mode)
|
||||
{
|
||||
ShowWindow(_mainWindow, mode);
|
||||
}
|
||||
|
||||
enum { TIMER_ID = 1, TIMER_DELAY = 1000 };
|
||||
|
||||
void startTimer()
|
||||
{
|
||||
reset(_worldStart);
|
||||
reset(_suiteStart);
|
||||
reset(_testStart);
|
||||
SetTimer(_mainWindow, TIMER_ID, TIMER_DELAY, 0);
|
||||
}
|
||||
|
||||
void reset(DWORD &tick)
|
||||
{
|
||||
tick = GetTickCount();
|
||||
}
|
||||
|
||||
void startTests()
|
||||
{
|
||||
SetEvent(_canStartTests);
|
||||
}
|
||||
|
||||
void messageLoop()
|
||||
{
|
||||
MSG message;
|
||||
while (BOOL haveMessage = GetMessage(&message, NULL, 0, 0))
|
||||
{
|
||||
if (haveMessage != -1)
|
||||
{
|
||||
DispatchMessage(&message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (message == WM_CREATE)
|
||||
{
|
||||
setUp(window, (LPCREATESTRUCT)lParam);
|
||||
}
|
||||
|
||||
Win32Gui *that = (Win32Gui *)GetWindowLong(window, GWL_USERDATA);
|
||||
return that->handle(window, message, wParam, lParam);
|
||||
}
|
||||
|
||||
static void setUp(HWND window, LPCREATESTRUCT create)
|
||||
{
|
||||
SetWindowLong(window, GWL_USERDATA, (LONG)create->lpCreateParams);
|
||||
}
|
||||
|
||||
LRESULT handle(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_SIZE: resizeControls(); break;
|
||||
|
||||
case WM_TIMER: updateTime(); break;
|
||||
|
||||
case WM_CLOSE:
|
||||
case WM_DESTROY:
|
||||
case WM_QUIT:
|
||||
ExitProcess(tracker().failedTests());
|
||||
|
||||
default: return DefWindowProc(window, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void resizeControls()
|
||||
{
|
||||
RECT r;
|
||||
GetClientRect(_mainWindow, &r);
|
||||
LONG width = r.right - r.left;
|
||||
LONG height = r.bottom - r.top;
|
||||
|
||||
GetClientRect(_statusBar, &r);
|
||||
LONG statusHeight = r.bottom - r.top;
|
||||
LONG resizeGripWidth = statusHeight;
|
||||
LONG progressHeight = height - statusHeight;
|
||||
|
||||
SetWindowPos(_progressBar, HWND_TOP, 0, 0, width, progressHeight, 0);
|
||||
SetWindowPos(_statusBar, HWND_TOP, 0, progressHeight, width, statusHeight, 0);
|
||||
setStatusParts(width - resizeGripWidth);
|
||||
}
|
||||
|
||||
void setStatusParts(LONG width)
|
||||
{
|
||||
for (unsigned i = 0; i < STATUS_TOTAL_PARTS; ++ i)
|
||||
{
|
||||
_statusWidths[i] = (width * _statusOffsets[i]) / _statusTotal;
|
||||
}
|
||||
|
||||
statusBarMessage(SB_SETPARTS, STATUS_TOTAL_PARTS, _statusWidths);
|
||||
}
|
||||
|
||||
void statusBarMessage(UINT message, WPARAM wParam = 0, const void *lParam = 0)
|
||||
{
|
||||
SendMessage(_statusBar, message, wParam, (LPARAM)lParam);
|
||||
}
|
||||
|
||||
void greenBar()
|
||||
{
|
||||
setColor(0, 255, 0);
|
||||
setIcon(IDI_INFORMATION);
|
||||
}
|
||||
|
||||
#ifdef PBM_SETBARCOLOR
|
||||
void setColor(BYTE red, BYTE green, BYTE blue)
|
||||
{
|
||||
progressBarMessage(PBM_SETBARCOLOR, 0, RGB(red, green, blue));
|
||||
}
|
||||
#else // !PBM_SETBARCOLOR
|
||||
void setColor(BYTE, BYTE, BYTE)
|
||||
{
|
||||
}
|
||||
#endif // PBM_SETBARCOLOR
|
||||
|
||||
void setIcon(LPCTSTR icon)
|
||||
{
|
||||
SendMessage(_mainWindow, WM_SETICON, ICON_BIG, (LPARAM)loadStandardIcon(icon));
|
||||
}
|
||||
|
||||
HICON loadStandardIcon(LPCTSTR icon)
|
||||
{
|
||||
return LoadIcon((HINSTANCE)NULL, icon);
|
||||
}
|
||||
|
||||
void setTestCaption(const char *suiteName, const char *testName)
|
||||
{
|
||||
setCaption(suiteName, "::", testName, "()");
|
||||
}
|
||||
|
||||
void setCaption(const char *a = "", const char *b = "", const char *c = "", const char *d = "")
|
||||
{
|
||||
unsigned length = lstrlenA(_title) + sizeof(" - ") +
|
||||
lstrlenA(a) + lstrlenA(b) + lstrlenA(c) + lstrlenA(d);
|
||||
char *name = allocate(length);
|
||||
lstrcpyA(name, _title);
|
||||
lstrcatA(name, " - ");
|
||||
lstrcatA(name, a);
|
||||
lstrcatA(name, b);
|
||||
lstrcatA(name, c);
|
||||
lstrcatA(name, d);
|
||||
SetWindowTextA(_mainWindow, name);
|
||||
deallocate(name);
|
||||
}
|
||||
|
||||
void showSuiteName(const char *suiteName)
|
||||
{
|
||||
setStatusPart(STATUS_SUITE_NAME, suiteName);
|
||||
}
|
||||
|
||||
void showTestName(const char *testName)
|
||||
{
|
||||
setStatusPart(STATUS_TEST_NAME, testName);
|
||||
}
|
||||
|
||||
void showTestsDone()
|
||||
{
|
||||
wsprintfA(_statusTestsDone, "%u of %s (%u%%)",
|
||||
_testsDone, _strTotalTests,
|
||||
(_testsDone * 100) / _numTotalTests);
|
||||
setStatusPart(STATUS_TESTS_DONE, _statusTestsDone);
|
||||
}
|
||||
|
||||
void updateTime()
|
||||
{
|
||||
setStatusTime(STATUS_WORLD_TIME, _worldStart);
|
||||
setStatusTime(STATUS_SUITE_TIME, _suiteStart);
|
||||
setStatusTime(STATUS_TEST_TIME, _testStart);
|
||||
}
|
||||
|
||||
void setStatusTime(unsigned part, DWORD start)
|
||||
{
|
||||
unsigned total = (GetTickCount() - start) / 1000;
|
||||
unsigned hours = total / 3600;
|
||||
unsigned minutes = (total / 60) % 60;
|
||||
unsigned seconds = total % 60;
|
||||
|
||||
if (hours)
|
||||
{
|
||||
wsprintfA(_timeString, "%u:%02u:%02u", hours, minutes, seconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintfA(_timeString, "%02u:%02u", minutes, seconds);
|
||||
}
|
||||
|
||||
setStatusPart(part, _timeString);
|
||||
}
|
||||
|
||||
bool keep()
|
||||
{
|
||||
if (!_keep)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!_startMinimized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return (_mainWindow == GetForegroundWindow());
|
||||
}
|
||||
|
||||
void showSummary()
|
||||
{
|
||||
stopTimer();
|
||||
setSummaryStatusBar();
|
||||
setSummaryCaption();
|
||||
}
|
||||
|
||||
void setStatusPart(unsigned part, const char *text)
|
||||
{
|
||||
statusBarMessage(SB_SETTEXTA, part, text);
|
||||
}
|
||||
|
||||
void stopTimer()
|
||||
{
|
||||
KillTimer(_mainWindow, TIMER_ID);
|
||||
setStatusTime(STATUS_WORLD_TIME, _worldStart);
|
||||
}
|
||||
|
||||
void setSummaryStatusBar()
|
||||
{
|
||||
setRatios(0, 0, 0, 0, 1, 1);
|
||||
resizeControls();
|
||||
|
||||
const char *tests = (_numTotalTests == 1) ? "test" : "tests";
|
||||
if (tracker().failedTests())
|
||||
{
|
||||
wsprintfA(_statusTestsDone, "Failed %u of %s %s",
|
||||
tracker().failedTests(), _strTotalTests, tests);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintfA(_statusTestsDone, "%s %s passed", _strTotalTests, tests);
|
||||
}
|
||||
|
||||
setStatusPart(STATUS_TESTS_DONE, _statusTestsDone);
|
||||
}
|
||||
|
||||
void setSummaryCaption()
|
||||
{
|
||||
setCaption(_statusTestsDone);
|
||||
}
|
||||
|
||||
char *allocate(unsigned length)
|
||||
{
|
||||
return (char *)HeapAlloc(GetProcessHeap(), 0, length);
|
||||
}
|
||||
|
||||
void deallocate(char *data)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, data);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__Win32Gui_h__
|
367
third-party/cxxtest/cxxtest/X11Gui.h
vendored
Normal file
367
third-party/cxxtest/cxxtest/X11Gui.h
vendored
Normal file
|
@ -0,0 +1,367 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__X11Gui_h__
|
||||
#define __cxxtest__X11Gui_h__
|
||||
|
||||
//
|
||||
// X11Gui displays a simple progress bar using X11
|
||||
//
|
||||
// It accepts the following command-line arguments:
|
||||
// -title <title> - Sets the application title
|
||||
// -fn or -font <font> - Sets the font
|
||||
// -bg or -background <color> - Sets the background color (default=Grey)
|
||||
// -fg or -foreground <color> - Sets the text color (default=Black)
|
||||
// -green/-yellow/-red <color> - Sets the colors of the bar
|
||||
//
|
||||
|
||||
#include <cxxtest/Gui.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class X11Gui : public GuiListener
|
||||
{
|
||||
public:
|
||||
void enterGui(int &argc, char **argv)
|
||||
{
|
||||
parseCommandLine(argc, argv);
|
||||
}
|
||||
|
||||
void enterWorld(const WorldDescription &wd)
|
||||
{
|
||||
openDisplay();
|
||||
if (_display)
|
||||
{
|
||||
createColors();
|
||||
createWindow();
|
||||
createGc();
|
||||
createFont();
|
||||
centerWindow();
|
||||
initializeEvents();
|
||||
initializeBar(wd);
|
||||
processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void guiEnterTest(const char *suiteName, const char *testName)
|
||||
{
|
||||
if (_display)
|
||||
{
|
||||
++ _testsDone;
|
||||
setWindowName(suiteName, testName);
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void yellowBar()
|
||||
{
|
||||
if (_display)
|
||||
{
|
||||
_barColor = getColor(_yellowName);
|
||||
getTotalTests();
|
||||
processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void redBar()
|
||||
{
|
||||
if (_display)
|
||||
{
|
||||
_barColor = getColor(_redName);
|
||||
getTotalTests();
|
||||
processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void leaveGui()
|
||||
{
|
||||
if (_display)
|
||||
{
|
||||
freeFontInfo();
|
||||
destroyGc();
|
||||
destroyWindow();
|
||||
closeDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const char *_programName;
|
||||
Display *_display;
|
||||
Window _window;
|
||||
unsigned _numTotalTests, _testsDone;
|
||||
char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
|
||||
const char *_foregroundName, *_backgroundName;
|
||||
const char *_greenName, *_yellowName, *_redName;
|
||||
unsigned long _foreground, _background, _barColor;
|
||||
int _width, _height;
|
||||
GC _gc;
|
||||
const char *_fontName;
|
||||
XID _fontId;
|
||||
XFontStruct *_fontInfo;
|
||||
int _textHeight, _textDescent;
|
||||
long _eventMask;
|
||||
Colormap _colormap;
|
||||
|
||||
void parseCommandLine(int &argc, char **argv)
|
||||
{
|
||||
_programName = argv[0];
|
||||
|
||||
_fontName = 0;
|
||||
_foregroundName = "Black";
|
||||
_backgroundName = "Grey";
|
||||
_greenName = "Green";
|
||||
_yellowName = "Yellow";
|
||||
_redName = "Red";
|
||||
|
||||
for (int i = 1; i + 1 < argc; ++ i)
|
||||
{
|
||||
if (!strcmp(argv[i], "-title"))
|
||||
{
|
||||
_programName = argv[++ i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-fn") || !strcmp(argv[i], "-font"))
|
||||
{
|
||||
_fontName = argv[++ i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-fg") || !strcmp(argv[i], "-foreground"))
|
||||
{
|
||||
_foregroundName = argv[++ i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-bg") || !strcmp(argv[i], "-background"))
|
||||
{
|
||||
_backgroundName = argv[++ i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-green"))
|
||||
{
|
||||
_greenName = argv[++ i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-yellow"))
|
||||
{
|
||||
_yellowName = argv[++ i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-red"))
|
||||
{
|
||||
_redName = argv[++ i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void openDisplay()
|
||||
{
|
||||
_display = XOpenDisplay(NULL);
|
||||
}
|
||||
|
||||
void createColors()
|
||||
{
|
||||
_colormap = DefaultColormap(_display, 0);
|
||||
_foreground = getColor(_foregroundName);
|
||||
_background = getColor(_backgroundName);
|
||||
}
|
||||
|
||||
unsigned long getColor(const char *colorName)
|
||||
{
|
||||
XColor color;
|
||||
XParseColor(_display, _colormap, colorName, &color);
|
||||
XAllocColor(_display, _colormap, &color);
|
||||
return color.pixel;
|
||||
}
|
||||
|
||||
void createWindow()
|
||||
{
|
||||
_window = XCreateSimpleWindow(_display, RootWindow(_display, 0), 0, 0, 1, 1, 0, 0, _background);
|
||||
}
|
||||
|
||||
void createGc()
|
||||
{
|
||||
_gc = XCreateGC(_display, _window, 0, 0);
|
||||
}
|
||||
|
||||
void createFont()
|
||||
{
|
||||
if (!loadFont())
|
||||
{
|
||||
useDefaultFont();
|
||||
}
|
||||
getFontInfo();
|
||||
_textHeight = _fontInfo->ascent + _fontInfo->descent;
|
||||
_textDescent = _fontInfo->descent;
|
||||
}
|
||||
|
||||
bool loadFont()
|
||||
{
|
||||
if (!_fontName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_fontId = XLoadFont(_display, _fontName);
|
||||
return (XSetFont(_display, _gc, _fontId) == Success);
|
||||
}
|
||||
|
||||
void useDefaultFont()
|
||||
{
|
||||
_fontId = XGContextFromGC(_gc);
|
||||
}
|
||||
|
||||
void getFontInfo()
|
||||
{
|
||||
_fontInfo = XQueryFont(_display, _fontId);
|
||||
}
|
||||
|
||||
void freeFontInfo()
|
||||
{
|
||||
XFreeFontInfo(NULL, _fontInfo, 1);
|
||||
}
|
||||
|
||||
void initializeEvents()
|
||||
{
|
||||
_eventMask = ExposureMask;
|
||||
XSelectInput(_display, _window, _eventMask);
|
||||
}
|
||||
|
||||
void initializeBar(const WorldDescription &wd)
|
||||
{
|
||||
getTotalTests(wd);
|
||||
_testsDone = 0;
|
||||
_barColor = getColor(_greenName);
|
||||
}
|
||||
|
||||
void getTotalTests()
|
||||
{
|
||||
getTotalTests(tracker().world());
|
||||
}
|
||||
|
||||
void getTotalTests(const WorldDescription &wd)
|
||||
{
|
||||
_numTotalTests = wd.numTotalTests();
|
||||
wd.strTotalTests(_strTotalTests);
|
||||
}
|
||||
|
||||
void centerWindow()
|
||||
{
|
||||
XMapWindow(_display, _window);
|
||||
|
||||
Screen *screen = XDefaultScreenOfDisplay(_display);
|
||||
int screenWidth = WidthOfScreen(screen);
|
||||
int screenHeight = HeightOfScreen(screen);
|
||||
int xCenter = screenWidth / 2;
|
||||
int yCenter = screenHeight / 2;
|
||||
|
||||
_width = (screenWidth * 4) / 5;
|
||||
_height = screenHeight / 14;
|
||||
|
||||
XMoveResizeWindow(_display, _window, xCenter - (_width / 2), yCenter - (_height / 2), _width, _height);
|
||||
}
|
||||
|
||||
void processEvents()
|
||||
{
|
||||
redraw();
|
||||
|
||||
XEvent event;
|
||||
while (XCheckMaskEvent(_display, _eventMask, &event))
|
||||
{
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void setWindowName(const char *suiteName, const char *testName)
|
||||
{
|
||||
unsigned length = strlen(_programName) + strlen(suiteName) + strlen(testName) + sizeof(" - ::()");
|
||||
char *name = (char *)malloc(length);
|
||||
sprintf(name, "%s - %s::%s()", _programName, suiteName, testName);
|
||||
XSetStandardProperties(_display, _window, name, 0, 0, 0, 0, 0);
|
||||
free(name);
|
||||
}
|
||||
|
||||
void redraw()
|
||||
{
|
||||
getWindowSize();
|
||||
drawSolidBar();
|
||||
drawDividers();
|
||||
drawPercentage();
|
||||
flush();
|
||||
}
|
||||
|
||||
void getWindowSize()
|
||||
{
|
||||
XWindowAttributes attributes;
|
||||
XGetWindowAttributes(_display, _window, &attributes);
|
||||
_width = attributes.width;
|
||||
_height = attributes.height;
|
||||
}
|
||||
|
||||
void drawSolidBar()
|
||||
{
|
||||
unsigned barWidth = (_width * _testsDone) / _numTotalTests;
|
||||
|
||||
XSetForeground(_display, _gc, _barColor);
|
||||
XFillRectangle(_display, _window, _gc, 0, 0, barWidth, _height);
|
||||
|
||||
XSetForeground(_display, _gc, _background);
|
||||
XFillRectangle(_display, _window, _gc, barWidth, 0, _width + 1 - barWidth, _height);
|
||||
}
|
||||
|
||||
void drawDividers()
|
||||
{
|
||||
if (_width / _numTotalTests < 5)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (unsigned i = 1; i < _testsDone; ++ i)
|
||||
{
|
||||
int x = (_width * i) / _numTotalTests;
|
||||
XDrawLine(_display, _window, _gc, x, 0, x, _height);
|
||||
}
|
||||
}
|
||||
|
||||
void drawPercentage()
|
||||
{
|
||||
XSetForeground(_display, _gc, _foreground);
|
||||
|
||||
char str[sizeof("1000000000 of ") + sizeof(_strTotalTests) + sizeof(" (100%)")];
|
||||
sprintf(str, "%u of %s (%u%%)", _testsDone, _strTotalTests, (_testsDone * 100) / _numTotalTests);
|
||||
unsigned len = strlen(str);
|
||||
|
||||
int textWidth = XTextWidth(_fontInfo, str, len);
|
||||
|
||||
XDrawString(_display, _window, _gc,
|
||||
(_width - textWidth) / 2, ((_height + _textHeight) / 2) - _textDescent,
|
||||
str, len);
|
||||
}
|
||||
|
||||
void flush()
|
||||
{
|
||||
XFlush(_display);
|
||||
}
|
||||
|
||||
void destroyGc()
|
||||
{
|
||||
XFreeGC(_display, _gc);
|
||||
}
|
||||
|
||||
void destroyWindow()
|
||||
{
|
||||
XDestroyWindow(_display, _window);
|
||||
}
|
||||
|
||||
void closeDisplay()
|
||||
{
|
||||
XCloseDisplay(_display);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //__cxxtest__X11Gui_h__
|
48
third-party/cxxtest/cxxtest/XUnitPrinter.h
vendored
Normal file
48
third-party/cxxtest/cxxtest/XUnitPrinter.h
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__XUNIT_PRINTER_H
|
||||
#define __CXXTEST__XUNIT_PRINTER_H
|
||||
|
||||
//
|
||||
// XUnitPrinter combines an ErrorPrinter with an XML formatter.
|
||||
//
|
||||
|
||||
#include <cxxtest/TeeListener.h>
|
||||
#include <cxxtest/ErrorPrinter.h>
|
||||
#include <cxxtest/XmlPrinter.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class XUnitPrinter : public TeeListener
|
||||
{
|
||||
public:
|
||||
|
||||
XmlPrinter xml_printer;
|
||||
ErrorPrinter error_printer;
|
||||
|
||||
XUnitPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout))
|
||||
: xml_printer(o)
|
||||
{
|
||||
setFirst(error_printer);
|
||||
setSecond(xml_printer);
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
TestRunner::runAllTests(*this);
|
||||
return tracker().failedTests();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //__CXXTEST__XUNIT_PRINTER_H
|
||||
|
664
third-party/cxxtest/cxxtest/XmlFormatter.h
vendored
Normal file
664
third-party/cxxtest/cxxtest/XmlFormatter.h
vendored
Normal file
|
@ -0,0 +1,664 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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.
|
||||
-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Licensed under the LGPL, see http://www.gnu.org/licenses/lgpl.html
|
||||
|
||||
#ifndef __CXXTEST__XMLFORMATTER_H
|
||||
#define __CXXTEST__XMLFORMATTER_H
|
||||
|
||||
//
|
||||
// The XmlFormatter is a TestListener that
|
||||
// prints reports of the errors to an output
|
||||
// stream in the form of an XML document.
|
||||
//
|
||||
|
||||
// The following definitions are used if stack trace support is enabled,
|
||||
// to give the traces an easily-parsable XML format. If stack tracing is
|
||||
// not enabled, then these definitions will be ignored.
|
||||
#define CXXTEST_STACK_TRACE_ESCAPE_AS_XML
|
||||
#define CXXTEST_STACK_TRACE_NO_ESCAPE_FILELINE_AFFIXES
|
||||
|
||||
#define CXXTEST_STACK_TRACE_INITIAL_PREFIX "<stack-frame function=\""
|
||||
#define CXXTEST_STACK_TRACE_INITIAL_SUFFIX "\"/>\n"
|
||||
#define CXXTEST_STACK_TRACE_OTHER_PREFIX CXXTEST_STACK_TRACE_INITIAL_PREFIX
|
||||
#define CXXTEST_STACK_TRACE_OTHER_SUFFIX CXXTEST_STACK_TRACE_INITIAL_SUFFIX
|
||||
#define CXXTEST_STACK_TRACE_ELLIDED_MESSAGE ""
|
||||
#define CXXTEST_STACK_TRACE_FILELINE_PREFIX "\" location=\""
|
||||
#define CXXTEST_STACK_TRACE_FILELINE_SUFFIX ""
|
||||
|
||||
|
||||
#include <cxxtest/TestRunner.h>
|
||||
#include <cxxtest/TestListener.h>
|
||||
#include <cxxtest/TestTracker.h>
|
||||
#include <cxxtest/ValueTraits.h>
|
||||
#include <cxxtest/ErrorFormatter.h>
|
||||
#include <cxxtest/StdHeaders.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class TeeOutputStreams
|
||||
{
|
||||
private:
|
||||
class teebuffer : public std::basic_streambuf<char>
|
||||
{
|
||||
typedef std::basic_streambuf<char> streambuf_t;
|
||||
public:
|
||||
teebuffer(streambuf_t * buf1, streambuf_t * buf2)
|
||||
: buffer1(buf1), buffer2(buf2)
|
||||
{}
|
||||
|
||||
virtual int overflow(int c)
|
||||
{
|
||||
if (c == EOF)
|
||||
{
|
||||
return !EOF;
|
||||
}
|
||||
else
|
||||
{
|
||||
int const ans1 = buffer1->sputc(c);
|
||||
int const ans2 = buffer2->sputc(c);
|
||||
return ans1 == EOF || ans2 == EOF ? EOF : c;
|
||||
}
|
||||
}
|
||||
|
||||
virtual int sync()
|
||||
{
|
||||
int ans1 = buffer1->pubsync();
|
||||
int ans2 = buffer2->pubsync();
|
||||
return ans1 || ans2 ? -1 : 0;
|
||||
}
|
||||
|
||||
streambuf_t * buffer1;
|
||||
streambuf_t * buffer2;
|
||||
};
|
||||
|
||||
public:
|
||||
TeeOutputStreams(std::ostream& _cout, std::ostream& _cerr)
|
||||
: out(),
|
||||
err(),
|
||||
orig_cout(_cout),
|
||||
orig_cerr(_cerr),
|
||||
tee_out(out.rdbuf(), _cout.rdbuf()),
|
||||
tee_err(err.rdbuf(), _cerr.rdbuf())
|
||||
{
|
||||
orig_cout.rdbuf(&tee_out);
|
||||
orig_cerr.rdbuf(&tee_err);
|
||||
}
|
||||
|
||||
~TeeOutputStreams()
|
||||
{
|
||||
orig_cout.rdbuf(tee_out.buffer2);
|
||||
orig_cerr.rdbuf(tee_err.buffer2);
|
||||
}
|
||||
|
||||
std::stringstream out;
|
||||
std::stringstream err;
|
||||
|
||||
private:
|
||||
std::ostream& orig_cout;
|
||||
std::ostream& orig_cerr;
|
||||
teebuffer tee_out;
|
||||
teebuffer tee_err;
|
||||
};
|
||||
|
||||
class ElementInfo
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
std::stringstream value;
|
||||
std::map<std::string, std::string> attribute;
|
||||
|
||||
ElementInfo()
|
||||
: name(), value(), attribute()
|
||||
{}
|
||||
|
||||
ElementInfo(const ElementInfo& rhs)
|
||||
: name(rhs.name), value(rhs.value.str()), attribute(rhs.attribute)
|
||||
{}
|
||||
|
||||
ElementInfo& operator=(const ElementInfo& rhs)
|
||||
{
|
||||
name = rhs.name;
|
||||
value.str(rhs.value.str());
|
||||
attribute = rhs.attribute;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
void add(const std::string& name_, Type& value_)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << value_;
|
||||
attribute[name_] = os.str();
|
||||
}
|
||||
|
||||
void write(OutputStream& os)
|
||||
{
|
||||
os << " <" << name.c_str() << " ";
|
||||
std::map<std::string, std::string>::iterator curr = attribute.begin();
|
||||
std::map<std::string, std::string>::iterator end = attribute.end();
|
||||
while (curr != end)
|
||||
{
|
||||
os << curr->first.c_str()
|
||||
<< "=\"" << curr->second.c_str() << "\" ";
|
||||
curr++;
|
||||
}
|
||||
if (value.str().empty())
|
||||
{
|
||||
os << "/>";
|
||||
}
|
||||
else
|
||||
{
|
||||
os << ">" << escape(value.str()).c_str()
|
||||
<< "</" << name.c_str() << ">";
|
||||
}
|
||||
os.endl(os);
|
||||
}
|
||||
|
||||
std::string escape(const std::string& str)
|
||||
{
|
||||
std::string escStr = "";
|
||||
for (size_t i = 0; i < str.length(); i++)
|
||||
{
|
||||
switch (str[i])
|
||||
{
|
||||
case '"': escStr += """; break;
|
||||
case '\'': escStr += "'"; break;
|
||||
case '<': escStr += "<"; break;
|
||||
case '>': escStr += ">"; break;
|
||||
case '&': escStr += "&"; break;
|
||||
default: escStr += str[i]; break;
|
||||
}
|
||||
}
|
||||
return escStr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class TestCaseInfo
|
||||
{
|
||||
public:
|
||||
|
||||
TestCaseInfo() : fail(false), error(false), runtime(0.0) {}
|
||||
std::string className;
|
||||
std::string testName;
|
||||
std::string line;
|
||||
bool fail;
|
||||
bool error;
|
||||
double runtime;
|
||||
std::list<ElementInfo> elements;
|
||||
typedef std::list<ElementInfo>::iterator element_t;
|
||||
std::string world;
|
||||
|
||||
element_t add_element(const std::string& name)
|
||||
{
|
||||
element_t elt = elements.insert(elements.end(), ElementInfo());
|
||||
elt->name = name;
|
||||
return elt;
|
||||
}
|
||||
|
||||
element_t update_element(const std::string& name)
|
||||
{
|
||||
element_t elt = elements.begin();
|
||||
while (elt != elements.end())
|
||||
{
|
||||
if (elt->name == name)
|
||||
{
|
||||
return elt;
|
||||
}
|
||||
elt++;
|
||||
}
|
||||
return add_element(name);
|
||||
}
|
||||
|
||||
void write(OutputStream &o)
|
||||
{
|
||||
o << " <testcase classname=\"" << className.c_str()
|
||||
<< "\" name=\"" << testName.c_str()
|
||||
<< "\" line=\"" << line.c_str() << "\"";
|
||||
bool elts = false;
|
||||
element_t curr = elements.begin();
|
||||
element_t end = elements.end();
|
||||
while (curr != end)
|
||||
{
|
||||
if (!elts)
|
||||
{
|
||||
o << ">";
|
||||
o.endl(o);
|
||||
elts = true;
|
||||
}
|
||||
curr->write(o);
|
||||
curr++;
|
||||
}
|
||||
if (elts)
|
||||
{
|
||||
o << " </testcase>";
|
||||
}
|
||||
else
|
||||
{
|
||||
o << " />";
|
||||
}
|
||||
o.endl(o);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class XmlFormatter : public TestListener
|
||||
{
|
||||
public:
|
||||
XmlFormatter(OutputStream *o, OutputStream *ostr, std::ostringstream *os)
|
||||
: _o(o), _ostr(ostr), _os(os), stream_redirect(NULL)
|
||||
{
|
||||
testcase = info.end();
|
||||
}
|
||||
|
||||
std::list<TestCaseInfo> info;
|
||||
std::list<TestCaseInfo>::iterator testcase;
|
||||
typedef std::list<ElementInfo>::iterator element_t;
|
||||
std::string classname;
|
||||
int ntests;
|
||||
int nfail;
|
||||
int nerror;
|
||||
double totaltime;
|
||||
|
||||
int run()
|
||||
{
|
||||
TestRunner::runAllTests(*this);
|
||||
return tracker().failedTests();
|
||||
}
|
||||
|
||||
void enterWorld(const WorldDescription & /*desc*/)
|
||||
{
|
||||
ntests = 0;
|
||||
nfail = 0;
|
||||
nerror = 0;
|
||||
totaltime = 0;
|
||||
}
|
||||
|
||||
static void totalTests(OutputStream &o)
|
||||
{
|
||||
char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
|
||||
const WorldDescription &wd = tracker().world();
|
||||
o << wd.strTotalTests(s)
|
||||
<< (wd.numTotalTests() == 1 ? " test" : " tests");
|
||||
}
|
||||
|
||||
void enterSuite(const SuiteDescription& desc)
|
||||
{
|
||||
classname = desc.suiteName();
|
||||
// replace "::" namespace with java-style "."
|
||||
size_t pos = 0;
|
||||
while ((pos = classname.find("::", pos)) !=
|
||||
CXXTEST_STD(string::npos))
|
||||
{
|
||||
classname.replace(pos, 2, ".");
|
||||
}
|
||||
while (! classname.empty() && classname[0] == '.')
|
||||
{
|
||||
classname.erase(0, 1);
|
||||
}
|
||||
|
||||
//CXXTEST_STD(cout) << "HERE " << desc.file() << " "
|
||||
// << classname << CXXTEST_STD(endl);
|
||||
|
||||
//classname=desc.suiteName();
|
||||
//(*_o) << "file=\"" << desc.file() << "\" ";
|
||||
//(*_o) << "line=\"" << desc.line() << "\"";
|
||||
//_o->flush();
|
||||
}
|
||||
|
||||
void leaveSuite(const SuiteDescription &)
|
||||
{
|
||||
std::list<TestCaseInfo>::iterator curr = info.begin();
|
||||
std::list<TestCaseInfo>::iterator end = info.end();
|
||||
while (curr != end)
|
||||
{
|
||||
if (curr->fail) { nfail++; }
|
||||
if (curr->error) { nerror++; }
|
||||
totaltime += curr->runtime;
|
||||
ntests++;
|
||||
curr++;
|
||||
}
|
||||
curr = info.begin();
|
||||
end = info.end();
|
||||
while (curr != end)
|
||||
{
|
||||
(*curr).write(*_ostr);
|
||||
curr++;
|
||||
}
|
||||
info.clear();
|
||||
}
|
||||
|
||||
void enterTest(const TestDescription & desc)
|
||||
{
|
||||
testcase = info.insert(info.end(), TestCaseInfo());
|
||||
testcase->testName = desc.testName();
|
||||
testcase->className = classname;
|
||||
std::ostringstream os;
|
||||
os << desc.line();
|
||||
testcase->line = os.str();
|
||||
|
||||
if (stream_redirect)
|
||||
CXXTEST_STD(cerr) << "ERROR: The stream_redirect != NULL"
|
||||
<< CXXTEST_STD(endl);
|
||||
|
||||
stream_redirect =
|
||||
new TeeOutputStreams(CXXTEST_STD(cout), CXXTEST_STD(cerr));
|
||||
}
|
||||
|
||||
void leaveTest(const TestDescription &)
|
||||
{
|
||||
if (stream_redirect != NULL)
|
||||
{
|
||||
std::string out = stream_redirect->out.str();
|
||||
if (! out.empty())
|
||||
{
|
||||
// silently ignore the '.'
|
||||
if (out[0] != '.' || out.size() > 1)
|
||||
{
|
||||
testcase->add_element("system-out")->value << out;
|
||||
}
|
||||
}
|
||||
if (! stream_redirect->err.str().empty())
|
||||
{
|
||||
testcase->add_element("system-err")->value << stream_redirect->err.str();
|
||||
}
|
||||
|
||||
delete stream_redirect;
|
||||
stream_redirect = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void leaveWorld(const WorldDescription& desc)
|
||||
{
|
||||
std::ostringstream os;
|
||||
const std::string currentDateTime = currentDateTimeStr();
|
||||
os << totaltime;
|
||||
(*_o) << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl;
|
||||
(*_o) << "<testsuite name=\"" << desc.worldName() << "\" ";
|
||||
(*_o) << "date=\"" << currentDateTime.c_str();
|
||||
(*_o) << "\" tests=\"" << ntests
|
||||
<< "\" errors=\"" << nerror
|
||||
<< "\" failures=\"" << nfail
|
||||
<< "\" time=\"" << os.str().c_str() << "\" >";
|
||||
_o->endl(*_o);
|
||||
(*_o) << _os->str().c_str();
|
||||
_os->clear();
|
||||
(*_o) << "</testsuite>" << endl;
|
||||
_o->flush();
|
||||
}
|
||||
|
||||
void trace(const char* /*file*/, int line, const char *expression)
|
||||
{
|
||||
if (testcase == info.end()) {
|
||||
return;
|
||||
}
|
||||
element_t elt = testcase->add_element("trace");
|
||||
elt->add("line", line);
|
||||
elt->value << expression;
|
||||
}
|
||||
|
||||
void warning(const char* /*file*/, int line, const char *expression)
|
||||
{
|
||||
if (testcase == info.end()) {
|
||||
return;
|
||||
}
|
||||
element_t elt = testcase->add_element("warning");
|
||||
elt->add("line", line);
|
||||
elt->value << expression;
|
||||
}
|
||||
|
||||
void skippedTest(const char* file, int line, const char* expression)
|
||||
{
|
||||
testSkipped(file, line, "skipped") << "Test skipped: " << expression;
|
||||
}
|
||||
|
||||
void failedTest(const char* file, int line, const char* expression)
|
||||
{
|
||||
testFailure(file, line, "failure") << "Test failed: " << expression;
|
||||
}
|
||||
|
||||
void failedAssert(const char *file, int line, const char *expression)
|
||||
{
|
||||
testFailure(file, line, "failedAssert")
|
||||
<< "Assertion failed: " << expression;
|
||||
}
|
||||
|
||||
void failedAssertEquals(const char *file, int line,
|
||||
const char* xStr, const char* yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
testFailure(file, line, "failedAssertEquals")
|
||||
<< "Error: Expected ("
|
||||
<< xStr << " == " << yStr << "), found ("
|
||||
<< x << " != " << y << ")";
|
||||
}
|
||||
|
||||
void failedAssertSameData(const char *file, int line,
|
||||
const char *xStr, const char *yStr, const char *sizeStr,
|
||||
const void* /*x*/, const void* /*y*/, unsigned size)
|
||||
{
|
||||
testFailure(file, line, "failedAssertSameData")
|
||||
<< "Error: Expected " << sizeStr
|
||||
<< " (" << size << ") bytes to be equal at ("
|
||||
<< xStr << ") and (" << yStr << "), found";
|
||||
}
|
||||
|
||||
void failedAssertSameFiles(const char *file, int line,
|
||||
const char *, const char *,
|
||||
const char* explanation
|
||||
)
|
||||
{
|
||||
testFailure(file, line, "failedAssertSameFiles")
|
||||
<< "Error: " << explanation;
|
||||
}
|
||||
|
||||
void failedAssertDelta(const char *file, int line,
|
||||
const char *xStr, const char *yStr, const char *dStr,
|
||||
const char *x, const char *y, const char *d)
|
||||
{
|
||||
testFailure(file, line, "failedAssertDelta")
|
||||
<< "Error: Expected ("
|
||||
<< xStr << " == " << yStr << ") up to " << dStr
|
||||
<< " (" << d << "), found ("
|
||||
<< x << " != " << y << ")";
|
||||
}
|
||||
|
||||
void failedAssertDiffers(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *value)
|
||||
{
|
||||
testFailure(file, line, "failedAssertDiffers")
|
||||
<< "Error: Expected ("
|
||||
<< xStr << " != " << yStr << "), found ("
|
||||
<< value << ")";
|
||||
}
|
||||
|
||||
void failedAssertLessThan(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
testFailure(file, line, "failedAssertLessThan")
|
||||
<< "Error: Expected (" <<
|
||||
xStr << " < " << yStr << "), found (" <<
|
||||
x << " >= " << y << ")";
|
||||
}
|
||||
|
||||
void failedAssertLessThanEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
testFailure(file, line, "failedAssertLessThanEquals")
|
||||
<< "Error: Expected (" <<
|
||||
xStr << " <= " << yStr << "), found (" <<
|
||||
x << " > " << y << ")";
|
||||
}
|
||||
|
||||
void failedAssertRelation(const char *file, int line,
|
||||
const char *relation, const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
testFailure(file, line, "failedAssertRelation")
|
||||
<< "Error: Expected " << relation << "( " <<
|
||||
xStr << ", " << yStr << " ), found !" << relation
|
||||
<< "( " << x << ", " << y << " )";
|
||||
}
|
||||
|
||||
void failedAssertPredicate(const char *file, int line,
|
||||
const char *predicate, const char *xStr, const char *x)
|
||||
{
|
||||
testFailure(file, line, "failedAssertPredicate")
|
||||
<< "Error: Expected " << predicate << "( " <<
|
||||
xStr << " ), found !" << predicate << "( " << x << " )";
|
||||
}
|
||||
|
||||
void failedAssertThrows(const char *file, int line,
|
||||
const char *expression, const char *type,
|
||||
bool otherThrown)
|
||||
{
|
||||
testFailure(file, line, "failedAssertThrows")
|
||||
<< "Error: Expected (" << expression << ") to throw (" <<
|
||||
type << ") but it "
|
||||
<< (otherThrown ? "threw something else" : "didn't throw");
|
||||
}
|
||||
|
||||
void failedAssertThrowsNot(const char *file, int line, const char *expression)
|
||||
{
|
||||
testFailure(file, line, "failedAssertThrowsNot")
|
||||
<< "Error: Expected (" << expression
|
||||
<< ") not to throw, but it did";
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
OutputStream *outputStream() const
|
||||
{
|
||||
return _o;
|
||||
}
|
||||
|
||||
OutputStream *outputFileStream() const
|
||||
{
|
||||
return _ostr;
|
||||
}
|
||||
|
||||
private:
|
||||
XmlFormatter(const XmlFormatter &);
|
||||
XmlFormatter &operator=(const XmlFormatter &);
|
||||
|
||||
std::stringstream& testFailure(const char* file, int line, const char *failureType)
|
||||
{
|
||||
testcase->fail = true;
|
||||
element_t elt = testcase->update_element("failure");
|
||||
if (elt->value.str().empty())
|
||||
{
|
||||
elt->add("type", failureType);
|
||||
elt->add("line", line);
|
||||
elt->add("file", file);
|
||||
}
|
||||
else
|
||||
{
|
||||
elt->value << CXXTEST_STD(endl);
|
||||
}
|
||||
return elt->value;
|
||||
//failedTest(file,line,message.c_str());
|
||||
}
|
||||
|
||||
std::stringstream& testSkipped(const char* file, int line, const char *failureType)
|
||||
{
|
||||
//testcase->fail = true;
|
||||
element_t elt = testcase->update_element("skipped");
|
||||
if (elt->value.str().empty())
|
||||
{
|
||||
elt->add("type", failureType);
|
||||
elt->add("line", line);
|
||||
elt->add("file", file);
|
||||
}
|
||||
else
|
||||
{
|
||||
elt->value << CXXTEST_STD(endl);
|
||||
}
|
||||
return elt->value;
|
||||
}
|
||||
|
||||
std::string currentDateTimeStr()
|
||||
{
|
||||
std::string retVal;
|
||||
const time_t now(time(NULL));
|
||||
char current_date_string[27];
|
||||
|
||||
#ifdef WIN32
|
||||
if (ctime_s(current_date_string, sizeof(current_date_string)-1, &now) == 0)
|
||||
{
|
||||
retVal = current_date_string;
|
||||
retVal.erase(retVal.find_last_not_of(" \n\r\t")+1); // trim trailing whitespace
|
||||
}
|
||||
#else
|
||||
const size_t n = strlen(ctime_r(&now, current_date_string));
|
||||
if (n)
|
||||
{
|
||||
current_date_string[n-1] = '\0'; // remove the ending \n
|
||||
retVal = current_date_string;
|
||||
}
|
||||
#endif
|
||||
return retVal;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void attributeBinary(const char* name, const void *value, unsigned size)
|
||||
{
|
||||
(*_o) << name;
|
||||
(*_o) << "=\"";
|
||||
dump(value, size);
|
||||
(*_o) << "\" ";
|
||||
}
|
||||
|
||||
void dump(const void *buffer, unsigned size)
|
||||
{
|
||||
if (!buffer) { return; }
|
||||
|
||||
unsigned dumpSize = size;
|
||||
if (maxDumpSize() && dumpSize > maxDumpSize())
|
||||
{
|
||||
dumpSize = maxDumpSize();
|
||||
}
|
||||
|
||||
const unsigned char *p = (const unsigned char *)buffer;
|
||||
for (unsigned i = 0; i < dumpSize; ++ i)
|
||||
{
|
||||
(*_o) << byteToHex(*p++) << " ";
|
||||
}
|
||||
if (dumpSize < size)
|
||||
{
|
||||
(*_o) << "... ";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void endl(OutputStream &o)
|
||||
{
|
||||
OutputStream::endl(o);
|
||||
}
|
||||
|
||||
OutputStream *_o;
|
||||
OutputStream *_ostr;
|
||||
std::ostringstream *_os;
|
||||
|
||||
TeeOutputStreams *stream_redirect;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __CXXTEST__XMLFORMATTER_H
|
||||
|
75
third-party/cxxtest/cxxtest/XmlPrinter.h
vendored
Normal file
75
third-party/cxxtest/cxxtest/XmlPrinter.h
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__XmlPrinter_h__
|
||||
#define __cxxtest__XmlPrinter_h__
|
||||
|
||||
//
|
||||
// The XmlPrinter is a simple TestListener that
|
||||
// prints JUnit style xml to the output stream
|
||||
//
|
||||
|
||||
|
||||
#include <cxxtest/Flags.h>
|
||||
|
||||
#ifndef _CXXTEST_HAVE_STD
|
||||
# define _CXXTEST_HAVE_STD
|
||||
#endif // _CXXTEST_HAVE_STD
|
||||
|
||||
#include <cxxtest/XmlFormatter.h>
|
||||
#include <cxxtest/StdValueTraits.h>
|
||||
|
||||
#include <sstream>
|
||||
#ifdef _CXXTEST_OLD_STD
|
||||
# include <iostream.h>
|
||||
#else // !_CXXTEST_OLD_STD
|
||||
# include <iostream>
|
||||
#endif // _CXXTEST_OLD_STD
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class XmlPrinter : public XmlFormatter
|
||||
{
|
||||
public:
|
||||
XmlPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char* /*preLine*/ = ":", const char* /*postLine*/ = "") :
|
||||
XmlFormatter(new Adapter(o), new Adapter(ostr), &ostr) {}
|
||||
|
||||
virtual ~XmlPrinter()
|
||||
{
|
||||
delete outputStream();
|
||||
delete outputFileStream();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::ostringstream ostr;
|
||||
|
||||
class Adapter : public OutputStream
|
||||
{
|
||||
CXXTEST_STD(ostream) &_o;
|
||||
public:
|
||||
Adapter(CXXTEST_STD(ostream) &o) : _o(o) {}
|
||||
void flush() { _o.flush(); }
|
||||
OutputStream &operator<<(const char *s) { _o << s; return *this; }
|
||||
OutputStream &operator<<(Manipulator m) { return OutputStream::operator<<(m); }
|
||||
OutputStream &operator<<(unsigned i)
|
||||
{
|
||||
char s[1 + 3 * sizeof(unsigned)];
|
||||
numberToString(i, s);
|
||||
_o << s;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__XmlPrinter_h__
|
||||
|
40
third-party/cxxtest/cxxtest/YesNoRunner.h
vendored
Normal file
40
third-party/cxxtest/cxxtest/YesNoRunner.h
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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__YesNoRunner_h__
|
||||
#define __cxxtest__YesNoRunner_h__
|
||||
|
||||
//
|
||||
// The YesNoRunner is a simple TestListener that
|
||||
// just returns true iff all tests passed.
|
||||
//
|
||||
|
||||
#include <cxxtest/TestRunner.h>
|
||||
#include <cxxtest/TestListener.h>
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class YesNoRunner : public TestListener
|
||||
{
|
||||
public:
|
||||
YesNoRunner()
|
||||
{
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
TestRunner::runAllTests(*this);
|
||||
return tracker().failedTests();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __cxxtest__YesNoRunner_h__
|
311
third-party/cxxtest/cxxtest/unix.h
vendored
Normal file
311
third-party/cxxtest/cxxtest/unix.h
vendored
Normal file
|
@ -0,0 +1,311 @@
|
|||
/*
|
||||
-------------------------------------------------------------------------
|
||||
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 UNIX_ERROR_PRINTER_H_N4C6JUX4
|
||||
#define UNIX_ERROR_PRINTER_H_N4C6JUX4
|
||||
|
||||
#ifndef _CXXTEST_HAVE_STD
|
||||
# define _CXXTEST_HAVE_STD
|
||||
#endif // _CXXTEST_HAVE_STD
|
||||
|
||||
#include <cxxtest/Flags.h>
|
||||
#include <cxxtest/TestRunner.h>
|
||||
#include <cxxtest/TestListener.h>
|
||||
#include <cxxtest/TestTracker.h>
|
||||
#include <cxxtest/ValueTraits.h>
|
||||
#include <cxxtest/StdValueTraits.h>
|
||||
#include <cxxtest/ErrorFormatter.h> // CxxTest::OutputStream
|
||||
|
||||
namespace CxxTest
|
||||
{
|
||||
class UNIXErrorFormatter : public TestListener
|
||||
{
|
||||
public:
|
||||
UNIXErrorFormatter(OutputStream *o, const char *preLine = ":", const char *postLine = "") :
|
||||
_reported(false),
|
||||
_o(o),
|
||||
_preLine(preLine),
|
||||
_postLine(postLine)
|
||||
{
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
TestRunner::runAllTests(*this);
|
||||
return tracker().failedTests();
|
||||
}
|
||||
|
||||
static void totalTests(OutputStream &o)
|
||||
{
|
||||
char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
|
||||
const WorldDescription &wd = tracker().world();
|
||||
o << wd.strTotalTests(s) << (wd.numTotalTests() == 1 ? " test" : " tests");
|
||||
}
|
||||
|
||||
void enterTest(const TestDescription &)
|
||||
{
|
||||
_reported = false;
|
||||
}
|
||||
|
||||
void leaveWorld(const WorldDescription &desc)
|
||||
{
|
||||
if (tracker().failedTests())
|
||||
{
|
||||
(*_o) << "Failed " << tracker().failedTests() << " of " << totalTests << endl;
|
||||
unsigned numPassed = desc.numTotalTests() - tracker().failedTests() - tracer().skippedTests();
|
||||
unsigned numTotal = desc.numTotalTests() - tracker().skippedTests();
|
||||
if (numTotal == 0)
|
||||
{
|
||||
(*_o) << "Success rate: 100%" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*_o) << "Success rate: " << (unsigned)(numPassed * 100.0 / numTotal) << "%" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void trace(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << "Trace: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void warning(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << "Warning: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void skippedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << "Warning: Test skipped: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void failedTest(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << "Error: Test failed: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void failedAssert(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << "Error: Assertion failed: " <<
|
||||
expression << endl;
|
||||
}
|
||||
|
||||
void failedAssertEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << "Error: Expected (" <<
|
||||
xStr << " == " << yStr << "), found (" <<
|
||||
x << " != " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertSameData(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *sizeStr, const void *x,
|
||||
const void *y, unsigned size)
|
||||
{
|
||||
stop(file, line) << "Error: Expected " << sizeStr << " (" << size << ") bytes to be equal at (" <<
|
||||
xStr << ") and (" << yStr << "), found:" << endl;
|
||||
dump(x, size);
|
||||
(*_o) << " differs from" << endl;
|
||||
dump(y, size);
|
||||
}
|
||||
|
||||
void failedAssertSameFiles(const char* file, int line,
|
||||
const char*, const char*,
|
||||
const char* explanation
|
||||
)
|
||||
{
|
||||
stop(file, line) << "Error: " << explanation << endl;
|
||||
}
|
||||
|
||||
void failedAssertDelta(const char *file, int line,
|
||||
const char *xStr, const char *yStr, const char *dStr,
|
||||
const char *x, const char *y, const char *d)
|
||||
{
|
||||
stop(file, line) << "Error: Expected (" <<
|
||||
xStr << " == " << yStr << ") up to " << dStr << " (" << d << "), found (" <<
|
||||
x << " != " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertDiffers(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *value)
|
||||
{
|
||||
stop(file, line) << "Error: Expected (" <<
|
||||
xStr << " != " << yStr << "), found (" <<
|
||||
value << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertLessThan(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << "Error: Expected (" <<
|
||||
xStr << " < " << yStr << "), found (" <<
|
||||
x << " >= " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertLessThanEquals(const char *file, int line,
|
||||
const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << "Error: Expected (" <<
|
||||
xStr << " <= " << yStr << "), found (" <<
|
||||
x << " > " << y << ")" << endl;
|
||||
}
|
||||
|
||||
void failedAssertRelation(const char *file, int line,
|
||||
const char *relation, const char *xStr, const char *yStr,
|
||||
const char *x, const char *y)
|
||||
{
|
||||
stop(file, line) << "Error: Expected " << relation << "( " <<
|
||||
xStr << ", " << yStr << " ), found !" << relation << "( " << x << ", " << y << " )" << endl;
|
||||
}
|
||||
|
||||
void failedAssertPredicate(const char *file, int line,
|
||||
const char *predicate, const char *xStr, const char *x)
|
||||
{
|
||||
stop(file, line) << "Error: Expected " << predicate << "( " <<
|
||||
xStr << " ), found !" << predicate << "( " << x << " )" << endl;
|
||||
}
|
||||
|
||||
void failedAssertThrows(const char *file, int line,
|
||||
const char *expression, const char *type,
|
||||
bool otherThrown)
|
||||
{
|
||||
stop(file, line) << "Error: Expected (" << expression << ") to throw (" <<
|
||||
type << ") but it " << (otherThrown ? "threw something else" : "didn't throw") <<
|
||||
endl;
|
||||
}
|
||||
|
||||
void failedAssertThrowsNot(const char *file, int line, const char *expression)
|
||||
{
|
||||
stop(file, line) << "Error: Expected (" << expression << ") not to throw, but it did" <<
|
||||
endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
OutputStream *outputStream() const
|
||||
{
|
||||
return _o;
|
||||
}
|
||||
|
||||
private:
|
||||
UNIXErrorFormatter(const UNIXErrorFormatter &);
|
||||
UNIXErrorFormatter &operator=(const UNIXErrorFormatter &);
|
||||
|
||||
OutputStream &stop(const char *file, int line)
|
||||
{
|
||||
reportTest();
|
||||
return (*_o) << file << _preLine << line << _postLine << ": ";
|
||||
}
|
||||
|
||||
void reportTest(void)
|
||||
{
|
||||
if (_reported)
|
||||
{
|
||||
return;
|
||||
}
|
||||
(*_o) << tracker().suite().file() << ": In " << tracker().suite().suiteName() << "::" << tracker().test().testName() << ":" << endl;
|
||||
_reported = true;
|
||||
}
|
||||
|
||||
void dump(const void *buffer, unsigned size)
|
||||
{
|
||||
if (!buffer)
|
||||
{
|
||||
dumpNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
dumpBuffer(buffer, size);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpNull()
|
||||
{
|
||||
(*_o) << " (null)" << endl;
|
||||
}
|
||||
|
||||
void dumpBuffer(const void *buffer, unsigned size)
|
||||
{
|
||||
unsigned dumpSize = size;
|
||||
if (maxDumpSize() && dumpSize > maxDumpSize())
|
||||
{
|
||||
dumpSize = maxDumpSize();
|
||||
}
|
||||
|
||||
const unsigned char *p = (const unsigned char *)buffer;
|
||||
(*_o) << " { ";
|
||||
for (unsigned i = 0; i < dumpSize; ++ i)
|
||||
{
|
||||
(*_o) << byteToHex(*p++) << " ";
|
||||
}
|
||||
if (dumpSize < size)
|
||||
{
|
||||
(*_o) << "... ";
|
||||
}
|
||||
(*_o) << "}" << endl;
|
||||
}
|
||||
|
||||
static void endl(OutputStream &o)
|
||||
{
|
||||
OutputStream::endl(o);
|
||||
}
|
||||
|
||||
bool _reported;
|
||||
OutputStream *_o;
|
||||
const char *_preLine;
|
||||
const char *_postLine;
|
||||
};
|
||||
|
||||
// ========================================================================================
|
||||
// = Actual runner is a subclass only because that is how the original ErrorPrinter works =
|
||||
// ========================================================================================
|
||||
|
||||
class unix : public UNIXErrorFormatter
|
||||
{
|
||||
public:
|
||||
unix(CXXTEST_STD(ostream) &o = CXXTEST_STD(cerr), const char *preLine = ":", const char *postLine = "") :
|
||||
UNIXErrorFormatter(new Adapter(o), preLine, postLine) {}
|
||||
virtual ~unix() { delete outputStream(); }
|
||||
|
||||
private:
|
||||
class Adapter : public OutputStream
|
||||
{
|
||||
CXXTEST_STD(ostream) &_o;
|
||||
public:
|
||||
Adapter(CXXTEST_STD(ostream) &o) : _o(o) {}
|
||||
void flush() { _o.flush(); }
|
||||
OutputStream &operator<<(const char *s) { _o << s; return *this; }
|
||||
OutputStream &operator<<(Manipulator m) { return OutputStream::operator<<(m); }
|
||||
OutputStream &operator<<(unsigned i)
|
||||
{
|
||||
char s[1 + 3 * sizeof(unsigned)];
|
||||
numberToString(i, s);
|
||||
_o << s;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* end of include guard: UNIX_ERROR_PRINTER_H_N4C6JUX4 */
|
||||
|
||||
// Copyright 2008 Sandia Corporation. Under the terms of Contract
|
||||
// DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
|
||||
// retains certain rights in this software.
|
Loading…
Reference in New Issue
Block a user