summaryrefslogtreecommitdiff
path: root/test/test-assetFactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-assetFactory.cpp')
-rw-r--r--test/test-assetFactory.cpp48
1 files changed, 46 insertions, 2 deletions
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());
+}