Skip to content

Commit

Permalink
Move existing tests to Tests/UnitTests directory
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Jan 28, 2025
1 parent d1370d7 commit 5a1974d
Show file tree
Hide file tree
Showing 59 changed files with 70 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ jobs:
- name: build source
run: cmake --build build --target Osiris -j $(nproc --all)
- name: build unit tests
run: cmake --build build --target Tests -j $(nproc --all)
run: cmake --build build --target UnitTests -j $(nproc --all)
- name: run unit tests
run: ctest --test-dir build --output-on-failure --schedule-random -j $(nproc --all)
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ jobs:
- name: build source
run: cmake --build build --target Osiris --config ${{ matrix.configuration }}
- name: build unit tests
run: cmake --build build --target Tests --config ${{ matrix.configuration }}
run: cmake --build build --target UnitTests --config ${{ matrix.configuration }}
- name: run unit tests
run: ctest --test-dir build --output-on-failure --schedule-random -j $env:NUMBER_OF_PROCESSORS
14 changes: 2 additions & 12 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(googletest)

add_executable(Tests UnitTests.cpp)

if(MSVC)
target_compile_options(Tests PRIVATE /bigobj)
endif()

add_subdirectory(MemoryAllocation)
add_subdirectory(Platform)
target_link_libraries(Tests gtest_main gmock Threads::Threads)
target_include_directories(Tests PRIVATE . "${CMAKE_SOURCE_DIR}/Source")

include(GoogleTest)
gtest_discover_tests(Tests DISCOVERY_TIMEOUT 60)

add_subdirectory(UnitTests)
3 changes: 0 additions & 3 deletions Tests/MemoryAllocation/CMakeLists.txt

This file was deleted.

30 changes: 0 additions & 30 deletions Tests/MemoryAllocation/MockMemoryAllocator.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions Tests/MemoryAllocation/MockMemoryAllocator.h

This file was deleted.

50 changes: 50 additions & 0 deletions Tests/Mocks/MockMemoryAllocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include <cstddef>
#include <memory>

#include <gmock/gmock.h>

#include <MemoryAllocation/MemoryAllocatorBase.h>

struct MockMemoryAllocator {
MOCK_METHOD(std::byte*, allocate, (std::size_t size), (noexcept));
MOCK_METHOD(void, deallocate, (std::byte* memory, std::size_t size), (noexcept));

using MockType = testing::StrictMock<MockMemoryAllocator>;
[[nodiscard]] static std::shared_ptr<MockType> create()
{
if (const auto existingMock = mockMemoryAllocator.lock())
return existingMock;

auto mock = std::make_shared<MockMemoryAllocator::MockType>();
mockMemoryAllocator = mock;
return mock;
}

static std::byte* invokeAllocate(std::size_t size)
{
if (const auto mock = mockMemoryAllocator.lock())
return mock->allocate(size);
return nullptr;
}

static void invokeDeallocate(std::byte* memory, std::size_t size)
{
if (const auto mock = mockMemoryAllocator.lock())
mock->deallocate(memory, size);
}

private:
inline static std::weak_ptr<MockMemoryAllocator::MockType> mockMemoryAllocator;
};

std::byte* MemoryAllocatorBase::allocate(std::size_t size) noexcept
{
return MockMemoryAllocator::invokeAllocate(size);
}

void MemoryAllocatorBase::deallocate(std::byte* memory, std::size_t size) noexcept
{
MockMemoryAllocator::invokeDeallocate(memory, size);
}
3 changes: 0 additions & 3 deletions Tests/Platform/Windows/CMakeLists.txt

This file was deleted.

12 changes: 12 additions & 0 deletions Tests/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_executable(UnitTests UnitTests.cpp)

if(MSVC)
target_compile_options(UnitTests PRIVATE /bigobj)
endif()

target_include_directories(UnitTests PRIVATE "${CMAKE_SOURCE_DIR}/Tests" "${CMAKE_SOURCE_DIR}/Source")
target_link_libraries(UnitTests gtest_main gmock Threads::Threads)
set_target_properties(UnitTests PROPERTIES OUTPUT_NAME UnitTestsBin)
gtest_discover_tests(UnitTests DISCOVERY_TIMEOUT 60)

add_subdirectory(PlatformTests)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions Tests/UnitTests/PlatformTests/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target_sources(UnitTests PRIVATE
MockWindowsPlatformApi.cpp
)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Tests/UnitTests.cpp → Tests/UnitTests/UnitTests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "FeatureTests/HudFeaturesTests/Tests.h"
#include "HelpersTests/Tests.h"
#include "MemorySearchTests/Tests.h"
#include "Platform/Tests.h"
#include "PlatformTests/Tests.h"
#include "UtilsTests/Tests.h"

#include "HudTests/BombStatusTests/BombStatusPanelTests.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5a1974d

Please sign in to comment.