| 1 |
|
| 2 |
CUnit : A Unit Testing Framework |
| 3 |
http://cunit.sourceforge.net |
| 4 |
|
| 5 |
CUnit is a Unit testing framework for C. |
| 6 |
|
| 7 |
The basic framework is platform/version independent and should be |
| 8 |
portable to all platforms. CUnit provides various interfaces to |
| 9 |
the framework, some of which are platform dependent (e.g. curses on |
| 10 |
*nix). Building other interfaces should be straightforward with |
| 11 |
the facilities provided in the framework. |
| 12 |
|
| 13 |
CUnit is built as either a static or shared library which provides |
| 14 |
framework support when linked into user testing code. The framework |
| 15 |
complies with the conventional structure of test cases bundled into |
| 16 |
suites which are registered with the framework for running. See the |
| 17 |
documentation for more about the structure and use of the framework. |
| 18 |
|
| 19 |
Note - the windows-specific gui interface is not yet written. It is |
| 20 |
still necessary to use either the automated, basic, or console |
| 21 |
interfaces to CUnit on Windows at this time. |
| 22 |
|
| 23 |
------------------------------------------------------- |
| 24 |
Important Note - Changes to CUnit Structure & Interface |
| 25 |
------------------------------------------------------- |
| 26 |
|
| 27 |
As of version 2.0, the interface functions used to interact with the |
| 28 |
CUnit framework have changed. The original interface did not attempt |
| 29 |
to protect user code from name clashes with public CUnit functions and |
| 30 |
variables. To minimize such name clashes, all CUnit public functions |
| 31 |
are now prefixed with 'CU_'. |
| 32 |
|
| 33 |
The old public names are deprecated as of Version 2.0, but continue |
| 34 |
to be supported with conversion macros. In order to compile older code |
| 35 |
using the original interface, it is now necessary to compile with the |
| 36 |
macro -USE_DEPRECATED_CUNIT_NAMES defined. If there are any problems |
| 37 |
compiling older code, please file a bug report. |
| 38 |
|
| 39 |
In addition, the DTD and XSL files for output from the automated test |
| 40 |
interface have been updated to support both old and new file structure. |
| 41 |
That is, a List or Run file generated using the version 1.1 library |
| 42 |
should be (1) valid under the version 2 DTD's and (2) formatted |
| 43 |
correctly by the version 2 XSL's. Note, however, that this has not |
| 44 |
been extended to the Memory-Dump DTD and XSL files. That is, memory |
| 45 |
dumps created using version 1.1 are ill-formed and incorrectly |
| 46 |
formatted using the version 2 DTD and XSL files. |
| 47 |
|
| 48 |
Another exception to backward compatibility occurs if the user has |
| 49 |
directly manipulated the global variables in version 1.1. The |
| 50 |
original CUnit structure included global variables error_number and |
| 51 |
g_pTestRegistry which have been removed from the global namespace as |
| 52 |
of Version 2.0. Any user code which directly accessed these variables |
| 53 |
will break. The variables must be retrieved using the accessor |
| 54 |
functions CU__get_error() and CU_get_registry(). |
| 55 |
|
| 56 |
Similarly, user code retrieving the active test registry and directly |
| 57 |
manipulating the uiNumberOfFailures or pResult members will break. |
| 58 |
These members have been moved to the TestRun.c part of the framework |
| 59 |
and are no longer available in the test registry as of version 2.0. |
| 60 |
|
| 61 |
Another change in Version 2.0 is the update of the framework terminology. |
| 62 |
What were termed 'test groups' in the original structure are now called |
| 63 |
"suites", and "test cases" are now just "tests". This change was made to |
| 64 |
bring CUnit in conformance with standard testing terminology, and results |
| 65 |
in a change in the name of some functions (e.g. run_group_tests() is |
| 66 |
now CU_run_suite(). |
| 67 |
|
| 68 |
--------------------------------------- |
| 69 |
Building the CUnit Library and Examples |
| 70 |
--------------------------------------- |
| 71 |
|
| 72 |
All Platforms: |
| 73 |
|
| 74 |
As of Version 2.0, a set of Jamfiles is provided for cross-platform |
| 75 |
building of the library, examples, and tests. The jam build system was |
| 76 |
implemented using ftjam 2.3.2 (http://www.freetype.org/jam/index.html). |
| 77 |
It may work under the original Perforce jam implementation, but has not |
| 78 |
been tested. It has been tested under gcc on Linux, and Borland C++ 5.5, |
| 79 |
VC7, MinGW 3.2.3, and Open Watcom 1.3 on Windows. Due to the nature of |
| 80 |
jam, the build system should be readily extensible to other platforms. |
| 81 |
|
| 82 |
The jam file set supports both standard and custom symbolic build |
| 83 |
targets (install, uninstall, clean, libcunit, examples, test). A |
| 84 |
customized Jambase file is provided which sorts out some of the |
| 85 |
rough edges for MinGW and Watcom on Windows. It may not be necessary |
| 86 |
when using gcc, Borland, or VC, but it won't hurt either. |
| 87 |
|
| 88 |
The files generated during the build are placed in a subdirectory |
| 89 |
given by <CONFIG>/<PLATFORM>, where: |
| 90 |
|
| 91 |
<CONFIG> = Debug or Release |
| 92 |
<PLATFORM> = bcc, mingw, msvc, watcom, linux |
| 93 |
|
| 94 |
This allows easy switching between compilers without overlap of the output |
| 95 |
files. The <CONFIG> is determined by whether NODEBUG is defined in your |
| 96 |
Jamrules file. <PLATFORM> is set automatically in Jamrules. |
| 97 |
|
| 98 |
To build using jam: |
| 99 |
|
| 100 |
1. Set the working directory to the top of the source tree |
| 101 |
|
| 102 |
2. Generate Jamrules |
| 103 |
a. On Linux, run autoconf & configure |
| 104 |
b. On Windows, copy Jamrules.in to Jamrules |
| 105 |
|
| 106 |
3. Edit the top section of Jamrules to match your preferences |
| 107 |
|
| 108 |
4. jam -f Jambase install |
| 109 |
|
| 110 |
Linux: |
| 111 |
|
| 112 |
In addition to jam, the standard GNU build system is still supported. |
| 113 |
The usual sequence of steps should succeed in building and installing CUnit: |
| 114 |
1. aclocal (if necessary) |
| 115 |
2. autoconf (if necessary) |
| 116 |
3. automake (if necessary) |
| 117 |
4. chmod u+x configure (if necessary) |
| 118 |
5. ./configure --prefix <Your choice of directory for installation> |
| 119 |
6. make |
| 120 |
7. make install |
| 121 |
|
| 122 |
What's installed: |
| 123 |
1. libcunit.a (Library file) |
| 124 |
2. CUnit Header files |
| 125 |
3. DTD and XSL files supporting xml output files in share directory |
| 126 |
4. Man Pages in relevant man directories under the installation path. |
| 127 |
5. HTML users guide in the doc subdirectory of the installation path. |
| 128 |
6. Example & test programs in the share subdirectory of the install path. |
| 129 |
|
| 130 |
Windows: |
| 131 |
|
| 132 |
Jam is the preferred build system for Windows. A set of old VC6 project |
| 133 |
files is included which have been partially updated but not tested. If |
| 134 |
they don't work and you get them working, we'd be happy to include them |
| 135 |
in the CUnit distribution. A set of Visual Studio 2003/VC7 solution and |
| 136 |
project files has also been provided in the VC7 subdirectory. Similarly, |
| 137 |
a set of Visual Studio 2005/VC8 solution and project files is located in |
| 138 |
the VC8 subdirectory. The latter should work with all versions of VC 2005, |
| 139 |
including the Express edition. |