summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Jamfile.jam9
-rw-r--r--test/test-assetFactory.cpp48
-rw-r--r--test/test-persistence.cpp7
-rw-r--r--test/testStructures.cpp6
-rw-r--r--test/testStructures.h3
5 files changed, 67 insertions, 6 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
index e178573..bf1c408 100644
--- a/test/Jamfile.jam
+++ b/test/Jamfile.jam
@@ -1,5 +1,6 @@
import testing ;
import sequence ;
+import path : glob-tree ;
lib boost_unit_test_framework ;
lib benchmark ;
@@ -48,14 +49,14 @@ run test-maths.cpp ;
run test-lib.cpp ;
run test-geo.cpp ;
run test-network.cpp ;
-run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob fixtures/json/*.json fixtures/json/bad/*.json ] ] : <library>test ;
+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-glContextBhvr.cpp ;
-run test-assetFactory.cpp : -- : ../res/brush47.xml : <library>test ;
-run perf-assetFactory.cpp : : : <library>benchmark <library>test ;
-run perf-persistence.cpp : : : <library>benchmark <library>test ;
+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 ;
compile test-static-enumDetails.cpp ;
compile test-static-stream_support.cpp ;
explicit perf-assetFactory ;
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index 204ffb3..54168aa 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -7,6 +7,7 @@
#include "assetFactory/assetFactory.h"
#include "assetFactory/object.h"
+#include "assetFactory/texturePacker.h"
#include "game/vehicles/railVehicle.h"
#include "game/vehicles/railVehicleClass.h"
#include "gfx/gl/sceneRenderer.h"
@@ -67,7 +68,7 @@ private:
};
BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture);
-BOOST_AUTO_TEST_CASE(brush47xml)
+BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5))
{
auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml");
BOOST_REQUIRE(mf);
@@ -117,7 +118,7 @@ BOOST_DATA_TEST_CASE(normalizeColourName,
BOOST_CHECK_EQUAL(in, exp);
}
-BOOST_AUTO_TEST_CASE(parseX11RGB)
+BOOST_AUTO_TEST_CASE(parseX11RGB, *boost::unit_test::timeout(5))
{
const auto parsedColours = AssetFactory::parseX11RGB(FIXTURESDIR "rgb.txt");
BOOST_REQUIRE_EQUAL(parsedColours.size(), 20);
@@ -125,3 +126,46 @@ BOOST_AUTO_TEST_CASE(parseX11RGB)
BOOST_CHECK_CLOSE_VEC(parsedColours.at("slategrey"), AssetFactory::Colour(0.44F, 0.5, 0.56F));
BOOST_CHECK_CLOSE_VEC(parsedColours.at("lightsteelblue1"), AssetFactory::Colour(0.79, 0.88, 1));
}
+
+BOOST_AUTO_TEST_CASE(texturePacker, *boost::unit_test::timeout(5))
+{
+ std::vector<TexturePacker::Image> input {
+ {10, 10},
+ {10, 10},
+ {10, 10},
+ {100, 10},
+ {10, 200},
+ {5, 5},
+ };
+ TexturePacker tp {input};
+ BOOST_CHECK_EQUAL(TexturePacker::Size(128, 256), tp.minSize());
+ const auto result = tp.pack();
+}
+
+BOOST_AUTO_TEST_CASE(texturePacker_many, *boost::unit_test::timeout(5))
+{
+ std::vector<TexturePacker::Image> 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) {
+ 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_EQUAL(totalSize, TexturePacker::area(result.second));
+}
+
+BOOST_AUTO_TEST_CASE(texturePacker_many_random, *boost::unit_test::timeout(5))
+{
+ std::vector<TexturePacker::Image> images(2048);
+ std::mt19937 gen(std::random_device {}());
+ std::uniform_int_distribution<> dim {1, 10};
+ std::generate(images.begin(), images.end(), [&dim, &gen]() {
+ return TexturePacker::Image {2 ^ dim(gen), 2 ^ dim(gen)};
+ });
+ TexturePacker tp {images};
+ const auto result = tp.pack();
+ BOOST_CHECK_EQUAL(result.first.size(), images.size());
+}
diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp
index a72c481..38bbf2f 100644
--- a/test/test-persistence.cpp
+++ b/test/test-persistence.cpp
@@ -34,6 +34,7 @@ struct JPP {
BOOST_FIXTURE_TEST_CASE(load_object, JPP)
{
auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/load_object.json");
+ BOOST_CHECK_EQUAL(to->postLoadCalled, 1);
BOOST_CHECK_CLOSE(to->flt, 3.14, 0.01);
BOOST_CHECK_EQUAL(to->str, "Lovely string");
BOOST_CHECK_EQUAL(to->bl, true);
@@ -69,6 +70,7 @@ BOOST_FIXTURE_TEST_CASE(load_object, JPP)
BOOST_FIXTURE_TEST_CASE(load_nested_object, JPP)
{
auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/nested.json");
+ BOOST_CHECK_EQUAL(to->postLoadCalled, 1);
BOOST_CHECK_EQUAL(to->flt, 1.F);
BOOST_CHECK_EQUAL(to->str, "one");
BOOST_REQUIRE(to->ptr);
@@ -86,6 +88,7 @@ BOOST_FIXTURE_TEST_CASE(load_nested_object, JPP)
BOOST_FIXTURE_TEST_CASE(load_implicit_object, JPP)
{
auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/implicit.json");
+ BOOST_CHECK_EQUAL(to->postLoadCalled, 1);
BOOST_CHECK(to->ptr);
BOOST_CHECK_EQUAL(to->flt, 1.F);
BOOST_CHECK_EQUAL(to->ptr->str, "trigger");
@@ -95,6 +98,7 @@ BOOST_FIXTURE_TEST_CASE(load_implicit_object, JPP)
BOOST_FIXTURE_TEST_CASE(load_empty_object, JPP)
{
auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/empty.json");
+ BOOST_CHECK_EQUAL(to->postLoadCalled, 1);
BOOST_CHECK_EQUAL(to->flt, 1.F);
BOOST_CHECK(to->ptr);
BOOST_CHECK_EQUAL(to->str, "after");
@@ -119,6 +123,7 @@ BOOST_FIXTURE_TEST_CASE(load_obj_no_such_type, JPP)
BOOST_FIXTURE_TEST_CASE(load_abs_object, JPP)
{
auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/abs.json");
+ BOOST_CHECK_EQUAL(to->postLoadCalled, 1);
BOOST_REQUIRE(to->aptr);
BOOST_CHECK_NO_THROW(to->aptr->dummy());
BOOST_CHECK_EQUAL(to->aptr->base, "set base");
@@ -130,6 +135,7 @@ BOOST_FIXTURE_TEST_CASE(load_abs_object, JPP)
BOOST_FIXTURE_TEST_CASE(load_vector_ptr, JPP)
{
auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/vector_ptr.json");
+ BOOST_CHECK_EQUAL(to->postLoadCalled, 1);
BOOST_CHECK(to->str.empty());
BOOST_CHECK_EQUAL(to->vptr.size(), 4);
BOOST_CHECK_EQUAL(to->vptr.at(0)->str, "type");
@@ -141,6 +147,7 @@ BOOST_FIXTURE_TEST_CASE(load_vector_ptr, JPP)
BOOST_FIXTURE_TEST_CASE(test_conversion, JPP)
{
auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/conv.json");
+ BOOST_CHECK_EQUAL(to->postLoadCalled, 1);
BOOST_REQUIRE(to);
BOOST_CHECK_EQUAL(to->bl, true);
BOOST_CHECK_EQUAL(to->flt, 3.14F);
diff --git a/test/testStructures.cpp b/test/testStructures.cpp
index 8305078..469ec37 100644
--- a/test/testStructures.cpp
+++ b/test/testStructures.cpp
@@ -42,6 +42,12 @@ TestObject::persist(Persistence::PersistenceStore & store)
&& STORE_MEMBER(vptr);
}
+void
+TestObject::postLoad()
+{
+ postLoadCalled++;
+}
+
bool
SharedTestObject::persist(Persistence::PersistenceStore & store)
{
diff --git a/test/testStructures.h b/test/testStructures.h
index 666562e..6966052 100644
--- a/test/testStructures.h
+++ b/test/testStructures.h
@@ -39,7 +39,10 @@ struct TestObject : public Persistence::Persistable {
std::unique_ptr<AbsObject> aptr;
std::vector<std::unique_ptr<TestObject>> vptr;
+ unsigned int postLoadCalled {};
+
bool persist(Persistence::PersistenceStore & store) override;
+ void postLoad() override;
};
struct SharedTestObject : public Persistence::Persistable {