From 3820593bb8dfdca4e2e17c70b278065b7f7894d9 Mon Sep 17 00:00:00 2001
From: Max Horn
Date: Wed, 29 Mar 2006 10:25:48 +0000
Subject: bringing cxxtest-3.10.1 to ScummVM's main branch
svn-id: r21488
---
test/cxxtest/COPYING | 504 ++++++
test/cxxtest/README | 63 +
test/cxxtest/TODO | 34 +
test/cxxtest/Versions | 152 ++
test/cxxtest/cxxtest.spec | 40 +
test/cxxtest/cxxtest/Descriptions.cpp | 58 +
test/cxxtest/cxxtest/Descriptions.h | 74 +
test/cxxtest/cxxtest/DummyDescriptions.cpp | 49 +
test/cxxtest/cxxtest/DummyDescriptions.h | 76 +
test/cxxtest/cxxtest/ErrorFormatter.h | 281 ++++
test/cxxtest/cxxtest/ErrorPrinter.h | 55 +
test/cxxtest/cxxtest/Flags.h | 121 ++
test/cxxtest/cxxtest/GlobalFixture.cpp | 23 +
test/cxxtest/cxxtest/GlobalFixture.h | 30 +
test/cxxtest/cxxtest/Gui.h | 178 ++
test/cxxtest/cxxtest/LinkedList.cpp | 172 ++
test/cxxtest/cxxtest/LinkedList.h | 65 +
test/cxxtest/cxxtest/Mock.h | 350 ++++
test/cxxtest/cxxtest/ParenPrinter.h | 21 +
test/cxxtest/cxxtest/QtGui.h | 271 ++++
test/cxxtest/cxxtest/RealDescriptions.cpp | 311 ++++
test/cxxtest/cxxtest/RealDescriptions.h | 223 +++
test/cxxtest/cxxtest/Root.cpp | 18 +
test/cxxtest/cxxtest/SelfTest.h | 7 +
test/cxxtest/cxxtest/StdHeaders.h | 25 +
test/cxxtest/cxxtest/StdValueTraits.h | 229 +++
test/cxxtest/cxxtest/StdioFilePrinter.h | 41 +
test/cxxtest/cxxtest/StdioPrinter.h | 22 +
test/cxxtest/cxxtest/TeeListener.h | 182 +++
test/cxxtest/cxxtest/TestListener.h | 70 +
test/cxxtest/cxxtest/TestRunner.h | 125 ++
test/cxxtest/cxxtest/TestSuite.cpp | 138 ++
test/cxxtest/cxxtest/TestSuite.h | 512 ++++++
test/cxxtest/cxxtest/TestTracker.cpp | 248 +++
test/cxxtest/cxxtest/TestTracker.h | 114 ++
test/cxxtest/cxxtest/ValueTraits.cpp | 140 ++
test/cxxtest/cxxtest/ValueTraits.h | 377 +++++
test/cxxtest/cxxtest/Win32Gui.h | 531 ++++++
test/cxxtest/cxxtest/X11Gui.h | 327 ++++
test/cxxtest/cxxtest/YesNoRunner.h | 29 +
test/cxxtest/cxxtestgen.pl | 551 +++++++
test/cxxtest/cxxtestgen.py | 593 +++++++
test/cxxtest/docs/convert.pl | 83 +
test/cxxtest/docs/guide.html | 1960 +++++++++++++++++++++++
test/cxxtest/docs/index.html | 56 +
test/cxxtest/docs/qt.png | Bin 0 -> 13630 bytes
test/cxxtest/docs/qt2.png | Bin 0 -> 11684 bytes
test/cxxtest/docs/win32.png | Bin 0 -> 1709 bytes
test/cxxtest/docs/x11.png | Bin 0 -> 1342 bytes
test/cxxtest/sample/Construct | 64 +
test/cxxtest/sample/CreatedTest.h | 31 +
test/cxxtest/sample/DeltaTest.h | 27 +
test/cxxtest/sample/EnumTraits.h | 39 +
test/cxxtest/sample/ExceptionTest.h | 52 +
test/cxxtest/sample/FixtureTest.h | 37 +
test/cxxtest/sample/Makefile.PL | 32 +
test/cxxtest/sample/Makefile.bcc32 | 94 ++
test/cxxtest/sample/Makefile.msvc | 93 ++
test/cxxtest/sample/Makefile.unix | 88 +
test/cxxtest/sample/MessageTest.h | 30 +
test/cxxtest/sample/SimpleTest.h | 59 +
test/cxxtest/sample/TraitsTest.h | 69 +
test/cxxtest/sample/aborter.tpl | 16 +
test/cxxtest/sample/file_printer.tpl | 22 +
test/cxxtest/sample/gui/GreenYellowRed.h | 57 +
test/cxxtest/sample/mock/Dice.cpp | 14 +
test/cxxtest/sample/mock/Dice.h | 13 +
test/cxxtest/sample/mock/Makefile | 22 +
test/cxxtest/sample/mock/MockStdlib.h | 31 +
test/cxxtest/sample/mock/T/stdlib.h | 13 +
test/cxxtest/sample/mock/TestDice.h | 62 +
test/cxxtest/sample/mock/mock_stdlib.cpp | 2 +
test/cxxtest/sample/mock/real_stdlib.cpp | 2 +
test/cxxtest/sample/mock/roll.cpp | 11 +
test/cxxtest/sample/msvc/CxxTest_1_Run.dsp | 93 ++
test/cxxtest/sample/msvc/CxxTest_2_Build.dsp | 94 ++
test/cxxtest/sample/msvc/CxxTest_3_Generate.dsp | 93 ++
test/cxxtest/sample/msvc/CxxTest_Workspace.dsw | 59 +
test/cxxtest/sample/msvc/FixFiles.bat | 212 +++
test/cxxtest/sample/msvc/Makefile | 36 +
test/cxxtest/sample/msvc/ReadMe.txt | 30 +
test/cxxtest/sample/only.tpl | 33 +
test/cxxtest/sample/parts/Makefile.unix | 39 +
test/cxxtest/sample/winddk/Makefile | 2 +
test/cxxtest/sample/winddk/Makefile.inc | 15 +
test/cxxtest/sample/winddk/RunTests.tpl | 13 +
test/cxxtest/sample/winddk/SOURCES | 46 +
test/cxxtest/sample/yes_no_runner.cpp | 11 +
88 files changed, 11285 insertions(+)
create mode 100644 test/cxxtest/COPYING
create mode 100644 test/cxxtest/README
create mode 100644 test/cxxtest/TODO
create mode 100644 test/cxxtest/Versions
create mode 100644 test/cxxtest/cxxtest.spec
create mode 100644 test/cxxtest/cxxtest/Descriptions.cpp
create mode 100644 test/cxxtest/cxxtest/Descriptions.h
create mode 100644 test/cxxtest/cxxtest/DummyDescriptions.cpp
create mode 100644 test/cxxtest/cxxtest/DummyDescriptions.h
create mode 100644 test/cxxtest/cxxtest/ErrorFormatter.h
create mode 100644 test/cxxtest/cxxtest/ErrorPrinter.h
create mode 100644 test/cxxtest/cxxtest/Flags.h
create mode 100644 test/cxxtest/cxxtest/GlobalFixture.cpp
create mode 100644 test/cxxtest/cxxtest/GlobalFixture.h
create mode 100644 test/cxxtest/cxxtest/Gui.h
create mode 100644 test/cxxtest/cxxtest/LinkedList.cpp
create mode 100644 test/cxxtest/cxxtest/LinkedList.h
create mode 100644 test/cxxtest/cxxtest/Mock.h
create mode 100644 test/cxxtest/cxxtest/ParenPrinter.h
create mode 100644 test/cxxtest/cxxtest/QtGui.h
create mode 100644 test/cxxtest/cxxtest/RealDescriptions.cpp
create mode 100644 test/cxxtest/cxxtest/RealDescriptions.h
create mode 100644 test/cxxtest/cxxtest/Root.cpp
create mode 100644 test/cxxtest/cxxtest/SelfTest.h
create mode 100644 test/cxxtest/cxxtest/StdHeaders.h
create mode 100644 test/cxxtest/cxxtest/StdValueTraits.h
create mode 100644 test/cxxtest/cxxtest/StdioFilePrinter.h
create mode 100644 test/cxxtest/cxxtest/StdioPrinter.h
create mode 100644 test/cxxtest/cxxtest/TeeListener.h
create mode 100644 test/cxxtest/cxxtest/TestListener.h
create mode 100644 test/cxxtest/cxxtest/TestRunner.h
create mode 100644 test/cxxtest/cxxtest/TestSuite.cpp
create mode 100644 test/cxxtest/cxxtest/TestSuite.h
create mode 100644 test/cxxtest/cxxtest/TestTracker.cpp
create mode 100644 test/cxxtest/cxxtest/TestTracker.h
create mode 100644 test/cxxtest/cxxtest/ValueTraits.cpp
create mode 100644 test/cxxtest/cxxtest/ValueTraits.h
create mode 100644 test/cxxtest/cxxtest/Win32Gui.h
create mode 100644 test/cxxtest/cxxtest/X11Gui.h
create mode 100644 test/cxxtest/cxxtest/YesNoRunner.h
create mode 100755 test/cxxtest/cxxtestgen.pl
create mode 100755 test/cxxtest/cxxtestgen.py
create mode 100644 test/cxxtest/docs/convert.pl
create mode 100644 test/cxxtest/docs/guide.html
create mode 100644 test/cxxtest/docs/index.html
create mode 100644 test/cxxtest/docs/qt.png
create mode 100644 test/cxxtest/docs/qt2.png
create mode 100644 test/cxxtest/docs/win32.png
create mode 100644 test/cxxtest/docs/x11.png
create mode 100644 test/cxxtest/sample/Construct
create mode 100644 test/cxxtest/sample/CreatedTest.h
create mode 100644 test/cxxtest/sample/DeltaTest.h
create mode 100644 test/cxxtest/sample/EnumTraits.h
create mode 100644 test/cxxtest/sample/ExceptionTest.h
create mode 100644 test/cxxtest/sample/FixtureTest.h
create mode 100755 test/cxxtest/sample/Makefile.PL
create mode 100644 test/cxxtest/sample/Makefile.bcc32
create mode 100644 test/cxxtest/sample/Makefile.msvc
create mode 100644 test/cxxtest/sample/Makefile.unix
create mode 100644 test/cxxtest/sample/MessageTest.h
create mode 100644 test/cxxtest/sample/SimpleTest.h
create mode 100644 test/cxxtest/sample/TraitsTest.h
create mode 100644 test/cxxtest/sample/aborter.tpl
create mode 100644 test/cxxtest/sample/file_printer.tpl
create mode 100644 test/cxxtest/sample/gui/GreenYellowRed.h
create mode 100644 test/cxxtest/sample/mock/Dice.cpp
create mode 100644 test/cxxtest/sample/mock/Dice.h
create mode 100644 test/cxxtest/sample/mock/Makefile
create mode 100644 test/cxxtest/sample/mock/MockStdlib.h
create mode 100644 test/cxxtest/sample/mock/T/stdlib.h
create mode 100644 test/cxxtest/sample/mock/TestDice.h
create mode 100644 test/cxxtest/sample/mock/mock_stdlib.cpp
create mode 100644 test/cxxtest/sample/mock/real_stdlib.cpp
create mode 100644 test/cxxtest/sample/mock/roll.cpp
create mode 100644 test/cxxtest/sample/msvc/CxxTest_1_Run.dsp
create mode 100644 test/cxxtest/sample/msvc/CxxTest_2_Build.dsp
create mode 100644 test/cxxtest/sample/msvc/CxxTest_3_Generate.dsp
create mode 100644 test/cxxtest/sample/msvc/CxxTest_Workspace.dsw
create mode 100644 test/cxxtest/sample/msvc/FixFiles.bat
create mode 100644 test/cxxtest/sample/msvc/Makefile
create mode 100644 test/cxxtest/sample/msvc/ReadMe.txt
create mode 100644 test/cxxtest/sample/only.tpl
create mode 100644 test/cxxtest/sample/parts/Makefile.unix
create mode 100644 test/cxxtest/sample/winddk/Makefile
create mode 100644 test/cxxtest/sample/winddk/Makefile.inc
create mode 100644 test/cxxtest/sample/winddk/RunTests.tpl
create mode 100644 test/cxxtest/sample/winddk/SOURCES
create mode 100644 test/cxxtest/sample/yes_no_runner.cpp
diff --git a/test/cxxtest/COPYING b/test/cxxtest/COPYING
new file mode 100644
index 0000000000..b1e3f5a263
--- /dev/null
+++ b/test/cxxtest/COPYING
@@ -0,0 +1,504 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/test/cxxtest/README b/test/cxxtest/README
new file mode 100644
index 0000000000..40722cd941
--- /dev/null
+++ b/test/cxxtest/README
@@ -0,0 +1,63 @@
+Introduction
+------------
+
+CxxTest is a JUnit/CppUnit/xUnit-like framework for C++.
+
+Its advantages over existing alternatives are that it:
+ - Doesn't require RTTI
+ - Doesn't require member template functions
+ - Doesn't require exception handling
+ - Doesn't require any external libraries (including memory management,
+ file/console I/O, graphics libraries)
+
+This makes it extremely portable and usable.
+
+CxxTest is available under the GNU Lesser General Public Licence (LGPL).
+See http://www.gnu.org/copyleft/lesser.html for the license.
+
+Simple user's guide
+-------------------
+
+1. Create a test suite header file:
+
+MyTest.h:
+ #include
+
+ class MyTestSuite : public CxxTest::TestSuite
+ {
+ public:
+ void testAddition( void )
+ {
+ TS_ASSERT( 1 + 1 > 1 );
+ TS_ASSERT_EQUALS( 1 + 1, 2 );
+ }
+ };
+
+
+2. Generate the tests file:
+
+ # cxxtestgen.pl -o tests.cpp MyTestSuite.h
+
+
+3. Create a main function that runs the tests
+
+main.cpp:
+ #include
+
+ int main( void )
+ {
+ CxxText::ErrorPrinter::runAllTests();
+ return 0;
+ }
+
+
+4. Compile and run!
+
+ # g++ -o main main.cpp tests.cpp
+ # ./main
+ Running 1 test(s).OK!
+
+
+Advanced User's Guide
+---------------------
+See docs/guide.html.
diff --git a/test/cxxtest/TODO b/test/cxxtest/TODO
new file mode 100644
index 0000000000..7a7f926e50
--- /dev/null
+++ b/test/cxxtest/TODO
@@ -0,0 +1,34 @@
+This is an -*- Outline -*- of ideas for future versions of CxxTest.
+It is not meant to be "human readable".
+
+* CxxTest To Do list
+
+** Mock framework
+
+Write some mocks
+
+*** Distribution
+Seperate packages (w/ binaries)? How would that be used?
+For Windows: .lib for "Real" and "Mock" parts.
+For Linux: Maybe. Different compilers etc.
+So probably only source release with Makefiles and .ds[pw]? Or just Win32 binary.
+
+**** Installation?
+extract cxxtest-x.y.z.tar.gz
+(extract cxxtest-mock-x.y.z.tar.gz) ?
+make -C cxxtest/Real
+make -C cxxtest/Mock
+
+or maybe make -C cxxtest -f Makefile.mock
+but then Makefile.mock.bcc32, Makefile.mock.msvc, Makefile.mock.gcc, and heaven knows what else.
+
+Could put the Makefile.mock.* in cxxtest/Real and cxxtest/Mock or in cxxtest/T
+
+Maybe this should be a different package altogether?
+Seems logical, since they evolve separately. But then you'd want to download both.
+
+** Thoughts
+-fomit-frame-pointer
+
+** TS_HEX
+
diff --git a/test/cxxtest/Versions b/test/cxxtest/Versions
new file mode 100644
index 0000000000..b35cba20ab
--- /dev/null
+++ b/test/cxxtest/Versions
@@ -0,0 +1,152 @@
+CxxTest Releases
+================
+
+Version 3.10.1 (2004-12-01):
+----------------------------
+ - Improved support for VC7
+ - Fixed clash with some versions of STL
+
+Version 3.10.0 (2004-11-20):
+----------------------------
+ - Added mock framework for global functions
+ - Added TS_ASSERT_THROWS_ASSERT and TS_ASSERT_THROWS_EQUALS
+ - Added CXXTEST_ENUM_TRAITS
+ - Improved support for STL classes (vector, map etc.)
+ - Added support for Digital Mars compiler
+ - Reduced root/part compilation time and binary size
+ - Support C++-style commenting of tests
+
+Version 3.9.1 (2004-01-19):
+---------------------------
+ - Fixed small bug with runner exit code
+ - Embedded test suites are now deprecated
+
+Version 3.9.0 (2004-01-17):
+---------------------------
+ - Added TS_TRACE
+ - Added --no-static-init
+ - CxxTest::setAbortTestOnFail() works even without --abort-on-fail
+
+Version 3.8.5 (2004-01-08):
+---------------------------
+ - Added --no-eh
+ - Added CxxTest::setAbortTestOnFail() and CXXTEST_DEFAULT_ABORT
+ - Added CxxTest::setMaxDumpSize()
+ - Added StdioFilePrinter
+
+Version 3.8.4 (2003-12-31):
+---------------------------
+ - Split distribution into cxxtest and cxxtest-selftest
+ - Added `sample/msvc/FixFiles.bat'
+
+Version 3.8.3 (2003-12-24):
+---------------------------
+ - Added TS_ASSERT_PREDICATE
+ - Template files can now specify where to insert the preamble
+ - Added a sample Visual Studio workspace in `sample/msvc'
+ - Can compile in MSVC with warning level 4
+ - Changed output format slightly
+
+Version 3.8.1 (2003-12-21):
+---------------------------
+ - Fixed small bug when using multiple --part files.
+ - Fixed X11 GUI crash when there's no X server.
+ - Added GlobalFixture::setUpWorld()/tearDownWorld()
+ - Added leaveOnly(), activateAllTests() and `sample/only.tpl'
+ - Should now run without warnings on Sun compiler.
+
+Version 3.8.0 (2003-12-13):
+---------------------------
+ - Fixed bug where `Root.cpp' needed exception handling
+ - Added TS_ASSERT_RELATION
+ - TSM_ macros now also tell you what went wrong
+ - Renamed Win32Gui::free() to avoid clashes
+ - Now compatible with more versions of Borland compiler
+ - Improved the documentation
+
+Version 3.7.1 (2003-09-29):
+---------------------------
+ - Added --version
+ - Compiles with even more exotic g++ warnings
+ - Win32 Gui compiles with UNICODE
+ - Should compile on some more platforms (Sun Forte, HP aCC)
+
+Version 3.7.0 (2003-09-20):
+---------------------------
+ - Added TS_ASSERT_LESS_THAN_EQUALS
+ - Minor cleanups
+
+Version 3.6.1 (2003-09-15):
+---------------------------
+ - Improved QT GUI
+ - Improved portability some more
+
+Version 3.6.0 (2003-09-04):
+---------------------------
+ - Added --longlong
+ - Some portability improvements
+
+Version 3.5.1 (2003-09-03):
+---------------------------
+ - Major internal rewrite of macros
+ - Added TS_ASSERT_SAME_DATA
+ - Added --include option
+ - Added --part and --root to enable splitting the test runner
+ - Added global fixtures
+ - Enhanced Win32 GUI with timers, -keep and -title
+ - Now compiles with strict warnings
+
+Version 3.1.1 (2003-08-27):
+---------------------------
+ - Fixed small bug in TS_ASSERT_THROWS_*()
+
+Version 3.1.0 (2003-08-23):
+---------------------------
+ - Default ValueTraits now dumps value as hex bytes
+ - Fixed double invocation bug (e.g. TS_FAIL(functionWithSideEffects()))
+ - TS_ASSERT_THROWS*() are now "abort on fail"-friendly
+ - Win32 GUI now supports Windows 98 and doesn't need comctl32.lib
+
+Version 3.0.1 (2003-08-07):
+---------------------------
+ - Added simple GUI for X11, Win32 and Qt
+ - Added TS_WARN() macro
+ - Removed --exit-code
+ - Improved samples
+ - Improved support for older (pre-std::) compilers
+ - Made a PDF version of the User's Guide
+
+Version 2.8.4 (2003-07-21):
+---------------------------
+ - Now supports g++-3.3
+ - Added --have-eh
+ - Fixed bug in numberToString()
+
+Version 2.8.3 (2003-06-30):
+---------------------------
+ - Fixed bugs in cxxtestgen.pl
+ - Fixed warning for some compilers in ErrorPrinter/StdioPrinter
+ - Thanks Martin Jost for pointing out these problems!
+
+Version 2.8.2 (2003-06-10):
+---------------------------
+ - Fixed bug when using CXXTEST_ABORT_TEST_ON_FAIL without standard library
+ - Added CXXTEST_USER_TRAITS
+ - Added --abort-on-fail
+
+Version 2.8.1 (2003-01-16):
+---------------------------
+ - Fixed charToString() for negative chars
+
+Version 2.8.0 (2003-01-13):
+---------------------------
+ - Added CXXTEST_ABORT_TEST_ON_FAIL for xUnit-like behaviour
+ - Added `sample/winddk'
+ - Improved ValueTraits
+ - Improved output formatter
+ - Started version history
+
+Version 2.7.0 (2002-09-29):
+---------------------------
+ - Added embedded test suites
+ - Major internal improvements
diff --git a/test/cxxtest/cxxtest.spec b/test/cxxtest/cxxtest.spec
new file mode 100644
index 0000000000..0f1ded6c53
--- /dev/null
+++ b/test/cxxtest/cxxtest.spec
@@ -0,0 +1,40 @@
+Name: cxxtest
+Summary: CxxTest Testing Framework for C++
+Version: 3.10.1
+Release: 1
+Copyright: LGPL
+Group: Development/C++
+Source: cxxtest-%{version}.tar.gz
+BuildRoot: /tmp/cxxtest-build
+BuildArch: noarch
+Prefix: /usr
+
+%description
+CxxTest is a JUnit/CppUnit/xUnit-like framework for C++.
+Its advantages over existing alternatives are that it:
+ - Doesn't require RTTI
+ - Doesn't require member template functions
+ - Doesn't require exception handling
+ - Doesn't require any external libraries (including memory management,
+ file/console I/O, graphics libraries)
+
+%prep
+%setup -n cxxtest
+
+%build
+
+%install
+install -m 755 -d $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/usr/include/cxxtest
+install -m 755 cxxtestgen.p[ly] $RPM_BUILD_ROOT/usr/bin/
+install -m 644 cxxtest/* $RPM_BUILD_ROOT/usr/include/cxxtest/
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%attr(-, root, root) %doc README
+%attr(-, root, root) %doc sample
+%attr(-, root, root) /usr/include/cxxtest
+%attr(-, root, root) /usr/bin/cxxtestgen.pl
+%attr(-, root, root) /usr/bin/cxxtestgen.py
+
diff --git a/test/cxxtest/cxxtest/Descriptions.cpp b/test/cxxtest/cxxtest/Descriptions.cpp
new file mode 100644
index 0000000000..143f8f8fd8
--- /dev/null
+++ b/test/cxxtest/cxxtest/Descriptions.cpp
@@ -0,0 +1,58 @@
+#ifndef __cxxtest__Descriptions_cpp__
+#define __cxxtest__Descriptions_cpp__
+
+#include
+
+namespace CxxTest
+{
+ TestDescription::~TestDescription() {}
+ SuiteDescription::~SuiteDescription() {}
+ WorldDescription::~WorldDescription() {}
+
+ //
+ // Convert total tests to string
+ //
+#ifndef _CXXTEST_FACTOR
+ char *WorldDescription::strTotalTests( char *s ) const
+ {
+ numberToString( numTotalTests(), s );
+ return s;
+ }
+#else // _CXXTEST_FACTOR
+ char *WorldDescription::strTotalTests( char *s ) const
+ {
+ char *p = numberToString( numTotalTests(), s );
+
+ if ( numTotalTests() <= 1 )
+ return s;
+
+ unsigned n = numTotalTests();
+ unsigned numFactors = 0;
+
+ for ( unsigned factor = 2; (factor * factor) <= n; factor += (factor == 2) ? 1 : 2 ) {
+ unsigned power;
+
+ for ( power = 0; (n % factor) == 0; n /= factor )
+ ++ power;
+
+ if ( !power )
+ continue;
+
+ p = numberToString( factor, copyString( p, (numFactors == 0) ? " = " : " * " ) );
+ if ( power > 1 )
+ p = numberToString( power, copyString( p, "^" ) );
+ ++ numFactors;
+ }
+
+ if ( n > 1 ) {
+ if ( !numFactors )
+ copyString( p, tracker().failedTests() ? " :(" : tracker().warnings() ? " :|" : " :)" );
+ else
+ numberToString( n, copyString( p, " * " ) );
+ }
+ return s;
+ }
+#endif // _CXXTEST_FACTOR
+};
+
+#endif // __cxxtest__Descriptions_cpp__
diff --git a/test/cxxtest/cxxtest/Descriptions.h b/test/cxxtest/cxxtest/Descriptions.h
new file mode 100644
index 0000000000..bd373ec762
--- /dev/null
+++ b/test/cxxtest/cxxtest/Descriptions.h
@@ -0,0 +1,74 @@
+#ifndef __cxxtest__Descriptions_h__
+#define __cxxtest__Descriptions_h__
+
+//
+// TestDescription, SuiteDescription and WorldDescription
+// hold information about tests so they can be run and reported.
+//
+
+#include
+
+namespace CxxTest
+{
+ class TestSuite;
+
+ class TestDescription : public Link
+ {
+ public:
+ virtual ~TestDescription();
+
+ virtual const char *file() const = 0;
+ virtual unsigned line() const = 0;
+ virtual const char *testName() const = 0;
+ virtual const char *suiteName() const = 0;
+
+ virtual void run() = 0;
+
+ virtual const TestDescription *next() const = 0;
+ virtual TestDescription *next() = 0;
+ };
+
+ class SuiteDescription : public Link
+ {
+ public:
+ virtual ~SuiteDescription();
+
+ virtual const char *file() const = 0;
+ virtual unsigned line() const = 0;
+ virtual const char *suiteName() const = 0;
+ virtual TestSuite *suite() const = 0;
+
+ virtual unsigned numTests() const = 0;
+ virtual const TestDescription &testDescription( unsigned /*i*/ ) const = 0;
+
+ virtual TestDescription *firstTest() = 0;
+ virtual const TestDescription *firstTest() const = 0;
+ virtual SuiteDescription *next() = 0;
+ virtual const SuiteDescription *next() const = 0;
+
+ virtual void activateAllTests() = 0;
+ virtual bool leaveOnly( const char * /*testName*/ ) = 0;
+ };
+
+ class WorldDescription : public Link
+ {
+ public:
+ virtual ~WorldDescription();
+
+ virtual unsigned numSuites( void ) const = 0;
+ virtual unsigned numTotalTests( void ) const = 0;
+ virtual const SuiteDescription &suiteDescription( unsigned /*i*/ ) const = 0;
+
+ enum { MAX_STRLEN_TOTAL_TESTS = 32 };
+ char *strTotalTests( char * /*buffer*/ ) const;
+
+ virtual SuiteDescription *firstSuite() = 0;
+ virtual const SuiteDescription *firstSuite() const = 0;
+
+ virtual void activateAllTests() = 0;
+ virtual bool leaveOnly( const char * /*suiteName*/, const char * /*testName*/ = 0 ) = 0;
+ };
+}
+
+#endif // __cxxtest__Descriptions_h__
+
diff --git a/test/cxxtest/cxxtest/DummyDescriptions.cpp b/test/cxxtest/cxxtest/DummyDescriptions.cpp
new file mode 100644
index 0000000000..c862e439d8
--- /dev/null
+++ b/test/cxxtest/cxxtest/DummyDescriptions.cpp
@@ -0,0 +1,49 @@
+#include
+
+namespace CxxTest
+{
+ DummyTestDescription::DummyTestDescription() {}
+
+ const char *DummyTestDescription::file() const { return ""; }
+ unsigned DummyTestDescription::line() const { return 0; }
+ const char *DummyTestDescription::testName() const { return ""; }
+ const char *DummyTestDescription::suiteName() const { return ""; }
+ bool DummyTestDescription::setUp() { return true;}
+ void DummyTestDescription::run() {}
+ bool DummyTestDescription::tearDown() { return true;}
+
+ TestDescription *DummyTestDescription::next() { return 0; }
+ const TestDescription *DummyTestDescription::next() const { return 0; }
+
+ DummySuiteDescription::DummySuiteDescription() : _test() {}
+
+ const char *DummySuiteDescription::file() const { return ""; }
+ unsigned DummySuiteDescription::line() const { return 0; }
+ const char *DummySuiteDescription::suiteName() const { return ""; }
+ TestSuite *DummySuiteDescription::suite() const { return 0; }
+ unsigned DummySuiteDescription::numTests() const { return 0; }
+ const TestDescription &DummySuiteDescription::testDescription( unsigned ) const { return _test; }
+ SuiteDescription *DummySuiteDescription::next() { return 0; }
+ TestDescription *DummySuiteDescription::firstTest() { return 0; }
+ const SuiteDescription *DummySuiteDescription::next() const { return 0; }
+ const TestDescription *DummySuiteDescription::firstTest() const { return 0; }
+ void DummySuiteDescription::activateAllTests() {}
+ bool DummySuiteDescription::leaveOnly( const char * /*testName*/ ) { return false; }
+
+ bool DummySuiteDescription::setUp() { return true;}
+ bool DummySuiteDescription::tearDown() { return true;}
+
+ DummyWorldDescription::DummyWorldDescription() : _suite() {}
+
+ unsigned DummyWorldDescription::numSuites( void ) const { return 0; }
+ unsigned DummyWorldDescription::numTotalTests( void ) const { return 0; }
+ const SuiteDescription &DummyWorldDescription::suiteDescription( unsigned ) const { return _suite; }
+ SuiteDescription *DummyWorldDescription::firstSuite() { return 0; }
+ const SuiteDescription *DummyWorldDescription::firstSuite() const { return 0; }
+ void DummyWorldDescription::activateAllTests() {}
+ bool DummyWorldDescription::leaveOnly( const char * /*suiteName*/, const char * /*testName*/ ) { return false; }
+
+ bool DummyWorldDescription::setUp() { return true;}
+ bool DummyWorldDescription::tearDown() { return true;}
+}
+
diff --git a/test/cxxtest/cxxtest/DummyDescriptions.h b/test/cxxtest/cxxtest/DummyDescriptions.h
new file mode 100644
index 0000000000..c9215d125f
--- /dev/null
+++ b/test/cxxtest/cxxtest/DummyDescriptions.h
@@ -0,0 +1,76 @@
+#ifndef __cxxtest__DummyDescriptions_h__
+#define __cxxtest__DummyDescriptions_h__
+
+//
+// DummyTestDescription, DummySuiteDescription and DummyWorldDescription
+//
+
+#include
+
+namespace CxxTest
+{
+ class DummyTestDescription : public TestDescription
+ {
+ public:
+ DummyTestDescription();
+
+ const char *file() const;
+ unsigned line() const;
+ const char *testName() const;
+ const char *suiteName() const;
+ bool setUp();
+ void run();
+ bool tearDown();
+
+ TestDescription *next();
+ const TestDescription *next() const;
+ };
+
+ class DummySuiteDescription : public SuiteDescription
+ {
+ public:
+ DummySuiteDescription();
+
+ const char *file() const;
+ unsigned line() const;
+ const char *suiteName() const;
+ TestSuite *suite() const;
+ unsigned numTests() const;
+ const TestDescription &testDescription( unsigned ) const;
+ SuiteDescription *next();
+ TestDescription *firstTest();
+ const SuiteDescription *next() const;
+ const TestDescription *firstTest() const;
+ void activateAllTests();
+ bool leaveOnly( const char * /*testName*/ );
+
+ bool setUp();
+ bool tearDown();
+
+ private:
+ DummyTestDescription _test;
+ };
+
+ class DummyWorldDescription : public WorldDescription
+ {
+ public:
+ DummyWorldDescription();
+
+ unsigned numSuites( void ) const;
+ unsigned numTotalTests( void ) const;
+ const SuiteDescription &suiteDescription( unsigned ) const;
+ SuiteDescription *firstSuite();
+ const SuiteDescription *firstSuite() const;
+ void activateAllTests();
+ bool leaveOnly( const char * /*suiteName*/, const char * /*testName*/ = 0 );
+
+ bool setUp();
+ bool tearDown();
+
+ private:
+ DummySuiteDescription _suite;
+ };
+}
+
+#endif // __cxxtest__DummyDescriptions_h__
+
diff --git a/test/cxxtest/cxxtest/ErrorFormatter.h b/test/cxxtest/cxxtest/ErrorFormatter.h
new file mode 100644
index 0000000000..968c310c2a
--- /dev/null
+++ b/test/cxxtest/cxxtest/ErrorFormatter.h
@@ -0,0 +1,281 @@
+#ifndef __cxxtest__ErrorFormatter_h__
+#define __cxxtest__ErrorFormatter_h__
+
+//
+// The ErrorFormatter is a TestListener that
+// prints reports of the errors to an output
+// stream. Since we cannot rely ou the standard
+// iostreams, this header defines a base class
+// analogout to std::ostream.
+//
+
+#include
+#include
+#include
+#include
+
+namespace CxxTest
+{
+ class OutputStream
+ {
+ public:
+ virtual ~OutputStream() {}
+ virtual void flush() {};
+ virtual OutputStream &operator<<( unsigned /*number*/ ) { return *this; }
+ virtual OutputStream &operator<<( const char * /*string*/ ) { return *this; }
+
+ typedef void (*Manipulator)( OutputStream & );
+
+ virtual OutputStream &operator<<( Manipulator m ) { m( *this ); return *this; }
+ static void endl( OutputStream &o ) { (o << "\n").flush(); }
+ };
+
+ class ErrorFormatter : public TestListener
+ {
+ public:
+ ErrorFormatter( OutputStream *o, const char *preLine = ":", const char *postLine = "" ) :
+ _dotting( true ),
+ _reported( false ),
+ _o(o),
+ _preLine(preLine),
+ _postLine(postLine)
+ {
+ }
+
+ int run()
+ {
+ TestRunner::runAllTests( *this );
+ return tracker().failedTests();
+ }
+
+ void enterWorld( const WorldDescription & /*desc*/ )
+ {
+ (*_o) << "Running " << totalTests;
+ _o->flush();
+ _dotting = true;
+ _reported = false;
+ }
+
+ static void totalTests( OutputStream &o )
+ {
+ char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
+ const WorldDescription &wd = tracker().world();
+ o << wd.strTotalTests( s ) << (wd.numTotalTests() == 1 ? " test" : " tests");
+ }
+
+ void enterSuite( const SuiteDescription & )
+ {
+ _reported = false;
+ }
+
+ void enterTest( const TestDescription & )
+ {
+ _reported = false;
+ }
+
+ void leaveTest( const TestDescription & )
+ {
+ if ( !tracker().testFailed() ) {
+ ((*_o) << ".").flush();
+ _dotting = true;
+ }
+ }
+
+ void leaveWorld( const WorldDescription &desc )
+ {
+ if ( !tracker().failedTests() ) {
+ (*_o) << "OK!" << endl;
+ return;
+ }
+ newLine();
+ (*_o) << "Failed " << tracker().failedTests() << " of " << totalTests << endl;
+ unsigned numPassed = desc.numTotalTests() - tracker().failedTests();
+ (*_o) << "Success rate: " << (numPassed * 100 / desc.numTotalTests()) << "%" << endl;
+ }
+
+ void trace( const char *file, unsigned line, const char *expression )
+ {
+ stop( file, line ) << "Trace: " <<
+ expression << endl;
+ }
+
+ void warning( const char *file, unsigned line, const char *expression )
+ {
+ stop( file, line ) << "Warning: " <<
+ expression << endl;
+ }
+
+ void failedTest( const char *file, unsigned line, const char *expression )
+ {
+ stop( file, line ) << "Error: Test failed: " <<
+ expression << endl;
+ }
+
+ void failedAssert( const char *file, unsigned line, const char *expression )
+ {
+ stop( file, line ) << "Error: Assertion failed: " <<
+ expression << endl;
+ }
+
+ void failedAssertEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ stop( file, line ) << "Error: Expected (" <<
+ xStr << " == " << yStr << "), found (" <<
+ x << " != " << y << ")" << endl;
+ }
+
+ void failedAssertSameData( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *sizeStr, const void *x,
+ const void *y, unsigned size )
+ {
+ stop( file, line ) << "Error: Expected " << sizeStr << " (" << size << ") bytes to be equal at (" <<
+ xStr << ") and (" << yStr << "), found:" << endl;
+ dump( x, size );
+ (*_o) << " differs from" << endl;
+ dump( y, size );
+ }
+
+ void failedAssertDelta( const char *file, unsigned line,
+ const char *xStr, const char *yStr, const char *dStr,
+ const char *x, const char *y, const char *d )
+ {
+ stop( file, line ) << "Error: Expected (" <<
+ xStr << " == " << yStr << ") up to " << dStr << " (" << d << "), found (" <<
+ x << " != " << y << ")" << endl;
+ }
+
+ void failedAssertDiffers( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *value )
+ {
+ stop( file, line ) << "Error: Expected (" <<
+ xStr << " != " << yStr << "), found (" <<
+ value << ")" << endl;
+ }
+
+ void failedAssertLessThan( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ stop( file, line ) << "Error: Expected (" <<
+ xStr << " < " << yStr << "), found (" <<
+ x << " >= " << y << ")" << endl;
+ }
+
+ void failedAssertLessThanEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ stop( file, line ) << "Error: Expected (" <<
+ xStr << " <= " << yStr << "), found (" <<
+ x << " > " << y << ")" << endl;
+ }
+
+ void failedAssertRelation( const char *file, unsigned line,
+ const char *relation, const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ stop( file, line ) << "Error: Expected " << relation << "( " <<
+ xStr << ", " << yStr << " ), found !" << relation << "( " << x << ", " << y << " )" << endl;
+ }
+
+ void failedAssertPredicate( const char *file, unsigned line,
+ const char *predicate, const char *xStr, const char *x )
+ {
+ stop( file, line ) << "Error: Expected " << predicate << "( " <<
+ xStr << " ), found !" << predicate << "( " << x << " )" << endl;
+ }
+
+ void failedAssertThrows( const char *file, unsigned line,
+ const char *expression, const char *type,
+ bool otherThrown )
+ {
+ stop( file, line ) << "Error: Expected (" << expression << ") to throw (" <<
+ type << ") but it " << (otherThrown ? "threw something else" : "didn't throw") <<
+ endl;
+ }
+
+ void failedAssertThrowsNot( const char *file, unsigned line, const char *expression )
+ {
+ stop( file, line ) << "Error: Expected (" << expression << ") not to throw, but it did" <<
+ endl;
+ }
+
+ protected:
+ OutputStream *outputStream() const
+ {
+ return _o;
+ }
+
+ private:
+ ErrorFormatter( const ErrorFormatter & );
+ ErrorFormatter &operator=( const ErrorFormatter & );
+
+ OutputStream &stop( const char *file, unsigned line )
+ {
+ newLine();
+ reportTest();
+ return (*_o) << file << _preLine << line << _postLine << ": ";
+ }
+
+ void newLine( void )
+ {
+ if ( _dotting ) {
+ (*_o) << endl;
+ _dotting = false;
+ }
+ }
+
+ void reportTest( void )
+ {
+ if( _reported )
+ return;
+ (*_o) << "In " << tracker().suite().suiteName() << "::" << tracker().test().testName() << ":" << endl;
+ _reported = true;
+ }
+
+ void dump( const void *buffer, unsigned size )
+ {
+ if ( !buffer )
+ dumpNull();
+ else
+ dumpBuffer( buffer, size );
+ }
+
+ void dumpNull()
+ {
+ (*_o) << " (null)" << endl;
+ }
+
+ void dumpBuffer( const void *buffer, unsigned size )
+ {
+ unsigned dumpSize = size;
+ if ( maxDumpSize() && dumpSize > maxDumpSize() )
+ dumpSize = maxDumpSize();
+
+ const unsigned char *p = (const unsigned char *)buffer;
+ (*_o) << " { ";
+ for ( unsigned i = 0; i < dumpSize; ++ i )
+ (*_o) << byteToHex( *p++ ) << " ";
+ if ( dumpSize < size )
+ (*_o) << "... ";
+ (*_o) << "}" << endl;
+ }
+
+ static void endl( OutputStream &o )
+ {
+ OutputStream::endl( o );
+ }
+
+ bool _dotting;
+ bool _reported;
+ OutputStream *_o;
+ const char *_preLine;
+ const char *_postLine;
+ };
+};
+
+#endif // __cxxtest__ErrorFormatter_h__
diff --git a/test/cxxtest/cxxtest/ErrorPrinter.h b/test/cxxtest/cxxtest/ErrorPrinter.h
new file mode 100644
index 0000000000..53d942532b
--- /dev/null
+++ b/test/cxxtest/cxxtest/ErrorPrinter.h
@@ -0,0 +1,55 @@
+#ifndef __cxxtest__ErrorPrinter_h__
+#define __cxxtest__ErrorPrinter_h__
+
+//
+// The ErrorPrinter is a simple TestListener that
+// just prints "OK" if everything goes well, otherwise
+// reports the error in the format of compiler messages.
+// The ErrorPrinter uses std::cout
+//
+
+#include
+
+#ifndef _CXXTEST_HAVE_STD
+# define _CXXTEST_HAVE_STD
+#endif // _CXXTEST_HAVE_STD
+
+#include
+#include
+
+#ifdef _CXXTEST_OLD_STD
+# include
+#else // !_CXXTEST_OLD_STD
+# include
+#endif // _CXXTEST_OLD_STD
+
+namespace CxxTest
+{
+ class ErrorPrinter : public ErrorFormatter
+ {
+ public:
+ ErrorPrinter( CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char *preLine = ":", const char *postLine = "" ) :
+ ErrorFormatter( new Adapter(o), preLine, postLine ) {}
+ virtual ~ErrorPrinter() { delete outputStream(); }
+
+ private:
+ class Adapter : public OutputStream
+ {
+ CXXTEST_STD(ostream) &_o;
+ public:
+ Adapter( CXXTEST_STD(ostream) &o ) : _o(o) {}
+ void flush() { _o.flush(); }
+ OutputStream &operator<<( const char *s ) { _o << s; return *this; }
+ OutputStream &operator<<( Manipulator m ) { return OutputStream::operator<<( m ); }
+ OutputStream &operator<<( unsigned i )
+ {
+ char s[1 + 3 * sizeof(unsigned)];
+ numberToString( i, s );
+ _o << s;
+ return *this;
+ }
+ };
+ };
+}
+
+#endif // __cxxtest__ErrorPrinter_h__
diff --git a/test/cxxtest/cxxtest/Flags.h b/test/cxxtest/cxxtest/Flags.h
new file mode 100644
index 0000000000..be2f9f2885
--- /dev/null
+++ b/test/cxxtest/cxxtest/Flags.h
@@ -0,0 +1,121 @@
+#ifndef __cxxtest__Flags_h__
+#define __cxxtest__Flags_h__
+
+//
+// These are the flags that control CxxTest
+//
+
+#if !defined(CXXTEST_FLAGS)
+# define CXXTEST_FLAGS
+#endif // !CXXTEST_FLAGS
+
+#if defined(CXXTEST_HAVE_EH) && !defined(_CXXTEST_HAVE_EH)
+# define _CXXTEST_HAVE_EH
+#endif // CXXTEST_HAVE_EH
+
+#if defined(CXXTEST_HAVE_STD) && !defined(_CXXTEST_HAVE_STD)
+# define _CXXTEST_HAVE_STD
+#endif // CXXTEST_HAVE_STD
+
+#if defined(CXXTEST_OLD_TEMPLATE_SYNTAX) && !defined(_CXXTEST_OLD_TEMPLATE_SYNTAX)
+# define _CXXTEST_OLD_TEMPLATE_SYNTAX
+#endif // CXXTEST_OLD_TEMPLATE_SYNTAX
+
+#if defined(CXXTEST_OLD_STD) && !defined(_CXXTEST_OLD_STD)
+# define _CXXTEST_OLD_STD
+#endif // CXXTEST_OLD_STD
+
+#if defined(CXXTEST_ABORT_TEST_ON_FAIL) && !defined(_CXXTEST_ABORT_TEST_ON_FAIL)
+# define _CXXTEST_ABORT_TEST_ON_FAIL
+#endif // CXXTEST_ABORT_TEST_ON_FAIL
+
+#if defined(CXXTEST_NO_COPY_CONST) && !defined(_CXXTEST_NO_COPY_CONST)
+# define _CXXTEST_NO_COPY_CONST
+#endif // CXXTEST_NO_COPY_CONST
+
+#if defined(CXXTEST_FACTOR) && !defined(_CXXTEST_FACTOR)
+# define _CXXTEST_FACTOR
+#endif // CXXTEST_FACTOR
+
+#if defined(CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION) && !defined(_CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION)
+# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+#endif // CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+
+#if defined(CXXTEST_LONGLONG)
+# if defined(_CXXTEST_LONGLONG)
+# undef _CXXTEST_LONGLONG
+# endif
+# define _CXXTEST_LONGLONG CXXTEST_LONGLONG
+#endif // CXXTEST_LONGLONG
+
+#ifndef CXXTEST_MAX_DUMP_SIZE
+# define CXXTEST_MAX_DUMP_SIZE 0
+#endif // CXXTEST_MAX_DUMP_SIZE
+
+#if defined(_CXXTEST_ABORT_TEST_ON_FAIL) && !defined(CXXTEST_DEFAULT_ABORT)
+# define CXXTEST_DEFAULT_ABORT true
+#endif // _CXXTEST_ABORT_TEST_ON_FAIL && !CXXTEST_DEFAULT_ABORT
+
+#if !defined(CXXTEST_DEFAULT_ABORT)
+# define CXXTEST_DEFAULT_ABORT false
+#endif // !CXXTEST_DEFAULT_ABORT
+
+#if defined(_CXXTEST_ABORT_TEST_ON_FAIL) && !defined(_CXXTEST_HAVE_EH)
+# warning "CXXTEST_ABORT_TEST_ON_FAIL is meaningless without CXXTEST_HAVE_EH"
+# undef _CXXTEST_ABORT_TEST_ON_FAIL
+#endif // _CXXTEST_ABORT_TEST_ON_FAIL && !_CXXTEST_HAVE_EH
+
+//
+// Some minimal per-compiler configuration to allow us to compile
+//
+
+#ifdef __BORLANDC__
+# if __BORLANDC__ <= 0x520 // Borland C++ 5.2 or earlier
+# ifndef _CXXTEST_OLD_STD
+# define _CXXTEST_OLD_STD
+# endif
+# ifndef _CXXTEST_OLD_TEMPLATE_SYNTAX
+# define _CXXTEST_OLD_TEMPLATE_SYNTAX
+# endif
+# endif
+# if __BORLANDC__ >= 0x540 // C++ Builder 4.0 or later
+# ifndef _CXXTEST_NO_COPY_CONST
+# define _CXXTEST_NO_COPY_CONST
+# endif
+# ifndef _CXXTEST_LONGLONG
+# define _CXXTEST_LONGLONG __int64
+# endif
+# endif
+#endif // __BORLANDC__
+
+#ifdef _MSC_VER // Visual C++
+# ifndef _CXXTEST_LONGLONG
+# define _CXXTEST_LONGLONG __int64
+# endif
+# if (_MSC_VER >= 0x51E)
+# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+# endif
+# endif
+# pragma warning( disable : 4127 )
+# pragma warning( disable : 4290 )
+# pragma warning( disable : 4511 )
+# pragma warning( disable : 4512 )
+# pragma warning( disable : 4514 )
+#endif // _MSC_VER
+
+#ifdef __GNUC__
+# if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 9)
+# ifndef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+# define _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+# endif
+# endif
+#endif // __GNUC__
+
+#ifdef __DMC__ // Digital Mars
+# ifndef _CXXTEST_OLD_STD
+# define _CXXTEST_OLD_STD
+# endif
+#endif
+
+#endif // __cxxtest__Flags_h__
diff --git a/test/cxxtest/cxxtest/GlobalFixture.cpp b/test/cxxtest/cxxtest/GlobalFixture.cpp
new file mode 100644
index 0000000000..29c6ab83a6
--- /dev/null
+++ b/test/cxxtest/cxxtest/GlobalFixture.cpp
@@ -0,0 +1,23 @@
+#ifndef __cxxtest__GlobalFixture_cpp__
+#define __cxxtest__GlobalFixture_cpp__
+
+#include
+
+namespace CxxTest
+{
+ bool GlobalFixture::setUpWorld() { return true; }
+ bool GlobalFixture::tearDownWorld() { return true; }
+ bool GlobalFixture::setUp() { return true; }
+ bool GlobalFixture::tearDown() { return true; }
+
+ GlobalFixture::GlobalFixture() { attach( _list ); }
+ GlobalFixture::~GlobalFixture() { detach( _list ); }
+
+ GlobalFixture *GlobalFixture::firstGlobalFixture() { return (GlobalFixture *)_list.head(); }
+ GlobalFixture *GlobalFixture::lastGlobalFixture() { return (GlobalFixture *)_list.tail(); }
+ GlobalFixture *GlobalFixture::nextGlobalFixture() { return (GlobalFixture *)next(); }
+ GlobalFixture *GlobalFixture::prevGlobalFixture() { return (GlobalFixture *)prev(); }
+}
+
+#endif // __cxxtest__GlobalFixture_cpp__
+
diff --git a/test/cxxtest/cxxtest/GlobalFixture.h b/test/cxxtest/cxxtest/GlobalFixture.h
new file mode 100644
index 0000000000..c8173633f6
--- /dev/null
+++ b/test/cxxtest/cxxtest/GlobalFixture.h
@@ -0,0 +1,30 @@
+#ifndef __cxxtest__GlobalFixture_h__
+#define __cxxtest__GlobalFixture_h__
+
+#include
+
+namespace CxxTest
+{
+ class GlobalFixture : public Link
+ {
+ public:
+ virtual bool setUpWorld();
+ virtual bool tearDownWorld();
+ virtual bool setUp();
+ virtual bool tearDown();
+
+ GlobalFixture();
+ ~GlobalFixture();
+
+ static GlobalFixture *firstGlobalFixture();
+ static GlobalFixture *lastGlobalFixture();
+ GlobalFixture *nextGlobalFixture();
+ GlobalFixture *prevGlobalFixture();
+
+ private:
+ static List _list;
+ };
+}
+
+#endif // __cxxtest__GlobalFixture_h__
+
diff --git a/test/cxxtest/cxxtest/Gui.h b/test/cxxtest/cxxtest/Gui.h
new file mode 100644
index 0000000000..ac53b298f5
--- /dev/null
+++ b/test/cxxtest/cxxtest/Gui.h
@@ -0,0 +1,178 @@
+#ifndef __CXXTEST__GUI_H
+#define __CXXTEST__GUI_H
+
+//
+// GuiListener is a simple base class for the differes GUIs
+// GuiTuiRunner combines a GUI with a text-mode error formatter
+//
+
+#include
+
+namespace CxxTest
+{
+ class GuiListener : public TestListener
+ {
+ public:
+ GuiListener() : _state( GREEN_BAR ) {}
+ virtual ~GuiListener() {}
+
+ virtual void runGui( int &argc, char **argv, TestListener &listener )
+ {
+ enterGui( argc, argv );
+ TestRunner::runAllTests( listener );
+ leaveGui();
+ }
+
+ virtual void enterGui( int & /*argc*/, char ** /*argv*/ ) {}
+ virtual void leaveGui() {}
+
+ //
+ // The easy way is to implement these functions:
+ //
+ virtual void guiEnterWorld( unsigned /*numTotalTests*/ ) {}
+ virtual void guiEnterSuite( const char * /*suiteName*/ ) {}
+ virtual void guiEnterTest( const char * /*suiteName*/, const char * /*testName*/ ) {}
+ virtual void yellowBar() {}
+ virtual void redBar() {}
+
+ //
+ // The hard way is this:
+ //
+ void enterWorld( const WorldDescription &d ) { guiEnterWorld( d.numTotalTests() ); }
+ void enterSuite( const SuiteDescription &d ) { guiEnterSuite( d.suiteName() ); }
+ void enterTest( const TestDescription &d ) { guiEnterTest( d.suiteName(), d.testName() ); }
+ void leaveTest( const TestDescription & ) {}
+ void leaveSuite( const SuiteDescription & ) {}
+ void leaveWorld( const WorldDescription & ) {}
+
+ void warning( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ )
+ {
+ yellowBarSafe();
+ }
+
+ void failedTest( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssert( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertEquals( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertSameData( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*sizeStr*/, const void * /*x*/,
+ const void * /*y*/, unsigned /*size*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertDelta( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/, const char * /*dStr*/,
+ const char * /*x*/, const char * /*y*/, const char * /*d*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertDiffers( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*value*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertLessThan( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertLessThanEquals( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertPredicate( const char * /*file*/, unsigned /*line*/,
+ const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertRelation( const char * /*file*/, unsigned /*line*/,
+ const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertThrows( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/, const char * /*type*/,
+ bool /*otherThrown*/ )
+ {
+ redBarSafe();
+ }
+
+ void failedAssertThrowsNot( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/ )
+ {
+ redBarSafe();
+ }
+
+ protected:
+ void yellowBarSafe()
+ {
+ if ( _state < YELLOW_BAR ) {
+ yellowBar();
+ _state = YELLOW_BAR;
+ }
+ }
+
+ void redBarSafe()
+ {
+ if ( _state < RED_BAR ) {
+ redBar();
+ _state = RED_BAR;
+ }
+ }
+
+ private:
+ enum { GREEN_BAR, YELLOW_BAR, RED_BAR } _state;
+ };
+
+ template
+ class GuiTuiRunner : public TeeListener
+ {
+ int &_argc;
+ char **_argv;
+ GuiT _gui;
+ TuiT _tui;
+
+ public:
+ GuiTuiRunner( int &argc, char **argv ) :
+ _argc( argc ),
+ _argv( argv )
+ {
+ setFirst( _gui );
+ setSecond( _tui );
+ }
+
+ int run()
+ {
+ _gui.runGui( _argc, _argv, *this );
+ return tracker().failedTests();
+ }
+ };
+};
+
+#endif //__CXXTEST__GUI_H
diff --git a/test/cxxtest/cxxtest/LinkedList.cpp b/test/cxxtest/cxxtest/LinkedList.cpp
new file mode 100644
index 0000000000..fb81d64cae
--- /dev/null
+++ b/test/cxxtest/cxxtest/LinkedList.cpp
@@ -0,0 +1,172 @@
+#ifndef __cxxtest__LinkedList_cpp__
+#define __cxxtest__LinkedList_cpp__
+
+#include
+
+namespace CxxTest
+{
+ List GlobalFixture::_list = { 0, 0 };
+ List RealSuiteDescription::_suites = { 0, 0 };
+
+ void List::initialize()
+ {
+ _head = _tail = 0;
+ }
+
+ Link *List::head()
+ {
+ Link *l = _head;
+ while ( l && !l->active() )
+ l = l->next();
+ return l;
+ }
+
+ const Link *List::head() const
+ {
+ Link *l = _head;
+ while ( l && !l->active() )
+ l = l->next();
+ return l;
+ }
+
+ Link *List::tail()
+ {
+ Link *l = _tail;
+ while ( l && !l->active() )
+ l = l->prev();
+ return l;
+ }
+
+ const Link *List::tail() const
+ {
+ Link *l = _tail;
+ while ( l && !l->active() )
+ l = l->prev();
+ return l;
+ }
+
+ bool List::empty() const
+ {
+ return (_head == 0);
+ }
+
+ unsigned List::size() const
+ {
+ unsigned count = 0;
+ for ( const Link *l = head(); l != 0; l = l->next() )
+ ++ count;
+ return count;
+ }
+
+ Link *List::nth( unsigned n )
+ {
+ Link *l = head();
+ while ( n -- )
+ l = l->next();
+ return l;
+ }
+
+ void List::activateAll()
+ {
+ for ( Link *l = _head; l != 0; l = l->justNext() )
+ l->setActive( true );
+ }
+
+ void List::leaveOnly( const Link &link )
+ {
+ for ( Link *l = head(); l != 0; l = l->next() )
+ if ( l != &link )
+ l->setActive( false );
+ }
+
+ Link::Link() :
+ _next( 0 ),
+ _prev( 0 ),
+ _active( true )
+ {
+ }
+
+ Link::~Link()
+ {
+ }
+
+ bool Link::active() const
+ {
+ return _active;
+ }
+
+ void Link::setActive( bool value )
+ {
+ _active = value;
+ }
+
+ Link * Link::justNext()
+ {
+ return _next;
+ }
+
+ Link * Link::justPrev()
+ {
+ return _prev;
+ }
+
+ Link * Link::next()
+ {
+ Link *l = _next;
+ while ( l && !l->_active )
+ l = l->_next;
+ return l;
+ }
+
+ Link * Link::prev()
+ {
+ Link *l = _prev;
+ while ( l && !l->_active )
+ l = l->_prev;
+ return l;
+ }
+
+ const Link * Link::next() const
+ {
+ Link *l = _next;
+ while ( l && !l->_active )
+ l = l->_next;
+ return l;
+ }
+
+ const Link * Link::prev() const
+ {
+ Link *l = _prev;
+ while ( l && !l->_active )
+ l = l->_prev;
+ return l;
+ }
+
+ void Link::attach( List &l )
+ {
+ if ( l._tail )
+ l._tail->_next = this;
+
+ _prev = l._tail;
+ _next = 0;
+
+ if ( l._head == 0 )
+ l._head = this;
+ l._tail = this;
+ }
+
+ void Link::detach( List &l )
+ {
+ if ( _prev )
+ _prev->_next = _next;
+ else
+ l._head = _next;
+
+ if ( _next )
+ _next->_prev = _prev;
+ else
+ l._tail = _prev;
+ }
+};
+
+#endif // __cxxtest__LinkedList_cpp__
diff --git a/test/cxxtest/cxxtest/LinkedList.h b/test/cxxtest/cxxtest/LinkedList.h
new file mode 100644
index 0000000000..983a6e244c
--- /dev/null
+++ b/test/cxxtest/cxxtest/LinkedList.h
@@ -0,0 +1,65 @@
+#ifndef __cxxtest__LinkedList_h__
+#define __cxxtest__LinkedList_h__
+
+#include
+
+namespace CxxTest
+{
+ struct List;
+ class Link;
+
+ struct List
+ {
+ Link *_head;
+ Link *_tail;
+
+ void initialize();
+
+ Link *head();
+ const Link *head() const;
+ Link *tail();
+ const Link *tail() const;
+
+ bool empty() const;
+ unsigned size() const;
+ Link *nth( unsigned n );
+
+ void activateAll();
+ void leaveOnly( const Link &link );
+ };
+
+ class Link
+ {
+ public:
+ Link();
+ virtual ~Link();
+
+ bool active() const;
+ void setActive( bool value = true );
+
+ Link *justNext();
+ Link *justPrev();
+
+ Link *next();
+ Link *prev();
+ const Link *next() const;
+ const Link *prev() const;
+
+ virtual bool setUp() = 0;
+ virtual bool tearDown() = 0;
+
+ void attach( List &l );
+ void detach( List &l );
+
+ private:
+ Link *_next;
+ Link *_prev;
+ bool _active;
+
+ Link( const Link & );
+ Link &operator=( const Link & );
+ };
+}
+
+#endif // __cxxtest__LinkedList_h__
+
diff --git a/test/cxxtest/cxxtest/Mock.h b/test/cxxtest/cxxtest/Mock.h
new file mode 100644
index 0000000000..647088e807
--- /dev/null
+++ b/test/cxxtest/cxxtest/Mock.h
@@ -0,0 +1,350 @@
+#ifndef __cxxtest__Mock_h__
+#define __cxxtest__Mock_h__
+
+//
+// The default namespace is T::
+//
+#ifndef CXXTEST_MOCK_NAMESPACE
+# define CXXTEST_MOCK_NAMESPACE T
+#endif // CXXTEST_MOCK_NAMESPACE
+
+//
+// MockTraits: What to return when no mock object has been created
+//
+#define __CXXTEST_MOCK__TRAITS \
+ namespace CXXTEST_MOCK_NAMESPACE \
+ { \
+ template \
+ class MockTraits \
+ { \
+ public: \
+ static T defaultValue() { return 0; } \
+ }; \
+ };
+
+//
+// extern "C" when needed
+//
+#ifdef __cplusplus
+# define CXXTEST_EXTERN_C extern "C"
+#else
+# define CXXTEST_EXTERN_C
+#endif // __cplusplus
+
+//
+// Prototypes: For "normal" headers
+//
+#define __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ namespace CXXTEST_MOCK_NAMESPACE { TYPE NAME ARGS; }
+
+#define __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__PROTOTYPE( MOCK, void, NAME, ARGS, REAL, CALL )
+
+#define __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ TYPE REAL ARGS;
+
+#define __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__PROTOTYPE( MOCK, void, NAME, ARGS, REAL, CALL )
+
+//
+// Class declarations: For test files
+//
+#define __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ namespace CXXTEST_MOCK_NAMESPACE { \
+ class Base_##MOCK : public CxxTest::Link \
+ { \
+ public: \
+ Base_##MOCK(); \
+ ~Base_##MOCK(); \
+ bool setUp(); \
+ bool tearDown(); \
+ \
+ static Base_##MOCK ¤t(); \
+ \
+ virtual TYPE NAME ARGS = 0; \
+ \
+ private: \
+ static CxxTest::List _list; \
+ }; \
+ \
+ class Real_##MOCK : public Base_##MOCK \
+ { \
+ public: \
+ TYPE NAME ARGS; \
+ }; \
+ \
+ class _Unimplemented_##MOCK : public Base_##MOCK \
+ { \
+ public: \
+ TYPE NAME ARGS; \
+ }; \
+ }
+
+#define __CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, void, NAME, ARGS, REAL, CALL )
+
+#define __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ namespace CXXTEST_MOCK_NAMESPACE { \
+ class Base_##MOCK : public CxxTest::Link \
+ { \
+ public: \
+ Base_##MOCK(); \
+ ~Base_##MOCK(); \
+ bool setUp(); \
+ bool tearDown(); \
+ \
+ static Base_##MOCK ¤t(); \
+ \
+ virtual TYPE NAME ARGS = 0; \
+ \
+ private: \
+ static CxxTest::List _list; \
+ }; \
+ \
+ class _Unimplemented_##MOCK : public Base_##MOCK \
+ { \
+ public: \
+ TYPE NAME ARGS; \
+ }; \
+ }
+
+#define __CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, void, NAME, ARGS, REAL, CALL )
+
+//
+// Class implementation: For test source files
+//
+#define __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
+ namespace CXXTEST_MOCK_NAMESPACE { \
+ \
+ CxxTest::List Base_##MOCK::_list = { 0, 0 }; \
+ \
+ Base_##MOCK::Base_##MOCK() { attach( _list ); } \
+ Base_##MOCK::~Base_##MOCK() { detach( _list ); } \
+ bool Base_##MOCK::setUp() { return true; } \
+ bool Base_##MOCK::tearDown() { return true; } \
+ \
+ Base_##MOCK &Base_##MOCK::current() \
+ { \
+ if ( _list.empty() ) \
+ static _Unimplemented_##MOCK unimplemented; \
+ return *(Base_##MOCK *)_list.tail(); \
+ } \
+ }
+
+#define __CXXTEST_MOCK__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
+ namespace CXXTEST_MOCK_NAMESPACE { \
+ TYPE Real_##MOCK::NAME ARGS \
+ { \
+ return REAL CALL; \
+ } \
+ \
+ TYPE _Unimplemented_##MOCK::NAME ARGS \
+ { \
+ while ( false ) \
+ return NAME CALL; \
+ __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
+ return MockTraits::defaultValue(); \
+ } \
+ \
+ TYPE NAME ARGS \
+ { \
+ return Base_##MOCK::current().NAME CALL; \
+ } \
+ }
+
+#define __CXXTEST_MOCK_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
+ namespace CXXTEST_MOCK_NAMESPACE { \
+ void Real_##MOCK::NAME ARGS \
+ { \
+ REAL CALL; \
+ } \
+ \
+ void _Unimplemented_##MOCK::NAME ARGS \
+ { \
+ while ( false ) \
+ NAME CALL; \
+ __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
+ } \
+ \
+ void NAME ARGS \
+ { \
+ Base_##MOCK::current().NAME CALL; \
+ } \
+ }
+
+#define __CXXTEST_SUPPLY__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
+ namespace CXXTEST_MOCK_NAMESPACE { \
+ TYPE _Unimplemented_##MOCK::NAME ARGS \
+ { \
+ while ( false ) \
+ return NAME CALL; \
+ __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
+ return MockTraits::defaultValue(); \
+ } \
+ } \
+ \
+ TYPE REAL ARGS \
+ { \
+ return CXXTEST_MOCK_NAMESPACE::Base_##MOCK::current().NAME CALL; \
+ }
+
+#define __CXXTEST_SUPPLY_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__COMMON_CLASS_IMPLEMENTATION( MOCK, NAME ) \
+ namespace CXXTEST_MOCK_NAMESPACE { \
+ void _Unimplemented_##MOCK::NAME ARGS \
+ { \
+ while ( false ) \
+ NAME CALL; \
+ __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
+ } \
+ } \
+ \
+ void REAL ARGS \
+ { \
+ CXXTEST_MOCK_NAMESPACE::Base_##MOCK::current().NAME CALL; \
+ } \
+
+//
+// Error for calling mock function w/o object
+//
+#define __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ) \
+ TS_FAIL( CXXTEST_MOCK_NAMESPACE_STR #NAME #ARGS " called with no " \
+ CXXTEST_MOCK_NAMESPACE_STR "Base_" #NAME " object" ); \
+
+#define CXXTEST_MOCK_NAMESPACE_STR __CXXTEST_STR(CXXTEST_MOCK_NAMESPACE) "::"
+#define __CXXTEST_STR(X) __CXXTEST_XSTR(X)
+#define __CXXTEST_XSTR(X) #X
+
+#if defined(CXXTEST_MOCK_TEST_SOURCE_FILE)
+//
+// Test source file: Prototypes, class declarations and implementation
+//
+#include
+
+__CXXTEST_MOCK__TRAITS;
+
+#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__CLASS_IMPLEMENTATION( MOCK, TYPE, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY_VOID__CLASS_IMPLEMENTATION( MOCK, NAME, ARGS, REAL, CALL )
+
+#elif defined(CXXTEST_FLAGS) || defined(CXXTEST_RUNNING)
+//
+// Test file other than source: Prototypes and class declarations
+//
+#include
+
+__CXXTEST_MOCK__TRAITS;
+
+#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__CLASS_DECLARATION( MOCK, TYPE, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY_VOID__CLASS_DECLARATION( MOCK, NAME, ARGS, REAL, CALL )
+
+#elif defined(CXXTEST_MOCK_REAL_SOURCE_FILE)
+//
+// Real source file: "Real" implementations
+//
+#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ namespace CXXTEST_MOCK_NAMESPACE { TYPE NAME ARGS { return REAL CALL; } }
+
+#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
+ namespace CXXTEST_MOCK_NAMESPACE { void NAME ARGS { REAL CALL; } }
+
+#else
+//
+// Ordinary header file: Just prototypes
+//
+
+#define CXXTEST_MOCK( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_MOCK_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_MOCK_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL ) \
+ __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL )
+
+#endif // Ordinary header file
+
+//
+// How to supply extern "C" functions
+//
+#define CXXTEST_SUPPLY_C( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ CXXTEST_EXTERN_C __CXXTEST_SUPPLY__PROTOTYPE( MOCK, TYPE, NAME, ARGS, REAL, CALL ) \
+ CXXTEST_SUPPLY( MOCK, TYPE, NAME, ARGS, REAL, CALL )
+
+#define CXXTEST_SUPPLY_VOID_C( MOCK, NAME, ARGS, REAL, CALL ) \
+ CXXTEST_EXTERN_C __CXXTEST_SUPPLY_VOID__PROTOTYPE( MOCK, NAME, ARGS, REAL, CALL ) \
+ CXXTEST_SUPPLY_VOID( MOCK, NAME, ARGS, REAL, CALL )
+
+//
+// Usually we mean the global namespace
+//
+#define CXXTEST_MOCK_GLOBAL( TYPE, NAME, ARGS, CALL ) \
+ CXXTEST_MOCK( NAME, TYPE, NAME, ARGS, ::NAME, CALL )
+
+#define CXXTEST_MOCK_VOID_GLOBAL( NAME, ARGS, CALL ) \
+ CXXTEST_MOCK_VOID( NAME, NAME, ARGS, ::NAME, CALL )
+
+#define CXXTEST_SUPPLY_GLOBAL( TYPE, NAME, ARGS, CALL ) \
+ CXXTEST_SUPPLY( NAME, TYPE, NAME, ARGS, NAME, CALL )
+
+#define CXXTEST_SUPPLY_VOID_GLOBAL( NAME, ARGS, CALL ) \
+ CXXTEST_SUPPLY_VOID( NAME, NAME, ARGS, NAME, CALL )
+
+#define CXXTEST_SUPPLY_GLOBAL_C( TYPE, NAME, ARGS, CALL ) \
+ CXXTEST_SUPPLY_C( NAME, TYPE, NAME, ARGS, NAME, CALL )
+
+#define CXXTEST_SUPPLY_VOID_GLOBAL_C( NAME, ARGS, CALL ) \
+ CXXTEST_SUPPLY_VOID_C( NAME, NAME, ARGS, NAME, CALL )
+
+//
+// What to return when no mock object has been created.
+// The default value of 0 usually works, but some cases may need this.
+//
+#define CXXTEST_MOCK_DEFAULT_VALUE( TYPE, VALUE ) \
+ namespace CXXTEST_MOCK_NAMESPACE \
+ { \
+ template<> \
+ class MockTraits \
+ { \
+ public: \
+ static TYPE defaultValue() { return VALUE; } \
+ }; \
+ }
+
+#endif // __cxxtest__Mock_h__
diff --git a/test/cxxtest/cxxtest/ParenPrinter.h b/test/cxxtest/cxxtest/ParenPrinter.h
new file mode 100644
index 0000000000..9ecf310532
--- /dev/null
+++ b/test/cxxtest/cxxtest/ParenPrinter.h
@@ -0,0 +1,21 @@
+#ifndef __cxxtest__ParenPrinter_h__
+#define __cxxtest__ParenPrinter_h__
+
+//
+// The ParenPrinter is identical to the ErrorPrinter, except it
+// prints the line number in a format expected by some compilers
+// (notably, MSVC).
+//
+
+#include
+
+namespace CxxTest
+{
+ class ParenPrinter : public ErrorPrinter
+ {
+ public:
+ ParenPrinter( CXXTEST_STD(ostream) &o = CXXTEST_STD(cout) ) : ErrorPrinter( o, "(", ")" ) {}
+ };
+}
+
+#endif // __cxxtest__ParenPrinter_h__
diff --git a/test/cxxtest/cxxtest/QtGui.h b/test/cxxtest/cxxtest/QtGui.h
new file mode 100644
index 0000000000..889825106a
--- /dev/null
+++ b/test/cxxtest/cxxtest/QtGui.h
@@ -0,0 +1,271 @@
+#ifndef __cxxtest__QtGui_h__
+#define __cxxtest__QtGui_h__
+
+//
+// The QtGui displays a simple progress bar using the Qt Toolkit. It
+// has been tested with versions 2.x and 3.x.
+//
+// Apart from normal Qt command-line arguments, it accepts the following options:
+// -minimized Start minimized, pop up on error
+// -keep Don't close the window at the end
+// -title TITLE Set the window caption
+//
+// If both are -minimized and -keep specified, GUI will only keep the
+// window if it's in focus.
+//
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace CxxTest
+{
+ class QtGui : public GuiListener
+ {
+ public:
+ void enterGui( int &argc, char **argv )
+ {
+ parseCommandLine( argc, argv );
+ createApplication( argc, argv );
+ }
+
+ void enterWorld( const WorldDescription &wd )
+ {
+ createWindow( wd );
+ processEvents();
+ }
+
+ void guiEnterSuite( const char *suiteName )
+ {
+ showSuiteName( suiteName );
+ }
+
+ void guiEnterTest( const char *suiteName, const char *testName )
+ {
+ setCaption( suiteName, testName );
+ advanceProgressBar();
+ showTestName( testName );
+ showTestsDone( _progressBar->progress() );
+ processEvents();
+ }
+
+ void yellowBar()
+ {
+ setColor( 255, 255, 0 );
+ setIcon( QMessageBox::Warning );
+ getTotalTests();
+ processEvents();
+ }
+
+ void redBar()
+ {
+ if ( _startMinimized && _mainWindow->isMinimized() )
+ showNormal();
+ setColor( 255, 0, 0 );
+ setIcon( QMessageBox::Critical );
+ getTotalTests();
+ processEvents();
+ }
+
+ void leaveGui()
+ {
+ if ( keep() ) {
+ showSummary();
+ _application->exec();
+ }
+ else
+ _mainWindow->close( true );
+ }
+
+ private:
+ QString _title;
+ bool _startMinimized, _keep;
+ unsigned _numTotalTests;
+ QString _strTotalTests;
+ QApplication *_application;
+ QWidget *_mainWindow;
+ QVBoxLayout *_layout;
+ QProgressBar *_progressBar;
+ QStatusBar *_statusBar;
+ QLabel *_suiteName, *_testName, *_testsDone;
+
+ void parseCommandLine( int argc, char **argv )
+ {
+ _startMinimized = _keep = false;
+ _title = argv[0];
+
+ for ( int i = 1; i < argc; ++ i ) {
+ QString arg( argv[i] );
+ if ( arg == "-minimized" )
+ _startMinimized = true;
+ else if ( arg == "-keep" )
+ _keep = true;
+ else if ( arg == "-title" && (i + 1 < argc) )
+ _title = argv[++i];
+ }
+ }
+
+ void createApplication( int &argc, char **argv )
+ {
+ _application = new QApplication( argc, argv );
+ }
+
+ void createWindow( const WorldDescription &wd )
+ {
+ getTotalTests( wd );
+ createMainWindow();
+ createProgressBar();
+ createStatusBar();
+ setMainWidget();
+ if ( _startMinimized )
+ showMinimized();
+ else
+ showNormal();
+ }
+
+ void getTotalTests()
+ {
+ getTotalTests( tracker().world() );
+ }
+
+ void getTotalTests( const WorldDescription &wd )
+ {
+ _numTotalTests = wd.numTotalTests();
+ char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
+ _strTotalTests = wd.strTotalTests( s );
+ }
+
+ void createMainWindow()
+ {
+ _mainWindow = new QWidget();
+ _layout = new QVBoxLayout( _mainWindow );
+ }
+
+ void createProgressBar()
+ {
+ _layout->addWidget( _progressBar = new QProgressBar( _numTotalTests, _mainWindow ) );
+ _progressBar->setProgress( 0 );
+ setColor( 0, 255, 0 );
+ setIcon( QMessageBox::Information );
+ }
+
+ void createStatusBar()
+ {
+ _layout->addWidget( _statusBar = new QStatusBar( _mainWindow ) );
+ _statusBar->addWidget( _suiteName = new QLabel( _statusBar ), 2 );
+ _statusBar->addWidget( _testName = new QLabel( _statusBar ), 4 );
+ _statusBar->addWidget( _testsDone = new QLabel( _statusBar ), 1 );
+ }
+
+ void setMainWidget()
+ {
+ _application->setMainWidget( _mainWindow );
+ }
+
+ void showMinimized()
+ {
+ _mainWindow->showMinimized();
+ }
+
+ void showNormal()
+ {
+ _mainWindow->showNormal();
+ centerWindow();
+ }
+
+ void setCaption( const QString &suiteName, const QString &testName )
+ {
+ _mainWindow->setCaption( _title + " - " + suiteName + "::" + testName + "()" );
+ }
+
+ void showSuiteName( const QString &suiteName )
+ {
+ _suiteName->setText( "class " + suiteName );
+ }
+
+ void advanceProgressBar()
+ {
+ _progressBar->setProgress( _progressBar->progress() + 1 );
+ }
+
+ void showTestName( const QString &testName )
+ {
+ _testName->setText( testName + "()" );
+ }
+
+ void showTestsDone( unsigned testsDone )
+ {
+ _testsDone->setText( asString( testsDone ) + " of " + _strTotalTests );
+ }
+
+ static QString asString( unsigned n )
+ {
+ return QString::number( n );
+ }
+
+ void setColor( int r, int g, int b )
+ {
+ QPalette palette = _progressBar->palette();
+ palette.setColor( QColorGroup::Highlight, QColor( r, g, b ) );
+ _progressBar->setPalette( palette );
+ }
+
+ void setIcon( QMessageBox::Icon icon )
+ {
+#if QT_VERSION >= 0x030000
+ _mainWindow->setIcon( QMessageBox::standardIcon( icon ) );
+#else // Qt version < 3.0.0
+ _mainWindow->setIcon( QMessageBox::standardIcon( icon, QApplication::style().guiStyle() ) );
+#endif // QT_VERSION
+ }
+
+ void processEvents()
+ {
+ _application->processEvents();
+ }
+
+ void centerWindow()
+ {
+ QWidget *desktop = QApplication::desktop();
+ int xCenter = desktop->x() + (desktop->width() / 2);
+ int yCenter = desktop->y() + (desktop->height() / 2);
+
+ int windowWidth = (desktop->width() * 4) / 5;
+ int windowHeight = _mainWindow->height();
+ _mainWindow->setGeometry( xCenter - (windowWidth / 2), yCenter - (windowHeight / 2), windowWidth, windowHeight );
+ }
+
+ bool keep()
+ {
+ if ( !_keep )
+ return false;
+ if ( !_startMinimized )
+ return true;
+ return (_mainWindow == _application->activeWindow());
+ }
+
+ void showSummary()
+ {
+ QString summary = _strTotalTests + (_numTotalTests == 1 ? " test" : " tests");
+ if ( tracker().failedTests() )
+ summary = "Failed " + asString( tracker().failedTests() ) + " of " + summary;
+ else
+ summary = summary + " passed";
+
+ _mainWindow->setCaption( _title + " - " + summary );
+
+ _statusBar->removeWidget( _suiteName );
+ _statusBar->removeWidget( _testName );
+ _testsDone->setText( summary );
+ }
+ };
+};
+
+#endif // __cxxtest__QtGui_h__
diff --git a/test/cxxtest/cxxtest/RealDescriptions.cpp b/test/cxxtest/cxxtest/RealDescriptions.cpp
new file mode 100644
index 0000000000..1e21ca7625
--- /dev/null
+++ b/test/cxxtest/cxxtest/RealDescriptions.cpp
@@ -0,0 +1,311 @@
+#ifndef __cxxtest__RealDescriptions_cpp__
+#define __cxxtest__RealDescriptions_cpp__
+
+//
+// NOTE: If an error occur during world construction/deletion, CxxTest cannot
+// know where the error originated.
+//
+
+#include
+
+namespace CxxTest
+{
+ RealTestDescription::RealTestDescription()
+ {
+ }
+
+ RealTestDescription::RealTestDescription( List &argList,
+ SuiteDescription &argSuite,
+ unsigned argLine,
+ const char *argTestName )
+ {
+ initialize( argList, argSuite, argLine, argTestName );
+ }
+
+ void RealTestDescription::initialize( List &argList,
+ SuiteDescription &argSuite,
+ unsigned argLine,
+ const char *argTestName )
+ {
+ _suite = &argSuite;
+ _line = argLine;
+ _testName = argTestName;
+ attach( argList );
+ }
+
+ bool RealTestDescription::setUp()
+ {
+ if ( !suite() )
+ return false;
+
+ for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) {
+ bool ok;
+ _TS_TRY { ok = gf->setUp(); }
+ _TS_LAST_CATCH( { ok = false; } );
+
+ if ( !ok ) {
+ doFailTest( file(), line(), "Error in GlobalFixture::setUp()" );
+ return false;
+ }
+ }
+
+ _TS_TRY {
+ _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from setUp()", suite()->setUp() );
+ }
+ _TS_CATCH_ABORT( { return false; } );
+
+ return true;
+ }
+
+ bool RealTestDescription::tearDown()
+ {
+ if ( !suite() )
+ return false;
+
+ _TS_TRY {
+ _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from tearDown()", suite()->tearDown() );
+ }
+ _TS_CATCH_ABORT( { return false; } );
+
+ for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) {
+ bool ok;
+ _TS_TRY { ok = gf->tearDown(); }
+ _TS_LAST_CATCH( { ok = false; } );
+
+ if ( !ok ) {
+ doFailTest( file(), line(), "Error in GlobalFixture::tearDown()" );
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ const char *RealTestDescription::file() const { return _suite->file(); }
+ unsigned RealTestDescription::line() const { return _line; }
+ const char *RealTestDescription::testName() const { return _testName; }
+ const char *RealTestDescription::suiteName() const { return _suite->suiteName(); }
+
+ TestDescription *RealTestDescription::next() { return (RealTestDescription *)Link::next(); }
+ const TestDescription *RealTestDescription::next() const { return (const RealTestDescription *)Link::next(); }
+
+ TestSuite *RealTestDescription::suite() const { return _suite->suite(); }
+
+ void RealTestDescription::run()
+ {
+ _TS_TRY { runTest(); }
+ _TS_CATCH_ABORT( {} )
+ ___TSM_CATCH( file(), line(), "Exception thrown from test" );
+ }
+
+ RealSuiteDescription::RealSuiteDescription() {}
+ RealSuiteDescription::RealSuiteDescription( const char *argFile,
+ unsigned argLine,
+ const char *argSuiteName,
+ List &argTests )
+ {
+ initialize( argFile, argLine, argSuiteName, argTests );
+ }
+
+ void RealSuiteDescription::initialize( const char *argFile,
+ unsigned argLine,
+ const char *argSuiteName,
+ List &argTests )
+ {
+ _file = argFile;
+ _line = argLine;
+ _suiteName = argSuiteName;
+ _tests = &argTests;
+
+ attach( _suites );
+ }
+
+ const char *RealSuiteDescription::file() const { return _file; }
+ unsigned RealSuiteDescription::line() const { return _line; }
+ const char *RealSuiteDescription::suiteName() const { return _suiteName; }
+
+ TestDescription *RealSuiteDescription::firstTest() { return (RealTestDescription *)_tests->head(); }
+ const TestDescription *RealSuiteDescription::firstTest() const { return (const RealTestDescription *)_tests->head(); }
+ SuiteDescription *RealSuiteDescription::next() { return (RealSuiteDescription *)Link::next(); }
+ const SuiteDescription *RealSuiteDescription::next() const { return (const RealSuiteDescription *)Link::next(); }
+
+ unsigned RealSuiteDescription::numTests() const { return _tests->size(); }
+
+ const TestDescription &RealSuiteDescription::testDescription( unsigned i ) const
+ {
+ return *(RealTestDescription *)_tests->nth( i );
+ }
+
+ void RealSuiteDescription::activateAllTests()
+ {
+ _tests->activateAll();
+ }
+
+ bool RealSuiteDescription::leaveOnly( const char *testName )
+ {
+ for ( TestDescription *td = firstTest(); td != 0; td = td->next() ) {
+ if ( stringsEqual( td->testName(), testName ) ) {
+ _tests->leaveOnly( *td );
+ return true;
+ }
+ }
+ return false;
+ }
+
+ StaticSuiteDescription::StaticSuiteDescription() {}
+ StaticSuiteDescription::StaticSuiteDescription( const char *argFile, unsigned argLine,
+ const char *argSuiteName, TestSuite &argSuite,
+ List &argTests ) :
+ RealSuiteDescription( argFile, argLine, argSuiteName, argTests )
+ {
+ doInitialize( argSuite );
+ }
+
+ void StaticSuiteDescription::initialize( const char *argFile, unsigned argLine,
+ const char *argSuiteName, TestSuite &argSuite,
+ List &argTests )
+ {
+ RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests );
+ doInitialize( argSuite );
+ }
+
+ void StaticSuiteDescription::doInitialize( TestSuite &argSuite )
+ {
+ _suite = &argSuite;
+ }
+
+ TestSuite *StaticSuiteDescription::suite() const
+ {
+ return _suite;
+ }
+
+ bool StaticSuiteDescription::setUp() { return true; }
+ bool StaticSuiteDescription::tearDown() { return true; }
+
+ CommonDynamicSuiteDescription::CommonDynamicSuiteDescription() {}
+ CommonDynamicSuiteDescription::CommonDynamicSuiteDescription( const char *argFile, unsigned argLine,
+ const char *argSuiteName, List &argTests,
+ unsigned argCreateLine, unsigned argDestroyLine ) :
+ RealSuiteDescription( argFile, argLine, argSuiteName, argTests )
+ {
+ doInitialize( argCreateLine, argDestroyLine );
+ }
+
+ void CommonDynamicSuiteDescription::initialize( const char *argFile, unsigned argLine,
+ const char *argSuiteName, List &argTests,
+ unsigned argCreateLine, unsigned argDestroyLine )
+ {
+ RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests );
+ doInitialize( argCreateLine, argDestroyLine );
+ }
+
+ void CommonDynamicSuiteDescription::doInitialize( unsigned argCreateLine, unsigned argDestroyLine )
+ {
+ _createLine = argCreateLine;
+ _destroyLine = argDestroyLine;
+ }
+
+ List &RealWorldDescription::suites()
+ {
+ return RealSuiteDescription::_suites;
+ }
+
+ unsigned RealWorldDescription::numSuites( void ) const
+ {
+ return suites().size();
+ }
+
+ unsigned RealWorldDescription::numTotalTests( void ) const
+ {
+ unsigned count = 0;
+ for ( const SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() )
+ count += sd->numTests();
+ return count;
+ }
+
+ SuiteDescription *RealWorldDescription::firstSuite()
+ {
+ return (RealSuiteDescription *)suites().head();
+ }
+
+ const SuiteDescription *RealWorldDescription::firstSuite() const
+ {
+ return (const RealSuiteDescription *)suites().head();
+ }
+
+ const SuiteDescription &RealWorldDescription::suiteDescription( unsigned i ) const
+ {
+ return *(const RealSuiteDescription *)suites().nth( i );
+ }
+
+ void RealWorldDescription::activateAllTests()
+ {
+ suites().activateAll();
+ for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() )
+ sd->activateAllTests();
+ }
+
+ bool RealWorldDescription::leaveOnly( const char *suiteName, const char *testName )
+ {
+ for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) {
+ if ( stringsEqual( sd->suiteName(), suiteName ) ) {
+ if ( testName )
+ if ( !sd->leaveOnly( testName ) )
+ return false;
+ suites().leaveOnly( *sd );
+ return true;
+ }
+ }
+ return false;
+ }
+
+ bool RealWorldDescription::setUp()
+ {
+ for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) {
+ bool ok;
+ _TS_TRY { ok = gf->setUpWorld(); }
+ _TS_LAST_CATCH( { ok = false; } );
+
+ if ( !ok ) {
+ reportError( "Error setting up world" );
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ bool RealWorldDescription::tearDown()
+ {
+ for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) {
+ bool ok;
+ _TS_TRY { ok = gf->tearDownWorld(); }
+ _TS_LAST_CATCH( { ok = false; } );
+
+ if ( !ok ) {
+ reportError( "Error tearing down world" );
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ void RealWorldDescription::reportError( const char *message )
+ {
+ doWarn( __FILE__, 5, message );
+ }
+
+ void activateAllTests()
+ {
+ RealWorldDescription().activateAllTests();
+ }
+
+ bool leaveOnly( const char *suiteName, const char *testName )
+ {
+ return RealWorldDescription().leaveOnly( suiteName, testName );
+ }
+}
+
+#endif // __cxxtest__RealDescriptions_cpp__
+
diff --git a/test/cxxtest/cxxtest/RealDescriptions.h b/test/cxxtest/cxxtest/RealDescriptions.h
new file mode 100644
index 0000000000..14c457de7e
--- /dev/null
+++ b/test/cxxtest/cxxtest/RealDescriptions.h
@@ -0,0 +1,223 @@
+#ifndef __cxxtest__RealDescriptions_h__
+#define __cxxtest__RealDescriptions_h__
+
+//
+// The "real" description classes
+//
+
+#include
+#include
+#include
+
+namespace CxxTest
+{
+ class RealTestDescription : public TestDescription
+ {
+ public:
+ RealTestDescription();
+ RealTestDescription( List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName );
+ void initialize( List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName );
+
+ const char *file() const;
+ unsigned line() const;
+ const char *testName() const;
+ const char *suiteName() const;
+
+ TestDescription *next();
+ const TestDescription *next() const;
+
+ TestSuite *suite() const;
+
+ bool setUp();
+ void run();
+ bool tearDown();
+
+ private:
+ RealTestDescription( const RealTestDescription & );
+ RealTestDescription &operator=( const RealTestDescription & );
+
+ virtual void runTest() = 0;
+
+ SuiteDescription *_suite;
+ unsigned _line;
+ const char *_testName;
+ };
+
+ class RealSuiteDescription : public SuiteDescription
+ {
+ public:
+ RealSuiteDescription();
+ RealSuiteDescription( const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests );
+
+ void initialize( const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests );
+
+ const char *file() const;
+ unsigned line() const;
+ const char *suiteName() const;
+
+ TestDescription *firstTest();
+ const TestDescription *firstTest() const;
+ SuiteDescription *next();
+ const SuiteDescription *next() const;
+
+ unsigned numTests() const;
+ const TestDescription &testDescription( unsigned i ) const;
+
+ void activateAllTests();
+ bool leaveOnly( const char *testName );
+
+ private:
+ RealSuiteDescription( const RealSuiteDescription & );
+ RealSuiteDescription &operator=( const RealSuiteDescription & );
+
+ const char *_file;
+ unsigned _line;
+ const char *_suiteName;
+ List *_tests;
+
+ static List _suites;
+ friend class RealWorldDescription;
+ };
+
+ class StaticSuiteDescription : public RealSuiteDescription
+ {
+ public:
+ StaticSuiteDescription();
+ StaticSuiteDescription( const char *argFile, unsigned argLine,
+ const char *argSuiteName, TestSuite &argSuite,
+ List &argTests );
+
+ void initialize( const char *argFile, unsigned argLine,
+ const char *argSuiteName, TestSuite &argSuite,
+ List &argTests );
+ TestSuite *suite() const;
+
+ bool setUp();
+ bool tearDown();
+
+ private:
+ StaticSuiteDescription( const StaticSuiteDescription & );
+ StaticSuiteDescription &operator=( const StaticSuiteDescription & );
+
+ void doInitialize( TestSuite &argSuite );
+
+ TestSuite *_suite;
+ };
+
+ class CommonDynamicSuiteDescription : public RealSuiteDescription
+ {
+ public:
+ CommonDynamicSuiteDescription();
+ CommonDynamicSuiteDescription( const char *argFile, unsigned argLine,
+ const char *argSuiteName, List &argTests,
+ unsigned argCreateLine, unsigned argDestroyLine );
+
+ void initialize( const char *argFile, unsigned argLine,
+ const char *argSuiteName, List &argTests,
+ unsigned argCreateLine, unsigned argDestroyLine );
+
+ protected:
+ unsigned _createLine, _destroyLine;
+
+ private:
+ void doInitialize( unsigned argCreateLine, unsigned argDestroyLine );
+ };
+
+ template
+ class DynamicSuiteDescription : public CommonDynamicSuiteDescription
+ {
+ public:
+ DynamicSuiteDescription() {}
+ DynamicSuiteDescription( const char *argFile, unsigned argLine,
+ const char *argSuiteName, List &argTests,
+ S *&argSuite, unsigned argCreateLine,
+ unsigned argDestroyLine ) :
+ CommonDynamicSuiteDescription( argFile, argLine, argSuiteName, argTests, argCreateLine, argDestroyLine )
+ {
+ _suite = &argSuite;
+ }
+
+ void initialize( const char *argFile, unsigned argLine,
+ const char *argSuiteName, List &argTests,
+ S *&argSuite, unsigned argCreateLine,
+ unsigned argDestroyLine )
+ {
+ CommonDynamicSuiteDescription::initialize( argFile, argLine,
+ argSuiteName, argTests,
+ argCreateLine, argDestroyLine );
+ _suite = &argSuite;
+ }
+
+ TestSuite *suite() const { return realSuite(); }
+
+ bool setUp();
+ bool tearDown();
+
+ private:
+ S *realSuite() const { return *_suite; }
+ void setSuite( S *s ) { *_suite = s; }
+
+ void createSuite()
+ {
+ setSuite( S::createSuite() );
+ }
+
+ void destroySuite()
+ {
+ S *s = realSuite();
+ setSuite( 0 );
+ S::destroySuite( s );
+ }
+
+ S **_suite;
+ };
+
+ template
+ bool DynamicSuiteDescription::setUp()
+ {
+ _TS_TRY {
+ _TSM_ASSERT_THROWS_NOTHING( file(), _createLine, "Exception thrown from createSuite()", createSuite() );
+ _TSM_ASSERT( file(), _createLine, "createSuite() failed", suite() != 0 );
+ }
+ _TS_CATCH_ABORT( { return false; } );
+
+ return (suite() != 0);
+ }
+
+ template
+ bool DynamicSuiteDescription::tearDown()
+ {
+ if ( !_suite )
+ return true;
+
+ _TS_TRY {
+ _TSM_ASSERT_THROWS_NOTHING( file(), _destroyLine, "destroySuite() failed", destroySuite() );
+ }
+ _TS_CATCH_ABORT( { return false; } );
+
+ return true;
+ }
+
+ class RealWorldDescription : public WorldDescription
+ {
+ public:
+ static List &suites();
+ unsigned numSuites( void ) const;
+ unsigned numTotalTests( void ) const;
+ SuiteDescription *firstSuite();
+ const SuiteDescription *firstSuite() const;
+ const SuiteDescription &suiteDescription( unsigned i ) const;
+ void activateAllTests();
+ bool leaveOnly( const char *suiteName, const char *testName = 0 );
+
+ bool setUp();
+ bool tearDown();
+ static void reportError( const char *message );
+ };
+
+ void activateAllTests();
+ bool leaveOnly( const char *suiteName, const char *testName = 0 );
+}
+
+#endif // __cxxtest__RealDescriptions_h__
+
diff --git a/test/cxxtest/cxxtest/Root.cpp b/test/cxxtest/cxxtest/Root.cpp
new file mode 100644
index 0000000000..c4320fde72
--- /dev/null
+++ b/test/cxxtest/cxxtest/Root.cpp
@@ -0,0 +1,18 @@
+#ifndef __cxxtest__Root_cpp__
+#define __cxxtest__Root_cpp__
+
+//
+// This file holds the "root" of CxxTest, i.e.
+// the parts that must be in a source file file.
+//
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#endif // __cxxtest__Root_cpp__
diff --git a/test/cxxtest/cxxtest/SelfTest.h b/test/cxxtest/cxxtest/SelfTest.h
new file mode 100644
index 0000000000..6d6b96e7d9
--- /dev/null
+++ b/test/cxxtest/cxxtest/SelfTest.h
@@ -0,0 +1,7 @@
+#ifndef __cxxtest_SelfTest_h__
+#define __cxxtest_SelfTest_h__
+
+#define CXXTEST_SUITE(name)
+#define CXXTEST_CODE(member)
+
+#endif // __cxxtest_SelfTest_h__
diff --git a/test/cxxtest/cxxtest/StdHeaders.h b/test/cxxtest/cxxtest/StdHeaders.h
new file mode 100644
index 0000000000..7c80b76f9a
--- /dev/null
+++ b/test/cxxtest/cxxtest/StdHeaders.h
@@ -0,0 +1,25 @@
+#ifndef __cxxtest_StdHeaders_h__
+#define __cxxtest_StdHeaders_h__
+
+//
+// This file basically #includes the STL headers.
+// It exists to support warning level 4 in Visual C++
+//
+
+#ifdef _MSC_VER
+# pragma warning( push, 1 )
+#endif // _MSC_VER
+
+#include
+#include
+#include
+#include
After you have your test suites, you use CxxTest to generate a "test runner" source file:
+
+
Fixing the bug is left as an excercise to the reader.
+
+
2.4 Graphical user interface
+
+ (v3.0.1)
+CxxTest can also display a simple GUI. The way to do this is depends on
+your compiler, OS and environment, but try the following pointers:
+
+
+
Under Windows with Visual C++, run perl cxxtestgen.pl -o runner.cpp
+--gui=Win32Gui MyTestSuite.h.
+
+
Under X-Windows, try ./cxxtestgen.pl -o runner.cpp
+--gui=X11Gui MyTestSuite. You may need to tell the compiler
+where to find X, usually something like g++ -o runner
+-L/usr/X11R6/lib runner.cpp -lX11.
+
+
If you have Qt installed, try running
+cxxtestgen.pl with the option --gui=QtGui. As
+always, compile and link the the Qt headers and libraries.
+
+
There is much more to CxxTest than seeing if two times two is four.
+You should probably take a look at the samples in the CxxTest distribution.
+Other than that, here are some more in-depth explanations.
+
+
3.1 What can you test
+
+
Here are the different "assertions" you can use in your tests:
+
+
TS_FAIL just fails the test.
+It is like an assert(false) with an error message.
+For example:
+
+
+
+ void testSomething( void )
+ {
+ TS_FAIL( "I don't know how to test this!" );
+ }
+
+
+
+
3.1.2 TS_ASSERT
+
+
+
+
TS_ASSERT is the basic all-around tester. It works just like the
+well-respected assert() macro (which I sincerely hope you know and
+use!) An example:
+
+
+
+ (v3.5.1)
+This assertion is similar to TS_ASSERT_EQUALS(), except that it
+compares the contents of two buffers in memory. If the comparison
+fails, the standard runner dumps the contents of both buffers as hex
+values.
+
+
+
+ (v3.8.2)
+This macro can be seen as a generalization of
+TS_ASSERT(). It takes as an argument the name of a class,
+similar to an STL unary_function, and evaluates
+operator(). The advantage this has over
+TS_ASSERT() is that you can see the failed value.
+
+
These assertions are used to test whether an expression throws an exception.
+TS_ASSERT_THROWS is used when you want to verify the type of exception
+thrown, and TS_ASSERT_THROWS_ANYTHING is used to just make sure something
+is thrown. As you might have guessed, TS_ASSERT_THROWS_NOTHING asserts
+that nothing is thrown.
+
+ (v3.10.0)
+TS_ASSERT_THROWS_EQUALS checks the type of the
+exception as in TS_ASSERT_THROWS then allows you to compare two
+value (one of which will presumably be the caught object).
+TS_ASSERT_THROWS_ASSERT is the general case, and allows you to
+make any assertion about the thrown value. These macros may seem a
+little complicated, but they can be very useful; see below for an
+example.
+
+
+
+
+ (v3.0.1)
+TS_WARN just prints out a message, like the
+#warning preprocessor directive. I find it very useful for "to
+do" items. For example:
+
+
In the GUI, TS_WARN sets the bar color to yellow (unless it was
+already red).
+
+ (v3.9.0)
+TS_TRACE is the same, except that it
+doesn't change the color of the progress bar.
+
+
3.1.13 The ETS_ macros
+
+
The TS_ macros mentioned above will catch exceptions thrown from tested code
+and fail the test, as if you called TS_FAIL().
+Sometimes, however, you may want to catch the exception yourself; when you do, you can
+use the ETS_ versions of the macros.
+
+
+
+ void testInterestingThrower()
+ {
+ // Normal way: if an exception is caught we can't examine it
+ TS_ASSERT_EQUALS( foo(2), 4 );
+
+ // More elaborate way:
+ try { ETS_ASSERT_EQUALS( foo(2), 4 ); }
+ catch( const BadFoo &e ) { TS_FAIL( e.bar() ); }
+ }
+
+
+
+
3.1.14 The TSM_ macros
+
+
Sometimes the default output generated by the ErrorPrinter doesn't give you enough
+information. This often happens when you move common test functionality to helper functions
+inside the test suite; when an assertion fails, you do not know its origin.
+
+
In the example below (which is the file sample/MessageTest.h from the CxxTest distribution),
+we need the message feature to know which invocation of checkValue() failed:
+
+
Note: As with normal asserts, all TSM_ macros have their
+non-exception-safe counterparts, the ETSM_ macros.
+
+
3.2 Running the samples
+
+
+
+
CxxTest comes with some samples in the sample/ subdirectory of
+the distribution. If you look in that directory, you will see three
+Makefiles: Makefile.unix, Makefile.msvc and
+Makefile.bcc32 which are for Linux/Unix, MS Visual C++ and
+Borland C++, repectively. These files are provided as a starting point,
+and some options may need to be tweaked in them for your system.
+
+
If you are running under Windows, a good guess would be to run
+nmake -fMakefile.msvc run_win32 (you may need to run
+VCVARS32.BAT first). Under Linux, make
+-fMakefile.unix run_x11 should probably work.
+
+
3.3 Test fixtures
+
+
When you have several test cases for the same module,
+you often find that all of them start with more or less
+the same code--creating objects, files, inputs, etc.
+They may all have a common ending, too--cleaning up
+the mess you left.
+
+
You can (and should) put all this code in a common place by overriding
+the virtual functions TestSuite::setUp() and
+TestSuite::tearDown(). setUp() will
+then be called before each test, and tearDown()
+after each test.
+
+
Note new users: This is probably the single most important
+feature to use when your tests become non-trivial.
+
+
3.3.1 Test suite level fixtures
+
+
setUp()/tearDown() are executed around each test case. If
+you need a fixture on the test suite level, i.e. something that gets
+constructed once before all the tests in the test suite are run, see
+Dynamically creating test suites below.
+
+
3.4 Integrating with your build environment
+
+
It's very hard to maintain your tests if you have to generate, compile and run the test runner
+manually all the time.
+Fortunately, that's why we have build tools!
+
+
3.4.1 Overview
+
+
Let's assume you're developing an application.
+What I usually do is the following:
+
+
Split the application into a library and a main module that just calls
+ the library classes.
+ This way, the test runner will be able to access all your classes through
+ the library.
+
Create another application (or target, or project, or whatever) for the test runner.
+ Make the build tool generate it automatically.
+
For extra points, make the build tool run the tests automatically.
+
+
+
3.4.2 Actually doing it
+
+
Unfortunately, there are way too many different build tools and IDE's for me
+to give ways to use CxxTest with all of them.
+
+
I will try to outline the usage for some cases.
+
+
3.4.2.1 Using Makefiles
+
+
Generating the tests with a makefile is pretty straightforward.
+Simply add rules to generate, compile and run the test runner.
+
+
+
+ all: lib run_tests app
+
+ # Rules to build your targets
+ lib: ...
+
+ app: ...
+
+ # A rule that runs the unit tests
+ run_tests: runner
+ ./runner
+
+ # How to build the test runner
+ runner: runner.cpp lib
+ g++ -o $@ $^
+
+ # How to generate the test runner
+ runner.cpp: SimpleTest.h ComplicatedTest.h
+ cxxtestgen.pl -o $@ --error-printer $^
+
+
+
+
3.4.2.2 Using Cons
+
+ Cons is a powerful and
+versatile make replacement which uses Perl scripts instead of Makefiles.
+
+
See sample/Construct in the CxxTest distribution for an example of building CxxTest test runners
+with Cons.
+
+
3.4.2.3 Using Microsoft Visual Studio
+
+
I have tried several ways to integrate CxxTest with visual studio, none of
+which is perfect. Take a look at sample/msvc in the distribution
+to see the best solution I'm aware of. Basically, the workspace has three
+projects:
+
+
+
The project CxxTest_3_Generate runs cxxtestgen.
+
+
The project CxxTest_2_Build compiles the generated file.
+
+
The project CxxTest_1_Run runs the tests.
+
+
+
This method certainly works, and the test results are conveniently
+displayed as compilation errors and warnings (for
+TS_WARN()). However, there are still a few things missing;
+to integrate this approach with your own project, you usually need to
+work a little bit and tweak some makefiles and project options. I have
+provided a small script in sample/msvc/FixFiles.bat to automate
+some of the process.
+
+
3.4.2.4 Using Microsoft Windows DDK
+
+
Unit testing for device drivers?! Why not?
+And besides, the build utility can also be used to build
+user-mode application.
+
+
To use CxxTest with the build utility,
+you add the generated tests file as an extra dependency
+using the NTBUILDTARGET0 macro and the Makefile.inc
+file.
+
+
You can see an example of how to do this in the CxxTest distribution
+under sample/winddk.
+
+
3.5 Graphical user interface
+
+
+
+
There are currently three GUIs implemented: native Win32, native X11 and
+Qt. To use this feature, just specify --gui=X11Gui,
+--gui=Win32Gui or --gui=QtGui as a parameter for
+cxxtestgen (instead of e.g. --error-printer). A
+progress bar is displayed, but the results are still written to standard
+output, where they can be processed by your IDE (e.g. Emacs or Visual
+Studio). The default behavior of the GUI is to close the window after
+the last test.
+
+
Note that whatevr GUI you use, you can combine it with the
+--runner option to control the formatting of the text output,
+e.g. Visual Studio likes it better if you use
+--runner=ParenPrinter.
+
+
3.5.1 Starting the GUI minimized
+
+
If you run the generated Win32 or Qt GUIs with the command line
+-minimized, the test window will start minimized (iconified)
+and only pop up if there is an error (the bar turns red). This is useful
+if you find the progress bar distracting and only want to check it if
+something happens.
+
+
3.5.2 Leaving the GUI open
+
+
The Win32 GUI accepts the -keep which instructs it to leave the
+window open after the tests are done. This allows you to see how many
+tests failed and how much time it took.
+
+
3.5.3 Screenshots!
+
+
As with any self-respecting GUI application, here are some screenshots for
+you to enjoy:
+
+
+
+
Using the Qt GUI on Linux (with the WindowMaker window manager):
+
+
+
Using the Win32 GUI on Windows 98:
+
+
+
Using the X11 GUI (with the venerable TWM):
+
+
+
And of course, no GUI is complete without the ability to mess around with
+its appearance:
+
+
+
Ahhh. Nothing like a beautiful user interface.
+
+
+
+
4 Advanced topics
+
+
Topics in this section are more technical, and you probably won't find them
+interesting unless you need them.
+
+
4.1 Aborting tests after failures
+
+
Usually, when a TS_ASSERT_* macro fails, CxxTest moves on to the
+next line. In many cases, however, this is not the desired behavior.
+Consider the following code:
+
+
+
+ void test_memset()
+ {
+ char *buffer = new char[1024];
+ TS_ASSERT( buffer );
+ memset( buffer, 0, 1024 ); // But what if buffer == 0?
+ }
+
+
+
+
If you have exception handling enabled, you can make CxxTest exit each
+test as soon as a failure occurs. To do this, you need to define
+CXXTEST_ABORT_TEST_ON_FAIL before including the CxxTest
+headers. This can be done using the --abort-on-fail
+command-line option or in a template file; see
+sample/aborter.tpl in the distribution. Note that if CxxTest
+doesn't find evidence of exception handling when scanning your files,
+this feature will not work. To overcome this, use the
+--have-eh command-line option.
+
+
4.1.1 Controlling this behavior at runtime
+
+ (v3.8.5)
+In some scenarios, you may want some tests to abort on
+failed assertions and others to continue. To do this you use the
+--abort-on-fail option and call the function
+CxxTest::setAbortTestOnFail( bool ) to change the runtime
+behavior. This flag is reset (normally, to true) after each
+test, but you can set it in your test suite's setUp() function to
+modify the behavior for all tests in a suite.
+
+ (v3.9.0)
+Note that this behavior is available whenever you have
+exception handling (--have-eh or CXXTEST_HAVE_EH); all
+--abort-on-fail does is set the default to true.
+
+
4.2 Commenting out tests
+
+
CxxTest does a very simple analysis of the input files, which is sufficient in most cases.
+This means, for example, that you can't indent you test code in "weird" ways.
+
+
A slight inconvenience arises, however, when you want to comment out
+tests. Commenting out the tests using C-style comments or the
+preprocessor will not work:
+
+
+
+ (v3.10.0)
+If you need to comment out tests, use C++-style
+comments. Also, if you just don't want CxxTest to run a specific test
+function, you can temporarily change its name, e.g. by prefixing it with
+x:
+
+
You may have noticed that TS_ASSERT_EQUALS() only works for built-in
+types.
+This is because CxxTest needs a way to compare object and to convert them to strings,
+in order to print them should the test fail.
+
+
If you do want to use TS_ASSERT_EQUALS() on your own data types,
+this is how you do it.
+
+
4.3.1 The equality operator
+
+
First of all, don't forget to implement the equality operator (operator==())
+on your data types!
+
+
4.3.2 Value traits
+
+
Since CxxTest tries not to rely on any external library (including the standard library,
+which is not always available), conversion from arbitrary data types to strings
+is done using value traits.
+
+
For example, to convert an integer to a string, CxxTest does the following actions:
+
+
int i = value to convert;
+
CxxTest::ValueTraits<int> converter(i);
+
string = converter.asString();
+
+
+
CxxTest comes with predefined ValueTraits for int,
+char, dobule etc. in cxxtest/ValueTraits.h in the
+cxxtest-selftest archive.
+
+
4.3.3 Unknown types
+
+
Obviously, CxxTest doesn't "know" about all possible types.
+The default ValueTraits class for unknown types dumps up to 8 bytes of the value in hex format.
+
+
+
+ (v3.10.0)
+CxxTest provides a simple way to define value traits for
+your enumeration types, which is very handy for things like status
+codes. To do this, simply use CXXTEST_VALUE_TRAITS as in the
+following example:
+
+
Defining value traits for new (non-enumeration) types is easy. All you
+need is to define a way to convert an object of your class to a
+string. You can use this example as a possible skeleton:
+
+
+
+ class MyClass
+ {
+ int _value;
+
+ public:
+ MyClass( int value ) : _value( value ) {}
+ int value() const { return _value; }
+
+ // CxxTest requires a copy constructor
+ MyClass( const MyClass &other ) : _value( other._value ) {}
+
+ // If you want to use TS_ASSERT_EQUALS
+ bool operator== ( const MyClass &other ) const { return _value == other._value; }
+
+ // If you want to use TS_ASSERT_LESS_THAN
+ bool operator== ( const MyClass &other ) const { return _value < other._value; }
+ };
+
+ #ifdef CXXTEST_RUNNING
+ #include <cxxtest/ValueTraits.h>
+ #include <stdio.h>
+
+ namespace CxxTest
+ {
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<MyClass>
+ {
+ char _s[256];
+
+ public:
+ ValueTraits( const MyClass &m ) { sprintf( _s, "MyClass( %i )", m.value() ); }
+ const char *asString() const { return _s; }
+ };
+ };
+ #endif // CXXTEST_RUNNING
+
+
+
+
4.3.5.1 Defining value traits for template classes
+
+
A simple modification to the above scheme allows you to define value
+traits for your template classes. Unfortunately, this syntax (partial
+template specialization) is not supported by some popular C++ compilers.
+Here is an example:
+
+
+
+ (v2.8.2)
+If you don't like the way CxxTest defines the default ValueTraits,
+you can override them by #define-ing CXXTEST_USER_VALUE_TRAITS;
+this causes CxxTest to omit the default definitions, and from there on you are
+free to implement them as you like.
+
+
You can see a sample of this technique in test/UserTraits.tpl in
+the cxxtest-selftest archive.
+
+
4.4 Global Fixtures
+
+ (v3.5.1)
+The setUp() and tearDown() functions allow
+to to have code executed before and after each test. What if you want
+some code to be executed before all tests in all test suites?
+Rather than duplicate that code, you can use global fixtures.
+These are basically classes that inherit from
+CxxTest::GlobalFixture. All objects of such classes are
+automatically notified before and after each test case. It is best to
+create them as static objects so they get called right from the start.
+Look at test/GlobalFixtures.h in the cxxtest-selftest
+archive.
+
+
Note: Unlike setUp() and tearDown() in
+TestSuite, global fixtures should return a bool value to
+indicate success/failure.
+
+
4.4.1 World fixtures
+
+ (v3.8.1)
+CxxTest also allows you to specify code which is executed
+once at the start of the testing process (and the corresponding cleanup
+code). To do this, create (one or more) global fixture objects and
+implement setUpWorld()/tearDownWorld(). For an example,
+see test/WorldFixtures.h in the cxxtest-selftest archive.
+
+
4.5 Mock Objects
+
+ (v3.10.0)
+Mock Objects are a very useful testing tool, which
+consists (in a nutshell) of passing special objects to tested code. For
+instance, to test a class that implements some protocol over TCP, you
+might have it use an abstract ISocket interface and in the tests
+pass it a MockSocket object. This MockSocket object can
+then do anything your tests find useful, e.g. keep a log of all data
+"sent" to verify later.
+
+
So far, so good. But the problem when developing in C/C++ is that your
+code probably needs to call global functions which you cannot
+override. Just consider any code which uses fopen(),
+fwrite() and fclose(). It is not very elegant to have
+this code actually create files while being tested. Even more
+importantly, you (should) want to test how the code behaves when "bad"
+things happen, say when fopen() fails. Although for some cases
+you can cause the effects to happen in the test code, this quickly
+becomes "hairy" and unmaintainable.
+
+
CxxTest solves this problem by allowing you to override any global
+function while testing. Here is an outline of how it works, before we
+see an actual example:
+
+
+
For each function you want to override, you use the macro
+CXXTEST_MOCK_GLOBAL to "prepare" the function (all is explained
+below in excruciating detail).
+
+
In the tested code you do not call the global functions directly;
+rather, you access them in the T (for Test) namespace. For
+instance, your code needs to call T::fopen() instead of
+fopen(). This is the equivalent of using abstract interfaces
+instead of concrete classes.
+
+
You link the "real" binary with a source file that implements
+T::fopen() by simply calling the original fopen().
+
+
You link the test binary with a source file that implements
+T::fopen() by calling a mock object.
+
+
To test, you should create a class that inherits T::Base_fopen
+and implement its fopen() function. Simply by creating an object
+of this class, calls made to T::fopen() will be redirected to it.
+
+
+
+
This may seem daunting at first, so let us work our way through a simple
+example. Say we want to override the well known standard library
+function time().
+
+
+
+
Prepare a header file to be used by both the real and test code.
+
+
+ // T/time.h
+ #include <time.h>
+ #include <cxxtest/Mock.h>
+
+ CXXTEST_MOCK_GLOBAL( time_t, /* Return type */
+ time, /* Name of the function */
+ ( time_t *t ), /* Prototype */
+ ( t ) /* Argument list */ );
+
+
+
+
In our tested code, we now include the special header instead of the
+system-supplied one, and call T::time() instead of time().
+
We also need to create a source file that implements T::time() by
+calling the real function. This is extremely easy: just define
+CXXTEST_MOCK_REAL_SOURCE_FILE before you include the header file:
+
I know that this might seem a bit heavy at first glance, but once you
+start using mock objects you will never go back. The hardest part may
+be getting this to work with your build system, which is why I have
+written a simple example much like this one in sample/mock, which
+uses GNU Make and G++.
+
+
4.5.2 Advanced topic with mock functions
+
+
4.5.2.1 Void functions
+
+
Void function are a little different, and you use
+CXXTEST_MOCK_VOID_GLOBAL to override them. This is identical to
+CXXTEST_MOCK_GLOBAL except that it doesn't specify the return
+type. Take a look in sample/mock/T/stdlib.h for a demonstation.
+
+
4.5.2.2 Calling the real functions while testing
+
+
From time to time, you might want to let the tested code call the real
+functions (while being tested). To do this, you create a special mock
+object called e.g. T::Real_time. While an object of this class
+is present, calls to T::time() will be redirected to the real
+function.
+
+
4.5.2.3 When there is no real function
+
+
Sometimes your code needs to call functions which are not available when
+testing. This happens for example when you test driver code using a
+user-mode test runner, and you need to call kernel functions. You can
+use CxxTest's mock framework to provide testable implementations for the
+test code, while maintaing the original functions for the real code.
+This you do with CXXTEST_SUPPLY_GLOBAL (and
+CXXTEST_SUPPLY_VOID_GLOBAL). For example, say you want to supply
+your code with the Win32 kernel function IoCallDriver:
+
+
+ CXXTEST_SUPPLY_GLOBAL( NTSTATUS, /* Return type */
+ IoCallDriver, /* Name */
+ ( PDEVICE_OBJECT Device, /* Prototype */
+ PIRP Irp ),
+ ( Device, Irp ) /* How to call */ );
+
+
+ The tested code (your driver) can now call IoCallDriver()
+normally (no need for T::), and the test code uses
+T::Base_IoCallDriver as with normal mock objects.
+
+
Note: Since these macros can also be used to actually declare
+the function prototypes (e.g. in the above example you might not be able
+to include the real <ntddk.h> from test code), they also have an
+extern "C" version which declares the functions with C
+linkage. These are CXXTEST_SUPPLY_GLOBAL_C and
+CXXTEST_SUPPLY_GLOBAL_VOID_C.
+
+
4.5.2.4 Functions in namespaces
+
+
Sometimes the functions you want to override are not in the global
+namespace like time(): they may be global functions in other
+namespaces or even static class member functions. The default mock
+implementation isn't suitable for these. For them, you can use the
+generic CXXTEST_MOCK, which is best explained by example. Say you
+have a namespace Files, and you want to override the function
+bool Files::FileExists( const String &name ), so that the mock
+class will be called T::Base_Files_FileExists and the function to
+implement would be fileExists. You would define it thus (of
+course, you would normally want the mock class name and member function
+to be the same as the real function):
+
+
+ CXXTEST_MOCK( Files_FileExists, /* Suffix of mock class */
+ bool, /* Return type */
+ fileExists, /* Name of mock member */
+ ( const String &name ), /* Prototype */
+ Files::FileExists, /* Name of real function */
+ ( name ) /* Parameter list */ );
+
+
+ Needless to say, there is also CXXTEST_MOCK_VOID for void functions.
+
+
There is also an equivalent version for CXXTEST_SUPPLY_GLOBAL, as
+demonstrated by another function from the Win32 DDK:
+
+
+ CXXTEST_SUPPLY( AllocateIrp, /* => T::Base_AllocateIrp */
+ PIRP, /* Return type */
+ allocateIrp, /* Name of mock member */
+ ( CCHAR StackSize ), /* Prototype */
+ IoAllocateIrp, /* Name of real function */
+ ( StackSize ) /* Parameter list */ );
+
+
+ And, with this macro you have CXXTEST_SUPPLY_VOID and of course
+CXXTEST_SUPPLY_C and CXXTEST_SUPPLY_VOID_C.
+
+
4.5.2.5 Overloaded functions
+
+
If you have two or more global functions which have the same name, you
+cannot create two mock classes with the same name. The solution is to
+use the general CXXTEST_MOCK/CXXTEST_MOCK_VOID as above:
+just give the two mock classes different names.
+
+
4.5.2.6 Changing the mock namespace
+
+
Finally, if you don't like or for some reason can't use the T::
+namespace for mock functions, you can change it by defining
+CXXTEST_MOCK_NAMESPACE. Have fun.
+
+
4.6 Test Listeners and Test Runners
+
+
A TestListener is a class that receives notifications about
+the testing process, notably which assertions failed. CxxTest defines
+a standard test listener class, ErrorPrinter, which is
+responsible for printing the dots and messages seen above. When the
+test runners generated in the examples run, they create an
+ErrorPrinter and pass it to
+TestRunner::runAllTests(). As you might have guessed, this
+functions runs all the test you've defined and reports to the
+TestListener it was passed.
+
+
4.6.1 Other test listeners
+
+
If you don't like or can't use the ErrorPrinter, you can use
+any other test listener.
+To do this you have to omit the --error-printer, --runner=
+or --gui= switch when generating the tests file.
+It is then up to you to write the main() function, using the
+test listener of your fancy.
+
+
4.6.1.1 The stdio printer
+
+
If the ErrorPrinter's usage of std::cout clashes
+with your environment or is unsupported by your compiler, don't dispair!
+You may still be able to use the StdioPrinter, which does the
+exact same thing but uses good old printf().
+
+
To use it, invoke cxxtestgen.pl with the --runner=StdioPrinter option.
+
+ (v3.8.5)
+Note:cxxtest/StdioPrinter makes
+reference to stdout as the default output stream. In some
+environments you may have <stdio.h> but not stdout, which
+will cause compiler errors. To overcome this problem, use
+--runner=StdioFilePrinter, which is exactly the same as
+--runner=StdioPrinter, but with no default output stream.
+
+
4.6.1.2 The Yes/No runner
+
+
As an example, CxxTest also provides the simplest possible test listener,
+one that just reports if there were any failures.
+You can see an example of using this listener in sample/yes_no_runner.cpp.
+
+
4.6.1.3 Template files
+
+
To use you own test runner, or to use the supplied ones in different ways, you can use
+CxxTest template files. These are ordinary source files with the embedded "command"
+<CxxTest world> which tells cxxtestgen.pl to insert the world definition
+at that point. You then specify the template file using the --template option.
+
+
See samples/file_printer.tpl for an example.
+
+
Note: CxxTest needs to insert certain definitions and
+#include directives in the runner file. It normally does that
+before the first #include <cxxtest/*.h> found in the template
+file. If this behvaior is not what you need, use the "command"
+<CxxTest preamble>. See test/preamble.tpl in the
+cxxtest-selftest archive for an example of this.
+
+
4.7 Dynamically creating test suites
+
+
+Usually, your test suites are instantiated statically in the tests file, i.e. say you
+defined class MyTest : public CxxTest::TestSuite, the generated file will
+contain something like static MyTest g_MyTest;.
+
+
If, however, your test suite must be created dynamically (it may need a constructor,
+for instance), CxxTest doesn't know how to create it unless you tell it how.
+You do this by writing two static functions, createSuite() and destroySuite().
+
+
See sample/CreatedTest.h for a demonstration.
+
+
4.8 Static initialization
+
+ (v3.9.0)
+The generated runner source file depends quite
+heavily on static initialization of the various "description" object
+used to run your tests. If your compiler/linker has a problem with this
+approach, use the --no-static-init option.
+
+
Appendix A Command line options
+
+
Here are the different command line options for cxxtestgen:
+
+
A.1 --version
+
+ (v3.7.1)
+Specify --version or -v to see the version of CxxTest you are using.
+
+
A.2 --output
+
+
Specify --output=FILE or -o FILE to determine the output file name.
+
+
A.3 --error-printer
+
+
This option creates a test runner which uses the standard error printer class.
+
+
A.4 --runner
+
+
Specify --runner=CLASS to generate a test
+runner that #includes <cxxtest/CLASS.h> and uses
+CxxTest::CLASS as the test runner.
+
+
The currently available runners are:
+
+
--runner=ErrorPrinter
+
This is the standard error printer, which formats its output to std::cout.
+
+
--runner=ParenPrinter
+
Identical to ErrorPrinter except that it prints line numbers in parantheses.
+This is the way Visual Studio expects it.
+
+
--runner=StdioPrinter
+
The same as ErrorPrinter except that it uses printf
+instead of cout.
+
+
--runner=YesNoRunner
+
This runner doesn't produce any output, merely returns a true/false result.
+
+
+
+
A.5 --gui
+
+
Specify --gui=CLASS to generate a test runner that
+#includes <cxxtest/CLASS.h> and uses CxxTest::CLASS
+to display a graphical user interface. This option can be combined with
+the --runner option to determine the text-mode output format.
+The default is the standard error printer.
+
+
There are three different GUIs:
+
+
--gui=Win32Gui
+
A native Win32 GUI. It has been tested on Windows 98, 2000 and XP and
+should work unmodified on other 32-bit versions of Windows.
+
+
--gui=X11Gui
+
A native XLib GUI. This GUI is very spartan and should work on any X server.
+
+
--gui=QtGui
+
A GUI that uses the Qt library from Troll. It has been tested with Qt versiond 2.2.1 and 3.0.1.
+
+
+
A.6 --include
+
+ (v3.5.1)
+If you specify --include=FILE, cxxtestgen will add
+#include "FILE" to the runner before including any other header.
+This allows you to define things that modify the behavior of CxxTest,
+e.g. your own ValueTraits.
+
+
Note: If you want the runner to #inculde <FILE>, specify
+it on the command line, e.g. --include=<FILE>. You will most
+likely need to use shell escapes, e.g. "--include=<FILE>" or
+--include=\<FILE\>.
+
+
Examples: --include=TestDefs.h or --include=\<GlobalDefs.h\>.
+
+
A.7 --template
+
+
Specify --template=FILE to use FILE as a template file.
+This is for cases for which --runner and/or --include
+are not enough. One example is the Windows DDK; see
+sample/winddk in the distribution.
+
+
A.8 --have-eh
+
+ (v2.8.4)
+cxxtestgen will scan its input files for uses of exception
+handling; if found, the TS_ macros will catch exceptions,
+allowing the testing to continue. Use --have-eh to tell
+cxxtestgen to enable that functionality even if exceptions
+are not used in the input files.
+
+
A.9 --no-eh
+
+ (v3.8.5)
+If you want cxxtestgen to ignore what may look as uses of
+exception handling in your test files, specify --no-eh.
+
+
A.10 --have-std
+
+ (v3.10.0)
+Same as --have-eh but for the standard library;
+basically, if you use this flag, CxxTest will print the values of
+std::string.
+
+
Note: If you reference the standard library anywhere in your
+test files, CxxTest will (usually) recognize it and automatically define
+this.
+
+
A.11 --no-std
+
+ (v3.10.0)
+The counterpart to --have-std, this tells
+CxxTest to ignore any evidence it finds for the std:: namespace
+in your code. Use it if your environment does not support std::
+but cxxtestgen thinks it does.
+
+
A.12 --longlong
+
+ (v3.6.0)
+Specify --longlong=TYPE to have CxxTest recognize TYPE
+as "long long" (e.g. --longlong=__int64). If you specify
+just --longlong= (no type), CxxTest will use the default type
+name of long long.
+
+
A.13 --abort-on-fail
+
+ (v2.8.2)
+This useful option tells CxxTest to abort the current test when any
+TS_ASSERT macro has failed.
+
+
A.14 --part
+
+ (v3.5.1)
+This option tells CxxTest now to write the CxxTest globals in the output
+file. Use this to link together more than one generated file.
+
+
A.15 --root
+
+ (v3.5.1)
+This is the counterpart of --part; it makes sure that the
+Cxxtest globals are written to the output file. If you specify this
+option, you can use cxxtestgen without any input files to
+create a file that hold only the "root" runner.
+
+
A.16 --no-static-init
+
+ (v3.9.0)
+Use this option if you encounter problems with the static
+initializations in the test runner.
+
+
Appendix B Controlling the behavior of CxxTest
+
+
Here are various #defines you can use to modify how CxxTest
+works. You will need to #define them before including any
+of the CxxTest headers, so use them in a template file or with the
+--include option.
+
+
B.1 CXXTEST_HAVE_STD
+
+
This is equivalent to the --have-std option.
+
+
B.2 CXXTEST_HAVE_EH
+
+
This is equivalent to the --have-eh option.
+
+
B.3 CXXTEST_ABORT_TEST_ON_FAIL
+
+ (v2.8.0)
+This is equivalent to the --abort-on-fail option.
+
+
B.4 CXXTEST_USER_VALUE_TRAITS
+
+
This tells CxxTest you wish to define you own ValueTraits. It will only
+declare the default traits, which dump up to 8 bytes of the data as hex
+values.
+
+
B.5 CXXTEST_OLD_TEMPLATE_SYNTAX
+
+
Some compilers (e.g. Borland C++ 5) don't support the standard way of
+instantiating template classes. Use this define to overcome the problem.
+
+
B.6 CXXTEST_OLD_STD
+
+
Again, this is used to support pre-std:: standard libraries.
+
+
B.7 CXXTEST_MAX_DUMP_SIZE
+
+
This sets the standard maximum number of bytes to dump if
+TS_ASSERT_SAME_DATA() fails. The default is 0, meaning
+no limit.
+
+
B.8 CXXTEST_DEFAULT_ABORT
+
+
This sets the default value of the dynamic "abort on fail" flag. Of
+course, this flag is only used when "abort on fail" is enabled.
+
+
B.9 CXXTEST_LONGLONG
+
+
This is equivalent to --longlong.
+
+
Appendix C Runtime options
+
+
The following functions can be called during runtime (i.e. from your
+tests) to control the behavior of CxxTest. They are reset to their
+default values after each test is executed (more precisely, after
+tearDown() is called). Consequently, if you set them in the
+setUp() function, they will be valid for the entire test suite.
+
+
C.1 setAbortTestOnFail( bool )
+
+
This only works when you have exception handling. It can be used to
+tell CxxTest to temporarily change its behavior. The default value of
+the flag is false, true if you set --abort-on-fail,
+or CXXTEST_DEFAULT_ABORT if you #define it.
+
+
C.2 setMaxDumpSize( unsigned )
+
+
This temporarily sets the maximum number of bytes to dump if
+TS_ASSERT_SAME_DATA() fails. The default is 0, meaning
+no limit, or CXXTEST_MAX_DUMP_SIZE if you #define it.
+
+
Appendix D Version history
+
+
+
Version 3.10.0 (2004-11-20)
+
+
Added mock framework for global functions
+
Added TS_ASSERT_THROWS_ASSERT and TS_ASSERT_THROWS_EQUALS
+
Added CXXTEST_ENUM_TRAITS
+
Improved support for STL classes (vector, map etc.)
+
Added support for Digital Mars compiler
+
Reduced root/part compilation time and binary size
+
Support C++-style commenting of tests
+
+
Version 3.9.1 (2004-01-19)
+
+
Fixed small bug with runner exit code
+
Embedded test suites are now deprecated
+
+
Version 3.9.0 (2004-01-17)
+
+
Added TS_TRACE
+
Added --no-static-init
+
CxxTest::setAbortTestOnFail() works even without --abort-on-fail
+
+
Version 3.8.5 (2004-01-08)
+
+
Added --no-eh
+
Added CxxTest::setAbortTestOnFail() and CXXTEST_DEFAULT_ABORT
+
Added CxxTest::setMaxDumpSize()
+
Added StdioFilePrinter
+
+
Version 3.8.4 (2003-12-31)
+
+
Split distribution into cxxtest and cxxtest-selftest
+
Added sample/msvc/FixFiles.bat
+
+
Version 3.8.3 (2003-12-24)
+
+
Added TS_ASSERT_PREDICATE
+
Template files can now specify where to insert the preamble
+
Added a sample Visual Studio workspace in sample/msvc
+
Can compile in MSVC with warning level 4
+
Changed output format slightly
+
+
Version 3.8.1 (2003-12-21)
+
+
Fixed small bug when using multiple --part files.
+
+You can always get the latest release from
+here or
+here.
+
+
There are several files you can download:
+
+
cxxtest-version-1.noarch.rpm
+
cxxtest-version.tar.gz
+
cxxtest-version.zip
+
cxxtest-guide-version.pdf (the user's guide)
+
+Note that, since CxxTest consists entirely of header files,
+there is no distinction between source and binary distribution.
+
+
There are also files called cxxtest-selftest-*: these
+are used (usually by me) to test the portability of CxxTest, so you
+can probably do without them.
+
+
If you just can't wait for the next release, I sometimes upload betas
+to here.
+
+
Getting started
+Get the sources and build the samples in the sample subdirectory.
+
+
+
+
+
+
diff --git a/test/cxxtest/docs/qt.png b/test/cxxtest/docs/qt.png
new file mode 100644
index 0000000000..56a7a67478
Binary files /dev/null and b/test/cxxtest/docs/qt.png differ
diff --git a/test/cxxtest/docs/qt2.png b/test/cxxtest/docs/qt2.png
new file mode 100644
index 0000000000..918a1f4b49
Binary files /dev/null and b/test/cxxtest/docs/qt2.png differ
diff --git a/test/cxxtest/docs/win32.png b/test/cxxtest/docs/win32.png
new file mode 100644
index 0000000000..5de325bb19
Binary files /dev/null and b/test/cxxtest/docs/win32.png differ
diff --git a/test/cxxtest/docs/x11.png b/test/cxxtest/docs/x11.png
new file mode 100644
index 0000000000..9be8c195aa
Binary files /dev/null and b/test/cxxtest/docs/x11.png differ
diff --git a/test/cxxtest/sample/Construct b/test/cxxtest/sample/Construct
new file mode 100644
index 0000000000..b8019616a9
--- /dev/null
+++ b/test/cxxtest/sample/Construct
@@ -0,0 +1,64 @@
+# -*- Perl -*-
+
+#
+# This file shows how to use CxxTest with Cons
+#
+
+$env = new cons( CXX => ("$^O" eq 'MSWin32') ? 'cl -nologo -GX' : 'c++',
+ CPPPATH => '..',
+ CXXTESTGEN => 'perl -w ../cxxtestgen.pl' );
+
+@tests = <*.h>;
+
+# The error printer is the most basic runner
+CxxTestErrorPrinter $env 'error_printer', @tests;
+
+# You can also specify which runner you want to use
+CxxTestRunner $env 'stdio_printer', 'StdioPrinter', @tests;
+
+# For more control, use template files
+CxxTestTemplate $env 'file_printer', 'file_printer.tpl', @tests;
+
+# Or, you can always separate the tests from the runner
+CxxTest $env 'tests.cpp', '', @tests;
+Program $env 'yes_no_runner', ('yes_no_runner.cpp', 'tests.cpp');
+
+
+#
+# Here is the code used to build these files
+# You can use this in your own Construct files
+#
+
+# cons::CxxTest $env $dst, $options, @srcs
+# Generates a CxxTest source file, passing the specified options to cxxtestgen
+sub cons::CxxTest($$$@) {
+ my ($env, $dst, $options, @srcs) = @_;
+ Command $env $dst, @srcs, "%CXXTESTGEN -o %> ${options} %<";
+}
+
+# cons::CxxTestTemplate $env $dst, $template, @srcs
+# Generates and builds a CxxTest runner using a template file
+sub cons::CxxTestTemplate($$$@) {
+ my ($env, $dst, $template, @srcs) = @_;
+ my $source = "${dst}.cpp";
+ CxxTest $env $source, "--template=${template}", ($template, @srcs);
+ Program $env $dst, $source;
+}
+
+# cons::CxxTestRunner $env $dst, $runner, @srcs
+# Generates and builds a CxxTest runner using the --runner option
+sub cons::CxxTestRunner($$$@) {
+ my ($env, $dst, $runner, @srcs) = @_;
+ my $source = "${dst}.cpp";
+ CxxTest $env $source, "--runner=${runner}", @srcs;
+ Program $env $dst, $source;
+}
+
+# cons::CxxTestErrorPrinter $env $dst, @srcs
+# Generates and builds a CxxTest ErrorPrinter
+sub cons::CxxTestErrorPrinter($$@) {
+ my ($env, $dst, @srcs) = @_;
+ CxxTestRunner $env $dst, 'ErrorPrinter', @srcs;
+}
+
+
diff --git a/test/cxxtest/sample/CreatedTest.h b/test/cxxtest/sample/CreatedTest.h
new file mode 100644
index 0000000000..84e8ae8a4b
--- /dev/null
+++ b/test/cxxtest/sample/CreatedTest.h
@@ -0,0 +1,31 @@
+#ifndef __CREATEDTEST_H
+#define __CREATEDTEST_H
+
+#include
+#include
+#include
+
+//
+// This test suite shows what to do when your test case
+// class cannot be instantiated statically.
+// As an example, this test suite requires a non-default constructor.
+//
+
+class CreatedTest : public CxxTest::TestSuite
+{
+ char *_buffer;
+public:
+ CreatedTest( unsigned size ) : _buffer( new char[size] ) {}
+ virtual ~CreatedTest() { delete [] _buffer; }
+
+ static CreatedTest *createSuite() { return new CreatedTest( 16 ); }
+ static void destroySuite( CreatedTest *suite ) { delete suite; }
+
+ void test_nothing()
+ {
+ TS_FAIL( "Nothing to test" );
+ }
+};
+
+
+#endif // __CREATEDTEST_H
diff --git a/test/cxxtest/sample/DeltaTest.h b/test/cxxtest/sample/DeltaTest.h
new file mode 100644
index 0000000000..7223c3af25
--- /dev/null
+++ b/test/cxxtest/sample/DeltaTest.h
@@ -0,0 +1,27 @@
+#ifndef __DELTATEST_H
+#define __DELTATEST_H
+
+#include
+#include
+
+class DeltaTest : public CxxTest::TestSuite
+{
+ double _pi, _delta;
+
+public:
+ void setUp()
+ {
+ _pi = 3.1415926535;
+ _delta = 0.0001;
+ }
+
+ void testSine()
+ {
+ TS_ASSERT_DELTA( sin(0.0), 0.0, _delta );
+ TS_ASSERT_DELTA( sin(_pi / 6), 0.5, _delta );
+ TS_ASSERT_DELTA( sin(_pi / 2), 1.0, _delta );
+ TS_ASSERT_DELTA( sin(_pi), 0.0, _delta );
+ }
+};
+
+#endif // __DELTATEST_H
diff --git a/test/cxxtest/sample/EnumTraits.h b/test/cxxtest/sample/EnumTraits.h
new file mode 100644
index 0000000000..1a987318f6
--- /dev/null
+++ b/test/cxxtest/sample/EnumTraits.h
@@ -0,0 +1,39 @@
+//
+// This is a test of CxxTest's ValueTraits for enumerations.
+//
+#include
+
+//
+// First define your enumeration
+//
+enum Answer {
+ Yes,
+ No,
+ Maybe,
+ DontKnow,
+ DontCare
+};
+
+//
+// Now make CxxTest aware of it
+//
+CXXTEST_ENUM_TRAITS( Answer,
+ CXXTEST_ENUM_MEMBER( Yes )
+ CXXTEST_ENUM_MEMBER( No )
+ CXXTEST_ENUM_MEMBER( Maybe )
+ CXXTEST_ENUM_MEMBER( DontKnow )
+ CXXTEST_ENUM_MEMBER( DontCare ) );
+
+class EnumTraits : public CxxTest::TestSuite
+{
+public:
+ void test_Enum_traits()
+ {
+ TS_FAIL( Yes );
+ TS_FAIL( No );
+ TS_FAIL( Maybe );
+ TS_FAIL( DontKnow );
+ TS_FAIL( DontCare );
+ TS_FAIL( (Answer)1000 );
+ }
+};
diff --git a/test/cxxtest/sample/ExceptionTest.h b/test/cxxtest/sample/ExceptionTest.h
new file mode 100644
index 0000000000..68363c8740
--- /dev/null
+++ b/test/cxxtest/sample/ExceptionTest.h
@@ -0,0 +1,52 @@
+#ifndef __EXCEPTIONTEST_H
+#define __EXCEPTIONTEST_H
+
+#include
+
+//
+// This test suite demonstrates the use of TS_ASSERT_THROWS
+//
+
+class ExceptionTest : public CxxTest::TestSuite
+{
+public:
+ void testAssertion( void )
+ {
+ // This assert passes, since throwThis() throws (Number)
+ TS_ASSERT_THROWS( throwThis(3), const Number & );
+ // This assert passes, since throwThis() throws something
+ TS_ASSERT_THROWS_ANYTHING( throwThis(-30) );
+ // This assert fails, since throwThis() doesn't throw char *
+ TS_ASSERT_THROWS( throwThis(5), const char * );
+ // This assert fails since goodFunction() throws nothing
+ TS_ASSERT_THROWS_ANYTHING( goodFunction(1) );
+ // The regular TS_ASSERT macros will catch unhandled exceptions
+ TS_ASSERT_EQUALS( throwThis(3), 333 );
+ // You can assert that a function throws nothing
+ TS_ASSERT_THROWS_NOTHING( throwThis(-1) );
+ // If you want to catch the exceptions yourself, use the ETS_ marcos
+ try {
+ ETS_ASSERT_EQUALS( throwThis(3), 333 );
+ } catch( const Number & ) {
+ TS_FAIL( "throwThis(3) failed" );
+ }
+ }
+
+private:
+ void goodFunction( int )
+ {
+ }
+
+ class Number
+ {
+ public:
+ Number( int ) {}
+ };
+
+ int throwThis( int i )
+ {
+ throw Number( i );
+ }
+};
+
+#endif // __EXCEPTIONTEST_H
diff --git a/test/cxxtest/sample/FixtureTest.h b/test/cxxtest/sample/FixtureTest.h
new file mode 100644
index 0000000000..653c7a14ae
--- /dev/null
+++ b/test/cxxtest/sample/FixtureTest.h
@@ -0,0 +1,37 @@
+#ifndef __FIXTURETEST_H
+#define __FIXTURETEST_H
+
+#include
+#include
+
+//
+// This test suite shows how to use setUp() and tearDown()
+// to initialize data common to all tests.
+// setUp()/tearDown() will be called before and after each
+// test.
+//
+
+class FixtureTest : public CxxTest::TestSuite
+{
+ char *_buffer;
+public:
+ void setUp()
+ {
+ _buffer = new char[1024];
+ }
+
+ void tearDown()
+ {
+ delete [] _buffer;
+ }
+
+ void test_strcpy()
+ {
+ strcpy( _buffer, "Hello, world!" );
+ TS_ASSERT_EQUALS( _buffer[0], 'H' );
+ TS_ASSERT_EQUALS( _buffer[1], 'E' );
+ }
+};
+
+
+#endif // __FIXTURETEST_H
diff --git a/test/cxxtest/sample/Makefile.PL b/test/cxxtest/sample/Makefile.PL
new file mode 100755
index 0000000000..d29afcc688
--- /dev/null
+++ b/test/cxxtest/sample/Makefile.PL
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+#
+# This isn't a "real" `Makefile.PL'
+# It just copies the correct `Makefile.*' to `Makefile'
+#
+use strict;
+use Getopt::Long;
+use File::Copy;
+
+sub usage() {
+ die "Usage: $0 [--bcc32]\n";
+}
+
+my $source;
+my $target = 'Makefile';
+my $windows = $ENV{'windir'};
+
+GetOptions( 'bcc32' => sub { $source = 'Makefile.bcc32' } ) or usage();
+if ( !defined( $source ) ) {
+ $source = $windows ? 'Makefile.msvc' : 'Makefile.unix';
+}
+
+unlink($target);
+$windows ? copy($source, $target) : symlink($source, $target);
+
+print "`Makefile' is now `$source'.\n";
+
+#
+# Local Variables:
+# compile-command: "perl Makefile.PL"
+# End:
+#
diff --git a/test/cxxtest/sample/Makefile.bcc32 b/test/cxxtest/sample/Makefile.bcc32
new file mode 100644
index 0000000000..907b98d596
--- /dev/null
+++ b/test/cxxtest/sample/Makefile.bcc32
@@ -0,0 +1,94 @@
+#
+# Makefile for Borland C++
+# Make sure bcc32.exe is in the PATH or change CXXC below
+#
+
+# For the Win32 GUI
+#WIN32_FLAGS = user32.lib comctl32.lib
+
+# For the Qt GUI
+#QTDIR = c:\qt
+QT_FLAGS = -I$(QTDIR)/include $(QTDIR)/lib/qt.lib
+
+
+TARGETS = error_printer.exe stdio_printer.exe yes_no_runner.exe file_printer.exe aborter.exe only.exe
+GUI_TARGETS = win32_runner.exe qt_runner.exe
+TESTS = *.h
+GUI_TESTS = gui/GreenYellowRed.h $(TESTS)
+TESTGEN = perl -w ../cxxtestgen.pl
+CXXC = bcc32.exe -w- -I. -I..
+
+all: $(TARGETS)
+
+clean:
+ del *~ *.o *.obj
+ del $(TARGETS)
+ del $(GUI_TARGETS)
+ del tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp
+ del win32_runner.cpp qt_runner.cpp
+
+distclean: clean
+ del Makefile
+
+run: error_printer.exe
+ error_printer.exe
+
+run_win32: win32_runner.exe
+ win32_runner.exe
+
+run_qt: qt_runner.exe
+ qt_runner.exe
+
+error_printer.cpp: $(TESTS)
+ $(TESTGEN) -o error_printer.cpp --error-printer $(TESTS)
+
+stdio_printer.cpp: $(TESTS)
+ $(TESTGEN) -o stdio_printer.cpp --runner=StdioPrinter $(TESTS)
+
+file_printer.cpp: file_printer.tpl $(TESTS)
+ $(TESTGEN) -o file_printer.cpp --template=file_printer.tpl $(TESTS)
+
+aborter.cpp: aborter.tpl $(TESTS)
+ $(TESTGEN) -o aborter.cpp --template=aborter.tpl $(TESTS)
+
+only.cpp: only.tpl $(TESTS)
+ $(TESTGEN) -o only.cpp --template=only.tpl $(TESTS)
+
+tests.cpp: $(TESTS)
+ $(TESTGEN) -o tests.cpp $(TESTS)
+
+win32_runner.cpp: $(GUI_TESTS)
+ $(TESTGEN) -o win32_runner.cpp --gui=Win32Gui $(GUI_TESTS)
+
+qt_runner.cpp: $(GUI_TESTS)
+ $(TESTGEN) -o qt_runner.cpp --gui=QtGui $(GUI_TESTS)
+
+error_printer.exe: error_printer.cpp
+ $(CXXC) -eerror_printer.exe error_printer.cpp
+
+stdio_printer.exe: stdio_printer.cpp
+ $(CXXC) -estdio_printer.exe stdio_printer.cpp
+
+file_printer.exe: file_printer.cpp
+ $(CXXC) -efile_printer.exe file_printer.cpp
+
+only.exe: only.cpp
+ $(CXXC) -eonly.exe only.cpp
+
+aborter.exe: aborter.cpp
+ $(CXXC) -eaborter.exe aborter.cpp
+
+yes_no_runner.exe: yes_no_runner.cpp tests.cpp
+ $(CXXC) -eyes_no_runner.exe yes_no_runner.cpp tests.cpp
+
+win32_runner.exe: win32_runner.cpp
+ $(CXXC) -ewin32_runner.exe win32_runner.cpp $(WIN32_FLAGS)
+
+qt_runner.exe: qt_runner.cpp
+ $(CXXC) -o qt_runner.exe qt_runner.cpp $(QT_FLAGS)
+
+#
+# Local Variables:
+# compile-command: "make -fMakefile.bcc32"
+# End:
+#
diff --git a/test/cxxtest/sample/Makefile.msvc b/test/cxxtest/sample/Makefile.msvc
new file mode 100644
index 0000000000..35ce2f9b17
--- /dev/null
+++ b/test/cxxtest/sample/Makefile.msvc
@@ -0,0 +1,93 @@
+#
+# Makefile for Microsoft Visual C++
+# Make sure cl.exe is in the PATH (run vcvars.bat) or change CXXC below
+#
+
+# For the Win32 GUI
+WIN32_FLAGS = user32.lib
+
+# For the Qt GUI
+# QTDIR = c:\qt
+QT_FLAGS = -I$(QTDIR)/include $(QTDIR)/lib/qt.lib
+
+TARGETS = error_printer.exe stdio_printer.exe yes_no_runner.exe file_printer.exe aborter.exe only.exe
+GUI_TARGETS = win32_runner.exe qt_runner.exe
+TESTS = *.h
+GUI_TESTS = gui/GreenYellowRed.h $(TESTS)
+TESTGEN = perl -w ../cxxtestgen.pl
+CXXC = cl.exe -GX -W3 -WX -I. -I..
+
+all: $(TARGETS)
+
+clean:
+ del *~ *.o *.obj
+ del $(TARGETS)
+ del $(GUI_TARGETS)
+ del tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp
+ del win32_runner.cpp qt_runner.cpp
+
+distclean: clean
+ del Makefile
+
+run: error_printer.exe
+ error_printer.exe
+
+run_win32: win32_runner.exe
+ win32_runner.exe
+
+run_qt: qt_runner.exe
+ qt_runner.exe
+
+error_printer.cpp: $(TESTS)
+ $(TESTGEN) -o error_printer.cpp --error-printer $(TESTS)
+
+stdio_printer.cpp: $(TESTS)
+ $(TESTGEN) -o stdio_printer.cpp --runner=StdioPrinter $(TESTS)
+
+file_printer.cpp: file_printer.tpl $(TESTS)
+ $(TESTGEN) -o file_printer.cpp --template=file_printer.tpl $(TESTS)
+
+aborter.cpp: aborter.tpl $(TESTS)
+ $(TESTGEN) -o aborter.cpp --template=aborter.tpl $(TESTS)
+
+only.cpp: only.tpl $(TESTS)
+ $(TESTGEN) -o only.cpp --template=only.tpl $(TESTS)
+
+tests.cpp: $(TESTS)
+ $(TESTGEN) -o tests.cpp $(TESTS)
+
+win32_runner.cpp: $(GUI_TESTS)
+ $(TESTGEN) -o win32_runner.cpp --gui=Win32Gui $(GUI_TESTS)
+
+qt_runner.cpp: $(GUI_TESTS)
+ $(TESTGEN) -o qt_runner.cpp --gui=QtGui $(GUI_TESTS)
+
+error_printer.exe: error_printer.cpp
+ $(CXXC) -o error_printer.exe error_printer.cpp
+
+stdio_printer.exe: stdio_printer.cpp
+ $(CXXC) -o stdio_printer.exe stdio_printer.cpp
+
+file_printer.exe: file_printer.cpp
+ $(CXXC) -o file_printer.exe file_printer.cpp
+
+only.exe: only.cpp
+ $(CXXC) -o only.exe only.cpp
+
+aborter.exe: aborter.cpp
+ $(CXXC) -o aborter.exe aborter.cpp
+
+yes_no_runner.exe: yes_no_runner.cpp tests.cpp
+ $(CXXC) -o yes_no_runner.exe yes_no_runner.cpp tests.cpp
+
+win32_runner.exe: win32_runner.cpp
+ $(CXXC) -o win32_runner.exe win32_runner.cpp $(WIN32_FLAGS)
+
+qt_runner.exe: qt_runner.cpp
+ $(CXXC) -o qt_runner.exe qt_runner.cpp $(QT_FLAGS)
+
+#
+# Local Variables:
+# compile-command: "nmake -fMakefile.msvc"
+# End:
+#
diff --git a/test/cxxtest/sample/Makefile.unix b/test/cxxtest/sample/Makefile.unix
new file mode 100644
index 0000000000..ee52c8f77a
--- /dev/null
+++ b/test/cxxtest/sample/Makefile.unix
@@ -0,0 +1,88 @@
+#
+# Makefile for UN*X-like systems
+#
+
+# Change this line if you want a different compiler
+CXXC = c++ -Wall -W -Werror -I. -I..
+
+# If you want to use python, specify USE_PYTHON=1 on the command line
+ifdef USE_PYTHON
+ TESTGEN = ../cxxtestgen.py
+else
+ TESTGEN = ../cxxtestgen.pl
+endif
+
+# For the X11 GUI
+X11_FLAGS = -I/usr/X11R6/include -L/usr/X11R6/lib -lX11
+
+# For the Qt GUI
+#QTDIR = /usr/lib/qt
+QTLIB = -lqt-mt
+#QTLIB = -lqt
+QT_FLAGS = -I$(QTDIR)/include -L$(QTDIR)/lib $(QTLIB) -O2
+
+TARGETS = error_printer stdio_printer yes_no_runner file_printer aborter only
+GUI_TARGETS = x11_runner qt_runner
+TESTS = *.h
+GUI_TESTS = gui/GreenYellowRed.h $(TESTS)
+
+all: $(TARGETS)
+
+clean:
+ rm -f *~ *.o *.obj $(TARGETS) $(GUI_TARGETS)
+ rm -f tests.cpp error_printer.cpp stdio_printer.cpp file_printer.cpp aborter.cpp only.cpp
+ rm -f x11_runner.cpp qt_runner.cpp
+
+distclean: clean
+ rm -f Makefile
+
+run: error_printer
+ ./error_printer
+
+run_x11: x11_runner
+ ./x11_runner
+
+run_qt: qt_runner
+ ./qt_runner
+
+error_printer.cpp: $(TESTS)
+ $(TESTGEN) -o $@ --error-printer $(TESTS)
+
+stdio_printer.cpp: $(TESTS)
+ $(TESTGEN) -o $@ --runner=StdioPrinter $(TESTS)
+
+file_printer.cpp: file_printer.tpl $(TESTS)
+ $(TESTGEN) -o $@ --template=file_printer.tpl $(TESTS)
+
+aborter.cpp: aborter.tpl $(TESTS)
+ $(TESTGEN) -o $@ --template=aborter.tpl $(TESTS)
+
+only.cpp: only.tpl $(TESTS)
+ $(TESTGEN) -o $@ --template=only.tpl $(TESTS)
+
+tests.cpp: $(TESTS)
+ $(TESTGEN) -o $@ $(TESTS)
+
+x11_runner.cpp: $(GUI_TESTS)
+ $(TESTGEN) -o $@ --gui=X11Gui $(GUI_TESTS)
+
+qt_runner.cpp: $(GUI_TESTS)
+ $(TESTGEN) -o $@ --gui=QtGui $(GUI_TESTS)
+
+%: %.cpp
+ $(CXXC) -o $@ $<
+
+yes_no_runner: yes_no_runner.cpp tests.cpp
+ $(CXXC) -o $@ $^
+
+x11_runner: x11_runner.cpp
+ $(CXXC) -o $@ $^ $(X11_FLAGS)
+
+qt_runner: qt_runner.cpp
+ $(CXXC) -o $@ $^ $(QT_FLAGS)
+
+#
+# Local Variables:
+# compile-command: "make -fMakefile.unix"
+# End:
+#
diff --git a/test/cxxtest/sample/MessageTest.h b/test/cxxtest/sample/MessageTest.h
new file mode 100644
index 0000000000..621289f78d
--- /dev/null
+++ b/test/cxxtest/sample/MessageTest.h
@@ -0,0 +1,30 @@
+#ifndef __MESSAGETEST_H
+#define __MESSAGETEST_H
+
+#include
+
+//
+// The [E]TSM_ macros can be used to print a specified message
+// instead of the default one.
+// This is useful when you refactor your tests, as shown below
+//
+
+class MessageTest : public CxxTest::TestSuite
+{
+public:
+ void testValues()
+ {
+ checkValue( 0, "My hovercraft" );
+ checkValue( 1, "is full" );
+ checkValue( 2, "of eels" );
+ }
+
+ void checkValue( unsigned value, const char *message )
+ {
+ TSM_ASSERT( message, value != 0 );
+ TSM_ASSERT_EQUALS( message, value, value * value );
+ }
+};
+
+
+#endif // __MESSAGETEST_H
diff --git a/test/cxxtest/sample/SimpleTest.h b/test/cxxtest/sample/SimpleTest.h
new file mode 100644
index 0000000000..b3fae12cad
--- /dev/null
+++ b/test/cxxtest/sample/SimpleTest.h
@@ -0,0 +1,59 @@
+#ifndef __SIMPLETEST_H
+#define __SIMPLETEST_H
+
+#include
+
+//
+// A simple test suite: Just inherit CxxTest::TestSuite and write tests!
+//
+
+class SimpleTest : public CxxTest::TestSuite
+{
+public:
+ void testEquality()
+ {
+ TS_ASSERT_EQUALS( 1, 1 );
+ TS_ASSERT_EQUALS( 1, 2 );
+ TS_ASSERT_EQUALS( 'a', 'A' );
+ TS_ASSERT_EQUALS( 1.0, -12345678900000000000000000000000000000000000000000.1234 );
+ }
+
+ void testAddition()
+ {
+ TS_ASSERT_EQUALS( 1 + 1, 2 );
+ TS_ASSERT_EQUALS( 2 + 2, 5 );
+ }
+
+ void TestMultiplication()
+ {
+ TS_ASSERT_EQUALS( 2 * 2, 4 );
+ TS_ASSERT_EQUALS( 4 * 4, 44 );
+ TS_ASSERT_DIFFERS( -2 * -2, 4 );
+ }
+
+ void testComparison()
+ {
+ TS_ASSERT_LESS_THAN( (int)1, (unsigned long)2 );
+ TS_ASSERT_LESS_THAN( -1, -2 );
+ }
+
+ void testTheWorldIsCrazy()
+ {
+ TS_ASSERT_EQUALS( true, false );
+ }
+
+ void test_Failure()
+ {
+ TS_FAIL( "Not implemented" );
+ TS_FAIL( 1569779912 );
+ }
+
+ void test_TS_WARN_macro()
+ {
+ TS_WARN( "Just a friendly warning" );
+ TS_WARN( "Warnings don't abort the test" );
+ }
+};
+
+
+#endif // __SIMPLETEST_H
diff --git a/test/cxxtest/sample/TraitsTest.h b/test/cxxtest/sample/TraitsTest.h
new file mode 100644
index 0000000000..14659385d0
--- /dev/null
+++ b/test/cxxtest/sample/TraitsTest.h
@@ -0,0 +1,69 @@
+#ifndef __TRAITSTEST_H
+#define __TRAITSTEST_H
+
+//
+// This example shows how to use TS_ASSERT_EQUALS for your own classes
+//
+#include
+#include
+
+//
+// Define your class with operator==
+//
+#include
+#include
+
+class Pet
+{
+ char _name[128];
+public:
+ Pet( const char *petName ) { strcpy( _name, petName ); }
+
+ const char *name() const { return _name; }
+
+ bool operator== ( const Pet &other ) const
+ {
+ return !strcmp( name(), other.name() );
+ }
+};
+
+//
+// Instantiate CxxTest::ValueTraits<*your class*>
+// Note: Most compilers do not require that you define both
+// ValueTraits and ValueTraits, but some do.
+//
+namespace CxxTest
+{
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits
+ {
+ char _asString[256];
+
+ public:
+ ValueTraits( const Pet &pet ) { sprintf( _asString, "Pet(\"%s\")", pet.name() ); }
+ const char *asString() const { return _asString; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( Pet );
+}
+
+//
+// Here's how it works
+//
+class TestFunky : public CxxTest::TestSuite
+{
+public:
+ void testPets()
+ {
+ Pet pet1("dog"), pet2("cat");
+ TS_ASSERT_EQUALS( pet1, pet2 );
+ Pet cat("cat"), gato("cat");
+ TS_ASSERT_DIFFERS( cat, gato );
+#ifdef _CXXTEST_HAVE_STD
+ typedef CXXTEST_STD(string) String;
+ TS_ASSERT_EQUALS( String("Hello"), String("World!") );
+#endif // _CXXTEST_HAVE_STD
+ }
+};
+
+#endif // __TRAITSTEST_H
diff --git a/test/cxxtest/sample/aborter.tpl b/test/cxxtest/sample/aborter.tpl
new file mode 100644
index 0000000000..14fc50d2c7
--- /dev/null
+++ b/test/cxxtest/sample/aborter.tpl
@@ -0,0 +1,16 @@
+// -*- C++ -*-
+// This template file demonstrates the use of CXXTEST_ABORT_TEST_ON_FAIL
+//
+
+#define CXXTEST_HAVE_STD
+#define CXXTEST_ABORT_TEST_ON_FAIL
+#include
+
+int main()
+{
+ return CxxTest::ErrorPrinter().run();
+}
+
+// The CxxTest "world"
+
+
diff --git a/test/cxxtest/sample/file_printer.tpl b/test/cxxtest/sample/file_printer.tpl
new file mode 100644
index 0000000000..a9627d6d0d
--- /dev/null
+++ b/test/cxxtest/sample/file_printer.tpl
@@ -0,0 +1,22 @@
+// -*- C++ -*-
+// This is a sample of a custom test runner
+// using CxxTest template files.
+// This prints the output to a file given on the command line.
+//
+
+#include
+#include
+
+int main( int argc, char *argv[] )
+{
+ if ( argc != 2 ) {
+ fprintf( stderr, "Usage: %s