Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaFramework] Create Sofa.Testing module #1834

Merged
merged 19 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ endif()

### Testing
option(SOFA_BUILD_TESTS "Compile the automatic tests for Sofa, along with the gtest library." ON)
if(SOFA_BUILD_TESTS OR SOFA_BUILD_RELEASE_PACKAGE)
# Enable testing features of cmake, like the add_test() command.
enable_testing()
add_subdirectory(extlibs/gtest)
endif()

## Active or not the use of ccache
option(SOFA_USE_CCACHE "Compile using ccache optimization" OFF)
Expand Down Expand Up @@ -189,9 +184,9 @@ add_subdirectory(extlibs)
### Main Sofa subdirectories
add_subdirectory(${SOFA_KERNEL_SOURCE_DIR}/SofaFramework)
add_subdirectory(${SOFA_KERNEL_SOURCE_DIR}/SofaSimulation)

if(SOFA_BUILD_TESTS OR SOFA_BUILD_RELEASE_PACKAGE)
# Depends on SofaSimulation
add_subdirectory(tools/SofaGTestMain)
add_subdirectory(${SOFA_KERNEL_SOURCE_DIR}/modules/Sofa.Testing)
endif()

add_subdirectory(${SOFA_KERNEL_SOURCE_DIR}/SofaBase)
Expand Down
4 changes: 0 additions & 4 deletions SofaKernel/SofaFramework/SofaFrameworkConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ set(SOFAFRAMEWORK_TARGETS @SOFAFRAMEWORK_TARGETS@)
set(SOFAHELPER_HAVE_BOOST "@SOFAHELPER_HAVE_BOOST@")
set(SOFAHELPER_HAVE_BOOST_FILESYSTEM "@SOFAHELPER_HAVE_BOOST_FILESYSTEM@")
set(SOFAHELPER_HAVE_BOOST_THREAD "@SOFAHELPER_HAVE_BOOST_THREAD@")
set(SOFAHELPER_HAVE_GTEST "@SOFAHELPER_HAVE_GTEST@")

# Find dependencies
find_package(Boost QUIET REQUIRED filesystem)
if(SOFAHELPER_HAVE_BOOST_THREAD)
find_package(Boost QUIET REQUIRED thread)
endif()
if(SOFAHELPER_HAVE_GTEST)
find_package(GTest CONFIG QUIET REQUIRED)
endif()

find_package(Sofa.Config QUIET REQUIRED)

Expand Down
2 changes: 1 addition & 1 deletion SofaKernel/modules/Sofa.GL/Sofa.GL_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ set(SOURCE_FILES
)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain Sofa.GL)
target_link_libraries(${PROJECT_NAME} Sofa.Testing Sofa.GL)

add_test(NAME Sofa.GL_test COMMAND Sofa.GL_test)
59 changes: 59 additions & 0 deletions SofaKernel/modules/Sofa.Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
cmake_minimum_required(VERSION 3.12)
project(Sofa.Testing LANGUAGES CXX)

# Enable testing features of cmake, like the add_test() command.
enable_testing()

# add gtest library
add_subdirectory(extlibs/gtest)
# add custom gtest main
add_subdirectory(SofaGTestMain)

set(SOFATESTINGSRC_ROOT "src/sofa/testing")

set(HEADER_FILES
${SOFATESTINGSRC_ROOT}/config.h.in
${SOFATESTINGSRC_ROOT}/initSofa.Testing.h
${SOFATESTINGSRC_ROOT}/BaseTest.h
${SOFATESTINGSRC_ROOT}/NumericTest.h
${SOFATESTINGSRC_ROOT}/TestMessageHandler.h
${SOFATESTINGSRC_ROOT}/BaseSimulationTest.h
)

set(SOURCE_FILES
${SOFATESTINGSRC_ROOT}/initSofa.Testing.cpp
${SOFATESTINGSRC_ROOT}/BaseTest.cpp
${SOFATESTINGSRC_ROOT}/NumericTest.cpp
${SOFATESTINGSRC_ROOT}/TestMessageHandler.cpp
${SOFATESTINGSRC_ROOT}/BaseSimulationTest.cpp
)


# Compatibility files
set (COMPATSRC_ROOT "compat/")
set (COMPAT_HEADER_FILES
${COMPATSRC_ROOT}/sofa/helper/testing/BaseTest.h
${COMPATSRC_ROOT}/sofa/helper/testing/NumericTest.h
${COMPATSRC_ROOT}/sofa/helper/testing/TestMessageHandler.h
${COMPATSRC_ROOT}/SofaSimulationGraph/testing/BaseSimulationTest.h
)

find_package(SofaFramework REQUIRED)
find_package(SofaSimulationGraph REQUIRED)

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${COMPAT_HEADER_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC SofaHelper SofaDefaultType SofaCore gtest SofaGTestMain SofaSimulationGraph)

target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${COMPATSRC_ROOT}>")
target_include_directories(${PROJECT_NAME} PUBLIC "$<INSTALL_INTERFACE:include/Sofa.Testing/Sofa.Testing/compat>")
source_group("compat" FILES ${COMPAT_HEADER_FILES} )

sofa_create_package_with_targets(
PACKAGE_NAME ${PROJECT_NAME}
PACKAGE_VERSION ${Sofa_VERSION}
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
)

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Testing)
15 changes: 15 additions & 0 deletions SofaKernel/modules/Sofa.Testing/Sofa.TestingConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# CMake package configuration file for the @PROJECT_NAME@ module

@PACKAGE_GUARD@
@PACKAGE_INIT@

find_package(GTest CONFIG QUIET REQUIRED)
find_package(SofaGTestMain QUIET REQUIRED)
find_package(SofaFramework QUIET REQUIRED)
find_package(SofaSimulationGraph QUIET REQUIRED)

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
endif()

check_required_components(@PROJECT_NAME@)
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ sofa_create_package_with_targets(
PACKAGE_VERSION ${Sofa_VERSION}
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
)

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Testing)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <sofa/testing/BaseSimulationTest.h>

//SOFA_DEPRECATED_HEADER(v21.12, "sofa/testing/BaseSimulationTest.h")

namespace sofa::helper
{
namespace testing = sofa::testing;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <sofa/testing/BaseTest.h>

//SOFA_DEPRECATED_HEADER(v21.12, "sofa/testing/BaseTest.h")

namespace sofa::helper
{
namespace testing = sofa::testing;
}

//{
// const SReal g_minDeltaErrorRatio = sofa::testing::g_minDeltaErrorRatio;
//
// using BaseTest = sofa::testing::BaseTest;
//
//} // namespace sofa::helper::testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <sofa/testing/NumericTest.h>

//SOFA_DEPRECATED_HEADER(v21.12, "sofa/testing/NumericTest.h")

namespace sofa::helper
{
namespace testing = sofa::testing;
}

//namespace sofa::helper::testing
//{
// template <typename _Real = SReal>
// using NumericTest = sofa::testing::NumericTest<_Real>;
//
// template<class Vector, class ReadData>
// void copyFromData(Vector& v, const ReadData& d)
// {
// sofa::testing::copyFromData(v,d);
// }
//
// template<class WriteData, class Vector>
// void copyToData(WriteData& d, const Vector& v)
// {
// sofa::testing::copyToData(v, d);
// }
//
// template<class _DataTypes>
// using data_traits = sofa::testing::data_traits<_DataTypes>;
//
//
//} // namespace sofa::helper::testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <sofa/testing/TestMessageHandler.h>

//SOFA_DEPRECATED_HEADER(v21.12, "sofa/testing/TestMessageHandler.h")

namespace sofa::helper::logging
{
using sofa::testing::MessageAsTestFailure;
using sofa::testing::IgnoreMessage;
using sofa::testing::MainGtestMessageHandler;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ sofa_create_package_with_targets(
INCLUDE_SOURCE_DIR "include"
INCLUDE_INSTALL_DIR "extlibs/GTest"
)

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Testing)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <SofaSimulationGraph/testing/BaseSimulationTest.h>
#include <sofa/testing/BaseSimulationTest.h>

#include <sofa/core/fwd.h>
using sofa::core::execparams::defaultInstance;
Expand All @@ -35,7 +35,7 @@ using sofa::simulation::SceneLoaderXML ;
#include <sofa/helper/system/PluginManager.h>
using sofa::helper::system::PluginManager ;

namespace sofa::helper::testing
namespace sofa::testing
{

bool BaseSimulationTest::importPlugin(const std::string& name)
Expand Down Expand Up @@ -105,4 +105,4 @@ BaseSimulationTest::BaseSimulationTest()
simulation::setSimulation(new simulation::graph::DAGSimulation()) ;
}

} // namespace sofa::helper::testing
} // namespace sofa::testing
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
******************************************************************************/
#pragma once

#include <SofaSimulationGraph/config.h>
#include <sofa/helper/testing/BaseTest.h>
#include <sofa/testing/config.h>

#include <sofa/testing/BaseTest.h>
#include <sofa/simulation/Node.h>
#include <sofa/simulation/Simulation.h>

namespace sofa::helper::testing
namespace sofa::testing
{
using sofa::simulation::Node ;
using sofa::simulation::Simulation ;

class SOFA_SOFASIMULATIONGRAPH_API BaseSimulationTest : public virtual BaseTest
class SOFA_TESTING_API BaseSimulationTest : public virtual BaseTest
{
public:
BaseSimulationTest() ;

bool importPlugin(const std::string& name) ;

class SOFA_SOFASIMULATIONGRAPH_API SceneInstance
class SOFA_TESTING_API SceneInstance
{
public:
SceneInstance(const std::string& rootname="root") ;
Expand All @@ -56,4 +57,4 @@ class SOFA_SOFASIMULATIONGRAPH_API BaseSimulationTest : public virtual BaseTest
} ;
};

} // namespace sofa::helper::testing
} // namespace sofa::testing