Changes for new ctest framework.

This commit is contained in:
John McNamara 2014-08-08 00:37:42 +01:00
parent fc51b4d7b1
commit ec995a785b
6 changed files with 28 additions and 55 deletions

9
.gitignore vendored
View file

@ -35,15 +35,6 @@ examples/*
cov-int
libxlsxwriter-coverity.tgz
third_party/gtest-1.7.0/Makefile
third_party/gtest-1.7.0/build-aux/config.h
third_party/gtest-1.7.0/build-aux/stamp-h1
third_party/gtest-1.7.0/config.log
third_party/gtest-1.7.0/config.status
third_party/gtest-1.7.0/lib/
third_party/gtest-1.7.0/libtool
third_party/gtest-1.7.0/scripts/gtest-config
third_party/zlib-1.2.8/configure.log
third_party/zlib-1.2.8/contrib/minizip/miniunz
third_party/zlib-1.2.8/contrib/minizip/minizip

View file

@ -46,52 +46,25 @@ The functional tests can then be run:
The unit tests test the components of the library at the level of individual
functions or compilation units.
The unit tests require the [googletest](https://code.google.com/p/googletest/)
test framework. There isn't a default installation method for `googletest` but
the following method from
[StackOverflow](http://stackoverflow.com/questions/13513905/how-to-properly-setup-googletest-on-linux)
works on Linux and OS X:
The unit tests uses the [ctest](http://github.com/bvdberg/ctest) test
framework. This is included as a header file in the `test/unit` directory
and doesn't need to be installed.
wget http://googletest.googlecode.com/files/gtest-1.7.0.zip
unzip gtest-1.7.0.zip
cd gtest-1.7.0
./configure
make
sudo cp -a include/gtest /usr/include
sudo cp -a lib/.libs/lib* /usr/lib/
The unit tests can then be run as follows. Note, the compilation of the unit
tests can take some time:
The unit tests can then be run as follows:
$ make test_unit
Compiling unit tests ...
Running main() from gtest_main.cc
[==========] Running 146 tests from 10 test cases.
[----------] Global test environment set-up.
[----------] 9 tests from utility
[ RUN ] utility._datetime_date_and_time
[ OK ] utility._datetime_date_and_time (0 ms)
[ RUN ] utility._datetime_date_only
[ OK ] utility._datetime_date_only (0 ms)
TEST 1/155 utility:_datetime_date_and_time [OK]
TEST 2/155 utility:_datetime_date_only [OK]
TEST 3/155 utility:_datetime_date_only_1904 [OK]
TEST 4/155 utility:_datetime_time_only [OK]
...
[ RUN ] styles.write_xf33
[ OK ] styles.write_xf33 (0 ms)
[ RUN ] styles.write_xf34
[ OK ] styles.write_xf34 (1 ms)
[ RUN ] styles.write_xf35
[ OK ] styles.write_xf35 (0 ms)
[ RUN ] styles.write_xf36
[ OK ] styles.write_xf36 (0 ms)
[ RUN ] styles.xml_declaration
[ OK ] styles.xml_declaration (0 ms)
[----------] 74 tests from styles (17 ms total)
[----------] Global test environment tear-down
[==========] 146 tests from 10 test cases ran. (33 ms total)
[ PASSED ] 146 tests.
TEST 152/155 styles:write_xf34 [OK]
TEST 153/155 styles:write_xf35 [OK]
TEST 154/155 styles:write_xf36 [OK]
TEST 155/155 styles:xml_declaration [OK]
RESULTS: 155 tests (155 ok, 0 failed, 0 skipped) ran in 42 ms
Both functional and unit test can be run together:

View file

@ -61,7 +61,7 @@ all :
# END make all
clean :
$(Q)rm -f $(TESTS) test_all
$(Q)rm -f $(TESTS) test_all *.o
$(Q)$(MAKE) clean -C utility
$(Q)$(MAKE) clean -C xmlwriter
$(Q)$(MAKE) clean -C worksheet

View file

@ -32,7 +32,7 @@ all : $(TESTS)
# Clean all the things!
clean :
$(Q)rm -f $(TESTS) test*.o
$(Q)rm -f $(TESTS) test_all *.o
# Build the testscases.
%.o: %.c

View file

@ -18,6 +18,9 @@
#ifndef CTEST_H
#define CTEST_H
#include <math.h>
#include <float.h>
typedef void (*SetupFunc)(void*);
typedef void (*TearDownFunc)(void*);
@ -264,8 +267,13 @@ void assert_not_equal(long exp, long real, const char* caller, int line) {
}
void assert_double(double exp, double real, const char* caller, int line) {
if (exp != real) {
CTEST_ERR("%s:%d expected %g, got %g", caller, line, exp, real);
double diff = fabs(exp - real);
exp = fabs(exp);
real = fabs(real);
double largest = (real > exp) ? real : exp;
if (diff > largest * FLT_EPSILON) {
CTEST_ERR("%s:%d DEXPECTED %g, got %g", caller, line, exp, real);
}
}
@ -430,7 +438,7 @@ int ctest_main(int argc, const char *argv[])
const char* color = (num_fail) ? ANSI_RED : ANSI_GREEN;
char results[80];
sprintf(results, "\nRESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %lld ms",
total, num_ok, num_fail, num_skip, (t2 - t1)/1000);
total, num_ok, num_fail, num_skip, (long long int)(t2 - t1)/1000);
color_print(color, results);
return num_fail;
}

View file

@ -161,6 +161,7 @@ CTEST(worksheet, spans04) {
// Test assembling a Worksheet file with different span ranges.
CTEST(worksheet, spans05) {
int i;
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
@ -281,7 +282,7 @@ CTEST(worksheet, spans05) {
worksheet->file = testfile;
worksheet->selected = 1;
for (int i = 0; i < 20; i++)
for (i = 0; i < 20; i++)
worksheet_write_number(worksheet, i, i, i + 1, NULL);
_worksheet_assemble_xml_file(worksheet);