From: Daniel Karbach Date: Thu, 7 Dec 2017 14:52:37 +0000 (+0100) Subject: test asset loading X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=commitdiff_plain;h=b6e259a227889cc8af26f599bf3b76b6abb6bbd4 test asset loading travis plz --- diff --git a/Makefile b/Makefile index a098252..7d29058 100644 --- a/Makefile +++ b/Makefile @@ -135,10 +135,14 @@ callgrind: $(ASSET_DEP) blobs.profile --dump-instr=yes --simulate-hwpref=yes --simulate-wb=yes \ ./blobs.profile -test: blobs.test +test: blobs.test $(ASSET_DEP) @echo run: blobs.test @./blobs.test +headless-test: blobs.test + @echo run: blobs.test --headless + @./blobs.test --headless + coverage: blobs.cover @echo run: blobs.cover @./blobs.cover @@ -162,7 +166,7 @@ distclean: clean rm -f $(BIN) cachegrind.out.* callgrind.out.* rm -Rf build client-saves saves -.PHONY: all release cover debug profile tests run gdb cachegrind callgrind test coverage codecov lint clean distclean +.PHONY: all release cover debug profile tests run gdb cachegrind callgrind test headless-test coverage codecov lint clean distclean -include $(DEP) diff --git a/src/world/Set.hpp b/src/world/Set.hpp index af4d8a2..ce832ac 100644 --- a/src/world/Set.hpp +++ b/src/world/Set.hpp @@ -25,6 +25,8 @@ public: bool Has(int id) const noexcept { return id < types.size(); } bool Has(const std::string &name) const noexcept { return names.find(name) != names.end(); } + typename std::vector::size_type Size() const noexcept { return types.size(); } + Type &operator [](int id) noexcept { return types[id]; } const Type &operator [](int id) const noexcept { return types[id]; } diff --git a/tst/app/AssetTest.cpp b/tst/app/AssetTest.cpp new file mode 100644 index 0000000..bd067d3 --- /dev/null +++ b/tst/app/AssetTest.cpp @@ -0,0 +1,75 @@ +#include "AssetTest.hpp" + +#include "app/Assets.hpp" +#include "app/init.hpp" + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(blobs::app::test::AssetTest, "headed"); + + +namespace blobs { +namespace app { +namespace test { + +void AssetTest::setUp() { +} + +void AssetTest::tearDown() { +} + + +void AssetTest::testLoadAll() { + Init init(true, 8); + Assets assets; + + CPPUNIT_ASSERT_MESSAGE( + "no resources loaded", + assets.data.resources.Size() > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "no tile types loaded", + assets.data.resources.Size() > 0 + ); + + CPPUNIT_ASSERT_MESSAGE( + "tile texture has no width", + assets.textures.tiles.Width() > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "tile texture has no height", + assets.textures.tiles.Height() > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "tile texture has no depth", + assets.textures.tiles.Depth() > 0 + ); + + CPPUNIT_ASSERT_MESSAGE( + "skin texture has no width", + assets.textures.skins.Width() > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "skin texture has no height", + assets.textures.skins.Height() > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "skin texture has no depth", + assets.textures.skins.Depth() > 0 + ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "large font has wrong family", + std::string("DejaVu Sans"), std::string(assets.fonts.large.FamilyName()) + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "medium font has wrong family", + std::string("DejaVu Sans"), std::string(assets.fonts.medium.FamilyName()) + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "small font has wrong family", + std::string("DejaVu Sans"), std::string(assets.fonts.small.FamilyName()) + ); +} + +} +} +} diff --git a/tst/app/AssetTest.hpp b/tst/app/AssetTest.hpp new file mode 100644 index 0000000..fa158bf --- /dev/null +++ b/tst/app/AssetTest.hpp @@ -0,0 +1,32 @@ +#ifndef BLOBS_TEST_APP_ASSETTEST_HPP_ +#define BLOBS_TEST_APP_ASSETTEST_HPP_ + +#include + + +namespace blobs { +namespace app { +namespace test { + +class AssetTest +: public CppUnit::TestFixture { + +CPPUNIT_TEST_SUITE(AssetTest); + +CPPUNIT_TEST(testLoadAll); + +CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + + void testLoadAll(); + +}; + +} +} +} + +#endif diff --git a/tst/test.cpp b/tst/test.cpp index ff1ce71..3f4ede0 100644 --- a/tst/test.cpp +++ b/tst/test.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -5,12 +6,25 @@ using CppUnit::TestFactoryRegistry; using CppUnit::TextUi::TestRunner; -int main(int, char **) { - TestRunner runner; - TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry(); - runner.addTest(registry.makeTest()); - runner.run(); +int main(int argc, char **argv) { + bool headless = false; + if (argc > 1 && std::strcmp(argv[1], "--headless") == 0) { + headless = true; + } - return 0; + TestRunner runner; + { + TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry(); + runner.addTest(registry.makeTest()); + } + if (!headless) { + TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry("headed"); + runner.addTest(registry.makeTest()); + } + if (runner.run()) { + return 0; + } else { + return 1; + } }