mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-07-02 05:35:11 +00:00
28
tests/unit_tests/memory_manager/CMakeLists.txt
Normal file
28
tests/unit_tests/memory_manager/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
# Define project
|
||||
project(MemoryManagerTests VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Define target
|
||||
add_executable(UnitTest_MemoryManager memmgr_test.cpp)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_libraries(UnitTest_MemoryManager GTest::GTest)
|
||||
if (WIN32)
|
||||
target_link_libraries(UnitTest_MemoryManager Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(UnitTest_MemoryManager ${CMAKE_DL_LIBS} rt)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(UnitTest_MemoryManager GTest::GTest Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
# Add the test
|
||||
add_test(NAME UnitTest_MemoryManager COMMAND UnitTest_MemoryManager WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
|
||||
# Execute the test
|
||||
add_custom_command(TARGET UnitTest_MemoryManager POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E env TEST_EXECUTION_MODE=CMake "$<TARGET_FILE:UnitTest_MemoryManager>" --gtest_output=xml:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/UnitTest_MemoryManager.xml
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# Build dependencies
|
||||
add_dependencies(UnitTest_MemoryManager dependency_sdv_components)
|
||||
55
tests/unit_tests/memory_manager/memmgr_test.cpp
Normal file
55
tests/unit_tests/memory_manager/memmgr_test.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <fstream>
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/process_watchdog.h"
|
||||
#include <support/mem_access.h>
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain(int argc, wchar_t* argv[])
|
||||
#else
|
||||
extern "C" int main(int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
CProcessWatchdog watchdog;
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
TEST(MemoryManagerTest, Instantiate)
|
||||
{
|
||||
EXPECT_NE(sdv::core::GetMemMgr(), nullptr);
|
||||
}
|
||||
|
||||
TEST(MemoryManagerTest, Allocate)
|
||||
{
|
||||
sdv::core::IMemoryAlloc* pAlloc = sdv::core::GetMemMgr();
|
||||
ASSERT_NE(pAlloc, nullptr);
|
||||
sdv::pointer<uint8_t> ptr = pAlloc->Allocate(1024 * 1024);
|
||||
ASSERT_TRUE(ptr);
|
||||
EXPECT_EQ(ptr.size(), 1024 * 1024);
|
||||
ptr.reset();
|
||||
ASSERT_FALSE(ptr);
|
||||
}
|
||||
|
||||
TEST(MemoryManagerTest, AllocateSupportFunc)
|
||||
{
|
||||
sdv::pointer<uint32_t> ptr = sdv::core::AllocMem<uint32_t>(1024 * 1024);
|
||||
ASSERT_TRUE(ptr);
|
||||
EXPECT_EQ(ptr.size(), 1024 * 1024);
|
||||
ptr.reset();
|
||||
ASSERT_FALSE(ptr);
|
||||
}
|
||||
|
||||
TEST(MemoryManagerTest, ReallocateSupportFunc)
|
||||
{
|
||||
sdv::pointer<uint32_t> ptr = sdv::core::AllocMem<uint32_t>(1024 * 1024);
|
||||
ASSERT_TRUE(ptr);
|
||||
EXPECT_EQ(ptr.size(), 1024 * 1024);
|
||||
ptr.resize(512 * 1024);
|
||||
EXPECT_EQ(ptr.size(), 512 * 1024);
|
||||
ptr.resize(2048 * 1024);
|
||||
EXPECT_EQ(ptr.size(), 2048 * 1024);
|
||||
ptr.reset();
|
||||
ASSERT_FALSE(ptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user