]> git.localhorst.tv Git - blobs.git/commitdiff
test asset loading
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 7 Dec 2017 14:52:37 +0000 (15:52 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 7 Dec 2017 14:52:37 +0000 (15:52 +0100)
travis plz

Makefile
src/world/Set.hpp
tst/app/AssetTest.cpp [new file with mode: 0644]
tst/app/AssetTest.hpp [new file with mode: 0644]
tst/test.cpp

index a09825234ba2fa8e8b2ce0f215a8b17110ab9a43..7d2905819ca111818c54d6f4652e7fb2d760bac2 100644 (file)
--- 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)
 
index af4d8a242959c166b95af639c6413bf8a81ff908..ce832ac06d9cadbe65bc29204db617c3ab46af28 100644 (file)
@@ -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<Type>::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 (file)
index 0000000..bd067d3
--- /dev/null
@@ -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 (file)
index 0000000..fa158bf
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef BLOBS_TEST_APP_ASSETTEST_HPP_
+#define BLOBS_TEST_APP_ASSETTEST_HPP_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+
+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
index ff1ce710c25c80912d4ab90ed2fd18e61a8d75fd..3f4ede00edbad18aa75c05fdd153a681aa65d0b3 100644 (file)
@@ -1,3 +1,4 @@
+#include <cstring>
 #include <cppunit/extensions/TestFactoryRegistry.h>
 #include <cppunit/ui/text/TestRunner.h>
 
@@ -5,12 +6,25 @@ using CppUnit::TestFactoryRegistry;
 using CppUnit::TextUi::TestRunner;
 
 
-int main(int, char **) {
-       TestRunner runner;
-       TestFactoryRegistry &registry = 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 &registry = TestFactoryRegistry::getRegistry();
+               runner.addTest(registry.makeTest());
+       }
+       if (!headless) {
+               TestFactoryRegistry &registry = TestFactoryRegistry::getRegistry("headed");
+               runner.addTest(registry.makeTest());
+       }
 
+       if (runner.run()) {
+               return 0;
+       } else {
+               return 1;
+       }
 }