Add unit tests for mimir::Region
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
@@ -41,3 +41,5 @@ install(
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include/mimir
|
||||
)
|
||||
|
||||
add_subdirectory(tests)
|
||||
|
||||
28
tests/CMakeLists.txt
Normal file
28
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
# ----====---- GoogleTest ----====---
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
# ----====---- End: GoogleTest ----====---
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_executable(
|
||||
mimir_test
|
||||
"region_test.cpp"
|
||||
)
|
||||
target_link_libraries(
|
||||
mimir_test
|
||||
GTest::gtest_main
|
||||
mimir
|
||||
)
|
||||
|
||||
target_include_directories(mimir_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(mimir_test)
|
||||
55
tests/region_test.cpp
Normal file
55
tests/region_test.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "mimir.h"
|
||||
|
||||
void writeData(std::byte* dest, size_t count, int seed)
|
||||
{
|
||||
for (int i = 0; i < count; i++) {
|
||||
dest[i] = std::byte((seed * 3162 + i * 63163) % 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkData(std::byte* src, size_t count, int seed)
|
||||
{
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (src[i] != std::byte((seed * 3162 + i * 63163) % 0xff)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(Mimir_Region, Uninitialized) {
|
||||
mimir::init();
|
||||
mimir::Region region;
|
||||
EXPECT_TRUE(region.getAddress() == nullptr);
|
||||
EXPECT_TRUE(region.getMaxSize() == 0);
|
||||
EXPECT_TRUE(region.getSize() == 0);
|
||||
}
|
||||
|
||||
TEST(Mimir_Region, Resizing)
|
||||
{
|
||||
mimir::init();
|
||||
mimir::Region region;
|
||||
|
||||
EXPECT_TRUE(region.init(1 << 10ULL));
|
||||
EXPECT_NE(region.getAddress(), nullptr);
|
||||
EXPECT_GT(region.getMaxSize(), 0);
|
||||
EXPECT_EQ(region.getSize(), 0);
|
||||
EXPECT_TRUE(region.resize(0));
|
||||
EXPECT_EQ(region.getSize(), 0);
|
||||
EXPECT_FALSE(region.resize(1 << 20ULL));
|
||||
EXPECT_EQ(region.getSize(), 0);
|
||||
EXPECT_TRUE(region.resize(100));
|
||||
EXPECT_GE(region.getSize(), 100);
|
||||
writeData(region.getAddress(), 100, 1);
|
||||
EXPECT_TRUE(checkData(region.getAddress(), 100, 1));
|
||||
EXPECT_TRUE(region.resize(1 << 9ULL));
|
||||
writeData(region.getAddress() + 100, 900, 2);
|
||||
EXPECT_TRUE(checkData(region.getAddress(), 100, 1));
|
||||
EXPECT_TRUE(checkData(region.getAddress() + 100, 900, 2));
|
||||
|
||||
EXPECT_TRUE(region.resize(1 << 10ULL));
|
||||
EXPECT_TRUE(region.resize(1 << 5ULL));
|
||||
EXPECT_TRUE(region.resize(1 << 0ULL));
|
||||
EXPECT_TRUE(region.resize(1 << 9ULL));
|
||||
}
|
||||
Reference in New Issue
Block a user