Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
#include <cxxtest/TestSuite.h>
//
// This is a test suite which doesn't use exception handling.
// It is used to verify --abort-on-fail + --have-eh
//
class AborterNoThrow : public CxxTest::TestSuite
{
public:
void testFailures()
{
TS_FAIL(1);
TS_FAIL(2);
TS_FAIL(3);
TS_FAIL(4);
TS_FAIL(5);
}
};

View File

@@ -0,0 +1,55 @@
#include <cxxtest/TestSuite.h>
//
// A simple test suite that cannot be parsed with the default test discovery mechanism
//
class BadTest
:
public CxxTest::TestSuite
{
public:
void testEquality()
{
TS_ASSERT_EQUALS(1, 1);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS('a', 'A');
TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234);
}
void testAddition()
{
TS_ASSERT_EQUALS(1 + 1, 2);
TS_ASSERT_EQUALS(2 + 2, 5);
}
void TestMultiplication()
{
TS_ASSERT_EQUALS(2 * 2, 4);
TS_ASSERT_EQUALS(4 * 4, 44);
TS_ASSERT_DIFFERS(-2 * -2, 4);
}
void testComparison()
{
TS_ASSERT_LESS_THAN((int)1, (unsigned long)2);
TS_ASSERT_LESS_THAN(-1, -2);
}
void testTheWorldIsCrazy()
{
TS_ASSERT_EQUALS(true, false);
}
void test_Failure()
{
TS_FAIL("Not implemented");
TS_FAIL(1569779912);
}
void test_TS_WARN_macro()
{
TS_WARN("Just a friendly warning");
TS_WARN("Warnings don't abort the test");
}
};

View File

@@ -0,0 +1,24 @@
#include <cxxtest/TestSuite.h>
//
// This is a test of commenting out tests in CxxTest
//
class Comments : public CxxTest::TestSuite
{
public:
void test_Something()
{
TS_WARN("Something");
}
// void test_Something_else()
// {
// TS_WARN( "Something else" );
// }
//void test_Something_else()
//{
// TS_WARN( "Something else" );
//}
};

View File

@@ -0,0 +1,21 @@
#include <cxxtest/TestSuite.h>
//
// This is a test of commenting out tests in CxxTest
//
class Comments : public CxxTest::TestSuite
{
public:
void test_Something()
{
TS_WARN("Something");
}
/*
void test_Something_else()
{
TS_WARN( "Something else" );
}
*/
};

View File

@@ -0,0 +1,39 @@
#include <cxxtest/TestSuite.h>
template <class T>
class Tests
{
public:
CXXTEST_STD(list)<T>* cache;
void setUp()
{
this->cache = new CXXTEST_STD(list)<T>();
}
void tearDown()
{
delete this->cache;
}
void test_size()
{
TS_ASSERT_EQUALS(cache->size(), 0);
}
void test_insert()
{
this->cache->push_back(1);
TS_ASSERT_EQUALS(cache->size(), 1);
}
};
class IntTests: public Tests<int>, public CxxTest::TestSuite
{
public:
void setUp() { Tests<int>::setUp(); }
void tearDown() { Tests<int>::tearDown(); }
};

View File

@@ -0,0 +1,84 @@
#include <cxxtest/TestSuite.h>
//
// This test suite verifies that the TS_ASSERT_THROWS*() macros are "abort on fail"-friendly
//
class DeepAbort : public CxxTest::TestSuite
{
public:
void testAssertThrowsPassesAbort()
{
TS_ASSERT_THROWS(fail(), int);
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testMessageAssertThrowsPassesAbort()
{
TSM_ASSERT_THROWS("fail() should throw an int", fail(), int);
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testAssertThrowsAborts()
{
TS_ASSERT_THROWS(succeed(), int);
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testMessageAssertThrowsAborts()
{
TSM_ASSERT_THROWS("succeed() should throw an int", succeed(), int);
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testAssertThrowsNothingPassesAbort()
{
TS_ASSERT_THROWS_NOTHING(fail());
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testMessageAssertThrowsNothingPassesAbort()
{
TSM_ASSERT_THROWS_NOTHING("fail() shouldn't throw anything", fail());
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testAssertThrowsNothingAborts()
{
TS_ASSERT_THROWS_NOTHING(throwSomething());
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testMessageAssertThrowsNothingAborts()
{
TSM_ASSERT_THROWS_NOTHING("fail() shouldn't throw anything", throwSomething());
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testAssertThrowsAnything()
{
TS_ASSERT_THROWS_ANYTHING(succeed());
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void testMessageAssertThrowsAnything()
{
TSM_ASSERT_THROWS_ANYTHING("succeed() should throw something", succeed());
TS_FAIL("You shouldn't see this if --abort-on-fail is used");
}
void fail()
{
TS_ASSERT_EQUALS(0, 1);
}
void throwSomething()
{
throw "something";
}
void succeed()
{
TS_ASSERT_EQUALS(1, 1);
}
};

View File

@@ -0,0 +1,3 @@
#define CXXTEST_HAVE_EH
#define CXXTEST_ABORT_TEST_ON_FAIL
#define CXXTEST_DEFAULT_ABORT false

View File

@@ -0,0 +1,41 @@
#include <cxxtest/TestSuite.h>
//
// This test suite demonstrates the default ValueTraits
//
class DefaultTraits : public CxxTest::TestSuite
{
public:
struct EightBytes
{
EightBytes() {}
unsigned char data[8];
};
void testSmallDefaultTraits()
{
EightBytes x;
for (unsigned i = 0; i < sizeof(x.data); ++ i)
{
x.data[i] = (unsigned char)i;
}
TS_FAIL(x);
}
struct NineBytes
{
NineBytes() {}
unsigned char data[9];
};
void testBigDefaultTraits()
{
NineBytes x;
for (unsigned i = 0; i < sizeof(x.data); ++ i)
{
x.data[i] = (unsigned char)(0x98 + i);
}
TS_FAIL(x);
}
};

View File

@@ -0,0 +1,38 @@
#include <cxxtest/TestSuite.h>
//
// This test suite tests double macro invocation
// E.g. when TS_ASSERT_EQUALS( x, y ) fails, it should evaulate x and y once
// Consider TS_ASSERT_EQUALS( readNextValue(), 3 )
//
class DoubleCall : public CxxTest::TestSuite
{
public:
int i;
void setUp()
{
i = 0;
}
void testAssertEqualsWithSideEffects()
{
TS_ASSERT_EQUALS(increment(), 3);
}
void testAssertDiffersWithSideEffects()
{
TS_ASSERT_DIFFERS(increment(), 1);
}
void testAssertDeltaWithSideEffects()
{
TS_ASSERT_DELTA(increment(), 2.0, 0.5);
}
int increment()
{
return ++i;
}
};

View File

@@ -0,0 +1,52 @@
#include <cxxtest/TestSuite.h>
class DynamicAbort : public CxxTest::TestSuite
{
public:
void test_Abort_on_fail_in_this_test()
{
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
}
void test_Dont_abort_in_this_test()
{
CxxTest::setAbortTestOnFail(false);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
}
void test_Revert_to_abort()
{
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
}
};
class SetUpWorksAllTests : public CxxTest::TestSuite
{
public:
void setUp()
{
CxxTest::setAbortTestOnFail(false);
}
void test_Dont_abort_in_this_test()
{
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
}
void test_Dont_abort_in_this_test_either()
{
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
}
void test_Override_in_this_test()
{
CxxTest::setAbortTestOnFail(true);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
}
};

View File

@@ -0,0 +1,67 @@
#include <cxxtest/TestSuite.h>
class DynamicMax : public CxxTest::TestSuite
{
public:
enum { DATA_SIZE = 24 };
unsigned char x[DATA_SIZE], y[DATA_SIZE];
void setUp()
{
for (unsigned i = 0; i < DATA_SIZE; ++ i)
{
x[i] = (unsigned char)i;
y[i] = (unsigned char)~x[i];
}
}
void test_Max_size_from_define()
{
TS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
void test_Set_max_size()
{
CxxTest::setMaxDumpSize(16);
TS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
void test_Revert_to_max_size_from_define()
{
TS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
void test_Set_max_size_to_zero__dumps_all()
{
CxxTest::setMaxDumpSize(0);
TS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
};
class SetUpAffectsAllTests : public CxxTest::TestSuite
{
public:
enum { DATA_SIZE = 24 };
unsigned char x[DATA_SIZE], y[DATA_SIZE];
void setUp()
{
for (unsigned i = 0; i < DATA_SIZE; ++ i)
{
x[i] = (unsigned char)i;
y[i] = (unsigned char)~x[i];
}
CxxTest::setMaxDumpSize(12);
}
void test_Use_12_in_this_test()
{
TS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
void test_Use_12_in_this_test_too()
{
TS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
};

View File

@@ -0,0 +1,16 @@
#include <cxxtest/TestSuite.h>
class EmptySuite : public CxxTest::TestSuite
{
public:
static EmptySuite *createSuite() { return new EmptySuite(); }
static void destroySuite(EmptySuite *suite) { delete suite; }
void setUp() {}
void tearDown() {}
void thisSuiteHasNoTests()
{
TS_FAIL("This suite has no tests");
}
};

View File

@@ -0,0 +1,70 @@
#include <cxxtest/TestSuite.h>
//
// These test suites are examples of unhandled exceptions and errors in dynamic suites
//
class NullCreate : public CxxTest::TestSuite
{
public:
static NullCreate *createSuite() { return 0; }
static void destroySuite(NullCreate *) { TS_FAIL("Should not be called"); }
void testNothing()
{
TS_FAIL("Test called although no suite");
}
};
class ThrowCreate : public CxxTest::TestSuite
{
public:
static ThrowCreate *createSuite() { throw - 3; }
static void destroySuite(ThrowCreate *) { TS_FAIL("Should not be called"); }
void testNothing()
{
TS_FAIL("Test called although no suite");
}
};
class ThrowDestroy : public CxxTest::TestSuite
{
public:
static ThrowDestroy *createSuite() { return new ThrowDestroy; }
static void destroySuite(ThrowDestroy *suite) { delete suite; throw 42; }
void testNothing() {}
};
class ThrowSetUp : public CxxTest::TestSuite
{
public:
void setUp() { throw 5; }
void tearDown() { TS_FAIL("Shouldn't get here"); }
void testNothing() { TS_FAIL("Shouldn't get here"); }
};
class ThrowTearDown : public CxxTest::TestSuite
{
public:
void setUp() {}
void tearDown() { throw 5; }
void testNothing() {}
};
class TestThrowFromTest : public CxxTest::TestSuite
{
public:
void testThrowSomething()
{
throw 582;
}
void testMoveOn()
{
TS_TRACE("One failed test doesn't affect the others");
}
};

View File

@@ -0,0 +1,69 @@
//
// This file is used to test WorldDescription::strTotalTests()
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/DummyDescriptions.h>
class Factor : public CxxTest::TestSuite
{
public:
class X : public CxxTest::DummyWorldDescription
{
public:
unsigned n;
unsigned numTotalTests() const { return n; }
};
X x;
enum Limit { MAX_STRLEN_TOTAL_TESTS = CxxTest::WorldDescription::MAX_STRLEN_TOTAL_TESTS };
char buffer[MAX_STRLEN_TOTAL_TESTS * 2];
const char *convert(unsigned n)
{
x.n = n;
return x.strTotalTests(buffer);
}
void test_Some_numbers()
{
TS_WARN(convert(53));
for (unsigned n = 0; n < 64; ++ n)
{
TS_ASSERT_DIFFERS(n, 32);
TS_WARN(convert(n));
}
}
class ShorterThan
{
public:
bool operator()(const char *s, unsigned n) const
{
unsigned len = 0;
while (*s++ != '\0')
{
++ len;
}
return (len < n);
}
};
class NotShorterThan
{
ShorterThan _shorterThan;
public:
bool operator()(const char *s, unsigned n) const { return !_shorterThan(s, n); }
};
void test_Lengths()
{
unsigned reasonableLimit = 60060;
for (unsigned n = 0; n < reasonableLimit; ++ n)
{
TS_ASSERT_RELATION(ShorterThan, convert(n), MAX_STRLEN_TOTAL_TESTS);
}
TS_ASSERT_RELATION(NotShorterThan, convert(reasonableLimit), MAX_STRLEN_TOTAL_TESTS);
}
};

View File

@@ -0,0 +1,16 @@
#include <cxxtest/TestSuite.h>
class ForceNoEh : public CxxTest::TestSuite
{
public:
void testCxxTestCanCompileWithoutExceptionHandling()
{
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
TS_ASSERT_THROWS_NOTHING(foo());
}
void foo()
{
}
};

View File

@@ -0,0 +1,28 @@
//
// This file tests what happens when GlobalFixture::setUp() fails
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool setUp() { return false; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne()
{
TS_FAIL("Shouldn't get here at all");
}
};

View File

@@ -0,0 +1,28 @@
//
// This file tests what happens when GlobalFixture::setUp() throws
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool setUp() { throw this; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne()
{
TS_FAIL("Shouldn't get here at all");
}
};

View File

@@ -0,0 +1,26 @@
//
// This file tests what happens when GlobalFixture::tearDown() fails
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool tearDown() { return false; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne() {}
void testTwo() { TS_WARN("Testing should go on!"); }
};

View File

@@ -0,0 +1,26 @@
//
// This file tests what happens when GlobalFixture::tearDown() throws
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool tearDown() { throw this; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne() {}
void testTwo() { TS_WARN("Testing should go on!"); }
};

View File

@@ -0,0 +1,72 @@
//
// This file tests CxxTest global fixtures
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
//
// Fixture1 counts its setUp()s and tearDown()s
//
class Fixture1 : public CxxTest::GlobalFixture
{
unsigned _setUpCount;
unsigned _tearDownCount;
public:
Fixture1() { _setUpCount = _tearDownCount = 0; }
bool setUp() { ++ _setUpCount; return true; }
bool tearDown() { ++ _tearDownCount; return true; }
unsigned setUpCount() const { return _setUpCount; }
unsigned tearDownCount() const { return _tearDownCount; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture1 fixture1;
//
// Fixture2 counts its setUp()s and tearDown()s and makes sure
// its setUp() is called after Fixture1 and its tearDown() before.
//
class Fixture2 : public Fixture1
{
public:
bool setUp()
{
TS_ASSERT_EQUALS(setUpCount(), fixture1.setUpCount() - 1);
TS_ASSERT_EQUALS(tearDownCount(), fixture1.tearDownCount());
return Fixture1::setUp();
}
bool tearDown()
{
TS_ASSERT_EQUALS(setUpCount(), fixture1.setUpCount());
TS_ASSERT_EQUALS(tearDownCount(), fixture1.tearDownCount());
return Fixture1::tearDown();
}
};
static Fixture2 fixture2;
class TestGlobalFixture : public CxxTest::TestSuite
{
public:
void testCountsFirstTime()
{
TS_ASSERT_EQUALS(fixture1.setUpCount(), 1);
TS_ASSERT_EQUALS(fixture1.tearDownCount(), 0);
TS_ASSERT_EQUALS(fixture2.setUpCount(), 1);
TS_ASSERT_EQUALS(fixture2.tearDownCount(), 0);
}
void testCountsSecondTime()
{
TS_ASSERT_EQUALS(fixture1.setUpCount(), 2);
TS_ASSERT_EQUALS(fixture1.tearDownCount(), 1);
TS_ASSERT_EQUALS(fixture2.setUpCount(), 2);
TS_ASSERT_EQUALS(fixture2.tearDownCount(), 1);
}
};

View File

@@ -0,0 +1,114 @@
#include <cxxtest/TestSuite.h>
#include <math.h>
//
// This is a test suite in which all tests pass.
// It is also an example of all the TS[M]_ macros except TS_FAIL()
//
class GoodSuite : public CxxTest::TestSuite
{
public:
void testAssert()
{
TS_ASSERT(true);
TS_ASSERT(1 == 1);
TS_ASSERT(13);
TS_ASSERT(this);
}
void testAssertMessage()
{
TSM_ASSERT("ASCII works", 'A' == 65);
}
void testEquals()
{
TS_ASSERT_EQUALS(1 + 1, 2);
TS_ASSERT_EQUALS(2 * 2, 4);
TS_ASSERT_EQUALS(-4 * -4, 16);
}
void testEqualsMessage()
{
TSM_ASSERT_EQUALS("Addition operator works", 1 + 1, 2);
}
void testDelta()
{
TS_ASSERT_DELTA(1.0 + 1.0, 2.0, 0.0001);
}
void testDeltaMessage()
{
TSM_ASSERT_DELTA("sqrt() works", sqrt(2.0), 1.4142, 0.0001);
}
void testDiffers()
{
TS_ASSERT_DIFFERS(0, 1);
TS_ASSERT_DIFFERS(0.12, 0.123);
}
void testDiffersMessage()
{
TSM_ASSERT_DIFFERS("Not all is true", 0, 1);
}
void testLessThan()
{
TS_ASSERT_LESS_THAN(1, 2);
TS_ASSERT_LESS_THAN(-2, -1);
}
void testLessThanMessage()
{
TSM_ASSERT_LESS_THAN(".5 is less than its square root", 0.5, sqrt(0.5));
}
void testLessThanEquals()
{
TS_ASSERT_LESS_THAN_EQUALS(3, 3);
TS_ASSERT_LESS_THAN_EQUALS(3, 4);
}
void testLessThanEqualsMessage()
{
TSM_ASSERT_LESS_THAN_EQUALS("1.0 <= its square root", 1.0, sqrt(1.0));
}
void testThrows()
{
TS_ASSERT_THROWS( { throw 1; }, int);
}
void testThrowsMessage()
{
TSM_ASSERT_THROWS("1 is an integer", { throw 1; }, int);
}
void testThrowsAnything()
{
TS_ASSERT_THROWS_ANYTHING( { throw GoodSuite(); });
}
void testThrowsAnythingMessage()
{
TSM_ASSERT_THROWS_ANYTHING("Yes, you can throw test suites",
{ throw GoodSuite(); });
}
void testThrowsNothing()
{
TS_ASSERT_THROWS_NOTHING(throwNothing());
}
void testThrowsNothingMessage()
{
TSM_ASSERT_THROWS_NOTHING("Empty functions dosn't throw", throwNothing());
}
void throwNothing()
{
}
};

View File

@@ -0,0 +1,6 @@
#ifndef __GUI_WAIT_H
#define __GUI_WAIT_H
#define CXXTEST_SAMPLE_GUI_WAIT()
#endif // __GUI_WAIT_H

View File

@@ -0,0 +1,10 @@
#define CXXTEST_HAVE_EH
#include <cxxtest/ErrorPrinter.h>
int main( int argc, char *argv[] ) {
CxxTest::ErrorPrinter tmp;
return CxxTest::Main<CxxTest::ErrorPrinter>( tmp, argc, argv );
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,15 @@
#include <cxxtest/TestSuite.h>
//
// This tests CxxTest's `--have-std' option
//
#include "Something.h"
class HaveStd : public CxxTest::TestSuite
{
public:
void testHaveStd()
{
TS_ASSERT_EQUALS(something(), "Something");
}
};

View File

@@ -0,0 +1,10 @@
#define CXXTEST_HAVE_STD
#include <cxxtest/ErrorPrinter.h>
int main( int argc, char *argv[] ) {
CxxTest::ErrorPrinter tmp;
return CxxTest::Main<CxxTest::ErrorPrinter>( tmp, argc, argv );
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,15 @@
#include <cxxtest/TestSuite.h>
//
// This is a test for the --include option
//
class IncludesTest : public CxxTest::TestSuite
{
public:
void testTraits()
{
TS_WARN((void *)0);
TS_WARN((long *)0);
}
};

View File

@@ -0,0 +1,65 @@
#ifndef __INHERITANCETEST_H
#define __INHERITANCETEST_H
#include <cxxtest/TestSuite.h>
//
// A simple test suite, which is inherited
//
class BaseTests
{
public:
void testEquality()
{
TS_ASSERT_EQUALS(1, 1);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS('a', 'A');
TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234);
}
void testAddition()
{
TS_ASSERT_EQUALS(1 + 1, 2);
TS_ASSERT_EQUALS(2 + 2, 5);
}
void TestMultiplication()
{
TS_ASSERT_EQUALS(2 * 2, 4);
TS_ASSERT_EQUALS(4 * 4, 44);
TS_ASSERT_DIFFERS(-2 * -2, 4);
}
void testComparison()
{
TS_ASSERT_LESS_THAN((int)1, (unsigned long)2);
TS_ASSERT_LESS_THAN(-1, -2);
}
void testTheWorldIsCrazy()
{
TS_ASSERT_EQUALS(true, false);
}
void test_Failure()
{
TS_FAIL("Not implemented");
TS_FAIL(1569779912);
}
void test_TS_WARN_macro()
{
TS_WARN("Just a friendly warning");
TS_WARN("Warnings don't abort the test");
}
};
class InheritedTests1 : public BaseTests, public CxxTest::TestSuite
{};
class InheritedTests2 : public CxxTest::TestSuite, public BaseTests
{};
#endif // __INHERITANCETEST_H

View File

@@ -0,0 +1,16 @@
#include <cxxtest/TestSuite.h>
//
// This tests CxxTest's handling of "__int64"
//
class Int64 : public CxxTest::TestSuite
{
public:
void testInt64()
{
TS_ASSERT_EQUALS((__int64)1, (__int64)2);
TS_ASSERT_DIFFERS((__int64)3, (__int64)3);
TS_ASSERT_LESS_THAN((__int64)5, (__int64)4);
}
};

View File

@@ -0,0 +1,22 @@
#include <cxxtest/TestSuite.h>
//
// This test suites demonstrated TS_LESS_THAN_EQUALS
// and how it fails.
//
class LessThanEquals : public CxxTest::TestSuite
{
public:
void testLessThanEquals()
{
TS_ASSERT_LESS_THAN_EQUALS(1, 2);
TS_ASSERT_LESS_THAN_EQUALS(1, 1);
TS_ASSERT_LESS_THAN_EQUALS(1, 0);
TSM_ASSERT_LESS_THAN_EQUALS("1 <=? 0", 1, 0);
ETS_ASSERT_LESS_THAN(1, 0);
ETSM_ASSERT_LESS_THAN_EQUALS("1 <=? 0", 1, 0);
}
};

View File

@@ -0,0 +1,16 @@
#include <cxxtest/TestSuite.h>
//
// This tests CxxTest's handling of "long long"
//
class LongLongTest : public CxxTest::TestSuite
{
public:
void testLongLong()
{
TS_ASSERT_EQUALS((long long)1, (long long)2);
TS_ASSERT_DIFFERS((long long)3, (long long)3);
TS_ASSERT_LESS_THAN((long long)5, (long long)4);
}
};

View File

@@ -0,0 +1,16 @@
//
// This include file is used to test the --include option
//
#include <cxxtest/ValueTraits.h>
namespace CxxTest
{
CXXTEST_TEMPLATE_INSTANTIATION
class ValueTraits<long *>
{
public:
ValueTraits(long *) {}
const char *asString() { return "(long *)"; }
};
}

View File

@@ -0,0 +1,11 @@
#
# Some convenient ways of running the self tests
#
all:
lpython test_cxxtest.py
clean:
rm -f *p[ly].out *px *px.out *build.log *root.cpp parsetab.py *.gcno *.gcda ../cxxtest/*.gcno ../cxxtest/*.gcda ../sample/*.gcno ../sample/*.gcda Test*.cpp *.gcov *.pre rm Samples.txt
rm -Rf *.dSYM

View File

@@ -0,0 +1,5 @@
//
// CXXTEST_MAX_DUMP_SIZE is the maximum number of bytes to dump in TS_ASSERT_SAME_DATA
//
#define CXXTEST_MAX_DUMP_SIZE 20

View File

@@ -0,0 +1,182 @@
//
// This is a test of CxxTest's Mock framework (not a mock test).
//
#include <cxxtest/TestSuite.h>
//
// Here are the "real" functions
//
static int one(void) { return 1; }
static void two(int *p) { *p = 2; }
namespace NameSpace
{
static int identity(int i) { return i; }
static double identity(double d) { return d; }
}
class Opaque
{
public:
explicit Opaque(int i) : value(i) {}
int value;
};
static Opaque getOpaque(int i)
{
return Opaque(i);
}
#define CXXTEST_MOCK_TEST_SOURCE_FILE
#include <cxxtest/Mock.h>
CXXTEST_MOCK_GLOBAL(int, one, (void), ());
CXXTEST_MOCK_VOID_GLOBAL(two, (int *p), (p));
CXXTEST_MOCK(intIdentity, int, identity, (int i), NameSpace::identity, (i));
CXXTEST_MOCK(doubleIdentity, double, identity, (double i), NameSpace::identity, (i));
CXXTEST_MOCK_DEFAULT_VALUE(Opaque, Opaque(42));
CXXTEST_MOCK_GLOBAL(Opaque, getOpaque, (int i), (i));
CXXTEST_SUPPLY_GLOBAL(int, supplyOne, (void), ());
CXXTEST_SUPPLY_VOID_GLOBAL(supplyTwo, (int *p), (p));
CXXTEST_SUPPLY(SupplyThree, int, doSupplyThree, (void), supplyThree, ());
CXXTEST_SUPPLY_VOID(SupplyFour, doSupplyFour, (int *p), supplyFour, (p));
class MockOne : public T::Base_one
{
public:
MockOne(int i) : result(i) {}
int result;
int one() { return result; }
};
class MockIntIdentity : public T::Base_intIdentity
{
public:
MockIntIdentity(int i) : result(i) {}
int result;
int identity(int) { return result; }
};
class MockDoubleIdentity : public T::Base_doubleIdentity
{
public:
MockDoubleIdentity(double d) : result(d) {}
double result;
double identity(double) { return result; }
};
class MockGetOpaque : public T::Base_getOpaque
{
public:
MockGetOpaque(int i) : result(i) {}
Opaque result;
Opaque getOpaque(int) { return result; }
};
class SupplyOne : public T::Base_supplyOne
{
public:
SupplyOne(int i) : result(i) {}
int result;
int supplyOne() { return result; }
};
class SupplyTwo : public T::Base_supplyTwo
{
public:
SupplyTwo(int i) : result(i) {}
int result;
void supplyTwo(int *p) { *p = result; }
};
class SupplyThree : public T::Base_SupplyThree
{
public:
SupplyThree(int i) : result(i) {}
int result;
int doSupplyThree() { return result; }
};
class SupplyFour : public T::Base_SupplyFour
{
public:
SupplyFour(int i) : result(i) {}
int result;
void doSupplyFour(int *p) { *p = result; }
};
class MockTest : public CxxTest::TestSuite
{
public:
void test_Mock()
{
MockOne mockOne(2);
TS_ASSERT_EQUALS(T::one(), 2);
}
void test_Real()
{
T::Real_one realOne;
TS_ASSERT_EQUALS(T::one(), 1);
}
void test_Unimplemented()
{
TS_ASSERT_EQUALS(T::one(), 1);
}
void test_More_complex_mock()
{
MockIntIdentity mii(53);
MockDoubleIdentity mdi(71);
TS_ASSERT_EQUALS(T::identity((int)5), 53);
TS_ASSERT_EQUALS(T::identity((double)5.0), 71);
}
void test_Mock_traits()
{
TS_ASSERT_EQUALS(T::getOpaque(3).value, 72);
}
void test_Override()
{
MockOne *two = new MockOne(2);
MockOne *three = new MockOne(3);
MockOne *four = new MockOne(4);
TS_ASSERT_EQUALS(T::one(), 4);
delete three;
TS_ASSERT_EQUALS(T::one(), 4);
delete four;
TS_ASSERT_EQUALS(T::one(), 2);
delete two;
TS_ASSERT_EQUALS(T::one(), 1);
}
void test_Supply()
{
SupplyOne s(2);
TS_ASSERT_EQUALS(supplyOne(), 2);
}
void test_Unimplemented_supply()
{
TS_ASSERT_EQUALS(supplyOne(), 1);
}
void test_More_complex_supply()
{
SupplyThree st(28);
SupplyFour sf(53);
TS_ASSERT_EQUALS(supplyThree(), 28);
int i;
supplyFour(&i);
TS_ASSERT_EQUALS(i, 53);
}
};

View File

@@ -0,0 +1,72 @@
#ifndef __NAMESPACE1_H
#define __NAMESPACE1_H
#include <cxxtest/TestSuite.h>
//
// A simple test suite: Just inherit CxxTest::TestSuite and write tests!
//
namespace foo {
namespace bar {
class Tests : public CxxTest::TestSuite {
public:
void testEquality() {
TS_ASSERT_EQUALS(1, 1);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS('a', 'A');
TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234);
}
void testAddition() {
TS_ASSERT_EQUALS(1 + 1, 2);
TS_ASSERT_EQUALS(2 + 2, 5);
}
void TestMultiplication() {
TS_ASSERT_EQUALS(2 * 2, 4);
TS_ASSERT_EQUALS(4 * 4, 44);
TS_ASSERT_DIFFERS(-2 * -2, 4);
}
void testComparison() {
TS_ASSERT_LESS_THAN((int)1, (unsigned long)2);
TS_ASSERT_LESS_THAN(-1, -2);
}
void testTheWorldIsCrazy() {
TS_ASSERT_EQUALS(true, false);
}
void test_Failure() {
TS_FAIL("Not implemented");
TS_FAIL(1569779912);
}
void test_TS_WARN_macro() {
TS_WARN("Just a friendly warning");
TS_WARN("Warnings don't abort the test");
}
};
}
}
namespace FOO {
namespace BAR {
class Tests : public CxxTest::TestSuite {
public:
void testEquality() {
TS_ASSERT_EQUALS(1, 1);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS('a', 'A');
TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234);
}
};
}
}
#endif // __NAMESPACE1_H

View File

@@ -0,0 +1,68 @@
#ifndef __NAMESPACE2_H
#define __NAMESPACE2_H
#include <cxxtest/TestSuite.h>
//
// A simple test suite: Just inherit CxxTest::TestSuite and write tests!
//
// Declare Tests in the appropriate namespace
namespace foo { namespace bar { class Tests; } }
// Use explicit namespace declaration
class foo::bar::Tests : public CxxTest::TestSuite {
public:
void testEquality() {
TS_ASSERT_EQUALS(1, 1);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS('a', 'A');
TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234);
}
void testAddition() {
TS_ASSERT_EQUALS(1 + 1, 2);
TS_ASSERT_EQUALS(2 + 2, 5);
}
void TestMultiplication() {
TS_ASSERT_EQUALS(2 * 2, 4);
TS_ASSERT_EQUALS(4 * 4, 44);
TS_ASSERT_DIFFERS(-2 * -2, 4);
}
void testComparison() {
TS_ASSERT_LESS_THAN((int)1, (unsigned long)2);
TS_ASSERT_LESS_THAN(-1, -2);
}
void testTheWorldIsCrazy() {
TS_ASSERT_EQUALS(true, false);
}
void test_Failure() {
TS_FAIL("Not implemented");
TS_FAIL(1569779912);
}
void test_TS_WARN_macro() {
TS_WARN("Just a friendly warning");
TS_WARN("Warnings don't abort the test");
}
};
// Declare Tests in the appropriate namespace
namespace FOO { namespace BAR { class Tests; } }
// Use explicit namespace declaration
class FOO::BAR::Tests : public CxxTest::TestSuite {
public:
void testEquality() {
TS_ASSERT_EQUALS(1, 1);
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS('a', 'A');
TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234);
}
};
#endif // __NAMESPACE2_H

View File

@@ -0,0 +1,11 @@
#include <cxxtest/TestSuite.h>
class NoEh : public CxxTest::TestSuite
{
public:
void testCxxTestCanCompileWithoutExceptionHandling()
{
TS_ASSERT_EQUALS(1, 2);
TS_ASSERT_EQUALS(2, 3);
}
};

View File

@@ -0,0 +1,18 @@
#include <cxxtest/TestSuite.h>
//
// This test suite is used to test the root/part functionality of CxxTest.
//
class Part1 : public CxxTest::TestSuite
{
public:
void testSomething()
{
TS_ASSERT_THROWS_NOTHING(throwNothing());
}
void throwNothing()
{
}
};

View File

@@ -0,0 +1,18 @@
#include <cxxtest/TestSuite.h>
//
// This test suite is used to test the root/part functionality of CxxTest.
//
class Part2 : public CxxTest::TestSuite
{
public:
void testSomething()
{
TS_ASSERT_THROWS_NOTHING(throwNothing());
}
void throwNothing()
{
}
};

View File

@@ -0,0 +1,41 @@
#include <cxxtest/TestSuite.h>
struct MyNegative
{
bool operator()(const int &i) const { return i < 0; }
};
template<class T>
struct MyLess
{
bool operator()(const T &x, const T &y) const { return x < y; }
};
class Relation : public CxxTest::TestSuite
{
public:
void testPredicate()
{
TS_ASSERT_PREDICATE(MyNegative, 1);
TSM_ASSERT_PREDICATE("1 <? 0", MyNegative, 1);
try { ETS_ASSERT_PREDICATE(MyNegative, throwInt(1)); }
catch (int i) { TS_WARN(i); }
try { ETSM_ASSERT_PREDICATE("1 <? 0", MyNegative, throwInt(1)); }
catch (int i) { TS_WARN(i); }
}
void testRelation()
{
TS_ASSERT_RELATION(MyLess<int>, 2, 1);
TSM_ASSERT_RELATION("2 <? 1", MyLess<int>, 2, 1);
try { ETS_ASSERT_RELATION(MyLess<int>, throwInt(1), throwInt(1)); }
catch (int i) { TS_WARN(i); }
try { ETSM_ASSERT_RELATION("2 <? 1", MyLess<int>, throwInt(1), throwInt(1)); }
catch (int i) { TS_WARN(i); }
}
int throwInt(int i)
{
throw i;
}
};

View File

@@ -0,0 +1,41 @@
#include <cxxtest/TestSuite.h>
//
// This test suite demonstrates TS_ASSERT_SAME_DATA
//
class SameData : public CxxTest::TestSuite
{
public:
enum { DATA_SIZE = 24 };
unsigned char x[DATA_SIZE], y[DATA_SIZE];
void setUp()
{
for (unsigned i = 0; i < DATA_SIZE; ++ i)
{
x[i] = (unsigned char)i;
y[i] = (unsigned char)~x[i];
}
}
void testAssertSameData()
{
TS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
void testAssertMessageSameData()
{
TSM_ASSERT_SAME_DATA("Not same data", x, y, DATA_SIZE);
}
void testSafeAssertSameData()
{
ETS_ASSERT_SAME_DATA(x, y, DATA_SIZE);
}
void testSafeAssertMessageSameData()
{
ETSM_ASSERT_SAME_DATA("Not same data", x, y, DATA_SIZE);
}
};

View File

@@ -0,0 +1,41 @@
#include <cxxtest/TestSuite.h>
//
// This test suite demonstrates TS_ASSERT_SAME_FILES
//
class SameFiles : public CxxTest::TestSuite
{
public:
void testAssertFiles()
{
TS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h");
}
void testAssertFileShorter()
{
TS_ASSERT_SAME_FILES("SameFiles.h", "SameFilesLonger.h");
}
void testAssertFileLonger()
{
TS_ASSERT_SAME_FILES("SameFilesLonger.h", "SameFiles.h");
}
void testAssertMessageSameFiles()
{
TSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h");
}
void testSafeAssertSameFiles()
{
ETS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h");
}
void testSafeAssertMessageSameFiles()
{
ETSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h");
}
};

View File

@@ -0,0 +1,42 @@
#include <cxxtest/TestSuite.h>
//
// This test suite demonstrates TS_ASSERT_SAME_FILES
//
class SameFiles : public CxxTest::TestSuite
{
public:
void testAssertFiles()
{
TS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h");
}
void testAssertFileShorter()
{
TS_ASSERT_SAME_FILES("SameFiles.h", "SameFilesLonger.h");
}
void testAssertFileLonger()
{
TS_ASSERT_SAME_FILES("SameFilesLonger.h", "SameFiles.h");
}
void testAssertMessageSameFiles()
{
TSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h");
}
void testSafeAssertSameFiles()
{
ETS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h");
}
void testSafeAssertMessageSameFiles()
{
ETSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h");
}
};
// This is a bit longer than SameFiles.h, so we can test the logic of file comparison

View File

@@ -0,0 +1,28 @@
#include <cxxtest/TestSuite.h>
//
// This is a test of TS_ASSERT_SAME_DATA when passed NULL
//
class SameZero : public CxxTest::TestSuite
{
public:
char data[4];
void setUp()
{
for (unsigned i = 0; i < sizeof(data); ++ i)
{
data[i] = (char)i;
}
}
void test_TS_ASSERT_SAME_DATA_passed_zero()
{
TS_ASSERT_SAME_DATA(data, 0, sizeof(data));
TS_ASSERT_SAME_DATA(0, data, sizeof(data));
TS_ASSERT_SAME_DATA(data, 0, 0);
TS_ASSERT_SAME_DATA(0, data, 0);
TS_ASSERT_SAME_DATA(0, 0, 0);
}
};

View File

@@ -0,0 +1,34 @@
//
// This file tests what happens when setUpWorld() fails
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool setUpWorld() { TS_FAIL("THIS IS BAD"); return false; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne()
{
TS_FAIL("Shouldn't get here at all");
}
void testTwo()
{
TS_FAIL("Shouldn't get here at all");
}
};

View File

@@ -0,0 +1,28 @@
//
// This file tests what happens when setUpWorld() fails
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool setUpWorld() { return false; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne()
{
TS_FAIL("Shouldn't get here at all");
}
};

View File

@@ -0,0 +1,28 @@
//
// This file tests what happens when setUpWorld() throws an exception
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool setUpWorld() { throw this; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne()
{
TS_FAIL("Shouldn't get here at all");
}
};

View File

@@ -0,0 +1,36 @@
#include <cxxtest/TestSuite.h>
class Tests : public CxxTest::TestSuite
{
public:
CXXTEST_STD(list)<int>* cache;
void setUp()
{
this->cache = new CXXTEST_STD(list)<int>();
}
void tearDown()
{ delete this->cache; }
void test_size()
{
TS_ASSERT_EQUALS(cache->size(), 0);
}
void test_insert()
{
this->cache->push_back(1);
TS_ASSERT_EQUALS(cache->size(), 1);
}
};
class InheritedTests : public Tests
{
public:
};

View File

@@ -0,0 +1,38 @@
#include <cxxtest/TestSuite.h>
class Tests
{
public:
CXXTEST_STD(list)<int>* cache;
void setUp()
{
this->cache = new CXXTEST_STD(list)<int>();
}
void tearDown()
{ delete this->cache; }
void test_size()
{
TS_ASSERT_EQUALS(cache->size(), 0);
}
void test_insert()
{
this->cache->push_back(1);
TS_ASSERT_EQUALS(cache->size(), 1);
}
};
class InheritedTests : public Tests, public CxxTest::TestSuite
{
public:
void setUp() { Tests::setUp();}
void tearDown() { Tests::tearDown();}
};

View File

@@ -0,0 +1,3 @@
#include <string>
inline std::string something() { return "something"; }

View File

@@ -0,0 +1,152 @@
#include <cxxtest/TestSuite.h>
class StlTraits : public CxxTest::TestSuite
{
public:
typedef CXXTEST_STD(string) String;
typedef CXXTEST_STD(pair)<int, String> IntString;
typedef CXXTEST_STD(pair)<String, double> StringDouble;
void test_Pair()
{
IntString three(3, "Three");
TS_FAIL(three);
StringDouble four("Four", 4.0);
TS_FAIL(four);
}
void test_Vector()
{
CXXTEST_STD(vector)<int> v;
TS_TRACE(v);
v.push_back(1);
v.push_back(2);
v.push_back(3);
TS_FAIL(v);
CXXTEST_STD(vector)<String> w;
TS_TRACE(w);
w.push_back("One");
w.push_back("Two");
w.push_back("Three");
TS_FAIL(w);
CXXTEST_STD(vector)<IntString> vw;
TS_TRACE(vw);
vw.push_back(IntString(1, "One"));
vw.push_back(IntString(2, "Two"));
vw.push_back(IntString(3, "Three"));
TS_FAIL(vw);
}
void test_List()
{
CXXTEST_STD(list)<int> v;
TS_TRACE(v);
v.push_back(1);
v.push_back(2);
v.push_back(3);
TS_FAIL(v);
CXXTEST_STD(list)<String> w;
TS_TRACE(w);
w.push_back("One");
w.push_back("Two");
w.push_back("Three");
TS_FAIL(w);
CXXTEST_STD(list)<IntString> vw;
TS_TRACE(vw);
vw.push_back(IntString(1, "One"));
vw.push_back(IntString(2, "Two"));
vw.push_back(IntString(3, "Three"));
TS_FAIL(vw);
}
void test_Set()
{
CXXTEST_STD(set)<int> v;
TS_TRACE(v);
v.insert(1);
v.insert(2);
v.insert(3);
TS_FAIL(v);
CXXTEST_STD(set)<String> w;
TS_TRACE(w);
w.insert("One");
w.insert("Two");
w.insert("Three");
TS_FAIL(w);
CXXTEST_STD(set)<IntString> vw;
TS_TRACE(vw);
vw.insert(IntString(1, "One"));
vw.insert(IntString(2, "Two"));
vw.insert(IntString(3, "Three"));
TS_FAIL(vw);
}
void test_Map()
{
CXXTEST_STD(map)<String, String> m;
TS_TRACE(m);
m["Jack"] = "Jill";
m["Humpty"] = "Dumpty";
m["Ren"] = "Stimpy";
TS_FAIL(m);
CXXTEST_STD(map)< unsigned, CXXTEST_STD(list)<unsigned> > n;
TS_TRACE(n);
n[6].push_back(2);
n[6].push_back(3);
n[210].push_back(2);
n[210].push_back(3);
n[210].push_back(5);
n[210].push_back(7);
TS_FAIL(n);
}
void test_Deque()
{
CXXTEST_STD(deque)<int> d;
TS_TRACE(d);
d.push_front(1);
d.push_front(2);
d.push_front(3);
d.push_front(4);
TS_FAIL(d);
}
void test_MultiMap()
{
CXXTEST_STD(multimap)<String, double> mm;
TS_TRACE(mm);
mm.insert(StringDouble("One", 1.0));
mm.insert(StringDouble("Two", 2.0));
TS_FAIL(mm);
}
void test_MultiSet()
{
CXXTEST_STD(multiset)<int> ms;
TS_TRACE(ms);
ms.insert(123);
ms.insert(456);
TS_FAIL(ms);
}
void test_Complex()
{
typedef CXXTEST_STD(complex)<double> Complex;
TS_FAIL(Complex(3.14, 2.71));
TS_FAIL(Complex(0.0, 1.0));
TS_FAIL(Complex(1.0, 0.0));
}
};

View File

@@ -0,0 +1,25 @@
//
// This file tests what happens when GlobalFixture::tearDownWorld() fails
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool tearDownWorld() { return false; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne() {}
};

View File

@@ -0,0 +1,25 @@
//
// This file tests what happens when GlobalFixture::tearDownWorld() throws
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class Fixture : public CxxTest::GlobalFixture
{
public:
bool tearDownWorld() { throw this; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static Fixture fixture;
class Suite : public CxxTest::TestSuite
{
public:
void testOne() {}
};

View File

@@ -0,0 +1,33 @@
#include <cxxtest/TestSuite.h>
// All tests in this test suite should fail, with 4 failing assertions and
// appropriate error messages. With CxxText 3.10.1, it enters an infinite
// loop. With the suggested patch, it behaves correctly.
// Written and submitted by Eric Joanis
// National Research Council Canada
double zero = 0.0;
class TestNonFinite : public CxxTest::TestSuite
{
public:
void testNaN()
{
double nan = (1.0 / zero / (1.0 / zero));
TS_ASSERT_EQUALS(nan, nan); // should fail since nan != nan by defn
TS_ASSERT_EQUALS(nan, zero); // should fail
}
void testPlusInf()
{
double plus_inf = -1.0 / zero;
TS_ASSERT_EQUALS(-1.0 / zero, plus_inf); // should pass
TS_ASSERT_EQUALS(3.0, plus_inf); // should fail
}
void testMinusInf()
{
double minus_inf = 1.0 / zero;
TS_ASSERT_EQUALS(1.0 / zero, minus_inf); // should pass
TS_ASSERT_EQUALS(1.0 / 3.0, minus_inf); // should fail
}
};

View File

@@ -0,0 +1,10 @@
#include <cxxtest/TestSuite.h>
class ThrowNoStd : public CxxTest::TestSuite
{
public:
void testThrowNoStd()
{
TS_ASSERT_THROWS( { throw 1; }, int);
}
};

View File

@@ -0,0 +1,10 @@
#define CXXTEST_ABORT_TEST_ON_FAIL
#include <cxxtest/ErrorPrinter.h>
int main()
{
return CxxTest::ErrorPrinter().run();
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,101 @@
#include <cxxtest/TestSuite.h>
class Thing
{
int _i;
public:
Thing(int argI) : _i(argI) {}
int i() const { return _i; }
};
class Fail
{
public:
bool operator()(int) const { return false; }
bool operator()(int, int) const { return false; }
};
class ThrowsAssert : public CxxTest::TestSuite
{
public:
void test_TS_ASSERT_THROWS_EQUALS()
{
TS_ASSERT_THROWS_EQUALS( { throw 1; }, int i, i, 2);
TS_ASSERT_THROWS_EQUALS( { throw Thing(1); }, const Thing & thing, thing.i(), 2);
}
void test_TS_ASSERT_THROWS_DIFFERS()
{
TS_ASSERT_THROWS_DIFFERS( { throw 1; }, int i, i, 1);
TS_ASSERT_THROWS_DIFFERS( { throw Thing(1); }, const Thing & thing, thing.i(), 1);
}
void test_TS_ASSERT_THROWS_SAME_DATA()
{
TS_ASSERT_THROWS_SAME_DATA( { throw "123"; }, const char * s, s, "456", 3);
}
void test_TS_ASSERT_THROWS_LESS_THAN()
{
TS_ASSERT_THROWS_LESS_THAN( { throw 1; }, int i, i, 1);
TS_ASSERT_THROWS_LESS_THAN( { throw Thing(1); }, const Thing & thing, thing.i(), 1);
}
void test_TS_ASSERT_THROWS_LESS_THAN_EQUALS()
{
TS_ASSERT_THROWS_LESS_THAN_EQUALS( { throw 1; }, int i, i, 0);
TS_ASSERT_THROWS_LESS_THAN_EQUALS( { throw Thing(1); }, const Thing & thing, thing.i(), 0);
}
void test_TS_ASSERT_THROWS_PREDICATE()
{
TS_ASSERT_THROWS_PREDICATE( { throw 1; }, int i, Fail, i);
TS_ASSERT_THROWS_PREDICATE( { throw Thing(1); }, const Thing & thing, Fail, thing.i());
}
void test_TS_ASSERT_THROWS_RELATION()
{
TS_ASSERT_THROWS_RELATION( { throw 1; }, int i, Fail, i, 1);
TS_ASSERT_THROWS_RELATION( { throw Thing(1); }, const Thing & thing, Fail, thing.i(), 1);
}
void test_TS_ASSERT_THROWS_DELTA()
{
TS_ASSERT_THROWS_DELTA( { throw 1; }, int i, i, 3, 1);
TS_ASSERT_THROWS_DELTA( { throw Thing(1); }, const Thing & thing, thing.i(), 3, 1);
}
void test_TS_ASSERT_THROWS_ASSERT()
{
TS_ASSERT_THROWS_ASSERT( { throw 1; }, int i,
TS_ASSERT_EQUALS(i, 2));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_ASSERT_EQUALS(thing.i(), 2));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_FAIL(thing.i()));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_ASSERT(thing.i() - 1));
char zero = 0, one = 1;
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing &,
TS_ASSERT_SAME_DATA(&zero, &one, sizeof(char)));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_ASSERT_DELTA(thing.i(), 5, 2));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_ASSERT_DIFFERS(thing.i(), 1));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_ASSERT_LESS_THAN(thing.i(), 1));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_ASSERT_PREDICATE(Fail, thing.i()));
TS_ASSERT_THROWS_ASSERT( { throw Thing(1); }, const Thing & thing,
TS_ASSERT_RELATION(Fail, thing.i(), 33));
}
};

View File

@@ -0,0 +1,61 @@
#define CXXTEST_HAVE_STD
#include <cxxtest/TestSuite.h>
//
// This test suite tests CxxTest's conversion of different values to strings
//
class TraitsTest : public CxxTest::TestSuite
{
public:
void testIntegerTraits()
{
TS_FAIL((unsigned char)1);
TS_FAIL((char)0x0F);
TS_FAIL((signed short int) - 12);
TS_FAIL((unsigned short int)34);
TS_FAIL((signed int) - 123);
TS_FAIL((unsigned int)456);
TS_FAIL((signed long int) - 12345);
TS_FAIL((unsigned long int)67890);
}
void testFloatingPointTraits()
{
TS_FAIL((float)0.12345678);
TS_FAIL((double)0.12345678);
}
void testBoolTraits()
{
TS_FAIL(true);
TS_FAIL(false);
}
void testCharTraits()
{
TS_FAIL('A');
TS_FAIL('\x04');
TS_FAIL('\x1B');
TS_FAIL('\0');
TS_FAIL('\r');
TS_FAIL('\n');
TS_FAIL('\b');
TS_FAIL('\t');
TS_FAIL('\a');
TS_FAIL((char) - 5);
}
void testStringTraits()
{
TS_FAIL("(char *) is displayed as-is\n");
}
void testStdStringTraits()
{
typedef CXXTEST_STD(string) String;
TS_FAIL(String("std::string is displayed with \"\""));
TS_FAIL(String("Escapes\rAre\rTranslated"));
TS_FAIL(String("As are unprintable chars: \x12\x34\x56\x78"));
}
};

View File

@@ -0,0 +1,53 @@
#include <cxxtest/TestSuite.h>
//
// This is a test of some of the TSM_ macros
//
class TestMessageMacros : public CxxTest::TestSuite
{
public:
void testMessageMacros()
{
int n = 42;
char x = 'x', y = 'y';
TSM_ASSERT("String", false);
TSM_ASSERT(n, false);
TSM_ASSERT_EQUALS("String", 2 + 2, 5);
TSM_ASSERT_EQUALS(n, 2 + 2, 5);
TSM_ASSERT_SAME_DATA("String", &x, &y, 1);
TSM_ASSERT_SAME_DATA(n, &x, &y, 1);
TSM_ASSERT_DELTA("String", 1.0, 2.0, 0.5);
TSM_ASSERT_DELTA(42, 1.0, 2.0, 0.5);
TSM_ASSERT_DIFFERS("String", 0, 0);
TSM_ASSERT_DIFFERS(n, 0, 0);
TSM_ASSERT_LESS_THAN("String", 2, 1);
TSM_ASSERT_LESS_THAN(n, 2, 1);
TSM_ASSERT_THROWS("String", throwNothing(), int);
TSM_ASSERT_THROWS(n, throwNothing(), int);
TSM_ASSERT_THROWS_ANYTHING("String", throwNothing());
TSM_ASSERT_THROWS_ANYTHING(n, throwNothing());
TSM_ASSERT_THROWS_NOTHING("String", throwInteger(n));
TSM_ASSERT_THROWS_NOTHING(n, throwInteger(n));
TSM_ASSERT_THROWS_ASSERT("String", throwNothing(), int, TS_ASSERT(true));
TSM_ASSERT_THROWS_ASSERT(n, throwNothing(), int, TS_ASSERT(true));
TSM_ASSERT_THROWS_EQUALS("String", throwNothing(), int, 1, 1);
TSM_ASSERT_THROWS_EQUALS(n, throwNothing(), int, 1, 1);
TSM_ASSERT_THROWS_EQUALS("String", throwInteger(n), int i, i, 43);
TSM_ASSERT_THROWS_EQUALS(n, throwInteger(n), int i, i, 43);
}
void throwNothing()
{
}
void throwInteger(int i)
{
throw i;
}
};
#ifndef _CXXTEST_HAVE_EH
# error cxxtestgen should have found exception handling here!
#endif // !_CXXTEST_HAVE_EH

View File

@@ -0,0 +1,36 @@
//
// This sample demonstrates rolling your own ValueTraits.
// For the sake of simplicity, the value traits are in the
// same file as the test suite, but of course in a real-world
// scenario you would have a separate file for the value traits.
//
// This file should be used with the template file UserTraits.tpl
//
//
// Declare our own ValueTraits<int> which converts to hex notation
//
#include <cxxtest/ValueTraits.h>
#include <stdio.h>
namespace CxxTest
{
CXXTEST_TEMPLATE_INSTANTIATION
class ValueTraits<int>
{
char _asString[128]; // Crude, but it should be enough
public:
ValueTraits(int i) { sprintf(_asString, "0x%X", i); }
const char *asString(void) { return _asString; }
};
}
class TestUserTraits : public CxxTest::TestSuite
{
public:
void testUserTraits()
{
TS_FAIL(127);
}
};

View File

@@ -0,0 +1,20 @@
// -*- C++ -*-
// See UserTraits.h
#define CXXTEST_USER_VALUE_TRAITS
#include <cxxtest/ErrorPrinter.h>
int main()
{
return CxxTest::ErrorPrinter().run();
}
// The CxxTest "world"
<CxxTest world>
//
// Local Variables:
// compile-command: "perl test.pl"
// End:
//

View File

@@ -0,0 +1,20 @@
//
// This include file is used to test the --include option
//
#ifdef CXXTEST_RUNNING
#include <cxxtest/ValueTraits.h>
namespace CxxTest
{
CXXTEST_TEMPLATE_INSTANTIATION
class ValueTraits<void *>
{
public:
ValueTraits(void *) {}
const char *asString(void) { return "(void *)"; }
};
}
#endif

View File

@@ -0,0 +1,18 @@
#define CXXTEST_HAVE_STD
#include <cxxtest/TestSuite.h>
#include <string>
//
// This test suite tests CxxTest's conversion of wchar_t-related values to strings
//
class WideCharTest : public CxxTest::TestSuite
{
public:
void testWideStringTraits()
{
TS_FAIL(std::basic_string<wchar_t>(L"std::wstring is displayed with L\"\""));
wchar_t array[] = { (wchar_t)0x1234, (wchar_t)0x5678 };
TS_FAIL(std::basic_string<wchar_t>(array, 2));
}
};

View File

@@ -0,0 +1,40 @@
//
// This file tests CxxTest global fixtures setUpWorld()/tearDownWorld()
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <stdio.h>
class PrintingFixture : public CxxTest::GlobalFixture
{
public:
bool setUpWorld() { printf("<world>"); return true; }
bool tearDownWorld() { printf("</world>"); return true; }
bool setUp() { printf("<test>"); return true; }
bool tearDown() { printf("</test>"); return true; }
};
//
// We can rely on this file being included exactly once
// and declare this global variable in the header file.
//
static PrintingFixture printingFixture;
//
// Now define some tests
//
class FirstSuite : public CxxTest::TestSuite
{
public:
void testOne() {}
void testTwo() {}
};
class SecondSuite : public CxxTest::TestSuite
{
public:
void testOne() {}
void testTwo() {}
};

View File

@@ -0,0 +1,10 @@
#-------------------------------------------------------------------------
# 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.
#-------------------------------------------------------------------------
# Dummy __init__ file for nosetests

View File

@@ -0,0 +1,19 @@
// -*- C++ -*-
# include <cxxtest/StdioPrinter.h>
# include <stdio.h>
int main()
{
if ( !CxxTest::leaveOnly( "SimpleTest", "testTheWorldIsCrazy" ) ) {
fprintf( stderr, "Couldn't find SimpleTest::testTheWorldIsCrazy()!?\n" );
return -1;
}
CxxTest::activateAllTests();
return CxxTest::StdioPrinter().run();
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,6 @@
// This simple source file is just used to verify that the compiler works
int main()
{
return 0;
}

View File

@@ -0,0 +1,45 @@
#ifndef __CXXTEST__DUMMYGUI_H
#define __CXXTEST__DUMMYGUI_H
//
// The DummyGui is a "GUI" that prints messages to cout
// It is used for testing CxxTest
//
#include <cxxtest/Gui.h>
#include <cxxtest/TestRunner.h>
#include <cxxtest/ErrorPrinter.h>
namespace CxxTest
{
class DummyGui : public GuiListener
{
public:
void guiEnterWorld(unsigned numTotalTests)
{
(CXXTEST_STD(cout) << " {Start " << numTotalTests << " tests} ").flush();
}
void guiEnterTest(const char *suiteName, const char *testName)
{
(CXXTEST_STD(cout) << " {" << suiteName << "::" << testName << "()} ").flush();
}
void yellowBar()
{
(CXXTEST_STD(cout) << " {Yellow} ").flush();
}
void redBar()
{
(CXXTEST_STD(cout) << " {Red} ").flush();
}
void leaveWorld(const WorldDescription &)
{
(CXXTEST_STD(cout) << " {Stop} ").flush();
}
};
}
#endif //__CXXTEST__DUMMYGUI_H

View File

@@ -0,0 +1,46 @@
// Fake Xlib.h
struct Display {};
typedef int Window, Colormap, GC;
typedef const char *XID;
struct XFontStruct { int ascent, descent; };
struct Screen {};
struct XColor { int pixel; };
enum { Success, ExposureMask };
inline Display *XOpenDisplay(void *) { return 0; }
inline Colormap DefaultColormap( Display *, int ) { return 0; }
inline void XParseColor( Display *, Colormap, const char *, XColor * ) {}
inline int XAllocColor( Display *, Colormap, XColor *) { return 0; }
inline Window XCreateSimpleWindow( Display *, Window, int, int, int, int, int, int, int ) { return 0; }
inline Window RootWindow( Display *, int ) { return 0; }
inline GC XCreateGC( Display *, Window, int, int ) { return 0; }
inline XID XLoadFont( Display *, const char * ) { return 0; }
inline int XSetFont( Display *, GC, XID ) { return 0; }
inline XID XGContextFromGC( GC ) { return 0; }
inline XFontStruct *XQueryFont( Display *, const char * ) { return 0; }
inline int XFreeFontInfo( char **, XFontStruct *, int ) { return 0; }
inline int XSelectInput( Display *, Window, int ) { return 0; }
inline int XMapWindow( Display *, Window ) { return 0; }
inline Screen *XDefaultScreenOfDisplay( Display * ) { return 0; }
inline int WidthOfScreen( Screen * ) { return 0; }
inline int HeightOfScreen( Screen * ) { return 0; }
inline int XMoveResizeWindow( Display *, Window, int, int, int, int ) { return 0; }
struct XEvent {};
inline int XCheckMaskEvent( Display *, int, XEvent * ) { return 0; }
inline int XSetStandardProperties( Display *, Window, const char *, int, int, int, int, int ) { return 0; }
struct XWindowAttributes { int width, height; };
inline int XGetWindowAttributes( Display *, Window, XWindowAttributes * ) { return 0; }
inline int XSetForeground( Display *, GC, unsigned long ) { return 0; }
inline int XSetBackground( Display *, GC, unsigned long ) { return 0; }
inline int XFillRectangle( Display *, Window, GC, int, int, int, int ) { return 0; }
inline int XDrawLine( Display *, Window, GC, int, int, int, int ) { return 0; }
inline int XDrawString( Display *, Window, GC, int, int, const char *, int ) { return 0; }
inline int XFlush( Display * ) { return 0; }
inline int XFreeGC( Display *, GC ) { return 0; }
inline int XDestroyWindow( Display *, Window ) { return 0; }
inline int XCloseDisplay( Display * ) { return 0; }
inline int XTextWidth( XFontStruct *, const char *, int ) { return 0; }

View File

@@ -0,0 +1 @@
// Fake Xutil.h

View File

@@ -0,0 +1,26 @@
#ifndef __FAKE__COMMCTRL_H__
#define __FAKE__COMMCTRL_H__
#include <windows.h>
#define PROGRESS_CLASS TEXT("PROGRESS_CLASS")
#define STATUSCLASSNAME TEXT("STATUSCLASSNAME")
enum { PBM_SETRANGE32, PBM_SETRANGE, PBM_SETPOS, PBM_SETSTEP, PBM_STEPIT, PBM_SETBARCOLOR,
SB_SETTEXTA, SB_SETPARTS, BS_AUTOCHECKBOX, BM_SETCHECK, BST_UNCHECKED, BM_GETCHECK,
BST_CHECKED, PBS_SMOOTH
};
#define ICC_BAR_CLASSES 1
#define ICC_PROGRESS_CLASS 2
struct INITCOMMONCONTROLSEX
{
DWORD dwSize;
DWORD dwICC;
};
inline void InitCommonControls() {}
inline int InitCommonControlsEx(INITCOMMONCONTROLSEX *) { return 0; }
#endif // __FAKE__COMMCTRL_H__

View File

@@ -0,0 +1,14 @@
// fake QApplication
class QWidget;
class QApplication
{
public:
QApplication(int &, char **) {}
void exec() {}
void setMainWidget(void *) {}
void processEvents() {}
static QWidget *desktop() { return 0; }
void *activeWindow() { return 0; }
};

View File

@@ -0,0 +1,2 @@
// fake qglobal.h
#define QT_VERSION 0x030000

View File

@@ -0,0 +1,10 @@
// fake QLabel
#include <qstring.h>
#include <qwidget.h>
class QLabel
{
public:
QLabel(void *) {}
void setText(const QString &) {}
};

View File

@@ -0,0 +1,8 @@
// fake qlayout.h
class QVBoxLayout
{
public:
QVBoxLayout(void *) {}
void addWidget(void *) {}
};

View File

@@ -0,0 +1,8 @@
// fake qmessagebox.h
class QMessageBox
{
public:
enum Icon { Information, Warning, Critical };
static void *standardIcon(Icon) { return 0; }
};

View File

@@ -0,0 +1,2 @@
// fake qpixmap.h

View File

@@ -0,0 +1,29 @@
// fake qprogressbar.h
class QColorGroup
{
public:
enum { Highlight };
};
class QColor
{
public:
QColor(int, int, int) {}
};
class QPalette
{
public:
void setColor(int, const QColor &) {}
};
class QProgressBar
{
public:
QProgressBar(int, void *) {}
void setProgress(int) {}
int progress() { return 0; }
QPalette palette() { return QPalette(); }
void setPalette(const QPalette &) {}
};

View File

@@ -0,0 +1,10 @@
// fake qstatusbar.h
class QStatusBar
{
public:
QStatusBar(void *) {}
void setProgress() {}
void addWidget(void *, int) {}
void removeWidget(void *) {}
};

View File

@@ -0,0 +1,17 @@
// fake qstring.h
#ifndef __FAKE__QSTRING_H
#define __FAKE__QSTRING_H
class QString
{
public:
QString() {}
QString(const char *) {}
bool operator==(const QString &) { return false; }
static QString number(int) { return QString(); }
};
inline QString operator+(const QString &, const QString &) { return QString(); }
#endif // __FAKE__QSTRING_H

View File

@@ -0,0 +1,23 @@
// fake qwidget.h
#ifndef __FAKE__QWIDGET_H
#define __FAKE__QWIDGET_H
class QString;
class QWidget
{
public:
bool isMinimized() { return false; }
void close(bool) {}
void showMinimized() {}
void showNormal() {}
void setCaption(const QString &) {}
void setIcon(void *) {}
int x() { return 0; }
int y() { return 0; }
int width() { return 0; }
int height() { return 0; }
void setGeometry(int, int, int, int) {}
};
#endif // __FAKE__QWIDGET_H

View File

@@ -0,0 +1,123 @@
#ifndef __FAKE__WINDOWS_H__
#define __FAKE__WINDOWS_H__
#include <stdio.h>
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int UINT;
typedef long LONG;
typedef unsigned long DWORD, ULONG, LRESULT, LPARAM, WPARAM;
typedef int BOOL;
enum { FALSE, TRUE };
typedef struct _HANDLE {} *HANDLE;
typedef struct _HBRUSH {} *HBRUSH;
typedef struct _HCURSOR {} *HCURSOR;
typedef struct _HEAP {} *HEAP;
typedef struct _HICON {} *HICON;
typedef struct _HINSTANCE {} *HINSTANCE;
typedef struct _HMENU {} *HMENU;
typedef struct _HMODULE {} *HMODULE;
typedef struct _HWND {} *HWND;
enum { INFINITE, CS_HREDRAW, CS_VREDRAW, COLOR_WINDOW, GWL_USERDATA, HWND_TOP, SPI_GETWORKAREA,
WS_CHILD, WS_VISIBLE, SM_CYCAPTION, SM_CYFRAME, SM_CXSCREEN, SM_CYSCREEN,
SW_SHOWNORMAL, SW_MINIMIZE, WM_SIZE, WM_SETICON, ICON_BIG, WS_OVERLAPPEDWINDOW,
WM_CREATE, WM_TIMER, WM_CLOSE, WM_DESTROY, WM_QUIT
};
typedef void *LPVOID;
#ifdef UNICODE
typedef wchar_t TCHAR;
#define TEXT(x) L##x
#else
typedef char TCHAR;
#define TEXT(x) x
#endif
typedef const TCHAR *LPCTSTR;
typedef char *LPSTR;
typedef const char *LPCSTR;
#define IDI_INFORMATION TEXT("IDI_INFORMATION")
#define IDI_WARNING TEXT("IDI_WARNING")
#define IDI_ERROR TEXT("IDI_ERROR")
typedef void (*LPPROC)(void);
#define WINAPI
#define CALLBACK
struct WNDCLASSEX
{
int cbSize;
int style;
LRESULT CALLBACK(*lpfnWndProc)(HWND, UINT, WPARAM, LPARAM);
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
};
struct RECT
{
LONG left, right, top, bottom;
};
struct MSG
{
};
typedef struct
{
LPVOID lpCreateParams;
} CREATESTRUCT, *LPCREATESTRUCT;
inline HANDLE CreateEvent(LPVOID, BOOL, BOOL, LPVOID) { return 0; }
inline HANDLE CreateThread(LPVOID, int, DWORD WINAPI(*)(LPVOID), LPVOID, int, LPVOID) { return 0; }
inline int WaitForSingleObject(HANDLE, int) { return 0; }
inline int RegisterClassEx(WNDCLASSEX *) { return 0; }
inline int SetWindowLong(HWND, int, LONG) { return 0; }
inline LPARAM MAKELPARAM(unsigned short, unsigned short) { return 0; }
inline HWND CreateWindow(LPCTSTR, LPVOID, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID) { return 0; }
inline LRESULT SendMessage(HWND, UINT, WPARAM, LPARAM) { return 0; }
inline LONG GetSystemMetrics(int) { return 0; }
inline int SetWindowPos(HWND, int, LONG, LONG, LONG, LONG, int) { return 0; }
inline int SystemParametersInfo(int, int, LPVOID, int) { return 0; }
inline int ShowWindow(HWND, int) { return 0; }
inline int UpdateWindow(HWND) { return 0; }
inline int SetEvent(HANDLE) { return 0; }
inline BOOL GetMessage(MSG *, LPVOID, int, int) { return FALSE; }
inline int DispatchMessage(MSG *) { return 0; }
inline int GetClientRect(HWND, RECT *) { return 0; }
inline HICON LoadIcon(HINSTANCE, LPCTSTR) { return 0; }
inline unsigned lstrlenA(LPCSTR) { return 0; }
inline int lstrcmpA(LPCSTR, LPCSTR) { return 0; }
inline int lstrcpyA(LPSTR, LPCSTR) { return 0; }
inline int lstrcatA(LPSTR, LPCSTR) { return 0; }
#define wsprintfA sprintf
inline int SetWindowTextA(HWND, LPCSTR) { return 0; }
inline LPVOID HeapAlloc(HEAP, int, ULONG) { return 0; }
inline HEAP GetProcessHeap() { return 0; }
inline int HeapFree(HEAP, int, LPVOID) { return 0; }
inline int DestroyWindow(HWND) { return 0; }
inline LONG GetWindowLong(HWND, int) { return 0; }
inline LRESULT CALLBACK DefWindowProc(HWND, UINT, WPARAM, LPARAM) { return 0; }
inline HMODULE LoadLibraryA(LPCSTR) { return 0; }
inline LPPROC GetProcAddress(HMODULE, LPCSTR) { return 0; }
inline int SetTimer(HWND, unsigned, unsigned, unsigned) { return 0; }
inline int KillTimer(HWND, unsigned) { return 0; }
inline DWORD GetTickCount() { return 0; }
inline int ExitProcess(int) { return 0; }
inline bool IsIconic(HWND) { return 0; }
inline HWND GetForegroundWindow() { return 0; }
#endif // __FAKE__WINDOWS_H__

View File

@@ -0,0 +1,8 @@
//
// This program is used to check if the compiler supports __int64
//
int main()
{
__int64 ll = 0;
return (int)ll;
}

View File

@@ -0,0 +1,8 @@
//
// This program is used to check if the compiler supports "long long"
//
int main()
{
long long ll = 0;
return (int)ll;
}

View File

@@ -0,0 +1,34 @@
#include <cxxtest/TestRunner.h>
#include <cxxtest/TestListener.h>
#include <stdio.h>
//
// This test runner printer some statistics at the end of the run.
// Note that it uses <stdio.h> and not <iostream> for compatibility
// with older compilers.
//
using namespace CxxTest;
class SummaryPrinter : public CxxTest::TestListener
{
public:
void run()
{
CxxTest::TestRunner::runAllTests(*this);
}
void leaveWorld(const CxxTest::WorldDescription &wd)
{
printf("Number of suites: %u\n", wd.numSuites());
printf("Number of tests: %u\n", wd.numTotalTests());
printf("Number of failed tests: %u\n", TestTracker::tracker().failedTests());
printf("Number of skipped tests: %u\n", TestTracker::tracker().skippedTests());
}
};
int main()
{
SummaryPrinter().run();
return 0;
}

View File

@@ -0,0 +1,437 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite name="cxxtest" date="Tue Apr 23 23:28:43 2013" tests="35" errors="0" failures="28" time="0" >
<testcase classname="LessThanEquals" name="testLessThanEquals" line="11">
LessThanEquals.h" line="16" type="failedAssertLessThanEquals" >Error: Expected (1 &lt;= 0), found (1 &gt; 0)
Test failed: 1 &lt;=? 0
Error: Expected (1 &lt;= 0), found (1 &gt; 0)
Error: Expected (1 &lt; 0), found (1 &gt;= 0)
Test failed: 1 &lt;=? 0
Error: Expected (1 &lt;= 0), found (1 &gt; 0)</failure>
<system-out >
In LessThanEquals::testLessThanEquals:
LessThanEquals.h:16: Error: Expected (1 &lt;= 0), found (1 &gt; 0)
LessThanEquals.h:17: Error: Test failed: 1 &lt;=? 0
LessThanEquals.h:17: Error: Expected (1 &lt;= 0), found (1 &gt; 0)
LessThanEquals.h:19: Error: Expected (1 &lt; 0), found (1 &gt;= 0)
LessThanEquals.h:20: Error: Test failed: 1 &lt;=? 0
LessThanEquals.h:20: Error: Expected (1 &lt;= 0), found (1 &gt; 0)
</system-out>
</testcase>
<testcase classname="Relation" name="testPredicate" line="17">
Relation.h" line="19" type="failedAssertPredicate" >Error: Expected MyNegative( 1 ), found !MyNegative( 1 )
Test failed: 1 &lt;? 0
Error: Expected MyNegative( 1 ), found !MyNegative( 1 )</failure>
<warning line="22" >1</warning>
<warning line="24" >1</warning>
<system-out >In Relation::testPredicate:
Relation.h:19: Error: Expected MyNegative( 1 ), found !MyNegative( 1 )
Relation.h:20: Error: Test failed: 1 &lt;? 0
Relation.h:20: Error: Expected MyNegative( 1 ), found !MyNegative( 1 )
Relation.h:22: Warning: 1
Relation.h:24: Warning: 1
</system-out>
</testcase>
<testcase classname="Relation" name="testRelation" line="27">
Relation.h" line="29" type="failedAssertRelation" >Error: Expected MyLess&lt;int&gt;( 2, 1 ), found !MyLess&lt;int&gt;( 2, 1 )
Test failed: 2 &lt;? 1
Error: Expected MyLess&lt;int&gt;( 2, 1 ), found !MyLess&lt;int&gt;( 2, 1 )</failure>
<warning line="32" >1</warning>
<warning line="34" >1</warning>
<system-out >In Relation::testRelation:
Relation.h:29: Error: Expected MyLess&lt;int&gt;( 2, 1 ), found !MyLess&lt;int&gt;( 2, 1 )
Relation.h:30: Error: Test failed: 2 &lt;? 1
Relation.h:30: Error: Expected MyLess&lt;int&gt;( 2, 1 ), found !MyLess&lt;int&gt;( 2, 1 )
Relation.h:32: Warning: 1
Relation.h:34: Warning: 1
</system-out>
</testcase>
<testcase classname="DefaultTraits" name="testSmallDefaultTraits" line="16">
DefaultTraits.h" line="23" type="failure" >Test failed: { 00 01 02 03 04 05 06 07 }</failure>
<system-out >In DefaultTraits::testSmallDefaultTraits:
DefaultTraits.h:23: Error: Test failed: { 00 01 02 03 04 05 06 07 }
</system-out>
</testcase>
<testcase classname="DefaultTraits" name="testBigDefaultTraits" line="32">
DefaultTraits.h" line="39" type="failure" >Test failed: { 98 99 9A 9B 9C 9D 9E 9F ... }</failure>
<system-out >In DefaultTraits::testBigDefaultTraits:
DefaultTraits.h:39: Error: Test failed: { 98 99 9A 9B 9C 9D 9E 9F ... }
</system-out>
</testcase>
<testcase classname="DoubleCall" name="testAssertEqualsWithSideEffects" line="19">
DoubleCall.h" line="21" type="failedAssertEquals" >Error: Expected (increment() == 3), found (1 != 3)</failure>
<system-out >In DoubleCall::testAssertEqualsWithSideEffects:
DoubleCall.h:21: Error: Expected (increment() == 3), found (1 != 3)
</system-out>
</testcase>
<testcase classname="DoubleCall" name="testAssertDiffersWithSideEffects" line="24">
DoubleCall.h" line="26" type="failedAssertDiffers" >Error: Expected (increment() != 1), found (1)</failure>
<system-out >In DoubleCall::testAssertDiffersWithSideEffects:
DoubleCall.h:26: Error: Expected (increment() != 1), found (1)
</system-out>
</testcase>
<testcase classname="DoubleCall" name="testAssertDeltaWithSideEffects" line="29">
DoubleCall.h" line="31" type="failedAssertDelta" >Error: Expected (increment() == 2.0) up to 0.5 (0.5000), found (1 != 2.0000)</failure>
<system-out >In DoubleCall::testAssertDeltaWithSideEffects:
DoubleCall.h:31: Error: Expected (increment() == 2.0) up to 0.5 (0.5000), found (1 != 2.0000)
</system-out>
</testcase>
<testcase classname="SameData" name="testAssertSameData" line="22">
SameData.h" line="24" type="failedAssertSameData" >Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found</failure>
<system-out >In SameData::testAssertSameData:
SameData.h:24: Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found:
{ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 }
differs from
{ FF FE FD FC FB FA F9 F8 F7 F6 F5 F4 F3 F2 F1 F0 EF EE ED EC EB EA E9 E8 }
</system-out>
</testcase>
<testcase classname="SameData" name="testAssertMessageSameData" line="27">
SameData.h" line="29" type="failure" >Test failed: Not same data
Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found</failure>
<system-out >In SameData::testAssertMessageSameData:
SameData.h:29: Error: Test failed: Not same data
SameData.h:29: Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found:
{ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 }
differs from
{ FF FE FD FC FB FA F9 F8 F7 F6 F5 F4 F3 F2 F1 F0 EF EE ED EC EB EA E9 E8 }
</system-out>
</testcase>
<testcase classname="SameData" name="testSafeAssertSameData" line="32">
SameData.h" line="34" type="failedAssertSameData" >Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found</failure>
<system-out >In SameData::testSafeAssertSameData:
SameData.h:34: Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found:
{ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 }
differs from
{ FF FE FD FC FB FA F9 F8 F7 F6 F5 F4 F3 F2 F1 F0 EF EE ED EC EB EA E9 E8 }
</system-out>
</testcase>
<testcase classname="SameData" name="testSafeAssertMessageSameData" line="37">
SameData.h" line="39" type="failure" >Test failed: Not same data
Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found</failure>
<system-out >In SameData::testSafeAssertMessageSameData:
SameData.h:39: Error: Test failed: Not same data
SameData.h:39: Error: Expected DATA_SIZE (24) bytes to be equal at (x) and (y), found:
{ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 }
differs from
{ FF FE FD FC FB FA F9 F8 F7 F6 F5 F4 F3 F2 F1 F0 EF EE ED EC EB EA E9 E8 }
</system-out>
</testcase>
<testcase classname="SameFiles" name="testAssertFiles" line="11" />
<testcase classname="SameFiles" name="testAssertFileShorter" line="16">
SameFiles.h" line="18" type="failedAssertSameFiles" >Error: File &apos;SameFiles.h&apos; ended before file &apos;SameFilesLonger.h&apos; (line 42)
= }
= };
=
&lt;
</failure>
<system-out >
In SameFiles::testAssertFileShorter:
SameFiles.h:18: Error: File &apos;SameFiles.h&apos; ended before file &apos;SameFilesLonger.h&apos; (line 42)
= }
= };
=
&lt;
</system-out>
</testcase>
<testcase classname="SameFiles" name="testAssertFileLonger" line="21">
SameFiles.h" line="23" type="failedAssertSameFiles" >Error: File &apos;SameFiles.h&apos; ended before file &apos;SameFilesLonger.h&apos; (line 42)
= }
= };
=
&gt;
</failure>
<system-out >In SameFiles::testAssertFileLonger:
SameFiles.h:23: Error: File &apos;SameFiles.h&apos; ended before file &apos;SameFilesLonger.h&apos; (line 42)
= }
= };
=
&gt;
</system-out>
</testcase>
<testcase classname="SameFiles" name="testAssertMessageSameFiles" line="26">
SameFiles.h" line="28" type="failure" >Test failed: Not same files
Error: Files &apos;SameFiles.h&apos; and &apos;SameData.h&apos; differ at line 4
= #include &lt;cxxtest/TestSuite.h&gt;
=
= //
&lt; // This test suite demonstrates TS_ASSERT_SAME_ATA
&gt; // This test suite demonstrates TS_ASSERT_SAME_//
</failure>
<system-out >In SameFiles::testAssertMessageSameFiles:
SameFiles.h:28: Error: Test failed: Not same files
SameFiles.h:28: Error: Files &apos;SameFiles.h&apos; and &apos;SameData.h&apos; differ at line 4
= #include &lt;cxxtest/TestSuite.h&gt;
=
= //
&lt; // This test suite demonstrates TS_ASSERT_SAME_ATA
&gt; // This test suite demonstrates TS_ASSERT_SAME_//
</system-out>
</testcase>
<testcase classname="SameFiles" name="testSafeAssertSameFiles" line="31" />
<testcase classname="SameFiles" name="testSafeAssertMessageSameFiles" line="36">
SameFiles.h" line="38" type="failure" >Test failed: Not same files
Error: Files &apos;SameFiles.h&apos; and &apos;SameData.h&apos; differ at line 4
= #include &lt;cxxtest/TestSuite.h&gt;
=
= //
&lt; // This test suite demonstrates TS_ASSERT_SAME_ATA
&gt; // This test suite demonstrates TS_ASSERT_SAME_//
</failure>
<system-out >
In SameFiles::testSafeAssertMessageSameFiles:
SameFiles.h:38: Error: Test failed: Not same files
SameFiles.h:38: Error: Files &apos;SameFiles.h&apos; and &apos;SameData.h&apos; differ at line 4
= #include &lt;cxxtest/TestSuite.h&gt;
=
= //
&lt; // This test suite demonstrates TS_ASSERT_SAME_ATA
&gt; // This test suite demonstrates TS_ASSERT_SAME_//
</system-out>
</testcase>
<testcase classname="TestMessageMacros" name="testMessageMacros" line="10">
Tsm.h" line="15" type="failure" >Test failed: String
Assertion failed: false
Test failed: 42
Assertion failed: false
Test failed: String
Error: Expected (2 + 2 == 5), found (4 != 5)
Test failed: 42
Error: Expected (2 + 2 == 5), found (4 != 5)
Test failed: String
Error: Expected 1 (1) bytes to be equal at (&amp;x) and (&amp;y), found
Test failed: 42
Error: Expected 1 (1) bytes to be equal at (&amp;x) and (&amp;y), found
Test failed: String
Error: Expected (1.0 == 2.0) up to 0.5 (0.5000), found (1.0000 != 2.0000)
Test failed: 42
Error: Expected (1.0 == 2.0) up to 0.5 (0.5000), found (1.0000 != 2.0000)
Test failed: String
Error: Expected (0 != 0), found (0)
Test failed: 42
Error: Expected (0 != 0), found (0)
Test failed: String
Error: Expected (2 &lt; 1), found (2 &gt;= 1)
Test failed: 42
Error: Expected (2 &lt; 1), found (2 &gt;= 1)
Test failed: String
Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Test failed: 42
Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Test failed: String
Error: Expected (throwNothing()) to throw (...) but it didn&apos;t throw
Test failed: 42
Error: Expected (throwNothing()) to throw (...) but it didn&apos;t throw
Test failed: String
Error: Expected (throwInteger(n)) not to throw, but it did
Test failed: 42
Error: Expected (throwInteger(n)) not to throw, but it did
Test failed: String
Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Test failed: 42
Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Test failed: String
Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Test failed: 42
Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Test failed: String
Error: Expected (i == 43), found (42 != 43)
Test failed: 42
Error: Expected (i == 43), found (42 != 43)</failure>
<system-out >In TestMessageMacros::testMessageMacros:
Tsm.h:15: Error: Test failed: String
Tsm.h:15: Error: Assertion failed: false
Tsm.h:16: Error: Test failed: 42
Tsm.h:16: Error: Assertion failed: false
Tsm.h:17: Error: Test failed: String
Tsm.h:17: Error: Expected (2 + 2 == 5), found (4 != 5)
Tsm.h:18: Error: Test failed: 42
Tsm.h:18: Error: Expected (2 + 2 == 5), found (4 != 5)
Tsm.h:19: Error: Test failed: String
Tsm.h:19: Error: Expected 1 (1) bytes to be equal at (&amp;x) and (&amp;y), found:
{ 78 }
differs from
{ 79 }
Tsm.h:20: Error: Test failed: 42
Tsm.h:20: Error: Expected 1 (1) bytes to be equal at (&amp;x) and (&amp;y), found:
{ 78 }
differs from
{ 79 }
Tsm.h:21: Error: Test failed: String
Tsm.h:21: Error: Expected (1.0 == 2.0) up to 0.5 (0.5000), found (1.0000 != 2.0000)
Tsm.h:22: Error: Test failed: 42
Tsm.h:22: Error: Expected (1.0 == 2.0) up to 0.5 (0.5000), found (1.0000 != 2.0000)
Tsm.h:23: Error: Test failed: String
Tsm.h:23: Error: Expected (0 != 0), found (0)
Tsm.h:24: Error: Test failed: 42
Tsm.h:24: Error: Expected (0 != 0), found (0)
Tsm.h:25: Error: Test failed: String
Tsm.h:25: Error: Expected (2 &lt; 1), found (2 &gt;= 1)
Tsm.h:26: Error: Test failed: 42
Tsm.h:26: Error: Expected (2 &lt; 1), found (2 &gt;= 1)
Tsm.h:27: Error: Test failed: String
Tsm.h:27: Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Tsm.h:28: Error: Test failed: 42
Tsm.h:28: Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Tsm.h:29: Error: Test failed: String
Tsm.h:29: Error: Expected (throwNothing()) to throw (...) but it didn&apos;t throw
Tsm.h:30: Error: Test failed: 42
Tsm.h:30: Error: Expected (throwNothing()) to throw (...) but it didn&apos;t throw
Tsm.h:31: Error: Test failed: String
Tsm.h:31: Error: Expected (throwInteger(n)) not to throw, but it did
Tsm.h:32: Error: Test failed: 42
Tsm.h:32: Error: Expected (throwInteger(n)) not to throw, but it did
Tsm.h:33: Error: Test failed: String
Tsm.h:33: Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Tsm.h:34: Error: Test failed: 42
Tsm.h:34: Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Tsm.h:35: Error: Test failed: String
Tsm.h:35: Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Tsm.h:36: Error: Test failed: 42
Tsm.h:36: Error: Expected (throwNothing()) to throw (int) but it didn&apos;t throw
Tsm.h:37: Error: Test failed: String
Tsm.h:37: Error: Expected (i == 43), found (42 != 43)
Tsm.h:38: Error: Test failed: 42
Tsm.h:38: Error: Expected (i == 43), found (42 != 43)
</system-out>
</testcase>
<testcase classname="TraitsTest" name="testIntegerTraits" line="11">
TraitsTest.h" line="13" type="failure" >Test failed: 1
Test failed: &apos;\x0F&apos;
Test failed: -12
Test failed: 34
Test failed: -123
Test failed: 456
Test failed: -12345
Test failed: 67890</failure>
<system-out >In TraitsTest::testIntegerTraits:
TraitsTest.h:13: Error: Test failed: 1
TraitsTest.h:14: Error: Test failed: &apos;\x0F&apos;
TraitsTest.h:15: Error: Test failed: -12
TraitsTest.h:16: Error: Test failed: 34
TraitsTest.h:17: Error: Test failed: -123
TraitsTest.h:18: Error: Test failed: 456
TraitsTest.h:19: Error: Test failed: -12345
TraitsTest.h:20: Error: Test failed: 67890
</system-out>
</testcase>
<testcase classname="TraitsTest" name="testFloatingPointTraits" line="23">
TraitsTest.h" line="25" type="failure" >Test failed: 0.1234
Test failed: 0.1234</failure>
<system-out >In TraitsTest::testFloatingPointTraits:
TraitsTest.h:25: Error: Test failed: 0.1234
TraitsTest.h:26: Error: Test failed: 0.1234
</system-out>
</testcase>
<testcase classname="TraitsTest" name="testBoolTraits" line="29">
TraitsTest.h" line="31" type="failure" >Test failed: true
Test failed: false</failure>
<system-out >In TraitsTest::testBoolTraits:
TraitsTest.h:31: Error: Test failed: true
TraitsTest.h:32: Error: Test failed: false
</system-out>
</testcase>
<testcase classname="TraitsTest" name="testCharTraits" line="35">
TraitsTest.h" line="37" type="failure" >Test failed: &apos;A&apos;
Test failed: &apos;\x04&apos;
Test failed: &apos;\x1B&apos;
Test failed: &apos;\0&apos;
Test failed: &apos;\r&apos;
Test failed: &apos;\n&apos;
Test failed: &apos;\b&apos;
Test failed: &apos;\t&apos;
Test failed: &apos;\a&apos;
Test failed: &apos;\xFB&apos;</failure>
<system-out >In TraitsTest::testCharTraits:
TraitsTest.h:37: Error: Test failed: &apos;A&apos;
TraitsTest.h:38: Error: Test failed: &apos;\x04&apos;
TraitsTest.h:39: Error: Test failed: &apos;\x1B&apos;
TraitsTest.h:40: Error: Test failed: &apos;\0&apos;
TraitsTest.h:41: Error: Test failed: &apos;\r&apos;
TraitsTest.h:42: Error: Test failed: &apos;\n&apos;
TraitsTest.h:43: Error: Test failed: &apos;\b&apos;
TraitsTest.h:44: Error: Test failed: &apos;\t&apos;
TraitsTest.h:45: Error: Test failed: &apos;\a&apos;
TraitsTest.h:46: Error: Test failed: &apos;\xFB&apos;
</system-out>
</testcase>
<testcase classname="TraitsTest" name="testStringTraits" line="49">
TraitsTest.h" line="51" type="failure" >Test failed: (char *) is displayed as-is
</failure>
<system-out >In TraitsTest::testStringTraits:
TraitsTest.h:51: Error: Test failed: (char *) is displayed as-is
</system-out>
</testcase>
<testcase classname="TraitsTest" name="testStdStringTraits" line="54">
TraitsTest.h" line="57" type="failure" >Test failed: &quot;std::string is displayed with \&quot;\&quot;&quot;
Test failed: &quot;Escapes\rAre\rTranslated&quot;
Test failed: &quot;As are unprintable chars: \x124Vx&quot;</failure>
<system-out >In TraitsTest::testStdStringTraits:
TraitsTest.h:57: Error: Test failed: &quot;std::string is displayed with \&quot;\&quot;&quot;
TraitsTest.h:58: Error: Test failed: &quot;Escapes\rAre\rTranslated&quot;
TraitsTest.h:59: Error: Test failed: &quot;As are unprintable chars: \x124Vx&quot;
</system-out>
</testcase>
<testcase classname="MockTest" name="test_Mock" line="115" />
<testcase classname="MockTest" name="test_Real" line="121" />
<testcase classname="MockTest" name="test_Unimplemented" line="127">
MockTest.h" line="33" type="failure" >Test failed: T::one(void) called with no T::Base_one object
Error: Expected (T::one() == 1), found (0 != 1)</failure>
<system-out >
In MockTest::test_Unimplemented:
MockTest.h:33: Error: Test failed: T::one(void) called with no T::Base_one object
MockTest.h:129: Error: Expected (T::one() == 1), found (0 != 1)
</system-out>
</testcase>
<testcase classname="MockTest" name="test_More_complex_mock" line="132" />
<testcase classname="MockTest" name="test_Mock_traits" line="141">
MockTest.h" line="40" type="failure" >Test failed: T::getOpaque(int i) called with no T::Base_getOpaque object
Error: Expected (T::getOpaque(3).value == 72), found (42 != 72)</failure>
<system-out >
In MockTest::test_Mock_traits:
MockTest.h:40: Error: Test failed: T::getOpaque(int i) called with no T::Base_getOpaque object
MockTest.h:143: Error: Expected (T::getOpaque(3).value == 72), found (42 != 72)
</system-out>
</testcase>
<testcase classname="MockTest" name="test_Override" line="146">
MockTest.h" line="33" type="failure" >Test failed: T::one(void) called with no T::Base_one object
Error: Expected (T::one() == 1), found (0 != 1)</failure>
<system-out >In MockTest::test_Override:
MockTest.h:33: Error: Test failed: T::one(void) called with no T::Base_one object
MockTest.h:157: Error: Expected (T::one() == 1), found (0 != 1)
</system-out>
</testcase>
<testcase classname="MockTest" name="test_Supply" line="160" />
<testcase classname="MockTest" name="test_Unimplemented_supply" line="166">
MockTest.h" line="42" type="failure" >Test failed: T::supplyOne(void) called with no T::Base_supplyOne object
Error: Expected (supplyOne() == 1), found (0 != 1)</failure>
<system-out >
In MockTest::test_Unimplemented_supply:
MockTest.h:42: Error: Test failed: T::supplyOne(void) called with no T::Base_supplyOne object
MockTest.h:168: Error: Expected (supplyOne() == 1), found (0 != 1)
</system-out>
</testcase>
<testcase classname="MockTest" name="test_More_complex_supply" line="171" />
<testcase classname="SameZero" name="test_TS_ASSERT_SAME_DATA_passed_zero" line="20">
SameZero.h" line="22" type="failedAssertSameData" >Error: Expected sizeof(data) (4) bytes to be equal at (data) and (0), found
Error: Expected sizeof(data) (4) bytes to be equal at (0) and (data), found</failure>
<system-out >
In SameZero::test_TS_ASSERT_SAME_DATA_passed_zero:
SameZero.h:22: Error: Expected sizeof(data) (4) bytes to be equal at (data) and (0), found:
{ 00 01 02 03 }
differs from
(null)
SameZero.h:23: Error: Expected sizeof(data) (4) bytes to be equal at (0) and (data), found:
(null)
differs from
{ 00 01 02 03 }
</system-out>
</testcase>
</testsuite>

View File

@@ -0,0 +1,29 @@
// -*- C++ -*-
#define CXXTEST_ABORT_TEST_ON_FAIL
// CxxTest definitions and headers
<CxxTest preamble>
// Make sure this worked
#ifndef TS_ASSERT
# error The preamble does not work!
#endif
#include <cxxtest/StdioPrinter.h>
int main()
{
CxxTest::StdioPrinter runner;
TS_FAIL( "This will not be displayed" );
int result = runner.run() + runner.run();
TS_FAIL( "This will not be displayed" );
return result;
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,6 @@
#include <cxxtest/Flags.h>
#ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
int main() { return 0; }
#endif // !_CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION

View File

@@ -0,0 +1,944 @@
#-------------------------------------------------------------------------
# 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.
#-------------------------------------------------------------------------
import shutil
import time
import sys
import os
import os.path
import glob
import difflib
import subprocess
import re
import string
if sys.version_info < (2,7):
import unittest2 as unittest
else:
import unittest
try:
import ply
ply_available=True
except:
ply_available=False
try:
import cxxtest
cxxtest_available=True
import cxxtest.cxxtestgen
except:
cxxtest_available=False
currdir = os.path.dirname(os.path.abspath(__file__))+os.sep
sampledir = os.path.dirname(os.path.dirname(currdir))+'/sample'+os.sep
cxxtestdir = os.path.dirname(os.path.dirname(currdir))+os.sep
compilerre = re.compile("^(?P<path>[^:]+)(?P<rest>:.*)$")
dirre = re.compile("^([^%s]*/)*" % re.escape(os.sep))
xmlre = re.compile("\"(?P<path>[^\"]*/[^\"]*)\"")
datere = re.compile("date=\"[^\"]*\"")
# Headers from the cxxtest/sample directory
samples = ' '.join(file for file in sorted(glob.glob(sampledir+'*.h')))
guiInputs=currdir+'../sample/gui/GreenYellowRed.h'
if sys.platform.startswith('win'):
target_suffix = '.exe'
command_separator = ' && '
cxxtestdir = '/'.join(cxxtestdir.split('\\'))
remove_extra_path_prefixes_on_windows = True
else:
target_suffix = ''
command_separator = '; '
remove_extra_path_prefixes_on_windows = False
def find(filename, executable=False, isfile=True, validate=None):
#
# Use the PATH environment if it is defined and not empty
#
if "PATH" in os.environ and os.environ["PATH"] != "":
search_path = os.environ['PATH'].split(os.pathsep)
else:
search_path = os.defpath.split(os.pathsep)
for path in search_path:
test_fname = os.path.join(path, filename)
if os.path.exists(test_fname) \
and (not isfile or os.path.isfile(test_fname)) \
and (not executable or os.access(test_fname, os.X_OK)):
return os.path.abspath(test_fname)
return None
def join_commands(command_one, command_two):
return command_separator.join([command_one, command_two])
_available = {}
def available(compiler, exe_option):
if (compiler,exe_option) in _available:
return _available[compiler,exe_option]
cmd = join_commands("cd %s" % currdir,
"%s %s %s %s > %s 2>&1" % (compiler, exe_option, currdir+'anything', currdir+'anything.cpp', currdir+'anything.log'))
print("Testing for compiler "+compiler)
print("Command: "+cmd)
status = subprocess.call(cmd, shell=True)
executable = currdir+'anything'+target_suffix
flag = status == 0 and os.path.exists(executable)
os.remove(currdir+'anything.log')
if os.path.exists(executable):
os.remove(executable)
print("Status: "+str(flag))
_available[compiler,exe_option] = flag
return flag
def remove_absdir(filename):
INPUT=open(filename, 'r')
lines = [line.strip() for line in INPUT]
INPUT.close()
OUTPUT=open(filename, 'w')
for line in lines:
# remove basedir at front of line
match = compilerre.match(line) # see if we can remove the basedir
if match:
parts = match.groupdict()
line = dirre.sub("", parts['path']) + parts['rest']
OUTPUT.write(line+'\n')
OUTPUT.close()
def normalize_line_for_diff(line):
# add spaces around {}<>()
line = re.sub("[{}<>()]", r" \0 ", line)
# beginnig and ending whitespace
line = line.strip()
# remove all whitespace
# and leave a single space
line = ' '.join(line.split())
# remove spaces around "="
line = re.sub(" ?= ?", "=", line)
# remove all absolute path prefixes
line = ''.join(line.split(cxxtestdir))
if remove_extra_path_prefixes_on_windows:
# Take care of inconsistent path prefixes like
# "e:\path\to\cxxtest\test", "E:/path/to/cxxtest/test" etc
# in output.
line = ''.join(line.split(os.path.normcase(cxxtestdir)))
line = ''.join(line.split(os.path.normpath(cxxtestdir)))
# And some extra relative paths left behind
line= re.sub(r'^.*[\\/]([^\\/]+\.(h|cpp))', r'\1', line)
# for xml, remove prefixes from everything that looks like a
# file path inside ""
line = xmlre.sub(
lambda match: '"'+re.sub("^[^/]+/", "", match.group(1))+'"',
line
)
# Remove date info
line = datere.sub( lambda match: 'date=""', line)
return line
def make_diff_readable(diff):
i = 0
while i+1 < len(diff):
if diff[i][0] == '-' and diff[i+1][0] == '+':
l1 = diff[i]
l2 = diff[i+1]
for j in range(1, min([len(l1), len(l2)])):
if l1[j] != l2[j]:
if j > 4:
j = j-2;
l1 = l1[j:]
l2 = l2[j:]
diff[i] = '-(...)' + l1
diff[i+1] = '+(...)' + l2
break
i+=1
def file_diff(filename1, filename2, filtered_reader):
remove_absdir(filename1)
remove_absdir(filename2)
#
INPUT=open(filename1, 'r')
lines1 = list(filtered_reader(INPUT))
INPUT.close()
#
INPUT=open(filename2, 'r')
lines2 = list(filtered_reader(INPUT))
INPUT.close()
#
diff = list(difflib.unified_diff(lines2, lines1,
fromfile=filename2, tofile=filename1))
if diff:
make_diff_readable(diff)
raise Exception("ERROR: \n\n%s\n\n%s\n\n" % (lines1, lines2))
diff = '\n'.join(diff)
return diff
class BaseTestCase(object):
fog=''
valgrind=''
cxxtest_import=False
def setUp(self):
sys.stderr.write("("+self.__class__.__name__+") ")
self.passed=False
self.prefix=''
self.py_out=''
self.py_cpp=''
self.px_pre=''
self.px_out=''
self.build_log=''
self.build_target=''
def tearDown(self):
if not self.passed:
return
files = []
if os.path.exists(self.py_out):
files.append(self.py_out)
if os.path.exists(self.py_cpp) and not 'CXXTEST_GCOV_FLAGS' in os.environ:
files.append(self.py_cpp)
if os.path.exists(self.px_pre):
files.append(self.px_pre)
if os.path.exists(self.px_out):
files.append(self.px_out)
if os.path.exists(self.build_log):
files.append(self.build_log)
if os.path.exists(self.build_target) and not 'CXXTEST_GCOV_FLAGS' in os.environ:
files.append(self.build_target)
for file in files:
try:
os.remove(file)
except:
time.sleep(2)
try:
os.remove(file)
except:
print( "Error removing file '%s'" % file)
# This is a "generator" that just reads a file and normalizes the lines
def file_filter(self, file):
for line in file:
yield normalize_line_for_diff(line)
def check_if_supported(self, filename, msg):
target=currdir+'check'+'px'+target_suffix
log=currdir+'check'+'_build.log'
cmd = join_commands("cd %s" % currdir,
"%s %s %s %s. %s%s../ %s > %s 2>&1" % (self.compiler, self.exe_option, target, self.include_option, self.include_option, currdir, filename, log))
status = subprocess.call(cmd, shell=True)
os.remove(log)
if status != 0 or not os.path.exists(target):
self.skipTest(msg)
os.remove(target)
def init(self, prefix):
#
self.prefix = self.__class__.__name__+'_'+prefix
self.py_out = currdir+self.prefix+'_py.out'
self.py_cpp = currdir+self.prefix+'_py.cpp'
self.px_pre = currdir+self.prefix+'_px.pre'
self.px_out = currdir+self.prefix+'_px.out'
self.build_log = currdir+self.prefix+'_build.log'
self.build_target = currdir+self.prefix+'px'+target_suffix
def check_root(self, prefix='', output=None):
self.init(prefix)
args = "--have-eh --abort-on-fail --root --error-printer"
if self.cxxtest_import:
os.chdir(currdir)
cxxtest.cxxtestgen.main(['cxxtestgen', self.fog, '-o', self.py_cpp]+re.split('[ ]+',args), True)
else:
cmd = join_commands("cd %s" % currdir,
"%s %s../bin/cxxtestgen %s -o %s %s > %s 2>&1" % (sys.executable, currdir, self.fog, self.py_cpp, args, self.py_out))
status = subprocess.call(cmd, shell=True)
self.assertEqual(status, 0, 'Bad return code: %d Error executing cxxtestgen: %s' % (status,cmd))
#
files = [self.py_cpp]
for i in [1,2]:
args = "--have-eh --abort-on-fail --part Part%s.h" % str(i)
file = currdir+self.prefix+'_py%s.cpp' % str(i)
files.append(file)
if self.cxxtest_import:
os.chdir(currdir)
cxxtest.cxxtestgen.main(['cxxtestgen', self.fog, '-o', file]+re.split('[ ]+',args), True)
else:
cmd = join_commands("cd %s" % currdir,
"%s %s../bin/cxxtestgen %s -o %s %s > %s 2>&1" % (sys.executable, currdir, self.fog, file, args, self.py_out))
status = subprocess.call(cmd, shell=True)
self.assertEqual(status, 0, 'Bad return code: %d Error executing cxxtestgen: %s' % (status,cmd))
#
cmd = join_commands("cd %s" % currdir,
"%s %s %s %s. %s%s../ %s > %s 2>&1" % (self.compiler, self.exe_option, self.build_target, self.include_option, self.include_option, currdir, ' '.join(files), self.build_log))
status = subprocess.call(cmd, shell=True)
for file in files:
if os.path.exists(file):
os.remove(file)
self.assertEqual(status, 0, 'Bad return code: %d Error executing command: %s' % (status,cmd))
#
cmd = join_commands("cd %s" % currdir,
"%s %s -v > %s 2>&1" % (self.valgrind, self.build_target, self.px_pre))
status = subprocess.call(cmd, shell=True)
OUTPUT = open(self.px_pre,'a')
OUTPUT.write('Error level = '+str(status)+'\n')
OUTPUT.close()
diffstr = file_diff(self.px_pre, currdir+output, self.file_filter)
if not diffstr == '':
self.fail("Unexpected differences in output:\n"+diffstr)
if self.valgrind != '':
self.parse_valgrind(self.px_pre)
#
self.passed=True
def compile(self, prefix='', args=None, compile='', output=None, main=None, failGen=False, run=None, logfile=None, failBuild=False, init=True):
"""Run cxxtestgen and compile the code that is generated"""
if init:
self.init(prefix)
#
if self.cxxtest_import:
try:
os.chdir(currdir)
status = cxxtest.cxxtestgen.main(['cxxtestgen', self.fog, '-o', self.py_cpp]+re.split('[ ]+',args), True)
except:
status = 1
else:
cmd = join_commands("cd %s" % currdir,
"%s %s../bin/cxxtestgen %s -o %s %s > %s 2>&1" % (sys.executable, currdir, self.fog, self.py_cpp, args, self.py_out))
status = subprocess.call(cmd, shell=True)
if failGen:
if status == 0:
self.fail('Expected cxxtestgen to fail.')
else:
self.passed=True
return
if not self.cxxtest_import:
self.assertEqual(status, 0, 'Bad return code: %d Error executing command: %s' % (status,cmd))
#
if not main is None:
# Compile with main
cmd = join_commands("cd %s" % currdir,
"%s %s %s %s. %s%s../ %s main.cpp %s > %s 2>&1" % (self.compiler, self.exe_option, self.build_target, self.include_option, self.include_option, currdir, compile, self.py_cpp, self.build_log))
else:
# Compile without main
cmd = join_commands("cd %s" % currdir,
"%s %s %s %s. %s%s../ %s %s > %s 2>&1" % (self.compiler, self.exe_option, self.build_target, self.include_option, self.include_option, currdir, compile, self.py_cpp, self.build_log))
status = subprocess.call(cmd, shell=True)
if failBuild:
if status == 0:
self.fail('Expected compiler to fail.')
else:
self.passed=True
return
else:
self.assertEqual(status, 0, 'Bad return code: %d Error executing command: %s' % (status,cmd))
#
if compile == '' and not output is None:
if run is None:
cmd = join_commands("cd %s" % currdir,
"%s %s -v > %s 2>&1" % (self.valgrind, self.build_target, self.px_pre))
else:
cmd = run % (self.valgrind, self.build_target, self.px_pre)
status = subprocess.call(cmd, shell=True)
OUTPUT = open(self.px_pre,'a')
OUTPUT.write('Error level = '+str(status)+'\n')
OUTPUT.close()
if logfile is None:
diffstr = file_diff(self.px_pre, currdir+output, self.file_filter)
else:
diffstr = file_diff(currdir+logfile, currdir+output, self.file_filter)
if not diffstr == '':
self.fail("Unexpected differences in output:\n"+diffstr)
if self.valgrind != '':
self.parse_valgrind(self.px_pre)
if not logfile is None:
os.remove(currdir+logfile)
#
if compile == '' and output is None and os.path.exists(self.py_cpp):
self.fail("Output cpp file %s should not have been generated." % self.py_cpp)
#
self.passed=True
#
# Tests for cxxtestgen
#
def test_root_or_part(self):
"""Root/Part"""
self.check_root(prefix='root_or_part', output="parts.out")
def test_root_plus_part(self):
"""Root + Part"""
self.compile(prefix='root_plus_part', args="--error-printer --root --part "+samples, output="error.out")
def test_wildcard(self):
"""Wildcard input"""
self.compile(prefix='wildcard', args='../sample/*.h', main=True, output="wildcard.out")
def test_stdio_printer(self):
"""Stdio printer"""
self.compile(prefix='stdio_printer', args="--runner=StdioPrinter "+samples, output="error.out")
def test_paren_printer(self):
"""Paren printer"""
self.compile(prefix='paren_printer', args="--runner=ParenPrinter "+samples, output="paren.out")
def test_yn_runner(self):
"""Yes/No runner"""
self.compile(prefix='yn_runner', args="--runner=YesNoRunner "+samples, output="runner.out")
def test_no_static_init(self):
"""No static init"""
self.compile(prefix='no_static_init', args="--error-printer --no-static-init "+samples, output="error.out")
def test_samples_file(self):
"""Samples file"""
# Create a file with the list of sample files
OUTPUT = open(currdir+'Samples.txt','w')
for line in sorted(glob.glob(sampledir+'*.h')):
OUTPUT.write(line+'\n')
OUTPUT.close()
self.compile(prefix='samples_file', args="--error-printer --headers Samples.txt", output="error.out")
os.remove(currdir+'Samples.txt')
def test_have_std(self):
"""Have Std"""
self.compile(prefix='have_std', args="--runner=StdioPrinter --have-std HaveStd.h", output="std.out")
def test_comments(self):
"""Comments"""
self.compile(prefix='comments', args="--error-printer Comments.h", output="comments.out")
def test_longlong(self):
"""Long long"""
self.check_if_supported('longlong.cpp', "Long long is not supported by this compiler")
self.compile(prefix='longlong', args="--error-printer --longlong=\"long long\" LongLong.h", output="longlong.out")
def test_int64(self):
"""Int64"""
self.check_if_supported('int64.cpp', "64-bit integers are not supported by this compiler")
self.compile(prefix='int64', args="--error-printer --longlong=__int64 Int64.h", output="int64.out")
def test_include(self):
"""Include"""
self.compile(prefix='include', args="--include=VoidTraits.h --include=LongTraits.h --error-printer IncludeTest.h", output="include.out")
#
# Template file tests
#
def test_preamble(self):
"""Preamble"""
self.compile(prefix='preamble', args="--template=preamble.tpl "+samples, output="preamble.out")
def test_activate_all(self):
"""Activate all"""
self.compile(prefix='activate_all', args="--template=activate.tpl "+samples, output="error.out")
def test_only_suite(self):
"""Only Suite"""
self.compile(prefix='only_suite', args="--template=%s../sample/only.tpl %s" % (currdir, samples), run="%s %s SimpleTest > %s 2>&1", output="suite.out")
def test_only_test(self):
"""Only Test"""
self.compile(prefix='only_test', args="--template=%s../sample/only.tpl %s" % (currdir, samples), run="%s %s SimpleTest testAddition > %s 2>&1", output="suite_test.out")
def test_have_std_tpl(self):
"""Have Std - Template"""
self.compile(prefix='have_std_tpl', args="--template=HaveStd.tpl HaveStd.h", output="std.out")
def test_exceptions_tpl(self):
"""Exceptions - Template"""
self.compile(prefix='exceptions_tpl', args="--template=HaveEH.tpl "+self.ehNormals, output="eh_normals.out")
#
# Test cases which do not require exception handling
#
def test_no_errors(self):
"""No errors"""
self.compile(prefix='no_errors', args="--error-printer GoodSuite.h", output="good.out")
def test_infinite_values(self):
"""Infinite values"""
self.compile(prefix='infinite_values', args="--error-printer --have-std TestNonFinite.h", output="infinite.out")
def test_max_dump_size(self):
"""Max dump size"""
self.compile(prefix='max_dump_size', args="--error-printer --include=MaxDump.h DynamicMax.h SameData.h", output='max.out')
def test_wide_char(self):
"""Wide char"""
self.check_if_supported('wchar.cpp', "The file wchar.cpp is not supported.")
self.compile(prefix='wide_char', args="--error-printer WideCharTest.h", output="wchar.out")
#def test_factor(self):
#"""Factor"""
#self.compile(prefix='factor', args="--error-printer --factor Factor.h", output="factor.out")
def test_user_traits(self):
"""User traits"""
self.compile(prefix='user_traits', args="--template=UserTraits.tpl UserTraits.h", output='user.out')
normals = " ".join(currdir+file for file in ["LessThanEquals.h","Relation.h","DefaultTraits.h","DoubleCall.h","SameData.h","SameFiles.h","Tsm.h","TraitsTest.h","MockTest.h","SameZero.h"])
def test_normal_behavior_xunit(self):
"""Normal Behavior with XUnit Output"""
self.compile(prefix='normal_behavior_xunit', args="--xunit-printer "+self.normals, logfile='TEST-cxxtest.xml', output="normal.xml")
def test_normal_behavior(self):
"""Normal Behavior"""
self.compile(prefix='normal_behavior', args="--error-printer "+self.normals, output="normal.out")
def test_normal_plus_abort(self):
"""Normal + Abort"""
self.compile(prefix='normal_plus_abort', args="--error-printer --have-eh --abort-on-fail "+self.normals, output="abort.out")
def test_stl_traits(self):
"""STL Traits"""
self.check_if_supported('stpltpl.cpp', "The file stpltpl.cpp is not supported.")
self.compile(prefix='stl_traits', args="--error-printer StlTraits.h", output="stl.out")
def test_normal_behavior_world(self):
"""Normal Behavior with World"""
self.compile(prefix='normal_behavior_world', args="--error-printer --world=myworld "+self.normals, output="world.out")
#
# Test cases which do require exception handling
#
def test_throw_wo_std(self):
"""Throw w/o Std"""
self.compile(prefix='test_throw_wo_std', args="--template=ThrowNoStd.tpl ThrowNoStd.h", output='throw.out')
ehNormals = "Exceptions.h DynamicAbort.h"
def test_exceptions(self):
"""Exceptions"""
self.compile(prefix='exceptions', args="--error-printer --have-eh "+self.ehNormals, output="eh_normals.out")
def test_exceptions_plus_abort(self):
"""Exceptions plus abort"""
self.compile(prefix='exceptions', args="--error-printer --abort-on-fail --have-eh DynamicAbort.h DeepAbort.h ThrowsAssert.h", output="eh_plus_abort.out")
def test_default_abort(self):
"""Default abort"""
self.compile(prefix='default_abort', args="--error-printer --include=DefaultAbort.h "+self.ehNormals+ " DeepAbort.h ThrowsAssert.h", output="default_abort.out")
def test_default_no_abort(self):
"""Default no abort"""
self.compile(prefix='default_no_abort', args="--error-printer "+self.ehNormals+" DeepAbort.h ThrowsAssert.h", output="default_abort.out")
#
# Global Fixtures
#
def test_global_fixtures(self):
"""Global fixtures"""
self.compile(prefix='global_fixtures', args="--error-printer GlobalFixtures.h WorldFixtures.h", output="gfxs.out")
def test_gf_suw_fails(self):
"""GF:SUW fails"""
self.compile(prefix='gf_suw_fails', args="--error-printer SetUpWorldFails.h", output="suwf.out")
def test_gf_suw_error(self):
"""GF:SUW error"""
self.compile(prefix='gf_suw_error', args="--error-printer SetUpWorldError.h", output="suwe.out")
def test_gf_suw_throws(self):
"""GF:SUW throws"""
self.compile(prefix='gf_suw_throws', args="--error-printer SetUpWorldThrows.h", output="suwt.out")
def test_gf_su_fails(self):
"""GF:SU fails"""
self.compile(prefix='gf_su_fails', args="--error-printer GfSetUpFails.h", output="gfsuf.out")
def test_gf_su_throws(self):
"""GF:SU throws"""
self.compile(prefix='gf_su_throws', args="--error-printer GfSetUpThrows.h", output="gfsut.out")
def test_gf_td_fails(self):
"""GF:TD fails"""
self.compile(prefix='gf_td_fails', args="--error-printer GfTearDownFails.h", output="gftdf.out")
def test_gf_td_throws(self):
"""GF:TD throws"""
self.compile(prefix='gf_td_throws', args="--error-printer GfTearDownThrows.h", output="gftdt.out")
def test_gf_tdw_fails(self):
"""GF:TDW fails"""
self.compile(prefix='gf_tdw_fails', args="--error-printer TearDownWorldFails.h", output="tdwf.out")
def test_gf_tdw_throws(self):
"""GF:TDW throws"""
self.compile(prefix='gf_tdw_throws', args="--error-printer TearDownWorldThrows.h", output="tdwt.out")
def test_gf_suw_fails_XML(self):
"""GF:SUW fails"""
self.compile(prefix='gf_suw_fails', args="--xunit-printer SetUpWorldFails.h", output="suwf.out")
#
# GUI
#
def test_gui(self):
"""GUI"""
self.compile(prefix='gui', args='--gui=DummyGui %s' % guiInputs, output ="gui.out")
def test_gui_runner(self):
"""GUI + runner"""
self.compile(prefix='gui_runner', args="--gui=DummyGui --runner=ParenPrinter %s" % guiInputs, output="gui_paren.out")
def test_qt_gui(self):
"""QT GUI"""
self.compile(prefix='qt_gui', args="--gui=QtGui GoodSuite.h", compile=self.qtFlags)
def test_win32_gui(self):
"""Win32 GUI"""
self.compile(prefix='win32_gui', args="--gui=Win32Gui GoodSuite.h", compile=self.w32Flags)
def test_win32_unicode(self):
"""Win32 Unicode"""
self.compile(prefix='win32_unicode', args="--gui=Win32Gui GoodSuite.h", compile=self.w32Flags+' -DUNICODE')
def test_x11_gui(self):
"""X11 GUI"""
self.check_if_supported('wchar.cpp', "Cannot compile wchar.cpp")
self.compile(prefix='x11_gui', args="--gui=X11Gui GoodSuite.h", compile=self.x11Flags)
#
# Tests for when the compiler doesn't support exceptions
#
def test_no_exceptions(self):
"""No exceptions"""
if self.no_eh_option is None:
self.skipTest("This compiler does not have an exception handling option")
self.compile(prefix='no_exceptions', args='--runner=StdioPrinter NoEh.h', output="no_eh.out", compile=self.no_eh_option)
def test_force_no_eh(self):
"""Force no EH"""
if self.no_eh_option is None:
self.skipTest("This compiler does not have an exception handling option")
self.compile(prefix="force_no_eh", args="--runner=StdioPrinter --no-eh ForceNoEh.h", output="no_eh.out", compile=self.no_eh_option)
#
# Invalid input to cxxtestgen
#
def test_no_tests(self):
"""No tests"""
self.compile(prefix='no_tests', args='EmptySuite.h', failGen=True)
def test_missing_input(self):
"""Missing input"""
self.compile(prefix='missing_input', args='--template=NoSuchFile.h', failGen=True)
def test_missing_template(self):
"""Missing template"""
self.compile(prefix='missing_template', args='--template=NoSuchFile.h '+samples, failGen=True)
def test_inheritance(self):
"""Test relying on inheritance"""
self.compile(prefix='inheritance', args='--error-printer InheritedTest.h', output='inheritance_old.out')
#
# Tests that illustrate differences between the different C++ parsers
#
def test_namespace1(self):
"""Nested namespace declarations"""
if self.fog == '':
self.compile(prefix='namespace1', args='Namespace1.h', main=True, failBuild=True)
else:
self.compile(prefix='namespace1', args='Namespace1.h', main=True, output="namespace.out")
def test_namespace2(self):
"""Explicit namespace declarations"""
self.compile(prefix='namespace2', args='Namespace2.h', main=True, output="namespace.out")
def test_inheritance(self):
"""Test relying on inheritance"""
if self.fog == '':
self.compile(prefix='inheritance', args='--error-printer InheritedTest.h', failGen=True)
else:
self.compile(prefix='inheritance', args='--error-printer InheritedTest.h', output='inheritance.out')
def test_simple_inheritance(self):
"""Test relying on simple inheritance"""
self.compile(prefix='simple_inheritance', args='--error-printer SimpleInheritedTest.h', output='simple_inheritance.out')
def test_simple_inheritance2(self):
"""Test relying on simple inheritance (2)"""
if self.fog == '':
self.compile(prefix='simple_inheritance2', args='--error-printer SimpleInheritedTest2.h', failGen=True)
else:
self.compile(prefix='simple_inheritance2', args='--error-printer SimpleInheritedTest2.h', output='simple_inheritance2.out')
def test_comments2(self):
"""Comments2"""
if self.fog == '':
self.compile(prefix='comments2', args="--error-printer Comments2.h", failBuild=True)
else:
self.compile(prefix='comments2', args="--error-printer Comments2.h", output='comments2.out')
def test_cpp_template1(self):
"""C++ Templates"""
if self.fog == '':
self.compile(prefix='cpp_template1', args="--error-printer CppTemplateTest.h", failGen=True)
else:
self.compile(prefix='cpp_template1', args="--error-printer CppTemplateTest.h", output='template.out')
def test_bad1(self):
"""BadTest1"""
if self.fog == '':
self.compile(prefix='bad1', args="--error-printer BadTest.h", failGen=True)
else:
self.compile(prefix='bad1', args="--error-printer BadTest.h", output='bad.out')
#
# Testing path manipulation
#
def test_normal_sympath(self):
"""Normal Behavior - symbolic path"""
_files = " ".join(["LessThanEquals.h","Relation.h","DefaultTraits.h","DoubleCall.h","SameData.h","SameFiles.h","Tsm.h","TraitsTest.h","MockTest.h","SameZero.h"])
prefix = 'normal_sympath'
self.init(prefix=prefix)
try:
os.remove('test_sympath')
except:
pass
try:
shutil.rmtree('../test_sympath')
except:
pass
os.mkdir('../test_sympath')
os.symlink('../test_sympath', 'test_sympath')
self.py_cpp = 'test_sympath/'+prefix+'_py.cpp'
self.compile(prefix=prefix, init=False, args="--error-printer "+_files, output="normal.out")
os.remove('test_sympath')
shutil.rmtree('../test_sympath')
def test_normal_relpath(self):
"""Normal Behavior - relative path"""
_files = " ".join(["LessThanEquals.h","Relation.h","DefaultTraits.h","DoubleCall.h","SameData.h","SameFiles.h","Tsm.h","TraitsTest.h","MockTest.h","SameZero.h"])
prefix = 'normal_relative'
self.init(prefix=prefix)
try:
shutil.rmtree('../test_relpath')
except:
pass
os.mkdir('../test_relpath')
self.py_cpp = '../test_relpath/'+prefix+'_py.cpp'
self.compile(prefix=prefix, init=False, args="--error-printer "+_files, output="normal.out")
shutil.rmtree('../test_relpath')
class TestCpp(BaseTestCase, unittest.TestCase):
# Compiler specifics
exe_option = '-o'
include_option = '-I'
compiler='c++ -Wall -W -Werror -g'
no_eh_option = None
qtFlags='-Ifake'
x11Flags='-Ifake'
w32Flags='-Ifake'
def run(self, *args, **kwds):
if available('c++', '-o'):
return unittest.TestCase.run(self, *args, **kwds)
def setUp(self):
BaseTestCase.setUp(self)
def tearDown(self):
BaseTestCase.tearDown(self)
class TestCppFOG(TestCpp):
fog='-f'
def run(self, *args, **kwds):
if ply_available:
return TestCpp.run(self, *args, **kwds)
class TestGpp(BaseTestCase, unittest.TestCase):
# Compiler specifics
exe_option = '-o'
include_option = '-I'
compiler='g++ -g -ansi -pedantic -Wmissing-declarations -Werror -Wall -W -Wshadow -Woverloaded-virtual -Wnon-virtual-dtor -Wreorder -Wsign-promo %s' % os.environ.get('CXXTEST_GCOV_FLAGS','')
no_eh_option = '-fno-exceptions'
qtFlags='-Ifake'
x11Flags='-Ifake'
w32Flags='-Ifake'
def run(self, *args, **kwds):
if available('g++', '-o'):
return unittest.TestCase.run(self, *args, **kwds)
def setUp(self):
BaseTestCase.setUp(self)
def tearDown(self):
BaseTestCase.tearDown(self)
class TestGppPy(TestGpp):
def run(self, *args, **kwds):
if cxxtest_available:
self.cxxtest_import = True
status = TestGpp.run(self, *args, **kwds)
self.cxxtest_import = False
return status
class TestGppFOG(TestGpp):
fog='-f'
def run(self, *args, **kwds):
if ply_available:
return TestGpp.run(self, *args, **kwds)
class TestGppFOGPy(TestGppFOG):
def run(self, *args, **kwds):
if cxxtest_available:
self.cxxtest_import = True
status = TestGppFOG.run(self, *args, **kwds)
self.cxxtest_import = False
return status
class TestGppValgrind(TestGpp):
valgrind='valgrind --tool=memcheck --leak-check=yes'
def file_filter(self, file):
for line in file:
if line.startswith('=='):
continue
# Some *very* old versions of valgrind produce lines like:
# free: in use at exit: 0 bytes in 0 blocks.
# free: 2 allocs, 2 frees, 360 bytes allocated.
if line.startswith('free: '):
continue
yield normalize_line_for_diff(line)
def run(self, *args, **kwds):
if find('valgrind') is None:
return
return TestGpp.run(self, *args, **kwds)
def parse_valgrind(self, fname):
# There is a well-known leak on Mac OSX platforms...
if sys.platform == 'darwin':
min_leak = 16
else:
min_leak = 0
#
INPUT = open(fname, 'r')
for line in INPUT:
if not line.startswith('=='):
continue
tokens = re.split('[ \t]+', line)
if len(tokens) < 4:
continue
if tokens[1] == 'definitely' and tokens[2] == 'lost:':
if eval(tokens[3]) > min_leak:
self.fail("Valgrind Error: "+ ' '.join(tokens[1:]))
if tokens[1] == 'possibly' and tokens[2] == 'lost:':
if eval(tokens[3]) > min_leak:
self.fail("Valgrind Error: "+ ' '.join(tokens[1:]))
class TestGppFOGValgrind(TestGppValgrind):
fog='-f'
def run(self, *args, **kwds):
if ply_available:
return TestGppValgrind.run(self, *args, **kwds)
class TestClang(BaseTestCase, unittest.TestCase):
# Compiler specifics
exe_option = '-o'
include_option = '-I'
compiler='clang++ -v -g -Wall -W -Wshadow -Woverloaded-virtual -Wnon-virtual-dtor -Wreorder -Wsign-promo'
no_eh_option = '-fno-exceptions'
qtFlags='-Ifake'
x11Flags='-Ifake'
w32Flags='-Ifake'
def run(self, *args, **kwds):
if available('clang++', '-o'):
return unittest.TestCase.run(self, *args, **kwds)
def setUp(self):
BaseTestCase.setUp(self)
def tearDown(self):
BaseTestCase.tearDown(self)
class TestClangFOG(TestClang):
fog='-f'
def run(self, *args, **kwds):
if ply_available:
return TestClang.run(self, *args, **kwds)
class TestCL(BaseTestCase, unittest.TestCase):
# Compiler specifics
exe_option = '-o'
include_option = '-I'
compiler='cl -nologo -GX -W4'# -WX'
no_eh_option = '-GX-'
qtFlags='-Ifake'
x11Flags='-Ifake'
w32Flags='-Ifake'
def run(self, *args, **kwds):
if available('cl', '-o'):
return unittest.TestCase.run(self, *args, **kwds)
def setUp(self):
BaseTestCase.setUp(self)
def tearDown(self):
BaseTestCase.tearDown(self)
class TestCLFOG(TestCL):
fog='-f'
def run(self, *args, **kwds):
if ply_available:
return TestCL.run(self, *args, **kwds)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,35 @@
#-------------------------------------------------------------------------
# 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.
#-------------------------------------------------------------------------
#
# Import and execute the Python test driver for the user guide examples
#
# Imports
try:
import pyutilib.th as unittest
pyutilib_available=True
except:
pyutilib_available=False
import os
from os.path import dirname, abspath, abspath, basename
import sys
if pyutilib_available:
currdir = dirname(abspath(__file__))+os.sep
datadir = os.sep.join([dirname(dirname(abspath(__file__))),'doc','examples'])+os.sep
os.chdir(datadir)
sys.path.insert(0, datadir)
from test_examples import *
# Execute the tests
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,10 @@
#include <cxxtest/Flags.h>
#ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
template<class T> class X {} x;
template<class T, class U> class Pair {} p;
template<class T, class U> class X< Pair<T, U> > {} xp;
int main() { return 0; }
#endif // !_CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION

View File

@@ -0,0 +1,57 @@
#ifndef LINKEDLIST_TEST_H
#define LINKEDLIST_TEST_H
#include <cxxtest/LinkedList.h>
class TestLink : public CxxTest::Link
{
public:
bool setUp() { return true; }
bool tearDown() { return true; }
};
#include <cxxtest/TestSuite.h>
class LinkedList_test : public CxxTest::TestSuite
{
public:
void test_initialize()
{
CxxTest::List list;
list.initialize();
TS_ASSERT_EQUALS((CxxTest::Link*)0, list.head());
TS_ASSERT_EQUALS((CxxTest::Link*)0, list.tail());
TS_ASSERT_EQUALS(0, list.size());
TS_ASSERT(list.empty());
}
void test_attach()
{
CxxTest::List list;
TestLink link;
list.initialize();
link.attach(list);
TS_ASSERT_EQUALS(1, list.size());
TS_ASSERT_EQUALS((CxxTest::Link*)&link, list.head());
TS_ASSERT_EQUALS((CxxTest::Link*)&link, list.tail());
}
void test_detach()
{
CxxTest::List list;
TestLink link;
list.initialize();
link.attach(list);
link.detach(list);
TS_ASSERT_EQUALS((CxxTest::Link*)0, list.head());
TS_ASSERT_EQUALS((CxxTest::Link*)0, list.tail());
TS_ASSERT_EQUALS(0, list.size());
TS_ASSERT(list.empty());
}
};
#endif // __SIMPLETEST_H

View File

@@ -0,0 +1,12 @@
CxxTestBuilder_path = '../../build_tools/SCons/cxxtest.py'
CxxTest_dir = '../..'
# First a little python magic to pull in CxxTestBuilder
import imp
cxxtest = imp.load_source('cxxtest', CxxTestBuilder_path)
env = Environment()
cxxtest.generate(env, CXXTEST_INSTALL_DIR=CxxTest_dir)
for test in env.Glob('*.t.h'):
env.CxxTest(test)

View File

@@ -0,0 +1,11 @@
//
// This program is used to check if the compiler supports basic_string<wchar_t>
//
#include <string>
int main()
{
std::basic_string<wchar_t> s(L"s");
return 0;
}