Added support for code coverage checking and unittests.

Added support for code coverage checking with gcov and
unittests with Google C++ unittest and GMock frameworks.

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
actorid
Lukasz Gromanowski 13 years ago
parent e9b80c34fe
commit 34513cf16b

@ -31,6 +31,8 @@ option(OGRE_STATIC "Link static build of Ogre and Ogre Plugins into the binaries
option(BUILD_ESMTOOL "build ESM inspector" ON)
option(BUILD_LAUNCHER "build Launcher" ON)
option(BUILD_MWINIIMPORTER "build MWiniImporter" ON)
option(BUILD_WITH_CODE_COVERAGE "Enable code coverage with gconv" OFF)
option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest ang GMock frameworks" OFF)
# Sound source selection
option(USE_FFMPEG "use ffmpeg for sound" OFF)
@ -464,6 +466,11 @@ if (BUILD_MWINIIMPORTER)
add_subdirectory( apps/mwiniimporter )
endif()
# UnitTests
if (BUILD_UNITTESTS)
add_subdirectory( apps/openmw_test_suite )
endif()
if (WIN32)
if (MSVC)
if (USE_DEBUG_CONSOLE)

@ -17,3 +17,8 @@ target_link_libraries(esmtool
# find_library(CARBON_FRAMEWORK Carbon)
# target_link_libraries(openmw ${CARBON_FRAMEWORK})
#endif (APPLE)
if (BUILD_WITH_CODE_COVERAGE)
add_definitions (--coverage)
target_link_libraries(esmtool gcov)
endif()

@ -100,3 +100,8 @@ else()
configure_file(${CMAKE_SOURCE_DIR}/files/launcher.cfg
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/launcher.cfg")
endif()
if (BUILD_WITH_CODE_COVERAGE)
add_definitions (--coverage)
target_link_libraries(omwlauncher gcov)
endif()

@ -18,3 +18,7 @@ target_link_libraries(mwiniimport
components
)
if (BUILD_WITH_CODE_COVERAGE)
add_definitions (--coverage)
target_link_libraries(mwiniimport gcov)
endif()

@ -120,3 +120,8 @@ endif(APPLE)
if(DPKG_PROGRAM)
INSTALL(TARGETS openmw RUNTIME DESTINATION games COMPONENT openmw)
endif(DPKG_PROGRAM)
if (BUILD_WITH_CODE_COVERAGE)
add_definitions (--coverage)
target_link_libraries(openmw gcov)
endif()

@ -0,0 +1,24 @@
# TODO: This should not be needed, check how it was done in FindGTEST
set(GMOCK_ROOT "/usr/include")
set(GMOCK_BUILD "/usr/lib")
find_package(GTest REQUIRED)
find_package(GMock REQUIRED)
if (GTEST_FOUND AND GMOCK_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
include_directories(${GMOCK_INCLUDE_DIRS})
file(GLOB UNITTEST_SRC_FILES
components/misc/*.cpp
)
source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES})
add_executable(openmw_test_suite openmw_test_suite.cpp ${UNITTEST_SRC_FILES})
target_link_libraries(openmw_test_suite ${GMOCK_BOTH_LIBRARIES} ${GTEST_BOTH_LIBRARIES})
endif()

@ -0,0 +1,7 @@
#include <gtest/gtest.h>
TEST(simple_test, dummy)
{
EXPECT_EQ(true, true);
}

@ -0,0 +1,12 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
int main(int argc, char** argv) {
// The following line causes Google Mock to throw an exception on failure,
// which will be interpreted by your testing framework as a test failure.
::testing::GTEST_FLAG(throw_on_failure) = true;
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}

@ -0,0 +1,91 @@
# Locate the Google C++ Mocking Framework.
#
# Defines the following variables:
#
# GMOCK_FOUND - Found the Google Mocking framework
# GMOCK_INCLUDE_DIRS - Include directories
#
# Also defines the library variables below as normal
# variables. These contain debug/optimized keywords when
# a debugging library is found.
#
# GMOCK_BOTH_LIBRARIES - Both libgmock & libgmock-main
# GMOCK_LIBRARIES - libgmock
# GMOCK_MAIN_LIBRARIES - libgmock-main
#
# Accepts the following variables as input:
#
# GMOCK_ROOT - (as CMake or env. variable)
# The root directory of the gmock install prefix
#
#-----------------------
# Example Usage:
#
# enable_testing(true)
# find_package(GMock REQUIRED)
# include_directories(${GMOCK_INCLUDE_DIRS})
#
# add_executable(foo foo.cc)
# target_link_libraries(foo ${GMOCK_BOTH_LIBRARIES})
#
# add_test(AllTestsInFoo foo)
#
#set (GMOCK_FOUND FALSE)
#set (GMOCK_ROOT $ENV{GMOCK_ROOT} CACHE PATH "Path to the gmock root directory.")
if (NOT EXISTS ${GMOCK_ROOT})
message (FATAL_ERROR "GMOCK_ROOT does not exist.")
endif ()
#set (GMOCK_BUILD ${GMOCK_ROOT}/build CACHE PATH "Path to the gmock build directory.")
if (NOT EXISTS ${GMOCK_BUILD})
message (FATAL_ERROR "GMOCK_BUILD does not exist.")
endif ()
# Find the include directory
find_path(GMOCK_INCLUDE_DIRS gmock/gmock.h
HINTS
$ENV{GMOCK_ROOT}/include
${GMOCK_ROOT}/include
)
mark_as_advanced(GMOCK_INCLUDE_DIRS)
function(_gmock_find_library _name)
find_library(${_name}
NAMES ${ARGN}
HINTS
$ENV{GMOCK_BUILD}
${GMOCK_BUILD}
)
mark_as_advanced(${_name})
endfunction()
# Find the gmock libraries
if (MSVC)
_gmock_find_library (GMOCK_LIBRARIES_DEBUG gmock ${GMOCK_BUILD}/Debug)
_gmock_find_library (GMOCK_LIBRARIES_RELEASE gmock ${GMOCK_BUILD}/Release)
_gmock_find_library (GMOCK_MAIN_LIBRARIES_DEBUG gmock_main ${GMOCK_BUILD}/Debug)
_gmock_find_library (GMOCK_MAIN_LIBRARIES_RELEASE gmock_main ${GMOCK_BUILD}/Release)
set (GMOCK_LIBRARIES
debug ${GMOCK_LIBRARIES_DEBUG}
optimized ${GMOCK_LIBRARIES_RELEASE}
)
set (GMOCK_MAIN_LIBRARIES
debug ${GMOCK_MAIN_LIBRARIES_DEBUG}
optimized ${GMOCK_MAIN_LIBRARIES_RELEASE}
)
else ()
_gmock_find_library (GMOCK_LIBRARIES gmock ${GMOCK_BUILD})
_gmock_find_library (GMOCK_MAIN_LIBRARIES gmock_main ${GMOCK_BUILD} ${GMOCK_BUILD}/Debug)
endif ()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARIES GMOCK_INCLUDE_DIRS GMOCK_MAIN_LIBRARIES)
if(GMOCK_FOUND)
set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR})
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})
endif()
Loading…
Cancel
Save