├── doc ├── examples │ ├── buildRunner5.txt │ ├── buildRunner.log │ ├── buildRunner.txt │ ├── buildRunner14.txt │ ├── buildRunner16.txt │ ├── buildRunner23.txt │ ├── GetGlobals.sh │ ├── buildRunner11.txt │ ├── buildRunner12.txt │ ├── buildRunner22.txt │ ├── buildRunner24.txt │ ├── buildRunner25.txt │ ├── time_mock.cpp │ ├── time_real.cpp │ ├── rand_example.cpp │ ├── buildRunner18.txt │ ├── runner13.help.txt │ ├── buildRunner2.txt │ ├── buildRunner3.txt │ ├── buildRunner4.txt │ ├── buildRunner7.txt │ ├── buildRunner20.txt │ ├── buildRunner21.txt │ ├── runner13.helpTests.txt │ ├── buildRunner15.txt │ ├── buildRunner2.log │ ├── buildRunner10.txt │ ├── runner13.MyTestSuite2.txt │ ├── runner13.testMultiplication.txt │ ├── MyTestSuite1.h │ ├── MyTestSuite4.h │ ├── buildRunner14.sh │ ├── buildRunner15.sh │ ├── buildRunner7.sh │ ├── buildRunner17.sh │ ├── buildRunner18.sh │ ├── buildRunner19.sh │ ├── buildRunner3.sh │ ├── buildRunner4.sh │ ├── buildRunner6.sh │ ├── buildRunner10.sh │ ├── buildRunner11.sh │ ├── buildRunner12.sh │ ├── buildRunner20.sh │ ├── buildRunner21.sh │ ├── buildRunner23.sh │ ├── buildRunner22.sh │ ├── buildRunner24.sh │ ├── buildRunner5.sh │ ├── time_mock.h │ ├── buildRunner16.sh │ ├── buildRunner2.sh │ ├── buildRunner.sh │ ├── buildRunner8.sh │ ├── buildRunner17.txt │ ├── runner10.tpl │ ├── MyTestSuite10.h │ ├── MyTestSuite11.h │ ├── BadTestSuite1.h │ ├── buildRunner19.txt │ ├── buildRunner6.txt │ ├── runner13.testMultiplicationVerbose.txt │ ├── MyTestSuite2.h │ ├── MyTestSuite12.h │ ├── buildRunner25.sh │ ├── MyTestSuite6.h │ ├── buildRunner9.sh │ ├── Namespace2.h │ ├── Namespace1.h │ ├── MockTestSuite.h │ ├── MyTestSuite3.h │ ├── MyTestSuite5.h │ ├── MyTestSuite7.h │ ├── MyTestSuite9.h │ ├── MyClass.h │ ├── buildRunner13.sh │ ├── TMyClass.h │ └── MyTestSuite8.h ├── images │ └── icons │ │ ├── tip.png │ │ ├── up.png │ │ ├── home.png │ │ ├── next.png │ │ ├── note.png │ │ ├── prev.png │ │ ├── caution.png │ │ ├── example.png │ │ ├── warning.png │ │ ├── callouts │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 13.png │ │ ├── 14.png │ │ ├── 15.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ │ ├── important.png │ │ └── README ├── catalog.xml ├── epub │ └── bin │ │ └── xslt │ │ └── obfuscate.xsl ├── README.txt └── Makefile ├── python ├── cxxtest │ ├── .gitignore │ ├── __release__.py │ └── __init__.py ├── python3 │ ├── scripts │ │ └── cxxtestgen │ └── cxxtest │ │ ├── __release__.py │ │ └── __init__.py ├── README.txt ├── scripts │ └── cxxtestgen ├── convert.py └── setup.py ├── test ├── fake │ ├── .cvsignore │ ├── X11 │ │ └── Xutil.h │ ├── qpixmap.h │ ├── qglobal.h │ ├── qlayout.h │ ├── qlabel.h │ ├── qmessagebox.h │ ├── qstatusbar.h │ ├── qapplication.h │ ├── qstring.h │ ├── qprogressbar.h │ ├── qwidget.h │ └── commctrl.h ├── runner.out ├── throw.out ├── parts.out ├── template.out ├── .cvsignore ├── good.out ├── simple_inheritance.out ├── simple_inheritance2.out ├── Something.h ├── DefaultAbort.h ├── GuiWait.h ├── anything.cpp ├── namespace.out ├── wildcard.out ├── comments.out ├── comments2.out ├── MaxDump.h ├── suwf.out ├── suwt.out ├── gfxs.out ├── int64.cpp ├── tdwf.out ├── tdwt.out ├── longlong.cpp ├── include.out ├── stpltpl.cpp ├── user.out ├── gfsuf.out ├── gfsut.out ├── suwe.out ├── suite_test.out ├── ThrowNoStd.tpl ├── ThrowNoStd.h ├── wchar.cpp ├── std.out ├── NoEh.h ├── HaveEH.tpl ├── HaveStd.tpl ├── wchar.out ├── IncludeTest.h ├── HaveStd.h ├── int64.out ├── tpltpl.cpp ├── Makefile ├── LongTraits.h ├── ForceNoEh.h ├── UserTraits.tpl ├── Part1.h ├── Part2.h ├── gftdf.out ├── gftdt.out ├── longlong.out ├── Int64.h ├── unit │ ├── SConstruct │ └── LinkedList_test.t.h ├── VoidTraits.h ├── LongLong.h ├── Comments2.h ├── EmptySuite.h ├── AborterNoThrow.h ├── activate.tpl ├── Comments.h ├── nullptr_guards.out ├── infinite.out ├── WideCharTest.h ├── __init__.py ├── LessThanEquals.h ├── TearDownWorldFails.h ├── TearDownWorldThrows.h ├── preamble.tpl ├── GfSetUpFails.h ├── GfSetUpThrows.h ├── GfTearDownFails.h ├── GfTearDownThrows.h ├── SetUpWorldFails.h ├── SetUpWorldThrows.h ├── SimpleInheritedTest.h ├── SameZero.h ├── SimpleInheritedTest2.h ├── SetUpWorldError.h ├── NullPtrGuards.h ├── CppTemplateTest.h ├── gui.out ├── gui_paren.out ├── DoubleCall.h ├── DefaultTraits.h ├── UserTraits.h ├── main.cpp ├── SameData.h ├── char_assertions.out ├── SameFiles.h ├── WorldFixtures.h ├── SameFilesLonger.h ├── bad.out ├── cxxtest │ └── DummyGui.h ├── TestNonFinite.h ├── Relation.h ├── test_doc.py ├── DynamicAbort.h ├── suite.out ├── BadTest.h ├── InheritedTest.h ├── DynamicMax.h ├── TraitsTest.h ├── Exceptions.h ├── Namespace1.h ├── Factor.h ├── Tsm.h ├── Namespace2.h ├── stl.out ├── GlobalFixtures.h ├── eh_normals.out ├── inheritance.out └── factor.out ├── sample ├── parts │ ├── .cvsignore │ └── Makefile.unix ├── winddk │ ├── Makefile │ ├── RunTests.tpl │ ├── Makefile.inc │ └── SOURCES ├── mock │ ├── mock_stdlib.cpp │ ├── real_stdlib.cpp │ ├── Dice.h │ ├── Dice.cpp │ ├── roll.cpp │ ├── T │ │ └── stdlib.h │ ├── Makefile │ ├── MockStdlib.h │ └── TestDice.h ├── .cvsignore ├── yes_no_runner.cpp ├── aborter.tpl ├── file_printer.tpl ├── SCons │ ├── include │ │ └── stack.h │ ├── src │ │ └── stack.c │ ├── tests │ │ └── stack_test.h │ └── SConstruct ├── DeltaTest.h ├── MessageTest.h ├── Makefile.PL ├── FixtureTest.h ├── CreatedTest.h ├── EnumTraits.h ├── msvc │ ├── Makefile │ ├── ReadMe.txt │ └── CxxTest_Workspace.dsw ├── only.tpl ├── gui │ └── GreenYellowRed.h ├── SimpleTest.h ├── ExceptionTest.h ├── TraitsTest.h ├── Makefile.unix └── Construct ├── bin ├── cxxtestgen.bat └── cxxtestgen ├── .gitignore ├── cxxtest ├── SelfTest.h ├── Root.cpp ├── ParenPrinter.h ├── StdHeaders.h ├── YesNoRunner.h ├── StdioPrinter.h ├── GlobalFixture.h ├── XUnitPrinter.h ├── GlobalFixture.cpp ├── MSVCErrorPrinter.h ├── LinkedList.h ├── StdioFilePrinter.h ├── StdTestSuite.h ├── XmlPrinter.h ├── Descriptions.cpp └── ErrorPrinter.h ├── admin ├── cxxtest.spec ├── announcement └── cloudbees_cxxtest └── README /doc/examples/buildRunner5.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /python/cxxtest/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /test/fake/.cvsignore: -------------------------------------------------------------------------------- 1 | *.cpp *_runner* -------------------------------------------------------------------------------- /test/runner.out: -------------------------------------------------------------------------------- 1 | Error level = 12 2 | -------------------------------------------------------------------------------- /sample/parts/.cvsignore: -------------------------------------------------------------------------------- 1 | *.cpp *.o runner -------------------------------------------------------------------------------- /test/fake/X11/Xutil.h: -------------------------------------------------------------------------------- 1 | // Fake Xutil.h 2 | -------------------------------------------------------------------------------- /test/fake/qpixmap.h: -------------------------------------------------------------------------------- 1 | // fake qpixmap.h 2 | 3 | -------------------------------------------------------------------------------- /doc/examples/buildRunner.log: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test).OK! 2 | -------------------------------------------------------------------------------- /doc/examples/buildRunner.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test).OK! 2 | -------------------------------------------------------------------------------- /doc/examples/buildRunner14.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests)..OK! 2 | -------------------------------------------------------------------------------- /doc/examples/buildRunner16.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test).OK! 2 | -------------------------------------------------------------------------------- /doc/examples/buildRunner23.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests)..OK! 2 | -------------------------------------------------------------------------------- /test/fake/qglobal.h: -------------------------------------------------------------------------------- 1 | // fake qglobal.h 2 | #define QT_VERSION 0x030000 3 | -------------------------------------------------------------------------------- /test/throw.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test).OK! 2 | Error level = 0 3 | -------------------------------------------------------------------------------- /test/parts.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests)..OK! 2 | Error level = 0 3 | -------------------------------------------------------------------------------- /test/template.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests)..OK! 2 | Error level = 0 3 | -------------------------------------------------------------------------------- /bin/cxxtestgen.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem Just run the python script 3 | python %0 %* 4 | -------------------------------------------------------------------------------- /sample/winddk/Makefile: -------------------------------------------------------------------------------- 1 | # Standard DDK Makefile 2 | !include $(NTMAKEENV)\makefile.def 3 | -------------------------------------------------------------------------------- /test/.cvsignore: -------------------------------------------------------------------------------- 1 | *pl.cpp *py.cpp *pl.out *py.out *px *px.exe *px.out *build.log *root.cpp 2 | -------------------------------------------------------------------------------- /test/good.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (18 tests)..................OK! 2 | Error level = 0 3 | -------------------------------------------------------------------------------- /test/simple_inheritance.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (4 tests)....OK! 2 | Error level = 0 3 | -------------------------------------------------------------------------------- /test/simple_inheritance2.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests)..OK! 2 | Error level = 0 3 | -------------------------------------------------------------------------------- /sample/mock/mock_stdlib.cpp: -------------------------------------------------------------------------------- 1 | #define CXXTEST_MOCK_TEST_SOURCE_FILE 2 | #include 3 | -------------------------------------------------------------------------------- /sample/mock/real_stdlib.cpp: -------------------------------------------------------------------------------- 1 | #define CXXTEST_MOCK_REAL_SOURCE_FILE 2 | #include 3 | -------------------------------------------------------------------------------- /doc/examples/GetGlobals.sh: -------------------------------------------------------------------------------- 1 | if [[ "x$CXXTEST" -eq "x" ]] 2 | then 3 | CXXTEST="../../" 4 | fi 5 | -------------------------------------------------------------------------------- /doc/images/icons/tip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/tip.png -------------------------------------------------------------------------------- /doc/images/icons/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/up.png -------------------------------------------------------------------------------- /test/Something.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | inline std::string something() { return "something"; } 4 | -------------------------------------------------------------------------------- /doc/examples/buildRunner11.txt: -------------------------------------------------------------------------------- 1 | Parsing file MyTestSuite3.h done. 2 | Running cxxtest tests (1 test).OK! 3 | -------------------------------------------------------------------------------- /doc/examples/buildRunner12.txt: -------------------------------------------------------------------------------- 1 | Parsing file MyTestSuite4.h done. 2 | Running cxxtest tests (1 test).OK! 3 | -------------------------------------------------------------------------------- /doc/examples/buildRunner22.txt: -------------------------------------------------------------------------------- 1 | Parsing file Namespace1.h done. 2 | Running cxxtest tests (2 tests)..OK! 3 | -------------------------------------------------------------------------------- /doc/examples/buildRunner24.txt: -------------------------------------------------------------------------------- 1 | Parsing file Namespace2.h done. 2 | Running cxxtest tests (2 tests)..OK! 3 | -------------------------------------------------------------------------------- /doc/images/icons/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/home.png -------------------------------------------------------------------------------- /doc/images/icons/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/next.png -------------------------------------------------------------------------------- /doc/images/icons/note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/note.png -------------------------------------------------------------------------------- /doc/images/icons/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/prev.png -------------------------------------------------------------------------------- /doc/examples/buildRunner25.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test).OK! 2 | Non-CxxTest stuff is happening now. 3 | -------------------------------------------------------------------------------- /doc/images/icons/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/caution.png -------------------------------------------------------------------------------- /doc/images/icons/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/example.png -------------------------------------------------------------------------------- /doc/images/icons/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/warning.png -------------------------------------------------------------------------------- /doc/examples/time_mock.cpp: -------------------------------------------------------------------------------- 1 | // time_mock.cpp 2 | #define CXXTEST_MOCK_TEST_SOURCE_FILE 3 | #include 4 | -------------------------------------------------------------------------------- /doc/examples/time_real.cpp: -------------------------------------------------------------------------------- 1 | // time_real.cpp 2 | #define CXXTEST_MOCK_REAL_SOURCE_FILE 3 | #include 4 | -------------------------------------------------------------------------------- /doc/images/icons/callouts/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/1.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/10.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/11.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/12.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/13.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/14.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/15.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/2.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/3.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/4.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/5.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/6.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/7.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/8.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/callouts/9.png -------------------------------------------------------------------------------- /doc/images/icons/important.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textmate/cxxtest/master/doc/images/icons/important.png -------------------------------------------------------------------------------- /python/python3/scripts/cxxtestgen: -------------------------------------------------------------------------------- 1 | #! python 2 | 3 | import cxxtest.cxxtestgen 4 | 5 | cxxtest.cxxtestgen.main() 6 | -------------------------------------------------------------------------------- /test/DefaultAbort.h: -------------------------------------------------------------------------------- 1 | #define CXXTEST_HAVE_EH 2 | #define CXXTEST_ABORT_TEST_ON_FAIL 3 | #define CXXTEST_DEFAULT_ABORT false 4 | -------------------------------------------------------------------------------- /test/GuiWait.h: -------------------------------------------------------------------------------- 1 | #ifndef __GUI_WAIT_H 2 | #define __GUI_WAIT_H 3 | 4 | #define CXXTEST_SAMPLE_GUI_WAIT() 5 | 6 | #endif // __GUI_WAIT_H 7 | -------------------------------------------------------------------------------- /test/anything.cpp: -------------------------------------------------------------------------------- 1 | // This simple source file is just used to verify that the compiler works 2 | 3 | int main() 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/namespace.out: -------------------------------------------------------------------------------- 1 | Number of suites: 2 2 | Number of tests: 8 3 | Number of failed tests: 7 4 | Number of skipped tests: 0 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /test/wildcard.out: -------------------------------------------------------------------------------- 1 | Number of suites: 8 2 | Number of tests: 16 3 | Number of failed tests: 12 4 | Number of skipped tests: 1 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /test/comments.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In Comments::test_Something: 3 | Comments.h:12: Warning: Something 4 | .OK! 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /test/comments2.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In Comments::test_Something: 3 | Comments2.h:12: Warning: Something 4 | .OK! 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /test/fake/qlayout.h: -------------------------------------------------------------------------------- 1 | // fake qlayout.h 2 | 3 | class QVBoxLayout 4 | { 5 | public: 6 | QVBoxLayout(void *) {} 7 | void addWidget(void *) {} 8 | }; 9 | -------------------------------------------------------------------------------- /doc/examples/rand_example.cpp: -------------------------------------------------------------------------------- 1 | // rand_example.cpp 2 | #include 3 | 4 | int generateRandomNumber() 5 | { 6 | return T::time(NULL) * 3; 7 | } 8 | -------------------------------------------------------------------------------- /test/MaxDump.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXXTEST_MAX_DUMP_SIZE is the maximum number of bytes to dump in TS_ASSERT_SAME_DATA 3 | // 4 | 5 | #define CXXTEST_MAX_DUMP_SIZE 20 6 | -------------------------------------------------------------------------------- /test/suwf.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In ::: 3 | RealDescriptions.cpp:5: Warning: Error setting up world 4 | OK! 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /test/suwt.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In ::: 3 | RealDescriptions.cpp:5: Warning: Error setting up world 4 | OK! 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /test/gfxs.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (6 tests)......OK! 2 | Error level = 0 3 | -------------------------------------------------------------------------------- /test/int64.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This program is used to check if the compiler supports __int64 3 | // 4 | int main() 5 | { 6 | __int64 ll = 0; 7 | return (int)ll; 8 | } 9 | -------------------------------------------------------------------------------- /test/tdwf.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test). 2 | In ::: 3 | RealDescriptions.cpp:5: Warning: Error tearing down world 4 | OK! 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /test/tdwt.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test). 2 | In ::: 3 | RealDescriptions.cpp:5: Warning: Error tearing down world 4 | OK! 5 | Error level = 0 6 | -------------------------------------------------------------------------------- /doc/examples/buildRunner18.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests)Starting a test suite 2 | Starting a test suite 3 | ..Finishing a test suite 4 | Finishing a test suite 5 | OK! 6 | -------------------------------------------------------------------------------- /test/longlong.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This program is used to check if the compiler supports "long long" 3 | // 4 | int main() 5 | { 6 | long long ll = 0; 7 | return (int)ll; 8 | } 9 | -------------------------------------------------------------------------------- /test/include.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In IncludesTest::testTraits: 3 | IncludeTest.h:12: Warning: (void *) 4 | IncludeTest.h:13: Warning: (long *) 5 | .OK! 6 | Error level = 0 7 | -------------------------------------------------------------------------------- /sample/mock/Dice.h: -------------------------------------------------------------------------------- 1 | #ifndef __DICE_H 2 | #define __DICE_H 3 | 4 | class Dice 5 | { 6 | public: 7 | Dice(); 8 | 9 | unsigned roll(); 10 | }; 11 | 12 | #endif // __DICE_H 13 | 14 | -------------------------------------------------------------------------------- /test/stpltpl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION 4 | int main() { return 0; } 5 | #endif // !_CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION 6 | 7 | -------------------------------------------------------------------------------- /sample/.cvsignore: -------------------------------------------------------------------------------- 1 | .consign 2 | Makefile 3 | *_runner* 4 | tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp 5 | error_printer stdio_printer file_printer aborter only 6 | -------------------------------------------------------------------------------- /doc/examples/runner13.help.txt: -------------------------------------------------------------------------------- 1 | ./runner 2 | ./runner 3 | ./runner -h 4 | ./runner --help 5 | ./runner --help-tests 6 | ./runner -v Enable tracing output. 7 | -------------------------------------------------------------------------------- /test/fake/qlabel.h: -------------------------------------------------------------------------------- 1 | // fake QLabel 2 | #include 3 | #include 4 | 5 | class QLabel 6 | { 7 | public: 8 | QLabel(void *) {} 9 | void setText(const QString &) {} 10 | }; 11 | -------------------------------------------------------------------------------- /test/fake/qmessagebox.h: -------------------------------------------------------------------------------- 1 | // fake qmessagebox.h 2 | 3 | class QMessageBox 4 | { 5 | public: 6 | enum Icon { Information, Warning, Critical }; 7 | static void *standardIcon(Icon) { return 0; } 8 | }; 9 | -------------------------------------------------------------------------------- /test/user.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In TestUserTraits::testUserTraits: 3 | UserTraits.h:34: Error: Test failed: 0x7F 4 | Failed 1 and Skipped 0 of 1 test 5 | Success rate: 0% 6 | Error level = 1 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.pyc 3 | *.bak 4 | .* 5 | guide.epub 6 | guide.pdf 7 | guide.html 8 | parsetab.py 9 | TEST-cxxtest.xml 10 | TestGpp_* 11 | TestClang_* 12 | TestGppPy_* 13 | *.dSYM 14 | TestCpp_* 15 | -------------------------------------------------------------------------------- /test/gfsuf.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In Suite::testOne: 3 | GfSetUpFails.h:24: Error: Test failed: Error in GlobalFixture::setUp() 4 | Failed 1 and Skipped 0 of 1 test 5 | Success rate: 0% 6 | Error level = 1 7 | -------------------------------------------------------------------------------- /test/gfsut.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In Suite::testOne: 3 | GfSetUpThrows.h:24: Error: Test failed: Error in GlobalFixture::setUp() 4 | Failed 1 and Skipped 0 of 1 test 5 | Success rate: 0% 6 | Error level = 1 7 | -------------------------------------------------------------------------------- /test/suwe.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests) 2 | In ::: 3 | SetUpWorldError.h:12: Error: Test failed: THIS IS BAD 4 | RealDescriptions.cpp:5: Warning: Error setting up world 5 | OK! 6 | Error level = 0 7 | -------------------------------------------------------------------------------- /test/suite_test.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In SimpleTest::testAddition: 3 | SimpleTest.h:23: Error: Expected (2 + 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 1 test 5 | Success rate: 0% 6 | Error level = 1 7 | -------------------------------------------------------------------------------- /doc/examples/buildRunner2.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite2::testMultiplication: 3 | MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /doc/examples/buildRunner3.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite2::testMultiplication: 3 | MyTestSuite2.h(16): Error: Expected (2 * 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /doc/examples/buildRunner4.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite2::testMultiplication: 3 | MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /doc/examples/buildRunner7.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite2::testMultiplication: 3 | MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /sample/mock/Dice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Dice.h" 3 | 4 | Dice::Dice() 5 | { 6 | T::srand(T::time(0)); 7 | } 8 | 9 | unsigned Dice::roll() 10 | { 11 | return (T::rand() % 6) + 1; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/ThrowNoStd.tpl: -------------------------------------------------------------------------------- 1 | #define CXXTEST_ABORT_TEST_ON_FAIL 2 | #include 3 | 4 | int main() 5 | { 6 | return CxxTest::ErrorPrinter().run(); 7 | } 8 | 9 | // The CxxTest "world" 10 | 11 | -------------------------------------------------------------------------------- /test/ThrowNoStd.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class ThrowNoStd : public CxxTest::TestSuite 4 | { 5 | public: 6 | void testThrowNoStd() 7 | { 8 | TS_ASSERT_THROWS( { throw 1; }, int); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /doc/examples/buildRunner20.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite10::test_eq: 3 | MyTestSuite10.h:17: Error: Expected (x == y), found (MyClass( 1 ) != MyClass( 2 )) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /test/fake/qstatusbar.h: -------------------------------------------------------------------------------- 1 | // fake qstatusbar.h 2 | 3 | class QStatusBar 4 | { 5 | public: 6 | QStatusBar(void *) {} 7 | void setProgress() {} 8 | void addWidget(void *, int) {} 9 | void removeWidget(void *) {} 10 | }; 11 | -------------------------------------------------------------------------------- /test/wchar.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This program is used to check if the compiler supports basic_string 3 | // 4 | #include 5 | 6 | int main() 7 | { 8 | std::basic_string s(L"s"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /sample/mock/roll.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Dice.h" 3 | 4 | int main() 5 | { 6 | Dice dice; 7 | printf("First roll: %u\n", dice.roll()); 8 | printf("Second roll: %u\n", dice.roll()); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/std.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In HaveStd::testHaveStd: 3 | HaveStd.h:13: Error: Expected (something() == "Something"), found ("something" != Something) 4 | Failed 1 and Skipped 0 of 1 test 5 | Success rate: 0% 6 | Error level = 1 7 | -------------------------------------------------------------------------------- /doc/examples/buildRunner21.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite11::test_eq: 3 | MyTestSuite11.h:17: Error: Expected (x == y), found (8TMyClassIiE( 1 ) != 8TMyClassIiE( 1 )) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /doc/examples/runner13.helpTests.txt: -------------------------------------------------------------------------------- 1 | Suite/Test Names 2 | --------------------------------------------------------------------------- 3 | MyTestSuite1 testAddition 4 | MyTestSuite2 testAddition 5 | MyTestSuite2 testMultiplication 6 | MyTestSuite4 testAddition 7 | -------------------------------------------------------------------------------- /doc/images/icons/README: -------------------------------------------------------------------------------- 1 | Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook 2 | icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency 3 | from the Jimmac icons to get round MS IE and FOP PNG incompatibilies. 4 | 5 | Stuart Rackham 6 | -------------------------------------------------------------------------------- /sample/yes_no_runner.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // A sample program that uses class YesNoRunner to run all the tests 3 | // and find out if all pass. 4 | // 5 | 6 | #include 7 | 8 | int main() { 9 | return CxxTest::YesNoRunner().run(); 10 | } 11 | -------------------------------------------------------------------------------- /doc/examples/buildRunner15.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In MyTestSuite6::: 3 | MyTestSuite6.h:8: Error: Test failed: createSuite() failed 4 | MyTestSuite6.h:8: Error: Assertion failed: suite() != 0 5 | Failed 1 and Skipped 0 of 1 test 6 | Success rate: 0% 7 | -------------------------------------------------------------------------------- /sample/winddk/RunTests.tpl: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | // 4 | // The DDK doesn't handle too well 5 | // 6 | #include 7 | 8 | int __cdecl main() 9 | { 10 | return CxxTest::StdioPrinter().run(); 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /doc/examples/buildRunner2.log: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite2::testMultiplication: 3 | /Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /doc/examples/buildRunner10.txt: -------------------------------------------------------------------------------- 1 | Starting test runner 2 | Running cxxtest tests (2 tests). 3 | In MyTestSuite2::testMultiplication: 4 | MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 5 | Failed 1 and Skipped 0 of 2 tests 6 | Success rate: 50% 7 | Stopping test runner 8 | -------------------------------------------------------------------------------- /test/NoEh.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class NoEh : public CxxTest::TestSuite 4 | { 5 | public: 6 | void testCxxTestCanCompileWithoutExceptionHandling() 7 | { 8 | TS_ASSERT_EQUALS(1, 2); 9 | TS_ASSERT_EQUALS(2, 3); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /doc/examples/runner13.MyTestSuite2.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests). 2 | In MyTestSuite2::testMultiplication: 3 | /Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 2 tests 5 | Success rate: 50% 6 | -------------------------------------------------------------------------------- /doc/examples/runner13.testMultiplication.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In MyTestSuite2::testMultiplication: 3 | /Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 4 | Failed 1 and Skipped 0 of 1 test 5 | Success rate: 0% 6 | -------------------------------------------------------------------------------- /python/README.txt: -------------------------------------------------------------------------------- 1 | CxxTest Python Package 2 | ====================== 3 | 4 | The CxxTest Python package includes utilities that are used by the 5 | CxxTest unit testing framework. Specifically, this Python package 6 | supports C++ parsing and code generation done in the cxxtestgen 7 | script. 8 | 9 | -------------------------------------------------------------------------------- /test/HaveEH.tpl: -------------------------------------------------------------------------------- 1 | #define CXXTEST_HAVE_EH 2 | #include 3 | 4 | int main( int argc, char *argv[] ) { 5 | CxxTest::ErrorPrinter tmp; 6 | return CxxTest::Main( tmp, argc, argv ); 7 | } 8 | 9 | // The CxxTest "world" 10 | 11 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite1.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite1.h 2 | #include 3 | 4 | class MyTestSuite1 : public CxxTest::TestSuite 5 | { 6 | public: 7 | void testAddition(void) 8 | { 9 | TS_ASSERT(1 + 1 > 1); 10 | TS_ASSERT_EQUALS(1 + 1, 2); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /test/HaveStd.tpl: -------------------------------------------------------------------------------- 1 | #define CXXTEST_HAVE_STD 2 | #include 3 | 4 | int main( int argc, char *argv[] ) { 5 | CxxTest::ErrorPrinter tmp; 6 | return CxxTest::Main( tmp, argc, argv ); 7 | } 8 | 9 | // The CxxTest "world" 10 | 11 | -------------------------------------------------------------------------------- /test/wchar.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In WideCharTest::testWideStringTraits: 3 | WideCharTest.h:14: Error: Test failed: L"std::wstring is displayed with L\"\"" 4 | WideCharTest.h:16: Error: Test failed: L"\x1234\x5678" 5 | Failed 1 and Skipped 0 of 1 test 6 | Success rate: 0% 7 | Error level = 1 8 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite4.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite4.h 2 | #include 3 | 4 | class MyTestSuite4 5 | : 6 | public CxxTest::TestSuite 7 | { 8 | public: 9 | void testAddition(void) 10 | { 11 | TS_ASSERT(1 + 1 > 1); 12 | TS_ASSERT_EQUALS(1 + 1, 2); 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /test/IncludeTest.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This is a test for the --include option 5 | // 6 | 7 | class IncludesTest : public CxxTest::TestSuite 8 | { 9 | public: 10 | void testTraits() 11 | { 12 | TS_WARN((void *)0); 13 | TS_WARN((long *)0); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner14.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite5.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner15.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite6.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner7.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --xunit-printer -o runner.cpp MyTestSuite2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /test/HaveStd.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This tests CxxTest's `--have-std' option 5 | // 6 | #include "Something.h" 7 | 8 | class HaveStd : public CxxTest::TestSuite 9 | { 10 | public: 11 | void testHaveStd() 12 | { 13 | TS_ASSERT_EQUALS(something(), "Something"); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner17.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite7.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner18.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite8.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner19.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite9.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --runner=ParenPrinter -o runner.cpp MyTestSuite2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --runner=StdioPrinter -o runner.cpp MyTestSuite2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --runner=XmlPrinter -o runner.cpp MyTestSuite2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen -o runner.cpp --template runner10.tpl MyTestSuite2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner11.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | 5 | export PATH=$CXXTEST/bin:$PATH 6 | 7 | # @main: 8 | cxxtestgen -f --error-printer -o runner.cpp MyTestSuite3.h 9 | # @:main 10 | 11 | # @compile: 12 | g++ -o runner -I$CXXTEST runner.cpp 13 | # @:compile 14 | 15 | ./runner 16 | \rm -f runner runner.cpp 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner12.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | 5 | export PATH=$CXXTEST/bin:$PATH 6 | 7 | # @main: 8 | cxxtestgen -f --error-printer -o runner.cpp MyTestSuite4.h 9 | # @:main 10 | 11 | # @compile: 12 | g++ -o runner -I$CXXTEST runner.cpp 13 | # @:compile 14 | 15 | ./runner 16 | \rm -f runner runner.cpp 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner20.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite10.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST -I. runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner21.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite11.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST -I. runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner23.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp Namespace2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST -I. runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner22.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --fog --error-printer -o runner.cpp Namespace1.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST -I. runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | #\rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner24.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --fog --error-printer -o runner.cpp Namespace2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST -I. runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | 17 | -------------------------------------------------------------------------------- /test/int64.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In Int64::testInt64: 3 | Int64.h:12: Error: Expected ((__int64)1 == (__int64)2), found (1 != 2) 4 | Int64.h:13: Error: Expected ((__int64)3 != (__int64)3), found (3) 5 | Int64.h:14: Error: Expected ((__int64)5 < (__int64)4), found (5 >= 4) 6 | Failed 1 of 1 test 7 | Success rate: 0% 8 | Error level = 1 9 | -------------------------------------------------------------------------------- /test/tpltpl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION 4 | template class X {} x; 5 | template class Pair {} p; 6 | template class X< Pair > {} xp; 7 | 8 | int main() { return 0; } 9 | #endif // !_CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION 10 | 11 | -------------------------------------------------------------------------------- /doc/examples/buildRunner5.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --runner=YesNoRunner -o runner.cpp MyTestSuite2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner 15 | echo $? 16 | 17 | \rm -f runner runner.cpp 18 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Some convenient ways of running the self tests 3 | # 4 | 5 | all: 6 | lpython test_cxxtest.py 7 | 8 | clean: 9 | 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 10 | rm -Rf *.dSYM 11 | 12 | -------------------------------------------------------------------------------- /doc/examples/time_mock.h: -------------------------------------------------------------------------------- 1 | // time_mock.h 2 | #include 3 | #include 4 | 5 | CXXTEST_MOCK_GLOBAL(time_t, /* Return type */ 6 | time, /* Name of the function */ 7 | (time_t *t), /* Prototype */ 8 | (t) /* Argument list */); 9 | -------------------------------------------------------------------------------- /test/LongTraits.h: -------------------------------------------------------------------------------- 1 | // 2 | // This include file is used to test the --include option 3 | // 4 | 5 | #include 6 | 7 | namespace CxxTest 8 | { 9 | CXXTEST_TEMPLATE_INSTANTIATION 10 | class ValueTraits 11 | { 12 | public: 13 | ValueTraits(long *) {} 14 | const char *asString() { return "(long *)"; } 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /test/fake/qapplication.h: -------------------------------------------------------------------------------- 1 | // fake QApplication 2 | 3 | class QWidget; 4 | 5 | class QApplication 6 | { 7 | public: 8 | QApplication(int &, char **) {} 9 | void exec() {} 10 | void setMainWidget(void *) {} 11 | void processEvents() {} 12 | static QWidget *desktop() { return 0; } 13 | void *activeWindow() { return 0; } 14 | }; 15 | -------------------------------------------------------------------------------- /doc/examples/buildRunner16.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MockTestSuite.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I. -I$CXXTEST runner.cpp time_mock.cpp rand_example.cpp 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite2.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner > buildRunner2.log 15 | cat buildRunner2.log 16 | \rm -f runner runner.cpp 17 | -------------------------------------------------------------------------------- /sample/aborter.tpl: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // This template file demonstrates the use of CXXTEST_ABORT_TEST_ON_FAIL 3 | // 4 | 5 | #define CXXTEST_HAVE_STD 6 | #define CXXTEST_ABORT_TEST_ON_FAIL 7 | #include 8 | 9 | int main() 10 | { 11 | return CxxTest::ErrorPrinter().run(); 12 | } 13 | 14 | // The CxxTest "world" 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/ForceNoEh.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class ForceNoEh : public CxxTest::TestSuite 4 | { 5 | public: 6 | void testCxxTestCanCompileWithoutExceptionHandling() 7 | { 8 | TS_ASSERT_EQUALS(1, 2); 9 | TS_ASSERT_EQUALS(2, 3); 10 | TS_ASSERT_THROWS_NOTHING(foo()); 11 | } 12 | 13 | void foo() 14 | { 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /doc/examples/buildRunner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite1.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner > buildRunner.log 15 | # @run: 16 | ./runner 17 | # @:run 18 | \rm -f runner runner.cpp 19 | -------------------------------------------------------------------------------- /sample/winddk/Makefile.inc: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | 3 | # 4 | # Tell the DDK how to generate RunTests.cpp from RunTests.tpl and the tests 5 | # 6 | 7 | PYTHON=python 8 | CXXTESTGEN=$(PYTHON) $(CXXTESTDIR)/bin/cxxtestgen 9 | 10 | TEST_SUITES=$(SUITESDIR)/*.h 11 | 12 | RunTests.cpp: RunTests.tpl $(TEST_SUITES) 13 | $(CXXTESTGEN) -o $@ --template=RunTests.tpl $(TEST_SUITES) 14 | -------------------------------------------------------------------------------- /test/UserTraits.tpl: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // See UserTraits.h 3 | 4 | #define CXXTEST_USER_VALUE_TRAITS 5 | #include 6 | 7 | int main() 8 | { 9 | return CxxTest::ErrorPrinter().run(); 10 | } 11 | 12 | // The CxxTest "world" 13 | 14 | 15 | 16 | // 17 | // Local Variables: 18 | // compile-command: "perl test.pl" 19 | // End: 20 | // 21 | -------------------------------------------------------------------------------- /sample/mock/T/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __T__STDLIB_H 2 | #define __T__STDLIB_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | CXXTEST_MOCK_VOID_GLOBAL( srand, ( unsigned seed ), ( seed ) ); 10 | CXXTEST_MOCK_GLOBAL( int, rand, ( void ), () ); 11 | CXXTEST_MOCK_GLOBAL( time_t, time, ( time_t *t ), ( t ) ); 12 | 13 | #endif // __T__STDLIB_H 14 | -------------------------------------------------------------------------------- /test/Part1.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suite is used to test the root/part functionality of CxxTest. 5 | // 6 | 7 | class Part1 : public CxxTest::TestSuite 8 | { 9 | public: 10 | void testSomething() 11 | { 12 | TS_ASSERT_THROWS_NOTHING(throwNothing()); 13 | } 14 | 15 | void throwNothing() 16 | { 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /test/Part2.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suite is used to test the root/part functionality of CxxTest. 5 | // 6 | 7 | class Part2 : public CxxTest::TestSuite 8 | { 9 | public: 10 | void testSomething() 11 | { 12 | TS_ASSERT_THROWS_NOTHING(throwNothing()); 13 | } 14 | 15 | void throwNothing() 16 | { 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /test/gftdf.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests) 2 | In Suite::testOne: 3 | GfTearDownFails.h:24: Error: Test failed: Error in GlobalFixture::tearDown() 4 | In Suite::testTwo: 5 | GfTearDownFails.h:25: Warning: Testing should go on! 6 | GfTearDownFails.h:25: Error: Test failed: Error in GlobalFixture::tearDown() 7 | Failed 2 and Skipped 0 of 2 tests 8 | Success rate: 0% 9 | Error level = 2 10 | -------------------------------------------------------------------------------- /test/gftdt.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests) 2 | In Suite::testOne: 3 | GfTearDownThrows.h:24: Error: Test failed: Error in GlobalFixture::tearDown() 4 | In Suite::testTwo: 5 | GfTearDownThrows.h:25: Warning: Testing should go on! 6 | GfTearDownThrows.h:25: Error: Test failed: Error in GlobalFixture::tearDown() 7 | Failed 2 and Skipped 0 of 2 tests 8 | Success rate: 0% 9 | Error level = 2 10 | -------------------------------------------------------------------------------- /test/longlong.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In LongLongTest::testLongLong: 3 | LongLong.h:12: Error: Expected ((long long)1 == (long long)2), found (1 != 2) 4 | LongLong.h:13: Error: Expected ((long long)3 != (long long)3), found (3) 5 | LongLong.h:14: Error: Expected ((long long)5 < (long long)4), found (5 >= 4) 6 | Failed 1 and Skipped 0 of 1 test 7 | Success rate: 0% 8 | Error level = 1 9 | -------------------------------------------------------------------------------- /doc/examples/buildRunner8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --gui=X11Gui -o runner.cpp MyTestSuite2.h ../../sample/gui/GreenYellowRed.h 8 | # @:main 9 | 10 | # @compile: 11 | /opt/local/bin/g++-mp-4.4 -o runner -I$CXXTEST runner.cpp -L/opt/local/lib -lX11 12 | # @:compile 13 | 14 | ./runner 15 | \rm -f runner runner.cpp 16 | -------------------------------------------------------------------------------- /doc/examples/buildRunner17.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In MyTestSuite7::testCompareData: 3 | MyTestSuite7.h:28: Error: Expected (x == y), found ({ 12 12 12 } != { F6 F6 F6 }) 4 | MyTestSuite7.h:33: Error: Expected sizeof(z) (3) bytes to be equal at (&z) and (&w), found: 5 | { 12 12 12 } 6 | differs from 7 | { F6 F6 F6 } 8 | Failed 1 and Skipped 0 of 1 test 9 | Success rate: 0% 10 | -------------------------------------------------------------------------------- /test/Int64.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This tests CxxTest's handling of "__int64" 5 | // 6 | 7 | class Int64 : public CxxTest::TestSuite 8 | { 9 | public: 10 | void testInt64() 11 | { 12 | TS_ASSERT_EQUALS((__int64)1, (__int64)2); 13 | TS_ASSERT_DIFFERS((__int64)3, (__int64)3); 14 | TS_ASSERT_LESS_THAN((__int64)5, (__int64)4); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /test/unit/SConstruct: -------------------------------------------------------------------------------- 1 | CxxTestBuilder_path = '../../build_tools/SCons/cxxtest.py' 2 | CxxTest_dir = '../..' 3 | 4 | # First a little python magic to pull in CxxTestBuilder 5 | import imp 6 | cxxtest = imp.load_source('cxxtest', CxxTestBuilder_path) 7 | env = Environment() 8 | cxxtest.generate(env, CXXTEST_INSTALL_DIR=CxxTest_dir) 9 | 10 | for test in env.Glob('*.t.h'): 11 | env.CxxTest(test) 12 | 13 | -------------------------------------------------------------------------------- /doc/catalog.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /doc/examples/runner10.tpl: -------------------------------------------------------------------------------- 1 | #define CXXTEST_HAVE_EH 2 | #define CXXTEST_ABORT_TEST_ON_FAIL 3 | #include 4 | 5 | int main() 6 | { 7 | std::cout << "Starting test runner" << std::endl; 8 | int status = CxxTest::ErrorPrinter().run(); 9 | std::cout << "Stopping test runner" << std::endl; 10 | return status; 11 | } 12 | 13 | // The CxxTest "world" 14 | 15 | -------------------------------------------------------------------------------- /test/VoidTraits.h: -------------------------------------------------------------------------------- 1 | // 2 | // This include file is used to test the --include option 3 | // 4 | 5 | #ifdef CXXTEST_RUNNING 6 | 7 | #include 8 | 9 | namespace CxxTest 10 | { 11 | CXXTEST_TEMPLATE_INSTANTIATION 12 | class ValueTraits 13 | { 14 | public: 15 | ValueTraits(void *) {} 16 | const char *asString(void) { return "(void *)"; } 17 | }; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /test/LongLong.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This tests CxxTest's handling of "long long" 5 | // 6 | 7 | class LongLongTest : public CxxTest::TestSuite 8 | { 9 | public: 10 | void testLongLong() 11 | { 12 | TS_ASSERT_EQUALS((long long)1, (long long)2); 13 | TS_ASSERT_DIFFERS((long long)3, (long long)3); 14 | TS_ASSERT_LESS_THAN((long long)5, (long long)4); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite10.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite10.h 2 | #include 3 | #include 4 | 5 | class MyTestSuite10 : public CxxTest::TestSuite 6 | { 7 | public: 8 | void test_le() 9 | { 10 | MyClass x(1), y(2); 11 | TS_ASSERT_LESS_THAN(x, y); 12 | } 13 | 14 | void test_eq() 15 | { 16 | MyClass x(1), y(2); 17 | TS_ASSERT_EQUALS(x, y); 18 | } 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /test/Comments2.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This is a test of commenting out tests in CxxTest 5 | // 6 | 7 | class Comments : public CxxTest::TestSuite 8 | { 9 | public: 10 | void test_Something() 11 | { 12 | TS_WARN("Something"); 13 | } 14 | 15 | /* 16 | void test_Something_else() 17 | { 18 | TS_WARN( "Something else" ); 19 | } 20 | */ 21 | }; 22 | -------------------------------------------------------------------------------- /test/EmptySuite.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class EmptySuite : public CxxTest::TestSuite 4 | { 5 | public: 6 | static EmptySuite *createSuite() { return new EmptySuite(); } 7 | static void destroySuite(EmptySuite *suite) { delete suite; } 8 | 9 | void setUp() {} 10 | void tearDown() {} 11 | 12 | void thisSuiteHasNoTests() 13 | { 14 | TS_FAIL("This suite has no tests"); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /sample/mock/Makefile: -------------------------------------------------------------------------------- 1 | all: roll run 2 | 3 | clean: 4 | rm -f *~ *.o roll test test.cpp 5 | 6 | CXXTEST = ../.. 7 | CCFLAGS = -I. -I$(CXXTEST) 8 | 9 | roll: roll.o Dice.o real_stdlib.o 10 | g++ -o $@ $^ 11 | 12 | run: test 13 | ./test 14 | 15 | test: test.o Dice.o mock_stdlib.o 16 | g++ -o $@ $^ 17 | 18 | .cpp.o: 19 | g++ -c -o $@ $(CCFLAGS) $< 20 | 21 | test.cpp: TestDice.h 22 | $(CXXTEST)/bin/cxxtestgen -o $@ --error-printer $< 23 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite11.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite11.h 2 | #include 3 | #include 4 | 5 | class MyTestSuite11 : public CxxTest::TestSuite 6 | { 7 | public: 8 | void test_le() 9 | { 10 | TMyClass x(1), y(2); 11 | TS_ASSERT_LESS_THAN(x, y); 12 | } 13 | 14 | void test_eq() 15 | { 16 | TMyClass x(1), y(2); 17 | TS_ASSERT_EQUALS(x, y); 18 | } 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /doc/examples/BadTestSuite1.h: -------------------------------------------------------------------------------- 1 | // BadTestSuite1.h 2 | #include 3 | 4 | class BadTestSuite1 : public CxxTest::TestSuite 5 | { 6 | public: 7 | void testAddition(void) 8 | { 9 | TS_ASSERT(1 + 1 > 1); 10 | TS_ASSERT_EQUALS(1 + 1, 2); 11 | } 12 | #if 0 13 | void testSubtraction(void) 14 | { 15 | TS_ASSERT(1 - 1 < 1); 16 | TS_ASSERT_EQUALS(1 - 1, 0); 17 | } 18 | #endif 19 | }; 20 | -------------------------------------------------------------------------------- /test/AborterNoThrow.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This is a test suite which doesn't use exception handling. 5 | // It is used to verify --abort-on-fail + --have-eh 6 | // 7 | 8 | class AborterNoThrow : public CxxTest::TestSuite 9 | { 10 | public: 11 | void testFailures() 12 | { 13 | TS_FAIL(1); 14 | TS_FAIL(2); 15 | TS_FAIL(3); 16 | TS_FAIL(4); 17 | TS_FAIL(5); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /doc/examples/buildRunner19.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In EnumTraits::test_Enum_traits: 3 | MyTestSuite9.h:27: Error: Test failed: Yes 4 | MyTestSuite9.h:28: Error: Test failed: No 5 | MyTestSuite9.h:29: Error: Test failed: Maybe 6 | MyTestSuite9.h:30: Error: Test failed: DontKnow 7 | MyTestSuite9.h:31: Error: Test failed: DontCare 8 | MyTestSuite9.h:32: Error: Test failed: (Answer)1000 9 | Failed 1 and Skipped 0 of 1 test 10 | Success rate: 0% 11 | -------------------------------------------------------------------------------- /test/fake/qstring.h: -------------------------------------------------------------------------------- 1 | // fake qstring.h 2 | #ifndef __FAKE__QSTRING_H 3 | #define __FAKE__QSTRING_H 4 | 5 | class QString 6 | { 7 | public: 8 | QString() {} 9 | QString(const char *) {} 10 | bool operator==(const QString &) { return false; } 11 | 12 | static QString number(int) { return QString(); } 13 | }; 14 | 15 | inline QString operator+(const QString &, const QString &) { return QString(); } 16 | 17 | #endif // __FAKE__QSTRING_H 18 | -------------------------------------------------------------------------------- /test/activate.tpl: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | # include 3 | # include 4 | 5 | int main() 6 | { 7 | if ( !CxxTest::leaveOnly( "SimpleTest", "testTheWorldIsCrazy" ) ) { 8 | fprintf( stderr, "Couldn't find SimpleTest::testTheWorldIsCrazy()!?\n" ); 9 | return -1; 10 | } 11 | 12 | CxxTest::activateAllTests(); 13 | return CxxTest::StdioPrinter().run(); 14 | } 15 | 16 | 17 | // The CxxTest "world" 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/examples/buildRunner6.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Error: Expected (2 * 2 == 5), found (4 != 5) 6 | 7 | 8 | -------------------------------------------------------------------------------- /doc/examples/runner13.testMultiplicationVerbose.txt: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (1 test) 2 | In MyTestSuite2::testMultiplication: 3 | /Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:15: Trace: Starting multiplication test 4 | /Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:16: Error: Expected (2 * 2 == 5), found (4 != 5) 5 | /Users/wehart/home/mac/src/cxxtest/doc/examples/MyTestSuite2.h:17: Trace: Finishing multiplication test 6 | Failed 1 and Skipped 0 of 1 test 7 | Success rate: 0% 8 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite2.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite2.h 2 | #include 3 | 4 | class MyTestSuite2 : public CxxTest::TestSuite 5 | { 6 | public: 7 | void testAddition(void) 8 | { 9 | TS_ASSERT(1 + 1 > 1); 10 | TS_ASSERT_EQUALS(1 + 1, 2); 11 | } 12 | 13 | void testMultiplication(void) 14 | { 15 | TS_TRACE("Starting multiplication test"); 16 | TS_ASSERT_EQUALS(2 * 2, 5); 17 | TS_TRACE("Finishing multiplication test"); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /bin/cxxtestgen: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # 3 | # The CxxTest driver script, which uses the cxxtest Python package. 4 | # 5 | 6 | import sys 7 | import os 8 | from os.path import realpath, dirname 9 | if sys.version_info < (3,0): 10 | sys.path.insert(0, dirname(dirname(realpath(__file__)))+os.sep+'python') 11 | else: 12 | sys.path.insert(0, dirname(dirname(realpath(__file__)))+os.sep+'python'+os.sep+'python3') 13 | sys.path.append(".") 14 | 15 | import cxxtest 16 | 17 | cxxtest.main(sys.argv) 18 | 19 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite12.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite12.h 2 | #include 3 | 4 | class MyTestSuite1 : public CxxTest::TestSuite 5 | { 6 | public: 7 | void testAddition(void) 8 | { 9 | TS_ASSERT(1 + 1 > 1); 10 | TS_ASSERT_EQUALS(1 + 1, 2); 11 | } 12 | }; 13 | 14 | 15 | #ifndef CXXTEST_RUNNING 16 | #include 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | 21 | std::cout << "Non-CxxTest stuff is happening now." << std::endl; 22 | 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /doc/examples/buildRunner25.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen --error-printer -o runner.cpp MyTestSuite12.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | ./runner > buildRunner.log 15 | # @run: 16 | ./runner 17 | # @:run 18 | \rm -f runner runner.cpp 19 | 20 | 21 | cp MyTestSuite12.h runner2.cpp 22 | g++ -o runner2 -I$CXXTEST runner2.cpp 23 | ./runner2 24 | \rm -f runner2 runner2.cpp 25 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite6.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite6.h 2 | #include 3 | 4 | class MyTestSuite6 : public CxxTest::TestSuite 5 | { 6 | public: 7 | 8 | static MyTestSuite6* createSuite() 9 | { 10 | #ifdef _MSC_VER 11 | return new MyTestSuite6(); 12 | #else 13 | return 0; 14 | #endif 15 | } 16 | 17 | static void destroySuite(MyTestSuite6* suite) 18 | { delete suite; } 19 | 20 | void test_nothing() 21 | { 22 | TS_FAIL("Nothing to test"); 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /test/Comments.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This is a test of commenting out tests in CxxTest 5 | // 6 | 7 | class Comments : public CxxTest::TestSuite 8 | { 9 | public: 10 | void test_Something() 11 | { 12 | TS_WARN("Something"); 13 | } 14 | 15 | // void test_Something_else() 16 | // { 17 | // TS_WARN( "Something else" ); 18 | // } 19 | 20 | //void test_Something_else() 21 | //{ 22 | // TS_WARN( "Something else" ); 23 | //} 24 | }; 25 | -------------------------------------------------------------------------------- /test/nullptr_guards.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (5 tests) 2 | In NullPtrFormatterTest::testTsAssert: 3 | filename:1: Error: Assertion failed: 4 | In NullPtrFormatterTest::testTsFail: 5 | filename:1: Error: Test failed: 6 | In NullPtrFormatterTest::testTsWarn: 7 | filename:1: Warning: 8 | . 9 | In NullPtrFormatterTest::testTsSkip: 10 | filename:1: Warning: Test skipped: 11 | s 12 | In NullPtrFormatterTest::testTsTrace: 13 | filename:1: Trace: 14 | . 15 | Failed 2 and Skipped 1 of 5 tests 16 | Success rate: 50% 17 | Error level=2 18 | -------------------------------------------------------------------------------- /python/scripts/cxxtestgen: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import os.path 5 | 6 | try: 7 | import cxxtest.cxxtestgen 8 | except ImportError: 9 | currdir = os.path.dirname(os.path.abspath(__file__)) 10 | 11 | if sys.version_info < (3,0): 12 | sys.path.append( os.path.abspath( os.path.sep.join([currdir, '..']) ) ) 13 | else: 14 | sys.path.append( os.path.abspath( os.path.sep.join([currdir, '..', python3]) ) ) 15 | 16 | import cxxtest.cxxtestgen 17 | 18 | cxxtest.cxxtestgen.main() 19 | -------------------------------------------------------------------------------- /test/infinite.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (3 tests) 2 | In TestNonFinite::testNaN: 3 | TestNonFinite.h:18: Error: Expected (nan == nan), found (nan != nan) 4 | TestNonFinite.h:19: Error: Expected (nan == zero), found (nan != 0.0000) 5 | In TestNonFinite::testPlusInf: 6 | TestNonFinite.h:25: Error: Expected (3.0 == plus_inf), found (3.0000 != inf) 7 | In TestNonFinite::testMinusInf: 8 | TestNonFinite.h:31: Error: Expected (1.0 / 3.0 == minus_inf), found (0.3333 != -inf) 9 | Failed 3 and Skipped 0 of 3 tests 10 | Success rate: 0% 11 | Error level = 3 12 | -------------------------------------------------------------------------------- /doc/examples/buildRunner9.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @part: 7 | cxxtestgen --part --error-printer -o MyTestSuite1.cpp MyTestSuite1.h 8 | cxxtestgen --part --error-printer -o MyTestSuite2.cpp MyTestSuite2.h 9 | # @:part 10 | 11 | # @root: 12 | cxxtestgen --root --error-printer -o runner.cpp 13 | # @:root 14 | 15 | # @compile: 16 | g++ -o runner -I$CXXTEST runner.cpp MyTestSuite1.cpp MyTestSuite2.cpp 17 | # @:compile 18 | 19 | ./runner -v 20 | 21 | rm -f MyTestSuite1.cpp MyTestSuite2.cpp runner.cpp runner 22 | -------------------------------------------------------------------------------- /test/WideCharTest.h: -------------------------------------------------------------------------------- 1 | #define CXXTEST_HAVE_STD 2 | #include 3 | #include 4 | 5 | // 6 | // This test suite tests CxxTest's conversion of wchar_t-related values to strings 7 | // 8 | 9 | class WideCharTest : public CxxTest::TestSuite 10 | { 11 | public: 12 | void testWideStringTraits() 13 | { 14 | TS_FAIL(std::basic_string(L"std::wstring is displayed with L\"\"")); 15 | wchar_t array[] = { (wchar_t)0x1234, (wchar_t)0x5678 }; 16 | TS_FAIL(std::basic_string(array, 2)); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /test/fake/qprogressbar.h: -------------------------------------------------------------------------------- 1 | // fake qprogressbar.h 2 | 3 | class QColorGroup 4 | { 5 | public: 6 | enum { Highlight }; 7 | }; 8 | 9 | class QColor 10 | { 11 | public: 12 | QColor(int, int, int) {} 13 | }; 14 | 15 | class QPalette 16 | { 17 | public: 18 | void setColor(int, const QColor &) {} 19 | }; 20 | 21 | class QProgressBar 22 | { 23 | public: 24 | QProgressBar(int, void *) {} 25 | void setProgress(int) {} 26 | int progress() { return 0; } 27 | QPalette palette() { return QPalette(); } 28 | void setPalette(const QPalette &) {} 29 | }; 30 | -------------------------------------------------------------------------------- /sample/file_printer.tpl: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // This is a sample of a custom test runner 3 | // using CxxTest template files. 4 | // This prints the output to a file given on the command line. 5 | // 6 | 7 | #include 8 | #include 9 | 10 | int main( int argc, char *argv[] ) 11 | { 12 | if ( argc != 2 ) { 13 | fprintf( stderr, "Usage: %s \n", argv[0] ); 14 | return -1; 15 | } 16 | 17 | return CxxTest::StdioPrinter( fopen( argv[1], "w" ) ).run(); 18 | } 19 | 20 | // The CxxTest "world" 21 | 22 | 23 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | 10 | # Dummy __init__ file for nosetests 11 | -------------------------------------------------------------------------------- /test/LessThanEquals.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suites demonstrated TS_LESS_THAN_EQUALS 5 | // and how it fails. 6 | // 7 | 8 | class LessThanEquals : public CxxTest::TestSuite 9 | { 10 | public: 11 | void testLessThanEquals() 12 | { 13 | TS_ASSERT_LESS_THAN_EQUALS(1, 2); 14 | TS_ASSERT_LESS_THAN_EQUALS(1, 1); 15 | 16 | TS_ASSERT_LESS_THAN_EQUALS(1, 0); 17 | TSM_ASSERT_LESS_THAN_EQUALS("1 <=? 0", 1, 0); 18 | 19 | ETS_ASSERT_LESS_THAN(1, 0); 20 | ETSM_ASSERT_LESS_THAN_EQUALS("1 <=? 0", 1, 0); 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /test/fake/qwidget.h: -------------------------------------------------------------------------------- 1 | // fake qwidget.h 2 | #ifndef __FAKE__QWIDGET_H 3 | #define __FAKE__QWIDGET_H 4 | 5 | class QString; 6 | 7 | class QWidget 8 | { 9 | public: 10 | bool isMinimized() { return false; } 11 | void close(bool) {} 12 | void showMinimized() {} 13 | void showNormal() {} 14 | void setCaption(const QString &) {} 15 | void setIcon(void *) {} 16 | int x() { return 0; } 17 | int y() { return 0; } 18 | int width() { return 0; } 19 | int height() { return 0; } 20 | void setGeometry(int, int, int, int) {} 21 | }; 22 | 23 | #endif // __FAKE__QWIDGET_H 24 | -------------------------------------------------------------------------------- /sample/mock/MockStdlib.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class MockStdlib : 4 | public T::Base_srand, 5 | public T::Base_rand, 6 | public T::Base_time 7 | { 8 | public: 9 | unsigned lastSeed; 10 | 11 | void srand(unsigned seed) 12 | { 13 | lastSeed = seed; 14 | } 15 | 16 | int nextRand; 17 | 18 | int rand() 19 | { 20 | return nextRand; 21 | } 22 | 23 | time_t nextTime; 24 | 25 | time_t time(time_t *t) 26 | { 27 | if (t) 28 | { 29 | *t = nextTime; 30 | } 31 | return nextTime; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /sample/SCons/include/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef STACK_H 2 | #define STACK_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct stack_t { 9 | int size; 10 | int* vals; 11 | int capacity; 12 | } stack_t; 13 | 14 | stack_t* stack_create(); 15 | void stack_free(stack_t* stack); 16 | int stack_size(stack_t* stack); 17 | void stack_push(stack_t* stack, int val); 18 | int stack_pop(stack_t* stack); 19 | int stack_peak(stack_t* stack); 20 | int stack_capacity(stack_t* stack); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /test/TearDownWorldFails.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when GlobalFixture::tearDownWorld() fails 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool tearDownWorld() { return false; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() {} 25 | }; 26 | -------------------------------------------------------------------------------- /test/TearDownWorldThrows.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when GlobalFixture::tearDownWorld() throws 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool tearDownWorld() { throw this; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() {} 25 | }; 26 | -------------------------------------------------------------------------------- /test/preamble.tpl: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #define CXXTEST_ABORT_TEST_ON_FAIL 4 | 5 | // CxxTest definitions and headers 6 | 7 | 8 | // Make sure this worked 9 | #ifndef TS_ASSERT 10 | # error The preamble does not work! 11 | #endif 12 | 13 | #include 14 | 15 | int main() 16 | { 17 | CxxTest::StdioPrinter runner; 18 | 19 | TS_FAIL( "This will not be displayed" ); 20 | int result = runner.run() + runner.run(); 21 | TS_FAIL( "This will not be displayed" ); 22 | 23 | return result; 24 | } 25 | 26 | 27 | // The CxxTest "world" 28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/examples/Namespace2.h: -------------------------------------------------------------------------------- 1 | // Namespace2.h 2 | #include 3 | 4 | namespace foo { namespace bar { class MyTestSuite1; } } 5 | 6 | class foo::bar::MyTestSuite1 : public CxxTest::TestSuite 7 | { 8 | public: 9 | void testAddition(void) 10 | { 11 | TS_ASSERT(1 + 1 > 1); 12 | TS_ASSERT_EQUALS(1 + 1, 2); 13 | } 14 | }; 15 | 16 | 17 | namespace FOO { namespace BAR { class MyTestSuite1; } } 18 | 19 | class MyTestSuite1 : public CxxTest::TestSuite 20 | { 21 | public: 22 | void testAddition(void) 23 | { 24 | TS_ASSERT(1 + 1 > 1); 25 | TS_ASSERT_EQUALS(1 + 1, 2); 26 | } 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /doc/examples/Namespace1.h: -------------------------------------------------------------------------------- 1 | // Namespace1.h 2 | #include 3 | 4 | namespace foo 5 | { 6 | namespace bar 7 | { 8 | 9 | class MyTestSuite1 : public CxxTest::TestSuite 10 | { 11 | public: 12 | void testAddition(void) 13 | { 14 | TS_ASSERT(1 + 1 > 1); 15 | TS_ASSERT_EQUALS(1 + 1, 2); 16 | } 17 | }; 18 | 19 | } 20 | } 21 | 22 | 23 | namespace FOO 24 | { 25 | namespace BAR 26 | { 27 | 28 | class MyTestSuite1 : public CxxTest::TestSuite 29 | { 30 | public: 31 | void testAddition(void) 32 | { 33 | TS_ASSERT(1 + 1 > 1); 34 | TS_ASSERT_EQUALS(1 + 1, 2); 35 | } 36 | }; 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/GfSetUpFails.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when GlobalFixture::setUp() fails 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool setUp() { return false; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() 25 | { 26 | TS_FAIL("Shouldn't get here at all"); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /test/GfSetUpThrows.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when GlobalFixture::setUp() throws 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool setUp() { throw this; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() 25 | { 26 | TS_FAIL("Shouldn't get here at all"); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /test/GfTearDownFails.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when GlobalFixture::tearDown() fails 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool tearDown() { return false; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() {} 25 | void testTwo() { TS_WARN("Testing should go on!"); } 26 | }; 27 | -------------------------------------------------------------------------------- /test/GfTearDownThrows.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when GlobalFixture::tearDown() throws 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool tearDown() { throw this; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() {} 25 | void testTwo() { TS_WARN("Testing should go on!"); } 26 | }; 27 | -------------------------------------------------------------------------------- /test/SetUpWorldFails.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when setUpWorld() fails 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool setUpWorld() { return false; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() 25 | { 26 | TS_FAIL("Shouldn't get here at all"); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /doc/epub/bin/xslt/obfuscate.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /python/cxxtest/__release__.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | 10 | """ Release Information for cxxtest """ 11 | 12 | __version__ = '4.4' 13 | __date__ = "2014-06-03" 14 | -------------------------------------------------------------------------------- /test/SetUpWorldThrows.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when setUpWorld() throws an exception 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool setUpWorld() { throw this; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | void testOne() 25 | { 26 | TS_FAIL("Shouldn't get here at all"); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /python/python3/cxxtest/__release__.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | 10 | """ Release Information for cxxtest """ 11 | 12 | __version__ = '4.4' 13 | __date__ = "2014-06-03" 14 | -------------------------------------------------------------------------------- /test/SimpleInheritedTest.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Tests : public CxxTest::TestSuite 4 | { 5 | public: 6 | 7 | CXXTEST_STD(list)* cache; 8 | 9 | void setUp() 10 | { 11 | this->cache = new CXXTEST_STD(list)(); 12 | } 13 | 14 | void tearDown() 15 | { delete this->cache; } 16 | 17 | void test_size() 18 | { 19 | TS_ASSERT_EQUALS(cache->size(), 0); 20 | } 21 | 22 | void test_insert() 23 | { 24 | this->cache->push_back(1); 25 | TS_ASSERT_EQUALS(cache->size(), 1); 26 | } 27 | 28 | }; 29 | 30 | 31 | class InheritedTests : public Tests 32 | { 33 | public: 34 | 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /doc/examples/MockTestSuite.h: -------------------------------------------------------------------------------- 1 | // MockTestSuite.h 2 | #include 3 | #include 4 | 5 | int generateRandomNumber(); 6 | 7 | 8 | class MockObject : public T::Base_time 9 | { 10 | public: 11 | MockObject(int initial) : counter(initial) {} 12 | int counter; 13 | time_t time(time_t *) { return counter++; } 14 | }; 15 | 16 | class TestRandom : public CxxTest::TestSuite 17 | { 18 | public: 19 | void test_generateRandomNumber() 20 | { 21 | MockObject t(1); 22 | TS_ASSERT_EQUALS(generateRandomNumber(), 3); 23 | TS_ASSERT_EQUALS(generateRandomNumber(), 6); 24 | TS_ASSERT_EQUALS(generateRandomNumber(), 9); 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /test/SameZero.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This is a test of TS_ASSERT_SAME_DATA when passed NULL 5 | // 6 | 7 | class SameZero : public CxxTest::TestSuite 8 | { 9 | public: 10 | char data[4]; 11 | 12 | void setUp() 13 | { 14 | for (unsigned i = 0; i < sizeof(data); ++ i) 15 | { 16 | data[i] = (char)i; 17 | } 18 | } 19 | 20 | void test_TS_ASSERT_SAME_DATA_passed_zero() 21 | { 22 | TS_ASSERT_SAME_DATA(data, 0, sizeof(data)); 23 | TS_ASSERT_SAME_DATA(0, data, sizeof(data)); 24 | TS_ASSERT_SAME_DATA(data, 0, 0); 25 | TS_ASSERT_SAME_DATA(0, data, 0); 26 | TS_ASSERT_SAME_DATA(0, 0, 0); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /cxxtest/SelfTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest_SelfTest_h__ 13 | #define __cxxtest_SelfTest_h__ 14 | 15 | #define CXXTEST_SUITE(name) 16 | #define CXXTEST_CODE(member) 17 | 18 | #endif // __cxxtest_SelfTest_h__ 19 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite3.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite3.h 2 | #include 3 | 4 | class MyTestSuite3 : public CxxTest::TestSuite 5 | { 6 | public: 7 | void testAddition(void) 8 | { 9 | TS_ASSERT(1 + 1 > 1); 10 | TS_ASSERT_EQUALS(1 + 1, 2); 11 | } 12 | 13 | // void testMultiplication( void ) 14 | // { 15 | // TS_ASSERT( 1 * 1 < 2 ); 16 | // TS_ASSERT_EQUALS( 1 * 1, 2 ); 17 | // } 18 | 19 | /* 20 | void testSubtraction( void ) 21 | { 22 | TS_ASSERT( 1 - 1 < 1 ); 23 | TS_ASSERT_EQUALS( 1 - 1, 0 ); 24 | } 25 | */ 26 | 27 | void XtestDivision(void) 28 | { 29 | TS_ASSERT(1 / 1 < 2); 30 | TS_ASSERT_EQUALS(1 / 1, 1); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /sample/DeltaTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __DELTATEST_H 2 | #define __DELTATEST_H 3 | 4 | #include 5 | #include 6 | 7 | class DeltaTest : public CxxTest::TestSuite { 8 | double _pi, _delta; 9 | 10 | public: 11 | void setUp() { 12 | _pi = 3.1415926535; 13 | _delta = 0.0001; 14 | } 15 | 16 | void testSine() { 17 | TS_ASSERT_DELTA(sin(0.0), 0.0, _delta); 18 | TS_ASSERT_DELTA(sin(_pi / 6), 0.5, _delta); 19 | TS_ASSERT_DELTA(sin(_pi / 2), 1.0, _delta); 20 | TS_ASSERT_DELTA(sin(_pi), 0.0, _delta); 21 | } 22 | 23 | void testInt() { 24 | unsigned a = 0; 25 | unsigned b = 0; 26 | TS_ASSERT_DELTA(a, b, 10); 27 | } 28 | }; 29 | 30 | #endif // __DELTATEST_H 31 | -------------------------------------------------------------------------------- /sample/MessageTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __MESSAGETEST_H 2 | #define __MESSAGETEST_H 3 | 4 | #include 5 | 6 | // 7 | // The [E]TSM_ macros can be used to print a specified message 8 | // instead of the default one. 9 | // This is useful when you refactor your tests, as shown below 10 | // 11 | 12 | class MessageTest : public CxxTest::TestSuite { 13 | public: 14 | void testValues() { 15 | checkValue(0, "My hovercraft"); 16 | checkValue(1, "is full"); 17 | checkValue(2, "of eels"); 18 | } 19 | 20 | void checkValue(unsigned value, const char *message) { 21 | TSM_ASSERT(message, value != 0); 22 | TSM_ASSERT_EQUALS(message, value, value * value); 23 | } 24 | }; 25 | 26 | 27 | #endif // __MESSAGETEST_H 28 | -------------------------------------------------------------------------------- /test/SimpleInheritedTest2.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Tests 4 | { 5 | public: 6 | 7 | CXXTEST_STD(list)* cache; 8 | 9 | void setUp() 10 | { 11 | this->cache = new CXXTEST_STD(list)(); 12 | } 13 | 14 | void tearDown() 15 | { delete this->cache; } 16 | 17 | void test_size() 18 | { 19 | TS_ASSERT_EQUALS(cache->size(), 0); 20 | } 21 | 22 | void test_insert() 23 | { 24 | this->cache->push_back(1); 25 | TS_ASSERT_EQUALS(cache->size(), 1); 26 | } 27 | 28 | }; 29 | 30 | 31 | class InheritedTests : public Tests, public CxxTest::TestSuite 32 | { 33 | public: 34 | 35 | void setUp() { Tests::setUp();} 36 | void tearDown() { Tests::tearDown();} 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /sample/Makefile.PL: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # This isn't a "real" `Makefile.PL' 4 | # It just copies the correct `Makefile.*' to `Makefile' 5 | # 6 | use strict; 7 | use Getopt::Long; 8 | use File::Copy; 9 | 10 | sub usage() { 11 | die "Usage: $0 [--bcc32]\n"; 12 | } 13 | 14 | my $source; 15 | my $target = 'Makefile'; 16 | my $windows = $ENV{'windir'}; 17 | 18 | GetOptions( 'bcc32' => sub { $source = 'Makefile.bcc32' } ) or usage(); 19 | if ( !defined( $source ) ) { 20 | $source = $windows ? 'Makefile.msvc' : 'Makefile.unix'; 21 | } 22 | 23 | unlink($target); 24 | $windows ? copy($source, $target) : symlink($source, $target); 25 | 26 | print "`Makefile' is now `$source'.\n"; 27 | 28 | # 29 | # Local Variables: 30 | # compile-command: "perl Makefile.PL" 31 | # End: 32 | # 33 | -------------------------------------------------------------------------------- /test/fake/commctrl.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAKE__COMMCTRL_H__ 2 | #define __FAKE__COMMCTRL_H__ 3 | 4 | #include 5 | 6 | #define PROGRESS_CLASS TEXT("PROGRESS_CLASS") 7 | #define STATUSCLASSNAME TEXT("STATUSCLASSNAME") 8 | 9 | enum { PBM_SETRANGE32, PBM_SETRANGE, PBM_SETPOS, PBM_SETSTEP, PBM_STEPIT, PBM_SETBARCOLOR, 10 | SB_SETTEXTA, SB_SETPARTS, BS_AUTOCHECKBOX, BM_SETCHECK, BST_UNCHECKED, BM_GETCHECK, 11 | BST_CHECKED, PBS_SMOOTH 12 | }; 13 | 14 | #define ICC_BAR_CLASSES 1 15 | #define ICC_PROGRESS_CLASS 2 16 | 17 | struct INITCOMMONCONTROLSEX 18 | { 19 | DWORD dwSize; 20 | DWORD dwICC; 21 | }; 22 | 23 | inline void InitCommonControls() {} 24 | inline int InitCommonControlsEx(INITCOMMONCONTROLSEX *) { return 0; } 25 | 26 | #endif // __FAKE__COMMCTRL_H__ 27 | -------------------------------------------------------------------------------- /test/SetUpWorldError.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests what happens when setUpWorld() fails 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class Fixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool setUpWorld() { TS_FAIL("THIS IS BAD"); return false; } 13 | }; 14 | 15 | // 16 | // We can rely on this file being included exactly once 17 | // and declare this global variable in the header file. 18 | // 19 | static Fixture fixture; 20 | 21 | class Suite : public CxxTest::TestSuite 22 | { 23 | public: 24 | 25 | void testOne() 26 | { 27 | TS_FAIL("Shouldn't get here at all"); 28 | } 29 | 30 | void testTwo() 31 | { 32 | TS_FAIL("Shouldn't get here at all"); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite5.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite5.h 2 | #include 3 | #include 4 | 5 | class MyTestSuite5 : public CxxTest::TestSuite 6 | { 7 | char *_buffer; 8 | 9 | public: 10 | 11 | void setUp() 12 | { 13 | _buffer = new char[1024]; 14 | } 15 | 16 | void tearDown() 17 | { 18 | delete [] _buffer; 19 | } 20 | 21 | void test_strcpy() 22 | { 23 | strcpy(_buffer, "Hello, world!"); 24 | TS_ASSERT_EQUALS(_buffer[0], 'H'); 25 | TS_ASSERT_EQUALS(_buffer[1], 'e'); 26 | } 27 | 28 | void test_memcpy() 29 | { 30 | memcpy(_buffer, "Hello, world!", sizeof(char)); 31 | TS_ASSERT_EQUALS(_buffer[0], 'H'); 32 | TS_ASSERT_EQUALS(_buffer[1], 'e'); 33 | } 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /test/NullPtrGuards.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static char const* const file = "filename"; 4 | static int line = 1; 5 | // 6 | // A test for issue #115: Defensive guards in ErrorFormatter to deal with 7 | // (char*) nullptr being passed as an error message. 8 | class NullPtrFormatterTest : public CxxTest::TestSuite { 9 | 10 | public: 11 | void testTsAssert() 12 | { 13 | CxxTest::doFailAssert(file, line, (char const*)NULL, (char const*)NULL); 14 | } 15 | void testTsFail() { CxxTest::doFailTest(file, line, (char const*)NULL); } 16 | void testTsWarn() { CxxTest::doWarn(file, line, (char const*)NULL); } 17 | void testTsSkip() { CxxTest::doSkipTest(file, line, (char const*)NULL); } 18 | void testTsTrace() { CxxTest::doTrace(file, line, (char const*)NULL); } 19 | }; 20 | -------------------------------------------------------------------------------- /test/CppTemplateTest.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | class Tests 5 | { 6 | public: 7 | 8 | CXXTEST_STD(list)* cache; 9 | 10 | void setUp() 11 | { 12 | this->cache = new CXXTEST_STD(list)(); 13 | } 14 | 15 | void tearDown() 16 | { 17 | delete this->cache; 18 | } 19 | 20 | void test_size() 21 | { 22 | TS_ASSERT_EQUALS(cache->size(), 0); 23 | } 24 | 25 | void test_insert() 26 | { 27 | this->cache->push_back(1); 28 | TS_ASSERT_EQUALS(cache->size(), 1); 29 | } 30 | 31 | }; 32 | 33 | class IntTests: public Tests, public CxxTest::TestSuite 34 | { 35 | public: 36 | 37 | void setUp() { Tests::setUp(); } 38 | void tearDown() { Tests::tearDown(); } 39 | }; 40 | -------------------------------------------------------------------------------- /sample/FixtureTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __FIXTURETEST_H 2 | #define __FIXTURETEST_H 3 | 4 | #include 5 | #include 6 | 7 | // 8 | // This test suite shows how to use setUp() and tearDown() 9 | // to initialize data common to all tests. 10 | // setUp()/tearDown() will be called before and after each 11 | // test. 12 | // 13 | 14 | class FixtureTest : public CxxTest::TestSuite { 15 | char *_buffer; 16 | public: 17 | void setUp() { 18 | _buffer = new char[1024]; 19 | } 20 | 21 | void tearDown() { 22 | delete [] _buffer; 23 | } 24 | 25 | void test_strcpy() { 26 | strcpy(_buffer, "Hello, world!"); 27 | TS_ASSERT_EQUALS(_buffer[0], 'H'); 28 | TS_ASSERT_EQUALS(_buffer[1], 'E'); 29 | } 30 | }; 31 | 32 | 33 | #endif // __FIXTURETEST_H 34 | -------------------------------------------------------------------------------- /test/gui.out: -------------------------------------------------------------------------------- 1 | {Start 7 tests} Running cxxtest tests (7 tests) {GreenYellowRed::test_Start_green()} . {GreenYellowRed::test_Green_again()} 2 | In GreenYellowRed::test_Green_again: 3 | GreenYellowRed.h:26: Trace: Still green 4 | . {GreenYellowRed::test_Now_yellow()} {Yellow} 5 | In GreenYellowRed::test_Now_yellow: 6 | GreenYellowRed.h:32: Warning: Yellow 7 | . {GreenYellowRed::test_Cannot_go_back()} . {GreenYellowRed::test_Finally_red()} {Red} 8 | In GreenYellowRed::test_Finally_red: 9 | GreenYellowRed.h:43: Error: Test failed: Red 10 | {GreenYellowRed::test_Cannot_go_back_to_yellow()} In GreenYellowRed::test_Cannot_go_back_to_yellow: 11 | GreenYellowRed.h:49: Warning: Yellow? 12 | . {GreenYellowRed::test_Cannot_go_back_to_green()} . {Stop} 13 | Failed 1 and Skipped 0 of 7 tests 14 | Success rate: 85% 15 | Error level = 1 16 | -------------------------------------------------------------------------------- /test/gui_paren.out: -------------------------------------------------------------------------------- 1 | {Start 7 tests} Running cxxtest tests (7 tests) {GreenYellowRed::test_Start_green()} . {GreenYellowRed::test_Green_again()} 2 | In GreenYellowRed::test_Green_again: 3 | GreenYellowRed.h(26): Trace: Still green 4 | . {GreenYellowRed::test_Now_yellow()} {Yellow} 5 | In GreenYellowRed::test_Now_yellow: 6 | GreenYellowRed.h(32): Warning: Yellow 7 | . {GreenYellowRed::test_Cannot_go_back()} . {GreenYellowRed::test_Finally_red()} {Red} 8 | In GreenYellowRed::test_Finally_red: 9 | GreenYellowRed.h(43): Error: Test failed: Red 10 | {GreenYellowRed::test_Cannot_go_back_to_yellow()} In GreenYellowRed::test_Cannot_go_back_to_yellow: 11 | GreenYellowRed.h(49): Warning: Yellow? 12 | . {GreenYellowRed::test_Cannot_go_back_to_green()} . {Stop} 13 | Failed 1 and Skipped 0 of 7 tests 14 | Success rate: 85% 15 | Error level = 1 16 | -------------------------------------------------------------------------------- /sample/CreatedTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __CREATEDTEST_H 2 | #define __CREATEDTEST_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | // 9 | // This test suite shows what to do when your test case 10 | // class cannot be instantiated statically. 11 | // As an example, this test suite requires a non-default constructor. 12 | // 13 | 14 | class CreatedTest : public CxxTest::TestSuite { 15 | char *_buffer; 16 | public: 17 | CreatedTest(unsigned size) : _buffer(new char[size]) {} 18 | virtual ~CreatedTest() { delete [] _buffer; } 19 | 20 | static CreatedTest *createSuite() { return new CreatedTest(16); } 21 | static void destroySuite(CreatedTest *suite) { delete suite; } 22 | 23 | void test_nothing() { 24 | TS_FAIL("Nothing to test"); 25 | } 26 | }; 27 | 28 | 29 | #endif // __CREATEDTEST_H 30 | -------------------------------------------------------------------------------- /sample/parts/Makefile.unix: -------------------------------------------------------------------------------- 1 | # 2 | # (GNU) Makefile for UN*X-like systems 3 | # This makefile shows how to make a different runner for each test 4 | # 5 | 6 | .PHONY: all clean 7 | 8 | all: run 9 | 10 | clean: 11 | rm -f *~ *.cpp *.o runner 12 | 13 | CXXTESTDIR = ../.. 14 | CXXTESTGEN = $(CXXTESTDIR)/bin/cxxtestgen 15 | CXXTESTFLAGS = --have-eh --abort-on-fail 16 | 17 | TESTS = $(wildcard ../*Test.h) 18 | OBJS = runner.o $(TESTS:../%.h=%.o) 19 | 20 | run: runner 21 | ./runner 22 | 23 | runner: $(OBJS) 24 | c++ -o $@ $^ 25 | 26 | %.o: %.cpp 27 | c++ -c -o $@ -I $(CXXTESTDIR) -I .. $^ 28 | 29 | %.cpp: ../%.h 30 | $(CXXTESTGEN) $(CXXTESTFLAGS) --part -o $@ $^ 31 | 32 | runner.cpp: 33 | $(CXXTESTGEN) $(CXXTESTFLAGS) --root --error-printer -o $@ 34 | 35 | # 36 | # Local Variables: 37 | # compile-command: "make -fMakefile.unix" 38 | # End: 39 | # 40 | -------------------------------------------------------------------------------- /test/DoubleCall.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suite tests double macro invocation 5 | // E.g. when TS_ASSERT_EQUALS( x, y ) fails, it should evaulate x and y once 6 | // Consider TS_ASSERT_EQUALS( readNextValue(), 3 ) 7 | // 8 | 9 | class DoubleCall : public CxxTest::TestSuite 10 | { 11 | public: 12 | int i; 13 | 14 | void setUp() 15 | { 16 | i = 0; 17 | } 18 | 19 | void testAssertEqualsWithSideEffects() 20 | { 21 | TS_ASSERT_EQUALS(increment(), 3); 22 | } 23 | 24 | void testAssertDiffersWithSideEffects() 25 | { 26 | TS_ASSERT_DIFFERS(increment(), 1); 27 | } 28 | 29 | void testAssertDeltaWithSideEffects() 30 | { 31 | TS_ASSERT_DELTA(increment(), 2.0, 0.5); 32 | } 33 | 34 | int increment() 35 | { 36 | return ++i; 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /doc/README.txt: -------------------------------------------------------------------------------- 1 | This directory supports the creation of the CxxTest User Guide using 2 | asciidoc and a2x commands. 3 | 4 | HTML 5 | 6 | The command 7 | 8 | make html 9 | 10 | creates the guide.html file. 11 | 12 | 13 | PDF 14 | 15 | The command 16 | 17 | make pdf 18 | 19 | creates the guide.tex file, which generates the guide.pdf file using 20 | dblatex. 21 | 22 | 23 | 24 | EPUB 25 | 26 | The command 27 | 28 | make epub 29 | 30 | creates the file make.epub. Note that the `catalog.xml` file is 31 | used, which configures asciidoc to use the docbook XML data in the 32 | `epub` directory. This is a bit of a hack. It apparently works 33 | around a limitation of the MacPorts installation of asciidoc. 34 | 35 | 36 | MANPAGES 37 | 38 | The command 39 | 40 | make manpages 41 | 42 | creates CxxTest man pages in the doc/man directory. 43 | 44 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite7.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite7.h 2 | #include 3 | #include 4 | 5 | class MyTestSuite7 : public CxxTest::TestSuite 6 | { 7 | public: 8 | 9 | struct Data 10 | { 11 | char data[3]; 12 | bool operator==(Data o) 13 | { 14 | return (memcmp(this, &o, sizeof(o)) == 0); 15 | } 16 | }; 17 | 18 | struct Data2 19 | { 20 | char data[3]; 21 | }; 22 | 23 | void testCompareData() 24 | { 25 | Data x, y; 26 | memset(x.data, 0x12, sizeof(x.data)); 27 | memset(y.data, 0xF6, sizeof(y.data)); 28 | TS_ASSERT_EQUALS(x, y); 29 | 30 | Data2 z, w; 31 | memset(z.data, 0x12, sizeof(x.data)); 32 | memset(w.data, 0xF6, sizeof(y.data)); 33 | TS_ASSERT_SAME_DATA(&z, &w, sizeof(z)) 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite9.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite9.h 2 | #include 3 | 4 | enum Answer 5 | { 6 | Yes, 7 | No, 8 | Maybe, 9 | DontKnow, 10 | DontCare 11 | }; 12 | 13 | // Declare value traits for the Answer enumeration 14 | CXXTEST_ENUM_TRAITS(Answer, 15 | CXXTEST_ENUM_MEMBER(Yes) 16 | CXXTEST_ENUM_MEMBER(No) 17 | CXXTEST_ENUM_MEMBER(Maybe) 18 | CXXTEST_ENUM_MEMBER(DontKnow) 19 | CXXTEST_ENUM_MEMBER(DontCare)); 20 | 21 | // Test the trait values 22 | class EnumTraits : public CxxTest::TestSuite 23 | { 24 | public: 25 | void test_Enum_traits() 26 | { 27 | TS_FAIL(Yes); 28 | TS_FAIL(No); 29 | TS_FAIL(Maybe); 30 | TS_FAIL(DontKnow); 31 | TS_FAIL(DontCare); 32 | TS_FAIL((Answer)1000); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /sample/EnumTraits.h: -------------------------------------------------------------------------------- 1 | // 2 | // This is a test of CxxTest's ValueTraits for enumerations. 3 | // 4 | #include 5 | 6 | // 7 | // First define your enumeration 8 | // 9 | enum Answer { 10 | Yes, 11 | No, 12 | Maybe, 13 | DontKnow, 14 | DontCare 15 | }; 16 | 17 | // 18 | // Now make CxxTest aware of it 19 | // 20 | CXXTEST_ENUM_TRAITS(Answer, 21 | CXXTEST_ENUM_MEMBER(Yes) 22 | CXXTEST_ENUM_MEMBER(No) 23 | CXXTEST_ENUM_MEMBER(Maybe) 24 | CXXTEST_ENUM_MEMBER(DontKnow) 25 | CXXTEST_ENUM_MEMBER(DontCare)); 26 | 27 | class EnumTraits : public CxxTest::TestSuite { 28 | public: 29 | void test_Enum_traits() { 30 | TS_FAIL(Yes); 31 | TS_FAIL(No); 32 | TS_FAIL(Maybe); 33 | TS_FAIL(DontKnow); 34 | TS_FAIL(DontCare); 35 | TS_FAIL((Answer)1000); 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /sample/winddk/SOURCES: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | 3 | # 4 | # Build this sample with the Windows DDK (XP or later) 5 | # 6 | SUITESDIR=.. 7 | CXXTESTDIR=../.. 8 | 9 | # 10 | # Build a user-mode application 11 | # 12 | TARGETNAME=RunTests 13 | TARGETPATH=. 14 | TARGETTYPE=PROGRAM 15 | 16 | # 17 | # Make it a console-mode app 18 | # 19 | UMTYPE=console 20 | 21 | # 22 | # Add CxxTest and tests directory to include path 23 | # 24 | INCLUDES=$(SUITESDIR);$(CXXTESTDIR) 25 | 26 | # 27 | # Enable exception handling and standard library 28 | # 29 | USE_NATIVE_EH=1 30 | LINKER_FLAGS=$(LINKER_FLAGS) -IGNORE:4099 31 | 386_WARNING_LEVEL=-W3 -WX -wd4290 32 | 33 | TARGETLIBS=\ 34 | $(CRT_LIB_PATH)\libcp.lib \ 35 | $(CRT_LIB_PATH)\libc.lib 36 | 37 | # 38 | # Only one source file -- the generated test runner 39 | # 40 | SOURCES=RunTests.cpp 41 | 42 | # 43 | # This line tells the build utility to process Makefile.inc 44 | # 45 | NTTARGETFILE0=RunTests.cpp 46 | 47 | -------------------------------------------------------------------------------- /test/DefaultTraits.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suite demonstrates the default ValueTraits 5 | // 6 | 7 | class DefaultTraits : public CxxTest::TestSuite 8 | { 9 | public: 10 | struct EightBytes 11 | { 12 | EightBytes() {} 13 | unsigned char data[8]; 14 | }; 15 | 16 | void testSmallDefaultTraits() 17 | { 18 | EightBytes x; 19 | for (unsigned i = 0; i < sizeof(x.data); ++ i) 20 | { 21 | x.data[i] = (unsigned char)i; 22 | } 23 | TS_FAIL(x); 24 | } 25 | 26 | struct NineBytes 27 | { 28 | NineBytes() {} 29 | unsigned char data[9]; 30 | }; 31 | 32 | void testBigDefaultTraits() 33 | { 34 | NineBytes x; 35 | for (unsigned i = 0; i < sizeof(x.data); ++ i) 36 | { 37 | x.data[i] = (unsigned char)(0x98 + i); 38 | } 39 | TS_FAIL(x); 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /test/UserTraits.h: -------------------------------------------------------------------------------- 1 | // 2 | // This sample demonstrates rolling your own ValueTraits. 3 | // For the sake of simplicity, the value traits are in the 4 | // same file as the test suite, but of course in a real-world 5 | // scenario you would have a separate file for the value traits. 6 | // 7 | // This file should be used with the template file UserTraits.tpl 8 | // 9 | 10 | 11 | // 12 | // Declare our own ValueTraits which converts to hex notation 13 | // 14 | #include 15 | #include 16 | 17 | namespace CxxTest 18 | { 19 | CXXTEST_TEMPLATE_INSTANTIATION 20 | class ValueTraits 21 | { 22 | char _asString[128]; // Crude, but it should be enough 23 | public: 24 | ValueTraits(int i) { sprintf(_asString, "0x%X", i); } 25 | const char *asString(void) { return _asString; } 26 | }; 27 | } 28 | 29 | class TestUserTraits : public CxxTest::TestSuite 30 | { 31 | public: 32 | void testUserTraits() 33 | { 34 | TS_FAIL(127); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // 6 | // This test runner printer some statistics at the end of the run. 7 | // Note that it uses and not for compatibility 8 | // with older compilers. 9 | // 10 | 11 | using namespace CxxTest; 12 | 13 | class SummaryPrinter : public CxxTest::TestListener 14 | { 15 | public: 16 | void run() 17 | { 18 | CxxTest::TestRunner::runAllTests(*this); 19 | } 20 | 21 | void leaveWorld(const CxxTest::WorldDescription &wd) 22 | { 23 | printf("Number of suites: %u\n", wd.numSuites()); 24 | printf("Number of tests: %u\n", wd.numTotalTests()); 25 | printf("Number of failed tests: %u\n", TestTracker::tracker().failedTests()); 26 | printf("Number of skipped tests: %u\n", TestTracker::tracker().skippedTests()); 27 | } 28 | }; 29 | 30 | int main() 31 | { 32 | SummaryPrinter().run(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/SameData.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suite demonstrates TS_ASSERT_SAME_DATA 5 | // 6 | 7 | class SameData : public CxxTest::TestSuite 8 | { 9 | public: 10 | enum { DATA_SIZE = 24 }; 11 | unsigned char x[DATA_SIZE], y[DATA_SIZE]; 12 | 13 | void setUp() 14 | { 15 | for (unsigned i = 0; i < DATA_SIZE; ++ i) 16 | { 17 | x[i] = (unsigned char)i; 18 | y[i] = (unsigned char)~x[i]; 19 | } 20 | } 21 | 22 | void testAssertSameData() 23 | { 24 | TS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 25 | } 26 | 27 | void testAssertMessageSameData() 28 | { 29 | TSM_ASSERT_SAME_DATA("Not same data", x, y, DATA_SIZE); 30 | } 31 | 32 | void testSafeAssertSameData() 33 | { 34 | ETS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 35 | } 36 | 37 | void testSafeAssertMessageSameData() 38 | { 39 | ETSM_ASSERT_SAME_DATA("Not same data", x, y, DATA_SIZE); 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /python/convert.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | # 10 | # Execute this script to copy the cxxtest/*.py files 11 | # and run 2to3 to convert them to Python 3. 12 | # 13 | 14 | import glob 15 | import subprocess 16 | import os 17 | import shutil 18 | 19 | os.chdir('cxxtest') 20 | for file in glob.glob('*.py'): 21 | shutil.copyfile(file, '../python3/cxxtest/'+file) 22 | # 23 | os.chdir('../python3/cxxtest') 24 | # 25 | for file in glob.glob('*.py'): 26 | subprocess.call('2to3 -w '+file, shell=True) 27 | 28 | -------------------------------------------------------------------------------- /test/char_assertions.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (16 tests).... 2 | In CharAssertions::test_dfcc: 3 | CharAssertions.h:24: Error: Expected (str1 != str2), found (toto) 4 | In CharAssertions::test_dfcm: 5 | CharAssertions.h:24: Error: Expected (str1 != str2), found (toto) 6 | In CharAssertions::test_dfmc: 7 | CharAssertions.h:24: Error: Expected (str1 != str2), found (toto) 8 | In CharAssertions::test_dfmm: 9 | CharAssertions.h:24: Error: Expected (str1 != str2), found (toto) 10 | .... 11 | In CharAssertions::test_efcc: 12 | CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus) 13 | In CharAssertions::test_efcm: 14 | CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus) 15 | In CharAssertions::test_efmc: 16 | CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus) 17 | In CharAssertions::test_efmm: 18 | CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus) 19 | Failed 8 and Skipped 0 of 16 tests 20 | Success rate: 50% 21 | Error level = 8 22 | -------------------------------------------------------------------------------- /test/SameFiles.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suite demonstrates TS_ASSERT_SAME_FILES 5 | // 6 | 7 | class SameFiles : public CxxTest::TestSuite 8 | { 9 | public: 10 | 11 | void testAssertFiles() 12 | { 13 | TS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h"); 14 | } 15 | 16 | void testAssertFileShorter() 17 | { 18 | TS_ASSERT_SAME_FILES("SameFiles.h", "SameFilesLonger.h"); 19 | } 20 | 21 | void testAssertFileLonger() 22 | { 23 | TS_ASSERT_SAME_FILES("SameFilesLonger.h", "SameFiles.h"); 24 | } 25 | 26 | void testAssertMessageSameFiles() 27 | { 28 | TSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h"); 29 | } 30 | 31 | void testSafeAssertSameFiles() 32 | { 33 | ETS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h"); 34 | } 35 | 36 | void testSafeAssertMessageSameFiles() 37 | { 38 | ETSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h"); 39 | } 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /test/WorldFixtures.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests CxxTest global fixtures setUpWorld()/tearDownWorld() 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class PrintingFixture : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | bool setUpWorld() { printf(""); return true; } 13 | bool tearDownWorld() { printf(""); return true; } 14 | bool setUp() { printf(""); return true; } 15 | bool tearDown() { printf(""); return true; } 16 | }; 17 | 18 | // 19 | // We can rely on this file being included exactly once 20 | // and declare this global variable in the header file. 21 | // 22 | static PrintingFixture printingFixture; 23 | 24 | // 25 | // Now define some tests 26 | // 27 | 28 | class FirstSuite : public CxxTest::TestSuite 29 | { 30 | public: 31 | void testOne() {} 32 | void testTwo() {} 33 | }; 34 | 35 | class SecondSuite : public CxxTest::TestSuite 36 | { 37 | public: 38 | void testOne() {} 39 | void testTwo() {} 40 | }; 41 | -------------------------------------------------------------------------------- /sample/msvc/Makefile: -------------------------------------------------------------------------------- 1 | # Where to look for the tests 2 | TESTS = ..\gui\*.h ..\*.h 3 | 4 | # Where the CxxTest distribution is unpacked 5 | CXXTESTDIR = ..\.. 6 | 7 | # Check CXXTESTDIR 8 | !if !exist($(CXXTESTDIR)\bin\cxxtestgen) 9 | !error Please fix CXXTESTDIR 10 | !endif 11 | 12 | # cxxtestgen needs Perl or Python 13 | !if defined(PYTHON) 14 | CXXTESTGEN = $(PYTHON) $(CXXTESTDIR)/bin/cxxtestgen 15 | !else 16 | !error You must define PERL or PYTHON 17 | !endif 18 | 19 | # The arguments to pass to cxxtestgen 20 | # - ParenPrinter is the way MSVC likes its compilation errors 21 | # - --have-eh/--abort-on-fail are nice when you have them 22 | CXXTESTGEN_FLAGS = \ 23 | --gui=Win32Gui \ 24 | --runner=ParenPrinter \ 25 | --have-eh \ 26 | --abort-on-fail 27 | 28 | # How to generate the test runner, `runner.cpp' 29 | runner.cpp: $(TESTS) 30 | $(CXXTESTGEN) $(CXXTESTGEN_FLAGS) -o $@ $(TESTS) 31 | 32 | # How to run the tests, which should be in DIR\runner.exe 33 | run: $(DIR)\runner.exe 34 | $(DIR)\runner.exe 35 | -------------------------------------------------------------------------------- /doc/examples/MyClass.h: -------------------------------------------------------------------------------- 1 | // MyClass.h 2 | 3 | class MyClass 4 | { 5 | public: 6 | 7 | int value; 8 | 9 | MyClass(int value_) : value(value_) {} 10 | 11 | // CxxTest requires a copy constructor 12 | MyClass(const MyClass& other) : value(other.value) {} 13 | 14 | // This is required if you want to use TS_ASSERT_EQUALS 15 | bool operator==(const MyClass& other) const { return value == other.value; } 16 | 17 | // If you want to use TS_ASSERT_LESS_THAN 18 | bool operator<(const MyClass& other) const { return value < other.value; } 19 | }; 20 | 21 | #ifdef CXXTEST_RUNNING 22 | // This declaration is only activated when building a CxxTest test suite 23 | #include 24 | #include 25 | 26 | namespace CxxTest 27 | { 28 | CXXTEST_TEMPLATE_INSTANTIATION 29 | class ValueTraits 30 | { 31 | char _s[256]; 32 | 33 | public: 34 | ValueTraits(const MyClass& m) { sprintf(_s, "MyClass( %i )", m.value); } 35 | const char *asString() const { return _s; } 36 | }; 37 | }; 38 | #endif // CXXTEST_RUNNING 39 | -------------------------------------------------------------------------------- /doc/examples/buildRunner13.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . GetGlobals.sh 4 | export PATH=$CXXTEST/bin:$PATH 5 | 6 | # @main: 7 | cxxtestgen -f --error-printer -o runner.cpp MyTestSuite1.h MyTestSuite2.h MyTestSuite4.h 8 | # @:main 9 | 10 | # @compile: 11 | g++ -o runner -I$CXXTEST runner.cpp 12 | # @:compile 13 | 14 | # @help: 15 | ./runner --help 16 | # @:help 17 | ./runner --help &> runner13.help.txt 18 | 19 | # @helpTests: 20 | ./runner --help-tests 21 | # @:helpTests 22 | ./runner --help-tests &> runner13.helpTests.txt 23 | 24 | # @MyTestSuite2: 25 | ./runner MyTestSuite2 26 | # @:MyTestSuite2 27 | ./runner MyTestSuite2 &> runner13.MyTestSuite2.txt 28 | 29 | # @testMultiplication: 30 | ./runner MyTestSuite2 testMultiplication 31 | # @:testMultiplication 32 | ./runner MyTestSuite2 testMultiplication &> runner13.testMultiplication.txt 33 | 34 | # @testMultiplicationVerbose: 35 | ./runner -v MyTestSuite2 testMultiplication 36 | # @:testMultiplicationVerbose 37 | ./runner -v MyTestSuite2 testMultiplication &> runner13.testMultiplicationVerbose.txt 38 | 39 | \rm -f runner runner.cpp 40 | 41 | -------------------------------------------------------------------------------- /sample/SCons/src/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | stack_t* stack_create() { 6 | stack_t* retVal = malloc(sizeof(stack_t)); 7 | retVal->size = 0; 8 | retVal->capacity = 10; 9 | retVal->vals = malloc(retVal->capacity*sizeof(int)); 10 | return retVal; 11 | } 12 | 13 | void stack_free(stack_t* stack) { 14 | free(stack->vals); 15 | free(stack); 16 | } 17 | 18 | int stack_size(stack_t* stack) { 19 | return stack->size; 20 | } 21 | 22 | void stack_push(stack_t* stack, int val) { 23 | if(stack->size == stack->capacity) { 24 | stack->capacity *= 2; 25 | stack->vals = realloc(stack->vals, stack->capacity*sizeof(int)); 26 | } 27 | stack->vals[stack->size++] = val; 28 | } 29 | 30 | int stack_pop(stack_t* stack) { 31 | if (stack->size >= 1) 32 | return stack->vals[--stack->size]; 33 | else 34 | return 0; 35 | } 36 | 37 | int stack_peak(stack_t* stack) { 38 | if (stack->size >= 1) 39 | return stack->vals[stack->size-1]; 40 | else 41 | return 0; 42 | } 43 | 44 | int stack_capacity(stack_t* stack) { 45 | return stack->capacity; 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /cxxtest/Root.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__Root_cpp__ 13 | #define __cxxtest__Root_cpp__ 14 | 15 | // 16 | // This file holds the "root" of CxxTest, i.e. 17 | // the parts that must be in a source file file. 18 | // 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #endif // __cxxtest__Root_cpp__ 30 | -------------------------------------------------------------------------------- /admin/cxxtest.spec: -------------------------------------------------------------------------------- 1 | Name: cxxtest 2 | Summary: CxxTest Testing Framework for C++ 3 | Version: %{version} 4 | Release: 1 5 | Copyright: LGPL 6 | Group: Development/C++ 7 | Source: cxxtest-%{version}.tar.gz 8 | BuildRoot: /tmp/cxxtest-build 9 | BuildArch: noarch 10 | Prefix: /usr 11 | 12 | %description 13 | CxxTest is a unit testing framework for C++ that is similar in 14 | spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because 15 | it does not require precompiling a CxxTest testing library, it 16 | employs no advanced features of C++ (e.g. RTTI) and it supports a 17 | very flexible form of test discovery. 18 | 19 | %prep 20 | %setup -n cxxtest 21 | 22 | %build 23 | 24 | %install 25 | install -m 755 -d $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/usr/include/cxxtest 26 | install -m 755 bin/cxxtestgen $RPM_BUILD_ROOT/usr/bin/ 27 | install -m 644 cxxtest/* $RPM_BUILD_ROOT/usr/include/cxxtest/ 28 | 29 | %clean 30 | rm -rf $RPM_BUILD_ROOT 31 | 32 | %files 33 | %attr(-, root, root) %doc README 34 | %attr(-, root, root) %doc sample 35 | %attr(-, root, root) /usr/include/cxxtest 36 | %attr(-, root, root) /usr/bin/cxxtestgen 37 | 38 | -------------------------------------------------------------------------------- /cxxtest/ParenPrinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__ParenPrinter_h__ 13 | #define __cxxtest__ParenPrinter_h__ 14 | 15 | // 16 | // The ParenPrinter is identical to the ErrorPrinter, except it 17 | // prints the line number in a format expected by some compilers 18 | // (notably, MSVC). 19 | // 20 | 21 | #include 22 | 23 | namespace CxxTest 24 | { 25 | class ParenPrinter : public ErrorPrinter 26 | { 27 | public: 28 | ParenPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout)) : ErrorPrinter(o, "(", ")") {} 29 | }; 30 | } 31 | 32 | #endif // __cxxtest__ParenPrinter_h__ 33 | -------------------------------------------------------------------------------- /test/SameFilesLonger.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This test suite demonstrates TS_ASSERT_SAME_FILES 5 | // 6 | 7 | class SameFiles : public CxxTest::TestSuite 8 | { 9 | public: 10 | 11 | void testAssertFiles() 12 | { 13 | TS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h"); 14 | } 15 | 16 | void testAssertFileShorter() 17 | { 18 | TS_ASSERT_SAME_FILES("SameFiles.h", "SameFilesLonger.h"); 19 | } 20 | 21 | void testAssertFileLonger() 22 | { 23 | TS_ASSERT_SAME_FILES("SameFilesLonger.h", "SameFiles.h"); 24 | } 25 | 26 | void testAssertMessageSameFiles() 27 | { 28 | TSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h"); 29 | } 30 | 31 | void testSafeAssertSameFiles() 32 | { 33 | ETS_ASSERT_SAME_FILES("SameFiles.h", "SameFiles.h"); 34 | } 35 | 36 | void testSafeAssertMessageSameFiles() 37 | { 38 | ETSM_ASSERT_SAME_FILES("Not same files", "SameFiles.h", "SameData.h"); 39 | } 40 | }; 41 | 42 | // This is a bit longer than SameFiles.h, so we can test the logic of file comparison 43 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Overview 2 | -------- 3 | 4 | CxxTest is a unit testing framework for C++ that is similar in 5 | spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because 6 | it does not require precompiling a CxxTest testing library, it 7 | employs no advanced features of C++ (e.g. RTTI) and it supports a 8 | very flexible form of test discovery. 9 | 10 | CxxTest is available under the GNU Lesser General Public Licence (LGPL). 11 | 12 | A user guide can be downloaded from http://cxxtest.com. 13 | 14 | 15 | A Simple Example 16 | ---------------- 17 | 18 | 1. Create a test suite header file: 19 | 20 | MyTestSuite.h: 21 | 22 | #include 23 | 24 | class MyTestSuite : public CxxTest::TestSuite 25 | { 26 | public: 27 | void testAddition( void ) 28 | { 29 | TS_ASSERT( 1 + 1 > 1 ); 30 | TS_ASSERT_EQUALS( 1 + 1, 2 ); 31 | } 32 | }; 33 | 34 | 35 | 2. Generate the tests file: 36 | 37 | # cxxtestgen --error-printer -o tests.cpp MyTestSuite.h 38 | 39 | 3. Compile and run! 40 | 41 | # g++ -o main tests.cpp 42 | # ./main 43 | Running cxxtest tests (1 test).OK! 44 | 45 | -------------------------------------------------------------------------------- /cxxtest/StdHeaders.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest_StdHeaders_h__ 13 | #define __cxxtest_StdHeaders_h__ 14 | 15 | // 16 | // This file basically #includes the STL headers. 17 | // It exists to support warning level 4 in Visual C++ 18 | // 19 | 20 | #ifdef _MSC_VER 21 | # pragma warning( push, 1 ) 22 | #endif // _MSC_VER 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef _MSC_VER 33 | # pragma warning( pop ) 34 | #endif // _MSC_VER 35 | 36 | #endif // __cxxtest_StdHeaders_h__ 37 | -------------------------------------------------------------------------------- /admin/announcement: -------------------------------------------------------------------------------- 1 | We are pleased to announce the updated release of CxxTest 4.4. CxxTest is a unit testing framework for C++ that is similar in spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because it does not require precompiling a CxxTest testing library, it employs no advanced features of C++ (e.g. RTTI) and it supports a very flexible form of test discovery. 2 | 3 | This release includes a variety of bug fixes: 4 | 5 | - Fixed compilation error on Windows (MSVC) in XmlFormatter.h (#86) 6 | - Fix to ensure that tearDown() is called (#89) 7 | - Add option run test with a user defined command in scons (#91) 8 | - Use a Python path relative to the cxxtestgen script (#88) 9 | - Add defensive guard in ErrorFormatter.h (#96) 10 | - Fixed bug with "None" appearing in CXXTEST_CPPATH (#99) 11 | - Added CXXTEST_LIBPATH to properly use shared libraries (#100) 12 | - Added guards when XmlFormatter.h data is not initialize (#87) 13 | 14 | See the CxxTest Home Page (http://cxxtest.com) for documentation and download instructions. 15 | 16 | Enjoy! 17 | 18 | CxxTest Developer Team 19 | cxxtest-developers@googlegroups.com 20 | -------------------------------------------------------------------------------- /test/bad.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (7 tests) 2 | In BadTest::testEquality: 3 | BadTest.h:15: Error: Expected (1 == 2), found (1 != 2) 4 | BadTest.h:16: Error: Expected ('a' == 'A'), found ('a' != 'A') 5 | BadTest.h:17: Error: Expected (1.0 == -12345678900000000000000000000000000000000000000000.1234), found (1.0000 != -1.2345E50) 6 | In BadTest::testAddition: 7 | BadTest.h:23: Error: Expected (2 + 2 == 5), found (4 != 5) 8 | In BadTest::TestMultiplication: 9 | BadTest.h:29: Error: Expected (4 * 4 == 44), found (16 != 44) 10 | BadTest.h:30: Error: Expected (-2 * -2 != 4), found (4) 11 | In BadTest::testComparison: 12 | BadTest.h:36: Error: Expected (-1 < -2), found (-1 >= -2) 13 | In BadTest::testTheWorldIsCrazy: 14 | BadTest.h:41: Error: Expected (true == false), found (true != false) 15 | In BadTest::test_Failure: 16 | BadTest.h:46: Error: Test failed: Not implemented 17 | BadTest.h:47: Error: Test failed: 1569779912 18 | In BadTest::test_TS_WARN_macro: 19 | BadTest.h:52: Warning: Just a friendly warning 20 | BadTest.h:53: Warning: Warnings don't abort the test 21 | . 22 | Failed 6 and Skipped 0 of 7 tests 23 | Success rate: 14% 24 | Error level = 6 25 | -------------------------------------------------------------------------------- /test/cxxtest/DummyGui.h: -------------------------------------------------------------------------------- 1 | #ifndef __CXXTEST__DUMMYGUI_H 2 | #define __CXXTEST__DUMMYGUI_H 3 | 4 | // 5 | // The DummyGui is a "GUI" that prints messages to cout 6 | // It is used for testing CxxTest 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace CxxTest 14 | { 15 | class DummyGui : public GuiListener 16 | { 17 | public: 18 | void guiEnterWorld(unsigned numTotalTests) 19 | { 20 | (CXXTEST_STD(cout) << " {Start " << numTotalTests << " tests} ").flush(); 21 | } 22 | 23 | void guiEnterTest(const char *suiteName, const char *testName) 24 | { 25 | (CXXTEST_STD(cout) << " {" << suiteName << "::" << testName << "()} ").flush(); 26 | } 27 | 28 | void yellowBar() 29 | { 30 | (CXXTEST_STD(cout) << " {Yellow} ").flush(); 31 | } 32 | 33 | void redBar() 34 | { 35 | (CXXTEST_STD(cout) << " {Red} ").flush(); 36 | } 37 | 38 | void leaveWorld(const WorldDescription &) 39 | { 40 | (CXXTEST_STD(cout) << " {Stop} ").flush(); 41 | } 42 | }; 43 | } 44 | 45 | #endif //__CXXTEST__DUMMYGUI_H 46 | -------------------------------------------------------------------------------- /test/TestNonFinite.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // All tests in this test suite should fail, with 4 failing assertions and 4 | // appropriate error messages. With CxxText 3.10.1, it enters an infinite 5 | // loop. With the suggested patch, it behaves correctly. 6 | 7 | // Written and submitted by Eric Joanis 8 | // National Research Council Canada 9 | 10 | double zero = 0.0; 11 | 12 | class TestNonFinite : public CxxTest::TestSuite 13 | { 14 | public: 15 | void testNaN() 16 | { 17 | double nan = (1.0 / zero / (1.0 / zero)); 18 | TS_ASSERT_EQUALS(nan, nan); // should fail since nan != nan by defn 19 | TS_ASSERT_EQUALS(nan, zero); // should fail 20 | } 21 | void testPlusInf() 22 | { 23 | double plus_inf = -1.0 / zero; 24 | TS_ASSERT_EQUALS(-1.0 / zero, plus_inf); // should pass 25 | TS_ASSERT_EQUALS(3.0, plus_inf); // should fail 26 | } 27 | void testMinusInf() 28 | { 29 | double minus_inf = 1.0 / zero; 30 | TS_ASSERT_EQUALS(1.0 / zero, minus_inf); // should pass 31 | TS_ASSERT_EQUALS(1.0 / 3.0, minus_inf); // should fail 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /sample/only.tpl: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | #include 3 | #include 4 | 5 | int main( int argc, char *argv[] ) 6 | { 7 | if ( argc < 2 || argc > 3 ) { 8 | fprintf( stderr, "Usage: only []\n\n" ); 9 | fprintf( stderr, "Available tests:\n" ); 10 | CxxTest::RealWorldDescription wd; 11 | for ( CxxTest::SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() ) 12 | for ( CxxTest::TestDescription *td = sd->firstTest(); td; td = td->next() ) 13 | fprintf( stderr, " - %s::%s()\n", sd->suiteName(), td->testName() ); 14 | return 1; 15 | } 16 | 17 | const char *suiteName = argv[1]; 18 | const char *testName = (argc > 2) ? argv[2] : 0; 19 | if ( !CxxTest::leaveOnly( suiteName, testName ) ) { 20 | if ( testName ) 21 | fprintf( stderr, "Cannot find %s::%s()\n", argv[1], argv[2] ); 22 | else 23 | fprintf( stderr, "Cannot find class %s\n", argv[1] ); 24 | return 2; 25 | } 26 | 27 | return CxxTest::StdioPrinter().run(); 28 | } 29 | 30 | 31 | // The CxxTest "world" 32 | 33 | 34 | -------------------------------------------------------------------------------- /cxxtest/YesNoRunner.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__YesNoRunner_h__ 13 | #define __cxxtest__YesNoRunner_h__ 14 | 15 | // 16 | // The YesNoRunner is a simple TestListener that 17 | // just returns true iff all tests passed. 18 | // 19 | 20 | #include 21 | #include 22 | 23 | namespace CxxTest 24 | { 25 | class YesNoRunner : public TestListener 26 | { 27 | public: 28 | YesNoRunner() 29 | { 30 | } 31 | 32 | int run() 33 | { 34 | TestRunner::runAllTests(*this); 35 | return tracker().failedTests(); 36 | } 37 | }; 38 | } 39 | 40 | #endif // __cxxtest__YesNoRunner_h__ 41 | -------------------------------------------------------------------------------- /sample/gui/GreenYellowRed.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef _WIN32 4 | # include 5 | # define CXXTEST_SAMPLE_GUI_WAIT() Sleep( 1000 ) 6 | #else // !_WIN32 7 | extern "C" unsigned sleep(unsigned seconds); 8 | # define CXXTEST_SAMPLE_GUI_WAIT() sleep( 1 ) 9 | #endif // _WIN32 10 | 11 | class GreenYellowRed : public CxxTest::TestSuite 12 | { 13 | public: 14 | void wait() 15 | { 16 | CXXTEST_SAMPLE_GUI_WAIT(); 17 | } 18 | 19 | void test_Start_green() 20 | { 21 | wait(); 22 | } 23 | 24 | void test_Green_again() 25 | { 26 | TS_TRACE("Still green"); 27 | wait(); 28 | } 29 | 30 | void test_Now_yellow() 31 | { 32 | TS_WARN("Yellow"); 33 | wait(); 34 | } 35 | 36 | void test_Cannot_go_back() 37 | { 38 | wait(); 39 | } 40 | 41 | void test_Finally_red() 42 | { 43 | TS_FAIL("Red"); 44 | wait(); 45 | } 46 | 47 | void test_Cannot_go_back_to_yellow() 48 | { 49 | TS_WARN("Yellow?"); 50 | wait(); 51 | } 52 | 53 | void test_Cannot_go_back_to_green() 54 | { 55 | wait(); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /sample/msvc/ReadMe.txt: -------------------------------------------------------------------------------- 1 | Sample files for Visual Studio 2 | ============================== 3 | 4 | There are three projects in this workspace: 5 | 6 | - CxxTest_3_Generate runs cxxtestgen to create runner.cpp 7 | - CxxTest_2_Build compiles the generated file 8 | - CxxTest_1_Run runs the compiled binary 9 | 10 | Whenever you build this workspace, the tests are run, and any failed assertions 11 | are displayed as compilation errors (you can browse them using F4). 12 | 13 | Note that to run this sample, you need first to create an environment 14 | variable PYTHON, e.g. Python=c:\Python25\bin\python.exe 15 | 16 | 17 | To use these .dsp and .dsw files in your own project, run FixFiles.bat 18 | to adjust them to where you've placed CxxTest and your own tests. 19 | 20 | If you want to use just the .dsp files in your own workspace, don't 21 | forget to: 22 | 23 | - Set up the dependencies (CxxTest_3_Generate depends on 24 | CxxTest_2_Build which depends on CxxTest_1_Run) 25 | 26 | - Add your own include paths, libraries etc. to the CxxTest_2_Build project 27 | 28 | 29 | NOTE: I haven't used "Post-Build Step" to run the tests because I 30 | wanted the tests to be executed even if nothing has changed. 31 | -------------------------------------------------------------------------------- /cxxtest/StdioPrinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__StdioPrinter_h__ 13 | #define __cxxtest__StdioPrinter_h__ 14 | 15 | // 16 | // The StdioPrinter is an StdioFilePrinter which defaults to stdout. 17 | // This should have been called StdOutPrinter or something, but the name 18 | // has been historically used. 19 | // 20 | 21 | #include 22 | 23 | namespace CxxTest 24 | { 25 | class StdioPrinter : public StdioFilePrinter 26 | { 27 | public: 28 | StdioPrinter(FILE *o = stdout, const char *preLine = ":", const char *postLine = "") : 29 | StdioFilePrinter(o, preLine, postLine) {} 30 | }; 31 | } 32 | 33 | #endif // __cxxtest__StdioPrinter_h__ 34 | -------------------------------------------------------------------------------- /test/Relation.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct MyNegative 4 | { 5 | bool operator()(const int &i) const { return i < 0; } 6 | }; 7 | 8 | template 9 | struct MyLess 10 | { 11 | bool operator()(const T &x, const T &y) const { return x < y; } 12 | }; 13 | 14 | class Relation : public CxxTest::TestSuite 15 | { 16 | public: 17 | void testPredicate() 18 | { 19 | TS_ASSERT_PREDICATE(MyNegative, 1); 20 | TSM_ASSERT_PREDICATE("1 , 2, 1); 30 | TSM_ASSERT_RELATION("2 , 2, 1); 31 | try { ETS_ASSERT_RELATION(MyLess, throwInt(1), throwInt(1)); } 32 | catch (int i) { TS_WARN(i); } 33 | try { ETSM_ASSERT_RELATION("2 , throwInt(1), throwInt(1)); } 34 | catch (int i) { TS_WARN(i); } 35 | } 36 | 37 | int throwInt(int i) 38 | { 39 | throw i; 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /test/test_doc.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | 10 | # 11 | # Import and execute the Python test driver for the user guide examples 12 | # 13 | 14 | # Imports 15 | try: 16 | import pyutilib.th as unittest 17 | pyutilib_available=True 18 | except: 19 | pyutilib_available=False 20 | import os 21 | from os.path import dirname, abspath, abspath, basename 22 | import sys 23 | 24 | if pyutilib_available: 25 | currdir = dirname(abspath(__file__))+os.sep 26 | datadir = os.sep.join([dirname(dirname(abspath(__file__))),'doc','examples'])+os.sep 27 | 28 | os.chdir(datadir) 29 | sys.path.insert(0, datadir) 30 | 31 | from test_examples import * 32 | 33 | # Execute the tests 34 | if __name__ == '__main__': 35 | unittest.main() 36 | -------------------------------------------------------------------------------- /doc/examples/TMyClass.h: -------------------------------------------------------------------------------- 1 | // TMyClass.h 2 | 3 | template 4 | class TMyClass 5 | { 6 | public: 7 | 8 | T value; 9 | 10 | TMyClass(const T& value_) : value(value_) {} 11 | 12 | // CxxTest requires a copy constructor 13 | TMyClass(const TMyClass& other) : value(other.value) {} 14 | 15 | // This is required if you want to use TS_ASSERT_EQUALS 16 | bool operator==(const TMyClass& other) const { return value == other.value; } 17 | 18 | // If you want to use TS_ASSERT_LESS_THAN 19 | bool operator<(const TMyClass& other) const { return value < other.value; } 20 | }; 21 | 22 | #ifdef CXXTEST_RUNNING 23 | // This declaration is only activated when building a CxxTest test suite 24 | #include 25 | #include 26 | #include 27 | 28 | namespace CxxTest 29 | { 30 | template 31 | class ValueTraits< TMyClass > 32 | { 33 | public: 34 | std::ostringstream _s; 35 | 36 | ValueTraits(const TMyClass& t) { _s << typeid(t).name() << "( " << t.value << " )"; } 37 | 38 | ValueTraits(const ValueTraits< TMyClass >& value) { _s << value._s.rdbuf(); } 39 | 40 | const char *asString() const { return _s.str().c_str(); } 41 | }; 42 | }; 43 | #endif // CXXTEST_RUNNING 44 | -------------------------------------------------------------------------------- /test/DynamicAbort.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class DynamicAbort : public CxxTest::TestSuite 4 | { 5 | public: 6 | void test_Abort_on_fail_in_this_test() 7 | { 8 | TS_ASSERT_EQUALS(1, 2); 9 | TS_ASSERT_EQUALS(2, 3); 10 | } 11 | 12 | void test_Dont_abort_in_this_test() 13 | { 14 | CxxTest::setAbortTestOnFail(false); 15 | TS_ASSERT_EQUALS(1, 2); 16 | TS_ASSERT_EQUALS(2, 3); 17 | } 18 | 19 | void test_Revert_to_abort() 20 | { 21 | TS_ASSERT_EQUALS(1, 2); 22 | TS_ASSERT_EQUALS(2, 3); 23 | } 24 | }; 25 | 26 | class SetUpWorksAllTests : public CxxTest::TestSuite 27 | { 28 | public: 29 | void setUp() 30 | { 31 | CxxTest::setAbortTestOnFail(false); 32 | } 33 | 34 | void test_Dont_abort_in_this_test() 35 | { 36 | TS_ASSERT_EQUALS(1, 2); 37 | TS_ASSERT_EQUALS(2, 3); 38 | } 39 | 40 | void test_Dont_abort_in_this_test_either() 41 | { 42 | TS_ASSERT_EQUALS(1, 2); 43 | TS_ASSERT_EQUALS(2, 3); 44 | } 45 | 46 | void test_Override_in_this_test() 47 | { 48 | CxxTest::setAbortTestOnFail(true); 49 | TS_ASSERT_EQUALS(1, 2); 50 | TS_ASSERT_EQUALS(2, 3); 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /cxxtest/GlobalFixture.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__GlobalFixture_h__ 13 | #define __cxxtest__GlobalFixture_h__ 14 | 15 | #include 16 | 17 | namespace CxxTest 18 | { 19 | class GlobalFixture : public Link 20 | { 21 | public: 22 | virtual bool setUpWorld(); 23 | virtual bool tearDownWorld(); 24 | virtual bool setUp(); 25 | virtual bool tearDown(); 26 | 27 | GlobalFixture(); 28 | virtual ~GlobalFixture(); 29 | 30 | static GlobalFixture *firstGlobalFixture(); 31 | static GlobalFixture *lastGlobalFixture(); 32 | GlobalFixture *nextGlobalFixture(); 33 | GlobalFixture *prevGlobalFixture(); 34 | 35 | private: 36 | static List _list; 37 | }; 38 | } 39 | 40 | #endif // __cxxtest__GlobalFixture_h__ 41 | 42 | -------------------------------------------------------------------------------- /test/suite.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (8 tests) 2 | In SimpleTest::testEquality: 3 | SimpleTest.h:14: Error: Expected (1 == 2), found (1 != 2) 4 | SimpleTest.h:15: Error: Expected ('a' == 'A'), found ('a' != 'A') 5 | SimpleTest.h:16: Error: Expected (1.0 == -12345678900000000000000000000000000000000000000000.1234), found (1.0000 != -1.2345E50) 6 | In SimpleTest::testAddition: 7 | SimpleTest.h:23: Error: Expected (2 + 2 == 5), found (4 != 5) 8 | In SimpleTest::TestMultiplication: 9 | SimpleTest.h:28: Error: Expected (4 * 4 == 44), found (16 != 44) 10 | SimpleTest.h:29: Error: Expected (-2 * -2 != 4), found (4) 11 | In SimpleTest::testComparison: 12 | SimpleTest.h:34: Error: Expected (-1 < -2), found (-1 >= -2) 13 | In SimpleTest::testTheWorldIsCrazy: 14 | SimpleTest.h:38: Error: Expected (true == false), found (true != false) 15 | In SimpleTest::test_Failure: 16 | SimpleTest.h:42: Error: Test failed: Not implemented 17 | SimpleTest.h:43: Error: Test failed: 1569779912 18 | In SimpleTest::test_TS_SKIP_macro: 19 | SimpleTest.h:47: Warning: Test skipped: Simply skip this test 20 | s 21 | In SimpleTest::test_TS_WARN_macro: 22 | SimpleTest.h:52: Warning: Just a friendly warning 23 | SimpleTest.h:53: Warning: Warnings don't abort the test 24 | . 25 | Failed 6 and Skipped 1 of 8 tests 26 | Success rate: 14% 27 | Error level = 6 28 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all anchors outputs clean manpages 2 | 3 | export XML_CATALOG_FILES = catalog.xml 4 | PY = python 5 | XSLTPROC_OPTS := --stringparam toc.section.depth 2 --stringparam generate.section.toc.level 1 6 | DBLATEX_OPTS := -P latex.output.revhistory=0 -P doc.collab.show=1 -P toc.section.depth=2 7 | A2X_OPTS := -a toc -a icons -L -d article -v --xsltproc-opts "$(XSLTPROC_OPTS)" --dblatex-opts "$(DBLATEX_OPTS)" 8 | 9 | %.html: %.txt anchors outputs 10 | asciidoc -a data-uri -v -b html -d article -n -a toc2 -a icons $< 11 | 12 | # Ignore errors (dblatex may not be installed) 13 | %.pdf: %.txt anchors outputs 14 | - a2x -f pdf $(A2X_OPTS) $< 15 | 16 | # Ignore errors 17 | %.epub: %.txt anchors outputs 18 | - a2x -f epub $(A2X_OPTS) $< 19 | 20 | all: guide.html guide.pdf guide.epub 21 | 22 | manpages: 23 | cd man; ./create_manpage; 24 | cd man; asciidoc -v -d manpage ./cxxtestgen.1.txt 25 | 26 | html: guide.html 27 | 28 | pdf: guide.pdf 29 | 30 | epub: guide.epub 31 | 32 | anchors: guide.txt 33 | $(PY) include_anchors.py $< 34 | 35 | outputs: 36 | ../bin/cxxtestgen -h > examples/cxxtestgen.out 37 | 38 | clean: 39 | - \rm -f guide.xml 40 | - \rm -f examples/.*.py examples/.*.h examples/.*.cpp examples/.*.sh examples/runner examples/TEST*.xml examples/parsetab.py examples/*.orig examples/runner.cpp 41 | -------------------------------------------------------------------------------- /admin/cloudbees_cxxtest: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export PATH=$WORKSPACE/vpython/bin:$PATH 4 | g++ --version 5 | 6 | # Setup virtual Python environment 7 | \rm -Rf vpython 8 | python cxxtest/admin/virtualenv.py vpython 9 | #vpy/scripts/vpy_install 10 | vpython/bin/easy_install nose 11 | vpython/bin/easy_install unittest2 12 | vpython/bin/easy_install ply 13 | vpython/bin/easy_install ordereddict 14 | vpython/bin/easy_install gcovr 15 | vpython/bin/easy_install pyutilib.th 16 | cd cxxtest/python 17 | ../../vpython/bin/python setup.py install 18 | 19 | # Cleanup test directory 20 | cd ../test 21 | make clean 22 | cd ../.. 23 | 24 | # Run tests 25 | #export CXXTEST_GCOV_FLAGS='-fprofile-arcs -ftest-coverage' 26 | vpython/bin/nosetests --verbosity=2 --with-xunit --xunit-file=$WORKSPACE/TEST-cxxtest.xml -w $WORKSPACE/cxxtest/test 27 | 28 | # Generate code coverage 29 | #cd cxxtest 30 | #../vpython/bin/gcovr -v -r $WORKSPACE/cxxtest -x -o $WORKSPACE/cxxtest/test/coverage.xml --gcov-filter '.*#test#(\.\.|\^)#cxxtest#.*gcov' 31 | 32 | echo "DONE" 33 | 34 | # Cleanup old gcov files 35 | cd $WORKSPACE 36 | #\rm -f *.gcov cxxtest/*.gcov doc/*.gcov doc/examples/*.gcov 37 | #\rm -f *.gcno cxxtest/*.gcno doc/*.gcno doc/examples/*.gcno 38 | #\rm -f *.gcda cxxtest/*.gcda doc/*.gcda doc/examples/*.gcda 39 | cd $WORKSPACE/cxxtest/test 40 | make clean 41 | 42 | -------------------------------------------------------------------------------- /test/BadTest.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // A simple test suite that cannot be parsed with the default test discovery mechanism 5 | // 6 | 7 | class BadTest 8 | : 9 | public CxxTest::TestSuite 10 | { 11 | public: 12 | void testEquality() 13 | { 14 | TS_ASSERT_EQUALS(1, 1); 15 | TS_ASSERT_EQUALS(1, 2); 16 | TS_ASSERT_EQUALS('a', 'A'); 17 | TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234); 18 | } 19 | 20 | void testAddition() 21 | { 22 | TS_ASSERT_EQUALS(1 + 1, 2); 23 | TS_ASSERT_EQUALS(2 + 2, 5); 24 | } 25 | 26 | void TestMultiplication() 27 | { 28 | TS_ASSERT_EQUALS(2 * 2, 4); 29 | TS_ASSERT_EQUALS(4 * 4, 44); 30 | TS_ASSERT_DIFFERS(-2 * -2, 4); 31 | } 32 | 33 | void testComparison() 34 | { 35 | TS_ASSERT_LESS_THAN((int)1, (unsigned long)2); 36 | TS_ASSERT_LESS_THAN(-1, -2); 37 | } 38 | 39 | void testTheWorldIsCrazy() 40 | { 41 | TS_ASSERT_EQUALS(true, false); 42 | } 43 | 44 | void test_Failure() 45 | { 46 | TS_FAIL("Not implemented"); 47 | TS_FAIL(1569779912); 48 | } 49 | 50 | void test_TS_WARN_macro() 51 | { 52 | TS_WARN("Just a friendly warning"); 53 | TS_WARN("Warnings don't abort the test"); 54 | } 55 | }; 56 | -------------------------------------------------------------------------------- /cxxtest/XUnitPrinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __CXXTEST__XUNIT_PRINTER_H 13 | #define __CXXTEST__XUNIT_PRINTER_H 14 | 15 | // 16 | // XUnitPrinter combines an ErrorPrinter with an XML formatter. 17 | // 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace CxxTest 24 | { 25 | class XUnitPrinter : public TeeListener 26 | { 27 | public: 28 | 29 | XmlPrinter xml_printer; 30 | ErrorPrinter error_printer; 31 | 32 | XUnitPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout)) 33 | : xml_printer(o) 34 | { 35 | setFirst(error_printer); 36 | setSecond(xml_printer); 37 | } 38 | 39 | int run() 40 | { 41 | TestRunner::runAllTests(*this); 42 | return tracker().failedTests(); 43 | } 44 | }; 45 | } 46 | 47 | #endif //__CXXTEST__XUNIT_PRINTER_H 48 | 49 | -------------------------------------------------------------------------------- /python/cxxtest/__init__.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | 10 | """cxxtest: A Python package that supports the CxxTest test framework for C/C++. 11 | 12 | .. _CxxTest: http://cxxtest.com/ 13 | 14 | CxxTest is a unit testing framework for C++ that is similar in 15 | spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because 16 | it does not require precompiling a CxxTest testing library, it 17 | employs no advanced features of C++ (e.g. RTTI) and it supports a 18 | very flexible form of test discovery. 19 | 20 | The cxxtest Python package includes capabilities for parsing C/C++ source files and generating 21 | CxxTest drivers. 22 | """ 23 | 24 | from cxxtest.__release__ import __version__, __date__ 25 | __date__ 26 | __version__ 27 | 28 | __maintainer__ = "William E. Hart" 29 | __maintainer_email__ = "whart222@gmail.com" 30 | __license__ = "LGPL" 31 | __url__ = "http://cxxtest.com" 32 | 33 | from cxxtest.cxxtestgen import * 34 | -------------------------------------------------------------------------------- /python/python3/cxxtest/__init__.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | 10 | """cxxtest: A Python package that supports the CxxTest test framework for C/C++. 11 | 12 | .. _CxxTest: http://cxxtest.com/ 13 | 14 | CxxTest is a unit testing framework for C++ that is similar in 15 | spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because 16 | it does not require precompiling a CxxTest testing library, it 17 | employs no advanced features of C++ (e.g. RTTI) and it supports a 18 | very flexible form of test discovery. 19 | 20 | The cxxtest Python package includes capabilities for parsing C/C++ source files and generating 21 | CxxTest drivers. 22 | """ 23 | 24 | from cxxtest.__release__ import __version__, __date__ 25 | __date__ 26 | __version__ 27 | 28 | __maintainer__ = "William E. Hart" 29 | __maintainer_email__ = "whart222@gmail.com" 30 | __license__ = "LGPL" 31 | __url__ = "http://cxxtest.com" 32 | 33 | from cxxtest.cxxtestgen import * 34 | -------------------------------------------------------------------------------- /sample/msvc/CxxTest_Workspace.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "CxxTest_1_Run"=.\CxxTest_1_Run.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | Begin Project Dependency 15 | Project_Dep_Name CxxTest_2_Build 16 | End Project Dependency 17 | }}} 18 | 19 | ############################################################################### 20 | 21 | Project: "CxxTest_2_Build"=.\CxxTest_2_Build.dsp - Package Owner=<4> 22 | 23 | Package=<5> 24 | {{{ 25 | }}} 26 | 27 | Package=<4> 28 | {{{ 29 | Begin Project Dependency 30 | Project_Dep_Name CxxTest_3_Generate 31 | End Project Dependency 32 | }}} 33 | 34 | ############################################################################### 35 | 36 | Project: "CxxTest_3_Generate"=.\CxxTest_3_Generate.dsp - Package Owner=<4> 37 | 38 | Package=<5> 39 | {{{ 40 | }}} 41 | 42 | Package=<4> 43 | {{{ 44 | }}} 45 | 46 | ############################################################################### 47 | 48 | Global: 49 | 50 | Package=<5> 51 | {{{ 52 | }}} 53 | 54 | Package=<3> 55 | {{{ 56 | }}} 57 | 58 | ############################################################################### 59 | 60 | -------------------------------------------------------------------------------- /cxxtest/GlobalFixture.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__GlobalFixture_cpp__ 13 | #define __cxxtest__GlobalFixture_cpp__ 14 | 15 | #include 16 | 17 | namespace CxxTest 18 | { 19 | bool GlobalFixture::setUpWorld() { return true; } 20 | bool GlobalFixture::tearDownWorld() { return true; } 21 | bool GlobalFixture::setUp() { return true; } 22 | bool GlobalFixture::tearDown() { return true; } 23 | 24 | GlobalFixture::GlobalFixture() { attach(_list); } 25 | GlobalFixture::~GlobalFixture() { detach(_list); } 26 | 27 | GlobalFixture *GlobalFixture::firstGlobalFixture() { return (GlobalFixture *)_list.head(); } 28 | GlobalFixture *GlobalFixture::lastGlobalFixture() { return (GlobalFixture *)_list.tail(); } 29 | GlobalFixture *GlobalFixture::nextGlobalFixture() { return (GlobalFixture *)next(); } 30 | GlobalFixture *GlobalFixture::prevGlobalFixture() { return (GlobalFixture *)prev(); } 31 | } 32 | 33 | #endif // __cxxtest__GlobalFixture_cpp__ 34 | 35 | -------------------------------------------------------------------------------- /sample/mock/TestDice.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Dice.h" 3 | #include "MockStdlib.h" 4 | 5 | class TestDice : public CxxTest::TestSuite 6 | { 7 | public: 8 | MockStdlib *stdlib; 9 | 10 | void setUp() 11 | { 12 | TS_ASSERT(stdlib = new MockStdlib); 13 | } 14 | 15 | void tearDown() 16 | { 17 | delete stdlib; 18 | } 19 | 20 | void test_Randomize_uses_time() 21 | { 22 | stdlib->nextTime = 12345; 23 | Dice dice; 24 | TS_ASSERT_EQUALS(stdlib->lastSeed, 12345); 25 | } 26 | 27 | void test_Roll() 28 | { 29 | Dice dice; 30 | 31 | stdlib->nextRand = 0; 32 | TS_ASSERT_EQUALS(dice.roll(), 1); 33 | 34 | stdlib->nextRand = 2; 35 | TS_ASSERT_EQUALS(dice.roll(), 3); 36 | 37 | stdlib->nextRand = 5; 38 | TS_ASSERT_EQUALS(dice.roll(), 6); 39 | 40 | stdlib->nextRand = 7; 41 | TS_ASSERT_EQUALS(dice.roll(), 2); 42 | } 43 | 44 | void test_Temporary_override_of_one_mock_function() 45 | { 46 | Dice dice; 47 | 48 | stdlib->nextRand = 2; 49 | TS_ASSERT_EQUALS(dice.roll(), 3); 50 | 51 | class Five : public T::Base_rand { int rand() { return 5; } }; 52 | 53 | Five *five = new Five; 54 | TS_ASSERT_EQUALS(dice.roll(), 6); 55 | TS_ASSERT_EQUALS(dice.roll(), 6); 56 | TS_ASSERT_EQUALS(dice.roll(), 6); 57 | delete five; 58 | 59 | stdlib->nextRand = 1; 60 | TS_ASSERT_EQUALS(dice.roll(), 2); 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /test/unit/LinkedList_test.t.h: -------------------------------------------------------------------------------- 1 | #ifndef LINKEDLIST_TEST_H 2 | #define LINKEDLIST_TEST_H 3 | 4 | #include 5 | 6 | class TestLink : public CxxTest::Link 7 | { 8 | public: 9 | bool setUp() { return true; } 10 | bool tearDown() { return true; } 11 | }; 12 | 13 | #include 14 | class LinkedList_test : public CxxTest::TestSuite 15 | { 16 | public: 17 | void test_initialize() 18 | { 19 | CxxTest::List list; 20 | list.initialize(); 21 | TS_ASSERT_EQUALS((CxxTest::Link*)0, list.head()); 22 | TS_ASSERT_EQUALS((CxxTest::Link*)0, list.tail()); 23 | TS_ASSERT_EQUALS(0, list.size()); 24 | TS_ASSERT(list.empty()); 25 | } 26 | 27 | void test_attach() 28 | { 29 | CxxTest::List list; 30 | TestLink link; 31 | 32 | list.initialize(); 33 | link.attach(list); 34 | 35 | TS_ASSERT_EQUALS(1, list.size()); 36 | TS_ASSERT_EQUALS((CxxTest::Link*)&link, list.head()); 37 | TS_ASSERT_EQUALS((CxxTest::Link*)&link, list.tail()); 38 | } 39 | 40 | void test_detach() 41 | { 42 | CxxTest::List list; 43 | TestLink link; 44 | 45 | list.initialize(); 46 | link.attach(list); 47 | link.detach(list); 48 | 49 | TS_ASSERT_EQUALS((CxxTest::Link*)0, list.head()); 50 | TS_ASSERT_EQUALS((CxxTest::Link*)0, list.tail()); 51 | TS_ASSERT_EQUALS(0, list.size()); 52 | TS_ASSERT(list.empty()); 53 | } 54 | }; 55 | 56 | 57 | #endif // __SIMPLETEST_H 58 | -------------------------------------------------------------------------------- /cxxtest/MSVCErrorPrinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__MSVCErrorPrinter_h__ 13 | #define __cxxtest__MSVCErrorPrinter_h__ 14 | 15 | // 16 | // The MSVCErrorPrinter is identical to the ErrorPrinter, except it 17 | // prints the line number and error/warning strings in a format 18 | // consistent with that generated by Microsoft's compiler. 19 | // 20 | // Strict error parsers (e.g. QtCreator's) expect each error to be 21 | // followed by a proper-looking error code, so give them one to make 22 | // them work. Same for warnings. 23 | // 24 | // C2999 : "Unknown error" from Visual Studio 6, no longer used. 25 | // C4999 : "Unknown warning" from Visual Studio 6, no longer used. 26 | // 27 | 28 | #include 29 | 30 | namespace CxxTest 31 | { 32 | class MSVCErrorPrinter : public ErrorPrinter 33 | { 34 | public: 35 | MSVCErrorPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout)) 36 | : ErrorPrinter(o, "(", ") ", "error C2999", "warning C4999") {} 37 | }; 38 | } 39 | 40 | #endif // __cxxtest__MSVCErrorPrinter_h__ 41 | -------------------------------------------------------------------------------- /test/InheritedTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __INHERITANCETEST_H 2 | #define __INHERITANCETEST_H 3 | 4 | #include 5 | 6 | // 7 | // A simple test suite, which is inherited 8 | // 9 | 10 | class BaseTests 11 | { 12 | public: 13 | void testEquality() 14 | { 15 | TS_ASSERT_EQUALS(1, 1); 16 | TS_ASSERT_EQUALS(1, 2); 17 | TS_ASSERT_EQUALS('a', 'A'); 18 | TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234); 19 | } 20 | 21 | void testAddition() 22 | { 23 | TS_ASSERT_EQUALS(1 + 1, 2); 24 | TS_ASSERT_EQUALS(2 + 2, 5); 25 | } 26 | 27 | void TestMultiplication() 28 | { 29 | TS_ASSERT_EQUALS(2 * 2, 4); 30 | TS_ASSERT_EQUALS(4 * 4, 44); 31 | TS_ASSERT_DIFFERS(-2 * -2, 4); 32 | } 33 | 34 | void testComparison() 35 | { 36 | TS_ASSERT_LESS_THAN((int)1, (unsigned long)2); 37 | TS_ASSERT_LESS_THAN(-1, -2); 38 | } 39 | 40 | void testTheWorldIsCrazy() 41 | { 42 | TS_ASSERT_EQUALS(true, false); 43 | } 44 | 45 | void test_Failure() 46 | { 47 | TS_FAIL("Not implemented"); 48 | TS_FAIL(1569779912); 49 | } 50 | 51 | void test_TS_WARN_macro() 52 | { 53 | TS_WARN("Just a friendly warning"); 54 | TS_WARN("Warnings don't abort the test"); 55 | } 56 | }; 57 | 58 | 59 | class InheritedTests1 : public BaseTests, public CxxTest::TestSuite 60 | {}; 61 | 62 | class InheritedTests2 : public CxxTest::TestSuite, public BaseTests 63 | {}; 64 | 65 | #endif // __INHERITANCETEST_H 66 | -------------------------------------------------------------------------------- /sample/SimpleTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __SIMPLETEST_H 2 | #define __SIMPLETEST_H 3 | 4 | #include 5 | 6 | // 7 | // A simple test suite: Just inherit CxxTest::TestSuite and write tests! 8 | // 9 | 10 | class SimpleTest : public CxxTest::TestSuite { 11 | public: 12 | void testEquality() { 13 | TS_ASSERT_EQUALS(1, 1); 14 | TS_ASSERT_EQUALS(1, 2); 15 | TS_ASSERT_EQUALS('a', 'A'); 16 | TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234); 17 | const char* tmp = "foo"; 18 | TS_ASSERT_EQUALS("foo", tmp); 19 | } 20 | 21 | void testAddition() { 22 | TS_ASSERT_EQUALS(1 + 1, 2); 23 | TS_ASSERT_EQUALS(2 + 2, 5); 24 | } 25 | 26 | void TestMultiplication() { 27 | TS_ASSERT_EQUALS(2 * 2, 4); 28 | TS_ASSERT_EQUALS(4 * 4, 44); 29 | TS_ASSERT_DIFFERS(-2 * -2, 4); 30 | } 31 | 32 | void testComparison() { 33 | TS_ASSERT_LESS_THAN((int)1, (unsigned long)2); 34 | TS_ASSERT_LESS_THAN(-1, -2); 35 | } 36 | 37 | void testTheWorldIsCrazy() { 38 | TS_ASSERT_EQUALS(true, false); 39 | } 40 | 41 | void test_Failure() { 42 | TS_FAIL("Not implemented"); 43 | TS_FAIL(1569779912); 44 | } 45 | 46 | void test_TS_SKIP_macro() { 47 | TS_SKIP("Simply skip this test"); 48 | TS_WARN("Skipping will abort the test"); 49 | } 50 | 51 | void test_TS_WARN_macro() { 52 | TS_WARN("Just a friendly warning"); 53 | TS_WARN("Warnings don't abort the test"); 54 | } 55 | }; 56 | 57 | 58 | #endif // __SIMPLETEST_H 59 | -------------------------------------------------------------------------------- /test/DynamicMax.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class DynamicMax : public CxxTest::TestSuite 4 | { 5 | public: 6 | enum { DATA_SIZE = 24 }; 7 | unsigned char x[DATA_SIZE], y[DATA_SIZE]; 8 | 9 | void setUp() 10 | { 11 | for (unsigned i = 0; i < DATA_SIZE; ++ i) 12 | { 13 | x[i] = (unsigned char)i; 14 | y[i] = (unsigned char)~x[i]; 15 | } 16 | } 17 | 18 | void test_Max_size_from_define() 19 | { 20 | TS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 21 | } 22 | 23 | void test_Set_max_size() 24 | { 25 | CxxTest::setMaxDumpSize(16); 26 | TS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 27 | } 28 | 29 | void test_Revert_to_max_size_from_define() 30 | { 31 | TS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 32 | } 33 | 34 | void test_Set_max_size_to_zero__dumps_all() 35 | { 36 | CxxTest::setMaxDumpSize(0); 37 | TS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 38 | } 39 | }; 40 | 41 | class SetUpAffectsAllTests : public CxxTest::TestSuite 42 | { 43 | public: 44 | enum { DATA_SIZE = 24 }; 45 | unsigned char x[DATA_SIZE], y[DATA_SIZE]; 46 | 47 | void setUp() 48 | { 49 | for (unsigned i = 0; i < DATA_SIZE; ++ i) 50 | { 51 | x[i] = (unsigned char)i; 52 | y[i] = (unsigned char)~x[i]; 53 | } 54 | 55 | CxxTest::setMaxDumpSize(12); 56 | } 57 | 58 | void test_Use_12_in_this_test() 59 | { 60 | TS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 61 | } 62 | 63 | void test_Use_12_in_this_test_too() 64 | { 65 | TS_ASSERT_SAME_DATA(x, y, DATA_SIZE); 66 | } 67 | }; 68 | -------------------------------------------------------------------------------- /test/TraitsTest.h: -------------------------------------------------------------------------------- 1 | #define CXXTEST_HAVE_STD 2 | #include 3 | 4 | // 5 | // This test suite tests CxxTest's conversion of different values to strings 6 | // 7 | 8 | class TraitsTest : public CxxTest::TestSuite 9 | { 10 | public: 11 | void testIntegerTraits() 12 | { 13 | TS_FAIL((unsigned char)1); 14 | TS_FAIL((char)0x0F); 15 | TS_FAIL((signed short int) - 12); 16 | TS_FAIL((unsigned short int)34); 17 | TS_FAIL((signed int) - 123); 18 | TS_FAIL((unsigned int)456); 19 | TS_FAIL((signed long int) - 12345); 20 | TS_FAIL((unsigned long int)67890); 21 | } 22 | 23 | void testFloatingPointTraits() 24 | { 25 | TS_FAIL((float)0.12345678); 26 | TS_FAIL((double)0.12345678); 27 | } 28 | 29 | void testBoolTraits() 30 | { 31 | TS_FAIL(true); 32 | TS_FAIL(false); 33 | } 34 | 35 | void testCharTraits() 36 | { 37 | TS_FAIL('A'); 38 | TS_FAIL('\x04'); 39 | TS_FAIL('\x1B'); 40 | TS_FAIL('\0'); 41 | TS_FAIL('\r'); 42 | TS_FAIL('\n'); 43 | TS_FAIL('\b'); 44 | TS_FAIL('\t'); 45 | TS_FAIL('\a'); 46 | TS_FAIL((char) - 5); 47 | } 48 | 49 | void testStringTraits() 50 | { 51 | TS_FAIL("(char *) is displayed as-is\n"); 52 | } 53 | 54 | void testStdStringTraits() 55 | { 56 | typedef CXXTEST_STD(string) String; 57 | TS_FAIL(String("std::string is displayed with \"\"")); 58 | TS_FAIL(String("Escapes\rAre\rTranslated")); 59 | TS_FAIL(String("As are unprintable chars: \x12\x34\x56\x78")); 60 | } 61 | }; 62 | -------------------------------------------------------------------------------- /sample/ExceptionTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __EXCEPTIONTEST_H 2 | #define __EXCEPTIONTEST_H 3 | 4 | #include 5 | 6 | // 7 | // This test suite demonstrates the use of TS_ASSERT_THROWS 8 | // 9 | 10 | class ExceptionTest : public CxxTest::TestSuite { 11 | public: 12 | void testAssertion(void) { 13 | // This assert passes, since throwThis() throws (Number) 14 | TS_ASSERT_THROWS(throwThis(3), const Number &); 15 | // This assert passes, since throwThis() throws something 16 | TS_ASSERT_THROWS_ANYTHING(throwThis(-30)); 17 | // This assert fails, since throwThis() doesn't throw char * 18 | TS_ASSERT_THROWS(throwThis(5), const char *); 19 | // This assert fails since goodFunction() throws nothing 20 | TS_ASSERT_THROWS_ANYTHING(goodFunction(1)); 21 | // The regular TS_ASSERT macros will catch unhandled exceptions 22 | TS_ASSERT_EQUALS(throwThis(3), 333); 23 | // You can assert that a function throws nothing 24 | TS_ASSERT_THROWS_NOTHING(throwThis(-1)); 25 | // This assert fails, since throwThis() throws (Number) 26 | TS_ASSERT_THROWS(throwThis(3), std::exception&); 27 | // If you want to catch the exceptions yourself, use the ETS_ marcos 28 | try { 29 | ETS_ASSERT_EQUALS(throwThis(3), 333); 30 | } catch (const Number &) { 31 | TS_FAIL("throwThis(3) failed"); 32 | } 33 | } 34 | 35 | private: 36 | void goodFunction(int) { 37 | } 38 | 39 | class Number { 40 | public: 41 | Number(int) {} 42 | }; 43 | 44 | int throwThis(int i) { 45 | throw Number(i); 46 | } 47 | }; 48 | 49 | #endif // __EXCEPTIONTEST_H 50 | -------------------------------------------------------------------------------- /sample/TraitsTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRAITSTEST_H 2 | #define __TRAITSTEST_H 3 | 4 | // 5 | // This example shows how to use TS_ASSERT_EQUALS for your own classes 6 | // 7 | #include 8 | #include 9 | 10 | // 11 | // Define your class with operator== 12 | // 13 | #include 14 | #include 15 | 16 | class Pet { 17 | char _name[128]; 18 | public: 19 | Pet(const char *petName) { strcpy(_name, petName); } 20 | 21 | const char *name() const { return _name; } 22 | 23 | bool operator== (const Pet &other) const { 24 | return !strcmp(name(), other.name()); 25 | } 26 | }; 27 | 28 | // 29 | // Instantiate CxxTest::ValueTraits<*your class*> 30 | // Note: Most compilers do not require that you define both 31 | // ValueTraits and ValueTraits, but some do. 32 | // 33 | namespace CxxTest { 34 | CXXTEST_TEMPLATE_INSTANTIATION 35 | class ValueTraits { 36 | char _asString[256]; 37 | 38 | public: 39 | ValueTraits(const Pet &pet) { sprintf(_asString, "Pet(\"%s\")", pet.name()); } 40 | const char *asString() const { return _asString; } 41 | }; 42 | 43 | CXXTEST_COPY_CONST_TRAITS(Pet); 44 | } 45 | 46 | // 47 | // Here's how it works 48 | // 49 | class TestFunky : public CxxTest::TestSuite { 50 | public: 51 | void testPets() { 52 | Pet pet1("dog"), pet2("cat"); 53 | TS_ASSERT_EQUALS(pet1, pet2); 54 | Pet cat("cat"), gato("cat"); 55 | TS_ASSERT_DIFFERS(cat, gato); 56 | #ifdef _CXXTEST_HAVE_STD 57 | typedef CXXTEST_STD(string) String; 58 | TS_ASSERT_EQUALS(String("Hello"), String("World!")); 59 | #endif // _CXXTEST_HAVE_STD 60 | } 61 | }; 62 | 63 | #endif // __TRAITSTEST_H 64 | -------------------------------------------------------------------------------- /cxxtest/LinkedList.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__LinkedList_h__ 13 | #define __cxxtest__LinkedList_h__ 14 | 15 | #include 16 | 17 | namespace CxxTest 18 | { 19 | struct List; 20 | class Link; 21 | 22 | struct List 23 | { 24 | Link *_head; 25 | Link *_tail; 26 | 27 | void initialize(); 28 | 29 | Link *head(); 30 | const Link *head() const; 31 | Link *tail(); 32 | const Link *tail() const; 33 | 34 | bool empty() const; 35 | unsigned size() const; 36 | Link *nth(unsigned n); 37 | 38 | void activateAll(); 39 | void leaveOnly(const Link &link); 40 | }; 41 | 42 | class Link 43 | { 44 | public: 45 | Link(); 46 | virtual ~Link(); 47 | 48 | bool active() const; 49 | void setActive(bool value = true); 50 | 51 | Link *justNext(); 52 | Link *justPrev(); 53 | 54 | Link *next(); 55 | Link *prev(); 56 | const Link *next() const; 57 | const Link *prev() const; 58 | 59 | void attach(List &l); 60 | void detach(List &l); 61 | 62 | private: 63 | Link *_next; 64 | Link *_prev; 65 | bool _active; 66 | 67 | Link(const Link &); 68 | Link &operator=(const Link &); 69 | }; 70 | } 71 | 72 | #endif // __cxxtest__LinkedList_h__ 73 | 74 | -------------------------------------------------------------------------------- /test/Exceptions.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // These test suites are examples of unhandled exceptions and errors in dynamic suites 5 | // 6 | 7 | class NullCreate : public CxxTest::TestSuite 8 | { 9 | public: 10 | static NullCreate *createSuite() { return 0; } 11 | static void destroySuite(NullCreate *) { TS_FAIL("Should not be called"); } 12 | 13 | void testNothing() 14 | { 15 | TS_FAIL("Test called although no suite"); 16 | } 17 | }; 18 | 19 | class ThrowCreate : public CxxTest::TestSuite 20 | { 21 | public: 22 | static ThrowCreate *createSuite() { throw - 3; } 23 | static void destroySuite(ThrowCreate *) { TS_FAIL("Should not be called"); } 24 | 25 | void testNothing() 26 | { 27 | TS_FAIL("Test called although no suite"); 28 | } 29 | }; 30 | 31 | class ThrowDestroy : public CxxTest::TestSuite 32 | { 33 | public: 34 | static ThrowDestroy *createSuite() { return new ThrowDestroy; } 35 | static void destroySuite(ThrowDestroy *suite) { delete suite; throw 42; } 36 | 37 | void testNothing() {} 38 | }; 39 | 40 | class ThrowSetUp : public CxxTest::TestSuite 41 | { 42 | public: 43 | void setUp() { throw 5; } 44 | void tearDown() { TS_FAIL("Shouldn't get here"); } 45 | 46 | void testNothing() { TS_FAIL("Shouldn't get here"); } 47 | }; 48 | 49 | class ThrowTearDown : public CxxTest::TestSuite 50 | { 51 | public: 52 | void setUp() {} 53 | void tearDown() { throw 5; } 54 | 55 | void testNothing() {} 56 | }; 57 | 58 | class TestThrowFromTest : public CxxTest::TestSuite 59 | { 60 | public: 61 | void testThrowSomething() 62 | { 63 | throw 582; 64 | } 65 | 66 | void testMoveOn() 67 | { 68 | TS_TRACE("One failed test doesn't affect the others"); 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /test/Namespace1.h: -------------------------------------------------------------------------------- 1 | #ifndef __NAMESPACE1_H 2 | #define __NAMESPACE1_H 3 | 4 | #include 5 | 6 | // 7 | // A simple test suite: Just inherit CxxTest::TestSuite and write tests! 8 | // 9 | 10 | namespace foo { 11 | namespace bar { 12 | 13 | class Tests : public CxxTest::TestSuite { 14 | public: 15 | void testEquality() { 16 | TS_ASSERT_EQUALS(1, 1); 17 | TS_ASSERT_EQUALS(1, 2); 18 | TS_ASSERT_EQUALS('a', 'A'); 19 | TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234); 20 | } 21 | 22 | void testAddition() { 23 | TS_ASSERT_EQUALS(1 + 1, 2); 24 | TS_ASSERT_EQUALS(2 + 2, 5); 25 | } 26 | 27 | void TestMultiplication() { 28 | TS_ASSERT_EQUALS(2 * 2, 4); 29 | TS_ASSERT_EQUALS(4 * 4, 44); 30 | TS_ASSERT_DIFFERS(-2 * -2, 4); 31 | } 32 | 33 | void testComparison() { 34 | TS_ASSERT_LESS_THAN((int)1, (unsigned long)2); 35 | TS_ASSERT_LESS_THAN(-1, -2); 36 | } 37 | 38 | void testTheWorldIsCrazy() { 39 | TS_ASSERT_EQUALS(true, false); 40 | } 41 | 42 | void test_Failure() { 43 | TS_FAIL("Not implemented"); 44 | TS_FAIL(1569779912); 45 | } 46 | 47 | void test_TS_WARN_macro() { 48 | TS_WARN("Just a friendly warning"); 49 | TS_WARN("Warnings don't abort the test"); 50 | } 51 | }; 52 | 53 | } 54 | } 55 | 56 | namespace FOO { 57 | namespace BAR { 58 | 59 | class Tests : public CxxTest::TestSuite { 60 | public: 61 | void testEquality() { 62 | TS_ASSERT_EQUALS(1, 1); 63 | TS_ASSERT_EQUALS(1, 2); 64 | TS_ASSERT_EQUALS('a', 'A'); 65 | TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234); 66 | } 67 | }; 68 | 69 | } 70 | } 71 | 72 | #endif // __NAMESPACE1_H 73 | -------------------------------------------------------------------------------- /sample/SCons/tests/stack_test.h: -------------------------------------------------------------------------------- 1 | #ifndef STACK_TEST_H 2 | #define STACK_TEST_H 3 | 4 | #include 5 | #include 6 | 7 | class stack_test : public CxxTest::TestSuite 8 | { 9 | 10 | private: 11 | stack_t* stack; 12 | public: 13 | 14 | void setUp() { 15 | stack = stack_create(); 16 | } 17 | 18 | void tearDown() { 19 | stack_free(stack); 20 | } 21 | 22 | void test_create_stack() { 23 | TS_ASSERT_DIFFERS((stack_t*)0, stack); 24 | } 25 | 26 | void test_new_stack_is_empty() { 27 | TS_ASSERT_EQUALS(0, stack_size(stack)); 28 | } 29 | 30 | void test_one_push_add_one_to_size() { 31 | stack_push(stack, 1); 32 | TS_ASSERT_EQUALS(1, stack_size(stack)); 33 | } 34 | 35 | void test_push_pop_doesnt_change_size() { 36 | stack_push(stack, 1); 37 | (void)stack_pop(stack); 38 | TS_ASSERT_EQUALS(0, stack_size(stack)); 39 | } 40 | 41 | void test_peak_after_push() { 42 | stack_push(stack, 1); 43 | TS_ASSERT_EQUALS(1, stack_peak(stack)) 44 | } 45 | 46 | void test_initial_capacity_is_positive() { 47 | TS_ASSERT(stack_capacity(stack) > 0); 48 | } 49 | 50 | void test_pop_on_empty() { 51 | TS_ASSERT_EQUALS(0, stack_pop(stack)); 52 | TS_ASSERT_EQUALS(0, stack_size(stack)); 53 | } 54 | 55 | void test_peak_on_empty() { 56 | TS_ASSERT_EQUALS(0, stack_peak(stack)); 57 | } 58 | 59 | void test_capacity_gte_size() { 60 | TS_ASSERT_LESS_THAN_EQUALS(stack_size(stack), stack_capacity(stack)); 61 | int init_capacity = stack_capacity(stack); 62 | for (int i=0; i < init_capacity + 1; i++) { 63 | stack_push(stack, i); 64 | } 65 | TS_ASSERT_LESS_THAN_EQUALS(stack_size(stack), stack_capacity(stack)); 66 | } 67 | 68 | }; 69 | 70 | #endif // STACK_TEST_H 71 | 72 | -------------------------------------------------------------------------------- /test/Factor.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file is used to test WorldDescription::strTotalTests() 3 | // 4 | 5 | #include 6 | #include 7 | 8 | class Factor : public CxxTest::TestSuite 9 | { 10 | public: 11 | class X : public CxxTest::DummyWorldDescription 12 | { 13 | public: 14 | unsigned n; 15 | unsigned numTotalTests() const { return n; } 16 | }; 17 | 18 | X x; 19 | enum Limit { MAX_STRLEN_TOTAL_TESTS = CxxTest::WorldDescription::MAX_STRLEN_TOTAL_TESTS }; 20 | char buffer[MAX_STRLEN_TOTAL_TESTS * 2]; 21 | 22 | const char *convert(unsigned n) 23 | { 24 | x.n = n; 25 | return x.strTotalTests(buffer); 26 | } 27 | 28 | void test_Some_numbers() 29 | { 30 | TS_WARN(convert(53)); 31 | for (unsigned n = 0; n < 64; ++ n) 32 | { 33 | TS_ASSERT_DIFFERS(n, 32); 34 | TS_WARN(convert(n)); 35 | } 36 | } 37 | 38 | class ShorterThan 39 | { 40 | public: 41 | bool operator()(const char *s, unsigned n) const 42 | { 43 | unsigned len = 0; 44 | while (*s++ != '\0') 45 | { 46 | ++ len; 47 | } 48 | return (len < n); 49 | } 50 | }; 51 | 52 | class NotShorterThan 53 | { 54 | ShorterThan _shorterThan; 55 | 56 | public: 57 | bool operator()(const char *s, unsigned n) const { return !_shorterThan(s, n); } 58 | }; 59 | 60 | void test_Lengths() 61 | { 62 | unsigned reasonableLimit = 60060; 63 | for (unsigned n = 0; n < reasonableLimit; ++ n) 64 | { 65 | TS_ASSERT_RELATION(ShorterThan, convert(n), MAX_STRLEN_TOTAL_TESTS); 66 | } 67 | TS_ASSERT_RELATION(NotShorterThan, convert(reasonableLimit), MAX_STRLEN_TOTAL_TESTS); 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /cxxtest/StdioFilePrinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__StdioFilePrinter_h__ 13 | #define __cxxtest__StdioFilePrinter_h__ 14 | 15 | // 16 | // The StdioFilePrinter is a simple TestListener that 17 | // just prints "OK" if everything goes well, otherwise 18 | // reports the error in the format of compiler messages. 19 | // This class uses , i.e. FILE * and fprintf(). 20 | // 21 | 22 | #include 23 | #include 24 | 25 | namespace CxxTest 26 | { 27 | class StdioFilePrinter : public ErrorFormatter 28 | { 29 | public: 30 | StdioFilePrinter(FILE *o, const char *preLine = ":", const char *postLine = "") : 31 | ErrorFormatter(new Adapter(o), preLine, postLine) {} 32 | virtual ~StdioFilePrinter() { delete outputStream(); } 33 | 34 | private: 35 | class Adapter : public OutputStream 36 | { 37 | Adapter(const Adapter &); 38 | Adapter &operator=(const Adapter &); 39 | 40 | FILE *_o; 41 | 42 | public: 43 | Adapter(FILE *o) : _o(o) {} 44 | void flush() { fflush(_o); } 45 | OutputStream &operator<<(unsigned i) { fprintf(_o, "%u", i); return *this; } 46 | OutputStream &operator<<(const char *s) { fputs(s, _o); return *this; } 47 | OutputStream &operator<<(Manipulator m) { return OutputStream::operator<<(m); } 48 | }; 49 | }; 50 | } 51 | 52 | #endif // __cxxtest__StdioFilePrinter_h__ 53 | -------------------------------------------------------------------------------- /test/Tsm.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // 4 | // This is a test of some of the TSM_ macros 5 | // 6 | 7 | class TestMessageMacros : public CxxTest::TestSuite 8 | { 9 | public: 10 | void testMessageMacros() 11 | { 12 | int n = 42; 13 | char x = 'x', y = 'y'; 14 | 15 | TSM_ASSERT("String", false); 16 | TSM_ASSERT(n, false); 17 | TSM_ASSERT_EQUALS("String", 2 + 2, 5); 18 | TSM_ASSERT_EQUALS(n, 2 + 2, 5); 19 | TSM_ASSERT_SAME_DATA("String", &x, &y, 1); 20 | TSM_ASSERT_SAME_DATA(n, &x, &y, 1); 21 | TSM_ASSERT_DELTA("String", 1.0, 2.0, 0.5); 22 | TSM_ASSERT_DELTA(42, 1.0, 2.0, 0.5); 23 | TSM_ASSERT_DIFFERS("String", 0, 0); 24 | TSM_ASSERT_DIFFERS(n, 0, 0); 25 | TSM_ASSERT_LESS_THAN("String", 2, 1); 26 | TSM_ASSERT_LESS_THAN(n, 2, 1); 27 | TSM_ASSERT_THROWS("String", throwNothing(), int); 28 | TSM_ASSERT_THROWS(n, throwNothing(), int); 29 | TSM_ASSERT_THROWS_ANYTHING("String", throwNothing()); 30 | TSM_ASSERT_THROWS_ANYTHING(n, throwNothing()); 31 | TSM_ASSERT_THROWS_NOTHING("String", throwInteger(n)); 32 | TSM_ASSERT_THROWS_NOTHING(n, throwInteger(n)); 33 | TSM_ASSERT_THROWS_ASSERT("String", throwNothing(), int, TS_ASSERT(true)); 34 | TSM_ASSERT_THROWS_ASSERT(n, throwNothing(), int, TS_ASSERT(true)); 35 | TSM_ASSERT_THROWS_EQUALS("String", throwNothing(), int, 1, 1); 36 | TSM_ASSERT_THROWS_EQUALS(n, throwNothing(), int, 1, 1); 37 | TSM_ASSERT_THROWS_EQUALS("String", throwInteger(n), int i, i, 43); 38 | TSM_ASSERT_THROWS_EQUALS(n, throwInteger(n), int i, i, 43); 39 | } 40 | 41 | void throwNothing() 42 | { 43 | } 44 | 45 | void throwInteger(int i) 46 | { 47 | throw i; 48 | } 49 | }; 50 | 51 | #ifndef _CXXTEST_HAVE_EH 52 | # error cxxtestgen should have found exception handling here! 53 | #endif // !_CXXTEST_HAVE_EH 54 | -------------------------------------------------------------------------------- /sample/SCons/SConstruct: -------------------------------------------------------------------------------- 1 | 2 | cxxtestbuilder_path = '../../build_tools/SCons/cxxtest.py' 3 | cxxtest_path = '../..' 4 | 5 | # First a bit of python magic to make the CxxTestBuilder available 6 | # without having to copy it into a particular path. 7 | # for nicer examples you *should* use, see the cxxtest builder tests in the 8 | # build_tools/SCons/test directory. 9 | import imp 10 | cxxtest = imp.load_source('cxxtest', cxxtestbuilder_path) 11 | 12 | # First build the 'real' library, when working on an embedded system 13 | # this may involve a cross compiler. 14 | env = Environment() 15 | env.BuildDir('build/embedded_platform', 'src') 16 | env.Append(CPPPATH=['include']) 17 | libtested = env.StaticLibrary('build/embedded_platform/tested', 18 | env.Glob('build/embedded_platform/*.c')) 19 | 20 | # Now create a seperate build environment for the tests so we can keep any 21 | # options that are specific to testing seperate from the 'production' build 22 | # environment. For simplicity I am just copying the production environment. 23 | # If we are cross compiling for the "real" library, then this 24 | # environement might be using the normal compiler. 25 | env_test = env.Clone() 26 | 27 | # Add the CxxTestBuilder to our testing build environment. 28 | cxxtest.generate(env_test, CXXTEST_INSTALL_DIR = cxxtest_path) 29 | 30 | # If we were working with an embedded platform we may want to create a 31 | # seperate version of our library that runs on our development box in 32 | # order to do our initial unit testing. This version may also include 33 | # any special preprocessor defines needed for testing e.g. -DTESTING 34 | env_test.BuildDir('build/dev_platform', 'src') 35 | env_test.BuildDir('build/tests', 'tests') 36 | lib_to_test = env_test.StaticLibrary('build/dev_platform/tested', 37 | env.Glob('build/dev_platform/*.c')) 38 | env_test.Append(LIBS=lib_to_test) 39 | env_test.CxxTest(env_test.Glob('tests/*.h')) 40 | 41 | -------------------------------------------------------------------------------- /test/Namespace2.h: -------------------------------------------------------------------------------- 1 | #ifndef __NAMESPACE2_H 2 | #define __NAMESPACE2_H 3 | 4 | #include 5 | 6 | // 7 | // A simple test suite: Just inherit CxxTest::TestSuite and write tests! 8 | // 9 | 10 | // Declare Tests in the appropriate namespace 11 | namespace foo { namespace bar { class Tests; } } 12 | 13 | // Use explicit namespace declaration 14 | class foo::bar::Tests : public CxxTest::TestSuite { 15 | public: 16 | void testEquality() { 17 | TS_ASSERT_EQUALS(1, 1); 18 | TS_ASSERT_EQUALS(1, 2); 19 | TS_ASSERT_EQUALS('a', 'A'); 20 | TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234); 21 | } 22 | 23 | void testAddition() { 24 | TS_ASSERT_EQUALS(1 + 1, 2); 25 | TS_ASSERT_EQUALS(2 + 2, 5); 26 | } 27 | 28 | void TestMultiplication() { 29 | TS_ASSERT_EQUALS(2 * 2, 4); 30 | TS_ASSERT_EQUALS(4 * 4, 44); 31 | TS_ASSERT_DIFFERS(-2 * -2, 4); 32 | } 33 | 34 | void testComparison() { 35 | TS_ASSERT_LESS_THAN((int)1, (unsigned long)2); 36 | TS_ASSERT_LESS_THAN(-1, -2); 37 | } 38 | 39 | void testTheWorldIsCrazy() { 40 | TS_ASSERT_EQUALS(true, false); 41 | } 42 | 43 | void test_Failure() { 44 | TS_FAIL("Not implemented"); 45 | TS_FAIL(1569779912); 46 | } 47 | 48 | void test_TS_WARN_macro() { 49 | TS_WARN("Just a friendly warning"); 50 | TS_WARN("Warnings don't abort the test"); 51 | } 52 | }; 53 | 54 | // Declare Tests in the appropriate namespace 55 | namespace FOO { namespace BAR { class Tests; } } 56 | 57 | // Use explicit namespace declaration 58 | class FOO::BAR::Tests : public CxxTest::TestSuite { 59 | public: 60 | void testEquality() { 61 | TS_ASSERT_EQUALS(1, 1); 62 | TS_ASSERT_EQUALS(1, 2); 63 | TS_ASSERT_EQUALS('a', 'A'); 64 | TS_ASSERT_EQUALS(1.0, -12345678900000000000000000000000000000000000000000.1234); 65 | } 66 | }; 67 | 68 | #endif // __NAMESPACE2_H 69 | -------------------------------------------------------------------------------- /test/stl.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (9 tests) 2 | In StlTraits::test_Pair: 3 | StlTraits.h:13: Error: Test failed: <3, "Three"> 4 | StlTraits.h:15: Error: Test failed: <"Four", 4.0000> 5 | In StlTraits::test_Vector: 6 | StlTraits.h:21: Trace: {} 7 | StlTraits.h:25: Error: Test failed: { 1, 2, 3 } 8 | StlTraits.h:28: Trace: {} 9 | StlTraits.h:32: Error: Test failed: { "One", "Two", "Three" } 10 | StlTraits.h:35: Trace: {} 11 | StlTraits.h:39: Error: Test failed: { <1, "One">, <2, "Two">, <3, "Three"> } 12 | In StlTraits::test_List: 13 | StlTraits.h:45: Trace: {} 14 | StlTraits.h:49: Error: Test failed: { 1, 2, 3 } 15 | StlTraits.h:52: Trace: {} 16 | StlTraits.h:56: Error: Test failed: { "One", "Two", "Three" } 17 | StlTraits.h:59: Trace: {} 18 | StlTraits.h:63: Error: Test failed: { <1, "One">, <2, "Two">, <3, "Three"> } 19 | In StlTraits::test_Set: 20 | StlTraits.h:69: Trace: {} 21 | StlTraits.h:73: Error: Test failed: { 1, 2, 3 } 22 | StlTraits.h:76: Trace: {} 23 | StlTraits.h:80: Error: Test failed: { "One", "Three", "Two" } 24 | StlTraits.h:83: Trace: {} 25 | StlTraits.h:87: Error: Test failed: { <1, "One">, <2, "Two">, <3, "Three"> } 26 | In StlTraits::test_Map: 27 | StlTraits.h:93: Trace: {} 28 | StlTraits.h:99: Error: Test failed: { <"Humpty", "Dumpty">, <"Jack", "Jill">, <"Ren", "Stimpy"> } 29 | StlTraits.h:102: Trace: {} 30 | StlTraits.h:111: Error: Test failed: { <6, { 2, 3 }>, <210, { 2, 3, 5, 7 }> } 31 | In StlTraits::test_Deque: 32 | StlTraits.h:117: Trace: {} 33 | StlTraits.h:122: Error: Test failed: { 4, 3, 2, 1 } 34 | In StlTraits::test_MultiMap: 35 | StlTraits.h:128: Trace: {} 36 | StlTraits.h:132: Error: Test failed: { <"One", 1.0000>, <"Two", 2.0000> } 37 | In StlTraits::test_MultiSet: 38 | StlTraits.h:138: Trace: {} 39 | StlTraits.h:142: Error: Test failed: { 123, 456 } 40 | In StlTraits::test_Complex: 41 | StlTraits.h:148: Error: Test failed: (3.1400 + 2.7100 * i) 42 | StlTraits.h:149: Error: Test failed: (1.0000 * i) 43 | StlTraits.h:150: Error: Test failed: 1.0000 44 | Failed 9 and Skipped 0 of 9 tests 45 | Success rate: 0% 46 | Error level = 9 47 | -------------------------------------------------------------------------------- /sample/Makefile.unix: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for UN*X-like systems 3 | # 4 | 5 | # Change this line if you want a different compiler 6 | CXXC = c++ -Wall -W -Werror -I. -I.. 7 | 8 | TESTGEN = ../bin/cxxtestgen 9 | 10 | # For the X11 GUI 11 | X11_FLAGS = -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 12 | 13 | # For the Qt GUI 14 | #QTDIR = /usr/lib/qt 15 | QTLIB = -lqt-mt 16 | #QTLIB = -lqt 17 | QT_FLAGS = -I$(QTDIR)/include -L$(QTDIR)/lib $(QTLIB) -O2 18 | 19 | TARGETS = error_printer stdio_printer yes_no_runner file_printer aborter only 20 | GUI_TARGETS = x11_runner qt_runner 21 | TESTS = *.h 22 | GUI_TESTS = gui/GreenYellowRed.h $(TESTS) 23 | 24 | all: $(TARGETS) 25 | 26 | clean: 27 | rm -f *~ *.o *.obj $(TARGETS) $(GUI_TARGETS) 28 | rm -f tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp 29 | rm -f x11_runner.cpp qt_runner.cpp 30 | 31 | distclean: clean 32 | rm -f Makefile 33 | 34 | run: error_printer 35 | ./error_printer 36 | 37 | run_x11: x11_runner 38 | ./x11_runner 39 | 40 | run_qt: qt_runner 41 | ./qt_runner 42 | 43 | error_printer.cpp: $(TESTS) 44 | $(TESTGEN) -o $@ --error-printer $(TESTS) 45 | 46 | stdio_printer.cpp: $(TESTS) 47 | $(TESTGEN) -o $@ --runner=StdioPrinter $(TESTS) 48 | 49 | file_printer.cpp: file_printer.tpl $(TESTS) 50 | $(TESTGEN) -o $@ --template=file_printer.tpl $(TESTS) 51 | 52 | aborter.cpp: aborter.tpl $(TESTS) 53 | $(TESTGEN) -o $@ --template=aborter.tpl $(TESTS) 54 | 55 | only.cpp: only.tpl $(TESTS) 56 | $(TESTGEN) -o $@ --template=only.tpl $(TESTS) 57 | 58 | tests.cpp: $(TESTS) 59 | $(TESTGEN) -o $@ $(TESTS) 60 | 61 | x11_runner.cpp: $(GUI_TESTS) 62 | $(TESTGEN) -o $@ --gui=X11Gui $(GUI_TESTS) 63 | 64 | qt_runner.cpp: $(GUI_TESTS) 65 | $(TESTGEN) -o $@ --gui=QtGui $(GUI_TESTS) 66 | 67 | %: %.cpp 68 | $(CXXC) -o $@ $< 69 | 70 | yes_no_runner: yes_no_runner.cpp tests.cpp 71 | $(CXXC) -o $@ $^ 72 | 73 | x11_runner: x11_runner.cpp 74 | $(CXXC) -o $@ $^ $(X11_FLAGS) 75 | 76 | qt_runner: qt_runner.cpp 77 | $(CXXC) -o $@ $^ $(QT_FLAGS) 78 | 79 | # 80 | # Local Variables: 81 | # compile-command: "make -fMakefile.unix" 82 | # End: 83 | # 84 | -------------------------------------------------------------------------------- /doc/examples/MyTestSuite8.h: -------------------------------------------------------------------------------- 1 | // MyTestSuite8.h 2 | #include 3 | #include 4 | #include 5 | 6 | // 7 | // Fixture1 counts its setUp()s and tearDown()s 8 | // 9 | class Fixture1 : public CxxTest::GlobalFixture 10 | { 11 | public: 12 | unsigned setUpCount; 13 | unsigned tearDownCount; 14 | 15 | Fixture1() { setUpCount = tearDownCount = 0; } 16 | 17 | bool setUp() { ++ setUpCount; return true; } 18 | bool tearDown() { ++ tearDownCount; return true; } 19 | 20 | bool setUpWorld() { printf("Starting a test suite\n"); return true;} 21 | bool tearDownWorld() { printf("Finishing a test suite\n"); return true;} 22 | }; 23 | static Fixture1 fixture1; 24 | 25 | 26 | // 27 | // Fixture2 counts its setUp()s and tearDown()s and makes sure 28 | // its setUp() is called after Fixture1 and its tearDown() before. 29 | // 30 | class Fixture2 : public Fixture1 31 | { 32 | public: 33 | bool setUp() 34 | { 35 | TS_ASSERT_EQUALS(setUpCount, fixture1.setUpCount - 1); 36 | TS_ASSERT_EQUALS(tearDownCount, fixture1.tearDownCount); 37 | return Fixture1::setUp(); 38 | } 39 | 40 | bool tearDown() 41 | { 42 | TS_ASSERT_EQUALS(setUpCount, fixture1.setUpCount); 43 | TS_ASSERT_EQUALS(tearDownCount, fixture1.tearDownCount); 44 | return Fixture1::tearDown(); 45 | } 46 | }; 47 | static Fixture2 fixture2; 48 | 49 | 50 | // 51 | // Verify the counts for the global fixtures 52 | // 53 | class MyTestSuite8 : public CxxTest::TestSuite 54 | { 55 | public: 56 | void testCountsFirstTime() 57 | { 58 | TS_ASSERT_EQUALS(fixture1.setUpCount, 1); 59 | TS_ASSERT_EQUALS(fixture1.tearDownCount, 0); 60 | TS_ASSERT_EQUALS(fixture2.setUpCount, 1); 61 | TS_ASSERT_EQUALS(fixture2.tearDownCount, 0); 62 | } 63 | 64 | void testCountsSecondTime() 65 | { 66 | TS_ASSERT_EQUALS(fixture1.setUpCount, 2); 67 | TS_ASSERT_EQUALS(fixture1.tearDownCount, 1); 68 | TS_ASSERT_EQUALS(fixture2.setUpCount, 2); 69 | TS_ASSERT_EQUALS(fixture2.tearDownCount, 1); 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /cxxtest/StdTestSuite.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__StdTestSuite_h__ 13 | #define __cxxtest__StdTestSuite_h__ 14 | 15 | // 16 | // This provides explicit partial specializations for STL-based 17 | // TestSuite comparison functions 18 | // 19 | 20 | namespace CxxTest 21 | { 22 | 23 | #ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION 24 | 25 | template 26 | struct delta, std::vector, D> 27 | { 28 | static bool test(std::vector x, std::vector y, D d) 29 | { 30 | if (x.size() != y.size()) 31 | { 32 | return false; 33 | } 34 | for (size_t i = 0; i < x.size(); ++i) 35 | if (! delta::test(x[i], y[i], d)) 36 | { 37 | return false; 38 | } 39 | return true; 40 | } 41 | }; 42 | 43 | template 44 | struct delta, std::list, D> 45 | { 46 | static bool test(std::list x, std::list y, D d) 47 | { 48 | typename std::list::const_iterator x_it = x.begin(); 49 | typename std::list::const_iterator y_it = y.begin(); 50 | for (; x_it != x.end(); ++x_it, ++y_it) 51 | { 52 | if (y_it == y.end()) 53 | { 54 | return false; 55 | } 56 | if (! delta::test(*x_it, *y_it, d)) 57 | { 58 | return false; 59 | } 60 | } 61 | return y_it == y.end(); 62 | } 63 | }; 64 | 65 | #endif 66 | 67 | } // namespace CxxTest 68 | 69 | #endif // __cxxtest__StdTestSuite_h__ 70 | 71 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # CxxTest: A lightweight C++ unit testing library. 3 | # Copyright (c) 2008 Sandia Corporation. 4 | # This software is distributed under the LGPL License v3 5 | # For more information, see the COPYING file in the top CxxTest directory. 6 | # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 7 | # the U.S. Government retains certain rights in this software. 8 | #------------------------------------------------------------------------- 9 | 10 | """ 11 | Script to generate the installer for cxxtest. 12 | """ 13 | 14 | classifiers = """\ 15 | Development Status :: 4 - Beta 16 | Intended Audience :: End Users/Desktop 17 | License :: OSI Approved :: LGPL License 18 | Natural Language :: English 19 | Operating System :: Microsoft :: Windows 20 | Operating System :: Unix 21 | Programming Language :: Python 22 | Topic :: Software Development :: Libraries :: Python Modules 23 | """ 24 | 25 | import os 26 | import sys 27 | from os.path import realpath, dirname 28 | if sys.version_info >= (3,0): 29 | sys.path.insert(0, dirname(realpath(__file__))+os.sep+'python3') 30 | os.chdir('python3') 31 | 32 | import cxxtest 33 | 34 | try: 35 | from setuptools import setup 36 | except ImportError: 37 | from distutils.core import setup 38 | 39 | doclines = cxxtest.__doc__.split("\n") 40 | 41 | setup(name="cxxtest", 42 | version=cxxtest.__version__, 43 | maintainer=cxxtest.__maintainer__, 44 | maintainer_email=cxxtest.__maintainer_email__, 45 | url = cxxtest.__url__, 46 | license = cxxtest.__license__, 47 | platforms = ["any"], 48 | description = doclines[0], 49 | classifiers = filter(None, classifiers.split("\n")), 50 | long_description = "\n".join(doclines[2:]), 51 | packages=['cxxtest'], 52 | keywords=['utility'], 53 | scripts=['scripts/cxxtestgen'] 54 | # 55 | # The entry_points option is not supported by distutils.core 56 | # 57 | #entry_points=""" 58 | #[console_scripts] 59 | #cxxtestgen = cxxtest.cxxtestgen:main 60 | #""" 61 | ) 62 | 63 | -------------------------------------------------------------------------------- /sample/Construct: -------------------------------------------------------------------------------- 1 | # -*- Perl -*- 2 | 3 | # 4 | # This file shows how to use CxxTest with Cons 5 | # 6 | 7 | $env = new cons( CXX => ("$^O" eq 'MSWin32') ? 'cl -nologo -GX' : 'c++', 8 | CPPPATH => '..', 9 | CXXTESTGEN => '../bin/cxxtestgen' ); 10 | 11 | @tests = <*.h>; 12 | 13 | # The error printer is the most basic runner 14 | CxxTestErrorPrinter $env 'error_printer', @tests; 15 | 16 | # You can also specify which runner you want to use 17 | CxxTestRunner $env 'stdio_printer', 'StdioPrinter', @tests; 18 | 19 | # For more control, use template files 20 | CxxTestTemplate $env 'file_printer', 'file_printer.tpl', @tests; 21 | 22 | # Or, you can always separate the tests from the runner 23 | CxxTest $env 'tests.cpp', '', @tests; 24 | Program $env 'yes_no_runner', ('yes_no_runner.cpp', 'tests.cpp'); 25 | 26 | 27 | # 28 | # Here is the code used to build these files 29 | # You can use this in your own Construct files 30 | # 31 | 32 | # cons::CxxTest $env $dst, $options, @srcs 33 | # Generates a CxxTest source file, passing the specified options to cxxtestgen 34 | sub cons::CxxTest($$$@) { 35 | my ($env, $dst, $options, @srcs) = @_; 36 | Command $env $dst, @srcs, "%CXXTESTGEN -o %> ${options} %<"; 37 | } 38 | 39 | # cons::CxxTestTemplate $env $dst, $template, @srcs 40 | # Generates and builds a CxxTest runner using a template file 41 | sub cons::CxxTestTemplate($$$@) { 42 | my ($env, $dst, $template, @srcs) = @_; 43 | my $source = "${dst}.cpp"; 44 | CxxTest $env $source, "--template=${template}", ($template, @srcs); 45 | Program $env $dst, $source; 46 | } 47 | 48 | # cons::CxxTestRunner $env $dst, $runner, @srcs 49 | # Generates and builds a CxxTest runner using the --runner option 50 | sub cons::CxxTestRunner($$$@) { 51 | my ($env, $dst, $runner, @srcs) = @_; 52 | my $source = "${dst}.cpp"; 53 | CxxTest $env $source, "--runner=${runner}", @srcs; 54 | Program $env $dst, $source; 55 | } 56 | 57 | # cons::CxxTestErrorPrinter $env $dst, @srcs 58 | # Generates and builds a CxxTest ErrorPrinter 59 | sub cons::CxxTestErrorPrinter($$@) { 60 | my ($env, $dst, @srcs) = @_; 61 | CxxTestRunner $env $dst, 'ErrorPrinter', @srcs; 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /test/GlobalFixtures.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file tests CxxTest global fixtures 3 | // 4 | 5 | #include 6 | #include 7 | 8 | // 9 | // Fixture1 counts its setUp()s and tearDown()s 10 | // 11 | class Fixture1 : public CxxTest::GlobalFixture 12 | { 13 | unsigned _setUpCount; 14 | unsigned _tearDownCount; 15 | 16 | public: 17 | Fixture1() { _setUpCount = _tearDownCount = 0; } 18 | bool setUp() { ++ _setUpCount; return true; } 19 | bool tearDown() { ++ _tearDownCount; return true; } 20 | unsigned setUpCount() const { return _setUpCount; } 21 | unsigned tearDownCount() const { return _tearDownCount; } 22 | }; 23 | 24 | // 25 | // We can rely on this file being included exactly once 26 | // and declare this global variable in the header file. 27 | // 28 | static Fixture1 fixture1; 29 | 30 | // 31 | // Fixture2 counts its setUp()s and tearDown()s and makes sure 32 | // its setUp() is called after Fixture1 and its tearDown() before. 33 | // 34 | class Fixture2 : public Fixture1 35 | { 36 | public: 37 | bool setUp() 38 | { 39 | TS_ASSERT_EQUALS(setUpCount(), fixture1.setUpCount() - 1); 40 | TS_ASSERT_EQUALS(tearDownCount(), fixture1.tearDownCount()); 41 | return Fixture1::setUp(); 42 | } 43 | 44 | bool tearDown() 45 | { 46 | TS_ASSERT_EQUALS(setUpCount(), fixture1.setUpCount()); 47 | TS_ASSERT_EQUALS(tearDownCount(), fixture1.tearDownCount()); 48 | return Fixture1::tearDown(); 49 | } 50 | }; 51 | 52 | static Fixture2 fixture2; 53 | 54 | class TestGlobalFixture : public CxxTest::TestSuite 55 | { 56 | public: 57 | void testCountsFirstTime() 58 | { 59 | TS_ASSERT_EQUALS(fixture1.setUpCount(), 1); 60 | TS_ASSERT_EQUALS(fixture1.tearDownCount(), 0); 61 | TS_ASSERT_EQUALS(fixture2.setUpCount(), 1); 62 | TS_ASSERT_EQUALS(fixture2.tearDownCount(), 0); 63 | } 64 | 65 | void testCountsSecondTime() 66 | { 67 | TS_ASSERT_EQUALS(fixture1.setUpCount(), 2); 68 | TS_ASSERT_EQUALS(fixture1.tearDownCount(), 1); 69 | TS_ASSERT_EQUALS(fixture2.setUpCount(), 2); 70 | TS_ASSERT_EQUALS(fixture2.tearDownCount(), 1); 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /cxxtest/XmlPrinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__XmlPrinter_h__ 13 | #define __cxxtest__XmlPrinter_h__ 14 | 15 | // 16 | // The XmlPrinter is a simple TestListener that 17 | // prints JUnit style xml to the output stream 18 | // 19 | 20 | 21 | #include 22 | 23 | #ifndef _CXXTEST_HAVE_STD 24 | # define _CXXTEST_HAVE_STD 25 | #endif // _CXXTEST_HAVE_STD 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #ifdef _CXXTEST_OLD_STD 32 | # include 33 | #else // !_CXXTEST_OLD_STD 34 | # include 35 | #endif // _CXXTEST_OLD_STD 36 | 37 | namespace CxxTest 38 | { 39 | class XmlPrinter : public XmlFormatter 40 | { 41 | public: 42 | XmlPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char* /*preLine*/ = ":", const char* /*postLine*/ = "") : 43 | XmlFormatter(new Adapter(o), new Adapter(ostr), &ostr) {} 44 | 45 | virtual ~XmlPrinter() 46 | { 47 | delete outputStream(); 48 | delete outputFileStream(); 49 | } 50 | 51 | private: 52 | 53 | std::ostringstream ostr; 54 | 55 | class Adapter : public OutputStream 56 | { 57 | CXXTEST_STD(ostream) &_o; 58 | public: 59 | Adapter(CXXTEST_STD(ostream) &o) : _o(o) {} 60 | void flush() { _o.flush(); } 61 | OutputStream &operator<<(const char *s) { _o << s; return *this; } 62 | OutputStream &operator<<(Manipulator m) { return OutputStream::operator<<(m); } 63 | OutputStream &operator<<(unsigned i) 64 | { 65 | char s[1 + 3 * sizeof(unsigned)]; 66 | numberToString(i, s); 67 | _o << s; 68 | return *this; 69 | } 70 | }; 71 | }; 72 | } 73 | 74 | #endif // __cxxtest__XmlPrinter_h__ 75 | 76 | -------------------------------------------------------------------------------- /test/eh_normals.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (13 tests) 2 | In NullCreate::: 3 | Exceptions.h:10: Error: Test failed: createSuite() failed 4 | Exceptions.h:10: Error: Assertion failed: suite() != 0 5 | In ThrowCreate::: 6 | Exceptions.h:22: Error: Test failed: Exception thrown from createSuite() 7 | Exceptions.h:22: Error: Expected (createSuite()) not to throw, but it did 8 | Exceptions.h:22: Error: Test failed: createSuite() failed 9 | Exceptions.h:22: Error: Assertion failed: suite() != 0 10 | . 11 | In ThrowDestroy::: 12 | Exceptions.h:35: Error: Test failed: destroySuite() failed 13 | Exceptions.h:35: Error: Expected (destroySuite()) not to throw, but it did 14 | In ThrowSetUp::testNothing: 15 | Exceptions.h:46: Error: Test failed: Exception thrown from setUp() 16 | Exceptions.h:46: Error: Expected (suite()->setUp(); ok=true) not to throw, but it did 17 | In ThrowTearDown::testNothing: 18 | Exceptions.h:55: Error: Test failed: Exception thrown from tearDown() 19 | Exceptions.h:55: Error: Expected (suite()->tearDown()) not to throw, but it did 20 | In TestThrowFromTest::testThrowSomething: 21 | Exceptions.h:61: Error: Test failed: Exception thrown from test 22 | In TestThrowFromTest::testMoveOn: 23 | Exceptions.h:68: Trace: One failed test doesn't affect the others 24 | . 25 | In DynamicAbort::test_Abort_on_fail_in_this_test: 26 | DynamicAbort.h:8: Error: Expected (1 == 2), found (1 != 2) 27 | DynamicAbort.h:9: Error: Expected (2 == 3), found (2 != 3) 28 | In DynamicAbort::test_Dont_abort_in_this_test: 29 | DynamicAbort.h:15: Error: Expected (1 == 2), found (1 != 2) 30 | DynamicAbort.h:16: Error: Expected (2 == 3), found (2 != 3) 31 | In DynamicAbort::test_Revert_to_abort: 32 | DynamicAbort.h:21: Error: Expected (1 == 2), found (1 != 2) 33 | DynamicAbort.h:22: Error: Expected (2 == 3), found (2 != 3) 34 | In SetUpWorksAllTests::test_Dont_abort_in_this_test: 35 | DynamicAbort.h:36: Error: Expected (1 == 2), found (1 != 2) 36 | DynamicAbort.h:37: Error: Expected (2 == 3), found (2 != 3) 37 | In SetUpWorksAllTests::test_Dont_abort_in_this_test_either: 38 | DynamicAbort.h:42: Error: Expected (1 == 2), found (1 != 2) 39 | DynamicAbort.h:43: Error: Expected (2 == 3), found (2 != 3) 40 | In SetUpWorksAllTests::test_Override_in_this_test: 41 | DynamicAbort.h:49: Error: Expected (1 == 2), found (1 != 2) 42 | Failed 12 and Skipped 0 of 13 tests 43 | Success rate: 7% 44 | Error level = 12 45 | -------------------------------------------------------------------------------- /cxxtest/Descriptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__Descriptions_cpp__ 13 | #define __cxxtest__Descriptions_cpp__ 14 | 15 | #include 16 | 17 | namespace CxxTest 18 | { 19 | TestDescription::~TestDescription() {} 20 | SuiteDescription::~SuiteDescription() {} 21 | WorldDescription::~WorldDescription() {} 22 | 23 | // 24 | // Convert total tests to string 25 | // 26 | #ifndef _CXXTEST_FACTOR 27 | char *WorldDescription::strTotalTests(char *s) const 28 | { 29 | numberToString(numTotalTests(), s); 30 | return s; 31 | } 32 | #else // _CXXTEST_FACTOR 33 | char *WorldDescription::strTotalTests(char *s) const 34 | { 35 | char *p = numberToString(numTotalTests(), s); 36 | 37 | if (numTotalTests() <= 1) 38 | { 39 | return s; 40 | } 41 | 42 | unsigned n = numTotalTests(); 43 | unsigned numFactors = 0; 44 | 45 | for (unsigned factor = 2; (factor * factor) <= n; factor += (factor == 2) ? 1 : 2) 46 | { 47 | unsigned power; 48 | 49 | for (power = 0; (n % factor) == 0; n /= factor) 50 | { 51 | ++ power; 52 | } 53 | 54 | if (!power) 55 | { 56 | continue; 57 | } 58 | 59 | p = numberToString(factor, copyString(p, (numFactors == 0) ? " = " : " * ")); 60 | if (power > 1) 61 | { 62 | p = numberToString(power, copyString(p, "^")); 63 | } 64 | ++ numFactors; 65 | } 66 | 67 | if (n > 1) 68 | { 69 | if (!numFactors) 70 | { 71 | copyString(p, tracker().failedTests() ? " :(" : tracker().warnings() ? " :|" : " :)"); 72 | } 73 | else 74 | { 75 | numberToString(n, copyString(p, " * ")); 76 | } 77 | } 78 | return s; 79 | } 80 | #endif // _CXXTEST_FACTOR 81 | } 82 | 83 | #endif // __cxxtest__Descriptions_cpp__ 84 | -------------------------------------------------------------------------------- /test/inheritance.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (14 tests) 2 | In InheritedTests1::testEquality: 3 | InheritedTest.h:16: Error: Expected (1 == 2), found (1 != 2) 4 | InheritedTest.h:17: Error: Expected ('a' == 'A'), found ('a' != 'A') 5 | InheritedTest.h:18: Error: Expected (1.0 == -12345678900000000000000000000000000000000000000000.1234), found (1.0000 != -1.2345E50) 6 | In InheritedTests1::testAddition: 7 | InheritedTest.h:24: Error: Expected (2 + 2 == 5), found (4 != 5) 8 | In InheritedTests1::TestMultiplication: 9 | InheritedTest.h:30: Error: Expected (4 * 4 == 44), found (16 != 44) 10 | InheritedTest.h:31: Error: Expected (-2 * -2 != 4), found (4) 11 | In InheritedTests1::testComparison: 12 | InheritedTest.h:37: Error: Expected (-1 < -2), found (-1 >= -2) 13 | In InheritedTests1::testTheWorldIsCrazy: 14 | InheritedTest.h:42: Error: Expected (true == false), found (true != false) 15 | In InheritedTests1::test_Failure: 16 | InheritedTest.h:47: Error: Test failed: Not implemented 17 | InheritedTest.h:48: Error: Test failed: 1569779912 18 | In InheritedTests1::test_TS_WARN_macro: 19 | InheritedTest.h:53: Warning: Just a friendly warning 20 | InheritedTest.h:54: Warning: Warnings don't abort the test 21 | . 22 | In InheritedTests2::testEquality: 23 | InheritedTest.h:16: Error: Expected (1 == 2), found (1 != 2) 24 | InheritedTest.h:17: Error: Expected ('a' == 'A'), found ('a' != 'A') 25 | InheritedTest.h:18: Error: Expected (1.0 == -12345678900000000000000000000000000000000000000000.1234), found (1.0000 != -1.2345E50) 26 | In InheritedTests2::testAddition: 27 | InheritedTest.h:24: Error: Expected (2 + 2 == 5), found (4 != 5) 28 | In InheritedTests2::TestMultiplication: 29 | InheritedTest.h:30: Error: Expected (4 * 4 == 44), found (16 != 44) 30 | InheritedTest.h:31: Error: Expected (-2 * -2 != 4), found (4) 31 | In InheritedTests2::testComparison: 32 | InheritedTest.h:37: Error: Expected (-1 < -2), found (-1 >= -2) 33 | In InheritedTests2::testTheWorldIsCrazy: 34 | InheritedTest.h:42: Error: Expected (true == false), found (true != false) 35 | In InheritedTests2::test_Failure: 36 | InheritedTest.h:47: Error: Test failed: Not implemented 37 | InheritedTest.h:48: Error: Test failed: 1569779912 38 | In InheritedTests2::test_TS_WARN_macro: 39 | InheritedTest.h:53: Warning: Just a friendly warning 40 | InheritedTest.h:54: Warning: Warnings don't abort the test 41 | . 42 | Failed 12 and Skipped 0 of 14 tests 43 | Success rate: 14% 44 | Error level = 12 45 | -------------------------------------------------------------------------------- /cxxtest/ErrorPrinter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | CxxTest: A lightweight C++ unit testing library. 4 | Copyright (c) 2008 Sandia Corporation. 5 | This software is distributed under the LGPL License v3 6 | For more information, see the COPYING file in the top CxxTest directory. 7 | Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 8 | the U.S. Government retains certain rights in this software. 9 | ------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef __cxxtest__ErrorPrinter_h__ 13 | #define __cxxtest__ErrorPrinter_h__ 14 | 15 | // 16 | // The ErrorPrinter is a simple TestListener that 17 | // just prints "OK" if everything goes well, otherwise 18 | // reports the error in the format of compiler messages. 19 | // The ErrorPrinter uses std::cout 20 | // 21 | 22 | #include 23 | 24 | #ifndef _CXXTEST_HAVE_STD 25 | # define _CXXTEST_HAVE_STD 26 | #endif // _CXXTEST_HAVE_STD 27 | 28 | #include 29 | #include 30 | 31 | #ifdef _CXXTEST_OLD_STD 32 | # include 33 | #else // !_CXXTEST_OLD_STD 34 | # include 35 | #endif // _CXXTEST_OLD_STD 36 | 37 | namespace CxxTest 38 | { 39 | class ErrorPrinter : public ErrorFormatter 40 | { 41 | public: 42 | ErrorPrinter(CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char *preLine = ":", const char *postLine = "", 43 | const char *errorString = "Error", 44 | const char *warningString = "Warning") : 45 | ErrorFormatter(new Adapter(o), preLine, postLine, errorString, warningString) {} 46 | virtual ~ErrorPrinter() { delete outputStream(); } 47 | 48 | private: 49 | class Adapter : public OutputStream 50 | { 51 | CXXTEST_STD(ostream) &_o; 52 | public: 53 | Adapter(CXXTEST_STD(ostream) &o) : _o(o) {} 54 | void flush() { _o.flush(); } 55 | OutputStream &operator<<(const char *s) { _o << s; return *this; } 56 | OutputStream &operator<<(Manipulator m) { return OutputStream::operator<<(m); } 57 | OutputStream &operator<<(unsigned i) 58 | { 59 | char s[1 + 3 * sizeof(unsigned)]; 60 | numberToString(i, s); 61 | _o << s; 62 | return *this; 63 | } 64 | }; 65 | }; 66 | } 67 | 68 | #endif // __cxxtest__ErrorPrinter_h__ 69 | -------------------------------------------------------------------------------- /test/factor.out: -------------------------------------------------------------------------------- 1 | Running cxxtest tests (2 tests) 2 | In Factor::test_Some_numbers: 3 | Factor.h:30: Warning: 53 :) 4 | Factor.h:33: Warning: 0 5 | Factor.h:33: Warning: 1 6 | Factor.h:33: Warning: 2 :| 7 | Factor.h:33: Warning: 3 :| 8 | Factor.h:33: Warning: 4 = 2^2 9 | Factor.h:33: Warning: 5 :| 10 | Factor.h:33: Warning: 6 = 2 * 3 11 | Factor.h:33: Warning: 7 :| 12 | Factor.h:33: Warning: 8 = 2^3 13 | Factor.h:33: Warning: 9 = 3^2 14 | Factor.h:33: Warning: 10 = 2 * 5 15 | Factor.h:33: Warning: 11 :| 16 | Factor.h:33: Warning: 12 = 2^2 * 3 17 | Factor.h:33: Warning: 13 :| 18 | Factor.h:33: Warning: 14 = 2 * 7 19 | Factor.h:33: Warning: 15 = 3 * 5 20 | Factor.h:33: Warning: 16 = 2^4 21 | Factor.h:33: Warning: 17 :| 22 | Factor.h:33: Warning: 18 = 2 * 3^2 23 | Factor.h:33: Warning: 19 :| 24 | Factor.h:33: Warning: 20 = 2^2 * 5 25 | Factor.h:33: Warning: 21 = 3 * 7 26 | Factor.h:33: Warning: 22 = 2 * 11 27 | Factor.h:33: Warning: 23 :| 28 | Factor.h:33: Warning: 24 = 2^3 * 3 29 | Factor.h:33: Warning: 25 = 5^2 30 | Factor.h:33: Warning: 26 = 2 * 13 31 | Factor.h:33: Warning: 27 = 3^3 32 | Factor.h:33: Warning: 28 = 2^2 * 7 33 | Factor.h:33: Warning: 29 :| 34 | Factor.h:33: Warning: 30 = 2 * 3 * 5 35 | Factor.h:33: Warning: 31 :| 36 | Factor.h:32: Error: Expected (n != 32), found (32) 37 | Factor.h:33: Warning: 32 = 2^5 38 | Factor.h:33: Warning: 33 = 3 * 11 39 | Factor.h:33: Warning: 34 = 2 * 17 40 | Factor.h:33: Warning: 35 = 5 * 7 41 | Factor.h:33: Warning: 36 = 2^2 * 3^2 42 | Factor.h:33: Warning: 37 :( 43 | Factor.h:33: Warning: 38 = 2 * 19 44 | Factor.h:33: Warning: 39 = 3 * 13 45 | Factor.h:33: Warning: 40 = 2^3 * 5 46 | Factor.h:33: Warning: 41 :( 47 | Factor.h:33: Warning: 42 = 2 * 3 * 7 48 | Factor.h:33: Warning: 43 :( 49 | Factor.h:33: Warning: 44 = 2^2 * 11 50 | Factor.h:33: Warning: 45 = 3^2 * 5 51 | Factor.h:33: Warning: 46 = 2 * 23 52 | Factor.h:33: Warning: 47 :( 53 | Factor.h:33: Warning: 48 = 2^4 * 3 54 | Factor.h:33: Warning: 49 = 7^2 55 | Factor.h:33: Warning: 50 = 2 * 5^2 56 | Factor.h:33: Warning: 51 = 3 * 17 57 | Factor.h:33: Warning: 52 = 2^2 * 13 58 | Factor.h:33: Warning: 53 :( 59 | Factor.h:33: Warning: 54 = 2 * 3^3 60 | Factor.h:33: Warning: 55 = 5 * 11 61 | Factor.h:33: Warning: 56 = 2^3 * 7 62 | Factor.h:33: Warning: 57 = 3 * 19 63 | Factor.h:33: Warning: 58 = 2 * 29 64 | Factor.h:33: Warning: 59 :( 65 | Factor.h:33: Warning: 60 = 2^2 * 3 * 5 66 | Factor.h:33: Warning: 61 :( 67 | Factor.h:33: Warning: 62 = 2 * 31 68 | Factor.h:33: Warning: 63 = 3^2 * 7 69 | . 70 | Failed 1 of 2 :( tests 71 | Success rate: 50% 72 | Error level = 1 73 | --------------------------------------------------------------------------------