COMPONENT development)
endif()
-option(GMX_USE_GTEST "Build tests that require Google C++ Testing Framework" ON)
-option(GMX_USE_GMOCK "Build tests that require Google C++ Mocking Framework" ON)
-mark_as_advanced(GMX_USE_GTEST)
-mark_as_advanced(GMX_USE_GMOCK)
-if (BUILD_TESTING)
- add_subdirectory(src/external/gmock-1.6.0)
- add_custom_target(tests)
-endif (BUILD_TESTING)
+if (LIBXML2_FOUND)
+ option(GMX_BUILD_UNITTESTS "Build unit tests with BUILD_TESTING (uses Google C++ Testing and Mocking Frameworks, requires libxml2)" ON)
+else (LIBXML2_FOUND)
+ set(GMX_BUILD_UNITTESTS OFF)
+endif (LIBXML2_FOUND)
+mark_as_advanced(GMX_BUILD_UNITTESTS)
set(MEMORYCHECK_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR}/cmake/legacy_and_external.supp)
find_package(Doxygen)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmakein ${CMAKE_CURRENT_BINARY_DIR}/config.h)
if (BUILD_TESTING)
+ add_custom_target(tests)
+ if (GMX_BUILD_UNITTESTS)
+ add_subdirectory(external/gmock-1.6.0)
+ endif (GMX_BUILD_UNITTESTS)
include(testutils/TestMacros.cmake)
- add_subdirectory(testutils)
+ if (GMX_BUILD_UNITTESTS)
+ add_subdirectory(testutils)
+ endif (GMX_BUILD_UNITTESTS)
endif (BUILD_TESTING)
add_subdirectory(gromacs)
set(GTEST_INCLUDE_DIRS ${GTEST_DIR}/include)
set(GMOCK_INCLUDE_DIRS ${GMOCK_DIR}/include ${GTEST_INCLUDE_DIRS})
-if (GMX_USE_GMOCK)
- set(GMX_USE_GTEST ON)
- include_directories(${GTEST_INCLUDE_DIRS})
- include_directories(${GTEST_DIR})
- include_directories(${GMOCK_INCLUDE_DIRS})
- include_directories(${GMOCK_DIR})
- add_library(gmock STATIC ${GMOCK_SOURCES} ${GTEST_SOURCES})
- set(GMOCK_LIBRARIES gmock ${PTHREADS_LIBRARIES} PARENT_SCOPE)
-endif (GMX_USE_GMOCK)
-if (GMX_USE_GTEST)
- include_directories(${GTEST_INCLUDE_DIRS})
- include_directories(${GTEST_DIR})
- add_library(gtest STATIC ${GTEST_SOURCES})
- set(GTEST_LIBRARIES gtest ${PTHREADS_LIBRARIES} PARENT_SCOPE)
-endif (GMX_USE_GTEST)
-set(GMX_USE_GTEST ${GMX_USE_GTEST} PARENT_SCOPE)
-set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} PARENT_SCOPE)
+
+include_directories(${GTEST_INCLUDE_DIRS})
+include_directories(${GTEST_DIR})
+include_directories(${GMOCK_INCLUDE_DIRS})
+include_directories(${GMOCK_DIR})
+add_library(gmock STATIC ${GMOCK_SOURCES} ${GTEST_SOURCES})
+set(GMOCK_LIBRARIES gmock ${PTHREADS_LIBRARIES} PARENT_SCOPE)
+set(GTEST_LIBRARIES ${GMOCK_LIBRARIES} PARENT_SCOPE)
set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIRS} PARENT_SCOPE)
+set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} PARENT_SCOPE)
-if (TESTUTILS_HAVE_REFDATA)
- add_gmock_test(AnalysisDataUnitTests analysisdata-test
- analysisdata.cpp arraydata.cpp
- average.cpp datatest.cpp histogram.cpp
- mock_module.cpp)
-endif ()
+gmx_add_unit_test(AnalysisDataUnitTests analysisdata-test
+ analysisdata.cpp
+ arraydata.cpp
+ average.cpp
+ datatest.cpp
+ histogram.cpp
+ mock_module.cpp)
-if (TESTUTILS_HAVE_REFDATA)
- add_gtest_or_gmock_test(CommandLineUnitTests commandline-test
- cmdlinehelpwriter.cpp
- cmdlineparser.cpp
- cmdlinetest.cpp
- GMOCK_ONLY
- cmdlinemodulemanager.cpp)
-endif ()
+gmx_add_unit_test(CommandLineUnitTests commandline-test
+ cmdlinehelpwriter.cpp
+ cmdlinemodulemanager.cpp
+ cmdlineparser.cpp
+ cmdlinetest.cpp)
-add_gtest_or_gmock_test(OptionsUnitTests options-test
- option.cpp optionsassigner.cpp
- timeunitmanager.cpp
- GMOCK_ONLY abstractoptionstorage.cpp)
+gmx_add_unit_test(OptionsUnitTests options-test
+ abstractoptionstorage.cpp
+ option.cpp
+ optionsassigner.cpp
+ timeunitmanager.cpp)
-if (TESTUTILS_HAVE_REFDATA)
- add_gtest_test(SelectionUnitTests selection-test
- selectioncollection.cpp selectionoption.cpp)
-endif ()
+gmx_add_unit_test(SelectionUnitTests selection-test
+ selectioncollection.cpp
+ selectionoption.cpp)
-if (TESTUTILS_HAVE_REFDATA)
- add_gtest_test(UtilityUnitTests utility-test
- format.cpp)
-endif ()
+gmx_add_unit_test(UtilityUnitTests utility-test
+ format.cpp)
-set(TESTUTILS_HAVE_REFDATA FALSE)
-set(COMMON_SOURCES datapath.cpp refdata-common.cpp testoptions.cpp)
-if (GMX_USE_GTEST AND LIBXML2_FOUND)
- include_directories(${GTEST_INCLUDE_DIRS})
- list(APPEND COMMON_SOURCES refdata.cpp stringtest.cpp)
- set(TESTUTILS_HAVE_REFDATA TRUE)
- add_definitions(-DTESTUTILS_HAVE_REFDATA)
-endif ()
+include_directories(${GTEST_INCLUDE_DIRS})
+set(COMMON_SOURCES datapath.cpp
+ refdata.cpp
+ stringtest.cpp
+ testoptions.cpp)
add_library(testutils STATIC ${COMMON_SOURCES})
-set(TESTUTILS_LIBS testutils)
-target_link_libraries(testutils libgromacs)
-if (TESTUTILS_HAVE_REFDATA)
- list(APPEND TESTUTILS_LIBS ${GTEST_LIBRARIES} ${LIBXML2_LIBRARIES})
- target_link_libraries(testutils ${GTEST_LIBRARIES} ${LIBXML2_LIBRARIES})
-endif ()
+set(TESTUTILS_LIBS testutils ${GTEST_LIBRARIES} ${LIBXML2_LIBRARIES})
+target_link_libraries(testutils libgromacs ${GTEST_LIBRARIES} ${LIBXML2_LIBRARIES})
set(TESTUTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(TESTUTILS_DIR ${TESTUTILS_DIR} PARENT_SCOPE)
set(TESTUTILS_LIBS ${TESTUTILS_LIBS} PARENT_SCOPE)
-set(TESTUTILS_HAVE_REFDATA ${TESTUTILS_HAVE_REFDATA} PARENT_SCOPE)
add_subdirectory(tests)
-function (add_gtest_test NAME EXENAME)
- if (GMX_USE_GTEST AND BUILD_TESTING)
- include_directories(${GTEST_INCLUDE_DIRS})
- add_executable(${EXENAME} ${ARGN} ${TESTUTILS_DIR}/test_main_gtest.cpp)
- target_link_libraries(${EXENAME} libgromacs ${TESTUTILS_LIBS} ${GTEST_LIBRARIES})
- get_target_property(DEFS ${EXENAME} COMPILE_DEFINITIONS)
- if (NOT DEFS)
- set(DEFS)
- endif ()
- list(APPEND DEFS TEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
- set_target_properties(${EXENAME} PROPERTIES COMPILE_DEFINITIONS ${DEFS})
- add_test(NAME ${NAME}
- COMMAND ${EXENAME} --gtest_output=xml:${CMAKE_BINARY_DIR}/Testing/Temporary/${EXENAME}.xml)
- set_tests_properties(${NAME} PROPERTIES LABELS "GTest")
- add_dependencies(tests ${EXENAME})
- endif ()
-endfunction ()
-
-function (add_gmock_test NAME EXENAME)
- if (GMX_USE_GMOCK AND BUILD_TESTING)
+function (gmx_add_unit_test NAME EXENAME)
+ if (GMX_BUILD_UNITTESTS AND BUILD_TESTING)
include_directories(${GMOCK_INCLUDE_DIRS})
- add_executable(${EXENAME} ${ARGN} ${TESTUTILS_DIR}/test_main_gmock.cpp)
+ add_executable(${EXENAME} ${ARGN} ${TESTUTILS_DIR}/unittest_main.cpp)
target_link_libraries(${EXENAME} libgromacs ${TESTUTILS_LIBS} ${GMOCK_LIBRARIES})
get_target_property(DEFS ${EXENAME} COMPILE_DEFINITIONS)
if (NOT DEFS)
add_test(NAME ${NAME}
COMMAND ${EXENAME} --gtest_output=xml:${CMAKE_BINARY_DIR}/Testing/Temporary/${EXENAME}.xml)
set_tests_properties(${NAME} PROPERTIES LABELS "GTest")
- add_dependencies(tests ${EXENAME})
- endif ()
-endfunction ()
-
-function (add_gtest_or_gmock_test NAME EXENAME)
- if (GMX_USE_GTEST AND BUILD_TESTING)
- set(_outvar GTEST_SOURCES)
- foreach(_source IN ITEMS ${ARGN})
- if (_source STREQUAL GMOCK_ONLY)
- set(_outvar GMOCK_SOURCES)
- else ()
- list(APPEND ${_outvar} ${_source})
- endif ()
- endforeach()
- if (GMX_USE_GMOCK)
- set(SOURCES ${GTEST_SOURCES} ${GMOCK_SOURCES})
- add_gmock_test(${NAME} ${EXENAME} ${SOURCES})
- else ()
- add_gtest_test(${NAME} ${EXENAME} ${GTEST_SOURCES})
- endif ()
+ add_dependencies(tests ${EXENAME})
endif ()
endfunction ()
* \inlibraryapi
* \ingroup module_testutils
*/
-/*! \libinternal \defgroup module_testutils Unit Testing Utility Modules
+/*! \libinternal \defgroup module_testutils Unit Testing Utilities
* \brief
* Common helper classes and functions for writing unit tests.
*
+ * To build unit tests using these utilities, libxml2 is required.
+ *
* \ingroup group_utilitymodules
*/
#ifndef GMX_TESTUTILS_DATAPATH_H
+++ /dev/null
-/*
- *
- * This source code is part of
- *
- * G R O M A C S
- *
- * GROningen MAchine for Chemical Simulations
- *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
- */
-/*! \internal \file
- * \brief
- * Implements functions in refdata.h that don't have external dependencies.
- *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_testutils
- */
-#include "refdata.h"
-
-#include <cstring>
-#include <cstdio>
-
-#include <new>
-
-#include "testutils/datapath.h"
-
-namespace gmx
-{
-namespace test
-{
-
-static ReferenceDataMode g_referenceDataMode = erefdataCompare;
-
-
-ReferenceDataMode getReferenceDataMode()
-{
- return g_referenceDataMode;
-}
-
-
-void setReferenceDataMode(ReferenceDataMode mode)
-{
- g_referenceDataMode = mode;
-}
-
-
-std::string getReferenceDataPath()
-{
- return getTestFilePath("refdata");
-}
-
-
-void initReferenceData(int *argc, char **argv)
-{
- int i, newi;
-
- for (i = newi = 1; i < *argc; ++i, ++newi)
- {
- argv[newi] = argv[i];
- if (!std::strcmp(argv[i], "--create-ref-data"))
- {
- setReferenceDataMode(erefdataCreateMissing);
- --newi;
- }
- else if (!std::strcmp(argv[i], "--update-ref-data"))
- {
- setReferenceDataMode(erefdataUpdateAll);
- --newi;
- }
- }
- *argc = newi;
-#ifdef TESTUTILS_HAVE_REFDATA
- try
- {
- internal::addGlobalReferenceDataEnvironment();
- }
- catch (const std::bad_alloc &)
- {
- std::fprintf(stderr, "Out of memory\n");
- std::exit(1);
- }
-#endif
-}
-
-} // namespace test
-} // namespace gmx
*/
/*! \internal \file
* \brief
- * Implements gmx::test::TestReferenceData.
+ * Implements classes and functions from refdata.h.
*
* \author Teemu Murtola <teemu.murtola@cbr.su.se>
* \ingroup module_testutils
#include <cstdio>
#include <cstdlib>
+#include <cstring>
+#include <new>
#include <string>
#include <gtest/gtest.h>
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/format.h"
+#include "testutils/datapath.h"
#include "testutils/testexceptions.h"
#include "refdata-impl.h"
namespace test
{
-/*! \cond internal */
-namespace internal
+static ReferenceDataMode g_referenceDataMode = erefdataCompare;
+
+ReferenceDataMode getReferenceDataMode()
{
+ return g_referenceDataMode;
+}
+
+void setReferenceDataMode(ReferenceDataMode mode)
+{
+ g_referenceDataMode = mode;
+}
-void addGlobalReferenceDataEnvironment()
+std::string getReferenceDataPath()
{
- ::testing::AddGlobalTestEnvironment(new TestReferenceDataEnvironment);
+ return getTestFilePath("refdata");
}
-} // namespace internal
-//! \endcond
+void initReferenceData(int *argc, char **argv)
+{
+ int i, newi;
+
+ for (i = newi = 1; i < *argc; ++i, ++newi)
+ {
+ argv[newi] = argv[i];
+ if (!std::strcmp(argv[i], "--create-ref-data"))
+ {
+ setReferenceDataMode(erefdataCreateMissing);
+ --newi;
+ }
+ else if (!std::strcmp(argv[i], "--update-ref-data"))
+ {
+ setReferenceDataMode(erefdataUpdateAll);
+ --newi;
+ }
+ }
+ *argc = newi;
+ try
+ {
+ ::testing::AddGlobalTestEnvironment(new TestReferenceDataEnvironment);
+ }
+ catch (const std::bad_alloc &)
+ {
+ std::fprintf(stderr, "Out of memory\n");
+ std::exit(1);
+ }
+}
/********************************************************************
* TestReferenceData::Impl
*/
void initReferenceData(int *argc, char **argv);
-/*! \cond internal */
-/*! \internal \brief
- * Internal testing namespace.
- *
- * This namespace is used to contain some implementation-specific functions and
- * classes. These are not meant for direct access, but typically reside in
- * visible headers because of implementation reasons.
- */
-namespace internal
-{
-
-/*! \internal \brief
- * Adds a global test teardown method for freeing libxml2 internal data.
- *
- * This method is called by initReferenceData(), and should not be called
- * directly.
- * It adds a global test environment object that calls xmlCleanupParser() at
- * the end of all tests. This makes memory reports from valgrind cleaner since
- * otherwise they show the memory as "still reachable".
- */
-void addGlobalReferenceDataEnvironment();
-
-} // namespace internal
-//! \endcond
-
class TestReferenceChecker;
* reference data file is not reported as an error, nor is empty reference data
* file created in write mode).
*
- * This class is only available if both Google Test and libxml2 are enabled.
- * If either one is missing, trying to use this class will result in unresolved
- * symbols in linking.
- *
* \inlibraryapi
* \ingroup module_testutils
*/
*
* Copies of this class behave have independent internal state.
*
- * This class is only available if both Google Test and libxml2 are enabled.
- * If either one is missing, trying to use this class will result in unresolved
- * symbols in linking.
- *
* \inlibraryapi
* \ingroup module_testutils
*/
+++ /dev/null
-/*
- *
- * This source code is part of
- *
- * G R O M A C S
- *
- * GROningen MAchine for Chemical Simulations
- *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
- */
-/*! \libinternal \file
- * \brief
- * main() for unit tests that use Google C++ Testing Framework.
- *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_testutils
- */
-#include <gtest/gtest.h>
-
-#include "testutils/testoptions.h"
-
-#ifndef TEST_DATA_PATH
-//! Path to test input data directory (needs to be set by the build system).
-#define TEST_DATA_PATH 0
-#endif
-
-/*! \brief
- * Initializes unit testing with Google C++ Testing Framework.
- */
-int main(int argc, char *argv[])
-{
- ::testing::InitGoogleTest(&argc, argv);
- ::gmx::test::initTestUtils(TEST_DATA_PATH, &argc, argv);
- return RUN_ALL_TESTS();
-}
-if (TESTUTILS_HAVE_REFDATA)
- add_gtest_test(TestUtilsUnitTests testutils-test
- refdata.cpp)
-endif (TESTUTILS_HAVE_REFDATA)
+gmx_add_unit_test(TestUtilsUnitTests testutils-test
+ refdata.cpp)