blob: 3fc9ebdc3841497f7496cdbdca260186d2cd85c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include <gtest/gtest.h>
#include <crepe/util/Log.h>
#include <crepe/api/Config.h>
#include <crepe/api/ResourceManager.h>
using namespace std;
using namespace crepe;
using namespace testing;
class ResourceManagerTest : public Test {
public:
ResourceManager & resman = ResourceManager::get_instance();
Config & cfg = Config::get_instance();
void SetUp() override {
resman.clear();
}
};
TEST_F(ResourceManagerTest, Main) {
// NOTE: there is no way (that I know of) to ensure the last cache call
// allocates the new Sound instance in a different location than the first,
// so this test should be verified manually using these print statements and
// debug trace messages.
cfg.log.level = Log::Level::TRACE;
Asset path1 = "mwe/audio/sfx1.wav";
Asset path2 = "mwe/audio/sfx1.wav";
ASSERT_EQ(path1, path2);
Sound * ptr1 = nullptr;
Sound * ptr2 = nullptr;
{
Log::logf(Log::Level::DEBUG, "Get first sound (constructor call)");
Sound & sound = resman.cache<Sound>(path1);
ptr1 = &sound;
}
{
Log::logf(Log::Level::DEBUG, "Get same sound (NO constructor call)");
Sound & sound = resman.cache<Sound>(path2);
ptr2 = &sound;
}
EXPECT_EQ(ptr1, ptr2);
Log::logf(Log::Level::DEBUG, "Clear cache (destructor call)");
resman.clear();
Log::logf(Log::Level::DEBUG, "Get first sound again (constructor call)");
Sound & sound = resman.cache<Sound>(path1);
}
|