aboutsummaryrefslogtreecommitdiff
path: root/test/cxxtest
diff options
context:
space:
mode:
Diffstat (limited to 'test/cxxtest')
-rw-r--r--test/cxxtest/COPYING504
-rw-r--r--test/cxxtest/README63
-rw-r--r--test/cxxtest/TODO34
-rw-r--r--test/cxxtest/Versions152
-rw-r--r--test/cxxtest/cxxtest.spec40
-rw-r--r--test/cxxtest/cxxtest/Descriptions.cpp58
-rw-r--r--test/cxxtest/cxxtest/Descriptions.h74
-rw-r--r--test/cxxtest/cxxtest/DummyDescriptions.cpp49
-rw-r--r--test/cxxtest/cxxtest/DummyDescriptions.h76
-rw-r--r--test/cxxtest/cxxtest/ErrorFormatter.h281
-rw-r--r--test/cxxtest/cxxtest/ErrorPrinter.h55
-rw-r--r--test/cxxtest/cxxtest/Flags.h121
-rw-r--r--test/cxxtest/cxxtest/GlobalFixture.cpp23
-rw-r--r--test/cxxtest/cxxtest/GlobalFixture.h30
-rw-r--r--test/cxxtest/cxxtest/Gui.h178
-rw-r--r--test/cxxtest/cxxtest/LinkedList.cpp172
-rw-r--r--test/cxxtest/cxxtest/LinkedList.h65
-rw-r--r--test/cxxtest/cxxtest/Mock.h350
-rw-r--r--test/cxxtest/cxxtest/ParenPrinter.h21
-rw-r--r--test/cxxtest/cxxtest/QtGui.h271
-rw-r--r--test/cxxtest/cxxtest/RealDescriptions.cpp311
-rw-r--r--test/cxxtest/cxxtest/RealDescriptions.h223
-rw-r--r--test/cxxtest/cxxtest/Root.cpp18
-rw-r--r--test/cxxtest/cxxtest/SelfTest.h7
-rw-r--r--test/cxxtest/cxxtest/StdHeaders.h25
-rw-r--r--test/cxxtest/cxxtest/StdValueTraits.h229
-rw-r--r--test/cxxtest/cxxtest/StdioFilePrinter.h41
-rw-r--r--test/cxxtest/cxxtest/StdioPrinter.h22
-rw-r--r--test/cxxtest/cxxtest/TeeListener.h182
-rw-r--r--test/cxxtest/cxxtest/TestListener.h70
-rw-r--r--test/cxxtest/cxxtest/TestRunner.h125
-rw-r--r--test/cxxtest/cxxtest/TestSuite.cpp138
-rw-r--r--test/cxxtest/cxxtest/TestSuite.h512
-rw-r--r--test/cxxtest/cxxtest/TestTracker.cpp248
-rw-r--r--test/cxxtest/cxxtest/TestTracker.h114
-rw-r--r--test/cxxtest/cxxtest/ValueTraits.cpp140
-rw-r--r--test/cxxtest/cxxtest/ValueTraits.h377
-rw-r--r--test/cxxtest/cxxtest/Win32Gui.h531
-rw-r--r--test/cxxtest/cxxtest/X11Gui.h327
-rw-r--r--test/cxxtest/cxxtest/YesNoRunner.h29
-rwxr-xr-xtest/cxxtest/cxxtestgen.pl551
-rwxr-xr-xtest/cxxtest/cxxtestgen.py593
-rw-r--r--test/cxxtest/docs/convert.pl83
-rw-r--r--test/cxxtest/docs/guide.html1960
-rw-r--r--test/cxxtest/docs/index.html56
-rw-r--r--test/cxxtest/docs/qt.pngbin0 -> 13630 bytes
-rw-r--r--test/cxxtest/docs/qt2.pngbin0 -> 11684 bytes
-rw-r--r--test/cxxtest/docs/win32.pngbin0 -> 1709 bytes
-rw-r--r--test/cxxtest/docs/x11.pngbin0 -> 1342 bytes
-rw-r--r--test/cxxtest/sample/Construct64
-rw-r--r--test/cxxtest/sample/CreatedTest.h31
-rw-r--r--test/cxxtest/sample/DeltaTest.h27
-rw-r--r--test/cxxtest/sample/EnumTraits.h39
-rw-r--r--test/cxxtest/sample/ExceptionTest.h52
-rw-r--r--test/cxxtest/sample/FixtureTest.h37
-rwxr-xr-xtest/cxxtest/sample/Makefile.PL32
-rw-r--r--test/cxxtest/sample/Makefile.bcc3294
-rw-r--r--test/cxxtest/sample/Makefile.msvc93
-rw-r--r--test/cxxtest/sample/Makefile.unix88
-rw-r--r--test/cxxtest/sample/MessageTest.h30
-rw-r--r--test/cxxtest/sample/SimpleTest.h59
-rw-r--r--test/cxxtest/sample/TraitsTest.h69
-rw-r--r--test/cxxtest/sample/aborter.tpl16
-rw-r--r--test/cxxtest/sample/file_printer.tpl22
-rw-r--r--test/cxxtest/sample/gui/GreenYellowRed.h57
-rw-r--r--test/cxxtest/sample/mock/Dice.cpp14
-rw-r--r--test/cxxtest/sample/mock/Dice.h13
-rw-r--r--test/cxxtest/sample/mock/Makefile22
-rw-r--r--test/cxxtest/sample/mock/MockStdlib.h31
-rw-r--r--test/cxxtest/sample/mock/T/stdlib.h13
-rw-r--r--test/cxxtest/sample/mock/TestDice.h62
-rw-r--r--test/cxxtest/sample/mock/mock_stdlib.cpp2
-rw-r--r--test/cxxtest/sample/mock/real_stdlib.cpp2
-rw-r--r--test/cxxtest/sample/mock/roll.cpp11
-rw-r--r--test/cxxtest/sample/msvc/CxxTest_1_Run.dsp93
-rw-r--r--test/cxxtest/sample/msvc/CxxTest_2_Build.dsp94
-rw-r--r--test/cxxtest/sample/msvc/CxxTest_3_Generate.dsp93
-rw-r--r--test/cxxtest/sample/msvc/CxxTest_Workspace.dsw59
-rw-r--r--test/cxxtest/sample/msvc/FixFiles.bat212
-rw-r--r--test/cxxtest/sample/msvc/Makefile36
-rw-r--r--test/cxxtest/sample/msvc/ReadMe.txt30
-rw-r--r--test/cxxtest/sample/only.tpl33
-rw-r--r--test/cxxtest/sample/parts/Makefile.unix39
-rw-r--r--test/cxxtest/sample/winddk/Makefile2
-rw-r--r--test/cxxtest/sample/winddk/Makefile.inc15
-rw-r--r--test/cxxtest/sample/winddk/RunTests.tpl13
-rw-r--r--test/cxxtest/sample/winddk/SOURCES46
-rw-r--r--test/cxxtest/sample/yes_no_runner.cpp11
88 files changed, 11285 insertions, 0 deletions
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.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.
+
+ <signature of Ty Coon>, 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 <cxxtest/TestSuite.h>
+
+ 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 <cxxtest/ErrorPrinter.h>
+
+ 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 <cxxtest/Descriptions.h>
+
+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 <cxxtest/LinkedList.h>
+
+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 <cxxtest/DummyDescriptions.h>
+
+namespace CxxTest
+{
+ DummyTestDescription::DummyTestDescription() {}
+
+ const char *DummyTestDescription::file() const { return "<no file>"; }
+ unsigned DummyTestDescription::line() const { return 0; }
+ const char *DummyTestDescription::testName() const { return "<no test>"; }
+ const char *DummyTestDescription::suiteName() const { return "<no suite>"; }
+ 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 "<no file>"; }
+ unsigned DummySuiteDescription::line() const { return 0; }
+ const char *DummySuiteDescription::suiteName() const { return "<no suite>"; }
+ 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 <cxxtest/Descriptions.h>
+
+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 <cxxtest/TestRunner.h>
+#include <cxxtest/TestListener.h>
+#include <cxxtest/TestTracker.h>
+#include <cxxtest/ValueTraits.h>
+
+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 <cxxtest/Flags.h>
+
+#ifndef _CXXTEST_HAVE_STD
+# define _CXXTEST_HAVE_STD
+#endif // _CXXTEST_HAVE_STD
+
+#include <cxxtest/ErrorFormatter.h>
+#include <cxxtest/StdValueTraits.h>
+
+#ifdef _CXXTEST_OLD_STD
+# include <iostream.h>
+#else // !_CXXTEST_OLD_STD
+# include <iostream>
+#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 <cxxtest/GlobalFixture.h>
+
+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 <cxxtest/LinkedList.h>
+
+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<GuiT, TuiT> combines a GUI with a text-mode error formatter
+//
+
+#include <cxxtest/TeeListener.h>
+
+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 GuiT, class TuiT>
+ 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 <cxxtest/LinkedList.h>
+
+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 <cxxtest/Flags.h>
+
+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 T> \
+ 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 &current(); \
+ \
+ 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 &current(); \
+ \
+ 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<TYPE>::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<TYPE>::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/TestSuite.h>
+
+__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/TestSuite.h>
+
+__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<TYPE> \
+ { \
+ 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 <cxxtest/ErrorPrinter.h>
+
+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 <cxxtest/Gui.h>
+
+#include <qapplication.h>
+#include <qglobal.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qmessagebox.h>
+#include <qpixmap.h>
+#include <qprogressbar.h>
+#include <qstatusbar.h>
+
+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 <cxxtest/RealDescriptions.h>
+
+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 <cxxtest/Descriptions.h>
+#include <cxxtest/TestSuite.h>
+#include <cxxtest/GlobalFixture.h>
+
+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 S>
+ 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<class S>
+ bool DynamicSuiteDescription<S>::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<class S>
+ bool DynamicSuiteDescription<S>::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 <cxxtest/Descriptions.cpp>
+#include <cxxtest/DummyDescriptions.cpp>
+#include <cxxtest/GlobalFixture.cpp>
+#include <cxxtest/LinkedList.cpp>
+#include <cxxtest/RealDescriptions.cpp>
+#include <cxxtest/TestSuite.cpp>
+#include <cxxtest/TestTracker.cpp>
+#include <cxxtest/ValueTraits.cpp>
+
+#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 <complex>
+#include <deque>
+#include <list>
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+#ifdef _MSC_VER
+# pragma warning( pop )
+#endif // _MSC_VER
+
+#endif // __cxxtest_StdHeaders_h__
diff --git a/test/cxxtest/cxxtest/StdValueTraits.h b/test/cxxtest/cxxtest/StdValueTraits.h
new file mode 100644
index 0000000000..036796b0df
--- /dev/null
+++ b/test/cxxtest/cxxtest/StdValueTraits.h
@@ -0,0 +1,229 @@
+#ifndef __cxxtest_StdValueTraits_h__
+#define __cxxtest_StdValueTraits_h__
+
+//
+// This file defines ValueTraits for std:: stuff.
+// It is #included by <cxxtest/ValueTraits.h> if you
+// define CXXTEST_HAVE_STD
+//
+
+#include <cxxtest/ValueTraits.h>
+#include <cxxtest/StdHeaders.h>
+
+#ifdef _CXXTEST_OLD_STD
+# define CXXTEST_STD(x) x
+#else // !_CXXTEST_OLD_STD
+# define CXXTEST_STD(x) std::x
+#endif // _CXXTEST_OLD_STD
+
+#ifndef CXXTEST_USER_VALUE_TRAITS
+
+namespace CxxTest
+{
+ //
+ // NOTE: This should have been
+ // template<class Char, class Traits, class Allocator>
+ // class ValueTraits< std::basic_string<Char, Traits, Allocator> > {};
+ // But MSVC doesn't support it (yet).
+ //
+
+ //
+ // If we have std::string, we might as well use it
+ //
+ class StdTraitsBase
+ {
+ public:
+ StdTraitsBase &operator<<( const CXXTEST_STD(string) &s ) { _s += s; return *this; }
+ const char *asString() const { return _s.c_str(); }
+
+ private:
+ CXXTEST_STD(string) _s;
+ };
+
+ //
+ // std::string
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const CXXTEST_STD(string)> : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(string) &s )
+ {
+ *this << "\"";
+ for ( unsigned i = 0; i < s.length(); ++ i ) {
+ char c[sizeof("\\xXX")];
+ charToString( s[i], c );
+ *this << c;
+ }
+ *this << "\"";
+ }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( CXXTEST_STD(string) );
+
+#ifndef _CXXTEST_OLD_STD
+ //
+ // std::wstring
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const CXXTEST_STD(basic_string<wchar_t>)> : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(basic_string<wchar_t>) &s )
+ {
+ *this << "L\"";
+ for ( unsigned i = 0; i < s.length(); ++ i ) {
+ char c[sizeof("\\x12345678")];
+ charToString( (unsigned long)s[i], c );
+ *this << c;
+ }
+ *this << "\"";
+ }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( CXXTEST_STD(basic_string<wchar_t>) );
+#endif // _CXXTEST_OLD_STD
+
+ //
+ // Convert a range defined by iterators to a string
+ // This is useful for almost all STL containers
+ //
+ template<class Stream, class Iterator>
+ void dumpRange( Stream &s, Iterator first, Iterator last )
+ {
+ s << "{ ";
+ while ( first != last ) {
+ s << TS_AS_STRING(*first);
+ ++ first;
+ s << ((first == last) ? " }" : ", ");
+ }
+ }
+
+#ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+ //
+ // std::pair
+ //
+ template<class First, class Second>
+ class ValueTraits< CXXTEST_STD(pair)<First, Second> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(pair)<First, Second> &p )
+ {
+ *this << "<" << TS_AS_STRING( p.first ) << ", " << TS_AS_STRING( p.second ) << ">";
+ }
+ };
+
+ //
+ // std::vector
+ //
+ template<class Element>
+ class ValueTraits< CXXTEST_STD(vector)<Element> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(vector)<Element> &v )
+ {
+ dumpRange( *this, v.begin(), v.end() );
+ }
+ };
+
+ //
+ // std::list
+ //
+ template<class Element>
+ class ValueTraits< CXXTEST_STD(list)<Element> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(list)<Element> &l )
+ {
+ dumpRange( *this, l.begin(), l.end() );
+ }
+ };
+
+ //
+ // std::set
+ //
+ template<class Element>
+ class ValueTraits< CXXTEST_STD(set)<Element> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(set)<Element> &s )
+ {
+ dumpRange( *this, s.begin(), s.end() );
+ }
+ };
+
+ //
+ // std::map
+ //
+ template<class Key, class Value>
+ class ValueTraits< CXXTEST_STD(map)<Key, Value> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(map)<Key, Value> &m )
+ {
+ dumpRange( *this, m.begin(), m.end() );
+ }
+ };
+
+ //
+ // std::deque
+ //
+ template<class Element>
+ class ValueTraits< CXXTEST_STD(deque)<Element> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(deque)<Element> &d )
+ {
+ dumpRange( *this, d.begin(), d.end() );
+ }
+ };
+
+ //
+ // std::multiset
+ //
+ template<class Element>
+ class ValueTraits< CXXTEST_STD(multiset)<Element> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(multiset)<Element> &ms )
+ {
+ dumpRange( *this, ms.begin(), ms.end() );
+ }
+ };
+
+ //
+ // std::multimap
+ //
+ template<class Key, class Value>
+ class ValueTraits< CXXTEST_STD(multimap)<Key, Value> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(multimap)<Key, Value> &mm )
+ {
+ dumpRange( *this, mm.begin(), mm.end() );
+ }
+ };
+
+ //
+ // std::complex
+ //
+ template<class Number>
+ class ValueTraits< CXXTEST_STD(complex)<Number> > : public StdTraitsBase
+ {
+ public:
+ ValueTraits( const CXXTEST_STD(complex)<Number> &c )
+ {
+ if ( !c.imag() )
+ *this << TS_AS_STRING(c.real());
+ else if ( !c.real() )
+ *this << "(" << TS_AS_STRING(c.imag()) << " * i)";
+ else
+ *this << "(" << TS_AS_STRING(c.real()) << " + " << TS_AS_STRING(c.imag()) << " * i)";
+ }
+ };
+#endif // _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
+};
+
+#endif // CXXTEST_USER_VALUE_TRAITS
+
+#endif // __cxxtest_StdValueTraits_h__
diff --git a/test/cxxtest/cxxtest/StdioFilePrinter.h b/test/cxxtest/cxxtest/StdioFilePrinter.h
new file mode 100644
index 0000000000..47984b69b9
--- /dev/null
+++ b/test/cxxtest/cxxtest/StdioFilePrinter.h
@@ -0,0 +1,41 @@
+#ifndef __cxxtest__StdioFilePrinter_h__
+#define __cxxtest__StdioFilePrinter_h__
+
+//
+// The StdioFilePrinter is a simple TestListener that
+// just prints "OK" if everything goes well, otherwise
+// reports the error in the format of compiler messages.
+// This class uses <stdio.h>, i.e. FILE * and fprintf().
+//
+
+#include <cxxtest/ErrorFormatter.h>
+#include <stdio.h>
+
+namespace CxxTest
+{
+ class StdioFilePrinter : public ErrorFormatter
+ {
+ public:
+ StdioFilePrinter( FILE *o, const char *preLine = ":", const char *postLine = "" ) :
+ ErrorFormatter( new Adapter(o), preLine, postLine ) {}
+ virtual ~StdioFilePrinter() { delete outputStream(); }
+
+ private:
+ class Adapter : public OutputStream
+ {
+ Adapter( const Adapter & );
+ Adapter &operator=( const Adapter & );
+
+ FILE *_o;
+
+ public:
+ Adapter( FILE *o ) : _o(o) {}
+ void flush() { fflush( _o ); }
+ OutputStream &operator<<( unsigned i ) { fprintf( _o, "%u", i ); return *this; }
+ OutputStream &operator<<( const char *s ) { fputs( s, _o ); return *this; }
+ OutputStream &operator<<( Manipulator m ) { return OutputStream::operator<<( m ); }
+ };
+ };
+}
+
+#endif // __cxxtest__StdioFilePrinter_h__
diff --git a/test/cxxtest/cxxtest/StdioPrinter.h b/test/cxxtest/cxxtest/StdioPrinter.h
new file mode 100644
index 0000000000..af5bc6b639
--- /dev/null
+++ b/test/cxxtest/cxxtest/StdioPrinter.h
@@ -0,0 +1,22 @@
+#ifndef __cxxtest__StdioPrinter_h__
+#define __cxxtest__StdioPrinter_h__
+
+//
+// The StdioPrinter is an StdioFilePrinter which defaults to stdout.
+// This should have been called StdOutPrinter or something, but the name
+// has been historically used.
+//
+
+#include <cxxtest/StdioFilePrinter.h>
+
+namespace CxxTest
+{
+ class StdioPrinter : public StdioFilePrinter
+ {
+ public:
+ StdioPrinter( FILE *o = stdout, const char *preLine = ":", const char *postLine = "" ) :
+ StdioFilePrinter( o, preLine, postLine ) {}
+ };
+}
+
+#endif // __cxxtest__StdioPrinter_h__
diff --git a/test/cxxtest/cxxtest/TeeListener.h b/test/cxxtest/cxxtest/TeeListener.h
new file mode 100644
index 0000000000..88afdd3ed6
--- /dev/null
+++ b/test/cxxtest/cxxtest/TeeListener.h
@@ -0,0 +1,182 @@
+#ifndef __cxxtest__TeeListener_h__
+#define __cxxtest__TeeListener_h__
+
+//
+// A TeeListener notifies two "reular" TestListeners
+//
+
+#include <cxxtest/TestListener.h>
+#include <cxxtest/TestListener.h>
+
+namespace CxxTest
+{
+ class TeeListener : public TestListener
+ {
+ public:
+ TeeListener()
+ {
+ setFirst( _dummy );
+ setSecond( _dummy );
+ }
+
+ virtual ~TeeListener()
+ {
+ }
+
+ void setFirst( TestListener &first )
+ {
+ _first = &first;
+ }
+
+ void setSecond( TestListener &second )
+ {
+ _second = &second;
+ }
+
+ void enterWorld( const WorldDescription &d )
+ {
+ _first->enterWorld( d );
+ _second->enterWorld( d );
+ }
+
+ void enterSuite( const SuiteDescription &d )
+ {
+ _first->enterSuite( d );
+ _second->enterSuite( d );
+ }
+
+ void enterTest( const TestDescription &d )
+ {
+ _first->enterTest( d );
+ _second->enterTest( d );
+ }
+
+ void trace( const char *file, unsigned line, const char *expression )
+ {
+ _first->trace( file, line, expression );
+ _second->trace( file, line, expression );
+ }
+
+ void warning( const char *file, unsigned line, const char *expression )
+ {
+ _first->warning( file, line, expression );
+ _second->warning( file, line, expression );
+ }
+
+ void failedTest( const char *file, unsigned line, const char *expression )
+ {
+ _first->failedTest( file, line, expression );
+ _second->failedTest( file, line, expression );
+ }
+
+ void failedAssert( const char *file, unsigned line, const char *expression )
+ {
+ _first->failedAssert( file, line, expression );
+ _second->failedAssert( file, line, expression );
+ }
+
+ void failedAssertEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ _first->failedAssertEquals( file, line, xStr, yStr, x, y );
+ _second->failedAssertEquals( file, line, xStr, yStr, x, y );
+ }
+
+ void failedAssertSameData( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *sizeStr, const void *x,
+ const void *y, unsigned size )
+ {
+ _first->failedAssertSameData( file, line, xStr, yStr, sizeStr, x, y, size );
+ _second->failedAssertSameData( file, line, xStr, yStr, sizeStr, x, 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 )
+ {
+ _first->failedAssertDelta( file, line, xStr, yStr, dStr, x, y, d );
+ _second->failedAssertDelta( file, line, xStr, yStr, dStr, x, y, d );
+ }
+
+ void failedAssertDiffers( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *value )
+ {
+ _first->failedAssertDiffers( file, line, xStr, yStr, value );
+ _second->failedAssertDiffers( file, line, xStr, yStr, value );
+ }
+
+ void failedAssertLessThan( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ _first->failedAssertLessThan( file, line, xStr, yStr, x, y );
+ _second->failedAssertLessThan( file, line, xStr, yStr, x, y );
+ }
+
+ void failedAssertLessThanEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ _first->failedAssertLessThanEquals( file, line, xStr, yStr, x, y );
+ _second->failedAssertLessThanEquals( file, line, xStr, yStr, x, y );
+ }
+
+ void failedAssertPredicate( const char *file, unsigned line,
+ const char *predicate, const char *xStr, const char *x )
+ {
+ _first->failedAssertPredicate( file, line, predicate, xStr, x );
+ _second->failedAssertPredicate( file, line, predicate, xStr, x );
+ }
+
+ void failedAssertRelation( const char *file, unsigned line,
+ const char *relation, const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ _first->failedAssertRelation( file, line, relation, xStr, yStr, x, y );
+ _second->failedAssertRelation( file, line, relation, xStr, yStr, x, y );
+ }
+
+ void failedAssertThrows( const char *file, unsigned line,
+ const char *expression, const char *type,
+ bool otherThrown )
+ {
+ _first->failedAssertThrows( file, line, expression, type, otherThrown );
+ _second->failedAssertThrows( file, line, expression, type, otherThrown );
+ }
+
+ void failedAssertThrowsNot( const char *file, unsigned line,
+ const char *expression )
+ {
+ _first->failedAssertThrowsNot( file, line, expression );
+ _second->failedAssertThrowsNot( file, line, expression );
+ }
+
+ void leaveTest( const TestDescription &d )
+ {
+ _first->leaveTest(d);
+ _second->leaveTest(d);
+ }
+
+ void leaveSuite( const SuiteDescription &d )
+ {
+ _first->leaveSuite(d);
+ _second->leaveSuite(d);
+ }
+
+ void leaveWorld( const WorldDescription &d )
+ {
+ _first->leaveWorld(d);
+ _second->leaveWorld(d);
+ }
+
+ private:
+ TestListener *_first, *_second;
+ TestListener _dummy;
+ };
+};
+
+
+#endif // __cxxtest__TeeListener_h__
diff --git a/test/cxxtest/cxxtest/TestListener.h b/test/cxxtest/cxxtest/TestListener.h
new file mode 100644
index 0000000000..0eeb5234ea
--- /dev/null
+++ b/test/cxxtest/cxxtest/TestListener.h
@@ -0,0 +1,70 @@
+#ifndef __cxxtest__TestListener_h__
+#define __cxxtest__TestListener_h__
+
+//
+// TestListener is the base class for all "listeners",
+// i.e. classes that receive notifications of the
+// testing process.
+//
+// The names of the parameters are in comments to avoid
+// "unused parameter" warnings.
+//
+
+#include <cxxtest/Descriptions.h>
+
+namespace CxxTest
+{
+ class TestListener
+ {
+ public:
+ TestListener() {}
+ virtual ~TestListener() {}
+
+ virtual void enterWorld( const WorldDescription & /*desc*/ ) {}
+ virtual void enterSuite( const SuiteDescription & /*desc*/ ) {}
+ virtual void enterTest( const TestDescription & /*desc*/ ) {}
+ virtual void trace( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/ ) {}
+ virtual void warning( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/ ) {}
+ virtual void failedTest( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/ ) {}
+ virtual void failedAssert( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/ ) {}
+ virtual void failedAssertEquals( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ ) {}
+ virtual void failedAssertSameData( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*sizeStr*/, const void * /*x*/,
+ const void * /*y*/, unsigned /*size*/ ) {}
+ virtual 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*/ ) {}
+ virtual void failedAssertDiffers( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*value*/ ) {}
+ virtual void failedAssertLessThan( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ ) {}
+ virtual void failedAssertLessThanEquals( const char * /*file*/, unsigned /*line*/,
+ const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ ) {}
+ virtual void failedAssertPredicate( const char * /*file*/, unsigned /*line*/,
+ const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/ ) {}
+ virtual void failedAssertRelation( const char * /*file*/, unsigned /*line*/,
+ const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/,
+ const char * /*x*/, const char * /*y*/ ) {}
+ virtual void failedAssertThrows( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/, const char * /*type*/,
+ bool /*otherThrown*/ ) {}
+ virtual void failedAssertThrowsNot( const char * /*file*/, unsigned /*line*/,
+ const char * /*expression*/ ) {}
+ virtual void leaveTest( const TestDescription & /*desc*/ ) {}
+ virtual void leaveSuite( const SuiteDescription & /*desc*/ ) {}
+ virtual void leaveWorld( const WorldDescription & /*desc*/ ) {}
+ };
+}
+
+#endif // __cxxtest__TestListener_h__
diff --git a/test/cxxtest/cxxtest/TestRunner.h b/test/cxxtest/cxxtest/TestRunner.h
new file mode 100644
index 0000000000..43f0832e2a
--- /dev/null
+++ b/test/cxxtest/cxxtest/TestRunner.h
@@ -0,0 +1,125 @@
+#ifndef __cxxtest_TestRunner_h__
+#define __cxxtest_TestRunner_h__
+
+//
+// TestRunner is the class that runs all the tests.
+// To use it, create an object that implements the TestListener
+// interface and call TestRunner::runAllTests( myListener );
+//
+
+#include <cxxtest/TestListener.h>
+#include <cxxtest/RealDescriptions.h>
+#include <cxxtest/TestSuite.h>
+#include <cxxtest/TestTracker.h>
+
+namespace CxxTest
+{
+ class TestRunner
+ {
+ public:
+ static void runAllTests( TestListener &listener )
+ {
+ tracker().setListener( &listener );
+ _TS_TRY { TestRunner().runWorld(); }
+ _TS_LAST_CATCH( { tracker().failedTest( __FILE__, __LINE__, "Exception thrown from world" ); } );
+ tracker().setListener( 0 );
+ }
+
+ static void runAllTests( TestListener *listener )
+ {
+ if ( listener ) {
+ listener->warning( __FILE__, __LINE__, "Deprecated; Use runAllTests( TestListener & )" );
+ runAllTests( *listener );
+ }
+ }
+
+ private:
+ void runWorld()
+ {
+ RealWorldDescription wd;
+ WorldGuard sg;
+
+ tracker().enterWorld( wd );
+ if ( wd.setUp() ) {
+ for ( SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() )
+ if ( sd->active() )
+ runSuite( *sd );
+
+ wd.tearDown();
+ }
+ tracker().leaveWorld( wd );
+ }
+
+ void runSuite( SuiteDescription &sd )
+ {
+ StateGuard sg;
+
+ tracker().enterSuite( sd );
+ if ( sd.setUp() ) {
+ for ( TestDescription *td = sd.firstTest(); td; td = td->next() )
+ if ( td->active() )
+ runTest( *td );
+
+ sd.tearDown();
+ }
+ tracker().leaveSuite( sd );
+ }
+
+ void runTest( TestDescription &td )
+ {
+ StateGuard sg;
+
+ tracker().enterTest( td );
+ if ( td.setUp() ) {
+ td.run();
+ td.tearDown();
+ }
+ tracker().leaveTest( td );
+ }
+
+ class StateGuard
+ {
+#ifdef _CXXTEST_HAVE_EH
+ bool _abortTestOnFail;
+#endif // _CXXTEST_HAVE_EH
+ unsigned _maxDumpSize;
+
+ public:
+ StateGuard()
+ {
+#ifdef _CXXTEST_HAVE_EH
+ _abortTestOnFail = abortTestOnFail();
+#endif // _CXXTEST_HAVE_EH
+ _maxDumpSize = maxDumpSize();
+ }
+
+ ~StateGuard()
+ {
+#ifdef _CXXTEST_HAVE_EH
+ setAbortTestOnFail( _abortTestOnFail );
+#endif // _CXXTEST_HAVE_EH
+ setMaxDumpSize( _maxDumpSize );
+ }
+ };
+
+ class WorldGuard : public StateGuard
+ {
+ public:
+ WorldGuard() : StateGuard()
+ {
+#ifdef _CXXTEST_HAVE_EH
+ setAbortTestOnFail( CXXTEST_DEFAULT_ABORT );
+#endif // _CXXTEST_HAVE_EH
+ setMaxDumpSize( CXXTEST_MAX_DUMP_SIZE );
+ }
+ };
+ };
+
+ //
+ // For --no-static-init
+ //
+ void initialize();
+};
+
+
+#endif // __cxxtest_TestRunner_h__
diff --git a/test/cxxtest/cxxtest/TestSuite.cpp b/test/cxxtest/cxxtest/TestSuite.cpp
new file mode 100644
index 0000000000..bc14c2cd87
--- /dev/null
+++ b/test/cxxtest/cxxtest/TestSuite.cpp
@@ -0,0 +1,138 @@
+#ifndef __cxxtest__TestSuite_cpp__
+#define __cxxtest__TestSuite_cpp__
+
+#include <cxxtest/TestSuite.h>
+
+namespace CxxTest
+{
+ //
+ // TestSuite members
+ //
+ TestSuite::~TestSuite() {}
+ void TestSuite::setUp() {}
+ void TestSuite::tearDown() {}
+
+ //
+ // Test-aborting stuff
+ //
+ static bool currentAbortTestOnFail = false;
+
+ bool abortTestOnFail()
+ {
+ return currentAbortTestOnFail;
+ }
+
+ void setAbortTestOnFail( bool value )
+ {
+ currentAbortTestOnFail = value;
+ }
+
+ void doAbortTest()
+ {
+# if defined(_CXXTEST_HAVE_EH)
+ if ( currentAbortTestOnFail )
+ throw AbortTest();
+# endif // _CXXTEST_HAVE_EH
+ }
+
+ //
+ // Max dump size
+ //
+ static unsigned currentMaxDumpSize = CXXTEST_MAX_DUMP_SIZE;
+
+ unsigned maxDumpSize()
+ {
+ return currentMaxDumpSize;
+ }
+
+ void setMaxDumpSize( unsigned value )
+ {
+ currentMaxDumpSize = value;
+ }
+
+ //
+ // Some non-template functions
+ //
+ void doTrace( const char *file, unsigned line, const char *message )
+ {
+ tracker().trace( file, line, message );
+ }
+
+ void doWarn( const char *file, unsigned line, const char *message )
+ {
+ tracker().warning( file, line, message );
+ }
+
+ void doFailTest( const char *file, unsigned line, const char *message )
+ {
+ tracker().failedTest( file, line, message );
+ TS_ABORT();
+ }
+
+ void doFailAssert( const char *file, unsigned line,
+ const char *expression, const char *message )
+ {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssert( file, line, expression );
+ TS_ABORT();
+ }
+
+ bool sameData( const void *x, const void *y, unsigned size )
+ {
+ if ( size == 0 )
+ return true;
+
+ if ( x == y )
+ return true;
+
+ if ( !x || !y )
+ return false;
+
+ const char *cx = (const char *)x;
+ const char *cy = (const char *)y;
+ while ( size -- )
+ if ( *cx++ != *cy++ )
+ return false;
+
+ return true;
+ }
+
+ void doAssertSameData( const char *file, unsigned line,
+ const char *xExpr, const void *x,
+ const char *yExpr, const void *y,
+ const char *sizeExpr, unsigned size,
+ const char *message )
+ {
+ if ( !sameData( x, y, size ) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssertSameData( file, line, xExpr, yExpr, sizeExpr, x, y, size );
+ TS_ABORT();
+ }
+ }
+
+ void doFailAssertThrows( const char *file, unsigned line,
+ const char *expr, const char *type,
+ bool otherThrown,
+ const char *message )
+ {
+ if ( message )
+ tracker().failedTest( file, line, message );
+
+ tracker().failedAssertThrows( file, line, expr, type, otherThrown );
+ TS_ABORT();
+ }
+
+ void doFailAssertThrowsNot( const char *file, unsigned line,
+ const char *expression, const char *message )
+ {
+ if ( message )
+ tracker().failedTest( file, line, message );
+
+ tracker().failedAssertThrowsNot( file, line, expression );
+ TS_ABORT();
+ }
+};
+
+#endif // __cxxtest__TestSuite_cpp__
diff --git a/test/cxxtest/cxxtest/TestSuite.h b/test/cxxtest/cxxtest/TestSuite.h
new file mode 100644
index 0000000000..fc5a206a7d
--- /dev/null
+++ b/test/cxxtest/cxxtest/TestSuite.h
@@ -0,0 +1,512 @@
+#ifndef __cxxtest__TestSuite_h__
+#define __cxxtest__TestSuite_h__
+
+//
+// class TestSuite is the base class for all test suites.
+// To define a test suite, derive from this class and add
+// member functions called void test*();
+//
+
+#include <cxxtest/Flags.h>
+#include <cxxtest/TestTracker.h>
+#include <cxxtest/Descriptions.h>
+#include <cxxtest/ValueTraits.h>
+
+#ifdef _CXXTEST_HAVE_STD
+# include <stdexcept>
+#endif // _CXXTEST_HAVE_STD
+
+namespace CxxTest
+{
+ class TestSuite
+ {
+ public:
+ virtual ~TestSuite();
+ virtual void setUp();
+ virtual void tearDown();
+ };
+
+ class AbortTest {};
+ void doAbortTest();
+# define TS_ABORT() CxxTest::doAbortTest()
+
+ bool abortTestOnFail();
+ void setAbortTestOnFail( bool value = CXXTEST_DEFAULT_ABORT );
+
+ unsigned maxDumpSize();
+ void setMaxDumpSize( unsigned value = CXXTEST_MAX_DUMP_SIZE );
+
+ void doTrace( const char *file, unsigned line, const char *message );
+ void doWarn( const char *file, unsigned line, const char *message );
+ void doFailTest( const char *file, unsigned line, const char *message );
+ void doFailAssert( const char *file, unsigned line, const char *expression, const char *message );
+
+ template<class X, class Y>
+ bool equals( X x, Y y )
+ {
+ return (x == y);
+ }
+
+ template<class X, class Y>
+ void doAssertEquals( const char *file, unsigned line,
+ const char *xExpr, X x,
+ const char *yExpr, Y y,
+ const char *message )
+ {
+ if ( !equals( x, y ) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssertEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
+ TS_ABORT();
+ }
+ }
+
+ void doAssertSameData( const char *file, unsigned line,
+ const char *xExpr, const void *x,
+ const char *yExpr, const void *y,
+ const char *sizeExpr, unsigned size,
+ const char *message );
+
+ template<class X, class Y>
+ bool differs( X x, Y y )
+ {
+ return !(x == y);
+ }
+
+ template<class X, class Y>
+ void doAssertDiffers( const char *file, unsigned line,
+ const char *xExpr, X x,
+ const char *yExpr, Y y,
+ const char *message )
+ {
+ if ( !differs( x, y ) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssertDiffers( file, line, xExpr, yExpr, TS_AS_STRING(x) );
+ TS_ABORT();
+ }
+ }
+
+ template<class X, class Y>
+ bool lessThan( X x, Y y )
+ {
+ return (x < y);
+ }
+
+ template<class X, class Y>
+ void doAssertLessThan( const char *file, unsigned line,
+ const char *xExpr, X x,
+ const char *yExpr, Y y,
+ const char *message )
+ {
+ if ( !lessThan(x, y) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssertLessThan( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
+ TS_ABORT();
+ }
+ }
+
+ template<class X, class Y>
+ bool lessThanEquals( X x, Y y )
+ {
+ return (x <= y);
+ }
+
+ template<class X, class Y>
+ void doAssertLessThanEquals( const char *file, unsigned line,
+ const char *xExpr, X x,
+ const char *yExpr, Y y,
+ const char *message )
+ {
+ if ( !lessThanEquals( x, y ) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssertLessThanEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
+ TS_ABORT();
+ }
+ }
+
+ template<class X, class P>
+ void doAssertPredicate( const char *file, unsigned line,
+ const char *pExpr, const P &p,
+ const char *xExpr, X x,
+ const char *message )
+ {
+ if ( !p( x ) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssertPredicate( file, line, pExpr, xExpr, TS_AS_STRING(x) );
+ TS_ABORT();
+ }
+ }
+
+ template<class X, class Y, class R>
+ void doAssertRelation( const char *file, unsigned line,
+ const char *rExpr, const R &r,
+ const char *xExpr, X x,
+ const char *yExpr, Y y,
+ const char *message )
+ {
+ if ( !r( x, y ) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+ tracker().failedAssertRelation( file, line, rExpr, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
+ TS_ABORT();
+ }
+ }
+
+ template<class X, class Y, class D>
+ bool delta( X x, Y y, D d )
+ {
+ return ((y >= x - d) && (y <= x + d));
+ }
+
+ template<class X, class Y, class D>
+ void doAssertDelta( const char *file, unsigned line,
+ const char *xExpr, X x,
+ const char *yExpr, Y y,
+ const char *dExpr, D d,
+ const char *message )
+ {
+ if ( !delta( x, y, d ) ) {
+ if ( message )
+ tracker().failedTest( file, line, message );
+
+ tracker().failedAssertDelta( file, line, xExpr, yExpr, dExpr,
+ TS_AS_STRING(x), TS_AS_STRING(y), TS_AS_STRING(d) );
+ TS_ABORT();
+ }
+ }
+
+ void doFailAssertThrows( const char *file, unsigned line,
+ const char *expr, const char *type,
+ bool otherThrown,
+ const char *message );
+
+ void doFailAssertThrowsNot( const char *file, unsigned line,
+ const char *expression, const char *message );
+
+# ifdef _CXXTEST_HAVE_EH
+# define _TS_TRY try
+# define _TS_CATCH_TYPE(t, b) catch t b
+# define _TS_CATCH_ABORT(b) _TS_CATCH_TYPE( (const CxxTest::AbortTest &), b )
+# define _TS_LAST_CATCH(b) _TS_CATCH_TYPE( (...), b )
+# define _TSM_LAST_CATCH(f,l,m) _TS_LAST_CATCH( { (CxxTest::tracker()).failedTest(f,l,m); } )
+# ifdef _CXXTEST_HAVE_STD
+# define ___TSM_CATCH(f,l,m) \
+ catch(const std::exception &e) { (CxxTest::tracker()).failedTest(f,l,e.what()); } \
+ _TSM_LAST_CATCH(f,l,m)
+# else // !_CXXTEST_HAVE_STD
+# define ___TSM_CATCH(f,l,m) _TSM_LAST_CATCH(f,l,m)
+# endif // _CXXTEST_HAVE_STD
+# define __TSM_CATCH(f,l,m) \
+ _TS_CATCH_ABORT( { throw; } ) \
+ ___TSM_CATCH(f,l,m)
+# define __TS_CATCH(f,l) __TSM_CATCH(f,l,"Unhandled exception")
+# define _TS_CATCH __TS_CATCH(__FILE__,__LINE__)
+# else // !_CXXTEST_HAVE_EH
+# define _TS_TRY
+# define ___TSM_CATCH(f,l,m)
+# define __TSM_CATCH(f,l,m)
+# define __TS_CATCH(f,l)
+# define _TS_CATCH
+# define _TS_CATCH_TYPE(t, b)
+# define _TS_LAST_CATCH(b)
+# define _TS_CATCH_ABORT(b)
+# endif // _CXXTEST_HAVE_EH
+
+ // TS_TRACE
+# define _TS_TRACE(f,l,e) CxxTest::doTrace( (f), (l), TS_AS_STRING(e) )
+# define TS_TRACE(e) _TS_TRACE( __FILE__, __LINE__, e )
+
+ // TS_WARN
+# define _TS_WARN(f,l,e) CxxTest::doWarn( (f), (l), TS_AS_STRING(e) )
+# define TS_WARN(e) _TS_WARN( __FILE__, __LINE__, e )
+
+ // TS_FAIL
+# define _TS_FAIL(f,l,e) CxxTest::doFailTest( (f), (l), TS_AS_STRING(e) )
+# define TS_FAIL(e) _TS_FAIL( __FILE__, __LINE__, e )
+
+ // TS_ASSERT
+# define ___ETS_ASSERT(f,l,e,m) { if ( !(e) ) CxxTest::doFailAssert( (f), (l), #e, (m) ); }
+# define ___TS_ASSERT(f,l,e,m) { _TS_TRY { ___ETS_ASSERT(f,l,e,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT(f,l,e) ___ETS_ASSERT(f,l,e,0)
+# define _TS_ASSERT(f,l,e) ___TS_ASSERT(f,l,e,0)
+
+# define ETS_ASSERT(e) _ETS_ASSERT(__FILE__,__LINE__,e)
+# define TS_ASSERT(e) _TS_ASSERT(__FILE__,__LINE__,e)
+
+# define _ETSM_ASSERT(f,l,m,e) ___ETS_ASSERT(f,l,e,TS_AS_STRING(m) )
+# define _TSM_ASSERT(f,l,m,e) ___TS_ASSERT(f,l,e,TS_AS_STRING(m) )
+
+# define ETSM_ASSERT(m,e) _ETSM_ASSERT(__FILE__,__LINE__,m,e)
+# define TSM_ASSERT(m,e) _TSM_ASSERT(__FILE__,__LINE__,m,e)
+
+ // TS_ASSERT_EQUALS
+# define ___ETS_ASSERT_EQUALS(f,l,x,y,m) CxxTest::doAssertEquals( (f), (l), #x, (x), #y, (y), (m) )
+# define ___TS_ASSERT_EQUALS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_EQUALS(f,l,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,0)
+# define _TS_ASSERT_EQUALS(f,l,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,0)
+
+# define ETS_ASSERT_EQUALS(x,y) _ETS_ASSERT_EQUALS(__FILE__,__LINE__,x,y)
+# define TS_ASSERT_EQUALS(x,y) _TS_ASSERT_EQUALS(__FILE__,__LINE__,x,y)
+
+# define _ETSM_ASSERT_EQUALS(f,l,m,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m))
+# define _TSM_ASSERT_EQUALS(f,l,m,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_EQUALS(m,x,y) _ETSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y)
+# define TSM_ASSERT_EQUALS(m,x,y) _TSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y)
+
+ // TS_ASSERT_SAME_DATA
+# define ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m) CxxTest::doAssertSameData( (f), (l), #x, (x), #y, (y), #s, (s), (m) )
+# define ___TS_ASSERT_SAME_DATA(f,l,x,y,s,m) { _TS_TRY { ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_SAME_DATA(f,l,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,0)
+# define _TS_ASSERT_SAME_DATA(f,l,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,0)
+
+# define ETS_ASSERT_SAME_DATA(x,y,s) _ETS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s)
+# define TS_ASSERT_SAME_DATA(x,y,s) _TS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s)
+
+# define _ETSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m))
+# define _TSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_SAME_DATA(m,x,y,s) _ETSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s)
+# define TSM_ASSERT_SAME_DATA(m,x,y,s) _TSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s)
+
+ // TS_ASSERT_DIFFERS
+# define ___ETS_ASSERT_DIFFERS(f,l,x,y,m) CxxTest::doAssertDiffers( (f), (l), #x, (x), #y, (y), (m) )
+# define ___TS_ASSERT_DIFFERS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_DIFFERS(f,l,x,y,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_DIFFERS(f,l,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,0)
+# define _TS_ASSERT_DIFFERS(f,l,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,0)
+
+# define ETS_ASSERT_DIFFERS(x,y) _ETS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y)
+# define TS_ASSERT_DIFFERS(x,y) _TS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y)
+
+# define _ETSM_ASSERT_DIFFERS(f,l,m,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m))
+# define _TSM_ASSERT_DIFFERS(f,l,m,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_DIFFERS(m,x,y) _ETSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y)
+# define TSM_ASSERT_DIFFERS(m,x,y) _TSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y)
+
+ // TS_ASSERT_LESS_THAN
+# define ___ETS_ASSERT_LESS_THAN(f,l,x,y,m) CxxTest::doAssertLessThan( (f), (l), #x, (x), #y, (y), (m) )
+# define ___TS_ASSERT_LESS_THAN(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_LESS_THAN(f,l,x,y,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_LESS_THAN(f,l,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,0)
+# define _TS_ASSERT_LESS_THAN(f,l,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,0)
+
+# define ETS_ASSERT_LESS_THAN(x,y) _ETS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y)
+# define TS_ASSERT_LESS_THAN(x,y) _TS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y)
+
+# define _ETSM_ASSERT_LESS_THAN(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m))
+# define _TSM_ASSERT_LESS_THAN(f,l,m,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_LESS_THAN(m,x,y) _ETSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y)
+# define TSM_ASSERT_LESS_THAN(m,x,y) _TSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y)
+
+ // TS_ASSERT_LESS_THAN_EQUALS
+# define ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
+ CxxTest::doAssertLessThanEquals( (f), (l), #x, (x), #y, (y), (m) )
+# define ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
+ { _TS_TRY { ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
+# define _TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
+
+# define ETS_ASSERT_LESS_THAN_EQUALS(x,y) _ETS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y)
+# define TS_ASSERT_LESS_THAN_EQUALS(x,y) _TS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y)
+
+# define _ETSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
+# define _TSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _ETSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y)
+# define TSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _TSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y)
+
+ // TS_ASSERT_PREDICATE
+# define ___ETS_ASSERT_PREDICATE(f,l,p,x,m) \
+ CxxTest::doAssertPredicate( (f), (l), #p, p(), #x, (x), (m) )
+# define ___TS_ASSERT_PREDICATE(f,l,p,x,m) \
+ { _TS_TRY { ___ETS_ASSERT_PREDICATE(f,l,p,x,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_PREDICATE(f,l,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,0)
+# define _TS_ASSERT_PREDICATE(f,l,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,0)
+
+# define ETS_ASSERT_PREDICATE(p,x) _ETS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x)
+# define TS_ASSERT_PREDICATE(p,x) _TS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x)
+
+# define _ETSM_ASSERT_PREDICATE(f,l,m,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m))
+# define _TSM_ASSERT_PREDICATE(f,l,m,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_PREDICATE(m,p,x) _ETSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x)
+# define TSM_ASSERT_PREDICATE(m,p,x) _TSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x)
+
+ // TS_ASSERT_RELATION
+# define ___ETS_ASSERT_RELATION(f,l,r,x,y,m) \
+ CxxTest::doAssertRelation( (f), (l), #r, r(), #x, (x), #y, (y), (m) )
+# define ___TS_ASSERT_RELATION(f,l,r,x,y,m) \
+ { _TS_TRY { ___ETS_ASSERT_RELATION(f,l,r,x,y,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_RELATION(f,l,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,0)
+# define _TS_ASSERT_RELATION(f,l,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,0)
+
+# define ETS_ASSERT_RELATION(r,x,y) _ETS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y)
+# define TS_ASSERT_RELATION(r,x,y) _TS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y)
+
+# define _ETSM_ASSERT_RELATION(f,l,m,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m))
+# define _TSM_ASSERT_RELATION(f,l,m,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_RELATION(m,r,x,y) _ETSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y)
+# define TSM_ASSERT_RELATION(m,r,x,y) _TSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y)
+
+ // TS_ASSERT_DELTA
+# define ___ETS_ASSERT_DELTA(f,l,x,y,d,m) CxxTest::doAssertDelta( (f), (l), #x, (x), #y, (y), #d, (d), (m) )
+# define ___TS_ASSERT_DELTA(f,l,x,y,d,m) { _TS_TRY { ___ETS_ASSERT_DELTA(f,l,x,y,d,m); } __TS_CATCH(f,l) }
+
+# define _ETS_ASSERT_DELTA(f,l,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,0)
+# define _TS_ASSERT_DELTA(f,l,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,0)
+
+# define ETS_ASSERT_DELTA(x,y,d) _ETS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d)
+# define TS_ASSERT_DELTA(x,y,d) _TS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d)
+
+# define _ETSM_ASSERT_DELTA(f,l,m,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m))
+# define _TSM_ASSERT_DELTA(f,l,m,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m))
+
+# define ETSM_ASSERT_DELTA(m,x,y,d) _ETSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d)
+# define TSM_ASSERT_DELTA(m,x,y,d) _TSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d)
+
+ // TS_ASSERT_THROWS
+# define ___TS_ASSERT_THROWS(f,l,e,t,m) { \
+ bool _ts_threw_expected = false, _ts_threw_else = false; \
+ _TS_TRY { e; } \
+ _TS_CATCH_TYPE( (t), { _ts_threw_expected = true; } ) \
+ _TS_CATCH_ABORT( { throw; } ) \
+ _TS_LAST_CATCH( { _ts_threw_else = true; } ) \
+ if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } }
+
+# define _TS_ASSERT_THROWS(f,l,e,t) ___TS_ASSERT_THROWS(f,l,e,t,0)
+# define TS_ASSERT_THROWS(e,t) _TS_ASSERT_THROWS(__FILE__,__LINE__,e,t)
+
+# define _TSM_ASSERT_THROWS(f,l,m,e,t) ___TS_ASSERT_THROWS(f,l,e,t,TS_AS_STRING(m))
+# define TSM_ASSERT_THROWS(m,e,t) _TSM_ASSERT_THROWS(__FILE__,__LINE__,m,e,t)
+
+ // TS_ASSERT_THROWS_ASSERT
+# define ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,m) { \
+ bool _ts_threw_expected = false, _ts_threw_else = false; \
+ _TS_TRY { e; } \
+ _TS_CATCH_TYPE( (t), { a; _ts_threw_expected = true; } ) \
+ _TS_CATCH_ABORT( { throw; } ) \
+ _TS_LAST_CATCH( { _ts_threw_else = true; } ) \
+ if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } }
+
+# define _TS_ASSERT_THROWS_ASSERT(f,l,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,0)
+# define TS_ASSERT_THROWS_ASSERT(e,t,a) _TS_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,e,t,a)
+
+# define _TSM_ASSERT_THROWS_ASSERT(f,l,m,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,TS_AS_STRING(m))
+# define TSM_ASSERT_THROWS_ASSERT(m,e,t,a) _TSM_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,m,e,t,a)
+
+ // TS_ASSERT_THROWS_EQUALS
+# define TS_ASSERT_THROWS_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_EQUALS(x,y))
+# define TSM_ASSERT_THROWS_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_EQUALS(m,x,y))
+
+ // TS_ASSERT_THROWS_DIFFERS
+# define TS_ASSERT_THROWS_DIFFERS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DIFFERS(x,y))
+# define TSM_ASSERT_THROWS_DIFFERS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DIFFERS(m,x,y))
+
+ // TS_ASSERT_THROWS_DELTA
+# define TS_ASSERT_THROWS_DELTA(e,t,x,y,d) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DELTA(x,y,d))
+# define TSM_ASSERT_THROWS_DELTA(m,e,t,x,y,d) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DELTA(m,x,y,d))
+
+ // TS_ASSERT_THROWS_SAME_DATA
+# define TS_ASSERT_THROWS_SAME_DATA(e,t,x,y,s) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_SAME_DATA(x,y,s))
+# define TSM_ASSERT_THROWS_SAME_DATA(m,e,t,x,y,s) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_SAME_DATA(m,x,y,s))
+
+ // TS_ASSERT_THROWS_LESS_THAN
+# define TS_ASSERT_THROWS_LESS_THAN(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN(x,y))
+# define TSM_ASSERT_THROWS_LESS_THAN(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN(m,x,y))
+
+ // TS_ASSERT_THROWS_LESS_THAN_EQUALS
+# define TS_ASSERT_THROWS_LESS_THAN_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN_EQUALS(x,y))
+# define TSM_ASSERT_THROWS_LESS_THAN_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN_EQUALS(m,x,y))
+
+ // TS_ASSERT_THROWS_PREDICATE
+# define TS_ASSERT_THROWS_PREDICATE(e,t,p,v) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_PREDICATE(p,v))
+# define TSM_ASSERT_THROWS_PREDICATE(m,e,t,p,v) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_PREDICATE(m,p,v))
+
+ // TS_ASSERT_THROWS_RELATION
+# define TS_ASSERT_THROWS_RELATION(e,t,r,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_RELATION(r,x,y))
+# define TSM_ASSERT_THROWS_RELATION(m,e,t,r,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_RELATION(m,r,x,y))
+
+ // TS_ASSERT_THROWS_ANYTHING
+# define ___TS_ASSERT_THROWS_ANYTHING(f,l,e,m) { \
+ bool _ts_threw = false; \
+ _TS_TRY { e; } \
+ _TS_LAST_CATCH( { _ts_threw = true; } ) \
+ if ( !_ts_threw ) { CxxTest::doFailAssertThrows( (f), (l), #e, "...", false, (m) ); } }
+
+# define _TS_ASSERT_THROWS_ANYTHING(f,l,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,0)
+# define TS_ASSERT_THROWS_ANYTHING(e) _TS_ASSERT_THROWS_ANYTHING(__FILE__, __LINE__, e)
+
+# define _TSM_ASSERT_THROWS_ANYTHING(f,l,m,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,TS_AS_STRING(m))
+# define TSM_ASSERT_THROWS_ANYTHING(m,e) _TSM_ASSERT_THROWS_ANYTHING(__FILE__,__LINE__,m,e)
+
+ // TS_ASSERT_THROWS_NOTHING
+# define ___TS_ASSERT_THROWS_NOTHING(f,l,e,m) { \
+ _TS_TRY { e; } \
+ _TS_CATCH_ABORT( { throw; } ) \
+ _TS_LAST_CATCH( { CxxTest::doFailAssertThrowsNot( (f), (l), #e, (m) ); } ) }
+
+# define _TS_ASSERT_THROWS_NOTHING(f,l,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,0)
+# define TS_ASSERT_THROWS_NOTHING(e) _TS_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,e)
+
+# define _TSM_ASSERT_THROWS_NOTHING(f,l,m,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,TS_AS_STRING(m))
+# define TSM_ASSERT_THROWS_NOTHING(m,e) _TSM_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,m,e)
+
+
+ //
+ // This takes care of "signed <-> unsigned" warnings
+ //
+# define CXXTEST_COMPARISONS(CXXTEST_X, CXXTEST_Y, CXXTEST_T) \
+ inline bool equals( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) == ((CXXTEST_T)y)); } \
+ inline bool equals( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) == ((CXXTEST_T)x)); } \
+ inline bool differs( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) != ((CXXTEST_T)y)); } \
+ inline bool differs( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) != ((CXXTEST_T)x)); } \
+ inline bool lessThan( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) < ((CXXTEST_T)y)); } \
+ inline bool lessThan( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) < ((CXXTEST_T)x)); } \
+ inline bool lessThanEquals( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) <= ((CXXTEST_T)y)); } \
+ inline bool lessThanEquals( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) <= ((CXXTEST_T)x)); }
+
+# define CXXTEST_INTEGRAL(CXXTEST_T) \
+ CXXTEST_COMPARISONS( signed CXXTEST_T, unsigned CXXTEST_T, unsigned CXXTEST_T )
+
+ CXXTEST_INTEGRAL( char )
+ CXXTEST_INTEGRAL( short )
+ CXXTEST_INTEGRAL( int )
+ CXXTEST_INTEGRAL( long )
+# ifdef _CXXTEST_LONGLONG
+ CXXTEST_INTEGRAL( _CXXTEST_LONGLONG )
+# endif // _CXXTEST_LONGLONG
+
+# define CXXTEST_SMALL_BIG(CXXTEST_SMALL, CXXTEST_BIG) \
+ CXXTEST_COMPARISONS( signed CXXTEST_SMALL, unsigned CXXTEST_BIG, unsigned CXXTEST_BIG ) \
+ CXXTEST_COMPARISONS( signed CXXTEST_BIG, unsigned CXXTEST_SMALL, unsigned CXXTEST_BIG )
+
+ CXXTEST_SMALL_BIG( char, short )
+ CXXTEST_SMALL_BIG( char, int )
+ CXXTEST_SMALL_BIG( short, int )
+ CXXTEST_SMALL_BIG( char, long )
+ CXXTEST_SMALL_BIG( short, long )
+ CXXTEST_SMALL_BIG( int, long )
+
+# ifdef _CXXTEST_LONGLONG
+ CXXTEST_SMALL_BIG( char, _CXXTEST_LONGLONG )
+ CXXTEST_SMALL_BIG( short, _CXXTEST_LONGLONG )
+ CXXTEST_SMALL_BIG( int, _CXXTEST_LONGLONG )
+ CXXTEST_SMALL_BIG( long, _CXXTEST_LONGLONG )
+# endif // _CXXTEST_LONGLONG
+}
+
+#endif // __cxxtest__TestSuite_h__
diff --git a/test/cxxtest/cxxtest/TestTracker.cpp b/test/cxxtest/cxxtest/TestTracker.cpp
new file mode 100644
index 0000000000..f3ce781880
--- /dev/null
+++ b/test/cxxtest/cxxtest/TestTracker.cpp
@@ -0,0 +1,248 @@
+#ifndef __cxxtest__TestTracker_cpp__
+#define __cxxtest__TestTracker_cpp__
+
+#include <cxxtest/TestTracker.h>
+
+namespace CxxTest
+{
+ bool TestTracker::_created = false;
+
+ TestTracker::TestTracker()
+ {
+ if ( !_created ) {
+ initialize();
+ _created = true;
+ }
+ }
+
+ TestTracker::~TestTracker()
+ {
+ }
+
+ TestTracker & TestTracker::tracker()
+ {
+ static TestTracker theTracker;
+ return theTracker;
+ }
+
+ void TestTracker::initialize()
+ {
+ _warnings = 0;
+ _failedTests = 0;
+ _testFailedAsserts = 0;
+ _suiteFailedTests = 0;
+ _failedSuites = 0;
+ setListener( 0 );
+ _world = 0;
+ _suite = 0;
+ _test = 0;
+ }
+
+ const TestDescription *TestTracker::fixTest( const TestDescription *d ) const
+ {
+ return d ? d : &dummyTest();
+ }
+
+ const SuiteDescription *TestTracker::fixSuite( const SuiteDescription *d ) const
+ {
+ return d ? d : &dummySuite();
+ }
+
+ const WorldDescription *TestTracker::fixWorld( const WorldDescription *d ) const
+ {
+ return d ? d : &dummyWorld();
+ }
+
+ const TestDescription &TestTracker::dummyTest() const
+ {
+ return dummySuite().testDescription(0);
+ }
+
+ const SuiteDescription &TestTracker::dummySuite() const
+ {
+ return dummyWorld().suiteDescription(0);
+ }
+
+ const WorldDescription &TestTracker::dummyWorld() const
+ {
+ return _dummyWorld;
+ }
+
+ void TestTracker::setListener( TestListener *l )
+ {
+ _l = l ? l : &_dummyListener;
+ }
+
+ void TestTracker::enterWorld( const WorldDescription &wd )
+ {
+ setWorld( &wd );
+ _warnings = _failedTests = _testFailedAsserts = _suiteFailedTests = _failedSuites = 0;
+ _l->enterWorld( wd );
+ }
+
+ void TestTracker::enterSuite( const SuiteDescription &sd )
+ {
+ setSuite( &sd );
+ _testFailedAsserts = _suiteFailedTests = 0;
+ _l->enterSuite(sd);
+ }
+
+ void TestTracker::enterTest( const TestDescription &td )
+ {
+ setTest( &td );
+ _testFailedAsserts = false;
+ _l->enterTest(td);
+ }
+
+ void TestTracker::leaveTest( const TestDescription &td )
+ {
+ _l->leaveTest( td );
+ setTest( 0 );
+ }
+
+ void TestTracker::leaveSuite( const SuiteDescription &sd )
+ {
+ _l->leaveSuite( sd );
+ setSuite( 0 );
+ }
+
+ void TestTracker::leaveWorld( const WorldDescription &wd )
+ {
+ _l->leaveWorld( wd );
+ setWorld( 0 );
+ }
+
+ void TestTracker::trace( const char *file, unsigned line, const char *expression )
+ {
+ _l->trace( file, line, expression );
+ }
+
+ void TestTracker::warning( const char *file, unsigned line, const char *expression )
+ {
+ countWarning();
+ _l->warning( file, line, expression );
+ }
+
+ void TestTracker::failedTest( const char *file, unsigned line, const char *expression )
+ {
+ countFailure();
+ _l->failedTest( file, line, expression );
+ }
+
+ void TestTracker::failedAssert( const char *file, unsigned line, const char *expression )
+ {
+ countFailure();
+ _l->failedAssert( file, line, expression );
+ }
+
+ void TestTracker::failedAssertEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ countFailure();
+ _l->failedAssertEquals( file, line, xStr, yStr, x, y );
+ }
+
+ void TestTracker::failedAssertSameData( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *sizeStr, const void *x,
+ const void *y, unsigned size )
+ {
+ countFailure();
+ _l->failedAssertSameData( file, line, xStr, yStr, sizeStr, x, y, size );
+ }
+
+ void TestTracker::failedAssertDelta( const char *file, unsigned line,
+ const char *xStr, const char *yStr, const char *dStr,
+ const char *x, const char *y, const char *d )
+ {
+ countFailure();
+ _l->failedAssertDelta( file, line, xStr, yStr, dStr, x, y, d );
+ }
+
+ void TestTracker::failedAssertDiffers( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *value )
+ {
+ countFailure();
+ _l->failedAssertDiffers( file, line, xStr, yStr, value );
+ }
+
+ void TestTracker::failedAssertLessThan( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ countFailure();
+ _l->failedAssertLessThan( file, line, xStr, yStr, x, y );
+ }
+
+ void TestTracker::failedAssertLessThanEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ countFailure();
+ _l->failedAssertLessThanEquals( file, line, xStr, yStr, x, y );
+ }
+
+ void TestTracker::failedAssertPredicate( const char *file, unsigned line,
+ const char *predicate, const char *xStr, const char *x )
+ {
+ countFailure();
+ _l->failedAssertPredicate( file, line, predicate, xStr, x );
+ }
+
+ void TestTracker::failedAssertRelation( const char *file, unsigned line,
+ const char *relation, const char *xStr, const char *yStr,
+ const char *x, const char *y )
+ {
+ countFailure();
+ _l->failedAssertRelation( file, line, relation, xStr, yStr, x, y );
+ }
+
+ void TestTracker::failedAssertThrows( const char *file, unsigned line,
+ const char *expression, const char *type,
+ bool otherThrown )
+ {
+ countFailure();
+ _l->failedAssertThrows( file, line, expression, type, otherThrown );
+ }
+
+ void TestTracker::failedAssertThrowsNot( const char *file, unsigned line, const char *expression )
+ {
+ countFailure();
+ _l->failedAssertThrowsNot( file, line, expression );
+ }
+
+ void TestTracker::setWorld( const WorldDescription *w )
+ {
+ _world = fixWorld( w );
+ setSuite( 0 );
+ }
+
+ void TestTracker::setSuite( const SuiteDescription *s )
+ {
+ _suite = fixSuite( s );
+ setTest( 0 );
+ }
+
+ void TestTracker::setTest( const TestDescription *t )
+ {
+ _test = fixTest( t );
+ }
+
+ void TestTracker::countWarning()
+ {
+ ++ _warnings;
+ }
+
+ void TestTracker::countFailure()
+ {
+ if ( ++ _testFailedAsserts == 1 ) {
+ ++ _failedTests;
+ if ( ++ _suiteFailedTests == 1 )
+ ++ _failedSuites;
+ }
+ }
+};
+
+#endif // __cxxtest__TestTracker_cpp__
diff --git a/test/cxxtest/cxxtest/TestTracker.h b/test/cxxtest/cxxtest/TestTracker.h
new file mode 100644
index 0000000000..c85abff141
--- /dev/null
+++ b/test/cxxtest/cxxtest/TestTracker.h
@@ -0,0 +1,114 @@
+#ifndef __cxxtest__TestTracker_h__
+#define __cxxtest__TestTracker_h__
+
+//
+// The TestTracker tracks running tests
+// The actual work is done in CountingListenerProxy,
+// but this way avoids cyclic references TestListener<->CountingListenerProxy
+//
+
+#include <cxxtest/TestListener.h>
+#include <cxxtest/DummyDescriptions.h>
+
+namespace CxxTest
+{
+ class TestListener;
+
+ class TestTracker : public TestListener
+ {
+ public:
+ virtual ~TestTracker();
+
+ static TestTracker &tracker();
+
+ const TestDescription *fixTest( const TestDescription *d ) const;
+ const SuiteDescription *fixSuite( const SuiteDescription *d ) const;
+ const WorldDescription *fixWorld( const WorldDescription *d ) const;
+
+ const TestDescription &test() const { return *_test; }
+ const SuiteDescription &suite() const { return *_suite; }
+ const WorldDescription &world() const { return *_world; }
+
+ bool testFailed() const { return (testFailedAsserts() > 0); }
+ bool suiteFailed() const { return (suiteFailedTests() > 0); }
+ bool worldFailed() const { return (failedSuites() > 0); }
+
+ unsigned warnings() const { return _warnings; }
+ unsigned failedTests() const { return _failedTests; }
+ unsigned testFailedAsserts() const { return _testFailedAsserts; }
+ unsigned suiteFailedTests() const { return _suiteFailedTests; }
+ unsigned failedSuites() const { return _failedSuites; }
+
+ void enterWorld( const WorldDescription &wd );
+ void enterSuite( const SuiteDescription &sd );
+ void enterTest( const TestDescription &td );
+ void leaveTest( const TestDescription &td );
+ void leaveSuite( const SuiteDescription &sd );
+ void leaveWorld( const WorldDescription &wd );
+ void trace( const char *file, unsigned line, const char *expression );
+ void warning( const char *file, unsigned line, const char *expression );
+ void failedTest( const char *file, unsigned line, const char *expression );
+ void failedAssert( const char *file, unsigned line, const char *expression );
+ void failedAssertEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y );
+ void failedAssertSameData( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *sizeStr, const void *x,
+ const void *y, unsigned 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 );
+ void failedAssertDiffers( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *value );
+ void failedAssertLessThan( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y );
+ void failedAssertLessThanEquals( const char *file, unsigned line,
+ const char *xStr, const char *yStr,
+ const char *x, const char *y );
+ void failedAssertPredicate( const char *file, unsigned line,
+ const char *predicate, const char *xStr, const char *x );
+ void failedAssertRelation( const char *file, unsigned line,
+ const char *relation, const char *xStr, const char *yStr,
+ const char *x, const char *y );
+ void failedAssertThrows( const char *file, unsigned line,
+ const char *expression, const char *type,
+ bool otherThrown );
+ void failedAssertThrowsNot( const char *file, unsigned line, const char *expression );
+
+ private:
+ TestTracker( const TestTracker & );
+ TestTracker &operator=( const TestTracker & );
+
+ static bool _created;
+ TestListener _dummyListener;
+ DummyWorldDescription _dummyWorld;
+ unsigned _warnings, _failedTests, _testFailedAsserts, _suiteFailedTests, _failedSuites;
+ TestListener *_l;
+ const WorldDescription *_world;
+ const SuiteDescription *_suite;
+ const TestDescription *_test;
+
+ const TestDescription &dummyTest() const;
+ const SuiteDescription &dummySuite() const;
+ const WorldDescription &dummyWorld() const;
+
+ void setWorld( const WorldDescription *w );
+ void setSuite( const SuiteDescription *s );
+ void setTest( const TestDescription *t );
+ void countWarning();
+ void countFailure();
+
+ friend class TestRunner;
+
+ TestTracker();
+ void initialize();
+ void setListener( TestListener *l );
+ };
+
+ inline TestTracker &tracker() { return TestTracker::tracker(); }
+};
+
+#endif // __cxxtest__TestTracker_h__
diff --git a/test/cxxtest/cxxtest/ValueTraits.cpp b/test/cxxtest/cxxtest/ValueTraits.cpp
new file mode 100644
index 0000000000..7d29ada9d2
--- /dev/null
+++ b/test/cxxtest/cxxtest/ValueTraits.cpp
@@ -0,0 +1,140 @@
+#ifndef __cxxtest__ValueTraits_cpp__
+#define __cxxtest__ValueTraits_cpp__
+
+#include <cxxtest/ValueTraits.h>
+
+namespace CxxTest
+{
+ //
+ // Non-inline functions from ValueTraits.h
+ //
+
+ char digitToChar( unsigned digit )
+ {
+ if ( digit < 10 )
+ return (char)('0' + digit);
+ if ( digit <= 10 + 'Z' - 'A' )
+ return (char)('A' + digit - 10);
+ return '?';
+ }
+
+ const char *byteToHex( unsigned char byte )
+ {
+ static char asHex[3];
+ asHex[0] = digitToChar( byte >> 4 );
+ asHex[1] = digitToChar( byte & 0x0F );
+ asHex[2] = '\0';
+ return asHex;
+ }
+
+ char *copyString( char *dst, const char *src )
+ {
+ while ( (*dst = *src) != '\0' ) {
+ ++ dst;
+ ++ src;
+ }
+ return dst;
+ }
+
+ bool stringsEqual( const char *s1, const char *s2 )
+ {
+ char c;
+ while ( (c = *s1++) == *s2++ )
+ if ( c == '\0' )
+ return true;
+ return false;
+ }
+
+ char *charToString( unsigned long c, char *s )
+ {
+ switch( c ) {
+ case '\\': return copyString( s, "\\\\" );
+ case '\"': return copyString( s, "\\\"" );
+ case '\'': return copyString( s, "\\\'" );
+ case '\0': return copyString( s, "\\0" );
+ case '\a': return copyString( s, "\\a" );
+ case '\b': return copyString( s, "\\b" );
+ case '\n': return copyString( s, "\\n" );
+ case '\r': return copyString( s, "\\r" );
+ case '\t': return copyString( s, "\\t" );
+ }
+ if ( c >= 32 && c <= 127 ) {
+ s[0] = (char)c;
+ s[1] = '\0';
+ return s + 1;
+ }
+ else {
+ s[0] = '\\';
+ s[1] = 'x';
+ if ( c < 0x10 ) {
+ s[2] = '0';
+ ++ s;
+ }
+ return numberToString( c, s + 2, 16UL );
+ }
+ }
+
+ char *charToString( char c, char *s )
+ {
+ return charToString( (unsigned long)(unsigned char)c, s );
+ }
+
+ char *bytesToString( const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s )
+ {
+ bool truncate = (numBytes > maxBytes);
+ if ( truncate )
+ numBytes = maxBytes;
+
+ s = copyString( s, "{ " );
+ for ( unsigned i = 0; i < numBytes; ++ i, ++ bytes )
+ s = copyString( copyString( s, byteToHex( *bytes ) ), " " );
+ if ( truncate )
+ s = copyString( s, "..." );
+ return copyString( s, " }" );
+ }
+
+#ifndef CXXTEST_USER_VALUE_TRAITS
+ unsigned ValueTraits<const double>::requiredDigitsOnLeft( double t )
+ {
+ unsigned digits = 1;
+ for ( t = (t < 0.0) ? -t : t; t > 1.0; t /= BASE )
+ ++ digits;
+ return digits;
+ }
+
+ char *ValueTraits<const double>::doNegative( double &t )
+ {
+ if ( t >= 0 )
+ return _asString;
+ _asString[0] = '-';
+ t = -t;
+ return _asString + 1;
+ }
+
+ void ValueTraits<const double>::hugeNumber( double t )
+ {
+ char *s = doNegative( t );
+ s = doubleToString( t, s, 0, 1 );
+ s = copyString( s, "." );
+ s = doubleToString( t, s, 1, DIGITS_ON_RIGHT );
+ s = copyString( s, "E" );
+ s = numberToString( requiredDigitsOnLeft( t ) - 1, s );
+ }
+
+ void ValueTraits<const double>::normalNumber( double t )
+ {
+ char *s = doNegative( t );
+ s = doubleToString( t, s );
+ s = copyString( s, "." );
+ for ( unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i )
+ s = numberToString( (unsigned)(t *= BASE) % BASE, s );
+ }
+
+ char *ValueTraits<const double>::doubleToString( double t, char *s, unsigned skip, unsigned max )
+ {
+ return numberToString<double>( t, s, BASE, skip, max );
+ }
+#endif // !CXXTEST_USER_VALUE_TRAITS
+};
+
+#endif // __cxxtest__ValueTraits_cpp__
diff --git a/test/cxxtest/cxxtest/ValueTraits.h b/test/cxxtest/cxxtest/ValueTraits.h
new file mode 100644
index 0000000000..71145ada7a
--- /dev/null
+++ b/test/cxxtest/cxxtest/ValueTraits.h
@@ -0,0 +1,377 @@
+#ifndef __cxxtest__ValueTraits_h__
+#define __cxxtest__ValueTraits_h__
+
+//
+// ValueTraits are used by CxxTest to convert arbitrary
+// values used in TS_ASSERT_EQUALS() to a string representation.
+//
+// This header file contains value traits for builtin integral types.
+// To declare value traits for new types you should instantiate the class
+// ValueTraits<YourClass>.
+//
+
+#include <cxxtest/Flags.h>
+
+#ifdef _CXXTEST_OLD_TEMPLATE_SYNTAX
+# define CXXTEST_TEMPLATE_INSTANTIATION
+#else // !_CXXTEST_OLD_TEMPLATE_SYNTAX
+# define CXXTEST_TEMPLATE_INSTANTIATION template<>
+#endif // _CXXTEST_OLD_TEMPLATE_SYNTAX
+
+namespace CxxTest
+{
+ //
+ // This is how we use the value traits
+ //
+# define TS_AS_STRING(x) CxxTest::traits(x).asString()
+
+ //
+ // Char representation of a digit
+ //
+ char digitToChar( unsigned digit );
+
+ //
+ // Convert byte value to hex digits
+ // Returns pointer to internal buffer
+ //
+ const char *byteToHex( unsigned char byte );
+
+ //
+ // Convert byte values to string
+ // Returns one past the copied data
+ //
+ char *bytesToString( const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s );
+
+ //
+ // Copy a string.
+ // Returns one past the end of the destination string
+ // Remember -- we can't use the standard library!
+ //
+ char *copyString( char *dst, const char *src );
+
+ //
+ // Compare two strings.
+ // Remember -- we can't use the standard library!
+ //
+ bool stringsEqual( const char *s1, const char *s2 );
+
+ //
+ // Represent a character value as a string
+ // Returns one past the end of the string
+ // This will be the actual char if printable or '\xXXXX' otherwise
+ //
+ char *charToString( unsigned long c, char *s );
+
+ //
+ // Prevent problems with negative (signed char)s
+ //
+ char *charToString( char c, char *s );
+
+ //
+ // The default ValueTraits class dumps up to 8 bytes as hex values
+ //
+ template <class T>
+ class ValueTraits
+ {
+ enum { MAX_BYTES = 8 };
+ char _asString[sizeof("{ ") + sizeof("XX ") * MAX_BYTES + sizeof("... }")];
+
+ public:
+ ValueTraits( const T &t ) { bytesToString( (const unsigned char *)&t, sizeof(T), MAX_BYTES, _asString ); }
+ const char *asString( void ) const { return _asString; }
+ };
+
+ //
+ // traits( T t )
+ // Creates an object of type ValueTraits<T>
+ //
+ template <class T>
+ inline ValueTraits<T> traits( T t )
+ {
+ return ValueTraits<T>( t );
+ }
+
+ //
+ // You can duplicate the implementation of an existing ValueTraits
+ //
+# define CXXTEST_COPY_TRAITS(CXXTEST_NEW_CLASS, CXXTEST_OLD_CLASS) \
+ CXXTEST_TEMPLATE_INSTANTIATION \
+ class ValueTraits< CXXTEST_NEW_CLASS > \
+ { \
+ ValueTraits< CXXTEST_OLD_CLASS > _old; \
+ public: \
+ ValueTraits( CXXTEST_NEW_CLASS n ) : _old( (CXXTEST_OLD_CLASS)n ) {} \
+ const char *asString( void ) const { return _old.asString(); } \
+ }
+
+ //
+ // Certain compilers need separate declarations for T and const T
+ //
+# ifdef _CXXTEST_NO_COPY_CONST
+# define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS)
+# else // !_CXXTEST_NO_COPY_CONST
+# define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS) CXXTEST_COPY_TRAITS(CXXTEST_CLASS, const CXXTEST_CLASS)
+# endif // _CXXTEST_NO_COPY_CONST
+
+ //
+ // Avoid compiler warnings about unsigned types always >= 0
+ //
+ template<class N> inline bool negative( N n ) { return n < 0; }
+ template<class N> inline N abs( N n ) { return negative(n) ? -n : n; }
+
+# define CXXTEST_NON_NEGATIVE(Type) \
+ CXXTEST_TEMPLATE_INSTANTIATION \
+ inline bool negative<Type>( Type ) { return false; } \
+ CXXTEST_TEMPLATE_INSTANTIATION \
+ inline Type abs<Type>( Type value ) { return value; }
+
+ CXXTEST_NON_NEGATIVE( bool )
+ CXXTEST_NON_NEGATIVE( unsigned char )
+ CXXTEST_NON_NEGATIVE( unsigned short int )
+ CXXTEST_NON_NEGATIVE( unsigned int )
+ CXXTEST_NON_NEGATIVE( unsigned long int )
+# ifdef _CXXTEST_LONGLONG
+ CXXTEST_NON_NEGATIVE( unsigned _CXXTEST_LONGLONG )
+# endif // _CXXTEST_LONGLONG
+
+ //
+ // Represent (integral) number as a string
+ // Returns one past the end of the string
+ // Remember -- we can't use the standard library!
+ //
+ template<class N>
+ char *numberToString( N n, char *s,
+ N base = 10,
+ unsigned skipDigits = 0,
+ unsigned maxDigits = (unsigned)-1 )
+ {
+ if ( negative(n) ) {
+ *s++ = '-';
+ n = abs(n);
+ }
+
+ N digit = 1;
+ while ( digit <= (n / base) )
+ digit *= base;
+ N digitValue;
+ for ( ; digit >= 1 && skipDigits; n -= digit * digitValue, digit /= base, -- skipDigits )
+ digitValue = (unsigned)(n / digit);
+ for ( ; digit >= 1 && maxDigits; n -= digit * digitValue, digit /= base, -- maxDigits )
+ *s++ = digitToChar( (unsigned)(digitValue = (unsigned)(n / digit)) );
+
+ *s = '\0';
+ return s;
+ }
+
+ //
+ // All the specific ValueTraits follow.
+ // You can #define CXXTEST_USER_VALUE_TRAITS if you don't want them
+ //
+
+#ifndef CXXTEST_USER_VALUE_TRAITS
+ //
+ // ValueTraits: const char * const &
+ // This is used for printing strings, as in TS_FAIL( "Message" )
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const char * const &>
+ {
+ ValueTraits &operator=( const ValueTraits & );
+ const char *_asString;
+
+ public:
+ ValueTraits( const char * const &value ) : _asString( value ) {}
+ ValueTraits( const ValueTraits &other ) : _asString( other._asString ) {}
+ const char *asString( void ) const { return _asString; }
+ };
+
+ CXXTEST_COPY_TRAITS( const char *, const char * const & );
+ CXXTEST_COPY_TRAITS( char *, const char * const & );
+
+ //
+ // ValueTraits: bool
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const bool>
+ {
+ bool _value;
+
+ public:
+ ValueTraits( const bool value ) : _value( value ) {}
+ const char *asString( void ) const { return _value ? "true" : "false"; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( bool );
+
+# ifdef _CXXTEST_LONGLONG
+ //
+ // ValueTraits: signed long long
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const signed _CXXTEST_LONGLONG>
+ {
+ typedef _CXXTEST_LONGLONG T;
+ char _asString[2 + 3 * sizeof(T)];
+ public:
+ ValueTraits( T t ) { numberToString<T>( t, _asString ); }
+ const char *asString( void ) const { return _asString; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( signed _CXXTEST_LONGLONG );
+
+ //
+ // ValueTraits: unsigned long long
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const unsigned _CXXTEST_LONGLONG>
+ {
+ typedef unsigned _CXXTEST_LONGLONG T;
+ char _asString[1 + 3 * sizeof(T)];
+ public:
+ ValueTraits( T t ) { numberToString<T>( t, _asString ); }
+ const char *asString( void ) const { return _asString; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( unsigned _CXXTEST_LONGLONG );
+# endif // _CXXTEST_LONGLONG
+
+ //
+ // ValueTraits: signed long
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const signed long int>
+ {
+ typedef signed long int T;
+ char _asString[2 + 3 * sizeof(T)];
+ public:
+ ValueTraits( T t ) { numberToString<T>( t, _asString ); }
+ const char *asString( void ) const { return _asString; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( signed long int );
+
+ //
+ // ValueTraits: unsigned long
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const unsigned long int>
+ {
+ typedef unsigned long int T;
+ char _asString[1 + 3 * sizeof(T)];
+ public:
+ ValueTraits( T t ) { numberToString<T>( t, _asString ); }
+ const char *asString( void ) const { return _asString; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( unsigned long int );
+
+ //
+ // All decimals are the same as the long version
+ //
+
+ CXXTEST_COPY_TRAITS( const signed int, const signed long int );
+ CXXTEST_COPY_TRAITS( const unsigned int, const unsigned long int );
+ CXXTEST_COPY_TRAITS( const signed short int, const signed long int );
+ CXXTEST_COPY_TRAITS( const unsigned short int, const unsigned long int );
+ CXXTEST_COPY_TRAITS( const unsigned char, const unsigned long int );
+
+ CXXTEST_COPY_CONST_TRAITS( signed int );
+ CXXTEST_COPY_CONST_TRAITS( unsigned int );
+ CXXTEST_COPY_CONST_TRAITS( signed short int );
+ CXXTEST_COPY_CONST_TRAITS( unsigned short int );
+ CXXTEST_COPY_CONST_TRAITS( unsigned char );
+
+ //
+ // ValueTraits: char
+ // Returns 'x' for printable chars, '\x??' for others
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const char>
+ {
+ char _asString[sizeof("'\\xXX'")];
+ public:
+ ValueTraits( char c ) { copyString( charToString( c, copyString( _asString, "'" ) ), "'" ); }
+ const char *asString( void ) const { return _asString; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( char );
+
+ //
+ // ValueTraits: signed char
+ // Same as char, some compilers need it
+ //
+ CXXTEST_COPY_TRAITS( const signed char, const char );
+ CXXTEST_COPY_CONST_TRAITS( signed char );
+
+ //
+ // ValueTraits: double
+ //
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const double>
+ {
+ public:
+ ValueTraits( double t )
+ {
+ ( requiredDigitsOnLeft( t ) > MAX_DIGITS_ON_LEFT ) ?
+ hugeNumber( t ) :
+ normalNumber( t );
+ }
+
+ const char *asString( void ) const { return _asString; }
+
+ private:
+ enum { MAX_DIGITS_ON_LEFT = 24, DIGITS_ON_RIGHT = 4, BASE = 10 };
+ char _asString[1 + MAX_DIGITS_ON_LEFT + 1 + DIGITS_ON_RIGHT + 1];
+
+ static unsigned requiredDigitsOnLeft( double t );
+ char *doNegative( double &t );
+ void hugeNumber( double t );
+ void normalNumber( double t );
+ char *doubleToString( double t, char *s, unsigned skip = 0, unsigned max = (unsigned)-1 );
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( double );
+
+ //
+ // ValueTraits: float
+ //
+ CXXTEST_COPY_TRAITS( const float, const double );
+ CXXTEST_COPY_CONST_TRAITS( float );
+#endif // !CXXTEST_USER_VALUE_TRAITS
+};
+
+#ifdef _CXXTEST_HAVE_STD
+# include <cxxtest/StdValueTraits.h>
+#endif // _CXXTEST_HAVE_STD
+
+//
+// CXXTEST_ENUM_TRAITS
+//
+#define CXXTEST_ENUM_TRAITS( TYPE, VALUES ) \
+ namespace CxxTest \
+ { \
+ CXXTEST_TEMPLATE_INSTANTIATION \
+ class ValueTraits<TYPE> \
+ { \
+ TYPE _value; \
+ char _fallback[sizeof("(" #TYPE ")") + 3 * sizeof(TYPE)]; \
+ public: \
+ ValueTraits( TYPE value ) { \
+ _value = value; \
+ numberToString<unsigned long int>( _value, copyString( _fallback, "(" #TYPE ")" ) ); \
+ } \
+ const char *asString( void ) const \
+ { \
+ switch ( _value ) \
+ { \
+ VALUES \
+ default: return _fallback; \
+ } \
+ } \
+ }; \
+ }
+
+#define CXXTEST_ENUM_MEMBER( MEMBER ) \
+ case MEMBER: return #MEMBER;
+
+#endif // __cxxtest__ValueTraits_h__
diff --git a/test/cxxtest/cxxtest/Win32Gui.h b/test/cxxtest/cxxtest/Win32Gui.h
new file mode 100644
index 0000000000..6b3e7583a5
--- /dev/null
+++ b/test/cxxtest/cxxtest/Win32Gui.h
@@ -0,0 +1,531 @@
+#ifndef __cxxtest__Win32Gui_h__
+#define __cxxtest__Win32Gui_h__
+
+//
+// The Win32Gui displays a simple progress bar using the Win32 API.
+//
+// It accepts the following command line 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 -minimized and -keep are specified, GUI will only keep the
+// window if it's in focus.
+//
+// N.B. If you're wondering why this class doesn't use any standard
+// library or STL (<string> would have been nice) it's because it only
+// uses "straight" Win32 API.
+//
+
+#include <cxxtest/Gui.h>
+
+#include <windows.h>
+#include <commctrl.h>
+
+namespace CxxTest
+{
+ class Win32Gui : public GuiListener
+ {
+ public:
+ void enterGui( int &argc, char **argv )
+ {
+ parseCommandLine( argc, argv );
+ }
+
+ void enterWorld( const WorldDescription &wd )
+ {
+ getTotalTests( wd );
+ _testsDone = 0;
+ startGuiThread();
+ }
+
+ void guiEnterSuite( const char *suiteName )
+ {
+ showSuiteName( suiteName );
+ reset( _suiteStart );
+ }
+
+ void guiEnterTest( const char *suiteName, const char *testName )
+ {
+ ++ _testsDone;
+ setTestCaption( suiteName, testName );
+ showTestName( testName );
+ showTestsDone();
+ progressBarMessage( PBM_STEPIT );
+ reset( _testStart );
+ }
+
+ void yellowBar()
+ {
+ setColor( 255, 255, 0 );
+ setIcon( IDI_WARNING );
+ getTotalTests();
+ }
+
+ void redBar()
+ {
+ if ( _startMinimized )
+ showMainWindow( SW_SHOWNORMAL );
+ setColor( 255, 0, 0 );
+ setIcon( IDI_ERROR );
+ getTotalTests();
+ }
+
+ void leaveGui()
+ {
+ if ( keep() )
+ {
+ showSummary();
+ WaitForSingleObject( _gui, INFINITE );
+ }
+ DestroyWindow( _mainWindow );
+ }
+
+ private:
+ const char *_title;
+ bool _startMinimized, _keep;
+ HANDLE _gui;
+ WNDCLASSEX _windowClass;
+ HWND _mainWindow, _progressBar, _statusBar;
+ HANDLE _canStartTests;
+ unsigned _numTotalTests, _testsDone;
+ char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
+ enum {
+ STATUS_SUITE_NAME, STATUS_SUITE_TIME,
+ STATUS_TEST_NAME, STATUS_TEST_TIME,
+ STATUS_TESTS_DONE, STATUS_WORLD_TIME,
+ STATUS_TOTAL_PARTS
+ };
+ int _statusWidths[STATUS_TOTAL_PARTS];
+ unsigned _statusOffsets[STATUS_TOTAL_PARTS];
+ unsigned _statusTotal;
+ char _statusTestsDone[sizeof("1000000000 of (100%)") + WorldDescription::MAX_STRLEN_TOTAL_TESTS];
+ DWORD _worldStart, _suiteStart, _testStart;
+ char _timeString[sizeof("00:00:00")];
+
+ void parseCommandLine( int argc, char **argv )
+ {
+ _startMinimized = _keep = false;
+ _title = argv[0];
+
+ for ( int i = 1; i < argc; ++ i )
+ {
+ if ( !lstrcmpA( argv[i], "-minimized" ) )
+ _startMinimized = true;
+ else if ( !lstrcmpA( argv[i], "-keep" ) )
+ _keep = true;
+ else if ( !lstrcmpA( argv[i], "-title" ) && (i + 1 < argc) )
+ _title = argv[++i];
+ }
+ }
+
+ void getTotalTests()
+ {
+ getTotalTests( tracker().world() );
+ }
+
+ void getTotalTests( const WorldDescription &wd )
+ {
+ _numTotalTests = wd.numTotalTests();
+ wd.strTotalTests( _strTotalTests );
+ }
+
+ void startGuiThread()
+ {
+ _canStartTests = CreateEvent( NULL, TRUE, FALSE, NULL );
+ DWORD threadId;
+ _gui = CreateThread( NULL, 0, &(Win32Gui::guiThread), (LPVOID)this, 0, &threadId );
+ WaitForSingleObject( _canStartTests, INFINITE );
+ }
+
+ static DWORD WINAPI guiThread( LPVOID parameter )
+ {
+ ((Win32Gui *)parameter)->gui();
+ return 0;
+ }
+
+ void gui()
+ {
+ registerWindowClass();
+ createMainWindow();
+ initCommonControls();
+ createProgressBar();
+ createStatusBar();
+ centerMainWindow();
+ showMainWindow();
+ startTimer();
+ startTests();
+
+ messageLoop();
+ }
+
+ void registerWindowClass()
+ {
+ _windowClass.cbSize = sizeof(_windowClass);
+ _windowClass.style = CS_HREDRAW | CS_VREDRAW;
+ _windowClass.lpfnWndProc = &(Win32Gui::windowProcedure);
+ _windowClass.cbClsExtra = 0;
+ _windowClass.cbWndExtra = sizeof(LONG);
+ _windowClass.hInstance = (HINSTANCE)NULL;
+ _windowClass.hIcon = (HICON)NULL;
+ _windowClass.hCursor = (HCURSOR)NULL;
+ _windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ _windowClass.lpszMenuName = NULL;
+ _windowClass.lpszClassName = TEXT("CxxTest Window Class");
+ _windowClass.hIconSm = (HICON)NULL;
+
+ RegisterClassEx( &_windowClass );
+ }
+
+ void createMainWindow()
+ {
+ _mainWindow = createWindow( _windowClass.lpszClassName, WS_OVERLAPPEDWINDOW );
+ }
+
+ void initCommonControls()
+ {
+ HMODULE dll = LoadLibraryA( "comctl32.dll" );
+ if ( !dll )
+ return;
+
+ typedef void (WINAPI *FUNC)( void );
+ FUNC func = (FUNC)GetProcAddress( dll, "InitCommonControls" );
+ if ( !func )
+ return;
+
+ func();
+ }
+
+ void createProgressBar()
+ {
+ _progressBar = createWindow( PROGRESS_CLASS, WS_CHILD | WS_VISIBLE | PBS_SMOOTH, _mainWindow );
+
+#ifdef PBM_SETRANGE32
+ progressBarMessage( PBM_SETRANGE32, 0, _numTotalTests );
+#else // No PBM_SETRANGE32, use PBM_SETRANGE
+ progressBarMessage( PBM_SETRANGE, 0, MAKELPARAM( 0, (WORD)_numTotalTests ) );
+#endif // PBM_SETRANGE32
+ progressBarMessage( PBM_SETPOS, 0 );
+ progressBarMessage( PBM_SETSTEP, 1 );
+ greenBar();
+ UpdateWindow( _progressBar );
+ }
+
+ void createStatusBar()
+ {
+ _statusBar = createWindow( STATUSCLASSNAME, WS_CHILD | WS_VISIBLE, _mainWindow );
+ setRatios( 4, 1, 3, 1, 3, 1 );
+ }
+
+ void setRatios( unsigned suiteNameRatio, unsigned suiteTimeRatio,
+ unsigned testNameRatio, unsigned testTimeRatio,
+ unsigned testsDoneRatio, unsigned worldTimeRatio )
+ {
+ _statusTotal = 0;
+ _statusOffsets[STATUS_SUITE_NAME] = (_statusTotal += suiteNameRatio);
+ _statusOffsets[STATUS_SUITE_TIME] = (_statusTotal += suiteTimeRatio);
+ _statusOffsets[STATUS_TEST_NAME] = (_statusTotal += testNameRatio);
+ _statusOffsets[STATUS_TEST_TIME] = (_statusTotal += testTimeRatio);
+ _statusOffsets[STATUS_TESTS_DONE] = (_statusTotal += testsDoneRatio);
+ _statusOffsets[STATUS_WORLD_TIME] = (_statusTotal += worldTimeRatio);
+ }
+
+ HWND createWindow( LPCTSTR className, DWORD style, HWND parent = (HWND)NULL )
+ {
+ return CreateWindow( className, NULL, style, 0, 0, 0, 0, parent,
+ (HMENU)NULL, (HINSTANCE)NULL, (LPVOID)this );
+ }
+
+ void progressBarMessage( UINT message, WPARAM wParam = 0, LPARAM lParam = 0 )
+ {
+ SendMessage( _progressBar, message, wParam, lParam );
+ }
+
+ void centerMainWindow()
+ {
+ RECT screen;
+ getScreenArea( screen );
+
+ LONG screenWidth = screen.right - screen.left;
+ LONG screenHeight = screen.bottom - screen.top;
+
+ LONG xCenter = (screen.right + screen.left) / 2;
+ LONG yCenter = (screen.bottom + screen.top) / 2;
+
+ LONG windowWidth = (screenWidth * 4) / 5;
+ LONG windowHeight = screenHeight / 10;
+ LONG minimumHeight = 2 * (GetSystemMetrics( SM_CYCAPTION ) + GetSystemMetrics( SM_CYFRAME ));
+ if ( windowHeight < minimumHeight )
+ windowHeight = minimumHeight;
+
+ SetWindowPos( _mainWindow, HWND_TOP,
+ xCenter - (windowWidth / 2), yCenter - (windowHeight / 2),
+ windowWidth, windowHeight, 0 );
+ }
+
+ void getScreenArea( RECT &area )
+ {
+ if ( !getScreenAreaWithoutTaskbar( area ) )
+ getWholeScreenArea( area );
+ }
+
+ bool getScreenAreaWithoutTaskbar( RECT &area )
+ {
+ return (SystemParametersInfo( SPI_GETWORKAREA, sizeof(RECT), &area, 0 ) != 0);
+ }
+
+ void getWholeScreenArea( RECT &area )
+ {
+ area.left = area.top = 0;
+ area.right = GetSystemMetrics( SM_CXSCREEN );
+ area.bottom = GetSystemMetrics( SM_CYSCREEN );
+ }
+
+ void showMainWindow()
+ {
+ showMainWindow( _startMinimized ? SW_MINIMIZE : SW_SHOWNORMAL );
+ UpdateWindow( _mainWindow );
+ }
+
+ void showMainWindow( int mode )
+ {
+ ShowWindow( _mainWindow, mode );
+ }
+
+ enum { TIMER_ID = 1, TIMER_DELAY = 1000 };
+
+ void startTimer()
+ {
+ reset( _worldStart );
+ reset( _suiteStart );
+ reset( _testStart );
+ SetTimer( _mainWindow, TIMER_ID, TIMER_DELAY, 0 );
+ }
+
+ void reset( DWORD &tick )
+ {
+ tick = GetTickCount();
+ }
+
+ void startTests()
+ {
+ SetEvent( _canStartTests );
+ }
+
+ void messageLoop()
+ {
+ MSG message;
+ while ( BOOL haveMessage = GetMessage( &message, NULL, 0, 0 ) )
+ if ( haveMessage != -1 )
+ DispatchMessage( &message );
+ }
+
+ static LRESULT CALLBACK windowProcedure( HWND window, UINT message, WPARAM wParam, LPARAM lParam )
+ {
+ if ( message == WM_CREATE )
+ setUp( window, (LPCREATESTRUCT)lParam );
+
+ Win32Gui *that = (Win32Gui *)GetWindowLong( window, GWL_USERDATA );
+ return that->handle( window, message, wParam, lParam );
+ }
+
+ static void setUp( HWND window, LPCREATESTRUCT create )
+ {
+ SetWindowLong( window, GWL_USERDATA, (LONG)create->lpCreateParams );
+ }
+
+ LRESULT handle( HWND window, UINT message, WPARAM wParam, LPARAM lParam )
+ {
+ switch ( message )
+ {
+ case WM_SIZE: resizeControls(); break;
+
+ case WM_TIMER: updateTime(); break;
+
+ case WM_CLOSE:
+ case WM_DESTROY:
+ case WM_QUIT:
+ ExitProcess( 0 );
+
+ default: return DefWindowProc( window, message, wParam, lParam );
+ }
+ return 0;
+ }
+
+ void resizeControls()
+ {
+ RECT r;
+ GetClientRect( _mainWindow, &r );
+ LONG width = r.right - r.left;
+ LONG height = r.bottom - r.top;
+
+ GetClientRect( _statusBar, &r );
+ LONG statusHeight = r.bottom - r.top;
+ LONG resizeGripWidth = statusHeight;
+ LONG progressHeight = height - statusHeight;
+
+ SetWindowPos( _progressBar, HWND_TOP, 0, 0, width, progressHeight, 0 );
+ SetWindowPos( _statusBar, HWND_TOP, 0, progressHeight, width, statusHeight, 0 );
+ setStatusParts( width - resizeGripWidth );
+ }
+
+ void setStatusParts( LONG width )
+ {
+ for ( unsigned i = 0; i < STATUS_TOTAL_PARTS; ++ i )
+ _statusWidths[i] = (width * _statusOffsets[i]) / _statusTotal;
+
+ statusBarMessage( SB_SETPARTS, STATUS_TOTAL_PARTS, _statusWidths );
+ }
+
+ void statusBarMessage( UINT message, WPARAM wParam = 0, const void *lParam = 0 )
+ {
+ SendMessage( _statusBar, message, wParam, (LPARAM)lParam );
+ }
+
+ void greenBar()
+ {
+ setColor( 0, 255, 0 );
+ setIcon( IDI_INFORMATION );
+ }
+
+#ifdef PBM_SETBARCOLOR
+ void setColor( BYTE red, BYTE green, BYTE blue )
+ {
+ progressBarMessage( PBM_SETBARCOLOR, 0, RGB( red, green, blue ) );
+ }
+#else // !PBM_SETBARCOLOR
+ void setColor( BYTE, BYTE, BYTE )
+ {
+ }
+#endif // PBM_SETBARCOLOR
+
+ void setIcon( LPCTSTR icon )
+ {
+ SendMessage( _mainWindow, WM_SETICON, ICON_BIG, (LPARAM)loadStandardIcon( icon ) );
+ }
+
+ HICON loadStandardIcon( LPCTSTR icon )
+ {
+ return LoadIcon( (HINSTANCE)NULL, icon );
+ }
+
+ void setTestCaption( const char *suiteName, const char *testName )
+ {
+ setCaption( suiteName, "::", testName, "()" );
+ }
+
+ void setCaption( const char *a = "", const char *b = "", const char *c = "", const char *d = "" )
+ {
+ unsigned length = lstrlenA( _title ) + sizeof( " - " ) +
+ lstrlenA( a ) + lstrlenA( b ) + lstrlenA( c ) + lstrlenA( d );
+ char *name = allocate( length );
+ lstrcpyA( name, _title );
+ lstrcatA( name, " - " );
+ lstrcatA( name, a );
+ lstrcatA( name, b );
+ lstrcatA( name, c );
+ lstrcatA( name, d );
+ SetWindowTextA( _mainWindow, name );
+ deallocate( name );
+ }
+
+ void showSuiteName( const char *suiteName )
+ {
+ setStatusPart( STATUS_SUITE_NAME, suiteName );
+ }
+
+ void showTestName( const char *testName )
+ {
+ setStatusPart( STATUS_TEST_NAME, testName );
+ }
+
+ void showTestsDone()
+ {
+ wsprintfA( _statusTestsDone, "%u of %s (%u%%)",
+ _testsDone, _strTotalTests,
+ (_testsDone * 100) / _numTotalTests );
+ setStatusPart( STATUS_TESTS_DONE, _statusTestsDone );
+ }
+
+ void updateTime()
+ {
+ setStatusTime( STATUS_WORLD_TIME, _worldStart );
+ setStatusTime( STATUS_SUITE_TIME, _suiteStart );
+ setStatusTime( STATUS_TEST_TIME, _testStart );
+ }
+
+ void setStatusTime( unsigned part, DWORD start )
+ {
+ unsigned total = (GetTickCount() - start) / 1000;
+ unsigned hours = total / 3600;
+ unsigned minutes = (total / 60) % 60;
+ unsigned seconds = total % 60;
+
+ if ( hours )
+ wsprintfA( _timeString, "%u:%02u:%02u", hours, minutes, seconds );
+ else
+ wsprintfA( _timeString, "%02u:%02u", minutes, seconds );
+
+ setStatusPart( part, _timeString );
+ }
+
+ bool keep()
+ {
+ if ( !_keep )
+ return false;
+ if ( !_startMinimized )
+ return true;
+ return (_mainWindow == GetForegroundWindow());
+ }
+
+ void showSummary()
+ {
+ stopTimer();
+ setSummaryStatusBar();
+ setSummaryCaption();
+ }
+
+ void setStatusPart( unsigned part, const char *text )
+ {
+ statusBarMessage( SB_SETTEXTA, part, text );
+ }
+
+ void stopTimer()
+ {
+ KillTimer( _mainWindow, TIMER_ID );
+ setStatusTime( STATUS_WORLD_TIME, _worldStart );
+ }
+
+ void setSummaryStatusBar()
+ {
+ setRatios( 0, 0, 0, 0, 1, 1 );
+ resizeControls();
+
+ const char *tests = (_numTotalTests == 1) ? "test" : "tests";
+ if ( tracker().failedTests() )
+ wsprintfA( _statusTestsDone, "Failed %u of %s %s",
+ tracker().failedTests(), _strTotalTests, tests );
+ else
+ wsprintfA( _statusTestsDone, "%s %s passed", _strTotalTests, tests );
+
+ setStatusPart( STATUS_TESTS_DONE, _statusTestsDone );
+ }
+
+ void setSummaryCaption()
+ {
+ setCaption( _statusTestsDone );
+ }
+
+ char *allocate( unsigned length )
+ {
+ return (char *)HeapAlloc( GetProcessHeap(), 0, length );
+ }
+
+ void deallocate( char *data )
+ {
+ HeapFree( GetProcessHeap(), 0, data );
+ }
+ };
+};
+
+#endif // __cxxtest__Win32Gui_h__
diff --git a/test/cxxtest/cxxtest/X11Gui.h b/test/cxxtest/cxxtest/X11Gui.h
new file mode 100644
index 0000000000..f14431d94f
--- /dev/null
+++ b/test/cxxtest/cxxtest/X11Gui.h
@@ -0,0 +1,327 @@
+#ifndef __cxxtest__X11Gui_h__
+#define __cxxtest__X11Gui_h__
+
+//
+// X11Gui displays a simple progress bar using X11
+//
+// It accepts the following command-line arguments:
+// -title <title> - Sets the application title
+// -fn or -font <font> - Sets the font
+// -bg or -background <color> - Sets the background color (default=Grey)
+// -fg or -foreground <color> - Sets the text color (default=Black)
+// -green/-yellow/-red <color> - Sets the colors of the bar
+//
+
+#include <cxxtest/Gui.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+namespace CxxTest
+{
+ class X11Gui : public GuiListener
+ {
+ public:
+ void enterGui( int &argc, char **argv )
+ {
+ parseCommandLine( argc, argv );
+ }
+
+ void enterWorld( const WorldDescription &wd )
+ {
+ openDisplay();
+ if ( _display ) {
+ createColors();
+ createWindow();
+ createGc();
+ createFont();
+ centerWindow();
+ initializeEvents();
+ initializeBar( wd );
+ processEvents();
+ }
+ }
+
+ void guiEnterTest( const char *suiteName, const char *testName )
+ {
+ if ( _display ) {
+ ++ _testsDone;
+ setWindowName( suiteName, testName );
+ redraw();
+ }
+ }
+
+ void yellowBar()
+ {
+ if ( _display ) {
+ _barColor = getColor( _yellowName );
+ getTotalTests();
+ processEvents();
+ }
+ }
+
+ void redBar()
+ {
+ if ( _display ) {
+ _barColor = getColor( _redName );
+ getTotalTests();
+ processEvents();
+ }
+ }
+
+ void leaveGui()
+ {
+ if ( _display ) {
+ freeFontInfo();
+ destroyGc();
+ destroyWindow();
+ closeDisplay();
+ }
+ }
+
+ private:
+ const char *_programName;
+ Display *_display;
+ Window _window;
+ unsigned _numTotalTests, _testsDone;
+ char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
+ const char *_foregroundName, *_backgroundName;
+ const char *_greenName, *_yellowName, *_redName;
+ unsigned long _foreground, _background, _barColor;
+ int _width, _height;
+ GC _gc;
+ const char *_fontName;
+ XID _fontId;
+ XFontStruct *_fontInfo;
+ int _textHeight, _textDescent;
+ long _eventMask;
+ Colormap _colormap;
+
+ void parseCommandLine( int &argc, char **argv )
+ {
+ _programName = argv[0];
+
+ _fontName = 0;
+ _foregroundName = "Black";
+ _backgroundName = "Grey";
+ _greenName = "Green";
+ _yellowName = "Yellow";
+ _redName = "Red";
+
+ for ( int i = 1; i + 1 < argc; ++ i ) {
+ if ( !strcmp( argv[i], "-title" ) )
+ _programName = argv[++ i];
+ else if ( !strcmp( argv[i], "-fn" ) || !strcmp( argv[i], "-font" ) )
+ _fontName = argv[++ i];
+ else if ( !strcmp( argv[i], "-fg" ) || !strcmp( argv[i], "-foreground" ) )
+ _foregroundName = argv[++ i];
+ else if ( !strcmp( argv[i], "-bg" ) || !strcmp( argv[i], "-background" ) )
+ _backgroundName = argv[++ i];
+ else if ( !strcmp( argv[i], "-green" ) )
+ _greenName = argv[++ i];
+ else if ( !strcmp( argv[i], "-yellow" ) )
+ _yellowName = argv[++ i];
+ else if ( !strcmp( argv[i], "-red" ) )
+ _redName = argv[++ i];
+ }
+ }
+
+ void openDisplay()
+ {
+ _display = XOpenDisplay( NULL );
+ }
+
+ void createColors()
+ {
+ _colormap = DefaultColormap( _display, 0 );
+ _foreground = getColor( _foregroundName );
+ _background = getColor( _backgroundName );
+ }
+
+ unsigned long getColor( const char *colorName )
+ {
+ XColor color;
+ XParseColor( _display, _colormap, colorName, &color );
+ XAllocColor( _display, _colormap, &color );
+ return color.pixel;
+ }
+
+ void createWindow()
+ {
+ _window = XCreateSimpleWindow( _display, RootWindow( _display, 0 ), 0, 0, 1, 1, 0, 0, _background );
+ }
+
+ void createGc()
+ {
+ _gc = XCreateGC( _display, _window, 0, 0 );
+ }
+
+ void createFont()
+ {
+ if ( !loadFont() )
+ useDefaultFont();
+ getFontInfo();
+ _textHeight = _fontInfo->ascent + _fontInfo->descent;
+ _textDescent = _fontInfo->descent;
+ }
+
+ bool loadFont()
+ {
+ if ( !_fontName )
+ return false;
+ _fontId = XLoadFont( _display, _fontName );
+ return (XSetFont( _display, _gc, _fontId ) == Success);
+ }
+
+ void useDefaultFont()
+ {
+ _fontId = XGContextFromGC( _gc );
+ }
+
+ void getFontInfo()
+ {
+ _fontInfo = XQueryFont( _display, _fontId );
+ }
+
+ void freeFontInfo()
+ {
+ XFreeFontInfo( NULL, _fontInfo, 1 );
+ }
+
+ void initializeEvents()
+ {
+ _eventMask = ExposureMask;
+ XSelectInput( _display, _window, _eventMask );
+ }
+
+ void initializeBar( const WorldDescription &wd )
+ {
+ getTotalTests( wd );
+ _testsDone = 0;
+ _barColor = getColor( _greenName );
+ }
+
+ void getTotalTests()
+ {
+ getTotalTests( tracker().world() );
+ }
+
+ void getTotalTests( const WorldDescription &wd )
+ {
+ _numTotalTests = wd.numTotalTests();
+ wd.strTotalTests( _strTotalTests );
+ }
+
+ void centerWindow()
+ {
+ XMapWindow( _display, _window );
+
+ Screen *screen = XDefaultScreenOfDisplay( _display );
+ int screenWidth = WidthOfScreen( screen );
+ int screenHeight = HeightOfScreen( screen );
+ int xCenter = screenWidth / 2;
+ int yCenter = screenHeight / 2;
+
+ _width = (screenWidth * 4) / 5;
+ _height = screenHeight / 14;
+
+ XMoveResizeWindow( _display, _window, xCenter - (_width / 2), yCenter - (_height / 2), _width, _height );
+ }
+
+ void processEvents()
+ {
+ redraw();
+
+ XEvent event;
+ while( XCheckMaskEvent( _display, _eventMask, &event ) )
+ redraw();
+ }
+
+ void setWindowName( const char *suiteName, const char *testName )
+ {
+ unsigned length = strlen( _programName ) + strlen( suiteName ) + strlen( testName ) + sizeof( " - ::()" );
+ char *name = (char *)malloc( length );
+ sprintf( name, "%s - %s::%s()", _programName, suiteName, testName );
+ XSetStandardProperties( _display, _window, name, 0, 0, 0, 0, 0 );
+ free( name );
+ }
+
+ void redraw()
+ {
+ getWindowSize();
+ drawSolidBar();
+ drawDividers();
+ drawPercentage();
+ flush();
+ }
+
+ void getWindowSize()
+ {
+ XWindowAttributes attributes;
+ XGetWindowAttributes( _display, _window, &attributes );
+ _width = attributes.width;
+ _height = attributes.height;
+ }
+
+ void drawSolidBar()
+ {
+ unsigned barWidth = (_width * _testsDone) / _numTotalTests;
+
+ XSetForeground( _display, _gc, _barColor );
+ XFillRectangle( _display, _window, _gc, 0, 0, barWidth, _height );
+
+ XSetForeground( _display, _gc, _background );
+ XFillRectangle( _display, _window, _gc, barWidth, 0, _width + 1 - barWidth, _height );
+ }
+
+ void drawDividers()
+ {
+ if(_width / _numTotalTests < 5)
+ return;
+ for ( unsigned i = 1; i < _testsDone; ++ i ) {
+ int x = (_width * i) / _numTotalTests;
+ XDrawLine( _display, _window, _gc, x, 0, x, _height);
+ }
+ }
+
+ void drawPercentage()
+ {
+ XSetForeground( _display, _gc, _foreground );
+
+ char str[sizeof("1000000000 of ") + sizeof(_strTotalTests) + sizeof(" (100%)")];
+ sprintf( str, "%u of %s (%u%%)", _testsDone, _strTotalTests, (_testsDone * 100) / _numTotalTests );
+ unsigned len = strlen( str );
+
+ int textWidth = XTextWidth( _fontInfo, str, len );
+
+ XDrawString( _display, _window, _gc,
+ (_width - textWidth) / 2, ((_height + _textHeight) / 2) - _textDescent,
+ str, len );
+ }
+
+ void flush()
+ {
+ XFlush( _display );
+ }
+
+ void destroyGc()
+ {
+ XFreeGC( _display, _gc );
+ }
+
+ void destroyWindow()
+ {
+ XDestroyWindow( _display, _window );
+ }
+
+ void closeDisplay()
+ {
+ XCloseDisplay( _display );
+ }
+ };
+};
+
+#endif //__cxxtest__X11Gui_h__
diff --git a/test/cxxtest/cxxtest/YesNoRunner.h b/test/cxxtest/cxxtest/YesNoRunner.h
new file mode 100644
index 0000000000..e7b83b6bb8
--- /dev/null
+++ b/test/cxxtest/cxxtest/YesNoRunner.h
@@ -0,0 +1,29 @@
+#ifndef __cxxtest__YesNoRunner_h__
+#define __cxxtest__YesNoRunner_h__
+
+//
+// The YesNoRunner is a simple TestListener that
+// just returns true iff all tests passed.
+//
+
+#include <cxxtest/TestRunner.h>
+#include <cxxtest/TestListener.h>
+
+namespace CxxTest
+{
+ class YesNoRunner : public TestListener
+ {
+ public:
+ YesNoRunner()
+ {
+ }
+
+ int run()
+ {
+ TestRunner::runAllTests( *this );
+ return tracker().failedTests();
+ }
+ };
+}
+
+#endif // __cxxtest__YesNoRunner_h__
diff --git a/test/cxxtest/cxxtestgen.pl b/test/cxxtest/cxxtestgen.pl
new file mode 100755
index 0000000000..378b0a38e5
--- /dev/null
+++ b/test/cxxtest/cxxtestgen.pl
@@ -0,0 +1,551 @@
+#!/usr/bin/perl -w
+use strict;
+use Getopt::Long;
+
+sub usage() {
+ print STDERR "Usage: $0 [OPTIONS] <input file(s)>\n";
+ print STDERR "Generate test source file for CxxTest.\n";
+ print STDERR "\n";
+ print STDERR " -v, --version Write CxxTest version\n";
+ print STDERR " -o, --output=NAME Write output to file NAME\n";
+ print STDERR " --runner=CLASS Create a main() function that runs CxxTest::CLASS\n";
+ print STDERR " --gui=CLASS Like --runner, with GUI component\n";
+ print STDERR " --error-printer Same as --runner=ErrorPrinter\n";
+ print STDERR " --abort-on-fail Abort tests on failed asserts (like xUnit)\n";
+ print STDERR " --have-std Use standard library (even if not found in tests)\n";
+ print STDERR " --no-std Don't use standard library (even if found in tests)\n";
+ print STDERR " --have-eh Use exception handling (even if not found in tests)\n";
+ print STDERR " --no-eh Don't use exception handling (even if found in tests)\n";
+ print STDERR " --longlong=[TYPE] Use TYPE as `long long' (defaut = long long)\n";
+ print STDERR " --template=TEMPLATE Use TEMPLATE file to generate the test runner\n";
+ print STDERR " --include=HEADER Include \"HEADER\" in test runner before other headers\n";
+ print STDERR " --root Write CxxTest globals\n";
+ print STDERR " --part Don't write CxxTest globals\n";
+ print STDERR " --no-static-init Don't rely on static initialization\n";
+ exit -1;
+}
+
+main();
+
+sub main {
+ parseCommandline();
+ scanInputFiles();
+ writeOutput();
+}
+
+#
+# Handling the command line
+#
+
+my ($output, $runner, $gui, $template, $abortOnFail, $haveEh, $noEh, $haveStd, $noStd);
+my ($root, $part, $noStaticInit, $longlong, $factor);
+my @headers = ();
+
+sub parseCommandline() {
+ @ARGV = expandWildcards(@ARGV);
+ GetOptions( 'version' => \&printVersion,
+ 'output=s' => \$output,
+ 'template=s' => \$template,
+ 'runner=s' => \$runner,
+ 'gui=s', => \$gui,
+ 'error-printer' => sub { $runner = 'ErrorPrinter'; $haveStd = 1; },
+ 'abort-on-fail' => \$abortOnFail,
+ 'have-eh' => \$haveEh,
+ 'no-eh' => \$noEh,
+ 'have-std' => \$haveStd,
+ 'no-std' => \$noStd,
+ 'include=s' => \@headers,
+ 'root' => \$root,
+ 'part' => \$part,
+ 'no-static-init' => \$noStaticInit,
+ 'factor' => \$factor,
+ 'longlong:s' => \$longlong
+ ) or usage();
+ scalar @ARGV or $root or usage();
+
+ if ( defined($noStaticInit) && (defined($root) || defined($part)) ) {
+ die "--no-static-init cannot be used with --root/--part\n";
+ }
+
+ if ( $gui && !$runner ) {
+ $runner = 'StdioPrinter';
+ }
+
+ if ( defined($longlong) && !$longlong ) {
+ $longlong = 'long long';
+ }
+
+ foreach my $header (@headers) {
+ if ( !($header =~ m/^["<].*[>"]$/) ) {
+ $header = "\"$header\"";
+ }
+ }
+}
+
+sub printVersion() {
+ print "This is CxxTest version 3.10.1.\n";
+ exit 0;
+}
+
+sub expandWildcards() {
+ my @result = ();
+ while( my $fn = shift @_ ) {
+ push @result, glob($fn);
+ }
+ return @result;
+}
+
+#
+# Reading the input files and scanning for test cases
+#
+
+my (@suites, $suite, $test, $inBlock);
+my $numTotalTests = 0;
+
+sub scanInputFiles() {
+ foreach my $file (@ARGV) {
+ scanInputFile( $file );
+ }
+ scalar @suites or $root or die("No tests defined\n");
+}
+
+sub scanInputFile($) {
+ my ($file) = @_;
+ open FILE, "<$file" or die("Cannot open input file \"$file\"\n");
+
+ my $line;
+ while (defined($line = <FILE>)) {
+ scanLineForExceptionHandling( $line );
+ scanLineForStandardLibrary( $line );
+
+ scanLineForSuiteStart( $file, $., $line );
+
+ if ( $suite ) {
+ if ( lineBelongsToSuite( $suite, $., $line ) ) {
+ scanLineForTest( $., $line );
+ scanLineForCreate( $., $line );
+ scanLineForDestroy( $., $line );
+ }
+ }
+ }
+ closeSuite();
+ close FILE;
+}
+
+sub lineBelongsToSuite($$$) {
+ my ($suite, $lineNo, $line) = @_;
+ if ( !$suite->{'generated'} ) {
+ return 1;
+ }
+
+ if ( !$inBlock ) {
+ $inBlock = lineStartsBlock( $line );
+ }
+ if ( $inBlock ) {
+ addLineToBlock( $suite->{'file'}, $lineNo, $line );
+ }
+ return $inBlock;
+}
+
+sub scanLineForExceptionHandling($) {
+ my ($line) = @_;
+ if ( $line =~ m/\b(try|throw|catch|TSM?_ASSERT_THROWS[A-Z_]*)\b/ ) {
+ addExceptionHandling();
+ }
+}
+
+sub scanLineForStandardLibrary($) {
+ my ($line) = @_;
+ if ( $line =~ m/\b(std\s*::|CXXTEST_STD|using\s+namespace\s+std\b|^\s*\#\s*include\s+<[a-z0-9]+>)/ ) {
+ addStandardLibrary();
+ }
+}
+
+sub scanLineForSuiteStart($$$) {
+ my ($fileName, $lineNo, $line) = @_;
+ if ( $line =~ m/\bclass\s+(\w+)\s*:\s*public\s+((::)?\s*CxxTest\s*::\s*)?TestSuite\b/ ) {
+ startSuite( $1, $fileName, $lineNo, 0 );
+ }
+ if ( $line =~ m/\bCXXTEST_SUITE\s*\(\s*(\w*)\s*\)/ ) {
+ print "$fileName:$lineNo: Warning: Inline test suites are deprecated.\n";
+ startSuite( $1, $fileName, $lineNo, 1 );
+ }
+}
+
+sub startSuite($$$$) {
+ my ($name, $file, $line, $generated) = @_;
+ closeSuite();
+ $suite = { 'name' => $name,
+ 'file' => $file,
+ 'line' => $line,
+ 'generated' => $generated,
+ 'create' => 0,
+ 'destroy' => 0,
+ 'tests' => [],
+ 'lines' => [] };
+}
+
+sub lineStartsBlock($) {
+ my ($line) = @_;
+ return $line =~ m/\bCXXTEST_CODE\s*\(/;
+}
+
+sub scanLineForTest($$) {
+ my ($lineNo, $line) = @_;
+ if ( $line =~ m/^([^\/]|\/[^\/])*\bvoid\s+([Tt]est\w+)\s*\(\s*(void)?\s*\)/ ) {
+ addTest( $2, $lineNo );
+ }
+}
+
+sub addTest($$$) {
+ my ($name, $line) = @_;
+ $test = { 'name' => $name,
+ 'line' => $line };
+ push @{suiteTests()}, $test;
+}
+
+sub addLineToBlock($$$) {
+ my ($fileName, $lineNo, $line) = @_;
+ $line = fixBlockLine( $fileName, $lineNo, $line );
+ $line =~ s/^.*\{\{//;
+ my $end = ($line =~ s/\}\}.*//s);
+ push @{$suite->{'lines'}}, $line;
+ if ( $end ) {
+ $inBlock = 0;
+ }
+}
+
+sub fixBlockLine($$$) {
+ my ($fileName, $lineNo, $line) = @_;
+ my $fileLine = cstr($fileName) . "," . $lineNo;
+ $line =~ s/\b(E?TSM?_(ASSERT[A-Z_]*|FAIL))\s*\(/_$1($fileLine,/g;
+ return $line;
+}
+
+sub scanLineForCreate($$) {
+ my ($lineNo, $line) = @_;
+ if ( $line =~ m/\bstatic\s+\w+\s*\*\s*createSuite\s*\(\s*(void)?\s*\)/ ) {
+ addCreateSuite( $lineNo );
+ }
+}
+
+sub scanLineForDestroy($$) {
+ my ($lineNo, $line) = @_;
+ if ( $line =~ m/\bstatic\s+void\s+destroySuite\s*\(\s*\w+\s*\*\s*\w*\s*\)/ ) {
+ addDestroySuite( $lineNo );
+ }
+}
+
+sub closeSuite() {
+ if ( $suite && scalar @{suiteTests()} ) {
+ verifySuite();
+ rememberSuite();
+ }
+ undef $suite;
+}
+
+sub addCreateSuite($) {
+ $suite->{'createSuite'} = $_[0];
+}
+
+sub addDestroySuite($) {
+ $suite->{'destroySuite'} = $_[0];
+}
+
+sub addExceptionHandling() {
+ $haveEh = 1 unless defined($noEh);
+}
+
+sub addStandardLibrary() {
+ $haveStd = 1 unless defined($noStd);
+}
+
+sub verifySuite() {
+ if (suiteCreateLine() || suiteDestroyLine()) {
+ die("Suite ", suiteName(), " must have both createSuite() and destroySuite()\n")
+ unless (suiteCreateLine() && suiteDestroyLine());
+ }
+}
+
+sub rememberSuite() {
+ push @suites, $suite;
+ $numTotalTests += scalar @{$suite->{'tests'}};
+}
+
+sub suiteName() { return $suite->{'name'}; }
+sub suiteTests() { return $suite->{'tests'}; }
+sub suiteCreateLine() { return $suite->{'createSuite'}; }
+sub suiteDestroyLine() { return $suite->{'destroySuite'}; }
+sub fileName() { return $suite->{'file'}; }
+sub fileString() { return cstr(fileName()); }
+sub testName() { return $test->{'name'}; }
+sub testLine() { return $test->{'line'}; }
+
+sub suiteObject() { return "suite_".suiteName(); }
+
+sub cstr($) {
+ my $file = $_[0];
+ $file =~ s/\\/\\\\/g;
+ return "\"".$file."\"";
+}
+
+#
+# Writing the test source file
+#
+
+sub writeOutput() {
+ $template ? writeTemplateOutput() : writeSimpleOutput();
+}
+
+sub startOutputFile() {
+ if ( !standardOutput() ) {
+ open OUTPUT_FILE,">$output" or die("Cannot create output file \"$output\"\n");
+ select OUTPUT_FILE;
+ }
+ print "/* Generated file, do not edit */\n\n";
+}
+
+sub standardOutput() {
+ return !$output;
+}
+
+sub writeSimpleOutput() {
+ startOutputFile();
+ writePreamble();
+ writeMain();
+ writeWorld();
+}
+
+my ($didPreamble, $didWorld);
+
+sub writeTemplateOutput() {
+ openTemplateFile();
+ startOutputFile();
+ my $line;
+ while (defined($line = <TEMPLATE_FILE>)) {
+ if ( $line =~ m/^\s*\#\s*include\s*<cxxtest\// ) {
+ writePreamble();
+ print $line;
+ } elsif ( $line =~ m/^\s*<CxxTest\s+preamble>\s*$/ ) {
+ writePreamble();
+ } elsif ( $line =~ m/^\s*<CxxTest\s+world>\s*$/ ) {
+ writeWorld();
+ } else {
+ print $line;
+ }
+ }
+}
+
+sub openTemplateFile() {
+ open TEMPLATE_FILE, "<$template" or die("Cannot open template file \"$template\"\n");
+}
+
+sub writePreamble() {
+ return if $didPreamble;
+ print "#ifndef CXXTEST_RUNNING\n";
+ print "#define CXXTEST_RUNNING\n";
+ print "#endif\n";
+ print "\n";
+ if ( $haveStd ) {
+ print "#define _CXXTEST_HAVE_STD\n";
+ }
+ if ( $haveEh ) {
+ print "#define _CXXTEST_HAVE_EH\n";
+ }
+ if ( $abortOnFail ) {
+ print "#define _CXXTEST_ABORT_TEST_ON_FAIL\n";
+ }
+ if ( $longlong ) {
+ print "#define _CXXTEST_LONGLONG $longlong\n";
+ }
+ if ( $factor ) {
+ print "#define _CXXTEST_FACTOR\n";
+ }
+ foreach my $header (@headers) {
+ print "#include $header\n";
+ }
+ print "#include <cxxtest/TestListener.h>\n";
+ print "#include <cxxtest/TestTracker.h>\n";
+ print "#include <cxxtest/TestRunner.h>\n";
+ print "#include <cxxtest/RealDescriptions.h>\n";
+ print "#include <cxxtest/$runner.h>\n" if $runner;
+ print "#include <cxxtest/$gui.h>\n" if $gui;
+ print "\n";
+ $didPreamble = 1;
+}
+
+sub writeWorld() {
+ return if $didWorld;
+ writePreamble();
+ writeSuites();
+ ($root or !$part) and writeRoot();
+ $noStaticInit and writeInitialize();
+ $didWorld = 1;
+}
+
+sub writeSuites() {
+ foreach (@suites) {
+ $suite = $_;
+ writeInclude(fileName());
+ if ( $suite->{'generated'} ) { generateSuite(); }
+ dynamicSuite() ? writeSuitePointer() : writeSuiteObject();
+ writeTestList();
+ writeSuiteDescription();
+ writeTestDescriptions();
+ }
+}
+
+sub dynamicSuite() {
+ return suiteCreateLine();
+}
+
+my $lastIncluded;
+
+sub writeInclude($) {
+ my $file = $_[0];
+ return if $lastIncluded && ($file eq $lastIncluded);
+ print "#include \"$file\"\n\n";
+ $lastIncluded = $file;
+}
+
+sub generateSuite() {
+ print "class ", suiteName(), " : public CxxTest::TestSuite {\n";
+ print "public:\n";
+ foreach my $line (@{$suite->{'lines'}}) {
+ print $line;
+ }
+ print "};\n\n";
+}
+
+sub writeTestDescriptionsBase() {
+ my $class = "TestDescriptionBase_" . suiteName();
+ print "class $class : public CxxTest::TestDescription {\n";
+ print "public:\n";
+ print " const char *file() const { return ", fileString(), "; }\n";
+ print " const char *suiteName() const { return \"", suiteName(), "\"; }\n";
+ print "};\n\n";
+}
+
+sub writeSuitePointer() {
+ if ( $noStaticInit ) {
+ print "static ", suiteName(), " *", suiteObject(), ";\n\n";
+ } else {
+ print "static ", suiteName(), " *", suiteObject(), " = 0;\n\n";
+ }
+}
+
+sub writeSuiteObject() {
+ print "static ", suiteName(), " ", suiteObject(), ";\n\n";
+}
+
+sub testList() {
+ return "Tests_" . suiteName();
+}
+
+sub writeTestList() {
+ if ( $noStaticInit ) {
+ printf "static CxxTest::List %s;\n", testList();
+ } else {
+ printf "static CxxTest::List %s = { 0, 0 };\n", testList();
+ }
+}
+
+sub writeTestDescriptions() {
+ foreach (@{suiteTests()}) {
+ $test = $_;
+ writeTestDescription();
+ }
+}
+
+sub suiteDescription() {
+ return "suiteDescription_" . suiteName();
+}
+
+sub writeTestDescription() {
+ my $class = "TestDescription_" . suiteName() . "_" . testName();
+ printf "static class $class : public CxxTest::RealTestDescription {\n";
+ printf "public:\n";
+ $noStaticInit or
+ printf " $class() : CxxTest::RealTestDescription( %s, %s, %s, \"%s\" ) {}\n",
+ testList(), suiteDescription(), testLine(), testName();
+ printf " void runTest() { %s }\n", dynamicSuite() ? dynamicRun() : staticRun();
+ printf "} testDescription_%s_%s;\n\n", suiteName(), testName();
+}
+
+sub dynamicRun() {
+ return sprintf( "if ( %s ) %s->%s();", suiteObject(), suiteObject(), testName() );
+}
+
+sub staticRun() {
+ return sprintf( "%s.%s();", suiteObject(), testName() );
+}
+
+sub writeSuiteDescription() {
+ dynamicSuite() ? writeDynamicDescription() : writeStaticDescription();
+}
+
+sub writeDynamicDescription() {
+ printf "CxxTest::DynamicSuiteDescription<%s> %s", suiteName(), suiteDescription();
+ if ( !$noStaticInit ) {
+ printf "( %s, %s, \"%s\", %s, %s, %s, %s )",
+ fileString(), $suite->{'line'}, suiteName(), testList(),
+ suiteObject(), suiteCreateLine(), suiteDestroyLine();
+ }
+ print ";\n\n";
+}
+
+sub writeStaticDescription() {
+ printf "CxxTest::StaticSuiteDescription %s", suiteDescription();
+ if ( !$noStaticInit ) {
+ printf "( %s, %s, \"%s\", %s, %s )", fileString(), $suite->{'line'}, suiteName(), suiteObject(), testList();
+ }
+ print ";\n\n";
+}
+
+sub writeRoot() {
+ print "#include <cxxtest/Root.cpp>\n";
+}
+
+sub writeInitialize() {
+ print "namespace CxxTest {\n";
+ print " void initialize()\n";
+ print " {\n";
+ foreach (@suites) {
+ $suite = $_;
+ printf " %s.initialize();\n", testList();
+ if ( dynamicSuite() ) {
+ printf " %s = 0;\n", suiteObject();
+ printf " %s.initialize( %s, %s, \"%s\", %s, %s, %s, %s );\n",
+ suiteDescription(), fileString(), $suite->{'line'}, suiteName(), testList(),
+ suiteObject(), suiteCreateLine(), suiteDestroyLine();
+ } else {
+ printf " %s.initialize( %s, %s, \"%s\", %s, %s );\n",
+ suiteDescription(), fileString(), $suite->{'line'}, suiteName(), suiteObject(), testList();
+ }
+
+ foreach (@{suiteTests()}) {
+ $test = $_;
+ printf " testDescription_%s_%s.initialize( %s, %s, %s, \"%s\" );\n",
+ suiteName(), testName(), testList(), suiteDescription(), testLine(), testName();
+ }
+ }
+ print " }\n";
+ print "}\n";
+}
+
+sub writeMain() {
+ if ( $gui ) {
+ print "int main( int argc, char *argv[] ) {\n";
+ $noStaticInit &&
+ print " CxxTest::initialize();\n";
+ print " return CxxTest::GuiTuiRunner<CxxTest::$gui, CxxTest::$runner>( argc, argv ).run();\n";
+ print "}\n";
+ }
+ elsif ( $runner ) {
+ print "int main() {\n";
+ $noStaticInit &&
+ print " CxxTest::initialize();\n";
+ print " return CxxTest::$runner().run();\n";
+ print "}\n";
+ }
+}
diff --git a/test/cxxtest/cxxtestgen.py b/test/cxxtest/cxxtestgen.py
new file mode 100755
index 0000000000..831d23ab41
--- /dev/null
+++ b/test/cxxtest/cxxtestgen.py
@@ -0,0 +1,593 @@
+#!/usr/bin/python
+'''Usage: %s [OPTIONS] <input file(s)>
+Generate test source file for CxxTest.
+
+ -v, --version Write CxxTest version
+ -o, --output=NAME Write output to file NAME
+ --runner=CLASS Create a main() function that runs CxxTest::CLASS
+ --gui=CLASS Like --runner, with GUI component
+ --error-printer Same as --runner=ErrorPrinter
+ --abort-on-fail Abort tests on failed asserts (like xUnit)
+ --have-std Use standard library (even if not found in tests)
+ --no-std Don\'t use standard library (even if found in tests)
+ --have-eh Use exception handling (even if not found in tests)
+ --no-eh Don\'t use exception handling (even if found in tests)
+ --longlong=[TYPE] Use TYPE (default: long long) as long long
+ --template=TEMPLATE Use TEMPLATE file to generate the test runner
+ --include=HEADER Include HEADER in test runner before other headers
+ --root Write CxxTest globals
+ --part Don\'t write CxxTest globals
+ --no-static-init Don\'t rely on static initialization
+'''
+
+import re
+import sys
+import getopt
+import glob
+import string
+
+# Global variables
+suites = []
+suite = None
+inBlock = 0
+
+outputFileName = None
+runner = None
+gui = None
+root = None
+part = None
+noStaticInit = None
+templateFileName = None
+headers = []
+
+haveExceptionHandling = 0
+noExceptionHandling = 0
+haveStandardLibrary = 0
+noStandardLibrary = 0
+abortOnFail = 0
+factor = 0
+longlong = 0
+
+def main():
+ '''The main program'''
+ files = parseCommandline()
+ scanInputFiles( files )
+ writeOutput()
+
+def usage( problem = None ):
+ '''Print usage info and exit'''
+ if problem is None:
+ print usageString()
+ sys.exit(0)
+ else:
+ sys.stderr.write( usageString() )
+ abort( problem )
+
+def usageString():
+ '''Construct program usage string'''
+ return __doc__ % sys.argv[0]
+
+def abort( problem ):
+ '''Print error message and exit'''
+ sys.stderr.write( '\n' )
+ sys.stderr.write( problem )
+ sys.stderr.write( '\n\n' )
+ sys.exit(2)
+
+def parseCommandline():
+ '''Analyze command line arguments'''
+ try:
+ options, patterns = getopt.getopt( sys.argv[1:], 'o:r:',
+ ['version', 'output=', 'runner=', 'gui=',
+ 'error-printer', 'abort-on-fail', 'have-std', 'no-std',
+ 'have-eh', 'no-eh', 'template=', 'include=',
+ 'root', 'part', 'no-static-init', 'factor', 'longlong='] )
+ except getopt.error, problem:
+ usage( problem )
+ setOptions( options )
+ return setFiles( patterns )
+
+def setOptions( options ):
+ '''Set options specified on command line'''
+ global outputFileName, templateFileName, runner, gui, haveStandardLibrary, factor, longlong
+ global haveExceptionHandling, noExceptionHandling, abortOnFail, headers, root, part, noStaticInit
+ for o, a in options:
+ if o in ('-v', '--version'):
+ printVersion()
+ elif o in ('-o', '--output'):
+ outputFileName = a
+ elif o == '--template':
+ templateFileName = a
+ elif o == '--runner':
+ runner = a
+ elif o == '--gui':
+ gui = a
+ elif o == '--include':
+ if not re.match( r'^["<].*[>"]$', a ):
+ a = ('"%s"' % a)
+ headers.append( a )
+ elif o == '--error-printer':
+ runner = 'ErrorPrinter'
+ haveStandardLibrary = 1
+ elif o == '--abort-on-fail':
+ abortOnFail = 1
+ elif o == '--have-std':
+ haveStandardLibrary = 1
+ elif o == '--no-std':
+ noStandardLibrary = 1
+ elif o == '--have-eh':
+ haveExceptionHandling = 1
+ elif o == '--no-eh':
+ noExceptionHandling = 1
+ elif o == '--root':
+ root = 1
+ elif o == '--part':
+ part = 1
+ elif o == '--no-static-init':
+ noStaticInit = 1
+ elif o == '--factor':
+ factor = 1
+ elif o == '--longlong':
+ if a:
+ longlong = a
+ else:
+ longlong = 'long long'
+
+ if noStaticInit and (root or part):
+ abort( '--no-static-init cannot be used with --root/--part' )
+
+ if gui and not runner:
+ runner = 'StdioPrinter'
+
+def printVersion():
+ '''Print CxxTest version and exit'''
+ sys.stdout.write( "This is CxxTest version 3.10.1.\n" )
+ sys.exit(0)
+
+def setFiles( patterns ):
+ '''Set input files specified on command line'''
+ files = expandWildcards( patterns )
+ if len(files) is 0 and not root:
+ usage( "No input files found" )
+ return files
+
+def expandWildcards( patterns ):
+ '''Expand all wildcards in an array (glob)'''
+ fileNames = []
+ for pathName in patterns:
+ patternFiles = glob.glob( pathName )
+ for fileName in patternFiles:
+ fileNames.append( fixBackslashes( fileName ) )
+ return fileNames
+
+def fixBackslashes( fileName ):
+ '''Convert backslashes to slashes in file name'''
+ return re.sub( r'\\', '/', fileName, 0 )
+
+def scanInputFiles(files):
+ '''Scan all input files for test suites'''
+ for file in files:
+ scanInputFile(file)
+ global suites
+ if len(suites) is 0 and not root:
+ abort( 'No tests defined' )
+
+def scanInputFile(fileName):
+ '''Scan single input file for test suites'''
+ file = open(fileName)
+ lineNo = 0
+ while 1:
+ line = file.readline()
+ if not line:
+ break
+ lineNo = lineNo + 1
+
+ scanInputLine( fileName, lineNo, line )
+ closeSuite()
+ file.close()
+
+def scanInputLine( fileName, lineNo, line ):
+ '''Scan single input line for interesting stuff'''
+ scanLineForExceptionHandling( line )
+ scanLineForStandardLibrary( line )
+
+ scanLineForSuiteStart( fileName, lineNo, line )
+
+ global suite
+ if suite:
+ scanLineInsideSuite( suite, lineNo, line )
+
+def scanLineInsideSuite( suite, lineNo, line ):
+ '''Analyze line which is part of a suite'''
+ global inBlock
+ if lineBelongsToSuite( suite, lineNo, line ):
+ scanLineForTest( suite, lineNo, line )
+ scanLineForCreate( suite, lineNo, line )
+ scanLineForDestroy( suite, lineNo, line )
+
+def lineBelongsToSuite( suite, lineNo, line ):
+ '''Returns whether current line is part of the current suite.
+ This can be false when we are in a generated suite outside of CXXTEST_CODE() blocks
+ If the suite is generated, adds the line to the list of lines'''
+ if not suite['generated']:
+ return 1
+
+ global inBlock
+ if not inBlock:
+ inBlock = lineStartsBlock( line )
+ if inBlock:
+ inBlock = addLineToBlock( suite, lineNo, line )
+ return inBlock
+
+
+std_re = re.compile( r"\b(std\s*::|CXXTEST_STD|using\s+namespace\s+std\b|^\s*\#\s*include\s+<[a-z0-9]+>)" )
+def scanLineForStandardLibrary( line ):
+ '''Check if current line uses standard library'''
+ global haveStandardLibrary, noStandardLibrary
+ if not haveStandardLibrary and std_re.search(line):
+ if not noStandardLibrary:
+ haveStandardLibrary = 1
+
+exception_re = re.compile( r"\b(throw|try|catch|TSM?_ASSERT_THROWS[A-Z_]*)\b" )
+def scanLineForExceptionHandling( line ):
+ '''Check if current line uses exception handling'''
+ global haveExceptionHandling, noExceptionHandling
+ if not haveExceptionHandling and exception_re.search(line):
+ if not noExceptionHandling:
+ haveExceptionHandling = 1
+
+suite_re = re.compile( r'\bclass\s+(\w+)\s*:\s*public\s+((::)?\s*CxxTest\s*::\s*)?TestSuite\b' )
+generatedSuite_re = re.compile( r'\bCXXTEST_SUITE\s*\(\s*(\w*)\s*\)' )
+def scanLineForSuiteStart( fileName, lineNo, line ):
+ '''Check if current line starts a new test suite'''
+ m = suite_re.search( line )
+ if m:
+ startSuite( m.group(1), fileName, lineNo, 0 )
+ m = generatedSuite_re.search( line )
+ if m:
+ sys.stdout.write( "%s:%s: Warning: Inline test suites are deprecated.\n" % (fileName, lineNo) )
+ startSuite( m.group(1), fileName, lineNo, 1 )
+
+def startSuite( name, file, line, generated ):
+ '''Start scanning a new suite'''
+ global suite
+ closeSuite()
+ suite = { 'name' : name,
+ 'file' : file,
+ 'cfile' : cstr(file),
+ 'line' : line,
+ 'generated' : generated,
+ 'object' : 'suite_%s' % name,
+ 'dobject' : 'suiteDescription_%s' % name,
+ 'tlist' : 'Tests_%s' % name,
+ 'tests' : [],
+ 'lines' : [] }
+
+def lineStartsBlock( line ):
+ '''Check if current line starts a new CXXTEST_CODE() block'''
+ return re.search( r'\bCXXTEST_CODE\s*\(', line ) is not None
+
+test_re = re.compile( r'^([^/]|/[^/])*\bvoid\s+([Tt]est\w+)\s*\(\s*(void)?\s*\)' )
+def scanLineForTest( suite, lineNo, line ):
+ '''Check if current line starts a test'''
+ m = test_re.search( line )
+ if m:
+ addTest( suite, m.group(2), lineNo )
+
+def addTest( suite, name, line ):
+ '''Add a test function to the current suite'''
+ test = { 'name' : name,
+ 'suite' : suite,
+ 'class' : 'TestDescription_%s_%s' % (suite['name'], name),
+ 'object' : 'testDescription_%s_%s' % (suite['name'], name),
+ 'line' : line,
+ }
+ suite['tests'].append( test )
+
+def addLineToBlock( suite, lineNo, line ):
+ '''Append the line to the current CXXTEST_CODE() block'''
+ line = fixBlockLine( suite, lineNo, line )
+ line = re.sub( r'^.*\{\{', '', line )
+
+ e = re.search( r'\}\}', line )
+ if e:
+ line = line[:e.start()]
+ suite['lines'].append( line )
+ return e is None
+
+def fixBlockLine( suite, lineNo, line):
+ '''Change all [E]TS_ macros used in a line to _[E]TS_ macros with the correct file/line'''
+ return re.sub( r'\b(E?TSM?_(ASSERT[A-Z_]*|FAIL))\s*\(',
+ r'_\1(%s,%s,' % (suite['cfile'], lineNo),
+ line, 0 )
+
+create_re = re.compile( r'\bstatic\s+\w+\s*\*\s*createSuite\s*\(\s*(void)?\s*\)' )
+def scanLineForCreate( suite, lineNo, line ):
+ '''Check if current line defines a createSuite() function'''
+ if create_re.search( line ):
+ addSuiteCreateDestroy( suite, 'create', lineNo )
+
+destroy_re = re.compile( r'\bstatic\s+void\s+destroySuite\s*\(\s*\w+\s*\*\s*\w*\s*\)' )
+def scanLineForDestroy( suite, lineNo, line ):
+ '''Check if current line defines a destroySuite() function'''
+ if destroy_re.search( line ):
+ addSuiteCreateDestroy( suite, 'destroy', lineNo )
+
+def cstr( str ):
+ '''Convert a string to its C representation'''
+ return '"' + string.replace( str, '\\', '\\\\' ) + '"'
+
+
+def addSuiteCreateDestroy( suite, which, line ):
+ '''Add createSuite()/destroySuite() to current suite'''
+ if suite.has_key(which):
+ abort( '%s:%s: %sSuite() already declared' % ( suite['file'], str(line), which ) )
+ suite[which] = line
+
+def closeSuite():
+ '''Close current suite and add it to the list if valid'''
+ global suite
+ if suite is not None:
+ if len(suite['tests']) is not 0:
+ verifySuite(suite)
+ rememberSuite(suite)
+ suite = None
+
+def verifySuite(suite):
+ '''Verify current suite is legal'''
+ if suite.has_key('create') and not suite.has_key('destroy'):
+ abort( '%s:%s: Suite %s has createSuite() but no destroySuite()' %
+ (suite['file'], suite['create'], suite['name']) )
+ if suite.has_key('destroy') and not suite.has_key('create'):
+ abort( '%s:%s: Suite %s has destroySuite() but no createSuite()' %
+ (suite['file'], suite['destroy'], suite['name']) )
+
+def rememberSuite(suite):
+ '''Add current suite to list'''
+ global suites
+ suites.append( suite )
+
+def writeOutput():
+ '''Create output file'''
+ if templateFileName:
+ writeTemplateOutput()
+ else:
+ writeSimpleOutput()
+
+def writeSimpleOutput():
+ '''Create output not based on template'''
+ output = startOutputFile()
+ writePreamble( output )
+ writeMain( output )
+ writeWorld( output )
+ output.close()
+
+include_re = re.compile( r"\s*\#\s*include\s+<cxxtest/" )
+preamble_re = re.compile( r"^\s*<CxxTest\s+preamble>\s*$" )
+world_re = re.compile( r"^\s*<CxxTest\s+world>\s*$" )
+def writeTemplateOutput():
+ '''Create output based on template file'''
+ template = open(templateFileName)
+ output = startOutputFile()
+ while 1:
+ line = template.readline()
+ if not line:
+ break;
+ if include_re.search( line ):
+ writePreamble( output )
+ output.write( line )
+ elif preamble_re.search( line ):
+ writePreamble( output )
+ elif world_re.search( line ):
+ writeWorld( output )
+ else:
+ output.write( line )
+ template.close()
+ output.close()
+
+def startOutputFile():
+ '''Create output file and write header'''
+ if outputFileName is not None:
+ output = open( outputFileName, 'w' )
+ else:
+ output = sys.stdout
+ output.write( "/* Generated file, do not edit */\n\n" )
+ return output
+
+wrotePreamble = 0
+def writePreamble( output ):
+ '''Write the CxxTest header (#includes and #defines)'''
+ global wrotePreamble, headers, longlong
+ if wrotePreamble: return
+ output.write( "#ifndef CXXTEST_RUNNING\n" )
+ output.write( "#define CXXTEST_RUNNING\n" )
+ output.write( "#endif\n" )
+ output.write( "\n" )
+ if haveStandardLibrary:
+ output.write( "#define _CXXTEST_HAVE_STD\n" )
+ if haveExceptionHandling:
+ output.write( "#define _CXXTEST_HAVE_EH\n" )
+ if abortOnFail:
+ output.write( "#define _CXXTEST_ABORT_TEST_ON_FAIL\n" )
+ if longlong:
+ output.write( "#define _CXXTEST_LONGLONG %s\n" % longlong )
+ if factor:
+ output.write( "#define _CXXTEST_FACTOR\n" )
+ for header in headers:
+ output.write( "#include %s\n" % header )
+ output.write( "#include <cxxtest/TestListener.h>\n" )
+ output.write( "#include <cxxtest/TestTracker.h>\n" )
+ output.write( "#include <cxxtest/TestRunner.h>\n" )
+ output.write( "#include <cxxtest/RealDescriptions.h>\n" )
+ if runner:
+ output.write( "#include <cxxtest/%s.h>\n" % runner )
+ if gui:
+ output.write( "#include <cxxtest/%s.h>\n" % gui )
+ output.write( "\n" )
+ wrotePreamble = 1
+
+def writeMain( output ):
+ '''Write the main() function for the test runner'''
+ if gui:
+ output.write( 'int main( int argc, char *argv[] ) {\n' )
+ if noStaticInit:
+ output.write( ' CxxTest::initialize();\n' )
+ output.write( ' return CxxTest::GuiTuiRunner<CxxTest::%s, CxxTest::%s>( argc, argv ).run();\n' % (gui, runner) )
+ output.write( '}\n' )
+ elif runner:
+ output.write( 'int main() {\n' )
+ if noStaticInit:
+ output.write( ' CxxTest::initialize();\n' )
+ output.write( ' return CxxTest::%s().run();\n' % runner )
+ output.write( '}\n' )
+
+wroteWorld = 0
+def writeWorld( output ):
+ '''Write the world definitions'''
+ global wroteWorld, part
+ if wroteWorld: return
+ writePreamble( output )
+ writeSuites( output )
+ if root or not part:
+ writeRoot( output )
+ if noStaticInit:
+ writeInitialize( output )
+ wroteWorld = 1
+
+def writeSuites(output):
+ '''Write all TestDescriptions and SuiteDescriptions'''
+ for suite in suites:
+ writeInclude( output, suite['file'] )
+ if isGenerated(suite):
+ generateSuite( output, suite )
+ if isDynamic(suite):
+ writeSuitePointer( output, suite )
+ else:
+ writeSuiteObject( output, suite )
+ writeTestList( output, suite )
+ writeSuiteDescription( output, suite )
+ writeTestDescriptions( output, suite )
+
+def isGenerated(suite):
+ '''Checks whether a suite class should be created'''
+ return suite['generated']
+
+def isDynamic(suite):
+ '''Checks whether a suite is dynamic'''
+ return suite.has_key('create')
+
+lastIncluded = ''
+def writeInclude(output, file):
+ '''Add #include "file" statement'''
+ global lastIncluded
+ if file == lastIncluded: return
+ output.writelines( [ '#include "', file, '"\n\n' ] )
+ lastIncluded = file
+
+def generateSuite( output, suite ):
+ '''Write a suite declared with CXXTEST_SUITE()'''
+ output.write( 'class %s : public CxxTest::TestSuite {\n' % suite['name'] )
+ output.write( 'public:\n' )
+ for line in suite['lines']:
+ output.write(line)
+ output.write( '};\n\n' )
+
+def writeSuitePointer( output, suite ):
+ '''Create static suite pointer object for dynamic suites'''
+ if noStaticInit:
+ output.write( 'static %s *%s;\n\n' % (suite['name'], suite['object']) )
+ else:
+ output.write( 'static %s *%s = 0;\n\n' % (suite['name'], suite['object']) )
+
+def writeSuiteObject( output, suite ):
+ '''Create static suite object for non-dynamic suites'''
+ output.writelines( [ "static ", suite['name'], " ", suite['object'], ";\n\n" ] )
+
+def writeTestList( output, suite ):
+ '''Write the head of the test linked list for a suite'''
+ if noStaticInit:
+ output.write( 'static CxxTest::List %s;\n' % suite['tlist'] )
+ else:
+ output.write( 'static CxxTest::List %s = { 0, 0 };\n' % suite['tlist'] )
+
+def writeTestDescriptions( output, suite ):
+ '''Write all test descriptions for a suite'''
+ for test in suite['tests']:
+ writeTestDescription( output, suite, test )
+
+def writeTestDescription( output, suite, test ):
+ '''Write test description object'''
+ output.write( 'static class %s : public CxxTest::RealTestDescription {\n' % test['class'] )
+ output.write( 'public:\n' )
+ if not noStaticInit:
+ output.write( ' %s() : CxxTest::RealTestDescription( %s, %s, %s, "%s" ) {}\n' %
+ (test['class'], suite['tlist'], suite['dobject'], test['line'], test['name']) )
+ output.write( ' void runTest() { %s }\n' % runBody( suite, test ) )
+ output.write( '} %s;\n\n' % test['object'] )
+
+def runBody( suite, test ):
+ '''Body of TestDescription::run()'''
+ if isDynamic(suite): return dynamicRun( suite, test )
+ else: return staticRun( suite, test )
+
+def dynamicRun( suite, test ):
+ '''Body of TestDescription::run() for test in a dynamic suite'''
+ return 'if ( ' + suite['object'] + ' ) ' + suite['object'] + '->' + test['name'] + '();'
+
+def staticRun( suite, test ):
+ '''Body of TestDescription::run() for test in a non-dynamic suite'''
+ return suite['object'] + '.' + test['name'] + '();'
+
+def writeSuiteDescription( output, suite ):
+ '''Write SuiteDescription object'''
+ if isDynamic( suite ):
+ writeDynamicDescription( output, suite )
+ else:
+ writeStaticDescription( output, suite )
+
+def writeDynamicDescription( output, suite ):
+ '''Write SuiteDescription for a dynamic suite'''
+ output.write( 'CxxTest::DynamicSuiteDescription<%s> %s' % (suite['name'], suite['dobject']) )
+ if not noStaticInit:
+ output.write( '( %s, %s, "%s", %s, %s, %s, %s )' %
+ (suite['cfile'], suite['line'], suite['name'], suite['tlist'],
+ suite['object'], suite['create'], suite['destroy']) )
+ output.write( ';\n\n' )
+
+def writeStaticDescription( output, suite ):
+ '''Write SuiteDescription for a static suite'''
+ output.write( 'CxxTest::StaticSuiteDescription %s' % suite['dobject'] )
+ if not noStaticInit:
+ output.write( '( %s, %s, "%s", %s, %s )' %
+ (suite['cfile'], suite['line'], suite['name'], suite['object'], suite['tlist']) )
+ output.write( ';\n\n' )
+
+def writeRoot(output):
+ '''Write static members of CxxTest classes'''
+ output.write( '#include <cxxtest/Root.cpp>\n' )
+
+def writeInitialize(output):
+ '''Write CxxTest::initialize(), which replaces static initialization'''
+ output.write( 'namespace CxxTest {\n' )
+ output.write( ' void initialize()\n' )
+ output.write( ' {\n' )
+ for suite in suites:
+ output.write( ' %s.initialize();\n' % suite['tlist'] )
+ if isDynamic(suite):
+ output.write( ' %s = 0;\n' % suite['object'] )
+ output.write( ' %s.initialize( %s, %s, "%s", %s, %s, %s, %s );\n' %
+ (suite['dobject'], suite['cfile'], suite['line'], suite['name'],
+ suite['tlist'], suite['object'], suite['create'], suite['destroy']) )
+ else:
+ output.write( ' %s.initialize( %s, %s, "%s", %s, %s );\n' %
+ (suite['dobject'], suite['cfile'], suite['line'], suite['name'],
+ suite['object'], suite['tlist']) )
+
+ for test in suite['tests']:
+ output.write( ' %s.initialize( %s, %s, %s, "%s" );\n' %
+ (test['object'], suite['tlist'], suite['dobject'], test['line'], test['name']) )
+
+ output.write( ' }\n' )
+ output.write( '}\n' )
+
+main()
diff --git a/test/cxxtest/docs/convert.pl b/test/cxxtest/docs/convert.pl
new file mode 100644
index 0000000000..9d83f1c0cf
--- /dev/null
+++ b/test/cxxtest/docs/convert.pl
@@ -0,0 +1,83 @@
+#!/usr/bin/perl
+
+die "Usage: $0 <text file> <html file> <TexInfo file>\n"
+ unless scalar @ARGV == 3;
+
+my ($text, $html, $texi) = @ARGV;
+
+open TEXT, "<$text" or die "Cannot open text file \"$text\"\n";
+open HTML, ">$html" or die "Cannot create html file \"$html\"\n";
+open TEXI, ">$texi" or die "Cannot create TexInfo file \"$texi\"\n";
+
+print HTML "<html>";
+
+sub analyze($) {
+ my ($line) = @_;
+ my ($htmlLine, $texiLine) = ($line, $line);
+
+ # command line options
+ $texiLine =~ s/ (--?[a-z-]*)/ \@option{$1}/g;
+ $htmlLine =~ s/ (--?[a-z-]*)/ <tt>$1<\/tt>/g;
+
+ # [Class::]function()
+ $texiLine =~ s/([^A-Za-z])(([A-Z][A-Za-z0-9]*::)?[A-Za-z0-9]+\(\))/$1\@code{$2}/g;
+ $htmlLine =~ s/([^A-Za-z])(([A-Z][A-Za-z0-9]*::)?[A-Za-z0-9]+\(\))/$1<code>$2<\/code>/g;
+
+ # `file'
+ $texiLine =~ s/`([A-Za-z.\/]*)'/\@file{$1}/g;
+ $htmlLine =~ s/`([A-Za-z.\/]*)'/<tt>`$1'<\/tt>/g;
+
+ # TS...
+ $texiLine =~ s/(^|[^A-Z])(TS[A-Za-z_*()]*)/$1\@code{$2}/g;
+ $htmlLine =~ s/(^|[^A-Z])(TS[A-Za-z_*()]*)/$1<code>$2<\/code>/g;
+
+ # CXXTEST_
+ $texiLine =~ s/(CXXTEST_[A-Z_]*)/\@code{$1}/g;
+ $htmlLine =~ s/(CXXTEST_[A-Z_]*)/<tt>$1<\/tt>/g;
+
+ return ($htmlLine, $texiLine);
+}
+
+my $line;
+my $inRelease = 0;
+while ( defined( $line = <TEXT> ) ) {
+ chomp $line;
+ if ( $line =~ m/^CxxTest Releases/ ) {
+ print HTML "<title>CxxTest Releases</title>\n";
+ print HTML "<h1>CxxTest Releases</h1>\n\n";
+
+ print TEXI "\@appendix Version history\n";
+ print TEXI "\@itemize \@bullet\n";
+ }
+ elsif ( $line =~ m/^(.*):$/ ) {
+ if ( $inRelease ) {
+ print HTML "</ul>\n\n";
+ print TEXI "\@end itemize\n";
+ }
+
+ print HTML "<h2>$1</h2>\n";
+ print HTML "<ul>\n";
+
+ print TEXI "\@item\n\@strong{$1}\n";
+ print TEXI "\@itemize \@minus\n";
+
+ $inRelease = 1;
+ }
+ elsif ( $line =~ m/^ - (.*)$/ ) {
+ my ($htmlLine, $texiLine) = analyze($1);
+ print HTML "<li>$htmlLine</li>\n";
+ print TEXI "\@item\n$texiLine\n";
+ }
+}
+
+if ( $inRelease ) {
+ print HTML "</ul>\n\n";
+ print TEXI "\@end itemize\n\n";
+}
+
+print HTML "</html>\n";
+print TEXI "\@end itemize\n";
+
+close TEXT or die "Error closing text file \"$text\"\n";
+close HTML or die "Error closing html file \"$html\"\n";
+close TEXI or die "Error closing TexInfo file \"$texi\"\n";
diff --git a/test/cxxtest/docs/guide.html b/test/cxxtest/docs/guide.html
new file mode 100644
index 0000000000..fb435fb8f1
--- /dev/null
+++ b/test/cxxtest/docs/guide.html
@@ -0,0 +1,1960 @@
+<html lang="en">
+<head>
+<title>CxxTest User's Guide</title>
+<meta http-equiv="Content-Type" content="text/html">
+<meta name="description" content="CxxTest User's Guide">
+<meta name="generator" content="makeinfo 4.3">
+<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
+</head>
+<body>
+<h1 class="settitle">CxxTest User's Guide</h1>
+<a href="#contents">Table of contents</a>
+
+<h2 class="chapter"><a name="TOC0"></a>1 Introduction</h2>
+
+ <p>CxxTest is a <a href="http://junit.org/">JUnit</a>/<a href="http://cppunit.sourceforge.net">CppUnit</a>/<a href="http://xprogramming.com/software.html">xUnit</a>-like framework for C++.
+
+ <p>Its advantages over existing alternatives are that it:
+ <ul>
+<li>Doesn't require RTTI
+<li>Doesn't require member template functions
+<li>Doesn't require exception handling
+<li>Doesn't require any external libraries (including memory management, file/console I/O, graphics libraries)
+</ul>
+ In other words, CxxTest is designed to be as portable as possible. Its
+only requirements are a reasonably modern C++ compiler and either Perl
+or Python. However, when advanced features are supported in your
+environment, CxxTest can use them, e.g. catch unhandled exceptions and
+even display a GUI.
+
+ <p>In addition, CxxTest is slightly easier to use than the C++
+alternatives, since you don't need to "register" your tests. It also
+features some extras like a richer set of assertions and even support
+for a "to do" list (see <a href="#warn"><code>TS_WARN(</code><em></em><code>)</code></a>).
+
+ <p>CxxTest is available under the
+<a href="http://www.gnu.org/copyleft/lesser.html">GNU Lesser General Public License</a>.
+
+<h3 class="section"><a name="TOC1"></a>1.1 About this guide</h3>
+
+ <p>This guide is not intended as an introduction to Extreme Progamming
+and/or unit testing. It describes the design and usage of CxxTest.
+
+<h2 class="chapter"><a name="TOC2"></a>2 Getting started</h2>
+
+<h3 class="section"><a name="TOC3"></a>2.1 Getting CxxTest</h3>
+
+ <p>The homepage for CxxTest is <a href="http://cxxtest.sourceforge.net">http://cxxtest.sourceforge.net</a>. You
+can always get the latest release from the SourceForge download page,
+<a href="http://sourceforge.net/project/showfiles.php?group_id=52834">here</a>
+or <a href="http://dl.sourceforge.net/cxxtest">here</a>. The latest version
+of this guide is available online at
+<a href="http://cxxtest.sourceforge.net/guide.html">http://cxxtest.sourceforge.net/guide.html</a>. A PDF version is also
+available at <a href="http://cxxtest.sourceforge.net/guide.pdf">http://cxxtest.sourceforge.net/guide.pdf</a>.
+
+<h3 class="section"><a name="TOC4"></a>2.2 Your first test!</h3>
+
+ <p>Here's a simple step-by-step guide:
+
+ <ol type=1 start=1>
+
+ <li>Tests are organized into "Test Suites".
+ Test suites are written in header files.
+
+ <p>A test suite is a class that inherits from <code>CxxTest::TestSuite</code>.
+ A test is a public <code>void (void)</code> member function of that class whose name starts with <code>test</code>,
+ e.g. <code>testDirectoryScanner()</code>, <code>test_cool_feature()</code> and even <code>TestImportantBugFix()</code>.
+
+ <pre class="smallexample">
+ <pre class="verbatim">
+ // MyTestSuite.h
+ #include &lt;cxxtest/TestSuite.h>
+
+ class MyTestSuite : public CxxTest::TestSuite
+ {
+ public:
+ void testAddition( void )
+ {
+ TS_ASSERT( 1 + 1 > 1 );
+ TS_ASSERT_EQUALS( 1 + 1, 2 );
+ }
+ };
+ </pre>
+ </pre>
+
+ </p><li>After you have your test suites, you use CxxTest to generate a "test runner" source file:
+
+ <pre class="verbatim">
+ # cxxtestgen.pl --error-printer -o runner.cpp MyTestSuite.h
+ </pre>
+
+ <p>or, for those less fortunate:
+
+ <pre class="verbatim">
+ C:\tmp> perl -w cxxtestgen.pl --error-printer -o runner.cpp MyTestSuite.h
+ </pre>
+
+ </p><li>You would then simply compile the resulting file:
+
+ <pre class="verbatim">
+ # g++ -o runner runner.cpp
+ </pre>
+
+ <p>or perhaps
+
+ <pre class="verbatim">
+ C:\tmp> cl -GX -o runner.exe runner.cpp
+ </pre>
+
+ <p>or maybe even
+
+ <pre class="verbatim">
+ C:\tmp> bcc32 -erunner.exe runner.cpp
+ </pre>
+
+ </p><li>Finally, you run the tests and enjoy a well tested piece of software:
+
+ <pre class="verbatim">
+ # ./runner
+ Running 1 test.OK!
+ </pre>
+
+ </ol>
+
+<h3 class="section"><a name="TOC5"></a>2.3 Your second test</h3>
+
+ <p>Now let's see what failed tests look like.
+We will add a failing test to the previous example:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ // MyTestSuite.h
+ #include &lt;cxxtest/TestSuite.h>
+
+ class MyTestSuite : public CxxTest::TestSuite
+ {
+ public:
+ void testAddition( void )
+ {
+ TS_ASSERT( 1 + 1 > 1 );
+ TS_ASSERT_EQUALS( 1 + 1, 2 );
+ }
+
+ void testMultiplication( void )
+ {
+ TS_ASSERT_EQUALS( 2 * 2, 5 );
+ }
+ };
+ </pre>
+ </pre>
+
+ <p>Generate, compile and run the test runner, and you will get this:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ # ./runner
+ Running 2 tests.
+ MyTestSuite.h:15: Expected (2 * 2 == 5), found (4 != 5)
+ Failed 1 of 2 tests
+ Success rate: 50%
+ </pre>
+ </pre>
+
+ <p>Fixing the bug is left as an excercise to the reader.
+
+<h3 class="section"><a name="TOC6"></a>2.4 Graphical user interface</h3>
+
+ <font size=-2>(v3.0.1)</font>
+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:
+ <ul>
+
+ <li>Under Windows with Visual C++, run <code>perl cxxtestgen.pl -o&nbsp;runner.cpp
+</code><em>--gui=Win32Gui</em><code> MyTestSuite.h</code>.
+
+ <li>Under X-Windows, try <code>./cxxtestgen.pl -o&nbsp;runner.cpp
+</code><em>--gui=X11Gui</em><code> MyTestSuite</code>. You may need to tell the compiler
+where to find X, usually something like <code>g++ -o&nbsp;runner
+-L/usr/X11R6/lib runner.cpp -lX11</code>.
+
+ <li>If you have <a href="http://www.trolltech.com">Qt</a> installed, try running
+<code>cxxtestgen.pl</code> with the option <code>--gui=QtGui</code>. As
+always, compile and link the the Qt headers and libraries.
+
+ </ul>
+
+ <p>See <a href="#GUI">Graphical user interface</a> and <a href="#samples">Running the samples</a> for
+more information.
+
+<h2 class="chapter"><a name="TOC7"></a>3 <em>Really</em> using CxxTest</h2>
+
+ <p>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.
+
+<h3 class="section"><a name="TOC8"></a>3.1 What can you test</h3>
+
+ <p>Here are the different "assertions" you can use in your tests:
+
+ <p><table><tr align="left"><td valign="top"><strong>Macro</strong> </td><td valign="top"><strong>Description</strong> </td><td valign="top"><strong>Example</strong>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#fail"><code>TS_FAIL(</code><em>message</em><code>)</code></a>
+</td><td valign="top">Fail unconditionally
+</td><td valign="top"><code>TS_FAIL("Test not implemented");</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#assert"><code>TS_ASSERT(</code><em>expr</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>(expr)</em><code></code> is true
+</td><td valign="top"><code>TS_ASSERT(messageReceived());</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#equals"><code>TS_ASSERT_EQUALS(</code><em>x, y</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>(x==y)</em><code></code>
+</td><td valign="top"><code>TS_ASSERT_EQUALS(nodeCount(), 14);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#sameData"><code>TS_ASSERT_SAME_DATA(</code><em>x, y, size</em><code>)</code></a>
+</td><td valign="top">Verify two buffers are equal
+</td><td valign="top"><code>TS_ASSERT_SAME_DATA(input, output,, size);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#delta"><code>TS_ASSERT_DELTA(</code><em>x, y, d</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>(x==y)</em><code></code> up to <code></code><em>d</em><code></code>
+</td><td valign="top"><code>TS_ASSERT_DELTA(sqrt(4.0), 2.0, 0.0001);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#differs"><code>TS_ASSERT_DIFFERS(</code><em>x, y</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>!(x==y)</em><code></code>
+</td><td valign="top"><code>TS_ASSERT_DIFFERS(exam.numTook(), exam.numPassed());</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#lessthan"><code>TS_ASSERT_LESS_THAN(</code><em>x, y</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>(x&lt;y)</em><code></code>
+</td><td valign="top"><code>TS_ASSERT_LESS_THAN(ship.speed(), SPEED_OF_LIGHT);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#lte"><code>TS_ASSERT_LESS_THAN_EQUALS(</code><em>x, y</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>(x&lt;=y)</em><code></code>
+</td><td valign="top"><code>TS_ASSERT_LESS_THAN_EQUALS(requests, items);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#predicate"><code>TS_ASSERT_PREDICATE(</code><em>R, x</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>P(x)</em><code></code>
+</td><td valign="top"><code>TS_ASSERT_PREDICATE(SeemsReasonable, salary);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#relation"><code>TS_ASSERT_RELATION(</code><em>R, x, y</em><code>)</code></a>
+</td><td valign="top">Verify <code></code><em>x R y</em><code></code>
+</td><td valign="top"><code>TS_ASSERT_RELATION(std::greater, salary, average);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#throwsx"><code>TS_ASSERT_THROWS(</code><em>expr, type</em><code>)</code></a>
+</td><td valign="top">Verify that <code></code><em>(expr)</em><code></code> throws a specific type of exception
+</td><td valign="top"><code>TS_ASSERT_THROWS(parse(file), Parser::ReadError);</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#throwsx"><code>TS_ASSERT_THROWS_EQUALS(</code><em>expr, arg, x, y</em><code>)</code></a>
+</td><td valign="top">Verify type and value of what <code></code><em>(expr)</em><code></code> throws
+</td><td valign="top">(See text)
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#throwsx"><code>TS_ASSERT_THROWS_ASSERT(</code><em>expr, arg, assertion</em><code>)</code></a>
+</td><td valign="top">Verify type and value of what <code></code><em>(expr)</em><code></code> throws
+</td><td valign="top">(See text)
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#throwsx"><code>TS_ASSERT_THROWS_ANYTHING(</code><em>expr</em><code>)</code></a>
+</td><td valign="top">Verify that <code></code><em>(expr)</em><code></code> throws an exception
+</td><td valign="top"><code>TS_ASSERT_THROWS_ANYTHING(buggy());</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#throwsx"><code>TS_ASSERT_THROWS_NOTHING(</code><em>expr</em><code>)</code></a>
+</td><td valign="top">Verify that <code></code><em>(expr)</em><code></code> doesn't throw anything
+</td><td valign="top"><code>TS_ASSERT_THROWS_NOTHING(robust());</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#warn"><code>TS_WARN(</code><em>message</em><code>)</code></a>
+</td><td valign="top">Print <code></code><em>message</em><code></code> as a warning
+</td><td valign="top"><code>TS_WARN("TODO: Check invalid parameters");</code>
+
+<br></td></tr><tr align="left"><td valign="top"><a href="#trace"><code>TS_TRACE(</code><em>message</em><code>)</code></a>
+</td><td valign="top">Print <code></code><em>message</em><code></code> as an informational message
+</td><td valign="top"><code>TS_TRACE(errno);</code>
+
+ <br></td></tr></table>
+
+<h4 class="subsection"><a name="TOC9"></a>3.1.1 <code>TS_FAIL</code></h4>
+
+ <p><a name="fail"></a>
+
+ <p><code>TS_FAIL</code> just fails the test.
+It is like an <code>assert(false)</code> with an error message.
+For example:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testSomething( void )
+ {
+ TS_FAIL( "I don't know how to test this!" );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC10"></a>3.1.2 <code>TS_ASSERT</code></h4>
+
+ <p><a name="assert"></a>
+
+ <p><code>TS_ASSERT</code> is the basic all-around tester. It works just like the
+well-respected <code>assert()</code> macro (which I sincerely hope you know and
+use!) An example:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testSquare( void )
+ {
+ MyFileLibrary::createEmptyFile( "test.bin" );
+ TS_ASSERT( access( "test.bin", 0 ) == 0 );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC11"></a>3.1.3 <code>TS_ASSERT_EQUALS</code></h4>
+
+ <p><a name="equals"></a>
+
+ <p>This is the second most useful tester.
+As the name hints, it is used to test if two values are equal.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testSquare( void )
+ {
+ TS_ASSERT_EQUALS( square(-5), 25 );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC12"></a>3.1.4 <code>TS_ASSERT_SAME_DATA</code></h4>
+
+ <p><a name="sameData"></a>
+
+ <font size=-2>(v3.5.1)</font>
+This assertion is similar to <a href="#equals"><code>TS_ASSERT_EQUALS(</code><em></em><code>)</code></a>, 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.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testCopyMemory( void )
+ {
+ char input[77], output[77];
+ myCopyMemory( output, input, 77 );
+ TS_ASSERT_SAME_DATA( input, output, 77 );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC13"></a>3.1.5 <code>TS_ASSERT_DELTA</code></h4>
+
+ <p><a name="delta"></a>
+
+ <p>Similar to <a href="#equals"><code>TS_ASSERT_EQUALS(</code><em></em><code>)</code></a>, this macro
+verifies two values are equal up to a delta.
+This is basically used for floating-point values.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testSquareRoot( void )
+ {
+ TS_ASSERT_DELTA( squareRoot(4.0), 2.0, 0.00001 );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC14"></a>3.1.6 <code>TS_ASSERT_DIFFERS</code></h4>
+
+ <p><a name="differs"></a>
+
+ <p>The opposite of <a href="#equals"><code>TS_ASSERT_EQUALS(</code><em></em><code>)</code></a>, this macro is used to assert
+that two values are not equal.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testNumberGenerator( void )
+ {
+ int first = generateNumber();
+ int second = generateNumber();
+ TS_ASSERT_DIFFERS( first, second );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC15"></a>3.1.7 <code>TS_ASSERT_LESS_THAN</code></h4>
+
+ <p><a name="lessthan"></a>
+
+ <p>This macro asserts that the first operand is less than the second.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testFindLargerNumber( void )
+ {
+ TS_ASSERT_LESS_THAN( 23, findLargerNumber(23) );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC16"></a>3.1.8 <code>TS_ASSERT_LESS_THAN_EQUALS</code></h4>
+
+ <p><a name="lte"></a>
+
+ <font size=-2>(v3.7.0)</font>
+Not surprisingly, this macro asserts that the first operand is less than or equals the second.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testBufferSize( void )
+ {
+ TS_ASSERT_LESS_THAN_EQUALS( bufferSize(), MAX_BUFFER_SIZE );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC17"></a>3.1.9 <code>TS_ASSERT_PREDICATE</code></h4>
+
+ <p><a name="predicate"></a>
+
+ <font size=-2>(v3.8.2)</font>
+This macro can be seen as a generalization of
+<a href="#assert"><code>TS_ASSERT(</code><em></em><code>)</code></a>. It takes as an argument the name of a class,
+similar to an STL <code>unary_function</code>, and evaluates
+<code>operator()</code>. The advantage this has over
+<a href="#assert"><code>TS_ASSERT(</code><em></em><code>)</code></a> is that you can see the failed value.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ class IsPrime
+ {
+ public:
+ bool operator()( unsigned ) const;
+ };
+
+ // ...
+
+ void testPrimeGenerator( void )
+ {
+ TS_ASSERT_PREDICATE( IsPrime, generatePrime() );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC18"></a>3.1.10 <code>TS_ASSERT_RELATION</code></h4>
+
+ <p><a name="relation"></a>
+
+ <font size=-2>(v3.8.0)</font>
+Closely related to
+<a href="#predicate"><code>TS_ASSERT_PREDICATE(</code><em></em><code>)</code></a>, this macro can be seen as a
+generalization of <a href="#equals"><code>TS_ASSERT_EQUALS(</code><em></em><code>)</code></a>,
+<a href="#differs"><code>TS_ASSERT_DIFFERS(</code><em></em><code>)</code></a>,
+<a href="#lessthan"><code>TS_ASSERT_LESS_THAN(</code><em></em><code>)</code></a> and
+<a href="#lte"><code>TS_ASSERT_LESS_THAN_EQUALS(</code><em></em><code>)</code></a>. It takes as an argument the
+name of a class, similar to an STL <code>binary_function</code>, and evaluates
+<code>operator()</code>. This can be used to very simply assert comparisons
+which are not covered by the builtin macros.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testGreater( void )
+ {
+ TS_ASSERT_RELATION( std::greater&lt;int>, ticketsSold(), 1000 );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC19"></a>3.1.11 <code>TS_ASSERT_THROWS</code> and friends</h4>
+
+ <p><a name="throwsx"></a>
+
+ <p>These assertions are used to test whether an expression throws an exception.
+<code>TS_ASSERT_THROWS</code> is used when you want to verify the type of exception
+thrown, and <code>TS_ASSERT_THROWS_ANYTHING</code> is used to just make sure something
+is thrown. As you might have guessed, <code>TS_ASSERT_THROWS_NOTHING</code> asserts
+that nothing is thrown.
+
+ <font size=-2>(v3.10.0)</font>
+<code>TS_ASSERT_THROWS_EQUALS</code> checks the type of the
+exception as in <code>TS_ASSERT_THROWS</code> then allows you to compare two
+value (one of which will presumably be the caught object).
+<code>TS_ASSERT_THROWS_ASSERT</code> 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.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testFunctionsWhichThrowExceptions( void )
+ {
+ TS_ASSERT_THROWS_NOTHING( checkInput(1) );
+ TS_ASSERT_THROWS( checkInput(-11), std::runtime_error );
+ TS_ASSERT_THROWS_ANYTHING( thirdPartyFunction() );
+
+ TS_ASSERT_THROWS_EQUALS( validate(), const std::exception &amp;e,
+ e.what(), "Invalid value" );
+ TS_ASSERT_THROWS_ASSERT( validate(), const Error &amp;e,
+ TS_ASSERT_DIFFERS( e.code(), SUCCESS ) );
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC20"></a>3.1.12 <code>TS_TRACE</code> and <code>TS_WARN</code></h4>
+
+ <p><a name="warn"></a>
+<a name="trace"></a>
+
+ <font size=-2>(v3.0.1)</font>
+<code>TS_WARN</code> just prints out a message, like the
+<code>#warning</code> preprocessor directive. I find it very useful for "to
+do" items. For example:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void testToDoList( void )
+ {
+ TS_WARN( "TODO: Write some tests!" );
+ TS_WARN( "TODO: Make $$$ fast!" );
+ }
+ </pre>
+ </pre>
+
+ <p>In the GUI, <code>TS_WARN</code> sets the bar color to yellow (unless it was
+already red).
+
+ <font size=-2>(v3.9.0)</font>
+<code>TS_TRACE</code> is the same, except that it
+doesn't change the color of the progress bar.
+
+<h4 class="subsection"><a name="TOC21"></a>3.1.13 The <code>ETS_</code> macros</h4>
+
+ <p>The <code>TS_</code> macros mentioned above will catch exceptions thrown from tested code
+and fail the test, as if you called <a href="#fail"><code>TS_FAIL(</code><em></em><code>)</code></a>.
+Sometimes, however, you may want to catch the exception yourself; when you do, you can
+use the <code>ETS_</code> versions of the macros.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ 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 &amp;e ) { TS_FAIL( e.bar() ); }
+ }
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC22"></a>3.1.14 The <code>TSM_</code> macros</h4>
+
+ <p>Sometimes the default output generated by the <code>ErrorPrinter</code> 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.
+
+ <p>In the example below (which is the file <code>sample/MessageTest.h</code> from the CxxTest distribution),
+we need the message feature to know which invocation of <code>checkValue()</code> failed:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ 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 );
+ TSM_ASSERT_EQUALS( message, value, value * value );
+ }
+ };
+ </pre>
+ </pre>
+
+<h5 class="subsubsection"><a name="TOC23"></a>3.1.14.1 The <code>ETSM_</code> macros</h5>
+
+ <p><strong>Note:</strong> As with normal asserts, all <code>TSM_</code> macros have their
+non-exception-safe counterparts, the <code>ETSM_</code> macros.
+
+<h3 class="section"><a name="TOC24"></a>3.2 Running the samples</h3>
+
+ <p><a name="samples"></a>
+
+ <p>CxxTest comes with some samples in the <code>sample/</code> subdirectory of
+the distribution. If you look in that directory, you will see three
+Makefiles: <code>Makefile.unix</code>, <code>Makefile.msvc</code> and
+<code>Makefile.bcc32</code> 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.
+
+ <p>If you are running under Windows, a good guess would be to run
+<code>nmake -fMakefile.msvc run_win32</code> (you may need to run
+<code>VCVARS32.BAT</code> first). Under Linux, <code>make
+-fMakefile.unix run_x11</code> should probably work.
+
+<h3 class="section"><a name="TOC25"></a>3.3 Test fixtures</h3>
+
+ <p>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.
+
+ <p>You can (and should) put all this code in a common place by overriding
+the virtual functions <code>TestSuite::setUp()</code> and
+<code>TestSuite::tearDown()</code>. <code>setUp()</code> will
+then be called before each test, and <code>tearDown()</code>
+after each test.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ class TestFileOps : public CxxTest::TestSuite
+ {
+ public:
+ void setUp() { mkdir( "playground" ); }
+ void tearDown() { system( "rm -Rf playground"); }
+
+ void testCreateFile()
+ {
+ FileCreator fc( "playground" );
+ fc.createFile( "test.bin" );
+ TS_ASSERT_EQUALS( access( "playground/test.bin", 0 ), 0 );
+ }
+ };
+ </pre>
+ </pre>
+
+ <p><strong>Note new users:</strong> This is probably the single most important
+feature to use when your tests become non-trivial.
+
+<h4 class="subsection"><a name="TOC26"></a>3.3.1 Test suite level fixtures</h4>
+
+ <p><code>setUp()</code>/<code>tearDown()</code> 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
+<a href="#dynamic">Dynamically creating test suites</a> below.
+
+<h3 class="section"><a name="TOC27"></a>3.4 Integrating with your build environment</h3>
+
+ <p>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!
+
+<h4 class="subsection"><a name="TOC28"></a>3.4.1 Overview</h4>
+
+ <p>Let's assume you're developing an application.
+What I usually do is the following:
+ <ul>
+<li>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.
+<li>Create another application (or target, or project, or whatever) for the test runner.
+ Make the build tool generate it automatically.
+<li>For extra points, make the build tool run the tests automatically.
+</ul>
+
+<h4 class="subsection"><a name="TOC29"></a>3.4.2 Actually doing it</h4>
+
+ <p>Unfortunately, there are way too many different build tools and IDE's for me
+to give ways to use CxxTest with all of them.
+
+ <p>I will try to outline the usage for some cases.
+
+<h5 class="subsubsection"><a name="TOC30"></a>3.4.2.1 Using Makefiles</h5>
+
+ <p>Generating the tests with a makefile is pretty straightforward.
+Simply add rules to generate, compile and run the test runner.
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ 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 $^
+ </pre>
+ </pre>
+
+<h5 class="subsubsection"><a name="TOC31"></a>3.4.2.2 Using Cons</h5>
+
+ <a href="http://dsmit.com/cons/">Cons</a> is a powerful and
+versatile make replacement which uses Perl scripts instead of Makefiles.
+
+ <p>See <code>sample/Construct</code> in the CxxTest distribution for an example of building CxxTest test runners
+with Cons.
+
+<h5 class="subsubsection"><a name="TOC32"></a>3.4.2.3 Using Microsoft Visual Studio</h5>
+
+ <p>I have tried several ways to integrate CxxTest with visual studio, none of
+which is perfect. Take a look at <code>sample/msvc</code> in the distribution
+to see the best solution I'm aware of. Basically, the workspace has three
+projects:
+
+ <ul>
+<li>The project <code>CxxTest_3_Generate</code> runs <code>cxxtestgen</code>.
+
+ <li>The project <code>CxxTest_2_Build</code> compiles the generated file.
+
+ <li>The project <code>CxxTest_1_Run</code> runs the tests.
+</ul>
+
+ <p>This method certainly works, and the test results are conveniently
+displayed as compilation errors and warnings (for
+<a href="#warn"><code>TS_WARN(</code><em></em><code>)</code></a>). 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 <code>sample/msvc/FixFiles.bat</code> to automate
+some of the process.
+
+<h5 class="subsubsection"><a name="TOC33"></a>3.4.2.4 Using Microsoft Windows DDK</h5>
+
+ <p>Unit testing for device drivers?! Why not?
+And besides, the <code>build</code> utility can also be used to build
+user-mode application.
+
+ <p>To use CxxTest with the <code>build</code> utility,
+you add the generated tests file as an extra dependency
+using the <code>NTBUILDTARGET0</code> macro and the <code>Makefile.inc</code>
+file.
+
+ <p>You can see an example of how to do this in the CxxTest distribution
+under <code>sample/winddk</code>.
+
+<h3 class="section"><a name="TOC34"></a>3.5 Graphical user interface</h3>
+
+ <p><a name="GUI"></a>
+
+ <p>There are currently three GUIs implemented: native Win32, native X11 and
+Qt. To use this feature, just specify <code>--gui=X11Gui</code>,
+<code>--gui=Win32Gui</code> or <code>--gui=QtGui</code> as a parameter for
+<code>cxxtestgen</code> (instead of e.g. <code>--error-printer</code>). 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.
+
+ <p>Note that whatevr GUI you use, you can combine it with the
+<code>--runner</code> option to control the formatting of the text output,
+e.g. Visual Studio likes it better if you use
+<code>--runner=ParenPrinter</code>.
+
+<h4 class="subsection"><a name="TOC35"></a>3.5.1 Starting the GUI minimized</h4>
+
+ <p>If you run the generated Win32 or Qt GUIs with the command line
+<code>-minimized</code>, 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.
+
+<h4 class="subsection"><a name="TOC36"></a>3.5.2 Leaving the GUI open</h4>
+
+ <p>The Win32 GUI accepts the <code>-keep</code> 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.
+
+<h4 class="subsection"><a name="TOC37"></a>3.5.3 Screenshots!</h4>
+
+ <p>As with any self-respecting GUI application, here are some screenshots for
+you to enjoy:
+
+ <ul>
+
+ <li>Using the Qt GUI on Linux (with the WindowMaker window manager):
+<div align="center"><img src="qt.png" alt="qt.png"></div>
+<br><p>
+ <li>Using the Win32 GUI on Windows 98:
+<div align="center"><img src="win32.png" alt="win32.png"></div>
+<br><p>
+ <li>Using the X11 GUI (with the venerable TWM):
+<div align="center"><img src="x11.png" alt="x11.png"></div>
+<br><p>
+ <li>And of course, no GUI is complete without the ability to mess around with
+its appearance:
+<div align="center"><img src="qt2.png" alt="qt2.png"></div>
+<br><p>
+ <p><em>Ahhh.</em> Nothing like a beautiful user interface.
+
+ </ul>
+
+<h2 class="chapter"><a name="TOC38"></a>4 Advanced topics</h2>
+
+ <p>Topics in this section are more technical, and you probably won't find them
+interesting unless you need them.
+
+<h3 class="section"><a name="TOC39"></a>4.1 Aborting tests after failures</h3>
+
+ <p>Usually, when a <code>TS_ASSERT_*</code> macro fails, CxxTest moves on to the
+next line. In many cases, however, this is not the desired behavior.
+Consider the following code:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ void test_memset()
+ {
+ char *buffer = new char[1024];
+ TS_ASSERT( buffer );
+ memset( buffer, 0, 1024 ); // But what if buffer == 0?
+ }
+ </pre>
+ </pre>
+
+ <p>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
+<code>CXXTEST_ABORT_TEST_ON_FAIL</code> before including the CxxTest
+headers. This can be done using the <code>--abort-on-fail</code>
+command-line option or in a template file; see
+<code>sample/aborter.tpl</code> 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
+<code>--have-eh</code> command-line option.
+
+<h4 class="subsection"><a name="TOC40"></a>4.1.1 Controlling this behavior at runtime</h4>
+
+ <font size=-2>(v3.8.5)</font>
+In some scenarios, you may want some tests to abort on
+failed assertions and others to continue. To do this you use the
+<code>--abort-on-fail</code> option and call the function
+<code>CxxTest::setAbortTestOnFail( bool )</code> to change the runtime
+behavior. This flag is reset (normally, to <code>true</code>) after each
+test, but you can set it in your test suite's <code>setUp()</code> function to
+modify the behavior for all tests in a suite.
+
+ <font size=-2>(v3.9.0)</font>
+Note that this behavior is available whenever you have
+exception handling (<code>--have-eh</code> or <code>CXXTEST_HAVE_EH</code>); all
+<code>--abort-on-fail</code> does is set the default to <code>true</code>.
+
+<h3 class="section"><a name="TOC41"></a>4.2 Commenting out tests</h3>
+
+ <p>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.
+
+ <p>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:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ class MyTest : public CxxTest::TestSuite
+ {
+ public:
+ /*
+ void testCommentedOutStillGetsCalled()
+ {
+ }
+ */
+
+ #if 0
+ void testMarkedOutStillGetsCalled()
+ {
+ }
+ #endif
+ };
+ </pre>
+ </pre>
+
+ <font size=-2>(v3.10.0)</font>
+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
+<code>x</code>:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ class MyTest : public CxxTest::TestSuite
+ {
+ public:
+ // void testFutureStuff()
+ // {
+ // }
+
+ void xtestFutureStuff()
+ {
+ }
+ };
+ </pre>
+ </pre>
+
+<h3 class="section"><a name="TOC42"></a>4.3 Comparing equality for your own types</h3>
+
+ <p>You may have noticed that <a href="#equals"><code>TS_ASSERT_EQUALS(</code><em></em><code>)</code></a> 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.
+
+ <p>If you do want to use <a href="#equals"><code>TS_ASSERT_EQUALS(</code><em></em><code>)</code></a> on your own data types,
+this is how you do it.
+
+<h4 class="subsection"><a name="TOC43"></a>4.3.1 The equality operator</h4>
+
+ <p>First of all, don't forget to implement the equality operator (<code>operator==()</code>)
+on your data types!
+
+<h4 class="subsection"><a name="TOC44"></a>4.3.2 Value traits</h4>
+
+ <p>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.
+
+ <p>For example, to convert an integer to a string, CxxTest does the following actions:
+ <ul>
+<li><code>int i = </code><em>value to convert</em><code>;</code>
+<li><code>CxxTest::ValueTraits&lt;int&gt; converter(i);</code>
+<li><code>string = converter.asString();</code>
+</ul>
+
+ <p>CxxTest comes with predefined <code>ValueTrait</code>s for <code>int</code>,
+<code>char</code>, <code>dobule</code> etc. in <code>cxxtest/ValueTraits.h</code> in the
+<code>cxxtest-selftest</code> archive.
+
+<h4 class="subsection"><a name="TOC45"></a>4.3.3 Unknown types</h4>
+
+ <p>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.
+
+ <p>For example, the following code
+<pre class="smallexample">
+ <pre class="verbatim">
+ #include &lt;cxxtest/TestSuite.h>
+
+ class TestMyData : public CxxTest::TestSuite
+ {
+ public:
+ struct Data
+ {
+ char data[3];
+ };
+
+ void testCompareData()
+ {
+ Data x, y;
+ memset( x.data, 0x12, sizeof(x.data) );
+ memset( y.data, 0xF6, sizeof(y.data) );
+ TS_ASSERT_EQUALS( x, y );
+ }
+ };
+ </pre>
+ </pre>
+ would output
+<pre class="smallexample">
+ <pre class="verbatim">
+ Running 1 test.
+ TestMyData.h:16: Expected (x == y), found ({ 12 12 12 } != { F6 F6 F6 })
+ Failed 1 of 1 test
+ Success rate: 0%
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC46"></a>4.3.4 Enumeration traits</h4>
+
+ <font size=-2>(v3.10.0)</font>
+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 <code>CXXTEST_VALUE_TRAITS</code> as in the
+following example:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ enum Status { STATUS_IDLE, STATUS_BUSY, STATUS_ERROR };
+
+ CXXTEST_ENUM_TRAITS( Status,
+ CXXTEST_ENUM_MEMBER( STATUS_IDLE )
+ CXXTEST_ENUM_MEMBER( STATUS_BUSY )
+ CXXTEST_ENUM_MEMBER( STATUS_ERROR ) );
+ </pre>
+ </pre>
+
+ <p>See <code>sample/EnumTraits.h</code> for a working sample.
+
+<h4 class="subsection"><a name="TOC47"></a>4.3.5 Defining new value traits</h4>
+
+ <p>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:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ class MyClass
+ {
+ int _value;
+
+ public:
+ MyClass( int value ) : _value( value ) {}
+ int value() const { return _value; }
+
+ // CxxTest requires a copy constructor
+ MyClass( const MyClass &amp;other ) : _value( other._value ) {}
+
+ // If you want to use TS_ASSERT_EQUALS
+ bool operator== ( const MyClass &amp;other ) const { return _value == other._value; }
+
+ // If you want to use TS_ASSERT_LESS_THAN
+ bool operator== ( const MyClass &amp;other ) const { return _value &lt; other._value; }
+ };
+
+ #ifdef CXXTEST_RUNNING
+ #include &lt;cxxtest/ValueTraits.h>
+ #include &lt;stdio.h>
+
+ namespace CxxTest
+ {
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits&lt;MyClass>
+ {
+ char _s[256];
+
+ public:
+ ValueTraits( const MyClass &amp;m ) { sprintf( _s, "MyClass( %i )", m.value() ); }
+ const char *asString() const { return _s; }
+ };
+ };
+ #endif // CXXTEST_RUNNING
+ </pre>
+ </pre>
+
+<h5 class="subsubsection"><a name="TOC48"></a>4.3.5.1 Defining value traits for template classes</h5>
+
+ <p>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:
+
+<pre class="smallexample">
+ <pre class="verbatim">
+ template&lt;class T>
+ class TMyClass
+ {
+ T _value;
+
+ public:
+ TMyClass( const T &amp;value ) : _value( value );
+ const T &amp;value() const { return _value; }
+
+ // CxxTest requires a copy constructor
+ TMyClass( const TMyClass&lt;T> &amp;other ) : _value( other._value ) {}
+
+ // If you want to use TS_ASSERT_EQUALS
+ bool operator== ( const TMyClass&lt;T> &amp;other ) const { return _value == other._value; }
+ };
+
+ #ifdef CXXTEST_RUNNING
+ #include &lt;cxxtest/ValueTraits.h>
+ #include &lt;typeinfo>
+ #include &lt;sstream>
+
+ namespace CxxTest
+ {
+ template&lt;class T>
+ class ValueTraits&lt; TMyClass&lt;T> >
+ {
+ std::ostringstream _s;
+
+ public:
+ ValueTraits( const TMyClass&lt;T> &amp;t )
+ { _s &lt;&lt; typeid(t).name() &lt;&lt; "( " &lt;&lt; t.value() &lt;&lt; " )"; }
+ const char *asString() const { return _s.str().c_str(); }
+ };
+ };
+ #endif // CXXTEST_RUNNING
+ </pre>
+ </pre>
+
+<h4 class="subsection"><a name="TOC49"></a>4.3.6 Overriding the default value traits</h4>
+
+ <font size=-2>(v2.8.2)</font>
+If you don't like the way CxxTest defines the default <code>ValueTrait</code>s,
+you can override them by <code>#define</code>-ing <code>CXXTEST_USER_VALUE_TRAITS</code>;
+this causes CxxTest to omit the default definitions, and from there on you are
+free to implement them as you like.
+
+ <p>You can see a sample of this technique in <code>test/UserTraits.tpl</code> in
+the <code>cxxtest-selftest</code> archive.
+
+<h3 class="section"><a name="TOC50"></a>4.4 Global Fixtures</h3>
+
+ <font size=-2>(v3.5.1)</font>
+The <code>setUp()</code> and <code>tearDown()</code> 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 <em>all</em> test suites?
+Rather than duplicate that code, you can use <dfn>global fixtures</dfn>.
+These are basically classes that inherit from
+<code>CxxTest::GlobalFixture</code>. 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 <code>test/GlobalFixtures.h</code> in the <code>cxxtest-selftest</code>
+archive.
+
+ <p><em>Note:</em> Unlike <code>setUp()</code> and <code>tearDown()</code> in
+<code>TestSuite</code>, global fixtures should return a <code>bool</code> value to
+indicate success/failure.
+
+<h4 class="subsection"><a name="TOC51"></a>4.4.1 World fixtures</h4>
+
+ <font size=-2>(v3.8.1)</font>
+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 <code>setUpWorld()</code>/<code>tearDownWorld()</code>. For an example,
+see <code>test/WorldFixtures.h</code> in the <code>cxxtest-selftest</code> archive.
+
+<h3 class="section"><a name="TOC52"></a>4.5 Mock Objects</h3>
+
+ <font size=-2>(v3.10.0)</font>
+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 <code>ISocket</code> interface and in the tests
+pass it a <code>MockSocket</code> object. This <code>MockSocket</code> object can
+then do anything your tests find useful, e.g. keep a log of all data
+"sent" to verify later.
+
+ <p>So far, so good. But the problem when developing in C/C++ is that your
+code probably needs to call <em>global</em> functions which you cannot
+override. Just consider any code which uses <code>fopen()</code>,
+<code>fwrite()</code> and <code>fclose()</code>. 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 <code>fopen()</code> fails. Although for some cases
+you can cause the effects to happen in the test code, this quickly
+becomes "hairy" and unmaintainable.
+
+ <p>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:
+ <ul>
+
+ <li>For each function you want to override, you use the macro
+<code>CXXTEST_MOCK_GLOBAL</code> to "prepare" the function (all is explained
+below in excruciating detail).
+
+ <li>In the tested code you do not call the global functions directly;
+rather, you access them in the <code>T</code> (for <em>Test</em>) namespace. For
+instance, your code needs to call <code>T::fopen()</code> instead of
+<code>fopen()</code>. This is the equivalent of using abstract interfaces
+instead of concrete classes.
+
+ <li>You link the "real" binary with a source file that implements
+<code>T::fopen()</code> by simply calling the original <code>fopen()</code>.
+
+ <li>You link the test binary with a source file that implements
+<code>T::fopen()</code> by calling a mock object.
+
+ <li>To test, you should create a class that inherits <code>T::Base_fopen</code>
+and implement its <code>fopen()</code> function. Simply by creating an object
+of this class, calls made to <code>T::fopen()</code> will be redirected to it.
+
+ </ul>
+
+ <p>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 <code>time()</code>.
+
+ <ul>
+
+ <li>Prepare a header file to be used by both the real and test code.
+ <pre class="smallexample">
+ <pre class="verbatim">
+ // T/time.h
+ #include &lt;time.h>
+ #include &lt;cxxtest/Mock.h>
+
+ CXXTEST_MOCK_GLOBAL( time_t, /* Return type */
+ time, /* Name of the function */
+ ( time_t *t ), /* Prototype */
+ ( t ) /* Argument list */ );
+ </pre>
+ </pre>
+
+ <li>In our tested code, we now include the special header instead of the
+system-supplied one, and call <code>T::time()</code> instead of <code>time()</code>.
+ <pre class="smallexample">
+ <pre class="verbatim">
+ // code.cpp
+ #include &lt;T/time.h>
+
+ int generateRandomNumber()
+ {
+ return T::time( NULL ) * 3;
+ }
+ </pre>
+ </pre>
+
+ <li>We also need to create a source file that implements <code>T::time()</code> by
+calling the real function. This is extremely easy: just define
+<code>CXXTEST_MOCK_REAL_SOURCE_FILE</code> before you include the header file:
+ <pre class="smallexample">
+ <pre class="verbatim">
+ // real_time.cpp
+ #define CXXTEST_MOCK_REAL_SOURCE_FILE
+ #include &lt;T/time.h>
+ </pre>
+ </pre>
+
+ <li>Before we can start testing, we need a different implementation of
+<code>T::time()</code> for our tests. This is just as easy as the previous
+one:
+ <pre class="smallexample">
+ <pre class="verbatim">
+ // mock_time.cpp
+ #define CXXTEST_MOCK_TEST_SOURCE_FILE
+ #include &lt;T/time.h>
+ </pre>
+ </pre>
+
+ <li>Now comes the fun part. In our test code, all we need to do is create a
+mock, and the tested code will magically call it:
+ <pre class="smallexample">
+ <pre class="verbatim">
+ // TestRandom.h
+ #include &lt;cxxtest/TestSuite.h>
+ #include &lt;T/time.h>
+
+ class TheTimeIsOne : public T::Base_time
+ {
+ public:
+ time_t time( time_t * ) { return 1; }
+ };
+
+ class TestRandom : public CxxTest::TestSuite
+ {
+ public:
+ void test_Random()
+ {
+ TheTimeIsOne t;
+ TS_ASSERT_EQUALS( generateRandomNumber(), 3 );
+ }
+ };
+ </pre>
+ </pre>
+
+ </ul>
+
+<h4 class="subsection"><a name="TOC53"></a>4.5.1 Actually doing it</h4>
+
+ <p>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 <code>sample/mock</code>, which
+uses GNU Make and G++.
+
+<h4 class="subsection"><a name="TOC54"></a>4.5.2 Advanced topic with mock functions</h4>
+
+<h5 class="subsubsection"><a name="TOC55"></a>4.5.2.1 Void functions</h5>
+
+ <p>Void function are a little different, and you use
+<code>CXXTEST_MOCK_VOID_GLOBAL</code> to override them. This is identical to
+<code>CXXTEST_MOCK_GLOBAL</code> except that it doesn't specify the return
+type. Take a look in <code>sample/mock/T/stdlib.h</code> for a demonstation.
+
+<h5 class="subsubsection"><a name="TOC56"></a>4.5.2.2 Calling the real functions while testing</h5>
+
+ <p>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. <code>T::Real_time</code>. While an object of this class
+is present, calls to <code>T::time()</code> will be redirected to the real
+function.
+
+<h5 class="subsubsection"><a name="TOC57"></a>4.5.2.3 When there is no real function</h5>
+
+ <p>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 <code>CXXTEST_SUPPLY_GLOBAL</code> (and
+<code>CXXTEST_SUPPLY_VOID_GLOBAL</code>). For example, say you want to supply
+your code with the Win32 kernel function <code>IoCallDriver</code>:
+<pre class="smallexample">
+ <pre class="verbatim">
+ CXXTEST_SUPPLY_GLOBAL( NTSTATUS, /* Return type */
+ IoCallDriver, /* Name */
+ ( PDEVICE_OBJECT Device, /* Prototype */
+ PIRP Irp ),
+ ( Device, Irp ) /* How to call */ );
+ </pre>
+ </pre>
+ The tested code (your driver) can now call <code>IoCallDriver()</code>
+normally (no need for <code>T::</code>), and the test code uses
+<code>T::Base_IoCallDriver</code> as with normal mock objects.
+
+ <p><strong>Note:</strong> 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 <code>&lt;ntddk.h&gt;</code> from test code), they also have an
+<code>extern "C"</code> version which declares the functions with <code>C</code>
+linkage. These are <code>CXXTEST_SUPPLY_GLOBAL_C</code> and
+<code>CXXTEST_SUPPLY_GLOBAL_VOID_C</code>.
+
+<h5 class="subsubsection"><a name="TOC58"></a>4.5.2.4 Functions in namespaces</h5>
+
+ <p>Sometimes the functions you want to override are not in the global
+namespace like <code>time()</code>: 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 <code>CXXTEST_MOCK</code>, which is best explained by example. Say you
+have a namespace <code>Files</code>, and you want to override the function
+<code>bool Files::FileExists( const String &amp;name )</code>, so that the mock
+class will be called <code>T::Base_Files_FileExists</code> and the function to
+implement would be <code>fileExists</code>. 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):
+<pre class="smallexample">
+ <pre class="verbatim">
+ CXXTEST_MOCK( Files_FileExists, /* Suffix of mock class */
+ bool, /* Return type */
+ fileExists, /* Name of mock member */
+ ( const String &amp;name ), /* Prototype */
+ Files::FileExists, /* Name of real function */
+ ( name ) /* Parameter list */ );
+ </pre>
+ </pre>
+ Needless to say, there is also <code>CXXTEST_MOCK_VOID</code> for void functions.
+
+ <p>There is also an equivalent version for <code>CXXTEST_SUPPLY_GLOBAL</code>, as
+demonstrated by another function from the Win32 DDK:
+<pre class="smallexample">
+ <pre class="verbatim">
+ 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 */ );
+ </pre>
+ </pre>
+ And, with this macro you have <code>CXXTEST_SUPPLY_VOID</code> and of course
+<code>CXXTEST_SUPPLY_C</code> and <code>CXXTEST_SUPPLY_VOID_C</code>.
+
+<h5 class="subsubsection"><a name="TOC59"></a>4.5.2.5 Overloaded functions</h5>
+
+ <p>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 <code>CXXTEST_MOCK</code>/<code>CXXTEST_MOCK_VOID</code> as above:
+just give the two mock classes different names.
+
+<h5 class="subsubsection"><a name="TOC60"></a>4.5.2.6 Changing the mock namespace</h5>
+
+ <p>Finally, if you don't like or for some reason can't use the <code>T::</code>
+namespace for mock functions, you can change it by defining
+<code>CXXTEST_MOCK_NAMESPACE</code>. Have fun.
+
+<h3 class="section"><a name="TOC61"></a>4.6 Test Listeners and Test Runners</h3>
+
+ <p>A <code>TestListener</code> is a class that receives notifications about
+the testing process, notably which assertions failed. CxxTest defines
+a standard test listener class, <code>ErrorPrinter</code>, which is
+responsible for printing the dots and messages seen above. When the
+test runners generated in the examples run, they create an
+<code>ErrorPrinter</code> and pass it to
+<code>TestRunner::runAllTests()</code>. As you might have guessed, this
+functions runs all the test you've defined and reports to the
+<code>TestListener</code> it was passed.
+
+<h4 class="subsection"><a name="TOC62"></a>4.6.1 Other test listeners</h4>
+
+ <p>If you don't like or can't use the <code>ErrorPrinter</code>, you can use
+any other test listener.
+To do this you have to omit the <code>--error-printer</code>, <code>--runner=</code>
+or <code>--gui=</code> switch when generating the tests file.
+It is then up to you to write the <code>main()</code> function, using the
+test listener of your fancy.
+
+<h5 class="subsubsection"><a name="TOC63"></a>4.6.1.1 The <code>stdio</code> printer</h5>
+
+ <p>If the <code>ErrorPrinter</code>'s usage of <code>std::cout</code> clashes
+with your environment or is unsupported by your compiler, don't dispair!
+You may still be able to use the <code>StdioPrinter</code>, which does the
+exact same thing but uses good old <code>printf()</code>.
+
+ <p>To use it, invoke <code>cxxtestgen.pl</code> with the <code>--runner=StdioPrinter</code> option.
+
+ <font size=-2>(v3.8.5)</font>
+<strong>Note:</strong> <code>cxxtest/StdioPrinter</code> makes
+reference to <code>stdout</code> as the default output stream. In some
+environments you may have <code>&lt;stdio.h&gt;</code> but not <code>stdout</code>, which
+will cause compiler errors. To overcome this problem, use
+<code>--runner=StdioFilePrinter</code>, which is exactly the same as
+<code>--runner=StdioPrinter</code>, but with no default output stream.
+
+<h5 class="subsubsection"><a name="TOC64"></a>4.6.1.2 The Yes/No runner</h5>
+
+ <p>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 <code>sample/yes_no_runner.cpp</code>.
+
+<h5 class="subsubsection"><a name="TOC65"></a>4.6.1.3 Template files</h5>
+
+ <p>To use you own test runner, or to use the supplied ones in different ways, you can use
+CxxTest <em>template files</em>. These are ordinary source files with the embedded "command"
+<code>&lt;CxxTest world&gt;</code> which tells <code>cxxtestgen.pl</code> to insert the world definition
+at that point. You then specify the template file using the <code>--template</code> option.
+
+ <p>See <code>samples/file_printer.tpl</code> for an example.
+
+ <p><strong>Note:</strong> CxxTest needs to insert certain definitions and
+<code>#include</code> directives in the runner file. It normally does that
+before the first <code>#include &lt;cxxtest/*.h&gt;</code> found in the template
+file. If this behvaior is not what you need, use the "command"
+<code>&lt;CxxTest preamble&gt;</code>. See <code>test/preamble.tpl</code> in the
+<code>cxxtest-selftest</code> archive for an example of this.
+
+<h3 class="section"><a name="TOC66"></a>4.7 Dynamically creating test suites</h3>
+
+ <p><a name="dynamic"></a>
+Usually, your test suites are instantiated statically in the tests file, i.e. say you
+defined <code>class MyTest : public CxxTest::TestSuite</code>, the generated file will
+contain something like <code>static MyTest g_MyTest;</code>.
+
+ <p>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, <code>createSuite()</code> and <code>destroySuite()</code>.
+
+ <p>See <code>sample/CreatedTest.h</code> for a demonstration.
+
+<h3 class="section"><a name="TOC67"></a>4.8 Static initialization</h3>
+
+ <font size=-2>(v3.9.0)</font>
+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 <code>--no-static-init</code> option.
+
+<h2 class="appendix"><a name="TOC68"></a>Appendix A Command line options</h2>
+
+ <p>Here are the different command line options for <code>cxxtestgen</code>:
+
+<h3 class="section"><a name="TOC69"></a>A.1 <code>--version</code></h3>
+
+ <font size=-2>(v3.7.1)</font>
+Specify <code>--version</code> or <code>-v</code> to see the version of CxxTest you are using.
+
+<h3 class="section"><a name="TOC70"></a>A.2 <code>--output</code></h3>
+
+ <p>Specify <code>--output=FILE</code> or <code>-o FILE</code> to determine the output file name.
+
+<h3 class="section"><a name="TOC71"></a>A.3 <code>--error-printer</code></h3>
+
+ <p>This option creates a test runner which uses the standard error printer class.
+
+<h3 class="section"><a name="TOC72"></a>A.4 <code>--runner</code></h3>
+
+ <p>Specify <code>--runner=CLASS</code> to generate a test
+runner that <code>#include</code>s <code>&lt;cxxtest/CLASS.h&gt;</code> and uses
+<code>CxxTest::CLASS</code> as the test runner.
+
+ <p>The currently available runners are:
+ <dl>
+<dt><code>--runner=ErrorPrinter</code>
+ <dd>This is the standard error printer, which formats its output to <code>std::cout</code>.
+
+ <br><dt><code>--runner=ParenPrinter</code>
+ <dd>Identical to <code>ErrorPrinter</code> except that it prints line numbers in parantheses.
+This is the way Visual Studio expects it.
+
+ <br><dt><code>--runner=StdioPrinter</code>
+ <dd>The same as <code>ErrorPrinter</code> except that it uses <code>printf</code>
+instead of <code>cout</code>.
+
+ <br><dt><code>--runner=YesNoRunner</code>
+ <dd>This runner doesn't produce any output, merely returns a true/false result.
+
+ </dl>
+
+<h3 class="section"><a name="TOC73"></a>A.5 <code>--gui</code></h3>
+
+ <p>Specify <code>--gui=CLASS</code> to generate a test runner that
+<code>#include</code>s <code>&lt;cxxtest/CLASS.h&gt;</code> and uses <code>CxxTest::CLASS</code>
+to display a graphical user interface. This option can be combined with
+the <code>--runner</code> option to determine the text-mode output format.
+The default is the standard error printer.
+
+ <p>There are three different GUIs:
+ <dl>
+<dt><code>--gui=Win32Gui</code>
+ <dd>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.
+
+ <br><dt><code>--gui=X11Gui</code>
+ <dd>A native XLib GUI. This GUI is very spartan and should work on any X server.
+
+ <br><dt><code>--gui=QtGui</code>
+ <dd>A GUI that uses the Qt library from Troll. It has been tested with Qt versiond 2.2.1 and 3.0.1.
+</dl>
+
+<h3 class="section"><a name="TOC74"></a>A.6 <code>--include</code></h3>
+
+ <font size=-2>(v3.5.1)</font>
+If you specify <code>--include=FILE</code>, <code>cxxtestgen</code> will add
+<code>#include "FILE"</code> 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.
+
+ <p><strong>Note:</strong> If you want the runner to <code>#inculde &lt;FILE&gt;</code>, specify
+it on the command line, e.g. <code>--include=&lt;FILE&gt;</code>. You will most
+likely need to use shell escapes, e.g. <code>"--include=&lt;FILE&gt;"</code> or
+<code>--include=\&lt;FILE\&gt;</code>.
+
+ <p>Examples: <code>--include=TestDefs.h</code> or <code>--include=\&lt;GlobalDefs.h\&gt;</code>.
+
+<h3 class="section"><a name="TOC75"></a>A.7 <code>--template</code></h3>
+
+ <p>Specify <code>--template=FILE</code> to use <code>FILE</code> as a template file.
+This is for cases for which <code>--runner</code> and/or <code>--include</code>
+are not enough. One example is the Windows DDK; see
+<code>sample/winddk</code> in the distribution.
+
+<h3 class="section"><a name="TOC76"></a>A.8 <code>--have-eh</code></h3>
+
+ <font size=-2>(v2.8.4)</font>
+<code>cxxtestgen</code> will scan its input files for uses of exception
+handling; if found, the <code>TS_</code> macros will catch exceptions,
+allowing the testing to continue. Use <code>--have-eh</code> to tell
+<code>cxxtestgen</code> to enable that functionality even if exceptions
+are not used in the input files.
+
+<h3 class="section"><a name="TOC77"></a>A.9 <code>--no-eh</code></h3>
+
+ <font size=-2>(v3.8.5)</font>
+If you want <code>cxxtestgen</code> to ignore what may look as uses of
+exception handling in your test files, specify <code>--no-eh</code>.
+
+<h3 class="section"><a name="TOC78"></a>A.10 <code>--have-std</code></h3>
+
+ <font size=-2>(v3.10.0)</font>
+Same as <code>--have-eh</code> but for the standard library;
+basically, if you use this flag, CxxTest will print the values of
+<code>std::string</code>.
+
+ <p><strong>Note:</strong> If you reference the standard library anywhere in your
+test files, CxxTest will (usually) recognize it and automatically define
+this.
+
+<h3 class="section"><a name="TOC79"></a>A.11 <code>--no-std</code></h3>
+
+ <font size=-2>(v3.10.0)</font>
+The counterpart to <code>--have-std</code>, this tells
+CxxTest to ignore any evidence it finds for the <code>std::</code> namespace
+in your code. Use it if your environment does not support <code>std::</code>
+but <code>cxxtestgen</code> thinks it does.
+
+<h3 class="section"><a name="TOC80"></a>A.12 <code>--longlong</code></h3>
+
+ <font size=-2>(v3.6.0)</font>
+Specify <code>--longlong=TYPE</code> to have CxxTest recognize <code>TYPE</code>
+as "long long" (e.g. <code>--longlong=__int64</code>). If you specify
+just <code>--longlong=</code> (no type), CxxTest will use the default type
+name of <code>long long</code>.
+
+<h3 class="section"><a name="TOC81"></a>A.13 <code>--abort-on-fail</code></h3>
+
+ <font size=-2>(v2.8.2)</font>
+This useful option tells CxxTest to abort the current test when any
+<code>TS_ASSERT</code> macro has failed.
+
+<h3 class="section"><a name="TOC82"></a>A.14 <code>--part</code></h3>
+
+ <font size=-2>(v3.5.1)</font>
+This option tells CxxTest now to write the CxxTest globals in the output
+file. Use this to link together more than one generated file.
+
+<h3 class="section"><a name="TOC83"></a>A.15 <code>--root</code></h3>
+
+ <font size=-2>(v3.5.1)</font>
+This is the counterpart of <code>--part</code>; it makes sure that the
+Cxxtest globals are written to the output file. If you specify this
+option, you can use <code>cxxtestgen</code> without any input files to
+create a file that hold only the "root" runner.
+
+<h3 class="section"><a name="TOC84"></a>A.16 <code>--no-static-init</code></h3>
+
+ <font size=-2>(v3.9.0)</font>
+Use this option if you encounter problems with the static
+initializations in the test runner.
+
+<h2 class="appendix"><a name="TOC85"></a>Appendix B Controlling the behavior of CxxTest</h2>
+
+ <p>Here are various <code>#define</code>s you can use to modify how CxxTest
+works. You will need to <code>#define</code> them <em>before</em> including any
+of the CxxTest headers, so use them in a template file or with the
+<code>--include</code> option.
+
+<h3 class="section"><a name="TOC86"></a>B.1 <code>CXXTEST_HAVE_STD</code></h3>
+
+ <p>This is equivalent to the <code>--have-std</code> option.
+
+<h3 class="section"><a name="TOC87"></a>B.2 <code>CXXTEST_HAVE_EH</code></h3>
+
+ <p>This is equivalent to the <code>--have-eh</code> option.
+
+<h3 class="section"><a name="TOC88"></a>B.3 <code>CXXTEST_ABORT_TEST_ON_FAIL</code></h3>
+
+ <font size=-2>(v2.8.0)</font>
+This is equivalent to the <code>--abort-on-fail</code> option.
+
+<h3 class="section"><a name="TOC89"></a>B.4 <code>CXXTEST_USER_VALUE_TRAITS</code></h3>
+
+ <p>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.
+
+<h3 class="section"><a name="TOC90"></a>B.5 <code>CXXTEST_OLD_TEMPLATE_SYNTAX</code></h3>
+
+ <p>Some compilers (e.g. Borland C++ 5) don't support the standard way of
+instantiating template classes. Use this define to overcome the problem.
+
+<h3 class="section"><a name="TOC91"></a>B.6 <code>CXXTEST_OLD_STD</code></h3>
+
+ <p>Again, this is used to support pre-<code>std::</code> standard libraries.
+
+<h3 class="section"><a name="TOC92"></a>B.7 <code>CXXTEST_MAX_DUMP_SIZE</code></h3>
+
+ <p>This sets the standard maximum number of bytes to dump if
+<a href="#sameData"><code>TS_ASSERT_SAME_DATA(</code><em></em><code>)</code></a> fails. The default is 0, meaning
+no limit.
+
+<h3 class="section"><a name="TOC93"></a>B.8 <code>CXXTEST_DEFAULT_ABORT</code></h3>
+
+ <p>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.
+
+<h3 class="section"><a name="TOC94"></a>B.9 <code>CXXTEST_LONGLONG</code></h3>
+
+ <p>This is equivalent to <code>--longlong</code>.
+
+<h2 class="appendix"><a name="TOC95"></a>Appendix C Runtime options</h2>
+
+ <p>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
+<code>tearDown()</code> is called). Consequently, if you set them in the
+<code>setUp()</code> function, they will be valid for the entire test suite.
+
+<h3 class="section"><a name="TOC96"></a>C.1 <code>setAbortTestOnFail( bool )</code></h3>
+
+ <p>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 <code>false</code>, <code>true</code> if you set <code>--abort-on-fail</code>,
+or <code>CXXTEST_DEFAULT_ABORT</code> if you <code>#define</code> it.
+
+<h3 class="section"><a name="TOC97"></a>C.2 <code>setMaxDumpSize( unsigned )</code></h3>
+
+ <p>This temporarily sets the maximum number of bytes to dump if
+<a href="#sameData"><code>TS_ASSERT_SAME_DATA(</code><em></em><code>)</code></a> fails. The default is 0, meaning
+no limit, or <code>CXXTEST_MAX_DUMP_SIZE</code> if you <code>#define</code> it.
+
+<h2 class="appendix"><a name="TOC98"></a>Appendix D Version history</h2>
+
+ <ul>
+<li><strong>Version 3.10.0 (2004-11-20)</strong>
+ <ul>
+<li>Added mock framework for global functions
+<li>Added <code>TS_ASSERT_THROWS_ASSERT</code> and <code>TS_ASSERT_THROWS_EQUALS</code>
+<li>Added <code>CXXTEST_ENUM_TRAITS</code>
+<li>Improved support for STL classes (vector, map etc.)
+<li>Added support for Digital Mars compiler
+<li>Reduced root/part compilation time and binary size
+<li>Support C++-style commenting of tests
+</ul>
+ <li><strong>Version 3.9.1 (2004-01-19)</strong>
+ <ul>
+<li>Fixed small bug with runner exit code
+<li>Embedded test suites are now deprecated
+</ul>
+ <li><strong>Version 3.9.0 (2004-01-17)</strong>
+ <ul>
+<li>Added <code>TS_TRACE</code>
+<li>Added <code>--no-static-init</code>
+<li>CxxTest::<code>setAbortTestOnFail()</code> works even without <code>--abort-on-fail</code>
+</ul>
+ <li><strong>Version 3.8.5 (2004-01-08)</strong>
+ <ul>
+<li>Added <code>--no-eh</code>
+<li>Added <code>CxxTest::setAbortTestOnFail()</code> and <code>CXXTEST_DEFAULT_ABORT</code>
+<li>Added <code>CxxTest::setMaxDumpSize()</code>
+<li>Added StdioFilePrinter
+</ul>
+ <li><strong>Version 3.8.4 (2003-12-31)</strong>
+ <ul>
+<li>Split distribution into cxxtest and cxxtest-selftest
+<li>Added <code>sample/msvc/FixFiles.bat</code>
+</ul>
+ <li><strong>Version 3.8.3 (2003-12-24)</strong>
+ <ul>
+<li>Added <code>TS_ASSERT_PREDICATE</code>
+<li>Template files can now specify where to insert the preamble
+<li>Added a sample Visual Studio workspace in <code>sample/msvc</code>
+<li>Can compile in MSVC with warning level 4
+<li>Changed output format slightly
+</ul>
+ <li><strong>Version 3.8.1 (2003-12-21)</strong>
+ <ul>
+<li>Fixed small bug when using multiple <code>--part</code> files.
+<li>Fixed X11 GUI crash when there's no X server.
+<li>Added <code>GlobalFixture::setUpWorld()</code>/<code>tearDownWorld()</code>
+<li>Added <code>leaveOnly()</code>, <code>activateAllTests()</code> and <code>sample/only.tpl</code>
+<li>Should now run without warnings on Sun compiler.
+</ul>
+ <li><strong>Version 3.8.0 (2003-12-13)</strong>
+ <ul>
+<li>Fixed bug where <code>Root.cpp</code> needed exception handling
+<li>Added <code>TS_ASSERT_RELATION</code>
+<li><code>TSM_</code> macros now also tell you what went wrong
+<li>Renamed <code>Win32Gui::free()</code> to avoid clashes
+<li>Now compatible with more versions of Borland compiler
+<li>Improved the documentation
+</ul>
+ <li><strong>Version 3.7.1 (2003-09-29)</strong>
+ <ul>
+<li>Added <code>--version</code>
+<li>Compiles with even more exotic g++ warnings
+<li>Win32 Gui compiles with UNICODE
+<li>Should compile on some more platforms (Sun Forte, HP aCC)
+</ul>
+ <li><strong>Version 3.7.0 (2003-09-20)</strong>
+ <ul>
+<li>Added <code>TS_ASSERT_LESS_THAN_EQUALS</code>
+<li>Minor cleanups
+</ul>
+ <li><strong>Version 3.6.1 (2003-09-15)</strong>
+ <ul>
+<li>Improved QT GUI
+<li>Improved portability some more
+</ul>
+ <li><strong>Version 3.6.0 (2003-09-04)</strong>
+ <ul>
+<li>Added <code>--longlong</code>
+<li>Some portability improvements
+</ul>
+ <li><strong>Version 3.5.1 (2003-09-03)</strong>
+ <ul>
+<li>Major internal rewrite of macros
+<li>Added <code>TS_ASSERT_SAME_DATA</code>
+<li>Added <code>--include</code> option
+<li>Added <code>--part</code> and <code>--root</code> to enable splitting the test runner
+<li>Added global fixtures
+<li>Enhanced Win32 GUI with timers, <code>-keep</code> and <code>-title</code>
+<li>Now compiles with strict warnings
+</ul>
+ <li><strong>Version 3.1.1 (2003-08-27)</strong>
+ <ul>
+<li>Fixed small bug in <code>TS_ASSERT_THROWS_*()</code>
+</ul>
+ <li><strong>Version 3.1.0 (2003-08-23)</strong>
+ <ul>
+<li>Default ValueTraits now dumps value as hex bytes
+<li>Fixed double invocation bug (e.g. <code>TS_FAIL(</code><code>functionWithSideEffects()</code>))
+<li><code>TS_ASSERT_THROWS*()</code> are now "abort on fail"-friendly
+<li>Win32 GUI now supports Windows 98 and doesn't need comctl32.lib
+</ul>
+ <li><strong>Version 3.0.1 (2003-08-07)</strong>
+ <ul>
+<li>Added simple GUI for X11, Win32 and Qt
+<li>Added <code>TS_</code><code>WARN()</code> macro
+<li>Removed <code>--exit-code</code>
+<li>Improved samples
+<li>Improved support for older (pre-std::) compilers
+<li>Made a PDF version of the User's Guide
+</ul>
+ <li><strong>Version 2.8.4 (2003-07-21)</strong>
+ <ul>
+<li>Now supports g++-3.3
+<li>Added <code>--have-eh</code>
+<li>Fixed bug in <code>numberToString()</code>
+</ul>
+ <li><strong>Version 2.8.3 (2003-06-30)</strong>
+ <ul>
+<li>Fixed bugs in cxxtestgen.pl
+<li>Fixed warning for some compilers in ErrorPrinter/StdioPrinter
+<li>Thanks Martin Jost for pointing out these problems!
+</ul>
+ <li><strong>Version 2.8.2 (2003-06-10)</strong>
+ <ul>
+<li>Fixed bug when using <code>CXXTEST_ABORT_TEST_ON_FAIL</code> without standard library
+<li>Added <code>CXXTEST_USER_TRAITS</code>
+<li>Added <code>--abort-on-fail</code>
+</ul>
+ <li><strong>Version 2.8.1 (2003-01-16)</strong>
+ <ul>
+<li>Fixed <code>charToString()</code> for negative chars
+</ul>
+ <li><strong>Version 2.8.0 (2003-01-13)</strong>
+ <ul>
+<li>Added <code>CXXTEST_ABORT_TEST_ON_FAIL</code> for xUnit-like behaviour
+<li>Added <code>sample/winddk</code>
+<li>Improved ValueTraits
+<li>Improved output formatter
+<li>Started version history
+</ul>
+ <li><strong>Version 2.7.0 (2002-09-29)</strong>
+ <ul>
+<li>Added embedded test suites
+<li>Major internal improvements
+</ul>
+
+ </ul>
+
+ <p><a name="contents"></a>
+
+<div class="contents">
+<h2>Table of Contents</h2>
+<ul>
+<li><a name="toc_TOC0" href="#TOC0">1 Introduction</a>
+<ul>
+<li><a href="#TOC1">1.1 About this guide</a>
+</li></ul>
+<li><a name="toc_TOC2" href="#TOC2">2 Getting started</a>
+<ul>
+<li><a href="#TOC3">2.1 Getting CxxTest</a>
+<li><a href="#TOC4">2.2 Your first test!</a>
+<li><a href="#TOC5">2.3 Your second test</a>
+<li><a href="#TOC6">2.4 Graphical user interface</a>
+</li></ul>
+<li><a name="toc_TOC7" href="#TOC7">3 <em>Really</em> using CxxTest</a>
+<ul>
+<li><a href="#TOC8">3.1 What can you test</a>
+<ul>
+<li><a href="#TOC9">3.1.1 <code>TS_FAIL</code></a>
+<li><a href="#TOC10">3.1.2 <code>TS_ASSERT</code></a>
+<li><a href="#TOC11">3.1.3 <code>TS_ASSERT_EQUALS</code></a>
+<li><a href="#TOC12">3.1.4 <code>TS_ASSERT_SAME_DATA</code></a>
+<li><a href="#TOC13">3.1.5 <code>TS_ASSERT_DELTA</code></a>
+<li><a href="#TOC14">3.1.6 <code>TS_ASSERT_DIFFERS</code></a>
+<li><a href="#TOC15">3.1.7 <code>TS_ASSERT_LESS_THAN</code></a>
+<li><a href="#TOC16">3.1.8 <code>TS_ASSERT_LESS_THAN_EQUALS</code></a>
+<li><a href="#TOC17">3.1.9 <code>TS_ASSERT_PREDICATE</code></a>
+<li><a href="#TOC18">3.1.10 <code>TS_ASSERT_RELATION</code></a>
+<li><a href="#TOC19">3.1.11 <code>TS_ASSERT_THROWS</code> and friends</a>
+<li><a href="#TOC20">3.1.12 <code>TS_TRACE</code> and <code>TS_WARN</code></a>
+<li><a href="#TOC21">3.1.13 The <code>ETS_</code> macros</a>
+<li><a href="#TOC22">3.1.14 The <code>TSM_</code> macros</a>
+<ul>
+<li><a href="#TOC23">3.1.14.1 The <code>ETSM_</code> macros</a>
+</li></ul>
+</li></ul>
+<li><a href="#TOC24">3.2 Running the samples</a>
+<li><a href="#TOC25">3.3 Test fixtures</a>
+<ul>
+<li><a href="#TOC26">3.3.1 Test suite level fixtures</a>
+</li></ul>
+<li><a href="#TOC27">3.4 Integrating with your build environment</a>
+<ul>
+<li><a href="#TOC28">3.4.1 Overview</a>
+<li><a href="#TOC29">3.4.2 Actually doing it</a>
+<ul>
+<li><a href="#TOC30">3.4.2.1 Using Makefiles</a>
+<li><a href="#TOC31">3.4.2.2 Using Cons</a>
+<li><a href="#TOC32">3.4.2.3 Using Microsoft Visual Studio</a>
+<li><a href="#TOC33">3.4.2.4 Using Microsoft Windows DDK</a>
+</li></ul>
+</li></ul>
+<li><a href="#TOC34">3.5 Graphical user interface</a>
+<ul>
+<li><a href="#TOC35">3.5.1 Starting the GUI minimized</a>
+<li><a href="#TOC36">3.5.2 Leaving the GUI open</a>
+<li><a href="#TOC37">3.5.3 Screenshots!</a>
+</li></ul>
+</li></ul>
+<li><a name="toc_TOC38" href="#TOC38">4 Advanced topics</a>
+<ul>
+<li><a href="#TOC39">4.1 Aborting tests after failures</a>
+<ul>
+<li><a href="#TOC40">4.1.1 Controlling this behavior at runtime</a>
+</li></ul>
+<li><a href="#TOC41">4.2 Commenting out tests</a>
+<li><a href="#TOC42">4.3 Comparing equality for your own types</a>
+<ul>
+<li><a href="#TOC43">4.3.1 The equality operator</a>
+<li><a href="#TOC44">4.3.2 Value traits</a>
+<li><a href="#TOC45">4.3.3 Unknown types</a>
+<li><a href="#TOC46">4.3.4 Enumeration traits</a>
+<li><a href="#TOC47">4.3.5 Defining new value traits</a>
+<ul>
+<li><a href="#TOC48">4.3.5.1 Defining value traits for template classes</a>
+</li></ul>
+<li><a href="#TOC49">4.3.6 Overriding the default value traits</a>
+</li></ul>
+<li><a href="#TOC50">4.4 Global Fixtures</a>
+<ul>
+<li><a href="#TOC51">4.4.1 World fixtures</a>
+</li></ul>
+<li><a href="#TOC52">4.5 Mock Objects</a>
+<ul>
+<li><a href="#TOC53">4.5.1 Actually doing it</a>
+<li><a href="#TOC54">4.5.2 Advanced topic with mock functions</a>
+<ul>
+<li><a href="#TOC55">4.5.2.1 Void functions</a>
+<li><a href="#TOC56">4.5.2.2 Calling the real functions while testing</a>
+<li><a href="#TOC57">4.5.2.3 When there is no real function</a>
+<li><a href="#TOC58">4.5.2.4 Functions in namespaces</a>
+<li><a href="#TOC59">4.5.2.5 Overloaded functions</a>
+<li><a href="#TOC60">4.5.2.6 Changing the mock namespace</a>
+</li></ul>
+</li></ul>
+<li><a href="#TOC61">4.6 Test Listeners and Test Runners</a>
+<ul>
+<li><a href="#TOC62">4.6.1 Other test listeners</a>
+<ul>
+<li><a href="#TOC63">4.6.1.1 The <code>stdio</code> printer</a>
+<li><a href="#TOC64">4.6.1.2 The Yes/No runner</a>
+<li><a href="#TOC65">4.6.1.3 Template files</a>
+</li></ul>
+</li></ul>
+<li><a href="#TOC66">4.7 Dynamically creating test suites</a>
+<li><a href="#TOC67">4.8 Static initialization</a>
+</li></ul>
+<li><a name="toc_TOC68" href="#TOC68">Appendix A Command line options</a>
+<ul>
+<li><a href="#TOC69">A.1 <code>--version</code></a>
+<li><a href="#TOC70">A.2 <code>--output</code></a>
+<li><a href="#TOC71">A.3 <code>--error-printer</code></a>
+<li><a href="#TOC72">A.4 <code>--runner</code></a>
+<li><a href="#TOC73">A.5 <code>--gui</code></a>
+<li><a href="#TOC74">A.6 <code>--include</code></a>
+<li><a href="#TOC75">A.7 <code>--template</code></a>
+<li><a href="#TOC76">A.8 <code>--have-eh</code></a>
+<li><a href="#TOC77">A.9 <code>--no-eh</code></a>
+<li><a href="#TOC78">A.10 <code>--have-std</code></a>
+<li><a href="#TOC79">A.11 <code>--no-std</code></a>
+<li><a href="#TOC80">A.12 <code>--longlong</code></a>
+<li><a href="#TOC81">A.13 <code>--abort-on-fail</code></a>
+<li><a href="#TOC82">A.14 <code>--part</code></a>
+<li><a href="#TOC83">A.15 <code>--root</code></a>
+<li><a href="#TOC84">A.16 <code>--no-static-init</code></a>
+</li></ul>
+<li><a name="toc_TOC85" href="#TOC85">Appendix B Controlling the behavior of CxxTest</a>
+<ul>
+<li><a href="#TOC86">B.1 <code>CXXTEST_HAVE_STD</code></a>
+<li><a href="#TOC87">B.2 <code>CXXTEST_HAVE_EH</code></a>
+<li><a href="#TOC88">B.3 <code>CXXTEST_ABORT_TEST_ON_FAIL</code></a>
+<li><a href="#TOC89">B.4 <code>CXXTEST_USER_VALUE_TRAITS</code></a>
+<li><a href="#TOC90">B.5 <code>CXXTEST_OLD_TEMPLATE_SYNTAX</code></a>
+<li><a href="#TOC91">B.6 <code>CXXTEST_OLD_STD</code></a>
+<li><a href="#TOC92">B.7 <code>CXXTEST_MAX_DUMP_SIZE</code></a>
+<li><a href="#TOC93">B.8 <code>CXXTEST_DEFAULT_ABORT</code></a>
+<li><a href="#TOC94">B.9 <code>CXXTEST_LONGLONG</code></a>
+</li></ul>
+<li><a name="toc_TOC95" href="#TOC95">Appendix C Runtime options</a>
+<ul>
+<li><a href="#TOC96">C.1 <code>setAbortTestOnFail( bool )</code></a>
+<li><a href="#TOC97">C.2 <code>setMaxDumpSize( unsigned )</code></a>
+</li></ul>
+<li><a name="toc_TOC98" href="#TOC98">Appendix D Version history</a>
+</li></ul>
+</div>
+
+
+ </body></html>
+
diff --git a/test/cxxtest/docs/index.html b/test/cxxtest/docs/index.html
new file mode 100644
index 0000000000..05ac5b3bab
--- /dev/null
+++ b/test/cxxtest/docs/index.html
@@ -0,0 +1,56 @@
+<html>
+<title>CxxTest</title>
+<h1>Introduction</h1>
+
+<p>CxxTest is a JUnit/CppUnit/xUnit-like framework for C++.
+
+<p>Its advantages over existing alternatives are that it:
+<ul>
+<li>Doesn't require RTTI
+<li>Doesn't require member template functions
+<li>Doesn't require exception handling
+<li>Doesn't require any external libraries (including memory management,
+ file/console I/O, graphics libraries)
+<li>Is distributed entirely as a set of header files
+</ul>
+
+<p>This makes it extremely portable and usable.
+
+<p>CxxTest is available under the <a href="http://www.gnu.org/copyleft/lesser.html">GNU
+Lesser General Public License</a>.
+
+<p>See <a href="guide.html">the user's guide</a> for information.
+It is also available as <a href="http://cxxtest.sourceforge.net/guide.pdf">a PDF file</a>.
+
+<p>The version history is available <a href="http://cxxtest.sourceforge.net/Versions.html">here</a>.
+
+<h1>Getting CxxTest</h1>
+You can always get the latest release from
+<a href="http://sourceforge.net/project/showfiles.php?group_id=52834">here</a> or
+<a href="http://dl.sourceforge.net/cxxtest">here</a>.
+
+<p>There are several files you can download:
+<ul>
+<li><code>cxxtest-<i>version</i>-1.noarch.rpm</code>
+<li><code>cxxtest-<i>version</i>.tar.gz</code>
+<li><code>cxxtest-<i>version</i>.zip</code>
+<li><code>cxxtest-guide-<i>version</i>.pdf</code> (the user's guide)
+</ul>
+Note that, since CxxTest consists entirely of header files,
+there is no distinction between source and binary distribution.
+
+<p>There are also files called <code>cxxtest-selftest-*</code>: these
+are used (usually by me) to test the portability of CxxTest, so you
+can probably do without them.
+
+<p>If you just can't wait for the next release, I sometimes upload betas
+to <a href="http://cxxtest.sourceforge.net/beta">here</a>.
+
+<h1>Getting started</h1>
+Get the sources and build the samples in the sample subdirectory.
+
+<br>
+<p>
+<A href="http://sourceforge.net"> <IMG src="http://sourceforge.net/sflogo.php?group_id=52834&type=4" border="0" alt="SourceForge Logo"></A>
+
+</html>
diff --git a/test/cxxtest/docs/qt.png b/test/cxxtest/docs/qt.png
new file mode 100644
index 0000000000..56a7a67478
--- /dev/null
+++ b/test/cxxtest/docs/qt.png
Binary files differ
diff --git a/test/cxxtest/docs/qt2.png b/test/cxxtest/docs/qt2.png
new file mode 100644
index 0000000000..918a1f4b49
--- /dev/null
+++ b/test/cxxtest/docs/qt2.png
Binary files differ
diff --git a/test/cxxtest/docs/win32.png b/test/cxxtest/docs/win32.png
new file mode 100644
index 0000000000..5de325bb19
--- /dev/null
+++ b/test/cxxtest/docs/win32.png
Binary files differ
diff --git a/test/cxxtest/docs/x11.png b/test/cxxtest/docs/x11.png
new file mode 100644
index 0000000000..9be8c195aa
--- /dev/null
+++ b/test/cxxtest/docs/x11.png
Binary files 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 <cxxtest/TestSuite.h>
+#include <string.h>
+#include <memory.h>
+
+//
+// This test suite shows what to do when your test case
+// class cannot be instantiated statically.
+// As an example, this test suite requires a non-default constructor.
+//
+
+class CreatedTest : public CxxTest::TestSuite
+{
+ char *_buffer;
+public:
+ CreatedTest( unsigned size ) : _buffer( new char[size] ) {}
+ virtual ~CreatedTest() { delete [] _buffer; }
+
+ static CreatedTest *createSuite() { return new CreatedTest( 16 ); }
+ static void destroySuite( CreatedTest *suite ) { delete suite; }
+
+ void test_nothing()
+ {
+ TS_FAIL( "Nothing to test" );
+ }
+};
+
+
+#endif // __CREATEDTEST_H
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 <cxxtest/TestSuite.h>
+#include <math.h>
+
+class DeltaTest : public CxxTest::TestSuite
+{
+ double _pi, _delta;
+
+public:
+ void setUp()
+ {
+ _pi = 3.1415926535;
+ _delta = 0.0001;
+ }
+
+ void testSine()
+ {
+ TS_ASSERT_DELTA( sin(0.0), 0.0, _delta );
+ TS_ASSERT_DELTA( sin(_pi / 6), 0.5, _delta );
+ TS_ASSERT_DELTA( sin(_pi / 2), 1.0, _delta );
+ TS_ASSERT_DELTA( sin(_pi), 0.0, _delta );
+ }
+};
+
+#endif // __DELTATEST_H
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 <cxxtest/TestSuite.h>
+
+//
+// First define your enumeration
+//
+enum Answer {
+ Yes,
+ No,
+ Maybe,
+ DontKnow,
+ DontCare
+};
+
+//
+// Now make CxxTest aware of it
+//
+CXXTEST_ENUM_TRAITS( Answer,
+ CXXTEST_ENUM_MEMBER( Yes )
+ CXXTEST_ENUM_MEMBER( No )
+ CXXTEST_ENUM_MEMBER( Maybe )
+ CXXTEST_ENUM_MEMBER( DontKnow )
+ CXXTEST_ENUM_MEMBER( DontCare ) );
+
+class EnumTraits : public CxxTest::TestSuite
+{
+public:
+ void test_Enum_traits()
+ {
+ TS_FAIL( Yes );
+ TS_FAIL( No );
+ TS_FAIL( Maybe );
+ TS_FAIL( DontKnow );
+ TS_FAIL( DontCare );
+ TS_FAIL( (Answer)1000 );
+ }
+};
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 <cxxtest/TestSuite.h>
+
+//
+// This test suite demonstrates the use of TS_ASSERT_THROWS
+//
+
+class ExceptionTest : public CxxTest::TestSuite
+{
+public:
+ void testAssertion( void )
+ {
+ // This assert passes, since throwThis() throws (Number)
+ TS_ASSERT_THROWS( throwThis(3), const Number & );
+ // This assert passes, since throwThis() throws something
+ TS_ASSERT_THROWS_ANYTHING( throwThis(-30) );
+ // This assert fails, since throwThis() doesn't throw char *
+ TS_ASSERT_THROWS( throwThis(5), const char * );
+ // This assert fails since goodFunction() throws nothing
+ TS_ASSERT_THROWS_ANYTHING( goodFunction(1) );
+ // The regular TS_ASSERT macros will catch unhandled exceptions
+ TS_ASSERT_EQUALS( throwThis(3), 333 );
+ // You can assert that a function throws nothing
+ TS_ASSERT_THROWS_NOTHING( throwThis(-1) );
+ // If you want to catch the exceptions yourself, use the ETS_ marcos
+ try {
+ ETS_ASSERT_EQUALS( throwThis(3), 333 );
+ } catch( const Number & ) {
+ TS_FAIL( "throwThis(3) failed" );
+ }
+ }
+
+private:
+ void goodFunction( int )
+ {
+ }
+
+ class Number
+ {
+ public:
+ Number( int ) {}
+ };
+
+ int throwThis( int i )
+ {
+ throw Number( i );
+ }
+};
+
+#endif // __EXCEPTIONTEST_H
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 <cxxtest/TestSuite.h>
+#include <string.h>
+
+//
+// This test suite shows how to use setUp() and tearDown()
+// to initialize data common to all tests.
+// setUp()/tearDown() will be called before and after each
+// test.
+//
+
+class FixtureTest : public CxxTest::TestSuite
+{
+ char *_buffer;
+public:
+ void setUp()
+ {
+ _buffer = new char[1024];
+ }
+
+ void tearDown()
+ {
+ delete [] _buffer;
+ }
+
+ void test_strcpy()
+ {
+ strcpy( _buffer, "Hello, world!" );
+ TS_ASSERT_EQUALS( _buffer[0], 'H' );
+ TS_ASSERT_EQUALS( _buffer[1], 'E' );
+ }
+};
+
+
+#endif // __FIXTURETEST_H
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 <cxxtest/TestSuite.h>
+
+//
+// The [E]TSM_ macros can be used to print a specified message
+// instead of the default one.
+// This is useful when you refactor your tests, as shown below
+//
+
+class MessageTest : public CxxTest::TestSuite
+{
+public:
+ void testValues()
+ {
+ checkValue( 0, "My hovercraft" );
+ checkValue( 1, "is full" );
+ checkValue( 2, "of eels" );
+ }
+
+ void checkValue( unsigned value, const char *message )
+ {
+ TSM_ASSERT( message, value != 0 );
+ TSM_ASSERT_EQUALS( message, value, value * value );
+ }
+};
+
+
+#endif // __MESSAGETEST_H
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 <cxxtest/TestSuite.h>
+
+//
+// A simple test suite: Just inherit CxxTest::TestSuite and write tests!
+//
+
+class SimpleTest : public CxxTest::TestSuite
+{
+public:
+ void testEquality()
+ {
+ TS_ASSERT_EQUALS( 1, 1 );
+ TS_ASSERT_EQUALS( 1, 2 );
+ TS_ASSERT_EQUALS( 'a', 'A' );
+ TS_ASSERT_EQUALS( 1.0, -12345678900000000000000000000000000000000000000000.1234 );
+ }
+
+ 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 <cxxtest/TestSuite.h>
+#include <cxxtest/ValueTraits.h>
+
+//
+// Define your class with operator==
+//
+#include <stdio.h>
+#include <string.h>
+
+class Pet
+{
+ char _name[128];
+public:
+ Pet( const char *petName ) { strcpy( _name, petName ); }
+
+ const char *name() const { return _name; }
+
+ bool operator== ( const Pet &other ) const
+ {
+ return !strcmp( name(), other.name() );
+ }
+};
+
+//
+// Instantiate CxxTest::ValueTraits<*your class*>
+// Note: Most compilers do not require that you define both
+// ValueTraits<const T> and ValueTraits<T>, but some do.
+//
+namespace CxxTest
+{
+ CXXTEST_TEMPLATE_INSTANTIATION
+ class ValueTraits<const Pet>
+ {
+ char _asString[256];
+
+ public:
+ ValueTraits( const Pet &pet ) { sprintf( _asString, "Pet(\"%s\")", pet.name() ); }
+ const char *asString() const { return _asString; }
+ };
+
+ CXXTEST_COPY_CONST_TRAITS( Pet );
+}
+
+//
+// Here's how it works
+//
+class TestFunky : public CxxTest::TestSuite
+{
+public:
+ void testPets()
+ {
+ Pet pet1("dog"), pet2("cat");
+ TS_ASSERT_EQUALS( pet1, pet2 );
+ Pet cat("cat"), gato("cat");
+ TS_ASSERT_DIFFERS( cat, gato );
+#ifdef _CXXTEST_HAVE_STD
+ typedef CXXTEST_STD(string) String;
+ TS_ASSERT_EQUALS( String("Hello"), String("World!") );
+#endif // _CXXTEST_HAVE_STD
+ }
+};
+
+#endif // __TRAITSTEST_H
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 <cxxtest/ErrorPrinter.h>
+
+int main()
+{
+ return CxxTest::ErrorPrinter().run();
+}
+
+// The CxxTest "world"
+<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 <cxxtest/StdioPrinter.h>
+#include <stdio.h>
+
+int main( int argc, char *argv[] )
+{
+ if ( argc != 2 ) {
+ fprintf( stderr, "Usage: %s <output file name>\n", argv[0] );
+ return -1;
+ }
+
+ return CxxTest::StdioPrinter( fopen( argv[1], "w" ) ).run();
+}
+
+// The CxxTest "world"
+<CxxTest world>
+
diff --git a/test/cxxtest/sample/gui/GreenYellowRed.h b/test/cxxtest/sample/gui/GreenYellowRed.h
new file mode 100644
index 0000000000..446b23345f
--- /dev/null
+++ b/test/cxxtest/sample/gui/GreenYellowRed.h
@@ -0,0 +1,57 @@
+#include <cxxtest/TestSuite.h>
+
+#ifdef _WIN32
+# include <windows.h>
+# define CXXTEST_SAMPLE_GUI_WAIT() Sleep( 1000 )
+#else // !_WIN32
+ extern "C" unsigned sleep( unsigned seconds );
+# define CXXTEST_SAMPLE_GUI_WAIT() sleep( 1 )
+#endif // _WIN32
+
+class GreenYellowRed : public CxxTest::TestSuite
+{
+public:
+ void wait()
+ {
+ CXXTEST_SAMPLE_GUI_WAIT();
+ }
+
+ void test_Start_green()
+ {
+ wait();
+ }
+
+ void test_Green_again()
+ {
+ TS_TRACE( "Still green" );
+ wait();
+ }
+
+ void test_Now_yellow()
+ {
+ TS_WARN( "Yellow" );
+ wait();
+ }
+
+ void test_Cannot_go_back()
+ {
+ wait();
+ }
+
+ void test_Finally_red()
+ {
+ TS_FAIL( "Red" );
+ wait();
+ }
+
+ void test_Cannot_go_back_to_yellow()
+ {
+ TS_WARN( "Yellow?" );
+ wait();
+ }
+
+ void test_Cannot_go_back_to_green()
+ {
+ wait();
+ }
+};
diff --git a/test/cxxtest/sample/mock/Dice.cpp b/test/cxxtest/sample/mock/Dice.cpp
new file mode 100644
index 0000000000..161b80fa2b
--- /dev/null
+++ b/test/cxxtest/sample/mock/Dice.cpp
@@ -0,0 +1,14 @@
+#include <T/stdlib.h>
+#include "Dice.h"
+
+Dice::Dice()
+{
+ T::srand( T::time( 0 ) );
+}
+
+unsigned Dice::roll()
+{
+ return (T::rand() % 6) + 1;
+}
+
+
diff --git a/test/cxxtest/sample/mock/Dice.h b/test/cxxtest/sample/mock/Dice.h
new file mode 100644
index 0000000000..94271417e1
--- /dev/null
+++ b/test/cxxtest/sample/mock/Dice.h
@@ -0,0 +1,13 @@
+#ifndef __DICE_H
+#define __DICE_H
+
+class Dice
+{
+public:
+ Dice();
+
+ unsigned roll();
+};
+
+#endif // __DICE_H
+
diff --git a/test/cxxtest/sample/mock/Makefile b/test/cxxtest/sample/mock/Makefile
new file mode 100644
index 0000000000..709b7cbe95
--- /dev/null
+++ b/test/cxxtest/sample/mock/Makefile
@@ -0,0 +1,22 @@
+all: roll run
+
+clean:
+ rm -f *~ *.o roll test test.cpp
+
+CXXTEST = ../..
+CCFLAGS = -I. -I$(CXXTEST)
+
+roll: roll.o Dice.o real_stdlib.o
+ g++ -o $@ $^
+
+run: test
+ ./test
+
+test: test.o Dice.o mock_stdlib.o
+ g++ -o $@ $^
+
+.cpp.o:
+ g++ -c -o $@ $(CCFLAGS) $<
+
+test.cpp: TestDice.h
+ $(CXXTEST)/cxxtestgen.pl -o $@ --error-printer $<
diff --git a/test/cxxtest/sample/mock/MockStdlib.h b/test/cxxtest/sample/mock/MockStdlib.h
new file mode 100644
index 0000000000..aee62bafe7
--- /dev/null
+++ b/test/cxxtest/sample/mock/MockStdlib.h
@@ -0,0 +1,31 @@
+#include <T/stdlib.h>
+
+class MockStdlib :
+ public T::Base_srand,
+ public T::Base_rand,
+ public T::Base_time
+{
+public:
+ unsigned lastSeed;
+
+ void srand( unsigned seed )
+ {
+ lastSeed = seed;
+ }
+
+ int nextRand;
+
+ int rand()
+ {
+ return nextRand;
+ }
+
+ time_t nextTime;
+
+ time_t time( time_t *t )
+ {
+ if ( t )
+ *t = nextTime;
+ return nextTime;
+ }
+};
diff --git a/test/cxxtest/sample/mock/T/stdlib.h b/test/cxxtest/sample/mock/T/stdlib.h
new file mode 100644
index 0000000000..30306ba22b
--- /dev/null
+++ b/test/cxxtest/sample/mock/T/stdlib.h
@@ -0,0 +1,13 @@
+#ifndef __T__STDLIB_H
+#define __T__STDLIB_H
+
+#include <stdlib.h>
+#include <time.h>
+
+#include <cxxtest/Mock.h>
+
+CXXTEST_MOCK_VOID_GLOBAL( srand, ( unsigned seed ), ( seed ) );
+CXXTEST_MOCK_GLOBAL( int, rand, ( void ), () );
+CXXTEST_MOCK_GLOBAL( time_t, time, ( time_t *t ), ( t ) );
+
+#endif // __T__STDLIB_H
diff --git a/test/cxxtest/sample/mock/TestDice.h b/test/cxxtest/sample/mock/TestDice.h
new file mode 100644
index 0000000000..35b3b7eec9
--- /dev/null
+++ b/test/cxxtest/sample/mock/TestDice.h
@@ -0,0 +1,62 @@
+#include <cxxtest/TestSuite.h>
+#include "Dice.h"
+#include "MockStdlib.h"
+
+class TestDice : public CxxTest::TestSuite
+{
+public:
+ MockStdlib *stdlib;
+
+ void setUp()
+ {
+ TS_ASSERT( stdlib = new MockStdlib );
+ }
+
+ void tearDown()
+ {
+ delete stdlib;
+ }
+
+ void test_Randomize_uses_time()
+ {
+ stdlib->nextTime = 12345;
+ Dice dice;
+ TS_ASSERT_EQUALS( stdlib->lastSeed, 12345 );
+ }
+
+ void test_Roll()
+ {
+ Dice dice;
+
+ stdlib->nextRand = 0;
+ TS_ASSERT_EQUALS( dice.roll(), 1 );
+
+ stdlib->nextRand = 2;
+ TS_ASSERT_EQUALS( dice.roll(), 3 );
+
+ stdlib->nextRand = 5;
+ TS_ASSERT_EQUALS( dice.roll(), 6 );
+
+ stdlib->nextRand = 7;
+ TS_ASSERT_EQUALS( dice.roll(), 2 );
+ }
+
+ void test_Temporary_override_of_one_mock_function()
+ {
+ Dice dice;
+
+ stdlib->nextRand = 2;
+ TS_ASSERT_EQUALS( dice.roll(), 3 );
+
+ class Five : public T::Base_rand { int rand() { return 5; } };
+
+ Five *five = new Five;
+ TS_ASSERT_EQUALS( dice.roll(), 6 );
+ TS_ASSERT_EQUALS( dice.roll(), 6 );
+ TS_ASSERT_EQUALS( dice.roll(), 6 );
+ delete five;
+
+ stdlib->nextRand = 1;
+ TS_ASSERT_EQUALS( dice.roll(), 2 );
+ }
+};
diff --git a/test/cxxtest/sample/mock/mock_stdlib.cpp b/test/cxxtest/sample/mock/mock_stdlib.cpp
new file mode 100644
index 0000000000..148a044d26
--- /dev/null
+++ b/test/cxxtest/sample/mock/mock_stdlib.cpp
@@ -0,0 +1,2 @@
+#define CXXTEST_MOCK_TEST_SOURCE_FILE
+#include <T/stdlib.h>
diff --git a/test/cxxtest/sample/mock/real_stdlib.cpp b/test/cxxtest/sample/mock/real_stdlib.cpp
new file mode 100644
index 0000000000..db02f3a154
--- /dev/null
+++ b/test/cxxtest/sample/mock/real_stdlib.cpp
@@ -0,0 +1,2 @@
+#define CXXTEST_MOCK_REAL_SOURCE_FILE
+#include <T/stdlib.h>
diff --git a/test/cxxtest/sample/mock/roll.cpp b/test/cxxtest/sample/mock/roll.cpp
new file mode 100644
index 0000000000..20ea967af3
--- /dev/null
+++ b/test/cxxtest/sample/mock/roll.cpp
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include "Dice.h"
+
+int main()
+{
+ Dice dice;
+ printf( "First roll: %u\n", dice.roll() );
+ printf( "Second roll: %u\n", dice.roll() );
+
+ return 0;
+}
diff --git a/test/cxxtest/sample/msvc/CxxTest_1_Run.dsp b/test/cxxtest/sample/msvc/CxxTest_1_Run.dsp
new file mode 100644
index 0000000000..9ab9114d53
--- /dev/null
+++ b/test/cxxtest/sample/msvc/CxxTest_1_Run.dsp
@@ -0,0 +1,93 @@
+# Microsoft Developer Studio Project File - Name="CxxTest_1_Run" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) External Target" 0x0106
+
+CFG=CxxTest_1_Run - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_1_Run.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_1_Run.mak" CFG="CxxTest_1_Run - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "CxxTest_1_Run - Win32 Release" (based on "Win32 (x86) External Target")
+!MESSAGE "CxxTest_1_Run - Win32 Debug" (based on "Win32 (x86) External Target")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+
+!IF "$(CFG)" == "CxxTest_1_Run - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Cmd_Line "NMAKE /f CxxTest_1_Run.mak"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "CxxTest_1_Run.exe"
+# PROP BASE Bsc_Name "CxxTest_1_Run.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Cmd_Line "nmake DIR=Release run"
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "Release\run.log"
+# PROP Bsc_Name ""
+# PROP Target_Dir ""
+
+!ELSEIF "$(CFG)" == "CxxTest_1_Run - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Cmd_Line "NMAKE /f CxxTest_1_Run.mak"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "CxxTest_1_Run.exe"
+# PROP BASE Bsc_Name "CxxTest_1_Run.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Cmd_Line "nmake DIR=Debug run"
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "Debug\run.log"
+# PROP Bsc_Name ""
+# PROP Target_Dir ""
+
+!ENDIF
+
+# Begin Target
+
+# Name "CxxTest_1_Run - Win32 Release"
+# Name "CxxTest_1_Run - Win32 Debug"
+
+!IF "$(CFG)" == "CxxTest_1_Run - Win32 Release"
+
+!ELSEIF "$(CFG)" == "CxxTest_1_Run - Win32 Debug"
+
+!ENDIF
+
+# Begin Source File
+
+SOURCE=.\Makefile
+# End Source File
+# Begin Source File
+
+SOURCE=.\ReadMe.txt
+# End Source File
+# End Target
+# End Project
diff --git a/test/cxxtest/sample/msvc/CxxTest_2_Build.dsp b/test/cxxtest/sample/msvc/CxxTest_2_Build.dsp
new file mode 100644
index 0000000000..301320d84b
--- /dev/null
+++ b/test/cxxtest/sample/msvc/CxxTest_2_Build.dsp
@@ -0,0 +1,94 @@
+# Microsoft Developer Studio Project File - Name="CxxTest_2_Build" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=CxxTest_2_Build - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_2_Build.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_2_Build.mak" CFG="CxxTest_2_Build - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "CxxTest_2_Build - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "CxxTest_2_Build - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "CxxTest_2_Build - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x40d /d "NDEBUG"
+# ADD RSC /l 0x40d /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Release/runner.exe"
+
+!ELSEIF "$(CFG)" == "CxxTest_2_Build - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x40d /d "_DEBUG"
+# ADD RSC /l 0x40d /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/runner.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "CxxTest_2_Build - Win32 Release"
+# Name "CxxTest_2_Build - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\ReadMe.txt
+# End Source File
+# Begin Source File
+
+SOURCE=.\runner.cpp
+# End Source File
+# End Target
+# End Project
diff --git a/test/cxxtest/sample/msvc/CxxTest_3_Generate.dsp b/test/cxxtest/sample/msvc/CxxTest_3_Generate.dsp
new file mode 100644
index 0000000000..1dd6d4dc5d
--- /dev/null
+++ b/test/cxxtest/sample/msvc/CxxTest_3_Generate.dsp
@@ -0,0 +1,93 @@
+# Microsoft Developer Studio Project File - Name="CxxTest_3_Generate" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) External Target" 0x0106
+
+CFG=CxxTest_3_Generate - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_3_Generate.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_3_Generate.mak" CFG="CxxTest_3_Generate - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "CxxTest_3_Generate - Win32 Release" (based on "Win32 (x86) External Target")
+!MESSAGE "CxxTest_3_Generate - Win32 Debug" (based on "Win32 (x86) External Target")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+
+!IF "$(CFG)" == "CxxTest_3_Generate - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Cmd_Line "NMAKE /f CxxTest_3_Generate.mak"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "CxxTest_3_Generate.exe"
+# PROP BASE Bsc_Name "CxxTest_3_Generate.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Cmd_Line "nmake runner.cpp"
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "runner.cpp"
+# PROP Bsc_Name ""
+# PROP Target_Dir ""
+
+!ELSEIF "$(CFG)" == "CxxTest_3_Generate - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Cmd_Line "NMAKE /f CxxTest_3_Generate.mak"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "CxxTest_3_Generate.exe"
+# PROP BASE Bsc_Name "CxxTest_3_Generate.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Cmd_Line "nmake runner.cpp"
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "runner.cpp"
+# PROP Bsc_Name ""
+# PROP Target_Dir ""
+
+!ENDIF
+
+# Begin Target
+
+# Name "CxxTest_3_Generate - Win32 Release"
+# Name "CxxTest_3_Generate - Win32 Debug"
+
+!IF "$(CFG)" == "CxxTest_3_Generate - Win32 Release"
+
+!ELSEIF "$(CFG)" == "CxxTest_3_Generate - Win32 Debug"
+
+!ENDIF
+
+# Begin Source File
+
+SOURCE=.\Makefile
+# End Source File
+# Begin Source File
+
+SOURCE=.\ReadMe.txt
+# End Source File
+# End Target
+# End Project
diff --git a/test/cxxtest/sample/msvc/CxxTest_Workspace.dsw b/test/cxxtest/sample/msvc/CxxTest_Workspace.dsw
new file mode 100644
index 0000000000..9a88de6ef7
--- /dev/null
+++ b/test/cxxtest/sample/msvc/CxxTest_Workspace.dsw
@@ -0,0 +1,59 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "CxxTest_1_Run"=.\CxxTest_1_Run.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name CxxTest_2_Build
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "CxxTest_2_Build"=.\CxxTest_2_Build.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name CxxTest_3_Generate
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "CxxTest_3_Generate"=.\CxxTest_3_Generate.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/test/cxxtest/sample/msvc/FixFiles.bat b/test/cxxtest/sample/msvc/FixFiles.bat
new file mode 100644
index 0000000000..fb14a6c495
--- /dev/null
+++ b/test/cxxtest/sample/msvc/FixFiles.bat
@@ -0,0 +1,212 @@
+@rem = '--*-Perl-*--
+@echo off
+if "%OS%" == "Windows_NT" goto WinNT
+perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
+goto endofperl
+:WinNT
+perl -x -S %0 %*
+if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
+if %errorlevel% == 9009 echo You do not have Perl in your PATH.
+if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
+goto endofperl
+@rem ';
+#!/usr/bin/perl -w
+#line 15
+use strict;
+use English;
+use Getopt::Long;
+
+$OUTPUT_AUTOFLUSH = 1;
+
+sub usage() {
+ print STDERR "Usage: $0 <OPTIONS>\n\n";
+ print STDERR "Fix Makefile and CxxTest_2_Build.dsp for your setup.\n\n";
+ print STDERR " --cxxtest=DIR Assume CxxTest is installed in DIR (default: '..\\..')\n";
+ print STDERR " --tests=SPEC Use SPEC for the test files (default: '../gui/*.h ../*.h')\n\n";
+ print STDERR "You must specify at least one option.\n";
+ exit -1;
+}
+
+my ($cxxtest, $tests);
+my ($Makefile, $CxxTest_2_Build);
+
+sub main {
+ parseCommandline();
+ fixFiles();
+}
+
+sub parseCommandline() {
+ GetOptions( 'cxxtest=s' => \$cxxtest,
+ 'tests=s' => \$tests,
+ ) or usage();
+
+ usage() unless (defined($cxxtest) || defined($tests));
+ $cxxtest = '..\\..' unless defined($cxxtest);
+ $tests = '../gui/*.h ../*.h' unless defined($tests);
+}
+
+sub fixFiles() {
+ fixFile( $Makefile, 'Makefile' );
+ fixFile( $CxxTest_2_Build, 'CxxTest_2_Build.dsp' );
+}
+
+sub fixFile($$) {
+ my ($data, $output) = @_;
+
+ print "$output...";
+
+ $data =~ s/<TESTS>/$tests/g;
+ $data =~ s/<CXXTEST>/$cxxtest/g;
+
+ open OUTPUT, ">$output" or die "Cannot create output file \"$output\"\n";
+ print OUTPUT $data;
+ close OUTPUT;
+
+ print "OK\n";
+}
+
+$Makefile =
+'# Where to look for the tests
+TESTS = <TESTS>
+
+# Where the CxxTest distribution is unpacked
+CXXTESTDIR = <CXXTEST>
+
+# Check CXXTESTDIR
+!if !exist($(CXXTESTDIR)\cxxtestgen.pl)
+!error Please fix CXXTESTDIR
+!endif
+
+# cxxtestgen needs Perl or Python
+!if defined(PERL)
+CXXTESTGEN = $(PERL) $(CXXTESTDIR)/cxxtestgen.pl
+!elseif defined(PYTHON)
+CXXTESTGEN = $(PYTHON) $(CXXTESTDIR)/cxxtestgen.py
+!else
+!error You must define PERL or PYTHON
+!endif
+
+# The arguments to pass to cxxtestgen
+# - ParenPrinter is the way MSVC likes its compilation errors
+# - --have-eh/--abort-on-fail are nice when you have them
+CXXTESTGEN_FLAGS = --gui=Win32Gui --runner=ParenPrinter --have-eh --abort-on-fail
+
+# How to generate the test runner, "runner.cpp"
+runner.cpp: $(TESTS)
+ $(CXXTESTGEN) $(CXXTESTGEN_FLAGS) -o $@ $(TESTS)
+
+# Command-line arguments to the runner
+RUNNER_FLAGS = -title "CxxTest Runner"
+
+# How to run the tests, which should be in DIR\runner.exe
+run: $(DIR)\runner.exe
+ $(DIR)\runner.exe $(RUNNER_FLAGS)
+';
+
+$CxxTest_2_Build =
+'# Microsoft Developer Studio Project File - Name="CxxTest_2_Build" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=CxxTest_2_Build - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_2_Build.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "CxxTest_2_Build.mak" CFG="CxxTest_2_Build - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "CxxTest_2_Build - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "CxxTest_2_Build - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "CxxTest_2_Build - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "<CXXTEST>" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x40d /d "NDEBUG"
+# ADD RSC /l 0x40d /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Release/runner.exe"
+
+!ELSEIF "$(CFG)" == "CxxTest_2_Build - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "<CXXTEST>" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x40d /d "_DEBUG"
+# ADD RSC /l 0x40d /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/runner.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "CxxTest_2_Build - Win32 Release"
+# Name "CxxTest_2_Build - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\ReadMe.txt
+# End Source File
+# Begin Source File
+
+SOURCE=.\runner.cpp
+# End Source File
+# End Target
+# End Project
+';
+
+main();
+
+__END__
+:endofperl
+
+rem
+rem Local Variables:
+rem compile-command: "perl FixFiles.bat"
+rem End:
+rem
diff --git a/test/cxxtest/sample/msvc/Makefile b/test/cxxtest/sample/msvc/Makefile
new file mode 100644
index 0000000000..606004d4cf
--- /dev/null
+++ b/test/cxxtest/sample/msvc/Makefile
@@ -0,0 +1,36 @@
+# Where to look for the tests
+TESTS = ..\gui\*.h ..\*.h
+
+# Where the CxxTest distribution is unpacked
+CXXTESTDIR = ..\..
+
+# Check CXXTESTDIR
+!if !exist($(CXXTESTDIR)\cxxtestgen.pl)
+!error Please fix CXXTESTDIR
+!endif
+
+# cxxtestgen needs Perl or Python
+!if defined(PERL)
+CXXTESTGEN = $(PERL) $(CXXTESTDIR)/cxxtestgen.pl
+!elseif defined(PYTHON)
+CXXTESTGEN = $(PYTHON) $(CXXTESTDIR)/cxxtestgen.py
+!else
+!error You must define PERL or PYTHON
+!endif
+
+# The arguments to pass to cxxtestgen
+# - ParenPrinter is the way MSVC likes its compilation errors
+# - --have-eh/--abort-on-fail are nice when you have them
+CXXTESTGEN_FLAGS = \
+ --gui=Win32Gui \
+ --runner=ParenPrinter \
+ --have-eh \
+ --abort-on-fail
+
+# How to generate the test runner, `runner.cpp'
+runner.cpp: $(TESTS)
+ $(CXXTESTGEN) $(CXXTESTGEN_FLAGS) -o $@ $(TESTS)
+
+# How to run the tests, which should be in DIR\runner.exe
+run: $(DIR)\runner.exe
+ $(DIR)\runner.exe
diff --git a/test/cxxtest/sample/msvc/ReadMe.txt b/test/cxxtest/sample/msvc/ReadMe.txt
new file mode 100644
index 0000000000..816fce45b0
--- /dev/null
+++ b/test/cxxtest/sample/msvc/ReadMe.txt
@@ -0,0 +1,30 @@
+Sample files for Visual Studio
+==============================
+
+There are three projects in this workspace:
+
+ - CxxTest_3_Generate runs cxxtestgen to create runner.cpp
+ - CxxTest_2_Build compiles the generated file
+ - CxxTest_1_Run runs the compiled binary
+
+Whenever you build this workspace, the tests are run, and any failed assertions
+are displayed as compilation errors (you can browse them using F4).
+
+Note that to run this sample, you need first to create an environment
+variable PERL or PYTHON, e.g. PERL=c:\perl\bin\perl.exe
+
+
+To use these .dsp and .dsw files in your own project, run FixFiles.bat
+to adjust them to where you've placed CxxTest and your own tests.
+
+If you want to use just the .dsp files in your own workspace, don't
+forget to:
+
+ - Set up the dependencies (CxxTest_3_Generate depends on
+ CxxTest_2_Build which depends on CxxTest_1_Run)
+
+ - Add your own include paths, libraries etc. to the CxxTest_2_Build project
+
+
+NOTE: I haven't used "Post-Build Step" to run the tests because I
+wanted the tests to be executed even if nothing has changed.
diff --git a/test/cxxtest/sample/only.tpl b/test/cxxtest/sample/only.tpl
new file mode 100644
index 0000000000..b2a7277cf6
--- /dev/null
+++ b/test/cxxtest/sample/only.tpl
@@ -0,0 +1,33 @@
+// -*- C++ -*-
+#include <cxxtest/StdioPrinter.h>
+#include <stdio.h>
+
+int main( int argc, char *argv[] )
+{
+ if ( argc < 2 || argc > 3 ) {
+ fprintf( stderr, "Usage: only <suite name> [<test name>]\n\n" );
+ fprintf( stderr, "Available tests:\n" );
+ CxxTest::RealWorldDescription wd;
+ for ( CxxTest::SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() )
+ for ( CxxTest::TestDescription *td = sd->firstTest(); td; td = td->next() )
+ fprintf( stderr, " - %s::%s()\n", sd->suiteName(), td->testName() );
+ return 1;
+ }
+
+ const char *suiteName = argv[1];
+ const char *testName = (argc > 2) ? argv[2] : 0;
+ if ( !CxxTest::leaveOnly( suiteName, testName ) ) {
+ if ( testName )
+ fprintf( stderr, "Cannot find %s::%s()\n", argv[1], argv[2] );
+ else
+ fprintf( stderr, "Cannot find class %s\n", argv[1] );
+ return 2;
+ }
+
+ return CxxTest::StdioPrinter().run();
+}
+
+
+// The CxxTest "world"
+<CxxTest world>
+
diff --git a/test/cxxtest/sample/parts/Makefile.unix b/test/cxxtest/sample/parts/Makefile.unix
new file mode 100644
index 0000000000..5e6ae4e43c
--- /dev/null
+++ b/test/cxxtest/sample/parts/Makefile.unix
@@ -0,0 +1,39 @@
+#
+# (GNU) Makefile for UN*X-like systems
+# This makefile shows how to make a different runner for each test
+#
+
+.PHONY: all clean
+
+all: run
+
+clean:
+ rm -f *~ *.cpp *.o runner
+
+CXXTESTDIR = ../..
+CXXTESTGEN = $(CXXTESTDIR)/cxxtestgen.pl
+CXXTESTFLAGS = --have-eh --abort-on-fail
+
+TESTS = $(wildcard ../*Test.h)
+OBJS = runner.o $(TESTS:../%.h=%.o)
+
+run: runner
+ ./runner
+
+runner: $(OBJS)
+ c++ -o $@ $^
+
+%.o: %.cpp
+ c++ -c -o $@ -I $(CXXTESTDIR) -I .. $^
+
+%.cpp: ../%.h
+ $(CXXTESTGEN) $(CXXTESTFLAGS) --part -o $@ $^
+
+runner.cpp:
+ $(CXXTESTGEN) $(CXXTESTFLAGS) --root --error-printer -o $@
+
+#
+# Local Variables:
+# compile-command: "make -fMakefile.unix"
+# End:
+#
diff --git a/test/cxxtest/sample/winddk/Makefile b/test/cxxtest/sample/winddk/Makefile
new file mode 100644
index 0000000000..8bf25333e8
--- /dev/null
+++ b/test/cxxtest/sample/winddk/Makefile
@@ -0,0 +1,2 @@
+# Standard DDK Makefile
+!include $(NTMAKEENV)\makefile.def
diff --git a/test/cxxtest/sample/winddk/Makefile.inc b/test/cxxtest/sample/winddk/Makefile.inc
new file mode 100644
index 0000000000..edc6f8c8cb
--- /dev/null
+++ b/test/cxxtest/sample/winddk/Makefile.inc
@@ -0,0 +1,15 @@
+# -*- Makefile -*-
+
+#
+# Tell the DDK how to generate RunTests.cpp from RunTests.tpl and the tests
+#
+
+PERL=perl
+PYTHON=python
+CXXTESTGEN=$(PERL) $(CXXTESTDIR)/cxxtestgen.pl
+#CXXTESTGEN=$(PYTHON) $(CXXTESTDIR)/cxxtestgen.py
+
+TEST_SUITES=$(SUITESDIR)/*.h
+
+RunTests.cpp: RunTests.tpl $(TEST_SUITES)
+ $(CXXTESTGEN) -o $@ --template=RunTests.tpl $(TEST_SUITES)
diff --git a/test/cxxtest/sample/winddk/RunTests.tpl b/test/cxxtest/sample/winddk/RunTests.tpl
new file mode 100644
index 0000000000..917f14b4d6
--- /dev/null
+++ b/test/cxxtest/sample/winddk/RunTests.tpl
@@ -0,0 +1,13 @@
+// -*- C++ -*-
+
+//
+// The DDK doesn't handle <iostream> too well
+//
+#include <cxxtest/StdioPrinter.h>
+
+int __cdecl main()
+{
+ return CxxTest::StdioPrinter().run();
+}
+
+<CxxTest world>
diff --git a/test/cxxtest/sample/winddk/SOURCES b/test/cxxtest/sample/winddk/SOURCES
new file mode 100644
index 0000000000..dae0148885
--- /dev/null
+++ b/test/cxxtest/sample/winddk/SOURCES
@@ -0,0 +1,46 @@
+# -*- Makefile -*-
+
+#
+# Build this sample with the Windows DDK (XP or later)
+#
+SUITESDIR=..
+CXXTESTDIR=../..
+
+#
+# Build a user-mode application
+#
+TARGETNAME=RunTests
+TARGETPATH=.
+TARGETTYPE=PROGRAM
+
+#
+# Make it a console-mode app
+#
+UMTYPE=console
+
+#
+# Add CxxTest and tests directory to include path
+#
+INCLUDES=$(SUITESDIR);$(CXXTESTDIR)
+
+#
+# Enable exception handling and standard library
+#
+USE_NATIVE_EH=1
+LINKER_FLAGS=$(LINKER_FLAGS) -IGNORE:4099
+386_WARNING_LEVEL=-W3 -WX -wd4290
+
+TARGETLIBS=\
+ $(CRT_LIB_PATH)\libcp.lib \
+ $(CRT_LIB_PATH)\libc.lib
+
+#
+# Only one source file -- the generated test runner
+#
+SOURCES=RunTests.cpp
+
+#
+# This line tells the build utility to process Makefile.inc
+#
+NTTARGETFILE0=RunTests.cpp
+
diff --git a/test/cxxtest/sample/yes_no_runner.cpp b/test/cxxtest/sample/yes_no_runner.cpp
new file mode 100644
index 0000000000..c32b94cd5c
--- /dev/null
+++ b/test/cxxtest/sample/yes_no_runner.cpp
@@ -0,0 +1,11 @@
+//
+// A sample program that uses class YesNoRunner to run all the tests
+// and find out if all pass.
+//
+
+#include <cxxtest/YesNoRunner.h>
+
+int main()
+{
+ return CxxTest::YesNoRunner().run();
+}