Loading [MathJax]/jax/output/HTML-CSS/config.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resources.cpp
1#include <Core/Resources/Resources.hpp>
2#include <catch2/catch_test_macros.hpp>
3
4#include <Core/Utils/StdFilesystem.hpp>
5namespace fs = ::std::filesystem;
6
7int dummy() {
8 return 42;
9}
10TEST_CASE( "Core/Resources", "[unittests][Core]" ) {
11 using namespace Ra::Core::Resources;
12 auto radiumResourcesPath = getRadiumResourcesPath();
13 auto radiumPluginPath = getRadiumPluginsPath();
14 auto basePath = getBasePath();
15 auto baseResourcesPath = getResourcesPath();
16 auto baseResourcesPath1 =
17 getResourcesPath( reinterpret_cast<void*>( getRadiumResourcesPath ), "Resources/Radium" );
18 auto baseResourcesPath2 = getResourcesPath( reinterpret_cast<void*>( dummy ), "" );
19 auto baseResourcesPath3 = getResourcesPath( nullptr, "" );
20 auto baseResourcesPath4 = getResourcesPath( nullptr, "hopeYouDontHaveAPathWithThisName" );
21
22 std::cout << radiumResourcesPath.value_or( "not found" ) << "\n"
23 << radiumPluginPath.value_or( "not found" ) << "\n"
24 << basePath.value_or( "not found" ) << "\n"
25 << baseResourcesPath.value_or( "not found" ) << "\n"
26 << baseResourcesPath1.value_or( "not found" ) << "\n"
27 << baseResourcesPath2.value_or( "not found" ) << "\n";
28
29 REQUIRE( baseResourcesPath1 == radiumResourcesPath );
30 REQUIRE( baseResourcesPath2 == basePath );
31 REQUIRE( baseResourcesPath2 == baseResourcesPath3 );
32 REQUIRE( !baseResourcesPath4 );
33
34 auto defaultDataPath = getDataPath();
35 REQUIRE( defaultDataPath == fs::current_path().string() );
36
37 pushDataPath( "data/tmp/foo/" );
38 pushDataPath( "data/tmp/bar/" );
39 auto currentDataPath = getDataPath();
40 REQUIRE( currentDataPath == "data/tmp/bar/" );
41 currentDataPath = popDataPath();
42 REQUIRE( currentDataPath == "data/tmp/bar/" );
43 currentDataPath = getDataPath();
44 REQUIRE( currentDataPath == "data/tmp/foo/" );
46 currentDataPath = getDataPath();
47 REQUIRE( currentDataPath == fs::current_path().string() );
48 fs::remove( "data/tmp/foo/" );
49 fs::remove( "data/tmp/bar/" );
50 fs::remove( "data/tmp/" );
51}
Resources paths, plugins paths and data paths management for Radium.
Definition Resources.cpp:11
std::string getDataPath()
Get the current data path.
Definition Resources.cpp:68
std::string popDataPath()
Pop the current data path.
Definition Resources.cpp:73
optional< std::string > getRadiumPluginsPath()
Get the path of Radium embedded plugins.
Definition Resources.cpp:42
optional< std::string > getBasePath()
this one is always found, use optional for consistency ?
Definition Resources.cpp:51
void pushDataPath(std::string datapath)
Push a new data path.
Definition Resources.cpp:80
optional< std::string > getResourcesPath(void *symbol, const std::string &pattern)
Search for general resource path.
Definition Resources.cpp:55
optional< std::string > getRadiumResourcesPath()
Get the path of Radium internal resources.
Definition Resources.cpp:33