Add the infrastructure required to easily add unit tests and test it with a very simple test file.
This commit is contained in:
parent
747021e0c8
commit
d4ed4adace
|
@ -333,8 +333,9 @@ endif()
|
|||
|
||||
include(FindGTest OPTIONAL)
|
||||
if(GTEST_FOUND)
|
||||
enable_testing()
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
message("GTest found, unit tests can be compiled and ran with 'ctest'")
|
||||
message("GTest found, unit tests can be compiled and ran with 'make unittests'")
|
||||
else()
|
||||
message("GTest NOT found, disabling unit tests")
|
||||
endif(GTEST_FOUND)
|
||||
|
|
|
@ -52,6 +52,9 @@ if (DSPTOOL)
|
|||
add_subdirectory(DSPTool)
|
||||
endif()
|
||||
|
||||
if (GTEST_FOUND)
|
||||
add_subdirectory(UnitTests)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
add_custom_target(unittests)
|
||||
add_custom_command(TARGET unittests POST_BUILD COMMAND ${CMAKE_CTEST_COMMAND})
|
||||
|
||||
macro(add_dolphin_test target srcs libs)
|
||||
add_executable(Tests/${target} EXCLUDE_FROM_ALL ${srcs})
|
||||
target_link_libraries(Tests/${target} ${libs} ${GTEST_BOTH_LIBRARIES})
|
||||
add_dependencies(unittests Tests/${target})
|
||||
add_test(NAME ${target} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Tests/${target})
|
||||
endmacro(add_dolphin_test)
|
||||
|
||||
add_subdirectory(Core)
|
|
@ -0,0 +1 @@
|
|||
add_dolphin_test(MMIOTest MMIOTest.cpp core)
|
|
@ -0,0 +1,24 @@
|
|||
#include <unordered_set>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/HW/MMIO.h"
|
||||
|
||||
// Tests that the UniqueID function returns a "unique enough" identifier
|
||||
// number: that is, it is unique in the address ranges we care about.
|
||||
TEST(UniqueID, UniqueEnough)
|
||||
{
|
||||
std::unordered_set<u32> ids;
|
||||
for (u32 i = 0xCC000000; i < 0xCC010000; ++i)
|
||||
{
|
||||
u32 unique_id = MMIO::UniqueID(i);
|
||||
EXPECT_EQ(ids.end(), ids.find(unique_id));
|
||||
ids.insert(unique_id);
|
||||
}
|
||||
for (u32 i = 0xCD000000; i < 0xCD010000; ++i)
|
||||
{
|
||||
u32 unique_id = MMIO::UniqueID(i);
|
||||
EXPECT_EQ(ids.end(), ids.find(unique_id));
|
||||
ids.insert(unique_id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue