summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test-geoData.cpp62
-rw-r--r--test/test-lib.cpp20
2 files changed, 81 insertions, 1 deletions
diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp
index 302cab7..ac1d668 100644
--- a/test/test-geoData.cpp
+++ b/test/test-geoData.cpp
@@ -1,7 +1,12 @@
#define BOOST_TEST_MODULE terrain
+#include "game/terrain.h"
+#include "test/testMainWindow.h"
+#include "test/testRenderOutput.h"
#include "testHelpers.h"
+#include "ui/applicationBase.h"
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
+#include <gfx/gl/sceneRenderer.h>
#include <stream_support.h>
#include <game/geoData.h>
@@ -114,7 +119,7 @@ BOOST_DATA_TEST_CASE(findRayIntersect,
}),
p, d, i)
{
- BOOST_CHECK_EQUAL(fixedTerrtain.intersectRay({p, d}).value(), i);
+ BOOST_CHECK_EQUAL(fixedTerrtain.intersectRay({p, d})->first, i);
}
BOOST_AUTO_TEST_CASE(boundaryWalk)
@@ -199,3 +204,58 @@ BOOST_DATA_TEST_CASE(findEntries,
{
BOOST_CHECK_EQUAL(fixedTerrtain.findEntry(from, to).idx(), heh);
}
+
+BOOST_AUTO_TEST_CASE(setTriangle, *boost::unit_test::timeout(5))
+{
+ auto gd = std::make_shared<GeoData>(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100));
+ std::array points {
+ GlobalPosition3D {70100, 123000, 6000},
+ GlobalPosition3D {50100, 52300, 6000},
+ GlobalPosition3D {191000, 283000, 8000},
+ GlobalPosition3D {241000, 123330, -2000},
+ };
+ BOOST_CHECK_NO_THROW(gd->setHeights(points));
+
+ ApplicationBase ab;
+ TestMainWindow tmw;
+ TestRenderOutput tro {{1792, 1024}};
+
+ SceneRenderer ss {tro.size, tro.output};
+ ss.camera.setView({-90000, -90000, 300000}, glm::normalize(glm::vec3 {1, 1, -1.5F}));
+
+ struct TestTerrain : public SceneProvider {
+ explicit TestTerrain(std::shared_ptr<GeoData> gd) : terrain(std::move(gd)) { }
+
+ const Terrain terrain;
+
+ void
+ content(const SceneShader & shader) const override
+ {
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ terrain.render(shader);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ }
+
+ void
+ environment(const SceneShader &, const SceneRenderer & sr) const override
+ {
+ sr.setAmbientLight({0.1, 0.1, 0.1});
+ sr.setDirectionalLight({1, 1, 1}, south + down, *this);
+ }
+
+ void
+ lights(const SceneShader &) const override
+ {
+ }
+
+ void
+ shadows(const ShadowMapper & shadowMapper) const override
+ {
+ terrain.shadows(shadowMapper);
+ }
+ };
+
+ TestTerrain t {gd};
+ BOOST_CHECK_NO_THROW(ss.render(t));
+ Texture::save(tro.outImage, "/tmp/geoData.tga");
+}
diff --git a/test/test-lib.cpp b/test/test-lib.cpp
index 58b769a..5f0b5e5 100644
--- a/test/test-lib.cpp
+++ b/test/test-lib.cpp
@@ -4,6 +4,7 @@
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
+#include <collections.h>
#include <glArrays.h>
#include <glad/gl.h>
#include <set>
@@ -49,3 +50,22 @@ BOOST_AUTO_TEST_CASE(generate_move_and_delete)
}
BOOST_CHECK(active.empty());
}
+
+constexpr std::array TRIANGLE_STRIP_IN {0, 1, 2, 3, 4, 5};
+static_assert(std::distance(strip_begin(TRIANGLE_STRIP_IN), strip_end(TRIANGLE_STRIP_IN)) == 4);
+
+BOOST_AUTO_TEST_CASE(triangle_strip_iter)
+{
+ constexpr std::array TRIANGLE_STRIP_EXPECTED {0, 1, 2, 2, 1, 3, 2, 3, 4, 4, 3, 5};
+
+ std::vector<int> out;
+ std::for_each(strip_begin(TRIANGLE_STRIP_IN), strip_end(TRIANGLE_STRIP_IN), [&out](const auto & t) {
+ const auto [a, b, c] = t;
+ out.push_back(a);
+ out.push_back(b);
+ out.push_back(c);
+ });
+ BOOST_REQUIRE_EQUAL(out.size(), (TRIANGLE_STRIP_IN.size() - 2) * 3);
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ out.begin(), out.end(), TRIANGLE_STRIP_EXPECTED.begin(), TRIANGLE_STRIP_EXPECTED.end());
+}