From 3eed7751c9f2a7ae5cdba1d233751f82dd8d9b10 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 3 Nov 2023 21:31:35 +0000 Subject: Don't request a specific OpenGL version, just check we get something sufficient from gladLoadGL --- test/test-glContextBhvr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test-glContextBhvr.cpp b/test/test-glContextBhvr.cpp index 1f1215c..769f61f 100644 --- a/test/test-glContextBhvr.cpp +++ b/test/test-glContextBhvr.cpp @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) const SDL_GLContextPtr context {window}; BOOST_REQUIRE(context); BOOST_REQUIRE(!glCreateProgram); - BOOST_REQUIRE_EQUAL(gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)), 40006); + BOOST_REQUIRE_GT(gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)), 0); BOOST_REQUIRE(glCreateProgram); CreateProgramTest(); } // Context destroyed -- cgit v1.2.3 From 2f8d7643d03f39fa848576692264d0fe3a37ed91 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 6 Nov 2023 20:48:33 +0000 Subject: Reformat with new clang-format --- 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(+) (limited to 'test') 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 769f61f..26b45d9 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 From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- test/test-assetFactory.cpp | 5 +++-- test/testRenderOutput.h | 7 ++++--- test/testStructures.h | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 145481e..177ab6a 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -183,14 +183,15 @@ BOOST_AUTO_TEST_CASE(texturePacker_many, *boost::unit_test::timeout(5)) { std::vector images(256); std::fill(images.begin(), images.end(), TexturePacker::Image {32, 32}); - const auto totalSize = std::accumulate(images.begin(), images.end(), 0U, [](auto t, const auto & i) { + const auto totalSize = std::accumulate(images.begin(), images.end(), 0, [](auto t, const auto & i) { return t + TexturePacker::area(i); }); TexturePacker tp {images}; BOOST_CHECK_EQUAL(TexturePacker::Size(32, 32), tp.minSize()); const auto result = tp.pack(); BOOST_CHECK_EQUAL(result.first.size(), images.size()); - BOOST_CHECK_GE(TexturePacker::area(result.second), TexturePacker::area(images.front()) * images.size()); + BOOST_CHECK_GE(TexturePacker::area(result.second), + TexturePacker::area(images.front()) * static_cast(images.size())); BOOST_CHECK_EQUAL(totalSize, TexturePacker::area(result.second)); } diff --git a/test/testRenderOutput.h b/test/testRenderOutput.h index 13c380f..056d029 100644 --- a/test/testRenderOutput.h +++ b/test/testRenderOutput.h @@ -1,24 +1,25 @@ #pragma once +#include "config/types.h" #include "glArrays.h" #include #include class TestRenderOutput { public: - TestRenderOutput(glm::ivec2 size = {640, 480}); + explicit TestRenderOutput(TextureAbsCoord size = {640, 480}); virtual ~TestRenderOutput() = default; NO_MOVE(TestRenderOutput); NO_COPY(TestRenderOutput); - const glm::ivec2 size; + const TextureAbsCoord size; glFrameBuffer output; glRenderBuffer depth; glTexture outImage; }; -template class TestRenderOutputSize : public TestRenderOutput { +template class TestRenderOutputSize : public TestRenderOutput { public: TestRenderOutputSize() : TestRenderOutput {Size} { } }; diff --git a/test/testStructures.h b/test/testStructures.h index 6966052..aaaf940 100644 --- a/test/testStructures.h +++ b/test/testStructures.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include struct AbsObject : public Persistence::Persistable { @@ -31,9 +32,9 @@ struct TestObject : public Persistence::Persistable { float flt {}; std::string str {}; bool bl {}; - glm::vec3 pos {}; + Position3D pos {}; std::vector flts; - std::vector poss; + std::vector poss; std::vector>> nest; std::unique_ptr ptr; std::unique_ptr aptr; -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- test/test-assetFactory.cpp | 2 +- test/testRenderOutput.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 177ab6a..9af08cb 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -25,7 +25,7 @@ BOOST_GLOBAL_FIXTURE(TestMainWindow); const std::filesystem::path TMP {"/tmp"}; -class FactoryFixture : public TestRenderOutputSize, public SceneProvider { +class FactoryFixture : public TestRenderOutputSize, public SceneProvider { public: FactoryFixture() : sceneRenderer {size, output} { } diff --git a/test/testRenderOutput.cpp b/test/testRenderOutput.cpp index 464b0b3..9af4451 100644 --- a/test/testRenderOutput.cpp +++ b/test/testRenderOutput.cpp @@ -1,7 +1,7 @@ #include "testRenderOutput.h" #include -TestRenderOutput::TestRenderOutput(glm::ivec2 s) : size {s} +TestRenderOutput::TestRenderOutput(TextureAbsCoord s) : size {s} { glBindFramebuffer(GL_FRAMEBUFFER, output); const auto configuregdata -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- test/test-assetFactory.cpp | 14 +++++++------- test/test-geo.cpp | 10 +++++----- test/test-render.cpp | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 9af08cb..c8183df 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -64,7 +64,7 @@ public: } void - render(float dist = 10.f) + render(float dist) { sceneRenderer.camera.setView({-dist, dist * 1.2f, dist * 1.2f}, south + east + down); sceneRenderer.render(*this); @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5)) auto railVehicle = std::make_shared(brush47rvc); objects.objects.push_back(brush47rvc); - render(); + render(10000); } BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) @@ -116,13 +116,13 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) auto tree_01_1_f = std::dynamic_pointer_cast(tree_01_1); BOOST_REQUIRE(tree_01_1_f); - auto plant1 = std::make_shared(tree_01_1_f, Location {{-2, 2, 0}, {0, 0, 0}}); - auto plant2 = std::make_shared(tree_01_1_f, Location {{3, -4, 0}, {0, 1, 0}}); - auto plant3 = std::make_shared(tree_01_1_f, Location {{-2, -4, 0}, {0, 2, 0}}); - auto plant4 = std::make_shared(tree_01_1_f, Location {{3, 2, 0}, {0, 3, 0}}); + auto plant1 = std::make_shared(tree_01_1_f, Location {{-2000, 2000, 0}, {0, 0, 0}}); + auto plant2 = std::make_shared(tree_01_1_f, Location {{3000, -4000, 0}, {0, 1, 0}}); + auto plant3 = std::make_shared(tree_01_1_f, Location {{-2000, -4000, 0}, {0, 2, 0}}); + auto plant4 = std::make_shared(tree_01_1_f, Location {{3000, 2000, 0}, {0, 3, 0}}); objects.objects.push_back(tree_01_1_f); - render(5); + render(6000); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/test/test-geo.cpp b/test/test-geo.cpp index 9874fb7..7404d32 100644 --- a/test/test-geo.cpp +++ b/test/test-geo.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(initialize) BOOST_CHECK_EQUAL(size, glm::uvec2(41, 46)); BOOST_CHECK_EQUAL(nodes.size(), 1886); BOOST_CHECK(std::all_of(nodes.begin(), nodes.end(), [](const auto & n) { - return n.height == -1.5F; + return n.height == -1500.F; })); } @@ -63,12 +63,12 @@ BOOST_AUTO_TEST_CASE(gen_random) })); // Still an island for (int x = limit.first.x; x <= limit.second.x; x += 1) { - BOOST_CHECK_EQUAL(nodes[at(x, limit.first.y)].height, -1.5F); - BOOST_CHECK_EQUAL(nodes[at(x, limit.second.y)].height, -1.5F); + BOOST_CHECK_EQUAL(nodes[at(x, limit.first.y)].height, -1500.F); + BOOST_CHECK_EQUAL(nodes[at(x, limit.second.y)].height, -1500.F); } for (int y = limit.first.y; y <= limit.second.y; y += 1) { - BOOST_CHECK_EQUAL(nodes[at(limit.first.x, y)].height, -1.5F); - BOOST_CHECK_EQUAL(nodes[at(limit.second.x, y)].height, -1.5F); + BOOST_CHECK_EQUAL(nodes[at(limit.first.x, y)].height, -1500.F); + BOOST_CHECK_EQUAL(nodes[at(limit.second.x, y)].height, -1500.F); } } diff --git a/test/test-render.cpp b/test/test-render.cpp index b16f241..766bb74 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -26,7 +26,7 @@ class TestScene : public SceneProvider { std::shared_ptr train1, train2; Terrain terrain {[]() { - auto gd = std::make_shared(GeoData::Limits {{0, 0}, {100, 100}}); + auto gd = std::make_shared(GeoData::Limits {{0, 0}, {100, 100}}, 10000); gd->generateRandom(); return gd; }()}; @@ -35,11 +35,11 @@ public: TestScene() { train1 = std::make_shared(brush47rvc); - train1->location.setPosition({52, 50, 2}); + train1->location.setPosition({52000, 50000, 2000}); train1->bogies.front().setPosition(train1->bogies.front().position() + train1->location.position()); train1->bogies.back().setPosition(train1->bogies.back().position() + train1->location.position()); train2 = std::make_shared(brush47rvc); - train2->location.setPosition({52, 30, 2}); + train2->location.setPosition({52000, 30000, 2000}); train2->bogies.front().setPosition(train2->bogies.front().position() + train2->location.position()); train2->bogies.back().setPosition(train2->bogies.back().position() + train2->location.position()); } @@ -88,7 +88,7 @@ BOOST_FIXTURE_TEST_SUITE(w, TestRenderOutput); BOOST_AUTO_TEST_CASE(basic) { SceneRenderer ss {size, output}; - ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); + ss.camera.setView({-10000, -10000, 60000}, glm::normalize(glm::vec3 {1, 1, -0.5F})); const TestScene scene; ss.render(scene); Texture::save(outImage, "/tmp/basic.tga"); @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(basic) BOOST_AUTO_TEST_CASE(pointlight) { SceneRenderer ss {size, output}; - ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); + ss.camera.setView({-10000, -10000, 60000}, glm::normalize(glm::vec3 {1, 1, -0.5F})); class PointLightScene : public TestScene { public: @@ -111,9 +111,9 @@ BOOST_AUTO_TEST_CASE(pointlight) void lights(const SceneShader & shader) const override { - for (int x = 50; x < 100; x += 20) { - for (int y = 50; y < 2000; y += 20) { - shader.pointLight.add({x, y, 4}, {1.0, 1.0, 1.0}, 0.1F); + for (int x = 50000; x < 100000; x += 20000) { + for (int y = 50000; y < 2000000; y += 20000) { + shader.pointLight.add({x, y, 4000}, {1.0, 1.0, 1.0}, 0.1F); } } } @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(pointlight) BOOST_AUTO_TEST_CASE(spotlight) { SceneRenderer ss {size, output}; - ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); + ss.camera.setView({-10000, -10000, 60000}, glm::normalize(glm::vec3 {1, 1, -0.5F})); class PointLightScene : public TestScene { public: @@ -141,10 +141,10 @@ BOOST_AUTO_TEST_CASE(spotlight) void lights(const SceneShader & shader) const override { - shader.spotLight.add({50, 50, 15}, down, {1.0, 1.0, 1.0}, 0.01F, 1); - shader.spotLight.add({51, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001F, .5); - shader.spotLight.add({53, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001F, .5); - shader.spotLight.add({60, 50, 3}, north + east, {1.0, 1.0, 1.0}, 0.0001F, .7F); + shader.spotLight.add({50000, 50000, 15000}, down, {1.0, 1.0, 1.0}, 0.01F, 1); + shader.spotLight.add({51000, 59500, 1000}, north, {1.0, 1.0, 1.0}, 0.001F, .5); + shader.spotLight.add({53000, 59500, 1000}, north, {1.0, 1.0, 1.0}, 0.001F, .5); + shader.spotLight.add({60000, 50000, 3000}, north + east, {1.0, 1.0, 1.0}, 0.0001F, .7F); } }; -- cgit v1.2.3 From 0aa665c3648d788755b00c9e431c872d57fddbb8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 16:28:39 +0000 Subject: Model positions as integers Introduces test failure in arcs due to rounding, but I don't want to create a complicated fix as link positions are still floats and hopefully that'll go away... somehow --- test/test-maths.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/test-maths.cpp b/test/test-maths.cpp index 2560319..9eae918 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -196,12 +196,12 @@ BOOST_DATA_TEST_CASE(straight1, const TestLinkStraight l(v); { const auto p = l.positionAt(0, 0); - BOOST_CHECK_EQUAL(p.pos, origin); + BOOST_CHECK_EQUAL(p.pos, GlobalPosition3D {origin}); BOOST_CHECK_EQUAL(p.rot, glm::vec3(0, angFor, 0)); } { const auto p = l.positionAt(0, 1); - BOOST_CHECK_EQUAL(p.pos, v); + BOOST_CHECK_EQUAL(p.pos, GlobalPosition3D {v}); BOOST_CHECK_EQUAL(p.rot, glm::vec3(0, angBack, 0)); } } @@ -231,12 +231,12 @@ BOOST_DATA_TEST_CASE(curve1, BOOST_CHECK_EQUAL(l.radius, 1.F); { const auto p = l.positionAt(0, 0); - BOOST_CHECK_CLOSE_VEC(p.pos, origin); + BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, origin); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angFor, 0)); } { const auto p = l.positionAt(0, 1); - BOOST_CHECK_CLOSE_VEC(p.pos, e1); + BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, e1); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angBack, 0)); } } @@ -247,13 +247,13 @@ BOOST_DATA_TEST_CASE(curve1, { const auto p = l.positionAt(0, 0); const auto angForReversed = normalize(vector_yaw(origin - e1) * 2 - angFor); - BOOST_CHECK_CLOSE_VEC(p.pos, e1); + BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, e1); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angForReversed, 0)); } { const auto p = l.positionAt(0, 1); const auto angBackReversed = normalize(vector_yaw(e1 - origin) * 2 - angBack); - BOOST_CHECK_CLOSE_VEC(p.pos, origin); + BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, origin); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angBackReversed, 0)); } } -- cgit v1.2.3