From 9307869e3be61354eb6b8b077510cbae9181931d Mon Sep 17 00:00:00 2001 From: Bernd Hentschel <hentschel@vr.rwth-aachen.de> Date: Mon, 25 Jun 2018 08:27:35 +0200 Subject: [PATCH] add test for searching behavior I added a test for the "search outside the default resource path" scenario pointed out by @hoverath in https://devhub.vr.rwth-aachen.de/VR-Group/Project_Phoenix/merge_requests/137#note_18001. That said, this test should only be temporary, because by #447, the resource_root will be gone soon'ish. Then, every resource lookup will test the "search in path" behavior and thus the test becomes obsolete. --- tests/src/test_resource_utils.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/src/test_resource_utils.cpp b/tests/src/test_resource_utils.cpp index 83cde13b..ac8c2a66 100644 --- a/tests/src/test_resource_utils.cpp +++ b/tests/src/test_resource_utils.cpp @@ -30,6 +30,17 @@ #include "phx/resources/types/image.hpp" #include "phx/resources_path.hpp" +namespace ResourceUtilsTest { +void CreateDummyFile(const std::string &file_name) { + std::fstream out_file(file_name.c_str(), std::ios::out); + // force fail test if file could not be created + REQUIRE(out_file.is_open()); +} +void DeleteDummyFile(const std::string &file_name) { + std::remove(file_name.c_str()); +} +} // namespace ResourceUtilsTest + SCENARIO("Resource utils can extract file extensions.", "[phx][phx::ResourceUtils]") { GIVEN("A file name") { @@ -90,9 +101,26 @@ SCENARIO("Resource utils can declarare a file resource.", } } +SCENARIO("Resource utils find file resource outside the original search path", + "[phx][phx::ResourceUtils]") { + GIVEN("A file outside the original resource tree") { + std::string dummy_file = "dummy.txt"; + std::string offset_search_path = "../"; + ResourceUtilsTest::CreateDummyFile(offset_search_path + dummy_file); + + phx::ResourceUtils::AddResourceSearchPath(offset_search_path); + THEN("the file is found and a valid declaration is returned") { + phx::ResourceDeclaration declaration = + phx::ResourceUtils::DeclarationFromFile(dummy_file, {}, false); + CHECK(declaration["file_name"] == offset_search_path + dummy_file); + ResourceUtilsTest::DeleteDummyFile(offset_search_path + dummy_file); + } + } +} + SCENARIO("Resource utils can load a file resource.", "[phx][phx::ResourceUtils]") { - GIVEN("A file name") { + GIVEN("A file name within the original resource tree") { std::string file_name{"textures/splash_progress.png"}; THEN("It can load it") { -- GitLab