diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-09 23:29:00 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-09 23:29:00 +0100 |
commit | b6b3944e9507f337f77a72ea44b5c0ccba7a2c01 (patch) | |
tree | a487df54853522f973ed987006e787117804b9eb /test/test-assetFactory.cpp | |
parent | Swap messy glmvec wrapper for OpenMesh Point/Normal with real glm::vec and a ... (diff) | |
parent | Move remaining split/plane functions to use library (diff) | |
download | ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.bz2 ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.xz ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.zip |
Merge branch 'model-factory-textures'
Diffstat (limited to 'test/test-assetFactory.cpp')
-rw-r--r-- | test/test-assetFactory.cpp | 48 |
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()); +} |