Test Suite

wpkg comes with a test suite that runs against the different libraries and tools. These tests ensure the validity of the project. It is expected that running all the tests (once the suite is complete) will cover around 99% of the code (i.e. full coverage.) The libexpr is already fully covered.

Commane Line Options

Once built, the unittest executable supports the following command line options that can be used to only run one specific test or a part of the tree of tests.

Commands

  • --all or -a — run all the tests
  • --license — print out the license of the unittest software
  • --list or -l — list all the available tests
  • --gui or -g — run the GUI version (may not work on your platform)
  • --version or -V — version of wpkg this test suites pertains to
  • --help or -h — print out a list of the command line options and exit

Options

  • --tmp or -t <directory> -- specify the path to a temporary directory; it will be created if it does not exist yet; this path is required by tests that test packages; if not available the tests fail (in other words, this parameter is pretty much mandatory.)
  • --wpkg or -w <path> — path to the wpkg command line option used to build and manage packages

Test Selection

--all is the default (similar to not specifying anything on the command line.)

--list gives you the list of tests that are available. Those names can be used on the command line to run just those tests and their children. There is an example of output (the current version already has many more tests):

prompt> BUILD/tests/unittests/unittest -l
All Tests
  MemfileUnitTests
    MemfileUnitTests::compression1
    MemfileUnitTests::compression2
    MemfileUnitTests::compression3
    MemfileUnitTests::compression4
    MemfileUnitTests::compression5
    MemfileUnitTests::compression6
    MemfileUnitTests::compression7
    MemfileUnitTests::compression8
    MemfileUnitTests::compression9
  URIFilenameUnitTests
    URIFilenameUnitTests::path

Out of this list you could enter the following to test the URI filename class:

unittest URIFilenameUnitTests

This is quite practical if you are making changes to that part of the software only.

Running the Package Tests

The package unit tests are peculiar in that they make use of a temporary directory to create sets of packages and then manage them on a target. All the files necessary for this test are all created under this temporary directory.

Similarly, you have to define a path to the wpkg tool, including the name of the tool. For example, assuming you are compiling wpkg under a directory named BUILD, the wpkg tool would be found under BUILD/tools/wpkg, under MS-Windows, you have an additional Release or Debug directory and the tool has a .exe extension.

unittest --wpkg BUILD/tools/wpkg --tmp tmp/unittest

There are no defaults for either one of these options. If not specified the Package Tests all fail.

Ubuntu (and probably other Debian and Linux platforms)

Under Ubuntu, you want to install the cppunit packages:

apt-get install libcppunit-1.12-1 libcppunit-dev libcppunit-doc

The version of the cppunit library is likely different on your version of Ubuntu (I have 12.04 at this time). To find the correct version use the search command like this:

apt-cache search libcppunit | less

Then browse the result for the library and its version.

If you also want the graphical interface coming with cppunit, use the following command:

apt-get install libqxcppunit-dev libqxcppunitd1 libqxrunner-dev libqxrunnerd1

cppunit organization under MS-Windows so it links and runs as expected.This adds the "qx" environment as it is called under Ubuntu. This is slightly diferent from the usual Qt extension supported by cppunit but the final result is pretty much the same.

MS-Windows

For MS-Windows, we do not facilate the task either. Not only that, you'll have to recompile cppunit yourself (we'll offer a package at some point though.)

The library can be found on SourceForge: https://sourceforge.net/projects/cppunit/

I suggest you download the latest source, although if you find binaries, you could attempt to use those... We only make use of the static cppunit.lib though.

To compile, open the cppunit-<version>/src/cppunit directory. It includes a couple of .dsp file. Open the cppunit.dsp. If you have a newer version of the IDE then the dsp file will automatically be converted. It should not cause any problem. Compile!

IMPORTANT NOTE

If you are creating the library under MS-Windows 64 bit, then note that the library is compiled in 32 bits only by default. To allow for 64 bit, enter the configuration manager and add 64 bit configuration as a copy of the existing 32 bit configuration. Then make sure it is selected when you compile.

The result is: cppunit.lib — that's it!

Now, you want to copy all the header files (include directory) and this cppunit.lib in your wpkg unittests environment. The cmake script searches for the cppunit data under a directory named cppunit which includes two directories: include and lib. The include has all the headers under a cppunit directory. The cppunit.lib directly appears under the lib directory. I did not use a debug version on my end. At this point I cannot compile the debug version of cppunit, and I run the result in the console anyway so it wouldn't help much to have debugs.

The image to the right shows you the directory structure I have for cppunit to work with wpkg under MS-Windows.

If you have problems, make sure to use the GUI based cmake tool and look what variables fail to be set. Look at the tests/unittests/cmake/FindCPPUNIT.cmake to see what the test does. If you are working in a cygwin or mingw32 environment, cppunit may be found under /usr/include and /usr/lib instead.

We will improve the unit test environment once we have our own packages of all those parts so everyone can just install the packages and the cmake tool will then automatically find all the necessary libraries. Until then... you'll have to follow those instructions to the letter to make it all work on your system.