summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Jamfile.jam3
-rw-r--r--test/fixtures/geoData/deform/1.json201
-rw-r--r--test/test-geoData.cpp77
-rw-r--r--test/test-lib.cpp20
-rw-r--r--test/test-static-stream_support.cpp21
-rw-r--r--test/testHelpers.h11
6 files changed, 325 insertions, 8 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
index 733ef05..cce4513 100644
--- a/test/Jamfile.jam
+++ b/test/Jamfile.jam
@@ -12,6 +12,7 @@ project : requirements
<define>BOOST_TEST_DYN_LINK
<define>RESDIR=\\\"$(res)/\\\"
<define>FIXTURESDIR=\\\"$(fixtures)/\\\"
+ <define>GLM_FORCE_SWIZZLE
<variant>debug:<warnings>pedantic
<variant>debug:<warnings-as-errors>on
<variant>debug:<cflags>-Wnon-virtual-dtor
@@ -46,7 +47,7 @@ lib test : [ glob *.cpp : test-*.cpp perf-*.cpp ] ;
run test-collection.cpp ;
run test-maths.cpp ;
run test-lib.cpp ;
-run test-geoData.cpp : -- : fixtures/height/SD19.asc : <library>test ;
+run test-geoData.cpp : -- : [ sequence.insertion-sort [ glob-tree $(fixtures)/geoData : *.json ] fixtures/height/SD19.asc ] : <library>test ;
run test-network.cpp : : : <library>test ;
run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob-tree $(fixtures)/json : *.json ] ] : <library>test ;
run test-text.cpp : -- : test-glContainer : <library>test ;
diff --git a/test/fixtures/geoData/deform/1.json b/test/fixtures/geoData/deform/1.json
new file mode 100644
index 0000000..6930238
--- /dev/null
+++ b/test/fixtures/geoData/deform/1.json
@@ -0,0 +1,201 @@
+[
+ [
+ [
+ [
+ 70100,
+ 123000,
+ 6000
+ ],
+ [
+ 50100,
+ 52300,
+ 6000
+ ],
+ [
+ 191000,
+ 283000,
+ 8000
+ ],
+ [
+ 241000,
+ 123330,
+ 2000
+ ]
+ ],
+ [
+ [
+ [
+ [
+ 20000,
+ 20000,
+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cab7..fb9aba0 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)
@@ -187,6 +192,23 @@ BOOST_DATA_TEST_CASE(walkTerrainUntil,
BOOST_CHECK_EQUAL_COLLECTIONS(visited.begin(), visited.end(), visits.begin(), visits.end());
}
+BOOST_AUTO_TEST_CASE(triangle_helpers)
+{
+ constexpr static GeoData::Triangle<3> t {{0, 0, 0}, {5, 0, 0}, {5, 5, 0}};
+
+ BOOST_CHECK_EQUAL(t.nnormal(), up);
+ BOOST_CHECK_CLOSE(t.angle(0), quarter_pi, 0.01F);
+ BOOST_CHECK_CLOSE(t.angleAt({0, 0, 0}), quarter_pi, 0.01F);
+ BOOST_CHECK_CLOSE(t.angle(1), half_pi, 0.01F);
+ BOOST_CHECK_CLOSE(t.angleAt({5, 0, 0}), half_pi, 0.01F);
+ BOOST_CHECK_CLOSE(t.angle(2), quarter_pi, 0.01F);
+ BOOST_CHECK_CLOSE(t.angleAt({5, 5, 0}), quarter_pi, 0.01F);
+
+ BOOST_CHECK_CLOSE(t.angleAt({0, 1, 0}), 0.F, 0.01F);
+
+ BOOST_CHECK_CLOSE(t.area(), 12.5F, 0.01F);
+}
+
using FindEntiesData = std::tuple<GlobalPosition2D, GlobalPosition2D, int>;
BOOST_DATA_TEST_CASE(findEntries,
@@ -199,3 +221,56 @@ BOOST_DATA_TEST_CASE(findEntries,
{
BOOST_CHECK_EQUAL(fixedTerrtain.findEntry(from, to).idx(), heh);
}
+
+using DeformTerrainData = std::tuple<std::vector<GlobalPosition3D>,
+ std::vector<std::pair<std::pair<GlobalPosition3D, Direction3D>, std::string>>>;
+
+BOOST_TEST_DECORATOR(*boost::unit_test::timeout(2));
+
+BOOST_DATA_TEST_CASE(deform, loadFixtureJson<DeformTerrainData>("geoData/deform/1.json"), points, cams)
+{
+ auto gd = std::make_shared<GeoData>(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100));
+ BOOST_CHECK_NO_THROW(gd->setHeights(points));
+
+ ApplicationBase ab;
+ TestMainWindow tmw;
+ TestRenderOutput tro {{640, 480}};
+
+ 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
+ {
+ terrain.render(shader);
+ }
+
+ 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};
+ SceneRenderer ss {tro.size, tro.output};
+ std::for_each(cams.begin(), cams.end(), [&ss, &t, &tro](const auto & cam) {
+ ss.camera.setView(cam.first.first, glm::normalize(cam.first.second));
+ BOOST_CHECK_NO_THROW(ss.render(t));
+ Texture::save(tro.outImage, cam.second.c_str());
+ });
+}
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());
+}
diff --git a/test/test-static-stream_support.cpp b/test/test-static-stream_support.cpp
index 3002ccc..6bf9ea4 100644
--- a/test/test-static-stream_support.cpp
+++ b/test/test-static-stream_support.cpp
@@ -1,11 +1,20 @@
#include "stream_support.h"
#include <array>
+#include <map>
+#include <set>
#include <vector>
-static_assert(spanable<std::vector<int>>);
-static_assert(spanable<std::vector<char>>);
-static_assert(spanable<std::array<int, 1>>);
-static_assert(spanable<std::array<char, 1>>);
-static_assert(!spanable<std::string>);
-static_assert(!spanable<std::string_view>);
+static_assert(NonStringIterableCollection<std::vector<int>>);
+static_assert(NonStringIterableCollection<std::set<int>>);
+static_assert(NonStringIterableCollection<std::map<int, int>>);
+static_assert(NonStringIterableCollection<std::vector<char>>);
+static_assert(NonStringIterableCollection<std::array<int, 1>>);
+static_assert(NonStringIterableCollection<std::array<char, 1>>);
+static_assert(!NonStringIterableCollection<std::string>);
+static_assert(!NonStringIterableCollection<std::string_view>);
+
+static_assert(requires(std::vector<int> i, std::ostream & o) { o << i; });
+static_assert(requires(std::array<int, 10> i, std::ostream & o) { o << i; });
+static_assert(requires(std::set<int> i, std::ostream & o) { o << i; });
+static_assert(requires(std::map<int, int> i, std::ostream & o) { o << i; });
diff --git a/test/testHelpers.h b/test/testHelpers.h
index f2b0901..58e4372 100644
--- a/test/testHelpers.h
+++ b/test/testHelpers.h
@@ -2,11 +2,22 @@
#include <boost/test/tools/context.hpp>
#include <boost/test/tools/interface.hpp>
+#include <filesystem>
+#include <fstream>
#include <iomanip> // IWYU pragma: keep std::setprecision
+#include <jsonParse-persistence.h>
#include <memory>
std::unique_ptr<char, decltype(&free)> uasprintf(const char * fmt, ...) __attribute__((format(printf, 1, 2)));
+template<typename T>
+decltype(auto)
+loadFixtureJson(const std::filesystem::path & path)
+{
+ std::ifstream in {FIXTURESDIR / path};
+ return Persistence::JsonParsePersistence {}.loadState<std::vector<T>>(in);
+}
+
#define BOOST_CHECK_CLOSE_VEC(a_, b_) \
{ \
const auto a {a_}, b {b_}; \