forked from CxxTest/cxxtest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy the v3 branch back to trunk since this is where most development
has been happening. git-svn-id: https://cxxtest.svn.sourceforge.net/svnroot/cxxtest/trunk@47 2f8b185b-e3eb-40a7-945f-4de83c84e57e
- Loading branch information
Showing
46 changed files
with
2,093 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.consign | ||
Makefile | ||
*_runner* | ||
tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp | ||
error_printer stdio_printer file_printer aborter only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 => 'perl -w ../cxxtestgen.pl' ); | ||
|
||
@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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#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 ); | ||
} | ||
}; | ||
|
||
#endif // __DELTATEST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// 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 ); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#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) ); | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = perl -w ../cxxtestgen.pl | ||
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: | ||
# |
Oops, something went wrong.