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,64 @@
# -*- Perl -*-
#
# This file shows how to use CxxTest with Cons
#
$env = new cons( CXX => ("$^O" eq 'MSWin32') ? 'cl -nologo -GX' : 'c++',
CPPPATH => '..',
CXXTESTGEN => '../bin/cxxtestgen' );
@tests = <*.h>;
# The error printer is the most basic runner
CxxTestErrorPrinter $env 'error_printer', @tests;
# You can also specify which runner you want to use
CxxTestRunner $env 'stdio_printer', 'StdioPrinter', @tests;
# For more control, use template files
CxxTestTemplate $env 'file_printer', 'file_printer.tpl', @tests;
# Or, you can always separate the tests from the runner
CxxTest $env 'tests.cpp', '', @tests;
Program $env 'yes_no_runner', ('yes_no_runner.cpp', 'tests.cpp');
#
# Here is the code used to build these files
# You can use this in your own Construct files
#
# cons::CxxTest $env $dst, $options, @srcs
# Generates a CxxTest source file, passing the specified options to cxxtestgen
sub cons::CxxTest($$$@) {
my ($env, $dst, $options, @srcs) = @_;
Command $env $dst, @srcs, "%CXXTESTGEN -o %> ${options} %<";
}
# cons::CxxTestTemplate $env $dst, $template, @srcs
# Generates and builds a CxxTest runner using a template file
sub cons::CxxTestTemplate($$$@) {
my ($env, $dst, $template, @srcs) = @_;
my $source = "${dst}.cpp";
CxxTest $env $source, "--template=${template}", ($template, @srcs);
Program $env $dst, $source;
}
# cons::CxxTestRunner $env $dst, $runner, @srcs
# Generates and builds a CxxTest runner using the --runner option
sub cons::CxxTestRunner($$$@) {
my ($env, $dst, $runner, @srcs) = @_;
my $source = "${dst}.cpp";
CxxTest $env $source, "--runner=${runner}", @srcs;
Program $env $dst, $source;
}
# cons::CxxTestErrorPrinter $env $dst, @srcs
# Generates and builds a CxxTest ErrorPrinter
sub cons::CxxTestErrorPrinter($$@) {
my ($env, $dst, @srcs) = @_;
CxxTestRunner $env $dst, 'ErrorPrinter', @srcs;
}

View File

@@ -0,0 +1,29 @@
#ifndef __CREATEDTEST_H
#define __CREATEDTEST_H
#include <cxxtest/TestSuite.h>
#include <string.h>
#include <memory.h>
//
// This test suite shows what to do when your test case
// class cannot be instantiated statically.
// As an example, this test suite requires a non-default constructor.
//
class CreatedTest : public CxxTest::TestSuite {
char *_buffer;
public:
CreatedTest(unsigned size) : _buffer(new char[size]) {}
virtual ~CreatedTest() { delete [] _buffer; }
static CreatedTest *createSuite() { return new CreatedTest(16); }
static void destroySuite(CreatedTest *suite) { delete suite; }
void test_nothing() {
TS_FAIL("Nothing to test");
}
};
#endif // __CREATEDTEST_H

View File

@@ -0,0 +1,30 @@
#ifndef __DELTATEST_H
#define __DELTATEST_H
#include <cxxtest/TestSuite.h>
#include <math.h>
class DeltaTest : public CxxTest::TestSuite {
double _pi, _delta;
public:
void setUp() {
_pi = 3.1415926535;
_delta = 0.0001;
}
void testSine() {
TS_ASSERT_DELTA(sin(0.0), 0.0, _delta);
TS_ASSERT_DELTA(sin(_pi / 6), 0.5, _delta);
TS_ASSERT_DELTA(sin(_pi / 2), 1.0, _delta);
TS_ASSERT_DELTA(sin(_pi), 0.0, _delta);
}
void testInt() {
unsigned a = 0;
unsigned b = 0;
TS_ASSERT_DELTA(a, b, 10);
}
};
#endif // __DELTATEST_H

View File

@@ -0,0 +1,37 @@
//
// This is a test of CxxTest's ValueTraits for enumerations.
//
#include <cxxtest/TestSuite.h>
//
// First define your enumeration
//
enum Answer {
Yes,
No,
Maybe,
DontKnow,
DontCare
};
//
// Now make CxxTest aware of it
//
CXXTEST_ENUM_TRAITS(Answer,
CXXTEST_ENUM_MEMBER(Yes)
CXXTEST_ENUM_MEMBER(No)
CXXTEST_ENUM_MEMBER(Maybe)
CXXTEST_ENUM_MEMBER(DontKnow)
CXXTEST_ENUM_MEMBER(DontCare));
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,49 @@
#ifndef __EXCEPTIONTEST_H
#define __EXCEPTIONTEST_H
#include <cxxtest/TestSuite.h>
//
// This test suite demonstrates the use of TS_ASSERT_THROWS
//
class ExceptionTest : public CxxTest::TestSuite {
public:
void testAssertion(void) {
// This assert passes, since throwThis() throws (Number)
TS_ASSERT_THROWS(throwThis(3), const Number &);
// This assert passes, since throwThis() throws something
TS_ASSERT_THROWS_ANYTHING(throwThis(-30));
// This assert fails, since throwThis() doesn't throw char *
TS_ASSERT_THROWS(throwThis(5), const char *);
// This assert fails since goodFunction() throws nothing
TS_ASSERT_THROWS_ANYTHING(goodFunction(1));
// The regular TS_ASSERT macros will catch unhandled exceptions
TS_ASSERT_EQUALS(throwThis(3), 333);
// You can assert that a function throws nothing
TS_ASSERT_THROWS_NOTHING(throwThis(-1));
// This assert fails, since throwThis() throws (Number)
TS_ASSERT_THROWS(throwThis(3), std::exception&);
// If you want to catch the exceptions yourself, use the ETS_ marcos
try {
ETS_ASSERT_EQUALS(throwThis(3), 333);
} catch (const Number &) {
TS_FAIL("throwThis(3) failed");
}
}
private:
void goodFunction(int) {
}
class Number {
public:
Number(int) {}
};
int throwThis(int i) {
throw Number(i);
}
};
#endif // __EXCEPTIONTEST_H

View File

@@ -0,0 +1,33 @@
#ifndef __FIXTURETEST_H
#define __FIXTURETEST_H
#include <cxxtest/TestSuite.h>
#include <string.h>
//
// This test suite shows how to use setUp() and tearDown()
// to initialize data common to all tests.
// setUp()/tearDown() will be called before and after each
// test.
//
class FixtureTest : 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');
}
};
#endif // __FIXTURETEST_H

View File

@@ -0,0 +1,32 @@
#!/usr/bin/perl
#
# This isn't a "real" `Makefile.PL'
# It just copies the correct `Makefile.*' to `Makefile'
#
use strict;
use Getopt::Long;
use File::Copy;
sub usage() {
die "Usage: $0 [--bcc32]\n";
}
my $source;
my $target = 'Makefile';
my $windows = $ENV{'windir'};
GetOptions( 'bcc32' => sub { $source = 'Makefile.bcc32' } ) or usage();
if ( !defined( $source ) ) {
$source = $windows ? 'Makefile.msvc' : 'Makefile.unix';
}
unlink($target);
$windows ? copy($source, $target) : symlink($source, $target);
print "`Makefile' is now `$source'.\n";
#
# Local Variables:
# compile-command: "perl Makefile.PL"
# End:
#

View File

@@ -0,0 +1,94 @@
#
# Makefile for Borland C++
# Make sure bcc32.exe is in the PATH or change CXXC below
#
# For the Win32 GUI
#WIN32_FLAGS = user32.lib comctl32.lib
# For the Qt GUI
#QTDIR = c:\qt
QT_FLAGS = -I$(QTDIR)/include $(QTDIR)/lib/qt.lib
TARGETS = error_printer.exe stdio_printer.exe yes_no_runner.exe file_printer.exe aborter.exe only.exe
GUI_TARGETS = win32_runner.exe qt_runner.exe
TESTS = *.h
GUI_TESTS = gui/GreenYellowRed.h $(TESTS)
TESTGEN = ../bin/cxxtestgen
CXXC = bcc32.exe -w- -I. -I..
all: $(TARGETS)
clean:
del *~ *.o *.obj
del $(TARGETS)
del $(GUI_TARGETS)
del tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp
del win32_runner.cpp qt_runner.cpp
distclean: clean
del Makefile
run: error_printer.exe
error_printer.exe
run_win32: win32_runner.exe
win32_runner.exe
run_qt: qt_runner.exe
qt_runner.exe
error_printer.cpp: $(TESTS)
$(TESTGEN) -o error_printer.cpp --error-printer $(TESTS)
stdio_printer.cpp: $(TESTS)
$(TESTGEN) -o stdio_printer.cpp --runner=StdioPrinter $(TESTS)
file_printer.cpp: file_printer.tpl $(TESTS)
$(TESTGEN) -o file_printer.cpp --template=file_printer.tpl $(TESTS)
aborter.cpp: aborter.tpl $(TESTS)
$(TESTGEN) -o aborter.cpp --template=aborter.tpl $(TESTS)
only.cpp: only.tpl $(TESTS)
$(TESTGEN) -o only.cpp --template=only.tpl $(TESTS)
tests.cpp: $(TESTS)
$(TESTGEN) -o tests.cpp $(TESTS)
win32_runner.cpp: $(GUI_TESTS)
$(TESTGEN) -o win32_runner.cpp --gui=Win32Gui $(GUI_TESTS)
qt_runner.cpp: $(GUI_TESTS)
$(TESTGEN) -o qt_runner.cpp --gui=QtGui $(GUI_TESTS)
error_printer.exe: error_printer.cpp
$(CXXC) -eerror_printer.exe error_printer.cpp
stdio_printer.exe: stdio_printer.cpp
$(CXXC) -estdio_printer.exe stdio_printer.cpp
file_printer.exe: file_printer.cpp
$(CXXC) -efile_printer.exe file_printer.cpp
only.exe: only.cpp
$(CXXC) -eonly.exe only.cpp
aborter.exe: aborter.cpp
$(CXXC) -eaborter.exe aborter.cpp
yes_no_runner.exe: yes_no_runner.cpp tests.cpp
$(CXXC) -eyes_no_runner.exe yes_no_runner.cpp tests.cpp
win32_runner.exe: win32_runner.cpp
$(CXXC) -ewin32_runner.exe win32_runner.cpp $(WIN32_FLAGS)
qt_runner.exe: qt_runner.cpp
$(CXXC) -o qt_runner.exe qt_runner.cpp $(QT_FLAGS)
#
# Local Variables:
# compile-command: "make -fMakefile.bcc32"
# End:
#

View File

@@ -0,0 +1,93 @@
#
# Makefile for Microsoft Visual C++
# Make sure cl.exe is in the PATH (run vcvars.bat) or change CXXC below
#
# For the Win32 GUI
WIN32_FLAGS = user32.lib
# For the Qt GUI
# QTDIR = c:\qt
QT_FLAGS = -I$(QTDIR)/include $(QTDIR)/lib/qt.lib
TARGETS = error_printer.exe stdio_printer.exe yes_no_runner.exe file_printer.exe aborter.exe only.exe
GUI_TARGETS = win32_runner.exe qt_runner.exe
TESTS = *.h
GUI_TESTS = gui/GreenYellowRed.h $(TESTS)
TESTGEN = python ../bin/cxxtestgen
CXXC = cl.exe -GX -W3 -WX -I. -I..
all: $(TARGETS)
clean:
del *~ *.o *.obj
del $(TARGETS)
del $(GUI_TARGETS)
del tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp
del win32_runner.cpp qt_runner.cpp
distclean: clean
del Makefile
run: error_printer.exe
error_printer.exe
run_win32: win32_runner.exe
win32_runner.exe
run_qt: qt_runner.exe
qt_runner.exe
error_printer.cpp: $(TESTS)
$(TESTGEN) -o error_printer.cpp --error-printer $(TESTS)
stdio_printer.cpp: $(TESTS)
$(TESTGEN) -o stdio_printer.cpp --runner=StdioPrinter $(TESTS)
file_printer.cpp: file_printer.tpl $(TESTS)
$(TESTGEN) -o file_printer.cpp --template=file_printer.tpl $(TESTS)
aborter.cpp: aborter.tpl $(TESTS)
$(TESTGEN) -o aborter.cpp --template=aborter.tpl $(TESTS)
only.cpp: only.tpl $(TESTS)
$(TESTGEN) -o only.cpp --template=only.tpl $(TESTS)
tests.cpp: $(TESTS)
$(TESTGEN) -o tests.cpp $(TESTS)
win32_runner.cpp: $(GUI_TESTS)
$(TESTGEN) -o win32_runner.cpp --gui=Win32Gui $(GUI_TESTS)
qt_runner.cpp: $(GUI_TESTS)
$(TESTGEN) -o qt_runner.cpp --gui=QtGui $(GUI_TESTS)
error_printer.exe: error_printer.cpp
$(CXXC) -o error_printer.exe error_printer.cpp
stdio_printer.exe: stdio_printer.cpp
$(CXXC) -o stdio_printer.exe stdio_printer.cpp
file_printer.exe: file_printer.cpp
$(CXXC) -o file_printer.exe file_printer.cpp
only.exe: only.cpp
$(CXXC) -o only.exe only.cpp
aborter.exe: aborter.cpp
$(CXXC) -o aborter.exe aborter.cpp
yes_no_runner.exe: yes_no_runner.cpp tests.cpp
$(CXXC) -o yes_no_runner.exe yes_no_runner.cpp tests.cpp
win32_runner.exe: win32_runner.cpp
$(CXXC) -o win32_runner.exe win32_runner.cpp $(WIN32_FLAGS)
qt_runner.exe: qt_runner.cpp
$(CXXC) -o qt_runner.exe qt_runner.cpp $(QT_FLAGS)
#
# Local Variables:
# compile-command: "nmake -fMakefile.msvc"
# End:
#

View File

@@ -0,0 +1,83 @@
#
# Makefile for UN*X-like systems
#
# Change this line if you want a different compiler
CXXC = c++ -Wall -W -Werror -I. -I..
TESTGEN = ../bin/cxxtestgen
# For the X11 GUI
X11_FLAGS = -I/usr/X11R6/include -L/usr/X11R6/lib -lX11
# For the Qt GUI
#QTDIR = /usr/lib/qt
QTLIB = -lqt-mt
#QTLIB = -lqt
QT_FLAGS = -I$(QTDIR)/include -L$(QTDIR)/lib $(QTLIB) -O2
TARGETS = error_printer stdio_printer yes_no_runner file_printer aborter only
GUI_TARGETS = x11_runner qt_runner
TESTS = *.h
GUI_TESTS = gui/GreenYellowRed.h $(TESTS)
all: $(TARGETS)
clean:
rm -f *~ *.o *.obj $(TARGETS) $(GUI_TARGETS)
rm -f tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp
rm -f x11_runner.cpp qt_runner.cpp
distclean: clean
rm -f Makefile
run: error_printer
./error_printer
run_x11: x11_runner
./x11_runner
run_qt: qt_runner
./qt_runner
error_printer.cpp: $(TESTS)
$(TESTGEN) -o $@ --error-printer $(TESTS)
stdio_printer.cpp: $(TESTS)
$(TESTGEN) -o $@ --runner=StdioPrinter $(TESTS)
file_printer.cpp: file_printer.tpl $(TESTS)
$(TESTGEN) -o $@ --template=file_printer.tpl $(TESTS)
aborter.cpp: aborter.tpl $(TESTS)
$(TESTGEN) -o $@ --template=aborter.tpl $(TESTS)
only.cpp: only.tpl $(TESTS)
$(TESTGEN) -o $@ --template=only.tpl $(TESTS)
tests.cpp: $(TESTS)
$(TESTGEN) -o $@ $(TESTS)
x11_runner.cpp: $(GUI_TESTS)
$(TESTGEN) -o $@ --gui=X11Gui $(GUI_TESTS)
qt_runner.cpp: $(GUI_TESTS)
$(TESTGEN) -o $@ --gui=QtGui $(GUI_TESTS)
%: %.cpp
$(CXXC) -o $@ $<
yes_no_runner: yes_no_runner.cpp tests.cpp
$(CXXC) -o $@ $^
x11_runner: x11_runner.cpp
$(CXXC) -o $@ $^ $(X11_FLAGS)
qt_runner: qt_runner.cpp
$(CXXC) -o $@ $^ $(QT_FLAGS)
#
# Local Variables:
# compile-command: "make -fMakefile.unix"
# End:
#

View File

@@ -0,0 +1,27 @@
#ifndef __MESSAGETEST_H
#define __MESSAGETEST_H
#include <cxxtest/TestSuite.h>
//
// The [E]TSM_ macros can be used to print a specified message
// instead of the default one.
// This is useful when you refactor your tests, as shown below
//
class MessageTest : public CxxTest::TestSuite {
public:
void testValues() {
checkValue(0, "My hovercraft");
checkValue(1, "is full");
checkValue(2, "of eels");
}
void checkValue(unsigned value, const char *message) {
TSM_ASSERT(message, value != 0);
TSM_ASSERT_EQUALS(message, value, value * value);
}
};
#endif // __MESSAGETEST_H

View File

@@ -0,0 +1,40 @@
cxxtestbuilder_path = '../../build_tools/SCons/cxxtest.py'
cxxtest_path = '../..'
# First a bit of python magic to make the CxxTestBuilder available
# without having to copy it into a particular path.
# for nicer examples you *should* use, see the cxxtest builder tests in the
# build_tools/SCons/test directory.
import imp
cxxtest = imp.load_source('cxxtest', cxxtestbuilder_path)
# First build the 'real' library, when working on an embedded system
# this may involve a cross compiler.
env = Environment()
env.BuildDir('build/embedded_platform', 'src')
env.Append(CPPPATH=['include'])
libtested = env.StaticLibrary('build/embedded_platform/tested',
env.Glob('build/embedded_platform/*.c'))
# Now create a seperate build environment for the tests so we can keep any
# options that are specific to testing seperate from the 'production' build
# environment. For simplicity I am just copying the production environment.
# If we are cross compiling for the "real" library, then this
# environement might be using the normal compiler.
env_test = env.Clone()
# Add the CxxTestBuilder to our testing build environment.
cxxtest.generate(env_test, CXXTEST_INSTALL_DIR = cxxtest_path)
# If we were working with an embedded platform we may want to create a
# seperate version of our library that runs on our development box in
# order to do our initial unit testing. This version may also include
# any special preprocessor defines needed for testing e.g. -DTESTING
env_test.BuildDir('build/dev_platform', 'src')
env_test.BuildDir('build/tests', 'tests')
lib_to_test = env_test.StaticLibrary('build/dev_platform/tested',
env.Glob('build/dev_platform/*.c'))
env_test.Append(LIBS=lib_to_test)
env_test.CxxTest(env_test.Glob('tests/*.h'))

View File

@@ -0,0 +1,27 @@
#ifndef STACK_H
#define STACK_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct stack_t {
int size;
int* vals;
int capacity;
} stack_t;
stack_t* stack_create();
void stack_free(stack_t* stack);
int stack_size(stack_t* stack);
void stack_push(stack_t* stack, int val);
int stack_pop(stack_t* stack);
int stack_peak(stack_t* stack);
int stack_capacity(stack_t* stack);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,48 @@
#include <stack.h>
#include <stdlib.h>
stack_t* stack_create() {
stack_t* retVal = malloc(sizeof(stack_t));
retVal->size = 0;
retVal->capacity = 10;
retVal->vals = malloc(retVal->capacity*sizeof(int));
return retVal;
}
void stack_free(stack_t* stack) {
free(stack->vals);
free(stack);
}
int stack_size(stack_t* stack) {
return stack->size;
}
void stack_push(stack_t* stack, int val) {
if(stack->size == stack->capacity) {
stack->capacity *= 2;
stack->vals = realloc(stack->vals, stack->capacity*sizeof(int));
}
stack->vals[stack->size++] = val;
}
int stack_pop(stack_t* stack) {
if (stack->size >= 1)
return stack->vals[--stack->size];
else
return 0;
}
int stack_peak(stack_t* stack) {
if (stack->size >= 1)
return stack->vals[stack->size-1];
else
return 0;
}
int stack_capacity(stack_t* stack) {
return stack->capacity;
}

View File

@@ -0,0 +1,71 @@
#ifndef STACK_TEST_H
#define STACK_TEST_H
#include <cxxtest/TestSuite.h>
#include <stack.h>
class stack_test : public CxxTest::TestSuite
{
private:
stack_t* stack;
public:
void setUp() {
stack = stack_create();
}
void tearDown() {
stack_free(stack);
}
void test_create_stack() {
TS_ASSERT_DIFFERS((stack_t*)0, stack);
}
void test_new_stack_is_empty() {
TS_ASSERT_EQUALS(0, stack_size(stack));
}
void test_one_push_add_one_to_size() {
stack_push(stack, 1);
TS_ASSERT_EQUALS(1, stack_size(stack));
}
void test_push_pop_doesnt_change_size() {
stack_push(stack, 1);
(void)stack_pop(stack);
TS_ASSERT_EQUALS(0, stack_size(stack));
}
void test_peak_after_push() {
stack_push(stack, 1);
TS_ASSERT_EQUALS(1, stack_peak(stack))
}
void test_initial_capacity_is_positive() {
TS_ASSERT(stack_capacity(stack) > 0);
}
void test_pop_on_empty() {
TS_ASSERT_EQUALS(0, stack_pop(stack));
TS_ASSERT_EQUALS(0, stack_size(stack));
}
void test_peak_on_empty() {
TS_ASSERT_EQUALS(0, stack_peak(stack));
}
void test_capacity_gte_size() {
TS_ASSERT_LESS_THAN_EQUALS(stack_size(stack), stack_capacity(stack));
int init_capacity = stack_capacity(stack);
for (int i=0; i < init_capacity + 1; i++) {
stack_push(stack, i);
}
TS_ASSERT_LESS_THAN_EQUALS(stack_size(stack), stack_capacity(stack));
}
};
#endif // STACK_TEST_H

View File

@@ -0,0 +1,58 @@
#ifndef __SIMPLETEST_H
#define __SIMPLETEST_H
#include <cxxtest/TestSuite.h>
//
// A simple test suite: Just inherit CxxTest::TestSuite and write tests!
//
class SimpleTest : 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);
const char* tmp = "foo";
TS_ASSERT_EQUALS("foo", tmp);
}
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_SKIP_macro() {
TS_SKIP("Simply skip this test");
TS_WARN("Skipping will abort the test");
}
void test_TS_WARN_macro() {
TS_WARN("Just a friendly warning");
TS_WARN("Warnings don't abort the test");
}
};
#endif // __SIMPLETEST_H

View File

@@ -0,0 +1,63 @@
#ifndef __TRAITSTEST_H
#define __TRAITSTEST_H
//
// This example shows how to use TS_ASSERT_EQUALS for your own classes
//
#include <cxxtest/TestSuite.h>
#include <cxxtest/ValueTraits.h>
//
// Define your class with operator==
//
#include <stdio.h>
#include <string.h>
class Pet {
char _name[128];
public:
Pet(const char *petName) { strcpy(_name, petName); }
const char *name() const { return _name; }
bool operator== (const Pet &other) const {
return !strcmp(name(), other.name());
}
};
//
// Instantiate CxxTest::ValueTraits<*your class*>
// Note: Most compilers do not require that you define both
// ValueTraits<const T> and ValueTraits<T>, but some do.
//
namespace CxxTest {
CXXTEST_TEMPLATE_INSTANTIATION
class ValueTraits<const Pet> {
char _asString[256];
public:
ValueTraits(const Pet &pet) { sprintf(_asString, "Pet(\"%s\")", pet.name()); }
const char *asString() const { return _asString; }
};
CXXTEST_COPY_CONST_TRAITS(Pet);
}
//
// Here's how it works
//
class TestFunky : public CxxTest::TestSuite {
public:
void testPets() {
Pet pet1("dog"), pet2("cat");
TS_ASSERT_EQUALS(pet1, pet2);
Pet cat("cat"), gato("cat");
TS_ASSERT_DIFFERS(cat, gato);
#ifdef _CXXTEST_HAVE_STD
typedef CXXTEST_STD(string) String;
TS_ASSERT_EQUALS(String("Hello"), String("World!"));
#endif // _CXXTEST_HAVE_STD
}
};
#endif // __TRAITSTEST_H

View File

@@ -0,0 +1,16 @@
// -*- C++ -*-
// This template file demonstrates the use of CXXTEST_ABORT_TEST_ON_FAIL
//
#define CXXTEST_HAVE_STD
#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,22 @@
// -*- C++ -*-
// This is a sample of a custom test runner
// using CxxTest template files.
// This prints the output to a file given on the command line.
//
#include <cxxtest/StdioPrinter.h>
#include <stdio.h>
int main( int argc, char *argv[] )
{
if ( argc != 2 ) {
fprintf( stderr, "Usage: %s <output file name>\n", argv[0] );
return -1;
}
return CxxTest::StdioPrinter( fopen( argv[1], "w" ) ).run();
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,57 @@
#include <cxxtest/TestSuite.h>
#ifdef _WIN32
# include <windows.h>
# define CXXTEST_SAMPLE_GUI_WAIT() Sleep( 1000 )
#else // !_WIN32
extern "C" unsigned sleep(unsigned seconds);
# define CXXTEST_SAMPLE_GUI_WAIT() sleep( 1 )
#endif // _WIN32
class GreenYellowRed : public CxxTest::TestSuite
{
public:
void wait()
{
CXXTEST_SAMPLE_GUI_WAIT();
}
void test_Start_green()
{
wait();
}
void test_Green_again()
{
TS_TRACE("Still green");
wait();
}
void test_Now_yellow()
{
TS_WARN("Yellow");
wait();
}
void test_Cannot_go_back()
{
wait();
}
void test_Finally_red()
{
TS_FAIL("Red");
wait();
}
void test_Cannot_go_back_to_yellow()
{
TS_WARN("Yellow?");
wait();
}
void test_Cannot_go_back_to_green()
{
wait();
}
};

View File

@@ -0,0 +1,14 @@
#include <T/stdlib.h>
#include "Dice.h"
Dice::Dice()
{
T::srand(T::time(0));
}
unsigned Dice::roll()
{
return (T::rand() % 6) + 1;
}

View File

@@ -0,0 +1,13 @@
#ifndef __DICE_H
#define __DICE_H
class Dice
{
public:
Dice();
unsigned roll();
};
#endif // __DICE_H

View File

@@ -0,0 +1,22 @@
all: roll run
clean:
rm -f *~ *.o roll test test.cpp
CXXTEST = ../..
CCFLAGS = -I. -I$(CXXTEST)
roll: roll.o Dice.o real_stdlib.o
g++ -o $@ $^
run: test
./test
test: test.o Dice.o mock_stdlib.o
g++ -o $@ $^
.cpp.o:
g++ -c -o $@ $(CCFLAGS) $<
test.cpp: TestDice.h
$(CXXTEST)/bin/cxxtestgen -o $@ --error-printer $<

View File

@@ -0,0 +1,33 @@
#include <T/stdlib.h>
class MockStdlib :
public T::Base_srand,
public T::Base_rand,
public T::Base_time
{
public:
unsigned lastSeed;
void srand(unsigned seed)
{
lastSeed = seed;
}
int nextRand;
int rand()
{
return nextRand;
}
time_t nextTime;
time_t time(time_t *t)
{
if (t)
{
*t = nextTime;
}
return nextTime;
}
};

View File

@@ -0,0 +1,13 @@
#ifndef __T__STDLIB_H
#define __T__STDLIB_H
#include <stdlib.h>
#include <time.h>
#include <cxxtest/Mock.h>
CXXTEST_MOCK_VOID_GLOBAL( srand, ( unsigned seed ), ( seed ) );
CXXTEST_MOCK_GLOBAL( int, rand, ( void ), () );
CXXTEST_MOCK_GLOBAL( time_t, time, ( time_t *t ), ( t ) );
#endif // __T__STDLIB_H

View File

@@ -0,0 +1,62 @@
#include <cxxtest/TestSuite.h>
#include "Dice.h"
#include "MockStdlib.h"
class TestDice : public CxxTest::TestSuite
{
public:
MockStdlib *stdlib;
void setUp()
{
TS_ASSERT(stdlib = new MockStdlib);
}
void tearDown()
{
delete stdlib;
}
void test_Randomize_uses_time()
{
stdlib->nextTime = 12345;
Dice dice;
TS_ASSERT_EQUALS(stdlib->lastSeed, 12345);
}
void test_Roll()
{
Dice dice;
stdlib->nextRand = 0;
TS_ASSERT_EQUALS(dice.roll(), 1);
stdlib->nextRand = 2;
TS_ASSERT_EQUALS(dice.roll(), 3);
stdlib->nextRand = 5;
TS_ASSERT_EQUALS(dice.roll(), 6);
stdlib->nextRand = 7;
TS_ASSERT_EQUALS(dice.roll(), 2);
}
void test_Temporary_override_of_one_mock_function()
{
Dice dice;
stdlib->nextRand = 2;
TS_ASSERT_EQUALS(dice.roll(), 3);
class Five : public T::Base_rand { int rand() { return 5; } };
Five *five = new Five;
TS_ASSERT_EQUALS(dice.roll(), 6);
TS_ASSERT_EQUALS(dice.roll(), 6);
TS_ASSERT_EQUALS(dice.roll(), 6);
delete five;
stdlib->nextRand = 1;
TS_ASSERT_EQUALS(dice.roll(), 2);
}
};

View File

@@ -0,0 +1,2 @@
#define CXXTEST_MOCK_TEST_SOURCE_FILE
#include <T/stdlib.h>

View File

@@ -0,0 +1,2 @@
#define CXXTEST_MOCK_REAL_SOURCE_FILE
#include <T/stdlib.h>

View File

@@ -0,0 +1,11 @@
#include <stdio.h>
#include "Dice.h"
int main()
{
Dice dice;
printf("First roll: %u\n", dice.roll());
printf("Second roll: %u\n", dice.roll());
return 0;
}

View File

@@ -0,0 +1,93 @@
# Microsoft Developer Studio Project File - Name="CxxTest_1_Run" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) External Target" 0x0106
CFG=CxxTest_1_Run - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_1_Run.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_1_Run.mak" CFG="CxxTest_1_Run - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "CxxTest_1_Run - Win32 Release" (based on "Win32 (x86) External Target")
!MESSAGE "CxxTest_1_Run - Win32 Debug" (based on "Win32 (x86) External Target")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
!IF "$(CFG)" == "CxxTest_1_Run - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Cmd_Line "NMAKE /f CxxTest_1_Run.mak"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "CxxTest_1_Run.exe"
# PROP BASE Bsc_Name "CxxTest_1_Run.bsc"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Cmd_Line "nmake DIR=Release run"
# PROP Rebuild_Opt "/a"
# PROP Target_File "Release\run.log"
# PROP Bsc_Name ""
# PROP Target_Dir ""
!ELSEIF "$(CFG)" == "CxxTest_1_Run - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Cmd_Line "NMAKE /f CxxTest_1_Run.mak"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "CxxTest_1_Run.exe"
# PROP BASE Bsc_Name "CxxTest_1_Run.bsc"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Cmd_Line "nmake DIR=Debug run"
# PROP Rebuild_Opt "/a"
# PROP Target_File "Debug\run.log"
# PROP Bsc_Name ""
# PROP Target_Dir ""
!ENDIF
# Begin Target
# Name "CxxTest_1_Run - Win32 Release"
# Name "CxxTest_1_Run - Win32 Debug"
!IF "$(CFG)" == "CxxTest_1_Run - Win32 Release"
!ELSEIF "$(CFG)" == "CxxTest_1_Run - Win32 Debug"
!ENDIF
# Begin Source File
SOURCE=.\Makefile
# End Source File
# Begin Source File
SOURCE=.\ReadMe.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,94 @@
# Microsoft Developer Studio Project File - Name="CxxTest_2_Build" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=CxxTest_2_Build - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_2_Build.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_2_Build.mak" CFG="CxxTest_2_Build - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "CxxTest_2_Build - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "CxxTest_2_Build - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "CxxTest_2_Build - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x40d /d "NDEBUG"
# ADD RSC /l 0x40d /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Release/runner.exe"
!ELSEIF "$(CFG)" == "CxxTest_2_Build - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x40d /d "_DEBUG"
# ADD RSC /l 0x40d /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/runner.exe" /pdbtype:sept
!ENDIF
# Begin Target
# Name "CxxTest_2_Build - Win32 Release"
# Name "CxxTest_2_Build - Win32 Debug"
# Begin Source File
SOURCE=.\ReadMe.txt
# End Source File
# Begin Source File
SOURCE=.\runner.cpp
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,93 @@
# Microsoft Developer Studio Project File - Name="CxxTest_3_Generate" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) External Target" 0x0106
CFG=CxxTest_3_Generate - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_3_Generate.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_3_Generate.mak" CFG="CxxTest_3_Generate - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "CxxTest_3_Generate - Win32 Release" (based on "Win32 (x86) External Target")
!MESSAGE "CxxTest_3_Generate - Win32 Debug" (based on "Win32 (x86) External Target")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
!IF "$(CFG)" == "CxxTest_3_Generate - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Cmd_Line "NMAKE /f CxxTest_3_Generate.mak"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "CxxTest_3_Generate.exe"
# PROP BASE Bsc_Name "CxxTest_3_Generate.bsc"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Cmd_Line "nmake runner.cpp"
# PROP Rebuild_Opt "/a"
# PROP Target_File "runner.cpp"
# PROP Bsc_Name ""
# PROP Target_Dir ""
!ELSEIF "$(CFG)" == "CxxTest_3_Generate - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Cmd_Line "NMAKE /f CxxTest_3_Generate.mak"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "CxxTest_3_Generate.exe"
# PROP BASE Bsc_Name "CxxTest_3_Generate.bsc"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Cmd_Line "nmake runner.cpp"
# PROP Rebuild_Opt "/a"
# PROP Target_File "runner.cpp"
# PROP Bsc_Name ""
# PROP Target_Dir ""
!ENDIF
# Begin Target
# Name "CxxTest_3_Generate - Win32 Release"
# Name "CxxTest_3_Generate - Win32 Debug"
!IF "$(CFG)" == "CxxTest_3_Generate - Win32 Release"
!ELSEIF "$(CFG)" == "CxxTest_3_Generate - Win32 Debug"
!ENDIF
# Begin Source File
SOURCE=.\Makefile
# End Source File
# Begin Source File
SOURCE=.\ReadMe.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,59 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "CxxTest_1_Run"=.\CxxTest_1_Run.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name CxxTest_2_Build
End Project Dependency
}}}
###############################################################################
Project: "CxxTest_2_Build"=.\CxxTest_2_Build.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name CxxTest_3_Generate
End Project Dependency
}}}
###############################################################################
Project: "CxxTest_3_Generate"=.\CxxTest_3_Generate.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,210 @@
@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!/usr/bin/perl -w
#line 15
use strict;
use English;
use Getopt::Long;
$OUTPUT_AUTOFLUSH = 1;
sub usage() {
print STDERR "Usage: $0 <OPTIONS>\n\n";
print STDERR "Fix Makefile and CxxTest_2_Build.dsp for your setup.\n\n";
print STDERR " --cxxtest=DIR Assume CxxTest is installed in DIR (default: '..\\..')\n";
print STDERR " --tests=SPEC Use SPEC for the test files (default: '../gui/*.h ../*.h')\n\n";
print STDERR "You must specify at least one option.\n";
exit -1;
}
my ($cxxtest, $tests);
my ($Makefile, $CxxTest_2_Build);
sub main {
parseCommandline();
fixFiles();
}
sub parseCommandline() {
GetOptions( 'cxxtest=s' => \$cxxtest,
'tests=s' => \$tests,
) or usage();
usage() unless (defined($cxxtest) || defined($tests));
$cxxtest = '..\\..' unless defined($cxxtest);
$tests = '../gui/*.h ../*.h' unless defined($tests);
}
sub fixFiles() {
fixFile( $Makefile, 'Makefile' );
fixFile( $CxxTest_2_Build, 'CxxTest_2_Build.dsp' );
}
sub fixFile($$) {
my ($data, $output) = @_;
print "$output...";
$data =~ s/<TESTS>/$tests/g;
$data =~ s/<CXXTEST>/$cxxtest/g;
open OUTPUT, ">$output" or die "Cannot create output file \"$output\"\n";
print OUTPUT $data;
close OUTPUT;
print "OK\n";
}
$Makefile =
'# Where to look for the tests
TESTS = <TESTS>
# Where the CxxTest distribution is unpacked
CXXTESTDIR = <CXXTEST>
# Check CXXTESTDIR
!if !exist($(CXXTESTDIR)\bin\cxxtestgen)
!error Please fix CXXTESTDIR
!endif
# cxxtestgen needs Python
!if defined(PYTHON)
CXXTESTGEN = $(PYTHON) $(CXXTESTDIR)/bin/cxxtestgen
!else
!error You must define PYTHON
!endif
# The arguments to pass to cxxtestgen
# - ParenPrinter is the way MSVC likes its compilation errors
# - --have-eh/--abort-on-fail are nice when you have them
CXXTESTGEN_FLAGS = --gui=Win32Gui --runner=ParenPrinter --have-eh --abort-on-fail
# How to generate the test runner, "runner.cpp"
runner.cpp: $(TESTS)
$(CXXTESTGEN) $(CXXTESTGEN_FLAGS) -o $@ $(TESTS)
# Command-line arguments to the runner
RUNNER_FLAGS = -title "CxxTest Runner"
# How to run the tests, which should be in DIR\runner.exe
run: $(DIR)\runner.exe
$(DIR)\runner.exe $(RUNNER_FLAGS)
';
$CxxTest_2_Build =
'# Microsoft Developer Studio Project File - Name="CxxTest_2_Build" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=CxxTest_2_Build - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_2_Build.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "CxxTest_2_Build.mak" CFG="CxxTest_2_Build - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "CxxTest_2_Build - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "CxxTest_2_Build - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "CxxTest_2_Build - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "<CXXTEST>" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x40d /d "NDEBUG"
# ADD RSC /l 0x40d /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Release/runner.exe"
!ELSEIF "$(CFG)" == "CxxTest_2_Build - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "<CXXTEST>" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x40d /d "_DEBUG"
# ADD RSC /l 0x40d /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/runner.exe" /pdbtype:sept
!ENDIF
# Begin Target
# Name "CxxTest_2_Build - Win32 Release"
# Name "CxxTest_2_Build - Win32 Debug"
# Begin Source File
SOURCE=.\ReadMe.txt
# End Source File
# Begin Source File
SOURCE=.\runner.cpp
# End Source File
# End Target
# End Project
';
main();
__END__
:endofperl
rem
rem Local Variables:
rem compile-command: "perl FixFiles.bat"
rem End:
rem

View File

@@ -0,0 +1,34 @@
# Where to look for the tests
TESTS = ..\gui\*.h ..\*.h
# Where the CxxTest distribution is unpacked
CXXTESTDIR = ..\..
# Check CXXTESTDIR
!if !exist($(CXXTESTDIR)\bin\cxxtestgen)
!error Please fix CXXTESTDIR
!endif
# cxxtestgen needs Perl or Python
!if defined(PYTHON)
CXXTESTGEN = $(PYTHON) $(CXXTESTDIR)/bin/cxxtestgen
!else
!error You must define PERL or PYTHON
!endif
# The arguments to pass to cxxtestgen
# - ParenPrinter is the way MSVC likes its compilation errors
# - --have-eh/--abort-on-fail are nice when you have them
CXXTESTGEN_FLAGS = \
--gui=Win32Gui \
--runner=ParenPrinter \
--have-eh \
--abort-on-fail
# How to generate the test runner, `runner.cpp'
runner.cpp: $(TESTS)
$(CXXTESTGEN) $(CXXTESTGEN_FLAGS) -o $@ $(TESTS)
# How to run the tests, which should be in DIR\runner.exe
run: $(DIR)\runner.exe
$(DIR)\runner.exe

View File

@@ -0,0 +1,30 @@
Sample files for Visual Studio
==============================
There are three projects in this workspace:
- CxxTest_3_Generate runs cxxtestgen to create runner.cpp
- CxxTest_2_Build compiles the generated file
- CxxTest_1_Run runs the compiled binary
Whenever you build this workspace, the tests are run, and any failed assertions
are displayed as compilation errors (you can browse them using F4).
Note that to run this sample, you need first to create an environment
variable PYTHON, e.g. Python=c:\Python25\bin\python.exe
To use these .dsp and .dsw files in your own project, run FixFiles.bat
to adjust them to where you've placed CxxTest and your own tests.
If you want to use just the .dsp files in your own workspace, don't
forget to:
- Set up the dependencies (CxxTest_3_Generate depends on
CxxTest_2_Build which depends on CxxTest_1_Run)
- Add your own include paths, libraries etc. to the CxxTest_2_Build project
NOTE: I haven't used "Post-Build Step" to run the tests because I
wanted the tests to be executed even if nothing has changed.

View File

@@ -0,0 +1,33 @@
// -*- C++ -*-
#include <cxxtest/StdioPrinter.h>
#include <stdio.h>
int main( int argc, char *argv[] )
{
if ( argc < 2 || argc > 3 ) {
fprintf( stderr, "Usage: only <suite name> [<test name>]\n\n" );
fprintf( stderr, "Available tests:\n" );
CxxTest::RealWorldDescription wd;
for ( CxxTest::SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() )
for ( CxxTest::TestDescription *td = sd->firstTest(); td; td = td->next() )
fprintf( stderr, " - %s::%s()\n", sd->suiteName(), td->testName() );
return 1;
}
const char *suiteName = argv[1];
const char *testName = (argc > 2) ? argv[2] : 0;
if ( !CxxTest::leaveOnly( suiteName, testName ) ) {
if ( testName )
fprintf( stderr, "Cannot find %s::%s()\n", argv[1], argv[2] );
else
fprintf( stderr, "Cannot find class %s\n", argv[1] );
return 2;
}
return CxxTest::StdioPrinter().run();
}
// The CxxTest "world"
<CxxTest world>

View File

@@ -0,0 +1,39 @@
#
# (GNU) Makefile for UN*X-like systems
# This makefile shows how to make a different runner for each test
#
.PHONY: all clean
all: run
clean:
rm -f *~ *.cpp *.o runner
CXXTESTDIR = ../..
CXXTESTGEN = $(CXXTESTDIR)/bin/cxxtestgen
CXXTESTFLAGS = --have-eh --abort-on-fail
TESTS = $(wildcard ../*Test.h)
OBJS = runner.o $(TESTS:../%.h=%.o)
run: runner
./runner
runner: $(OBJS)
c++ -o $@ $^
%.o: %.cpp
c++ -c -o $@ -I $(CXXTESTDIR) -I .. $^
%.cpp: ../%.h
$(CXXTESTGEN) $(CXXTESTFLAGS) --part -o $@ $^
runner.cpp:
$(CXXTESTGEN) $(CXXTESTFLAGS) --root --error-printer -o $@
#
# Local Variables:
# compile-command: "make -fMakefile.unix"
# End:
#

View File

@@ -0,0 +1,2 @@
# Standard DDK Makefile
!include $(NTMAKEENV)\makefile.def

View File

@@ -0,0 +1,13 @@
# -*- Makefile -*-
#
# Tell the DDK how to generate RunTests.cpp from RunTests.tpl and the tests
#
PYTHON=python
CXXTESTGEN=$(PYTHON) $(CXXTESTDIR)/bin/cxxtestgen
TEST_SUITES=$(SUITESDIR)/*.h
RunTests.cpp: RunTests.tpl $(TEST_SUITES)
$(CXXTESTGEN) -o $@ --template=RunTests.tpl $(TEST_SUITES)

View File

@@ -0,0 +1,13 @@
// -*- C++ -*-
//
// The DDK doesn't handle <iostream> too well
//
#include <cxxtest/StdioPrinter.h>
int __cdecl main()
{
return CxxTest::StdioPrinter().run();
}
<CxxTest world>

View File

@@ -0,0 +1,46 @@
# -*- Makefile -*-
#
# Build this sample with the Windows DDK (XP or later)
#
SUITESDIR=..
CXXTESTDIR=../..
#
# Build a user-mode application
#
TARGETNAME=RunTests
TARGETPATH=.
TARGETTYPE=PROGRAM
#
# Make it a console-mode app
#
UMTYPE=console
#
# Add CxxTest and tests directory to include path
#
INCLUDES=$(SUITESDIR);$(CXXTESTDIR)
#
# Enable exception handling and standard library
#
USE_NATIVE_EH=1
LINKER_FLAGS=$(LINKER_FLAGS) -IGNORE:4099
386_WARNING_LEVEL=-W3 -WX -wd4290
TARGETLIBS=\
$(CRT_LIB_PATH)\libcp.lib \
$(CRT_LIB_PATH)\libc.lib
#
# Only one source file -- the generated test runner
#
SOURCES=RunTests.cpp
#
# This line tells the build utility to process Makefile.inc
#
NTTARGETFILE0=RunTests.cpp

View File

@@ -0,0 +1,10 @@
//
// A sample program that uses class YesNoRunner to run all the tests
// and find out if all pass.
//
#include <cxxtest/YesNoRunner.h>
int main() {
return CxxTest::YesNoRunner().run();
}