-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathresource_loader_test.cpp
More file actions
65 lines (51 loc) · 1.94 KB
/
Copy pathresource_loader_test.cpp
File metadata and controls
65 lines (51 loc) · 1.94 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <gtest/gtest.h>
#include "../src/core/root_node.h"
#include "../src/resource/render_resource.h"
#include <filesystem>
#include <memory>
#include <string>
#include <vector>
namespace fs = std::filesystem;
namespace {
const std::string kResourcesDir = VP_RESOURCES_DIR;
// 共享 RootNode(持有 GL + Skia 上下文),避免每个用例重复初始化。
class ResourceLoaderTest : public ::testing::Test {
protected:
static void SetUpTestSuite() {
root_ = new vp::RootNode();
ASSERT_TRUE(root_->init()) << "failed to init RootNode (GL context required)";
}
static void TearDownTestSuite() {
delete root_;
root_ = nullptr;
}
static std::vector<std::string> scanResourceDirs() {
std::vector<std::string> dirs;
if (!fs::exists(kResourcesDir))
return dirs;
for (const auto &entry : fs::directory_iterator(kResourcesDir)) {
if (entry.is_directory() && fs::exists(entry.path() / "config.json"))
dirs.push_back(entry.path().string());
}
return dirs;
}
static vp::RootNode *root_;
};
vp::RootNode *ResourceLoaderTest::root_ = nullptr;
// 测试资源目录存在且至少有一个特效包。
TEST_F(ResourceLoaderTest, ResourcesDirHasEffects) {
ASSERT_TRUE(fs::exists(kResourcesDir)) << "resources dir missing: " << kResourcesDir;
auto dirs = scanResourceDirs();
EXPECT_FALSE(dirs.empty()) << "no effect package found under " << kResourcesDir;
}
// 逐个加载每个特效包,全部应成功并带非空 id。
TEST_F(ResourceLoaderTest, LoadAllEffectPackages) {
auto dirs = scanResourceDirs();
ASSERT_FALSE(dirs.empty());
for (const auto &dir : dirs) {
auto resource = std::make_unique<vp::RenderResource>(root_);
EXPECT_TRUE(resource->loadFromFolder(dir)) << "failed to load: " << dir;
EXPECT_FALSE(resource->getId().empty()) << "empty id for: " << dir;
}
}
} // namespace