Files
XCEngine/tests/memory/test_memory_manager.cpp
ssdfasd 34c75e7129 feat: 实现Containers、Memory、Threading核心模块及单元测试
- Containers: String, Array, HashMap 容器实现及测试
- Memory: Allocator, LinearAllocator, PoolAllocator, ProxyAllocator, MemoryManager 实现及测试
- Threading: Mutex, SpinLock, ReadWriteLock, Thread, Task, TaskSystem 实现及测试
- 修复Windows平台兼容性: _aligned_malloc, std::hash特化
- 修复构建错误和测试用例问题
2026-03-13 20:37:08 +08:00

45 lines
1.2 KiB
C++

#include <gtest/gtest.h>
#include <XCEngine/Memory/MemoryManager.h>
using namespace XCEngine::Memory;
namespace {
class MemoryTest : public ::testing::Test {
protected:
void SetUp() override {
MemoryManager::Get().Initialize();
}
void TearDown() override {
MemoryManager::Get().Shutdown();
}
};
TEST_F(MemoryTest, GetSystemAllocator_ReturnsValidPointer) {
IAllocator* allocator = MemoryManager::Get().GetSystemAllocator();
ASSERT_NE(allocator, nullptr);
}
TEST_F(MemoryTest, CreateLinearAllocator) {
auto allocator = MemoryManager::Get().CreateLinearAllocator(1024);
ASSERT_NE(allocator, nullptr);
EXPECT_EQ(allocator->GetCapacity(), 1024u);
}
TEST_F(MemoryTest, CreatePoolAllocator) {
auto allocator = MemoryManager::Get().CreatePoolAllocator(64, 100);
ASSERT_NE(allocator, nullptr);
EXPECT_EQ(allocator->GetBlockSize(), 64u);
EXPECT_EQ(allocator->GetTotalBlockCount(), 100u);
EXPECT_EQ(allocator->GetFreeBlockCount(), 100u);
}
TEST_F(MemoryTest, CreateProxyAllocator) {
auto allocator = MemoryManager::Get().CreateProxyAllocator("Test");
ASSERT_NE(allocator, nullptr);
EXPECT_STREQ(allocator->GetName(), "Test");
}
} // namespace