From d46d8385ab68fd8f902016b3e7406290cb46c0db Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Nov 2023 13:12:24 +0000 Subject: Reformat test source --- test/enumDetailsData.h | 3 +++ test/test-assetFactory.cpp | 11 +++++++++++ test/test-collection.cpp | 2 ++ test/test-geo.cpp | 7 +++++++ test/test-glContainer.cpp | 3 +++ test/test-glContextBhvr.cpp | 2 ++ test/test-instancing.cpp | 1 + test/test-lib.cpp | 1 + test/test-maths.cpp | 7 +++++++ test/test-network.cpp | 3 +++ test/test-persistence.cpp | 4 ++++ test/test-render.cpp | 9 +++++++++ test/test-text.cpp | 2 ++ test/testMainWindow.h | 1 + test/testRenderOutput.h | 1 + 15 files changed, 57 insertions(+) diff --git a/test/enumDetailsData.h b/test/enumDetailsData.h index 713d742..b7bd601 100644 --- a/test/enumDetailsData.h +++ b/test/enumDetailsData.h @@ -3,13 +3,16 @@ enum GlobalUnscoped { aa, b, c }; enum class GlobalScoped { aa, b, c }; + namespace ns { enum Unscoped { aa, b, c }; enum class Scoped { aa, b, c }; } + namespace test1 { enum class DefaultDense { a, bee, ci, de }; } + namespace test2 { enum class NumberedSparse { a = 0, bee = 3, ci = -20, de = 100 }; } diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 18dc778..145481e 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -24,44 +24,52 @@ BOOST_GLOBAL_FIXTURE(ApplicationBase); BOOST_GLOBAL_FIXTURE(TestMainWindow); const std::filesystem::path TMP {"/tmp"}; + class FactoryFixture : public TestRenderOutputSize, public SceneProvider { public: FactoryFixture() : sceneRenderer {size, output} { } + ~FactoryFixture() { auto outpath = (TMP / boost::unit_test::framework::current_test_case().full_name()).replace_extension(".tga"); std::filesystem::create_directories(outpath.parent_path()); Texture::save(outImage, outpath.c_str()); } + void content(const SceneShader & shader) const override { shader.basic.use(Location {{0, 0, 0}, {0, 0, 0}}); objects.apply(&Renderable::render, shader); } + void lights(const SceneShader & shader) const override { shader.pointLight.add({-3, 1, 5}, {1, 1, 1}, .1F); } + void environment(const SceneShader &, const SceneRenderer & sceneRenderer) const override { sceneRenderer.setAmbientLight({.4, .4, .4}); sceneRenderer.setDirectionalLight({.6, .6, .6}, east + south + south + down, *this); } + void shadows(const ShadowMapper & mapper) const override { mapper.dynamicPoint.use(Location {{0, 0, 0}, {0, 0, 0}}); objects.apply(&Renderable::shadows, mapper); } + void render(float dist = 10.f) { sceneRenderer.camera.setView({-dist, dist * 1.2f, dist * 1.2f}, south + east + down); sceneRenderer.render(*this); } + Collection objects; private: @@ -69,6 +77,7 @@ private: }; BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture); + BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5)) { auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml"); @@ -115,6 +124,7 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) render(5); } + BOOST_AUTO_TEST_SUITE_END(); BOOST_AUTO_TEST_CASE(loadall) @@ -125,6 +135,7 @@ BOOST_AUTO_TEST_CASE(loadall) } template using InOut = std::tuple; + BOOST_DATA_TEST_CASE(normalizeColourName, boost::unit_test::data::make>({ {"", ""}, diff --git a/test/test-collection.cpp b/test/test-collection.cpp index 16db792..00204fc 100644 --- a/test/test-collection.cpp +++ b/test/test-collection.cpp @@ -13,12 +13,14 @@ public: Base() = default; virtual ~Base() = default; DEFAULT_MOVE_COPY(Base); + virtual bool add() { total += 1; return false; } + unsigned int total {0}; }; diff --git a/test/test-geo.cpp b/test/test-geo.cpp index e672e54..9874fb7 100644 --- a/test/test-geo.cpp +++ b/test/test-geo.cpp @@ -108,6 +108,7 @@ BOOST_AUTO_TEST_CASE(get_height_at) using TestRayTracerData = std::tuple>; BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) + BOOST_DATA_TEST_CASE(raytracer, boost::unit_test::data::make({ {{1, 2}, {4, 5}, 4, @@ -145,6 +146,7 @@ BOOST_DATA_TEST_CASE(raytracer, using TestRayData = std::tuple; BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) + BOOST_DATA_TEST_CASE(intersect_ray, boost::unit_test::data::make({ {{-1, -1, 1.0}, {1, 1, 0}, {0, 0, 1}}, @@ -169,6 +171,7 @@ BOOST_DATA_TEST_CASE(intersect_ray, nodes[at(1, 1)].height = 4; const auto intersect = intersectRay({start, glm::normalize(dir)}); + BOOST_CHECK_IF(has_intersect, intersect) { BOOST_CHECK_CLOSE_VEC(*intersect, pos); } @@ -178,6 +181,7 @@ auto xs = boost::unit_test::data::xrange(-20.F, 0.F, 0.6F), ys = boost::unit_tes auto targetsx = boost::unit_test::data::xrange(0.2F, 4.9F, 1.3F), targetsy = boost::unit_test::data::xrange(0.3F, 4.9F, 1.3F); BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) + BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, targetx, targety) { // at(x,y) is index based @@ -189,8 +193,10 @@ BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, ta const glm::vec3 start {x, y, 10}; const auto target {this->positionAt({targetx, targety})}; const Ray ray {start, glm::normalize(target - start)}; + BOOST_TEST_CONTEXT(ray) { const auto intersect = intersectRay(ray); + BOOST_CHECK_IF(has_intersect, intersect) { BOOST_CHECK_CLOSE_VEC(*intersect, target); } @@ -198,6 +204,7 @@ BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, ta } BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) + BOOST_DATA_TEST_CASE(intersect_ray_miss, boost::unit_test::data::make({ {{3, 3, 5}, {-1, -1, 0}}, diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index 33ec992..cd57a6b 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -281,6 +281,7 @@ struct C { int x; float y; }; + static_assert(std::is_trivially_destructible_v); BOOST_FIXTURE_TEST_SUITE(c, glContainer) @@ -307,9 +308,11 @@ struct CC { { ++x; } + int x; float y; }; + static_assert(!std::is_trivially_destructible_v); BOOST_FIXTURE_TEST_SUITE(cc, glContainer) diff --git a/test/test-glContextBhvr.cpp b/test/test-glContextBhvr.cpp index 1f1215c..2f71aec 100644 --- a/test/test-glContextBhvr.cpp +++ b/test/test-glContextBhvr.cpp @@ -11,12 +11,14 @@ BOOST_GLOBAL_FIXTURE(ApplicationBase); #define TEST_WINDOW_PARAMS __FILE__, 0, 0, 640, 480, static_cast(SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN) + static void CreateProgramTest() { const ProgramRef p; BOOST_REQUIRE(p); } + BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) { BOOST_REQUIRE(!glCreateProgram); // Init not called yet diff --git a/test/test-instancing.cpp b/test/test-instancing.cpp index 7d8ea55..c1860a4 100644 --- a/test/test-instancing.cpp +++ b/test/test-instancing.cpp @@ -163,6 +163,7 @@ BOOST_DATA_TEST_CASE(shuffle_random, boost::unit_test::data::xrange(0, 10), x) iused.emplace(index[i]); } } + BOOST_TEST_CONTEXT(index) { BOOST_REQUIRE_EQUAL(iused.size(), size()); if (!iused.empty()) { diff --git a/test/test-lib.cpp b/test/test-lib.cpp index aaf6292..58b769a 100644 --- a/test/test-lib.cpp +++ b/test/test-lib.cpp @@ -9,6 +9,7 @@ #include std::set active; + void generator(GLsizei n, GLuint * out) { diff --git a/test/test-maths.cpp b/test/test-maths.cpp index a4a881d..2560319 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -36,6 +36,7 @@ static_assert(east.x > 0); static_assert(west == -east); // (-ve, y, z) is "west" static_assert(west.x < 0); + // // Therefore, the geographic world exists west -ve to east +ve and from south -ve to north +ve. Forward shall be // considered +ve motion; the "front" of a vehicle shall have a +ve value in y axis. @@ -110,9 +111,11 @@ const auto rots = boost::unit_test::data::make; + BOOST_DATA_TEST_CASE(test_create_arc, boost::unit_test::data::make({ {{0, 0, 0}, north, east, {0, half_pi}}, @@ -148,6 +152,7 @@ BOOST_DATA_TEST_CASE(test_create_arc, } using fac = std::tuple; + BOOST_DATA_TEST_CASE(test_find_arc_centre, boost::unit_test::data::make({ {{2, 2}, pi, {3, 3}, half_pi, {3, 2}, true}, @@ -178,6 +183,7 @@ struct TestLinkStraight : public LinkStraight { }; using StraightsData = std::tuple; + BOOST_DATA_TEST_CASE(straight1, boost::unit_test::data::make({ {north, 0, pi}, @@ -210,6 +216,7 @@ struct TestLinkCurve : public LinkCurve { }; using CurvesData = std::tuple; + BOOST_DATA_TEST_CASE(curve1, boost::unit_test::data::make({ {north + east, east, 0, -half_pi}, diff --git a/test/test-network.cpp b/test/test-network.cpp index a8db2b6..ab0818a 100644 --- a/test/test-network.cpp +++ b/test/test-network.cpp @@ -25,8 +25,11 @@ BOOST_GLOBAL_FIXTURE(TestMainWindow); struct TestLink : public LinkStraight { TestLink(const Node::Ptr & a, const Node::Ptr & b) : TestLink {a, b, (a->pos - b->pos)} { } + TestLink(Node::Ptr a, Node::Ptr b, glm::vec2 l) : Link {{std::move(a), 0}, {std::move(b), pi}, glm::length(l)} { } + TestLink(Node::Ptr a, Node::Ptr b, float l) : Link {{std::move(a), 0}, {std::move(b), pi}, l} { } + using StraightLink = TestLink; using CurveLink = TestLink; }; diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp index 38bbf2f..abb68c2 100644 --- a/test/test-persistence.cpp +++ b/test/test-persistence.cpp @@ -26,6 +26,7 @@ struct JPP { BOOST_REQUIRE(to); return to; } + // Presumably BOOST_TEST_CONTEXT is implemented as an if (...) { } throw std::logic_error("We shouldn't ever get here, but apparently we can!"); } @@ -213,6 +214,7 @@ auto const TEST_STRINGS_DECODE_ONLY = boost::unit_test::data::make({ {R"J("\u056b ARMENIAN SMALL LETTER INI")J", "ի ARMENIAN SMALL LETTER INI"}, {R"J("\u0833 SAMARITAN PUNCTUATION BAU")J", "࠳ SAMARITAN PUNCTUATION BAU"}, }); + BOOST_DATA_TEST_CASE(load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in, exp) { std::stringstream str {in}; @@ -220,6 +222,7 @@ BOOST_DATA_TEST_CASE(load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in, } using cpstr = std::tuple; + BOOST_DATA_TEST_CASE(utf8_decode, boost::unit_test::data::make({ {9, "\t"}, @@ -296,6 +299,7 @@ BOOST_AUTO_TEST_CASE(get_default_id) { SubObject2 so; const auto id {so.getId()}; + BOOST_TEST_CONTEXT(id) { auto ptr = std::stoul(id, nullptr, 16); BOOST_CHECK_EQUAL(ptr, reinterpret_cast(&so)); diff --git a/test/test-render.cpp b/test/test-render.cpp index 0d384a3..b16f241 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -43,16 +43,19 @@ public: train2->bogies.front().setPosition(train2->bogies.front().position() + train2->location.position()); train2->bogies.back().setPosition(train2->bogies.back().position() + train2->location.position()); } + void content(const SceneShader & shader) const override { terrain.render(shader); brush47rvc->render(shader); } + void lights(const SceneShader &) const override { } + void shadows(const ShadowMapper & shadowMapper) const override { @@ -95,6 +98,7 @@ BOOST_AUTO_TEST_CASE(pointlight) { SceneRenderer ss {size, output}; ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); + class PointLightScene : public TestScene { public: void @@ -103,6 +107,7 @@ BOOST_AUTO_TEST_CASE(pointlight) r.setAmbientLight({0.2F, 0.2F, 0.2F}); r.setDirectionalLight({0.2F, 0.2F, 0.2F}, west + down, *this); } + void lights(const SceneShader & shader) const override { @@ -113,6 +118,7 @@ BOOST_AUTO_TEST_CASE(pointlight) } } }; + const PointLightScene scene; ss.render(scene); Texture::save(outImage, "/tmp/pointlight.tga"); @@ -122,6 +128,7 @@ BOOST_AUTO_TEST_CASE(spotlight) { SceneRenderer ss {size, output}; ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); + class PointLightScene : public TestScene { public: void @@ -130,6 +137,7 @@ BOOST_AUTO_TEST_CASE(spotlight) r.setAmbientLight({0.2F, 0.2F, 0.2F}); r.setDirectionalLight({0.2F, 0.2F, 0.2F}, west + down, *this); } + void lights(const SceneShader & shader) const override { @@ -139,6 +147,7 @@ BOOST_AUTO_TEST_CASE(spotlight) shader.spotLight.add({60, 50, 3}, north + east, {1.0, 1.0, 1.0}, 0.0001F, .7F); } }; + const PointLightScene scene; ss.render(scene); Texture::save(outImage, "/tmp/spotlight.tga"); diff --git a/test/test-text.cpp b/test/test-text.cpp index 629892f..166a6fa 100644 --- a/test/test-text.cpp +++ b/test/test-text.cpp @@ -36,6 +36,7 @@ struct FontTest : public Font { BOOST_TEST_DONT_PRINT_LOG_VALUE(Font::CharData); using TextureSizeTestData = std::tuple; + BOOST_DATA_TEST_CASE(fontTextureSize, boost::unit_test::data::make({2, 3, 10, 50, 250}), fontHeight) { auto isPowerOfTwo = [](auto x) { @@ -64,6 +65,7 @@ BOOST_AUTO_TEST_CASE(initialize_chardata) } using CharDataTest = std::tuple; + BOOST_DATA_TEST_CASE(initialize_chardata_A, boost::unit_test::data::make({ {'A', {0, {34, 35}, {627, 0}, {-1, 35}, 32}}, diff --git a/test/testMainWindow.h b/test/testMainWindow.h index bc9c0bd..445491d 100644 --- a/test/testMainWindow.h +++ b/test/testMainWindow.h @@ -7,6 +7,7 @@ class TestMainWindow : public Window { // in the same way a real main window would always exist. public: TestMainWindow(); + void tick(TickDuration) override { diff --git a/test/testRenderOutput.h b/test/testRenderOutput.h index f5cd56b..13c380f 100644 --- a/test/testRenderOutput.h +++ b/test/testRenderOutput.h @@ -17,6 +17,7 @@ public: glRenderBuffer depth; glTexture outImage; }; + template class TestRenderOutputSize : public TestRenderOutput { public: TestRenderOutputSize() : TestRenderOutput {Size} { } -- cgit v1.2.3