summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 18:03:34 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 18:03:34 +0100
commit5776a36b454fac04617313da011d7aa2b0e834d3 (patch)
tree1eb96d07e9a17a51e5763f397fc003f762cd2e75 /test
parentMerge branch 'model-factory-textures' (diff)
parentAdd an asset template and use it to define all the foliage assets in the plan... (diff)
downloadilt-5776a36b454fac04617313da011d7aa2b0e834d3.tar.bz2
ilt-5776a36b454fac04617313da011d7aa2b0e834d3.tar.xz
ilt-5776a36b454fac04617313da011d7aa2b0e834d3.zip
Merge branch 'assimp'
Diffstat (limited to 'test')
-rw-r--r--test/Jamfile.jam10
-rw-r--r--test/perf-assetFactory.cpp11
-rw-r--r--test/test-assetFactory.cpp28
-rw-r--r--test/test-obj.cpp39
-rw-r--r--test/test-render.cpp30
-rw-r--r--test/test-worker.cpp104
6 files changed, 168 insertions, 54 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
index bf1c408..b0eed5e 100644
--- a/test/Jamfile.jam
+++ b/test/Jamfile.jam
@@ -44,7 +44,6 @@ project : requirements
lib test : [ glob *.cpp : test-*.cpp perf-*.cpp ] ;
run test-collection.cpp ;
-run test-obj.cpp ;
run test-maths.cpp ;
run test-lib.cpp ;
run test-geo.cpp ;
@@ -52,11 +51,12 @@ run test-network.cpp ;
run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob-tree fixtures : *.json ] ] : <library>test ;
run test-text.cpp ;
run test-enumDetails.cpp ;
-run test-render.cpp : : : <library>test ;
+run test-render.cpp : -- : test-assetFactory : <library>test ;
run test-glContextBhvr.cpp ;
-run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.xml *.png ] fixtures/rgb.txt ] : <library>test ;
-run perf-assetFactory.cpp : : : <library>benchmark <library>test <dependency>test-assetFactory ;
-run perf-persistence.cpp : : : <library>benchmark <library>test <dependency>test-persistence ;
+run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.* ] fixtures/rgb.txt ] : <library>test ;
+run perf-assetFactory.cpp : -- : test-assetFactory : <library>benchmark <library>test ;
+run perf-persistence.cpp : -- : test-persistence : <library>benchmark <library>test ;
+run test-worker.cpp ;
compile test-static-enumDetails.cpp ;
compile test-static-stream_support.cpp ;
explicit perf-assetFactory ;
diff --git a/test/perf-assetFactory.cpp b/test/perf-assetFactory.cpp
index c90ac52..147e4ba 100644
--- a/test/perf-assetFactory.cpp
+++ b/test/perf-assetFactory.cpp
@@ -14,6 +14,17 @@ brush47xml_load(benchmark::State & state)
}
}
+static void
+foliagexml_load(benchmark::State & state)
+{
+ TestMainWindow window;
+
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(AssetFactory::loadXML(RESDIR "/foliage.xml"));
+ }
+}
+
BENCHMARK(brush47xml_load);
+BENCHMARK(foliagexml_load);
BENCHMARK_MAIN();
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index 54168aa..3d79213 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -8,6 +8,8 @@
#include "assetFactory/assetFactory.h"
#include "assetFactory/object.h"
#include "assetFactory/texturePacker.h"
+#include "game/scenary/foliage.h"
+#include "game/scenary/plant.h"
#include "game/vehicles/railVehicle.h"
#include "game/vehicles/railVehicleClass.h"
#include "gfx/gl/sceneRenderer.h"
@@ -30,7 +32,7 @@ public:
glDisable(GL_DEBUG_OUTPUT);
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, size, outpath.c_str());
+ Texture::save(outImage, outpath.c_str());
}
void
content(const SceneShader & shader) const override
@@ -96,8 +98,30 @@ BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5))
render();
}
+
+BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5))
+{
+ auto mf = AssetFactory::loadXML(RESDIR "/foliage.xml");
+ BOOST_REQUIRE(mf);
+ auto tree_01_1 = mf->assets.at("Tree-01-1");
+ BOOST_REQUIRE(tree_01_1);
+ auto tree_01_1_f = std::dynamic_pointer_cast<Foliage>(tree_01_1);
+ BOOST_REQUIRE(tree_01_1_f);
+
+ auto plant = std::make_shared<Plant>(tree_01_1_f, Location {{-2, 2, 0}, {}});
+ objects.objects.push_back(plant);
+
+ render(5);
+}
BOOST_AUTO_TEST_SUITE_END();
+BOOST_AUTO_TEST_CASE(loadall)
+{
+ const auto assets = AssetFactory::loadAll(RESDIR);
+ BOOST_CHECK(assets.at("brush-47"));
+ BOOST_CHECK(assets.at("Tree-01-1"));
+}
+
template<typename T> using InOut = std::tuple<T, T>;
BOOST_DATA_TEST_CASE(normalizeColourName,
boost::unit_test::data::make<InOut<std::string>>({
@@ -157,7 +181,7 @@ BOOST_AUTO_TEST_CASE(texturePacker_many, *boost::unit_test::timeout(5))
BOOST_CHECK_EQUAL(totalSize, TexturePacker::area(result.second));
}
-BOOST_AUTO_TEST_CASE(texturePacker_many_random, *boost::unit_test::timeout(5))
+BOOST_AUTO_TEST_CASE(texturePacker_many_random, *boost::unit_test::timeout(15))
{
std::vector<TexturePacker::Image> images(2048);
std::mt19937 gen(std::random_device {}());
diff --git a/test/test-obj.cpp b/test/test-obj.cpp
deleted file mode 100644
index e6e725d..0000000
--- a/test/test-obj.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#define BOOST_TEST_MODULE test_obj
-
-#include <boost/test/unit_test.hpp>
-
-#include <gfx/models/obj.h>
-#include <gfx/models/vertex.hpp>
-#include <glm/glm.hpp>
-#include <map>
-#include <memory>
-#include <utility>
-#include <vector>
-
-BOOST_AUTO_TEST_CASE(objparse)
-{
- const ObjParser op {RESDIR "/brush47.obj"};
- BOOST_CHECK_EQUAL(75, op.vertices.size());
- BOOST_CHECK_EQUAL(112, op.texCoords.size());
- BOOST_CHECK_EQUAL(31, op.normals.size());
- BOOST_CHECK_EQUAL(3, op.objects.size());
- const auto & object {op.objects.front()};
- BOOST_CHECK_EQUAL("Body", object.first);
- BOOST_CHECK_EQUAL(21, object.second.size());
- BOOST_CHECK_EQUAL(8, object.second[0].size());
- BOOST_CHECK_EQUAL(8, object.second[1].size());
- BOOST_CHECK_EQUAL(4, object.second[12].size());
-}
-
-BOOST_AUTO_TEST_CASE(create_meshes)
-{
- const ObjParser op {RESDIR "/brush47.obj"};
- const auto ms = op.createMeshData();
- BOOST_REQUIRE_EQUAL(3, ms.size());
- BOOST_REQUIRE_EQUAL("Body", ms.begin()->first);
- const auto & o = ms.at("Body");
- BOOST_REQUIRE_EQUAL(88, o.first.size());
- const auto & v = o.first.front();
- BOOST_REQUIRE_CLOSE(-1.345, v.pos.x, 1);
- BOOST_REQUIRE_EQUAL(138, o.second.size());
-}
diff --git a/test/test-render.cpp b/test/test-render.cpp
index 7771760..45acab5 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -6,8 +6,10 @@
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
+#include <assetFactory/assetFactory.h>
#include <game/geoData.h>
#include <game/terrain.h>
+#include <game/vehicles/railVehicle.h>
#include <game/vehicles/railVehicleClass.h>
#include <gfx/gl/sceneRenderer.h>
#include <gfx/models/texture.h>
@@ -19,18 +21,30 @@
#include <ui/window.h>
class TestScene : public SceneProvider {
- RailVehicleClass train {"brush47"};
+ std::shared_ptr<RailVehicle> train1, train2;
+
Terrain terrain {[]() {
auto gd = std::make_shared<GeoData>(GeoData::Limits {{0, 0}, {100, 100}});
gd->generateRandom();
return gd;
}()};
+
+public:
+ TestScene()
+ {
+ const auto assetFactory = AssetFactory::loadXML(RESDIR "/brush47.xml");
+ const auto brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>(assetFactory->assets.at("brush-47"));
+ train1 = std::make_shared<RailVehicle>(brush47rvc);
+ train1->location.pos = {52, 50, 2};
+ train2 = std::make_shared<RailVehicle>(brush47rvc);
+ train2->location.pos = {52, 30, 2};
+ }
void
content(const SceneShader & shader) const override
{
terrain.render(shader);
- train.render(shader, Location {{52, 50, 2}}, {Location {{52, 56, 2}}, Location {{52, 44, 2}}});
- train.render(shader, Location {{52, 30, 2}}, {Location {{52, 36, 2}}, Location {{52, 24, 2}}});
+ train1->render(shader);
+ train2->render(shader);
}
void
lights(const SceneShader &) const override
@@ -40,8 +54,8 @@ class TestScene : public SceneProvider {
shadows(const ShadowMapper & shadowMapper) const override
{
terrain.shadows(shadowMapper);
- train.shadows(shadowMapper, Location {{52, 50, 2}}, {Location {{52, 56, 2}}, Location {{52, 44, 2}}});
- train.shadows(shadowMapper, Location {{52, 30, 2}}, {Location {{52, 36, 2}}, Location {{52, 24, 2}}});
+ train1->shadows(shadowMapper);
+ train2->shadows(shadowMapper);
}
};
@@ -73,7 +87,7 @@ BOOST_AUTO_TEST_CASE(basic)
const TestScene scene;
ss.render(scene);
glDisable(GL_DEBUG_OUTPUT);
- Texture::save(outImage, size, "/tmp/basic.tga");
+ Texture::save(outImage, "/tmp/basic.tga");
}
BOOST_AUTO_TEST_CASE(pointlight)
@@ -101,7 +115,7 @@ BOOST_AUTO_TEST_CASE(pointlight)
const PointLightScene scene;
ss.render(scene);
glDisable(GL_DEBUG_OUTPUT);
- Texture::save(outImage, size, "/tmp/pointlight.tga");
+ Texture::save(outImage, "/tmp/pointlight.tga");
}
BOOST_AUTO_TEST_CASE(spotlight)
@@ -128,7 +142,7 @@ BOOST_AUTO_TEST_CASE(spotlight)
const PointLightScene scene;
ss.render(scene);
glDisable(GL_DEBUG_OUTPUT);
- Texture::save(outImage, size, "/tmp/spotlight.tga");
+ Texture::save(outImage, "/tmp/spotlight.tga");
}
BOOST_AUTO_TEST_SUITE_END();
diff --git a/test/test-worker.cpp b/test/test-worker.cpp
new file mode 100644
index 0000000..76b7138
--- /dev/null
+++ b/test/test-worker.cpp
@@ -0,0 +1,104 @@
+#define BOOST_TEST_MODULE test_worker
+
+#include "testHelpers.h"
+#include <boost/test/unit_test.hpp>
+#include <set>
+#include <stream_support.hpp>
+#include <worker.h>
+
+uint32_t
+workCounter()
+{
+ static std::atomic_uint32_t n;
+ usleep(1000);
+ return n++;
+}
+
+void
+workVoid()
+{
+ usleep(1000);
+}
+
+void
+workFail()
+{
+ usleep(1000);
+ throw std::runtime_error {"test"};
+}
+
+BOOST_AUTO_TEST_CASE(basic_slow_counter)
+{
+ std::vector<Worker::WorkPtrT<uint32_t>> ps;
+ for (int i {}; i < 30; ++i) {
+ ps.push_back(Worker::addWork(workCounter));
+ }
+ std::set<uint32_t> out;
+ std::transform(ps.begin(), ps.end(), std::inserter(out, out.end()), [](auto && p) {
+ return p->get();
+ });
+ BOOST_REQUIRE_EQUAL(out.size(), ps.size());
+ BOOST_CHECK_EQUAL(*out.begin(), 0);
+ BOOST_CHECK_EQUAL(*out.rbegin(), ps.size() - 1);
+}
+
+BOOST_AUTO_TEST_CASE(basic_error_handler)
+{
+ auto workitem = Worker::addWork(workFail);
+ BOOST_CHECK_THROW(workitem->get(), std::runtime_error);
+}
+
+BOOST_AUTO_TEST_CASE(basic_void_work)
+{
+ auto workitem = Worker::addWork(workVoid);
+ BOOST_CHECK_NO_THROW(workitem->get());
+}
+
+BOOST_AUTO_TEST_CASE(lambda_void)
+{
+ BOOST_CHECK_NO_THROW(Worker::addWork([]() {})->get());
+ BOOST_CHECK_NO_THROW(Worker::addWork([](int) {}, 0)->get());
+ BOOST_CHECK_NO_THROW(Worker::addWork([](int, int) {}, 0, 0)->get());
+}
+
+BOOST_AUTO_TEST_CASE(lambda_value)
+{
+ BOOST_CHECK_EQUAL(1, Worker::addWork([]() {
+ return 1;
+ })->get());
+ BOOST_CHECK_EQUAL(2,
+ Worker::addWork(
+ [](int i) {
+ return i;
+ },
+ 2)
+ ->get());
+ BOOST_CHECK_EQUAL(3,
+ Worker::addWork(
+ [](int i, int j) {
+ return i + j;
+ },
+ 1, 2)
+ ->get());
+}
+
+BOOST_AUTO_TEST_CASE(recursive, *boost::unit_test::timeout(5))
+{
+ auto recurse = []() {
+ std::vector<Worker::WorkPtrT<uint32_t>> ps;
+ for (int i {}; i < 30; ++i) {
+ ps.push_back(Worker::addWork(workCounter));
+ }
+ return std::accumulate(ps.begin(), ps.end(), 0U, [](auto && out, auto && p) {
+ return out += p->get();
+ });
+ };
+ std::vector<Worker::WorkPtrT<uint32_t>> ps;
+ for (int i {}; i < 30; ++i) {
+ ps.push_back(Worker::addWork(recurse));
+ }
+ std::set<uint32_t> out;
+ std::transform(ps.begin(), ps.end(), std::inserter(out, out.end()), [](auto && p) {
+ return p->get();
+ });
+}