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,193 @@
// Assertions.h
#include <cxxtest/TestSuite.h>
class Test : public CxxTest::TestSuite
{
public:
// @assert:
void test_assert(void)
{
TS_ASSERT(1 + 1 > 1);
}
// @:assert
// @assertDelta:
void test_assert_delta(void)
{
TS_ASSERT_DELTA(sqrt(4.0), 2.0, 1e-7);
}
// @:assertDelta
// @assertDiffers:
void test_assert_differs(void)
{
TS_ASSERT_DIFFERS(1, 2);
}
// @:assertDiffers
// @assertEquals:
void test_assert_equals(void)
{
TS_ASSERT_EQUALS(21 % 5, 1);
}
// @:assertEquals
// @assertIsNan:
void test_assert_is_nan(void)
{
TS_ASSERT_IS_NAN( 0.0/0.0 );
}
// @:assertIsNan
// @assertIsInfinite:
void test_assert_is_infinite(void)
{
TS_ASSERT_IS_INFINITE( 1.0/0.0 );
}
// @:assertIsInfinite
// @assertLessThan:
void test_assert_less_than(void)
{
TS_ASSERT_LESS_THAN(0, 1);
}
// @:assertLessThan
// @assertLessThanEquals:
void test_assert_less_than_equals(void)
{
TS_ASSERT_LESS_THAN_EQUALS(0, 0);
}
// @:assertLessThanEquals
// @assertPredicate:
class IsOdd
{
public:
bool operator()(int x) const { return x % 2 == 1; }
};
void test_assert_predicate(void)
{
TS_ASSERT_PREDICATE(IsOdd, 29);
}
// @:assertPredicate
// @assertRelation:
void test_assert_relation(void)
{
TS_ASSERT_RELATION(std::greater<double>, 1e6, 1000.0);
}
// @:assertRelation
// @assertSameData:
void test_assert_same_data(void)
{
char input = "The quick brown fox ran over the lazy dog";
char output[26];
memcopy(output, input, 26);
TS_ASSERT_SAME_DATA(input, output, 26);
}
// @:assertSameData
// @assertThrows:
void throws_runtime_error(void)
{
raise std::runtime_error, "This method simply generates an exception";
}
void test_assert_throws(void)
{
TS_ASSERT_THROWS(self.throws_runtime_error(), std::runtime_error);
}
// @:assertThrows
// @assertThrowsAnything:
void test_assert_throws_anything(void)
{
TS_ASSERT_THROWS_ANYTHING(self.throws_runtime_error());
}
// @:assertThrowsAnything
// @assertThrowsAssert:
void throws_value(void)
{
raise 1;
}
void test_assert_throws_assert(void)
{
TS_ASSERT_THROWS_ASSERT(self.throws_value(), const Error & e, TS_ASSERT_EQUALS(e, 1));
}
// @:assertThrowsAssert
// @assertThrowsEquals:
void test_assert_throws_equals(void)
{
TS_ASSERT_THROWS_EQUALS(self.throws_value(), const Error & e, e.what(), 1);
}
// @:assertThrowsEquals
// @assertThrowsIsNan:
void throws_nan(void)
{
raise 0.0/0.0;
}
void test_assert_throws_is_nan(void)
{
TS_ASSERT_THROWS_IS_NAN(self.throws_nan(), const Error & e, e.what());
}
// @:assertThrowsIsNan
// @assertThrowsIsInfinite:
void throws_infinite(void)
{
raise 1.0/0.0;
}
void test_assert_throws_is_infinite(void)
{
TS_ASSERT_THROWS_IS_INFINITE(self.throws_infinite(), const Error & e, e.what());
}
// @:assertThrowsIsInfinite
// @assertThrowsNothing:
void throws_nothing(void)
{ }
void test_assert_throws_nothing(void)
{
TS_ASSERT_THROWS_ASSERT(self.throws_nothing());
}
// @:assertThrowsNothing
// @fail:
void test_fail(void)
{
TS_FAIL("This test has failed.");
}
// @:fail
// @skip:
void test_skip(void)
{
TS_SKIP("This test has been skipped.");
}
// @:skip
// @trace:
void test_trace(void)
{
TS_TRACE("This is a test tracing message.");
}
// @:trace
// @warn:
void test_warn(void)
{
TS_WARN("This is a warning message.");
}
// @:warn
};

View File

@@ -0,0 +1,19 @@
// BadTestSuite1.h
#include <cxxtest/TestSuite.h>
class BadTestSuite1 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
#if 0
void testSubtraction(void)
{
TS_ASSERT(1 - 1 < 1);
TS_ASSERT_EQUALS(1 - 1, 0);
}
#endif
};

View File

@@ -0,0 +1,4 @@
if [[ "x$CXXTEST" -eq "x" ]]
then
CXXTEST="../../"
fi

View File

@@ -0,0 +1,26 @@
// MockTestSuite.h
#include <cxxtest/TestSuite.h>
#include <time_mock.h>
int generateRandomNumber();
class MockObject : public T::Base_time
{
public:
MockObject(int initial) : counter(initial) {}
int counter;
time_t time(time_t *) { return counter++; }
};
class TestRandom : public CxxTest::TestSuite
{
public:
void test_generateRandomNumber()
{
MockObject t(1);
TS_ASSERT_EQUALS(generateRandomNumber(), 3);
TS_ASSERT_EQUALS(generateRandomNumber(), 6);
TS_ASSERT_EQUALS(generateRandomNumber(), 9);
}
};

View File

@@ -0,0 +1,38 @@
// MyClass.h
class MyClass
{
public:
int value;
MyClass(int value_) : value(value_) {}
// CxxTest requires a copy constructor
MyClass(const MyClass& other) : value(other.value) {}
// This is required if you want to use TS_ASSERT_EQUALS
bool operator==(const MyClass& other) const { return value == other.value; }
// If you want to use TS_ASSERT_LESS_THAN
bool operator<(const MyClass& other) const { return value < other.value; }
};
#ifdef CXXTEST_RUNNING
// This declaration is only activated when building a CxxTest test suite
#include <cxxtest/ValueTraits.h>
#include <stdio.h>
namespace CxxTest
{
CXXTEST_TEMPLATE_INSTANTIATION
class ValueTraits<MyClass>
{
char _s[256];
public:
ValueTraits(const MyClass& m) { sprintf(_s, "MyClass( %i )", m.value); }
const char *asString() const { return _s; }
};
};
#endif // CXXTEST_RUNNING

View File

@@ -0,0 +1,12 @@
// MyTestSuite1.h
#include <cxxtest/TestSuite.h>
class MyTestSuite1 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
};

View File

@@ -0,0 +1,20 @@
// MyTestSuite10.h
#include <cxxtest/TestSuite.h>
#include <MyClass.h>
class MyTestSuite10 : public CxxTest::TestSuite
{
public:
void test_le()
{
MyClass x(1), y(2);
TS_ASSERT_LESS_THAN(x, y);
}
void test_eq()
{
MyClass x(1), y(2);
TS_ASSERT_EQUALS(x, y);
}
};

View File

@@ -0,0 +1,20 @@
// MyTestSuite11.h
#include <cxxtest/TestSuite.h>
#include <TMyClass.h>
class MyTestSuite11 : public CxxTest::TestSuite
{
public:
void test_le()
{
TMyClass<int> x(1), y(2);
TS_ASSERT_LESS_THAN(x, y);
}
void test_eq()
{
TMyClass<int> x(1), y(2);
TS_ASSERT_EQUALS(x, y);
}
};

View File

@@ -0,0 +1,24 @@
// MyTestSuite12.h
#include <cxxtest/TestSuite.h>
class MyTestSuite1 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
};
#ifndef CXXTEST_RUNNING
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Non-CxxTest stuff is happening now." << std::endl;
}
#endif

View File

@@ -0,0 +1,19 @@
// MyTestSuite2.h
#include <cxxtest/TestSuite.h>
class MyTestSuite2 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
void testMultiplication(void)
{
TS_TRACE("Starting multiplication test");
TS_ASSERT_EQUALS(2 * 2, 5);
TS_TRACE("Finishing multiplication test");
}
};

View File

@@ -0,0 +1,32 @@
// MyTestSuite3.h
#include <cxxtest/TestSuite.h>
class MyTestSuite3 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
// void testMultiplication( void )
// {
// TS_ASSERT( 1 * 1 < 2 );
// TS_ASSERT_EQUALS( 1 * 1, 2 );
// }
/*
void testSubtraction( void )
{
TS_ASSERT( 1 - 1 < 1 );
TS_ASSERT_EQUALS( 1 - 1, 0 );
}
*/
void XtestDivision(void)
{
TS_ASSERT(1 / 1 < 2);
TS_ASSERT_EQUALS(1 / 1, 1);
}
};

View File

@@ -0,0 +1,14 @@
// MyTestSuite4.h
#include <cxxtest/TestSuite.h>
class MyTestSuite4
:
public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
};

View File

@@ -0,0 +1,35 @@
// MyTestSuite5.h
#include <cxxtest/TestSuite.h>
#include <string.h>
class MyTestSuite5 : public CxxTest::TestSuite
{
char *_buffer;
public:
void setUp()
{
_buffer = new char[1024];
}
void tearDown()
{
delete [] _buffer;
}
void test_strcpy()
{
strcpy(_buffer, "Hello, world!");
TS_ASSERT_EQUALS(_buffer[0], 'H');
TS_ASSERT_EQUALS(_buffer[1], 'e');
}
void test_memcpy()
{
memcpy(_buffer, "Hello, world!", sizeof(char));
TS_ASSERT_EQUALS(_buffer[0], 'H');
TS_ASSERT_EQUALS(_buffer[1], 'e');
}
};

View File

@@ -0,0 +1,24 @@
// MyTestSuite6.h
#include <cxxtest/TestSuite.h>
class MyTestSuite6 : public CxxTest::TestSuite
{
public:
static MyTestSuite6* createSuite()
{
#ifdef _MSC_VER
return new MyTestSuite6();
#else
return 0;
#endif
}
static void destroySuite(MyTestSuite6* suite)
{ delete suite; }
void test_nothing()
{
TS_FAIL("Nothing to test");
}
};

View File

@@ -0,0 +1,36 @@
// MyTestSuite7.h
#include <cxxtest/TestSuite.h>
#include <iostream>
class MyTestSuite7 : public CxxTest::TestSuite
{
public:
struct Data
{
char data[3];
bool operator==(Data o)
{
return (memcmp(this, &o, sizeof(o)) == 0);
}
};
struct Data2
{
char data[3];
};
void testCompareData()
{
Data x, y;
memset(x.data, 0x12, sizeof(x.data));
memset(y.data, 0xF6, sizeof(y.data));
TS_ASSERT_EQUALS(x, y);
Data2 z, w;
memset(z.data, 0x12, sizeof(x.data));
memset(w.data, 0xF6, sizeof(y.data));
TS_ASSERT_SAME_DATA(&z, &w, sizeof(z))
}
};

View File

@@ -0,0 +1,71 @@
// MyTestSuite8.h
#include <cstdio>
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
//
// Fixture1 counts its setUp()s and tearDown()s
//
class Fixture1 : public CxxTest::GlobalFixture
{
public:
unsigned setUpCount;
unsigned tearDownCount;
Fixture1() { setUpCount = tearDownCount = 0; }
bool setUp() { ++ setUpCount; return true; }
bool tearDown() { ++ tearDownCount; return true; }
bool setUpWorld() { printf("Starting a test suite\n"); return true;}
bool tearDownWorld() { printf("Finishing a test suite\n"); return true;}
};
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;
//
// Verify the counts for the global fixtures
//
class MyTestSuite8 : 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,34 @@
// MyTestSuite9.h
#include <cxxtest/TestSuite.h>
enum Answer
{
Yes,
No,
Maybe,
DontKnow,
DontCare
};
// Declare value traits for the Answer enumeration
CXXTEST_ENUM_TRAITS(Answer,
CXXTEST_ENUM_MEMBER(Yes)
CXXTEST_ENUM_MEMBER(No)
CXXTEST_ENUM_MEMBER(Maybe)
CXXTEST_ENUM_MEMBER(DontKnow)
CXXTEST_ENUM_MEMBER(DontCare));
// Test the trait values
class EnumTraits : public CxxTest::TestSuite
{
public:
void test_Enum_traits()
{
TS_FAIL(Yes);
TS_FAIL(No);
TS_FAIL(Maybe);
TS_FAIL(DontKnow);
TS_FAIL(DontCare);
TS_FAIL((Answer)1000);
}
};

View File

@@ -0,0 +1,39 @@
// Namespace1.h
#include <cxxtest/TestSuite.h>
namespace foo
{
namespace bar
{
class MyTestSuite1 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
};
}
}
namespace FOO
{
namespace BAR
{
class MyTestSuite1 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
};
}
}

View File

@@ -0,0 +1,28 @@
// Namespace2.h
#include <cxxtest/TestSuite.h>
namespace foo { namespace bar { class MyTestSuite1; } }
class foo::bar::MyTestSuite1 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
};
namespace FOO { namespace BAR { class MyTestSuite1; } }
class MyTestSuite1 : public CxxTest::TestSuite
{
public:
void testAddition(void)
{
TS_ASSERT(1 + 1 > 1);
TS_ASSERT_EQUALS(1 + 1, 2);
}
};

View File

@@ -0,0 +1,43 @@
// TMyClass.h
template<class T>
class TMyClass
{
public:
T value;
TMyClass(const T& value_) : value(value_) {}
// CxxTest requires a copy constructor
TMyClass(const TMyClass<T>& other) : value(other.value) {}
// This is required if you want to use TS_ASSERT_EQUALS
bool operator==(const TMyClass<T>& other) const { return value == other.value; }
// If you want to use TS_ASSERT_LESS_THAN
bool operator<(const TMyClass<T>& other) const { return value < other.value; }
};
#ifdef CXXTEST_RUNNING
// This declaration is only activated when building a CxxTest test suite
#include <cxxtest/ValueTraits.h>
#include <typeinfo>
#include <sstream>
namespace CxxTest
{
template <class T>
class ValueTraits< TMyClass<T> >
{
public:
std::ostringstream _s;
ValueTraits(const TMyClass<T>& t) { _s << typeid(t).name() << "( " << t.value << " )"; }
ValueTraits(const ValueTraits< TMyClass<T> >& value) { _s << value._s.rdbuf(); }
const char *asString() const { return _s.str().c_str(); }
};
};
#endif // CXXTEST_RUNNING

View File

@@ -0,0 +1 @@
Running cxxtest tests (1 test).OK!

View File

@@ -0,0 +1,18 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite1.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner > buildRunner.log
# @run:
./runner
# @:run
\rm -f runner runner.cpp

View File

@@ -0,0 +1 @@
Running cxxtest tests (1 test).OK!

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen -o runner.cpp --template runner10.tpl MyTestSuite2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,7 @@
Starting test runner
Running cxxtest tests (2 tests).
In MyTestSuite2::testMultiplication:
MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%
Stopping test runner

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen -f --error-printer -o runner.cpp MyTestSuite3.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,2 @@
Parsing file MyTestSuite3.h done.
Running cxxtest tests (1 test).OK!

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen -f --error-printer -o runner.cpp MyTestSuite4.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,2 @@
Parsing file MyTestSuite4.h done.
Running cxxtest tests (1 test).OK!

View File

@@ -0,0 +1,40 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen -f --error-printer -o runner.cpp MyTestSuite1.h MyTestSuite2.h MyTestSuite4.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
# @help:
./runner --help
# @:help
./runner --help &> runner13.help.txt
# @helpTests:
./runner --help-tests
# @:helpTests
./runner --help-tests &> runner13.helpTests.txt
# @MyTestSuite2:
./runner MyTestSuite2
# @:MyTestSuite2
./runner MyTestSuite2 &> runner13.MyTestSuite2.txt
# @testMultiplication:
./runner MyTestSuite2 testMultiplication
# @:testMultiplication
./runner MyTestSuite2 testMultiplication &> runner13.testMultiplication.txt
# @testMultiplicationVerbose:
./runner -v MyTestSuite2 testMultiplication
# @:testMultiplicationVerbose
./runner -v MyTestSuite2 testMultiplication &> runner13.testMultiplicationVerbose.txt
\rm -f runner runner.cpp

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite5.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1 @@
Running cxxtest tests (2 tests)..OK!

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite6.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,6 @@
Running cxxtest tests (1 test)
In MyTestSuite6::<no test>:
MyTestSuite6.h:8: Error: Test failed: createSuite() failed
MyTestSuite6.h:8: Error: Assertion failed: suite() != 0
Failed 1 and Skipped 0 of 1 test
Success rate: 0%

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MockTestSuite.h
# @:main
# @compile:
g++ -o runner -I. -I$CXXTEST runner.cpp time_mock.cpp rand_example.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1 @@
Running cxxtest tests (1 test).OK!

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite7.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,9 @@
Running cxxtest tests (1 test)
In MyTestSuite7::testCompareData:
MyTestSuite7.h:28: Error: Expected (x == y), found ({ 12 12 12 } != { F6 F6 F6 })
MyTestSuite7.h:33: Error: Expected sizeof(z) (3) bytes to be equal at (&z) and (&w), found:
{ 12 12 12 }
differs from
{ F6 F6 F6 }
Failed 1 and Skipped 0 of 1 test
Success rate: 0%

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite8.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests)Starting a test suite
Starting a test suite
..Finishing a test suite
Finishing a test suite
OK!

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite9.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,10 @@
Running cxxtest tests (1 test)
In EnumTraits::test_Enum_traits:
MyTestSuite9.h:27: Error: Test failed: Yes
MyTestSuite9.h:28: Error: Test failed: No
MyTestSuite9.h:29: Error: Test failed: Maybe
MyTestSuite9.h:30: Error: Test failed: DontKnow
MyTestSuite9.h:31: Error: Test failed: DontCare
MyTestSuite9.h:32: Error: Test failed: (Answer)1000
Failed 1 and Skipped 0 of 1 test
Success rate: 0%

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite2::testMultiplication:
/Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner > buildRunner2.log
cat buildRunner2.log
\rm -f runner runner.cpp

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite2::testMultiplication:
MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite10.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST -I. runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite10::test_eq:
MyTestSuite10.h:17: Error: Expected (x == y), found (MyClass( 1 ) != MyClass( 2 ))
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite11.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST -I. runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite11::test_eq:
MyTestSuite11.h:17: Error: Expected (x == y), found (8TMyClassIiE( 1 ) != 8TMyClassIiE( 1 ))
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --fog --error-printer -o runner.cpp Namespace1.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST -I. runner.cpp
# @:compile
./runner
#\rm -f runner runner.cpp

View File

@@ -0,0 +1,2 @@
Parsing file Namespace1.h done.
Running cxxtest tests (2 tests)..OK!

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp Namespace2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST -I. runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1 @@
Running cxxtest tests (2 tests)..OK!

View File

@@ -0,0 +1,16 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --fog --error-printer -o runner.cpp Namespace2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST -I. runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,2 @@
Parsing file Namespace2.h done.
Running cxxtest tests (2 tests)..OK!

View File

@@ -0,0 +1,24 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --error-printer -o runner.cpp MyTestSuite12.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner > buildRunner.log
# @run:
./runner
# @:run
\rm -f runner runner.cpp
cp MyTestSuite12.h runner2.cpp
g++ -o runner2 -I$CXXTEST runner2.cpp
./runner2
\rm -f runner2 runner2.cpp

View File

@@ -0,0 +1,2 @@
Running cxxtest tests (1 test).OK!
Non-CxxTest stuff is happening now.

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --runner=ParenPrinter -o runner.cpp MyTestSuite2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite2::testMultiplication:
MyTestSuite2.h(16): Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --runner=StdioPrinter -o runner.cpp MyTestSuite2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite2::testMultiplication:
MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,17 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --runner=YesNoRunner -o runner.cpp MyTestSuite2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
echo $?
\rm -f runner runner.cpp

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --runner=XmlPrinter -o runner.cpp MyTestSuite2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite name="cxxtest" date="Tue Apr 23 23:28:43 2013" tests="2" errors="0" failures="1" time="0" >
<testcase classname="MyTestSuite2" name="testAddition" line="7" />
<testcase classname="MyTestSuite2" name="testMultiplication" line="13">
<failure file="MyTestSuite2.h" line="16" type="failedAssertEquals" >Error: Expected (2 * 2 == 5), found (4 != 5)</failure>
</testcase>
</testsuite>

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --xunit-printer -o runner.cpp MyTestSuite2.h
# @:main
# @compile:
g++ -o runner -I$CXXTEST runner.cpp
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite2::testMultiplication:
MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,15 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @main:
cxxtestgen --gui=X11Gui -o runner.cpp MyTestSuite2.h ../../sample/gui/GreenYellowRed.h
# @:main
# @compile:
/opt/local/bin/g++-mp-4.4 -o runner -I$CXXTEST runner.cpp -L/opt/local/lib -lX11
# @:compile
./runner
\rm -f runner runner.cpp

View File

@@ -0,0 +1,21 @@
#!/bin/bash
. GetGlobals.sh
export PATH=$CXXTEST/bin:$PATH
# @part:
cxxtestgen --part --error-printer -o MyTestSuite1.cpp MyTestSuite1.h
cxxtestgen --part --error-printer -o MyTestSuite2.cpp MyTestSuite2.h
# @:part
# @root:
cxxtestgen --root --error-printer -o runner.cpp
# @:root
# @compile:
g++ -o runner -I$CXXTEST runner.cpp MyTestSuite1.cpp MyTestSuite2.cpp
# @:compile
./runner -v
rm -f MyTestSuite1.cpp MyTestSuite2.cpp runner.cpp runner

View File

@@ -0,0 +1,7 @@
// rand_example.cpp
#include <time_mock.h>
int generateRandomNumber()
{
return T::time(NULL) * 3;
}

View File

@@ -0,0 +1,14 @@
#define CXXTEST_HAVE_EH
#define CXXTEST_ABORT_TEST_ON_FAIL
#include <cxxtest/ErrorPrinter.h>
int main()
{
std::cout << "Starting test runner" << std::endl;
int status = CxxTest::ErrorPrinter().run();
std::cout << "Stopping test runner" << std::endl;
return status;
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (2 tests).
In MyTestSuite2::testMultiplication:
/Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 2 tests
Success rate: 50%

View File

@@ -0,0 +1,6 @@
./runner <suitename>
./runner <suitename> <testname>
./runner -h
./runner --help
./runner --help-tests
./runner -v Enable tracing output.

View File

@@ -0,0 +1,6 @@
Suite/Test Names
---------------------------------------------------------------------------
MyTestSuite1 testAddition
MyTestSuite2 testAddition
MyTestSuite2 testMultiplication
MyTestSuite4 testAddition

View File

@@ -0,0 +1,5 @@
Running cxxtest tests (1 test)
In MyTestSuite2::testMultiplication:
/Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
Failed 1 and Skipped 0 of 1 test
Success rate: 0%

View File

@@ -0,0 +1,7 @@
Running cxxtest tests (1 test)
In MyTestSuite2::testMultiplication:
/Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:15: Trace: Starting multiplication test
/Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5)
/Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:17: Trace: Finishing multiplication test
Failed 1 and Skipped 0 of 1 test
Success rate: 0%

View File

@@ -0,0 +1,68 @@
#-------------------------------------------------------------------------
# CxxTest: A lightweight C++ unit testing library.
# Copyright (c) 2008 Sandia Corporation.
# This software is distributed under the LGPL License v3
# For more information, see the COPYING file in the top CxxTest directory.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#-------------------------------------------------------------------------
# Imports
import pyutilib.th as unittest
import glob
import os
from os.path import dirname, abspath, basename
import sys
import re
currdir = dirname(abspath(__file__))+os.sep
datadir = currdir
compilerre = re.compile("^(?P<path>[^:]+)(?P<rest>:.*)$")
dirre = re.compile("^([^%s]*/)*" % re.escape(os.sep))
xmlre = re.compile("\"(?P<path>[^\"]*/[^\"]*)\"")
datere = re.compile("date=\"[^\"]*\"")
failure = re.compile("^(?P<prefix>.+)file=\"(?P<path>[^\"]+)\"(?P<suffix>.*)$")
#print "FOO", dirre
def filter(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)
if 'Running' in line:
return False
if "IGNORE" in line:
return True
pathmatch = compilerre.match(line) # see if we can remove the basedir
failmatch = failure.match(line) # see if we can remove the basedir
#print "HERE", pathmatch, failmatch
if failmatch:
parts = failmatch.groupdict()
#print "X", parts
line = "%s file=\"%s\" %s" % (parts['prefix'], dirre.sub("", parts['path']), parts['suffix'])
elif pathmatch:
parts = pathmatch.groupdict()
#print "Y", parts
line = dirre.sub("", parts['path']) + parts['rest']
return line
# Declare an empty TestCase class
class Test(unittest.TestCase): pass
if not sys.platform.startswith('win'):
# Find all *.sh files, and use them to define baseline tests
for file in glob.glob(datadir+'*.sh'):
bname = basename(file)
name=bname.split('.')[0]
if os.path.exists(datadir+name+'.txt'):
Test.add_baseline_test(cwd=datadir, cmd=file, baseline=datadir+name+'.txt', name=name, filter=filter)
# Execute the tests
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,3 @@
// time_mock.cpp
#define CXXTEST_MOCK_TEST_SOURCE_FILE
#include <time_mock.h>

View File

@@ -0,0 +1,8 @@
// time_mock.h
#include <time.h>
#include <cxxtest/Mock.h>
CXXTEST_MOCK_GLOBAL(time_t, /* Return type */
time, /* Name of the function */
(time_t *t), /* Prototype */
(t) /* Argument list */);

View File

@@ -0,0 +1,3 @@
// time_real.cpp
#define CXXTEST_MOCK_REAL_SOURCE_FILE
#include <time_mock.h>