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 e14c079
Show file tree
Hide file tree
Showing 57 changed files with 69 additions and 63 deletions.
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.
3 changes: 2 additions & 1 deletion Tests/UnitTests.cpp → Tests/UnitTests/UnitTests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#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"
#include "HudTests/BombStatusTests/BombStatusPanelManagerTests.h"
#include "Mocks/MockMemoryAllocator.h"
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 e14c079

Please sign in to comment.