diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 48baa235626ffec7e4eb963d01dc0a136e186f26..b3333652b9f5e2f245a29dcaf37c199c5d783bdb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -195,7 +195,7 @@ test:windows_nightly:msvc++14.1: conan:linux:clang: stage: conan except: - - shedules + - schedules tags: - CentOS - opengl @@ -214,7 +214,7 @@ conan:linux:clang: cmake:linux:clang: stage: cmake except: - - shedules + - schedules tags: - CentOS - opengl @@ -289,7 +289,7 @@ clear:linux_nightly:clang: conan:linux_nightly:clang: stage: conan only: - - shedules + - schedules tags: - nightly - clang @@ -309,7 +309,7 @@ conan:linux_nightly:clang: cmake:linux_nightly:clang: stage: cmake only: - - shedules + - schedules tags: - nightly - clang diff --git a/cmake/WarningLevels.cmake b/cmake/WarningLevels.cmake index 56a8e549bb1067c10917f306c3ef5e7b68d45396..cfe1929d1499691c9051370dd51170a008947a62 100644 --- a/cmake/WarningLevels.cmake +++ b/cmake/WarningLevels.cmake @@ -34,6 +34,7 @@ set(WARNING_LEVELS_RWTH_CLANG -Wno-weak-vtables -Wno-exit-time-destructors -Wno-global-constructors + -Wno-padded ) set(WARNING_LEVELS_RWTH_GCC diff --git a/cmake/suppress_warnings.hpp.in b/cmake/suppress_warnings.hpp.in index f245a38cd380b356ca26bdcbf0cadf7a247d0ea5..ddd2a44b761befa44ce4e8096990ea918503ce1b 100644 --- a/cmake/suppress_warnings.hpp.in +++ b/cmake/suppress_warnings.hpp.in @@ -42,9 +42,6 @@ _Pragma("clang diagnostic ignored \"-Wnon-virtual-dtor\"") \ _Pragma("clang diagnostic ignored \"-Wzero-as-null-pointer-constant\"") \ _Pragma("clang diagnostic ignored \"-Wextra-semi\"") -#define SUPPRESS_WARNINGS_BEGIN_PADDED \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wpadded\"") #define SUPPRESS_WARNINGS_BEGIN_MISSING_DECLARATIONS \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wmissing-prototypes\"") @@ -52,7 +49,6 @@ #elif defined _MSC_VER #define SUPPRESS_WARNINGS_BEGIN __pragma(warning(push, 0)); -#define SUPPRESS_WARNINGS_BEGIN_PADDED __pragma(warning(push)); #define SUPPRESS_WARNINGS_BEGIN_MISSING_DECLARATIONS __pragma(warning(push)); #define SUPPRESS_WARNINGS_END __pragma(warning(pop)); @@ -70,9 +66,6 @@ _Pragma("GCC diagnostic ignored \"-Wextra\"") \ _Pragma("GCC diagnostic ignored \"-Wmissing-declarations\"") \ _Pragma("GCC diagnostic ignored \"-Wpadded\"") -#define SUPPRESS_WARNINGS_BEGIN_PADDED \ - _Pragma("GCC diagnostic push") \ - _Pragma("GCC diagnostic ignored \"-Wpadded\"") #define SUPPRESS_WARNINGS_BEGIN_MISSING_DECLARATIONS \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wmissing-declarations\"") diff --git a/demos/viewer/src/viewer_system.hpp b/demos/viewer/src/viewer_system.hpp index d425eec4e77fd65b9705ec5e6fb0b9f0823ed149..dcb4d7168a8d7c85fa9139653846d83a9ef33ab4 100644 --- a/demos/viewer/src/viewer_system.hpp +++ b/demos/viewer/src/viewer_system.hpp @@ -31,8 +31,6 @@ #include "phx/core/frame_timer.hpp" #include "phx/core/system.hpp" -SUPPRESS_WARNINGS_BEGIN_PADDED - class ViewerSystem : public phx::System { public: ViewerSystem() = delete; @@ -58,6 +56,4 @@ class ViewerSystem : public phx::System { explicit ViewerSystem(phx::Engine* engine); }; -SUPPRESS_WARNINGS_END - #endif // DEMOS_VIEWER_SRC_VIEWER_SYSTEM_HPP_ diff --git a/library/phx/core/engine.hpp b/library/phx/core/engine.hpp index e13934b7390e5c2d4e674c7f61ac261fa30ae950..fabc9c0bd93fe3fa98a91c9c1dd28950dc96b83c 100644 --- a/library/phx/core/engine.hpp +++ b/library/phx/core/engine.hpp @@ -43,15 +43,13 @@ SUPPRESS_WARNINGS_END #include "phx/core/frame_timer.hpp" #include "phx/core/scene.hpp" #include "phx/core/system.hpp" +#include "phx/export.hpp" #include "phx/scripting/behavior.hpp" #include "phx/utility/aspects/loggable.hpp" #include "phx/utility/orderable_list.hpp" -#include "phx/export.hpp" namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED - class PHOENIX_EXPORT Engine final : public Loggable { public: Engine(); @@ -165,8 +163,6 @@ std::vector<std::tuple<Components*...>> Engine::GetFirstComponentsMany() const { return scene_->GetFirstComponentsMany<Components...>(); } -SUPPRESS_WARNINGS_END - } // namespace phx #endif // LIBRARY_PHX_CORE_ENGINE_HPP_ diff --git a/library/phx/input/input_system.hpp b/library/phx/input/input_system.hpp index 0d4d4ccde4b8eda65f5c85250ec495e217e4b3cf..9862ea78119438869c1e37162909df8c9faba169 100644 --- a/library/phx/input/input_system.hpp +++ b/library/phx/input/input_system.hpp @@ -73,20 +73,12 @@ class PHOENIX_EXPORT InputSystem : public System { void UpdateSDLEvents(); - // TODO(@tvierjahn) check if Wpadded is here only emitted by some clang - // versions. - // There will be only one input system.Padding will not waste - // significant memory - SUPPRESS_WARNINGS_BEGIN_PADDED - boost::signals2::signal<void()> quit_signal_; boost::signals2::signal<void(char)> key_press_signal_; boost::signals2::signal<void(char)> key_release_signal_; boost::signals2::signal<void(int, int)> mouse_move_signal_; boost::signals2::signal<void(unsigned int)> mouse_press_signal_; boost::signals2::signal<void(unsigned int)> mouse_release_signal_; - - SUPPRESS_WARNINGS_END }; } // namespace phx diff --git a/library/phx/input/openvr_controller_behavior.hpp b/library/phx/input/openvr_controller_behavior.hpp index eec3b6cb3b87874a450b4ee9801a770396abd1a8..9f8ce400b7a42d04937543ca2daf4df505361814 100644 --- a/library/phx/input/openvr_controller_behavior.hpp +++ b/library/phx/input/openvr_controller_behavior.hpp @@ -30,7 +30,6 @@ #include "phx/scripting/behavior.hpp" namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED class PHOENIX_EXPORT OpenVRControllerBehavior : public Behavior { public: void OnUpdate() override; @@ -41,7 +40,6 @@ class PHOENIX_EXPORT OpenVRControllerBehavior : public Behavior { private: VRController::ControllerSide side_ = VRController::LEFT_CONTROLLER; }; -SUPPRESS_WARNINGS_END } // namespace phx #endif // LIBRARY_PHX_INPUT_OPENVR_CONTROLLER_BEHAVIOR_HPP_ diff --git a/library/phx/rendering/auxiliary/splash_screen.hpp b/library/phx/rendering/auxiliary/splash_screen.hpp index 2a9007e7b2a870d788a5492fef07de605364332a..56faa94f741e3296f50dc891a5fe0f7d92428bbd 100644 --- a/library/phx/rendering/auxiliary/splash_screen.hpp +++ b/library/phx/rendering/auxiliary/splash_screen.hpp @@ -38,7 +38,6 @@ namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED class PHOENIX_EXPORT SplashScreen : public System { public: SplashScreen() = delete; @@ -65,7 +64,6 @@ class PHOENIX_EXPORT SplashScreen : public System { std::mutex load_progress_mutex_; float load_progress_ = 0.f; }; -SUPPRESS_WARNINGS_END } // namespace phx diff --git a/library/phx/rendering/backend/render_target.hpp b/library/phx/rendering/backend/render_target.hpp index be07213d041ca9e41aec02c17b72d5e00f56090f..bed8eda040f06f9c5916be24de53b12962be7908 100644 --- a/library/phx/rendering/backend/render_target.hpp +++ b/library/phx/rendering/backend/render_target.hpp @@ -43,7 +43,6 @@ SUPPRESS_WARNINGS_END namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED class PHOENIX_EXPORT RenderTarget : public Component, public gl::framebuffer { public: RenderTarget() = delete; @@ -69,7 +68,6 @@ class PHOENIX_EXPORT RenderTarget : public Component, public gl::framebuffer { glm::uvec2 dimensions_; }; -SUPPRESS_WARNINGS_END } // namespace phx diff --git a/library/phx/rendering/backend/shader_program.hpp b/library/phx/rendering/backend/shader_program.hpp index 93c6d7a56319bc436740a4e938fba132490a00ec..679130847e0cc4b611c486eb881fff57b752d819 100644 --- a/library/phx/rendering/backend/shader_program.hpp +++ b/library/phx/rendering/backend/shader_program.hpp @@ -37,19 +37,15 @@ SUPPRESS_WARNINGS_END #include "gl/program.hpp" #include "gl/shader.hpp" +#include "phx/export.hpp" #include "phx/rendering/components/transform.hpp" #include "phx/rendering/render_passes/render_pass.hpp" +#include "phx/resources/resource_pointer.hpp" #include "phx/resources/types/mesh.hpp" #include "phx/resources/types/shader_source.hpp" -#include "phx/resources/resource_pointer.hpp" -#include "phx/export.hpp" namespace phx { -// TODO(@all) Will padding waste too much memory? How many shaders will we -// have? -SUPPRESS_WARNINGS_BEGIN_PADDED - class PHOENIX_EXPORT ShaderProgram : public gl::program { public: enum ShaderChannel { @@ -71,7 +67,7 @@ class PHOENIX_EXPORT ShaderProgram : public gl::program { ShaderProgram& operator=(ShaderProgram&&) = default; bool SetShader(ShaderChannel channel, - ResourcePointer<ShaderSource> shader_source); + ResourcePointer<ShaderSource> shader_source); template <typename T> void SetUniform(const std::string& name, T value) { @@ -91,8 +87,6 @@ class PHOENIX_EXPORT ShaderProgram : public gl::program { std::array<ShaderHandle, MAX_SHADER_CHANNEL> shaders_; }; -SUPPRESS_WARNINGS_END - } // namespace phx #endif // LIBRARY_PHX_RENDERING_BACKEND_SHADER_PROGRAM_HPP_ diff --git a/library/phx/rendering/components/light.hpp b/library/phx/rendering/components/light.hpp index e8abc925810b1d63db905fad6a885e2843d2cb90..9c0403289ad1584c5ad8463b233cb6a001917679 100644 --- a/library/phx/rendering/components/light.hpp +++ b/library/phx/rendering/components/light.hpp @@ -36,8 +36,6 @@ SUPPRESS_WARNINGS_END namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED - class PHOENIX_EXPORT Light final : public Component { public: enum class Type { @@ -80,8 +78,6 @@ class PHOENIX_EXPORT Light final : public Component { float spot_angle_ = 45.0f; // Only for spot lights. }; -SUPPRESS_WARNINGS_END - } // namespace phx #endif // LIBRARY_PHX_RENDERING_COMPONENTS_LIGHT_HPP_ diff --git a/library/phx/rendering/render_passes/geometry_pass.hpp b/library/phx/rendering/render_passes/geometry_pass.hpp index bd2edb0c40e650bf294feac2a7834babe3c53570..0b2104f103ee0ffa9a0ce2afd147d89630c36862 100644 --- a/library/phx/rendering/render_passes/geometry_pass.hpp +++ b/library/phx/rendering/render_passes/geometry_pass.hpp @@ -36,6 +36,7 @@ SUPPRESS_WARNINGS_BEGIN #include "gl/vertex_array.hpp" SUPPRESS_WARNINGS_END +#include "phx/export.hpp" #include "phx/rendering/backend/render_target.hpp" #include "phx/rendering/backend/shader_program.hpp" #include "phx/rendering/components/light.hpp" @@ -43,14 +44,11 @@ SUPPRESS_WARNINGS_END #include "phx/rendering/components/projection.hpp" #include "phx/rendering/components/transform.hpp" #include "phx/rendering/render_passes/render_pass.hpp" -#include "phx/resources/types/mesh.hpp" #include "phx/resources/resource_manager.hpp" -#include "phx/export.hpp" +#include "phx/resources/types/mesh.hpp" namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED - class PHOENIX_EXPORT GeometryPass : public RenderPass { public: explicit GeometryPass(RenderTarget* render_target); @@ -87,8 +85,6 @@ class PHOENIX_EXPORT GeometryPass : public RenderPass { bool IsValid() const; private: - // TODO(@all) Will padding waste too much memory? - SUPPRESS_WARNINGS_BEGIN_PADDED struct RenderingResource { RenderingResource() = default; RenderingResource(const RenderingResource&) = delete; @@ -107,7 +103,6 @@ class PHOENIX_EXPORT GeometryPass : public RenderPass { unsigned int vertex_buffer_size; unsigned int index_buffer_size; }; - SUPPRESS_WARNINGS_END void SetUpShaders(); void CreateRenderingResource(); @@ -136,8 +131,6 @@ class PHOENIX_EXPORT GeometryPass : public RenderPass { RenderTarget* render_target_; }; -SUPPRESS_WARNINGS_END - } // namespace phx #endif // LIBRARY_PHX_RENDERING_RENDER_PASSES_GEOMETRY_PASS_HPP_ diff --git a/library/phx/resources/loaders/assimp_model_loader.hpp b/library/phx/resources/loaders/assimp_model_loader.hpp index 9f5abd2073008c220b8b1aea02d50a0cc2b3b5b6..5b7777567c1c0a907194c4866ae77979b001134f 100644 --- a/library/phx/resources/loaders/assimp_model_loader.hpp +++ b/library/phx/resources/loaders/assimp_model_loader.hpp @@ -39,16 +39,15 @@ SUPPRESS_WARNINGS_BEGIN SUPPRESS_WARNINGS_END #include "phx/export.hpp" -#include "phx/resources/types/material.hpp" -#include "phx/resources/types/mesh.hpp" -#include "phx/resources/types/model.hpp" #include "phx/resources/resource_declaration.hpp" #include "phx/resources/resource_load_strategy.hpp" #include "phx/resources/resource_pointer.hpp" +#include "phx/resources/types/material.hpp" +#include "phx/resources/types/mesh.hpp" +#include "phx/resources/types/model.hpp" namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED class PHOENIX_EXPORT AssimpModelLoader final : public ResourceLoadStrategy { public: AssimpModelLoader(); @@ -114,7 +113,6 @@ class PHOENIX_EXPORT AssimpModelLoader final : public ResourceLoadStrategy { int last_material_index_ = kInvalidMaterialIndex; std::function<void(float)> on_progress_update_callback_; }; -SUPPRESS_WARNINGS_END template <typename FileSourceType> std::vector<glm::vec3> phx::AssimpModelLoader::LoadVectorData( diff --git a/library/phx/resources/resource_utils.cpp b/library/phx/resources/resource_utils.cpp index e8e82fcb5356defa3988ae2696281f75a7054cc9..3804fae89b37f689c34763a38e47933942da29df 100644 --- a/library/phx/resources/resource_utils.cpp +++ b/library/phx/resources/resource_utils.cpp @@ -22,13 +22,41 @@ #include "phx/resources/resource_utils.hpp" #include <algorithm> +#include <cassert> +#include <fstream> #include <locale> #include <string> +#include <vector> + +#include "boost/filesystem.hpp" #include "phx/resources/resource_manager.hpp" #include "phx/resources_path.hpp" namespace phx { +namespace { +std::vector<std::string> default_resource_search_paths = { + {std::string("./"), resources_root}}; +} + +std::vector<std::string> ResourceUtils::resource_search_paths_{ + default_resource_search_paths}; + +void ResourceUtils::AddResourceSearchPath(const std::string& path_to_add) { + assert(!path_to_add.empty()); + auto p = (path_to_add.back() == '/' ? path_to_add + : path_to_add + std::string("/")); + resource_search_paths_.push_back(p); +} + +void ResourceUtils::ResetResourceSearchPath() { + resource_search_paths_ = default_resource_search_paths; +} + +std::vector<std::string> ResourceUtils::GetResourceSearchPath() { + return resource_search_paths_; +} + ResourceDeclaration ResourceUtils::DeclarationFromFile( const std::string& file_name, nlohmann::json additional_info /*= {}*/, bool absolute_path /*= false*/) { @@ -36,7 +64,7 @@ ResourceDeclaration ResourceUtils::DeclarationFromFile( if (absolute_path) { declaration["file_name"] = file_name; } else { - declaration["file_name"] = resources_root + file_name; + declaration["file_name"] = FindFileInSearchPath(file_name); } for (nlohmann::json::iterator it = additional_info.begin(); it != additional_info.end(); ++it) { @@ -52,4 +80,12 @@ std::string ResourceUtils::ExtractFileExtension(const std::string& file_name) { return extension; } +std::string ResourceUtils::FindFileInSearchPath(const std::string& file_name) { + for (auto& entry : resource_search_paths_) { + auto full_name = entry + file_name; + if (boost::filesystem::exists(full_name.c_str())) return full_name; + } + return ""; +} + } // namespace phx diff --git a/library/phx/resources/resource_utils.hpp b/library/phx/resources/resource_utils.hpp index 8f18bc1fa3c17ae0db1dc93a83ed4aebab8d8236..95cba49f82f2601230288d4e65a948b376d436f0 100644 --- a/library/phx/resources/resource_utils.hpp +++ b/library/phx/resources/resource_utils.hpp @@ -26,25 +26,35 @@ #include <map> #include <memory> #include <string> +#include <vector> #include "json.hpp" #include "phx/core/logger.hpp" +#include "phx/export.hpp" #include "phx/resources/resource_declaration.hpp" #include "phx/resources/resource_load_strategy.hpp" #include "phx/resources/resource_manager.hpp" #include "phx/resources/resource_pointer.hpp" #include "phx/utility/aspects/singleton.hpp" -#include "phx/export.hpp" namespace phx { /** * The ResourceUtils class contains static convenience methods to simplify - * interactions with the resource system. It should never hold any state. + * interactions with the resource system. It also holds a user configurable + * resource search path. When operating on a relative file name, it will + * search all entries in the search path and return/load the first file that + * matches the given file name. Per default, the resource search path + * contains the local directory and phx::resources_root. */ class PHOENIX_EXPORT ResourceUtils final { public: + static void AddResourceSearchPath(const std::string& path_to_add); + static void ResetResourceSearchPath(); + static std::vector<std::string> GetResourceSearchPath(); + static std::string ExtractFileExtension(const std::string& file_name); + static ResourceDeclaration DeclarationFromFile( const std::string& file_name, nlohmann::json additional_info = {}, bool absolute_path = false); @@ -59,6 +69,11 @@ class PHOENIX_EXPORT ResourceUtils final { res_ptr.Load(); return res_ptr; } + + private: + static std::string FindFileInSearchPath(const std::string& file_name); + + static std::vector<std::string> resource_search_paths_; }; } // namespace phx diff --git a/library/phx/scripting/behavior_system.hpp b/library/phx/scripting/behavior_system.hpp index 11a95e0631e66ec4322c82e83dba5508d32fd967..e723ab04016c3b1aa9369dd78fb0c9079a050a15 100644 --- a/library/phx/scripting/behavior_system.hpp +++ b/library/phx/scripting/behavior_system.hpp @@ -31,8 +31,6 @@ namespace phx { -SUPPRESS_WARNINGS_BEGIN_PADDED - class PHOENIX_EXPORT BehaviorSystem : public System { public: BehaviorSystem() = delete; @@ -50,8 +48,6 @@ class PHOENIX_EXPORT BehaviorSystem : public System { explicit BehaviorSystem(Engine* engine); }; -SUPPRESS_WARNINGS_END - } // namespace phx #endif // LIBRARY_PHX_SCRIPTING_BEHAVIOR_SYSTEM_HPP_ diff --git a/library/phx/utility/stream_helpers.hpp b/library/phx/utility/stream_helpers.hpp index c464887c49b75208f9433a0181e50e5b2e4046db..89902b6cd7f208dc3f746915c003be3f36d55c51 100644 --- a/library/phx/utility/stream_helpers.hpp +++ b/library/phx/utility/stream_helpers.hpp @@ -41,7 +41,6 @@ SUPPRESS_WARNINGS_END // namespace like e.g. phx, leaving them in global namespace would not work namespace glm { -SUPPRESS_WARNINGS_BEGIN_PADDED class PHOENIX_EXPORT PhxStreamSettings { public: explicit PhxStreamSettings(std::ostream& stream); @@ -57,7 +56,6 @@ class PHOENIX_EXPORT PhxStreamSettings { std::streamsize stream_precision_; std::ios::fmtflags stream_flags_; }; -SUPPRESS_WARNINGS_END PHOENIX_EXPORT std::ostream& operator<<(std::ostream& out, const glm::vec2& vec); diff --git a/tests/src/mocks/openvr_mock.hpp b/tests/src/mocks/openvr_mock.hpp index 73523f87a2456e4dcec7a786b70488dbaf4f5390..2b0d15f92f91a2acb820db4f3f1fd871ba923aeb 100644 --- a/tests/src/mocks/openvr_mock.hpp +++ b/tests/src/mocks/openvr_mock.hpp @@ -252,8 +252,6 @@ class OPENVR_MOCK_EXPORT IVRRenderModelsMock : public IVRRenderModels { } // namespace vr -SUPPRESS_WARNINGS_BEGIN_PADDED - class OPENVR_MOCK_EXPORT OpenVRMock { public: OpenVRMock() @@ -358,8 +356,6 @@ class OPENVR_MOCK_EXPORT OpenVRMock { vr::IVRRenderModelsMock* ivr_render_models_mock_; }; -SUPPRESS_WARNINGS_END - extern OPENVR_MOCK_EXPORT OpenVRMock openvr_mock; #define OPENVR_MOCK_ALLOW_ANY_CALL \ diff --git a/tests/src/test_resource_utils.cpp b/tests/src/test_resource_utils.cpp index d2b0a9bb82b807735219581322600fec1e1c6e26..1da8fcab9e8789cba8a6a11d1a0261b45dc8aa36 100644 --- a/tests/src/test_resource_utils.cpp +++ b/tests/src/test_resource_utils.cpp @@ -20,15 +20,27 @@ // limitations under the License. //------------------------------------------------------------------------------ +#include <fstream> #include <string> #include "catch/catch.hpp" -#include "phx/resources/types/image.hpp" #include "phx/resources/resource_declaration.hpp" #include "phx/resources/resource_utils.hpp" +#include "phx/resources/types/image.hpp" #include "phx/resources_path.hpp" +namespace { +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 + SCENARIO("Resource utils can extract file extensions.", "[phx][phx::ResourceUtils]") { GIVEN("A file name") { @@ -56,17 +68,19 @@ SCENARIO("Resource utils can declarare a file resource.", GIVEN("A file name with absolute path") { std::string file_name{"C:/some_path/to/file.34.ext"}; - THEN("It can declare it") { + THEN("we get a declaration with a valid (unmodified) file name") { phx::ResourceDeclaration declaration = phx::ResourceUtils::DeclarationFromFile(file_name, {}, true); REQUIRE(declaration["TYPE"] == ".ext"); REQUIRE(declaration["file_name"] == file_name); } } - GIVEN("A file name with relative path") { - std::string file_name{"file.png"}; + GIVEN("A file name and a search path") { + std::string file_name{"textures/splash_progress.png"}; - THEN("It can declare it") { + THEN( + "we get a declaration with a valid file name that has been pre-pended " + "by the first hit in the search path") { phx::ResourceDeclaration declaration = phx::ResourceUtils::DeclarationFromFile(file_name); REQUIRE(declaration["TYPE"] == ".png"); @@ -74,11 +88,11 @@ SCENARIO("Resource utils can declarare a file resource.", } } GIVEN("Additional key, value pairs are provided") { - std::string file_name{"file.png"}; + std::string file_name{"textures/splash_progress.png"}; std::string key = "some_key"; int value = 42; - THEN("these are in the resulting declaration") { + THEN("the resulting declaration contains them") { phx::ResourceDeclaration declaration = phx::ResourceUtils::DeclarationFromFile(file_name, {{key, value}}, false); @@ -87,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 = "../"; + ::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); + ::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") { diff --git a/tests/test_utilities/approx.hpp b/tests/test_utilities/approx.hpp index f09bbcaaba026bf7bad7ccfeaf8468dfe4ba3e1b..bfd3956d4824c5a64936d39a9ceb4c35922519c6 100644 --- a/tests/test_utilities/approx.hpp +++ b/tests/test_utilities/approx.hpp @@ -38,8 +38,6 @@ SUPPRESS_WARNINGS_END namespace test_utilities { -SUPPRESS_WARNINGS_BEGIN_PADDED - template <typename T> class Approx { public: @@ -76,8 +74,6 @@ class Approx { const T& value_; }; -SUPPRESS_WARNINGS_END - } // namespace test_utilities namespace Catch { diff --git a/tests/test_utilities/log_capture.hpp b/tests/test_utilities/log_capture.hpp index ba70a17190eb1d0c9f1ba7da9b9cc2cea32457cf..aa0e5dddec6f8ee823877b6e032eafe98b81cf5b 100644 --- a/tests/test_utilities/log_capture.hpp +++ b/tests/test_utilities/log_capture.hpp @@ -34,8 +34,6 @@ namespace test_utilities { -SUPPRESS_WARNINGS_BEGIN_PADDED - class LogCapture : public spdlog::sinks::sink { public: void log(const spdlog::details::log_msg& msg) override; @@ -49,8 +47,6 @@ class LogCapture : public spdlog::sinks::sink { std::stringstream log_stream_; }; -SUPPRESS_WARNINGS_END - } // namespace test_utilities namespace Catch {