From bbbbb675a624addf96a7405333f4ad4261c6a666 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 13 Apr 2015 16:45:56 +1000 Subject: [PATCH] test: move tests to TAP output --- Makefile.am | 6 +- configure.ac | 5 +- test/aabb.cpp | 22 ++- test/backtrace.cpp | 11 +- test/bezier.cpp | 138 +++++++++++-------- test/bitwise.cpp | 72 ++++++---- test/checksum.cpp | 7 +- test/colour.cpp | 36 +++-- test/extent.cpp | 5 +- test/fixed.cpp | 41 +++--- test/float.cpp | 10 +- test/hmac.cpp | 4 + test/hotp.cpp | 6 +- test/hton.cpp | 12 +- test/ip.cpp | 12 +- test/{json.test.in => json-parse.in} | 0 test/{json-schema.test.in => json-schema.in} | 0 test/json_types.cpp | 12 +- test/maths.cpp | 9 +- test/maths_matrix.cpp | 13 +- test/matrix.cpp | 9 +- test/md2.cpp | 8 +- test/md4.cpp | 8 +- test/md5.cpp | 8 +- test/options.cpp | 4 + test/point.cpp | 4 + test/pool.cpp | 4 + test/rand.cpp | 8 +- test/range.cpp | 10 +- test/ray.cpp | 17 ++- test/region.cpp | 11 +- test/ripemd.cpp | 11 +- test/sha1.cpp | 12 +- test/sha2.cpp | 8 +- test/signal.cpp | 7 +- test/static.test.in | 14 -- test/stringid.cpp | 26 +--- test/uri.cpp | 4 + test/vector.cpp | 4 + test/version.cpp | 10 +- 40 files changed, 353 insertions(+), 255 deletions(-) rename test/{json.test.in => json-parse.in} (100%) rename test/{json-schema.test.in => json-schema.in} (100%) delete mode 100755 test/static.test.in diff --git a/Makefile.am b/Makefile.am index e46671a1..366c6582 100644 --- a/Makefile.am +++ b/Makefile.am @@ -288,7 +288,7 @@ if PLATFORM_WIN32 test_hton_LDFLAGS = -lws2_32 endif -TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh -TESTS = $(top_builddir)/test/static.test $(top_builddir)/test/json.test $(top_builddir)/test/json-schema.test +LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh +TESTS = $(top_builddir)/test/json-parse $(top_builddir)/test/json-schema $(TEST_BIN) check_PROGRAMS = $(TEST_BIN) -EXTRA_DIST += test/static.test test/json.test test/json test/json-schema +EXTRA_DIST += test/json test/json-parse test/json-schema diff --git a/configure.ac b/configure.ac index ffd78556..ea4c268e 100644 --- a/configure.ac +++ b/configure.ac @@ -110,7 +110,6 @@ AC_CONFIG_FILES([ Makefile test/Makefile ]) -AC_CONFIG_FILES([test/json.test], [chmod a+x test/json.test]) -AC_CONFIG_FILES([test/json-schema.test], [chmod a+x test/json-schema.test]) -AC_CONFIG_FILES([test/static.test], [chmod a+x test/static.test]) +AC_CONFIG_FILES([test/json-parse], [chmod a+x test/json-parse]) +AC_CONFIG_FILES([test/json-schema], [chmod a+x test/json-schema]) AC_OUTPUT diff --git a/test/aabb.cpp b/test/aabb.cpp index e8daff86..f35e9cb8 100644 --- a/test/aabb.cpp +++ b/test/aabb.cpp @@ -1,8 +1,15 @@ #include "aabb.hpp" +#include "tap.hpp" + +#include + + int main (int, char**) { + util::TAP::logger tap; + { // Test contraction util::AABB2f box { @@ -12,10 +19,7 @@ main (int, char**) box.contract (2.f); - CHECK_EQ (box.p0.x, 3); - CHECK_EQ (box.p0.y, 3); - CHECK_EQ (box.p1.x, 7); - CHECK_EQ (box.p1.y, 7); + tap.expect_eq (box, { { 3, 3 }, { 7, 7 }}, "over contraction"); } { @@ -27,10 +31,7 @@ main (int, char**) box.expand (2.f); - CHECK_EQ (box.p0.x, 1); - CHECK_EQ (box.p0.y, 1); - CHECK_EQ (box.p1.x, 9); - CHECK_EQ (box.p1.y, 9); + tap.expect_eq (box, { { 1, 1 }, { 9, 9 }}, "expansion"); } @@ -43,9 +44,6 @@ main (int, char**) small.contract (10); - CHECK_EQ (small.p0.x, 0.5f); - CHECK_EQ (small.p0.y, 0.5f); - CHECK_EQ (small.p1.x, 0.5f); - CHECK_EQ (small.p1.y, 0.5f); + tap.expect_eq (small, { { 0.5f, 0.5f }, { 0.5f, 0.5f }}, "unsigned over-contract"); } } diff --git a/test/backtrace.cpp b/test/backtrace.cpp index c8b311ff..cdd54be1 100644 --- a/test/backtrace.cpp +++ b/test/backtrace.cpp @@ -1,4 +1,7 @@ -#include "../backtrace.hpp" +#include "backtrace.hpp" +#include "tap.hpp" +#include "stream.hpp" + #include #include @@ -7,7 +10,11 @@ using namespace std; int main (int, char **) { - cout << debug::backtrace() << endl; + util::TAP::logger tap; + + util::stream::null out; + out << debug::backtrace() << endl; + tap.noop (); return EXIT_SUCCESS; } diff --git a/test/bezier.cpp b/test/bezier.cpp index 51aff935..b604f1fb 100644 --- a/test/bezier.cpp +++ b/test/bezier.cpp @@ -1,20 +1,20 @@ #include "bezier.hpp" -#include "debug.hpp" +#include "tap.hpp" #include //----------------------------------------------------------------------------- -template void test_eval (void); -template void test_intersect (void); -template void test_region (void); +template void test_eval (util::TAP::logger&); +template void test_intersect (util::TAP::logger&); +template void test_region (util::TAP::logger&); //----------------------------------------------------------------------------- template <> void -test_eval<1> (void) +test_eval<1> (util::TAP::logger &tap) { static const util::bezier<1> b1 ({{ 0.f, 0.f}, {100.f, 100.f}}); @@ -22,19 +22,20 @@ test_eval<1> (void) auto p0 = b1.eval(0.f); auto p1 = b1.eval(1.f); - CHECK_EQ (p0, b1[0]); - CHECK_EQ (p1, b1[1]); + tap.expect_eq (p0, b1[0], "eval bezier-1 extrema"); + tap.expect_eq (p1, b1[1], "eval bezier-1 extrema"); auto px = b1.eval(0.5f); auto rx = b1[0] + 0.5f * (b1[1]-b1[0]); - CHECK_EQ (px, rx); + + tap.expect_eq (px, rx, "eval bezier-1 midpoint"); } //----------------------------------------------------------------------------- template <> void -test_eval<2> (void) +test_eval<2> (util::TAP::logger &tap) { static const util::bezier<2> b2 ({{ 0.f, 0.f}, { 50.f, 50.f}, @@ -43,19 +44,20 @@ test_eval<2> (void) auto p0 = b2.eval(0.f); auto p2 = b2.eval(1.f); - CHECK_EQ (p0, b2[0]); - CHECK_EQ (p2, b2[2]); + tap.expect_eq (p0, b2[0], "eval bezier-2 extrema"); + tap.expect_eq (p2, b2[2], "eval bezier-2 extrema"); auto px = b2.eval(0.5f); auto rx = b2[0] + 0.5f * (b2[2]-b2[0]); - CHECK_EQ (px, rx); + + tap.expect_eq (px, rx, "eval bezier-2 midpoint"); } //----------------------------------------------------------------------------- template <> void -test_eval<3> (void) +test_eval<3> (util::TAP::logger &tap) { static const util::bezier<3> b3 ({{ 0.f, 0.f }, { 33.f, 33.f }, @@ -65,46 +67,61 @@ test_eval<3> (void) auto p0 = b3.eval (0.f); auto p3 = b3.eval (1.f); - CHECK_EQ (p0, b3[0]); - CHECK_EQ (p3, b3[3]); + tap.expect_eq (p0, b3[0], "eval bezier-3 extrema"); + tap.expect_eq (p3, b3[3], "eval bezier-3 extrema"); auto px = b3.eval (0.5f); auto rx = b3[0] + 0.5f * (b3[3] - b3[0]); - CHECK_EQ (px, rx); + + tap.expect_eq (px, rx, "eval bezier-3 midpoint"); } //----------------------------------------------------------------------------- template <> void -test_intersect<1> (void) +test_intersect<1> (util::TAP::logger &tap) { // A line from (0,0) to (100,100) static const util::bezier<1> b1 ({{0.f, 0.f}, {100.f, 100.f}}); // Through the centre - CHECK_EQ (b1.intersections ({0.f, 100.f}, {100.f, 0.f}), 1); - CHECK_EQ (b1.intersections ({100.f, 0.f}, {0.f, 100.f}), 1); + tap.expect_eq (b1.intersections ({0.f, 100.f}, {100.f, 0.f}), + 1u, + "intersect bezier-1 centre"); + tap.expect_eq (b1.intersections ({100.f, 0.f}, {0.f, 100.f}), + 1u, + "intersect bezier-1 centre"); // Coincident with endpoints - CHECK_EQ (b1.intersections ({0.f, 0.f}, {1.f,0.f}), 1); - CHECK_EQ (b1.intersections ({100.f, 100.f}, {100.f,0.f}), 1); + tap.expect_eq (b1.intersections ({0.f, 0.f}, {1.f,0.f}), + 1u, + "intersect bezier-1 endpoints"); + tap.expect_eq (b1.intersections ({100.f, 100.f}, {100.f,0.f}), + 1u, + "intersect bezier-1 endpoints"); // Co-planar - CHECK_EQ (b1.intersections ({0.f, 0.f}, {1.f, 1.f}), 1); + tap.expect_eq (b1.intersections ({0.f, 0.f}, {1.f, 1.f}), + 1u, + "intersect bezier-1 co-planar"); // Underneath - CHECK_EQ (b1.intersections ({1000.f, -10.f}, {-1000.f, -10.f}), 0); + tap.expect_eq (b1.intersections ({1000.f, -10.f}, {-1000.f, -10.f}), + 0u, + "intersect bezier-1 under"); // Above - CHECK_EQ (b1.intersections ({1000.f, 110.f}, {-1000.f, 110.f}), 0); + tap.expect_eq (b1.intersections ({1000.f, 110.f}, {-1000.f, 110.f}), + 0u, + "intersect bezier-1 above"); } //----------------------------------------------------------------------------- template <> void -test_intersect<2> (void) +test_intersect<2> (util::TAP::logger &tap) { // A linear curve from (0,0) to (100,100) static const util::bezier<2> b2 ({{ 0.0f, 0.0f}, @@ -112,29 +129,29 @@ test_intersect<2> (void) {100.f, 100.f}}); // Through the centre - CHECK_EQ (b2.intersections ({100.f, 0.f}, {0.f, 100.f}), 1); - CHECK_EQ (b2.intersections ({0.f, 100.f}, {100.f, 0.f}), 1); + tap.expect_eq (b2.intersections ({100.f, 0.f}, {0.f, 100.f}), 1, "intersect bezier-2 centre"); + tap.expect_eq (b2.intersections ({0.f, 100.f}, {100.f, 0.f}), 1, "intersect bezier-2 centre"); // Coincident with endpoints - CHECK_EQ (b2.intersections ({0.f, 0.f}, {0.f,100.f}), 1); - CHECK_EQ (b2.intersections ({0.f, 0.f}, {100.f,0.f}), 1); - CHECK_EQ (b2.intersections ({100.f, 100.f}, {100.f,0.f}), 1); + tap.expect_eq (b2.intersections ({0.f, 0.f}, {0.f,100.f}), 1, "intersect bezier-2 endpoint"); + tap.expect_eq (b2.intersections ({0.f, 0.f}, {100.f,0.f}), 1, "intersect bezier-2 endpoint"); + tap.expect_eq (b2.intersections ({100.f, 100.f}, {100.f,0.f}), 1, "intersect bezier-2 endpoint"); // Co-planar - CHECK_EQ (b2.intersections ({0.f, 0.f}, {1.f, 1.f}), 1); + tap.expect_eq (b2.intersections ({0.f, 0.f}, {1.f, 1.f}), 1, "intersect bezier-2 co-planar"); // Underneath - CHECK_EQ (b2.intersections ({1000.f, -10.f}, {-1000.f, -10.f}), 0); + tap.expect_eq (b2.intersections ({1000.f, -10.f}, {-1000.f, -10.f}), 0, "intersect bezier-2 under"); // Above - CHECK_EQ (b2.intersections ({1000.f, 110.f}, {-1000.f, 110.f}), 0); + tap.expect_eq (b2.intersections ({1000.f, 110.f}, {-1000.f, 110.f}), 0, "intersect bezier-2 above"); } //----------------------------------------------------------------------------- template <> void -test_intersect<3> (void) +test_intersect<3> (util::TAP::logger &tap) { // A linear curve from (0,0) to (100,100) static const util::bezier<3> b3 ({{ 0.f, 0.f }, @@ -143,29 +160,28 @@ test_intersect<3> (void) { 100.f, 100.f }}); // Through the centre - CHECK_EQ (b3.intersections ({100.f, 0.f}, {0.f, 100.f}), 1); - CHECK_EQ (b3.intersections ({0.f, 100.f}, {100.f, 0.f}), 1); + tap.expect_eq (b3.intersections ({100.f, 0.f}, {0.f, 100.f}), 1, "intersect bezier-3 centre"); // Coincident with endpoints - CHECK_EQ (b3.intersections ({0.f, 0.f}, {0.f,100.f}), 1); - CHECK_EQ (b3.intersections ({0.f, 0.f}, {100.f,0.f}), 1); - CHECK_EQ (b3.intersections ({100.f, 100.f}, {100.f,0.f}), 1); + tap.expect_eq (b3.intersections ({0.f, 0.f}, {0.f,100.f}), 1, "intersect bezier-3 endpoint"); + tap.expect_eq (b3.intersections ({0.f, 0.f}, {100.f,0.f}), 1, "intersect bezier-3 endpoint"); + tap.expect_eq (b3.intersections ({100.f, 100.f}, {100.f,0.f}), 1, "intersect bezier-3 endpoint"); // Co-planar - CHECK_EQ (b3.intersections ({0.f, 0.f}, {1.f, 1.f}), 1); + tap.expect_eq (b3.intersections ({0.f, 0.f}, {1.f, 1.f}), 1, "intersect bezier-3 co-planar"); // Underneath - CHECK_EQ (b3.intersections ({1000.f, -10.f}, {-1000.f, -10.f}), 0); + tap.expect_eq (b3.intersections ({1000.f, -10.f}, {-1000.f, -10.f}), 0, "intersect bezier-3 under"); // Above - CHECK_EQ (b3.intersections ({1000.f, 110.f}, {-1000.f, 110.f}), 0); + tap.expect_eq (b3.intersections ({1000.f, 110.f}, {-1000.f, 110.f}), 0, "intersect bezier-3 above"); } //----------------------------------------------------------------------------- template <> void -test_region<1> (void) +test_region<1> (util::TAP::logger &tap) { util::point2f p0 { 0, 0 }, p1 { 100, 0 }, @@ -177,17 +193,17 @@ test_region<1> (void) static const util::bezier<1> vertical ({p0, p3}); static const util::bezier<1> horizontal ({p0, p2}); - CHECK_EQ (upright.region (), util::region2f (p0, p2)); - CHECK_EQ (downleft.region (), util::region2f (p0, p2)); - CHECK_EQ (vertical.region (), util::region2f (p0, p3)); - CHECK_EQ (horizontal.region (), util::region2f (p0, p2)); + tap.expect_eq (upright.region (), util::region2f (p0, p2), "bezier-1 region"); + tap.expect_eq (downleft.region (), util::region2f (p0, p2), "bezier-1 region"); + tap.expect_eq (vertical.region (), util::region2f (p0, p3), "bezier-1 region"); + tap.expect_eq (horizontal.region (), util::region2f (p0, p2), "bezier-1 region"); } //----------------------------------------------------------------------------- template <> void -test_region<2> (void) +test_region<2> (util::TAP::logger &tap) { util::point2f p0 { 0, 0 }, p1 { 50, 50 }, @@ -195,14 +211,14 @@ test_region<2> (void) static const util::bezier<2> upright({p0, p1, p2}); - CHECK_EQ (upright.region (), util::region2f (p0, p2)); + tap.expect_eq (upright.region (), util::region2f (p0, p2), "bezier-2 region"); } //----------------------------------------------------------------------------- template <> void -test_region<3> (void) +test_region<3> (util::TAP::logger &tap) { util::point2f p0 { 0, 0 }, p1 { 33, 33 }, @@ -211,7 +227,7 @@ test_region<3> (void) static const util::bezier<3> upright({p0, p1, p2, p3}); - CHECK_EQ (upright.region (), util::region2f (p0, p3)); + tap.expect_eq (upright.region (), util::region2f (p0, p3), "bezier-3 region"); } @@ -219,17 +235,19 @@ test_region<3> (void) int main (int, char**) { - test_eval<1> (); - test_eval<2> (); - test_eval<3> (); + util::TAP::logger tap; - test_intersect<1> (); - test_intersect<2> (); - test_intersect<3> (); + test_eval<1> (tap); + test_eval<2> (tap); + test_eval<3> (tap); - test_region<1> (); - test_region<2> (); - test_region<3> (); + test_intersect<1> (tap); + test_intersect<2> (tap); + test_intersect<3> (tap); + + test_region<1> (tap); + test_region<2> (tap); + test_region<3> (tap); return EXIT_SUCCESS; } diff --git a/test/bitwise.cpp b/test/bitwise.cpp index 9478d1c2..db9fa273 100644 --- a/test/bitwise.cpp +++ b/test/bitwise.cpp @@ -1,51 +1,65 @@ -#include "../bitwise.hpp" +#include "bitwise.hpp" +#include "tap.hpp" +//----------------------------------------------------------------------------- static void -test_rotate (void) { - CHECK_EQ (rotatel (uint8_t (0x0F), 0), 0x0F); - CHECK_EQ (rotatel (uint8_t (0x0F), 4), 0xF0); - CHECK_EQ (rotatel (uint8_t (0xF0), 4), 0x0F); - CHECK_EQ (rotatel (uint8_t (0x0F), 8), 0x0F); +test_rotate (util::TAP::logger &tap) +{ + tap.expect_eq (rotatel (uint8_t (0x0F), 0), 0x0F); + tap.expect_eq (rotatel (uint8_t (0x0F), 4), 0xF0); + tap.expect_eq (rotatel (uint8_t (0xF0), 4), 0x0F); + tap.expect_eq (rotatel (uint8_t (0x0F), 8), 0x0F); - CHECK_EQ (rotater (uint8_t (0x0F), 0), 0x0F); - CHECK_EQ (rotater (uint8_t (0x0F), 4), 0xF0); - CHECK_EQ (rotater (uint8_t (0xF0), 4), 0x0F); - CHECK_EQ (rotater (uint8_t (0x0F), 8), 0x0F); + tap.expect_eq (rotater (uint8_t (0x0F), 0), 0x0F); + tap.expect_eq (rotater (uint8_t (0x0F), 4), 0xF0); + tap.expect_eq (rotater (uint8_t (0xF0), 4), 0x0F); + tap.expect_eq (rotater (uint8_t (0x0F), 8), 0x0F); - CHECK_EQ (rotatel (uint16_t (0xABCD), 0), 0xABCD); - CHECK_EQ (rotatel (uint16_t (0xABCD), 4), 0xBCDA); - CHECK_EQ (rotatel (uint16_t (0xABCD), 8), 0xCDAB); - CHECK_EQ (rotatel (uint16_t (0xABCD), 12), 0xDABC); - CHECK_EQ (rotatel (uint16_t (0xABCD), 16), 0xABCD); + tap.expect_eq (rotatel (uint16_t (0xABCD), 0), 0xABCD); + tap.expect_eq (rotatel (uint16_t (0xABCD), 4), 0xBCDA); + tap.expect_eq (rotatel (uint16_t (0xABCD), 8), 0xCDAB); + tap.expect_eq (rotatel (uint16_t (0xABCD), 12), 0xDABC); + tap.expect_eq (rotatel (uint16_t (0xABCD), 16), 0xABCD); - CHECK_EQ (rotater (uint16_t (0xABCD), 0), 0xABCD); - CHECK_EQ (rotater (uint16_t (0xABCD), 4), 0xDABC); - CHECK_EQ (rotater (uint16_t (0xABCD), 8), 0xCDAB); - CHECK_EQ (rotater (uint16_t (0xABCD), 12), 0xBCDA); - CHECK_EQ (rotater (uint16_t (0xABCD), 16), 0xABCD); + tap.expect_eq (rotater (uint16_t (0xABCD), 0), 0xABCD); + tap.expect_eq (rotater (uint16_t (0xABCD), 4), 0xDABC); + tap.expect_eq (rotater (uint16_t (0xABCD), 8), 0xCDAB); + tap.expect_eq (rotater (uint16_t (0xABCD), 12), 0xBCDA); + tap.expect_eq (rotater (uint16_t (0xABCD), 16), 0xABCD); - CHECK_EQ (rotatel (uint32_t (0x12345670), 12), 0x45670123); - CHECK_EQ (rotater (uint32_t (0x12345670), 12), 0x67012345); + tap.expect_eq (rotatel (uint32_t (0x12345670), 12), 0x45670123); + tap.expect_eq (rotater (uint32_t (0x12345670), 12), 0x67012345); - CHECK_EQ (rotatel (uint64_t (0x1234567890ABCDEF), 12), 0x4567890ABCDEF123); - CHECK_EQ (rotater (uint64_t (0x1234567890ABCDEF), 12), 0xDEF1234567890ABC); + tap.expect_eq (rotatel (uint64_t (0x1234567890ABCDEF), 12), 0x4567890ABCDEF123); + tap.expect_eq (rotater (uint64_t (0x1234567890ABCDEF), 12), 0xDEF1234567890ABC); } +//----------------------------------------------------------------------------- void -test_reverse (void) { +test_reverse (util::TAP::logger &tap) +{ + size_t matches = 0; for (unsigned i = 0; i < 256; ++i) { auto first = reverse (i); auto last = reverse (first); - CHECK_EQ (last, i); + if (last == i) + matches++; } + + tap.expect_eq (matches, 256, "exhaustive 8 bit reverse"); } + +//----------------------------------------------------------------------------- int -main (int, char**) { - test_rotate (); - test_reverse (); +main (int, char**) +{ + util::TAP::logger tap; + + test_rotate (tap); + test_reverse (tap); return 0; } diff --git a/test/checksum.cpp b/test/checksum.cpp index 386b2bf2..d929c05d 100644 --- a/test/checksum.cpp +++ b/test/checksum.cpp @@ -2,6 +2,7 @@ #include "hash/adler.hpp" #include "hash/bsdsum.hpp" #include "types.hpp" +#include "tap.hpp" #include "debug.hpp" #include @@ -25,9 +26,11 @@ static const struct { int main (int, char**) { + util::TAP::logger tap; + for (unsigned i = 0; i < elems (TESTS); ++i) { - CHECK_EQ (TESTS[i].adler, adler32 (TESTS[i].data, TESTS[i].size)); - CHECK_EQ (TESTS[i].bsd, bsdsum (TESTS[i].data, TESTS[i].size)); + tap.expect_eq (TESTS[i].adler, adler32 (TESTS[i].data, TESTS[i].size), "adler checksum"); + tap.expect_eq (TESTS[i].bsd, bsdsum (TESTS[i].data, TESTS[i].size), "bsdsum checksum"); } return EXIT_SUCCESS; diff --git a/test/colour.cpp b/test/colour.cpp index 023d08d6..b9345ae9 100644 --- a/test/colour.cpp +++ b/test/colour.cpp @@ -1,53 +1,51 @@ #include "colour.hpp" -#include "debug.hpp" +#include "tap.hpp" int main (int, char**) { + util::TAP::logger tap; + // Simple check for symbol visibility - CHECK_EQ (util::colour4f::WHITE.r, 1.f); - CHECK_EQ (util::colour4f::WHITE.g, 1.f); - CHECK_EQ (util::colour4f::WHITE.b, 1.f); - CHECK_EQ (util::colour4f::WHITE.a, 1.f); + tap.expect_eq (util::colour4f::WHITE, util::colour4f (1), "WHITE available"); // Check casting works between intergral and floating formats { util::colour4f f (1); util::colour<4,uint8_t> u (255); - CHECK_EQ (f.cast (), u); - CHECK_EQ (u.cast (), f); + tap.expect_eq (f.cast (), u, "cast float to u8"); + tap.expect_eq (u.cast (), f, "cast u8 to float"); } // Check lookups are working - CHECK_EQ (util::colour4f::from_html ("white"), util::colour4f::WHITE); - CHECK_EQ (util::colour4f::from_x11 ("white"), util::colour4f::WHITE); + tap.expect_eq (util::colour4f::from_html ("white"), util::colour4f::WHITE, "HTML lookup"); + tap.expect_eq ( util::colour4f::from_x11 ("white"), util::colour4f::WHITE, "X11 lookup"); // Check HSV conversions { // white: hue is undefined auto white = util::rgb_to_hsv ({1,1,1}); - CHECK_EQ (white.s, 0); - CHECK_EQ (white.v, 1); + tap.expect (exactly_equal (white.s, 0) && exactly_equal (white.v, 1), "white hsv"); // black: hue is undefined auto black = util::rgb_to_hsv ({0,0,0}); - CHECK_EQ (black.s, 0); - CHECK_EQ (black.v, 0); + tap.expect (exactly_equal (black.s, 0) && exactly_equal (black.v, 0), "black hsv"); struct { + const char *name; util::colour3f rgb; util::colour3f hsv; } TESTS[] = { - { { 1, 0, 0, }, { 0, 1, 1, } }, // red - { { 0, 1, 0, }, { 120, 1, 1, } }, // green - { { 0, 0, 1, }, { 240, 1, 1, } }, // blue - { { 0.75f, 0.25f, 0.75f }, { 300, 2/3.f, 0.75f } }, + { "red", { 1, 0, 0, }, { 0, 1, 1, } }, // red + { "green", { 0, 1, 0, }, { 120, 1, 1, } }, // green + { "blue", { 0, 0, 1, }, { 240, 1, 1, } }, // blue + { "misc", { 0.75f, 0.25f, 0.75f }, { 300, 2/3.f, 0.75f } }, }; for (auto i: TESTS) { - CHECK_EQ (util::rgb_to_hsv (i.rgb), i.hsv); - CHECK_EQ (util::hsv_to_rgb (i.hsv), i.rgb); + tap.expect_eq (util::rgb_to_hsv (i.rgb), i.hsv, i.name); + tap.expect_eq (util::hsv_to_rgb (i.hsv), i.rgb, i.name); } } } diff --git a/test/extent.cpp b/test/extent.cpp index def7f591..ce1b68cb 100644 --- a/test/extent.cpp +++ b/test/extent.cpp @@ -1,9 +1,10 @@ #include "extent.hpp" -#include "debug.hpp" +#include "tap.hpp" int main (void) { - // Simple symbol visibility check + util::TAP::logger tap; util::extent2f instance; + tap.todo ("instancing test"); } diff --git a/test/fixed.cpp b/test/fixed.cpp index 146a16c5..fdde6972 100644 --- a/test/fixed.cpp +++ b/test/fixed.cpp @@ -1,10 +1,10 @@ #include "fixed.hpp" -#include "debug.hpp" +#include "tap.hpp" template void -test_simple (void) +test_simple (util::TAP::logger &tap) { using fixed_t = util::fixed; using integer_t = typename fixed_t::integer_t; @@ -12,30 +12,35 @@ test_simple (void) const fixed_t lo = integer_t{0}; const fixed_t hi = integer_t{1}; - CHECK_EQ (lo, lo); - CHECK_EQ (hi, hi); + std::ostringstream os; + os << "fixed<" << type_to_string () << ',' << I << ',' << E << '>'; - CHECK_NEQ (hi, lo); - CHECK_NEQ (lo, hi); + tap.expect_eq (lo, lo, os.str () + " self equality"); + tap.expect_eq (hi, hi, os.str () + " self equality"); - CHECK_LT (lo, hi); - CHECK_LE (lo, hi); - CHECK_LE (lo, lo); + tap.expect_neq (hi, lo, os.str () + " inequality"); + tap.expect_neq (lo, hi, os.str () + " inequality"); - CHECK_GT (hi, lo); - CHECK_GE (lo, lo); - CHECK_GE (hi, lo); + tap.expect_lt (lo, hi, os.str () + " less than"); + tap.expect_le (lo, hi, os.str () + " less than equal"); + tap.expect_le (lo, lo, os.str () + " less than equal"); + + tap.expect_gt (hi, lo, os.str () + " greater than"); + tap.expect_ge (lo, lo, os.str () + " greater than equal"); + tap.expect_ge (hi, lo, os.str () + " greater than equal"); } int main (void) { - test_simple (); - test_simple (); - test_simple (); + util::TAP::logger tap; - test_simple (); - test_simple (); - test_simple (); + test_simple (tap); + test_simple (tap); + test_simple (tap); + + test_simple (tap); + test_simple (tap); + test_simple (tap); } diff --git a/test/float.cpp b/test/float.cpp index f3d0c9aa..d729197e 100644 --- a/test/float.cpp +++ b/test/float.cpp @@ -1,7 +1,8 @@ -#include "../float.hpp" +#include "float.hpp" -#include "../debug.hpp" -#include "../types.hpp" +#include "debug.hpp" +#include "tap.hpp" +#include "types.hpp" #include @@ -72,4 +73,7 @@ int main (int, char **) { test_single (); test_double (); + + util::TAP::logger tap; + tap.todo ("convert to TAP"); } diff --git a/test/hmac.cpp b/test/hmac.cpp index 1468e12e..9c2ee73e 100644 --- a/test/hmac.cpp +++ b/test/hmac.cpp @@ -3,6 +3,7 @@ #include "debug.hpp" #include "hash/md5.hpp" #include "hash/sha1.hpp" +#include "tap.hpp" #include "types.hpp" #include @@ -279,5 +280,8 @@ main (int, char**) return EXIT_FAILURE; } + util::TAP::logger tap; + tap.todo ("convert to TAP"); + return EXIT_SUCCESS; } diff --git a/test/hotp.cpp b/test/hotp.cpp index fc52c438..ecd2eb2d 100644 --- a/test/hotp.cpp +++ b/test/hotp.cpp @@ -1,7 +1,8 @@ #include "hash/hotp.hpp" -#include "types.hpp" #include "debug.hpp" +#include "tap.hpp" +#include "types.hpp" using util::hash::HOTP; @@ -25,4 +26,7 @@ main (int, char**) for (size_t i = 0; i < elems (EXPECTED); ++i) CHECK_EQ (EXPECTED[i], h.value ()); + + util::TAP::logger tap; + tap.todo ("convert to TAP"); } diff --git a/test/hton.cpp b/test/hton.cpp index aeed4113..3f8dd91e 100644 --- a/test/hton.cpp +++ b/test/hton.cpp @@ -1,8 +1,9 @@ -#include "../endian.hpp" +#include "endian.hpp" -#include "../debug.hpp" -#include "../platform.hpp" +#include "debug.hpp" +#include "tap.hpp" +#include "platform.hpp" #include #if defined(PLATFORM_WIN32) @@ -12,8 +13,6 @@ #include #endif -using namespace std; - int main (int, char **) { @@ -27,5 +26,6 @@ main (int, char **) { CHECK_EQ (ntohs (u16), hton (u16)); CHECK_EQ (ntohl (u32), hton (u32)); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.todo ("convert to TAP"); } diff --git a/test/ip.cpp b/test/ip.cpp index a85786cb..5279a069 100644 --- a/test/ip.cpp +++ b/test/ip.cpp @@ -1,9 +1,10 @@ -#include "../ip.hpp" +#include "ip.hpp" -#include "../debug.hpp" -#include "../platform.hpp" -#include "../types.hpp" +#include "debug.hpp" +#include "platform.hpp" +#include "tap.hpp" +#include "types.hpp" #include @@ -26,5 +27,6 @@ main (int, char **) { CHECK (parsed == data[i].ip); } - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.todo ("convert to TAP"); } diff --git a/test/json.test.in b/test/json-parse.in similarity index 100% rename from test/json.test.in rename to test/json-parse.in diff --git a/test/json-schema.test.in b/test/json-schema.in similarity index 100% rename from test/json-schema.test.in rename to test/json-schema.in diff --git a/test/json_types.cpp b/test/json_types.cpp index d32100cf..42b0cd2d 100644 --- a/test/json_types.cpp +++ b/test/json_types.cpp @@ -1,13 +1,14 @@ +#include "json/tree.hpp" -#include "../debug.hpp" -#include "../json/tree.hpp" -#include "../maths.hpp" +#include "debug.hpp" +#include "maths.hpp" +#include "tap.hpp" #include #include int -main (int, char**) { +main (void) { static const char TEST_STRING[] = R"_( { "string":"brad", @@ -100,5 +101,6 @@ main (int, char**) { CHECK (!ref["array"].is_object ()); CHECK (!ref["array"].is_string ()); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/maths.cpp b/test/maths.cpp index 50258ed1..8f44990f 100644 --- a/test/maths.cpp +++ b/test/maths.cpp @@ -1,5 +1,7 @@ -#include "../debug.hpp" -#include "../maths.hpp" +#include "maths.hpp" + +#include "debug.hpp" +#include "tap.hpp" #include #include @@ -125,5 +127,6 @@ main (int, char **) { CHECK_EQ (log2up (8u), 3); CHECK_EQ (log2up (1u), 0); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.todo ("conver to TAP"); } diff --git a/test/maths_matrix.cpp b/test/maths_matrix.cpp index 2c684bc4..ce5afa7c 100644 --- a/test/maths_matrix.cpp +++ b/test/maths_matrix.cpp @@ -1,6 +1,8 @@ -#include "../debug.hpp" -#include "../maths/matrix.hpp" -#include "../maths.hpp" +#include "maths/matrix.hpp" + +#include "debug.hpp" +#include "maths.hpp" +#include "tap.hpp" #include #include @@ -52,7 +54,7 @@ test_identity (const matrix &m) { int -main (int, char **) { +main (void) { for (unsigned int i = 1; i < 10; ++i) { test_zeroes (matrix::zeroes (i)); test_identity (matrix::identity (i)); @@ -129,5 +131,6 @@ main (int, char **) { CHECK ( matrix::identity (3).is_homogeneous ()); CHECK (invertible4.is_homogeneous ()); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/matrix.cpp b/test/matrix.cpp index 7bf07931..344ff296 100644 --- a/test/matrix.cpp +++ b/test/matrix.cpp @@ -1,11 +1,13 @@ #include "matrix.hpp" -#include "vector.hpp" + #include "debug.hpp" +#include "tap.hpp" +#include "vector.hpp" #include int -main (int, char **) { +main (void) { { // Identity matrix-vector multiplication auto v = util::vector<4,float> { 1.f, 2.f, 3.f, 4.f }; @@ -93,5 +95,6 @@ main (int, char **) { CHECK_EQ (m.inverse (), r / 40.f); } - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/md2.cpp b/test/md2.cpp index 0583ca60..2a4dbed3 100644 --- a/test/md2.cpp +++ b/test/md2.cpp @@ -1,4 +1,6 @@ -#include "../hash/md2.hpp" +#include "hash/md2.hpp" + +#include "tap.hpp" using util::hash::MD2; @@ -56,5 +58,7 @@ main (int, char **) { } } - return success ? 0 : 1; + util::TAP::logger tap; + tap.expect (success, "test vectors"); + return tap.status (); } diff --git a/test/md4.cpp b/test/md4.cpp index c1d7509d..a0cdd607 100644 --- a/test/md4.cpp +++ b/test/md4.cpp @@ -1,4 +1,6 @@ -#include "../hash/md4.hpp" +#include "hash/md4.hpp" + +#include "tap.hpp" #include #include @@ -64,5 +66,7 @@ main (int, char**) { } } - return success ? 0 : 1; + util::TAP::logger tap; + tap.expect (success, "test vectors"); + return tap.status (); } diff --git a/test/md5.cpp b/test/md5.cpp index 3d4c016d..641dcd98 100644 --- a/test/md5.cpp +++ b/test/md5.cpp @@ -1,4 +1,6 @@ -#include "../hash/md5.hpp" +#include "hash/md5.hpp" + +#include "tap.hpp" #include #include @@ -55,5 +57,7 @@ main (int, char**) { } } - return success ? 0 : 1; + util::TAP::logger tap; + tap.expect (success, "test vectors"); + return tap.status (); } diff --git a/test/options.cpp b/test/options.cpp index 50f59c2e..69dd5791 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -1,6 +1,7 @@ #include "options.hpp" #include "debug.hpp" +#include "tap.hpp" #include "types.hpp" #include @@ -271,4 +272,7 @@ main (int, char **) { test_bytes_opt (); test_insert_remove_opt (); test_required (); + + util::TAP::logger tap; + tap.todo ("convert to TAP"); } diff --git a/test/point.cpp b/test/point.cpp index 128e3ba8..4faa972a 100644 --- a/test/point.cpp +++ b/test/point.cpp @@ -2,6 +2,7 @@ #include "point.hpp" #include "debug.hpp" +#include "tap.hpp" #include "types.hpp" using namespace util; @@ -55,4 +56,7 @@ main (int, char**) { CHECK_EQ (q.z, 0); CHECK_EQ (q.w, 1); } + + util::TAP::logger tap; + tap.todo ("convert to TAP"); } diff --git a/test/pool.cpp b/test/pool.cpp index f9628536..0a1a954e 100644 --- a/test/pool.cpp +++ b/test/pool.cpp @@ -1,6 +1,7 @@ #include "debug.hpp" #include "pool.hpp" +#include "tap.hpp" #include #include @@ -83,4 +84,7 @@ main (int, char **) { check_single (); check_unique_ptr (); check_keep_value (); + + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/rand.cpp b/test/rand.cpp index e69e72c1..5e63fb90 100644 --- a/test/rand.cpp +++ b/test/rand.cpp @@ -1,5 +1,6 @@ -#include "../random.hpp" -#include "../debug.hpp" +#include "random.hpp" +#include "debug.hpp" +#include "tap.hpp" #include #include @@ -55,5 +56,6 @@ main (int, char **) { test_bool (); test_float (); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/range.cpp b/test/range.cpp index 643747e7..747a4741 100644 --- a/test/range.cpp +++ b/test/range.cpp @@ -1,9 +1,10 @@ +#include "debug.hpp" +#include "range.hpp" +#include "tap.hpp" + #include #include -#include "../debug.hpp" -#include "../range.hpp" - using namespace std; using namespace util; @@ -49,6 +50,7 @@ main (int, char **) { CHECK_EQ (initial_nan.max, 1.0); } - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/ray.cpp b/test/ray.cpp index f17e8516..b0d695d1 100644 --- a/test/ray.cpp +++ b/test/ray.cpp @@ -1,7 +1,8 @@ -#include "ray.hpp" -#include "plane.hpp" -#include "debug.hpp" #include "aabb.hpp" +#include "debug.hpp" +#include "plane.hpp" +#include "ray.hpp" +#include "tap.hpp" void @@ -33,9 +34,19 @@ test_intersect_aabb (void) } +void +test_intersect_sphere (void) +{ + +} + + int main (void) { test_intersect_plane (); test_intersect_aabb (); + + util::TAP::logger tap; + tap.todo ("convert to TAP"); } diff --git a/test/region.cpp b/test/region.cpp index 4a7578c4..e0e3a1eb 100644 --- a/test/region.cpp +++ b/test/region.cpp @@ -1,6 +1,8 @@ -#include "../region.hpp" -#include "../point.hpp" -#include "../debug.hpp" +#include "region.hpp" + +#include "debug.hpp" +#include "point.hpp" +#include "tap.hpp" using namespace util; @@ -39,5 +41,6 @@ main (int, char **) { //CHECK (region<2,intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01))); //CHECK (region<2,intmax_t> (0, 0, 10, 10).contains (point2d (0.4, 0.01))); - return 0; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/ripemd.cpp b/test/ripemd.cpp index 3fcd03d2..b6c1312d 100644 --- a/test/ripemd.cpp +++ b/test/ripemd.cpp @@ -1,6 +1,8 @@ -#include "../debug.hpp" -#include "../types.hpp" -#include "../hash/ripemd.hpp" +#include "hash/ripemd.hpp" + +#include "debug.hpp" +#include "tap.hpp" +#include "types.hpp" #include #include @@ -132,5 +134,6 @@ main(int, char**) { }; CHECK (obj.digest () == MILLION); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/sha1.cpp b/test/sha1.cpp index bda841b0..dbcde5f9 100644 --- a/test/sha1.cpp +++ b/test/sha1.cpp @@ -1,7 +1,8 @@ -#include "../hash/sha1.hpp" +#include "hash/sha1.hpp" -#include "../debug.hpp" -#include "../types.hpp" +#include "debug.hpp" +#include "tap.hpp" +#include "types.hpp" #include #include @@ -67,6 +68,7 @@ main (int, char**) { CHECK (obj.digest () == i.output); } - - return 0; + + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/sha2.cpp b/test/sha2.cpp index 8c94f56c..95f09361 100644 --- a/test/sha2.cpp +++ b/test/sha2.cpp @@ -1,6 +1,7 @@ -#include "../hash/sha2.hpp" +#include "hash/sha2.hpp" -#include "../debug.hpp" +#include "debug.hpp" +#include "tap.hpp" #include @@ -56,5 +57,6 @@ main (int, char **) { CHECK (obj.digest () == i.output); } - return 0; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/signal.cpp b/test/signal.cpp index 260af61f..a83eb37b 100644 --- a/test/signal.cpp +++ b/test/signal.cpp @@ -1,8 +1,8 @@ -#include - #include "signal.hpp" + #include "debug.hpp" #include "raii.hpp" +#include "tap.hpp" //----------------------------------------------------------------------------- @@ -129,5 +129,6 @@ main (int, char **) test_combiner (); test_disconnect (); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/static.test.in b/test/static.test.in deleted file mode 100755 index bbed8344..00000000 --- a/test/static.test.in +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -tests=($(find "@abs_top_builddir@/test/" -type f -executable | grep -v ".test$")) - -echo 1..$((${#tests[@]})) - -for i in ${tests[@]}; -do - $i 2>/dev/null 1>&2 - case $? in - 0) echo "ok - $(basename $i)";; - *) echo "not ok - $(basename $i)";; - esac -done diff --git a/test/stringid.cpp b/test/stringid.cpp index 0202e28d..0f67ba59 100644 --- a/test/stringid.cpp +++ b/test/stringid.cpp @@ -1,24 +1,7 @@ -/* - * This file is part of libgim. - * - * libgim is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * libgim 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 General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with libgim. If not, see . - * - * Copyright 2014 Danny Robson - */ +#include "stringid.hpp" -#include "../stringid.hpp" -#include "../debug.hpp" +#include "debug.hpp" +#include "tap.hpp" #include #include @@ -38,5 +21,6 @@ main (int, char**) { CHECK_EQ (id1 + 1, id2); CHECK_EQ (id1, map.find ("first")); - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/uri.cpp b/test/uri.cpp index aee9bca6..fec2ebae 100644 --- a/test/uri.cpp +++ b/test/uri.cpp @@ -1,6 +1,7 @@ #include "uri.hpp" #include "debug.hpp" +#include "tap.hpp" int main (void) @@ -41,4 +42,7 @@ main (void) for (auto i: BAD) CHECK_THROWS (util::uri::parse_error, util::uri foo (i)); + + util::TAP::logger tap; + tap.skip ("convert to TAP"); } diff --git a/test/vector.cpp b/test/vector.cpp index c6ec9c92..6e111eea 100644 --- a/test/vector.cpp +++ b/test/vector.cpp @@ -1,6 +1,7 @@ #include "vector.hpp" #include "maths.hpp" +#include "tap.hpp" using util::vector; using util::vector2f; @@ -64,4 +65,7 @@ int main () { test_polar (); + + util::TAP::logger test; + test.skip ("convert to TAP"); } diff --git a/test/version.cpp b/test/version.cpp index eb2b4b38..22334a57 100644 --- a/test/version.cpp +++ b/test/version.cpp @@ -1,6 +1,7 @@ +#include "version.hpp" -#include "../version.hpp" -#include "../debug.hpp" +#include "debug.hpp" +#include "tap.hpp" #include #include @@ -17,7 +18,7 @@ struct parsed_version { int -main (int, char **) { +main () { vector tests ({ { "1", { 1 } }, @@ -47,5 +48,6 @@ main (int, char **) { CHECK_LE (i->parts.size (), 4); } - return EXIT_SUCCESS; + util::TAP::logger tap; + tap.skip ("convert to TAP"); }