feat(Resources): Add ResourcePackage system for asset bundling
- Implement ResourcePackageBuilder for creating .xcp packages - Implement ResourcePackage for reading packaged assets - Add unit tests for package builder and package reader
This commit is contained in:
@@ -21,6 +21,7 @@ set(RESOURCES_TEST_SOURCES
|
||||
test_audio_loader.cpp
|
||||
test_shader_loader.cpp
|
||||
test_material_loader.cpp
|
||||
test_resource_package.cpp
|
||||
)
|
||||
|
||||
add_executable(xcengine_resources_tests ${RESOURCES_TEST_SOURCES})
|
||||
|
||||
75
tests/Resources/test_resource_package.cpp
Normal file
75
tests/Resources/test_resource_package.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <XCEngine/Resources/ResourcePackage.h>
|
||||
#include <XCEngine/Containers/Array.h>
|
||||
#include <XCEngine/Core/Types.h>
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
using namespace XCEngine::Containers;
|
||||
using namespace XCEngine::Core;
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(ResourcePackageBuilder, DefaultConstructor) {
|
||||
ResourcePackageBuilder builder;
|
||||
EXPECT_TRUE(builder.GetOutputPath().Empty());
|
||||
EXPECT_EQ(builder.GetProgress(), 0.0f);
|
||||
}
|
||||
|
||||
TEST(ResourcePackageBuilder, SetOutputPath) {
|
||||
ResourcePackageBuilder builder;
|
||||
builder.SetOutputPath("test.pkg");
|
||||
EXPECT_EQ(builder.GetOutputPath(), "test.pkg");
|
||||
}
|
||||
|
||||
TEST(ResourcePackageBuilder, AddFile) {
|
||||
ResourcePackageBuilder builder;
|
||||
builder.SetOutputPath("test.pkg");
|
||||
|
||||
bool result = builder.AddFile("nonexistent.txt", "test.txt");
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(ResourcePackageBuilder, BuildWithoutFiles) {
|
||||
ResourcePackageBuilder builder;
|
||||
builder.SetOutputPath("test.pkg");
|
||||
|
||||
bool result = builder.Build();
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(ResourcePackage, DefaultConstructor) {
|
||||
ResourcePackage pkg;
|
||||
EXPECT_FALSE(pkg.IsValid());
|
||||
}
|
||||
|
||||
TEST(ResourcePackage, OpenInvalidPath) {
|
||||
ResourcePackage pkg;
|
||||
bool result = pkg.Open("invalid/path/package.pkg");
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_FALSE(pkg.IsValid());
|
||||
}
|
||||
|
||||
TEST(ResourcePackage, Exists) {
|
||||
ResourcePackage pkg;
|
||||
EXPECT_FALSE(pkg.Exists("test.txt"));
|
||||
}
|
||||
|
||||
TEST(ResourcePackage, GetSize) {
|
||||
ResourcePackage pkg;
|
||||
EXPECT_EQ(pkg.GetSize("test.txt"), 0u);
|
||||
}
|
||||
|
||||
TEST(ResourcePackage, Read) {
|
||||
ResourcePackage pkg;
|
||||
Array<XCEngine::Core::uint8> data = pkg.Read("test.txt");
|
||||
EXPECT_EQ(data.Size(), 0u);
|
||||
}
|
||||
|
||||
TEST(ResourcePackage, Enumerate) {
|
||||
ResourcePackage pkg;
|
||||
Array<String> files(10);
|
||||
pkg.Enumerate("*.txt", files);
|
||||
EXPECT_EQ(files.Size(), 0u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user