Commit 2427b412 authored by GILLES Sebastien's avatar GILLES Sebastien

#1246 Tests: introduce a generic Fixture class and use it for Pk2 operator.

parent 8598cba1
......@@ -880,6 +880,8 @@
BE53FC331E0D86B900C5D6F5 /* Subtuple.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE53FC311E0D86B900C5D6F5 /* Subtuple.hxx */; };
BE5657411D3CD7470091F063 /* Array.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE56573F1D3CD7470091F063 /* Array.hpp */; };
BE5657421D3CD7470091F063 /* Array.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE5657401D3CD7470091F063 /* Array.hxx */; };
BE57F669205BDCDE00BA471A /* Fixture.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE57F666205BDCDE00BA471A /* Fixture.hxx */; };
BE57F66A205BDCDE00BA471A /* Fixture.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE57F667205BDCDE00BA471A /* Fixture.hpp */; };
BE59D6971DDF5212006FF5CB /* FromVertexMatching.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE59D68D1DDF5212006FF5CB /* FromVertexMatching.cpp */; };
BE59D6981DDF5212006FF5CB /* FromVertexMatching.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE59D68E1DDF5212006FF5CB /* FromVertexMatching.hpp */; };
BE59D6991DDF5212006FF5CB /* FromVertexMatching.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE59D68F1DDF5212006FF5CB /* FromVertexMatching.hxx */; };
......@@ -4860,6 +4862,8 @@
BE56573F1D3CD7470091F063 /* Array.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Array.hpp; sourceTree = "<group>"; };
BE5657401D3CD7470091F063 /* Array.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Array.hxx; sourceTree = "<group>"; };
BE576E941CB56C7C00872AA1 /* Model.doxygen */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Model.doxygen; sourceTree = "<group>"; };
BE57F666205BDCDE00BA471A /* Fixture.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Fixture.hxx; sourceTree = "<group>"; };
BE57F667205BDCDE00BA471A /* Fixture.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Fixture.hpp; sourceTree = "<group>"; };
BE5891171E1525840075B046 /* ThirdParty.doxygen */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ThirdParty.doxygen; sourceTree = "<group>"; };
BE5891181E1526A30075B046 /* ParameterInstances.doxygen */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ParameterInstances.doxygen; sourceTree = "<group>"; };
BE5892941E1528050075B046 /* OperatorInstances.doxygen */ = {isa = PBXFileReference; explicitFileType = text.rtf; fileEncoding = 4; path = OperatorInstances.doxygen; sourceTree = "<group>"; };
......@@ -8525,6 +8529,8 @@
BE436A181F694FE9003CE8E3 /* TestLinearAlgebra.hxx */,
BEBFCE7820580C610033C4C1 /* InitializeTestMoReFEMData.hpp */,
BEBFCE7720580C610033C4C1 /* InitializeTestMoReFEMData.hxx */,
BE57F667205BDCDE00BA471A /* Fixture.hpp */,
BE57F666205BDCDE00BA471A /* Fixture.hxx */,
);
path = Tools;
sourceTree = "<group>";
......@@ -12008,6 +12014,8 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
BE57F66A205BDCDE00BA471A /* Fixture.hpp in Headers */,
BE57F669205BDCDE00BA471A /* Fixture.hxx in Headers */,
BEBFCE7A20580C610033C4C1 /* InitializeTestMoReFEMData.hxx in Headers */,
BE436A1B1F694FE9003CE8E3 /* TestLinearAlgebra.hxx in Headers */,
BEBFCE7B20580C610033C4C1 /* InitializeTestMoReFEMData.hpp in Headers */,
......@@ -12,7 +12,7 @@
#include "Core/MoReFEMData/MoReFEMData.hpp"
#define CATCH_CONFIG_MAIN
#include "Test/Tools/InitializeTestMoReFEMData.hpp"
#include "Test/Tools/Fixture.hpp"
#include "Test/Operators/VariationalInstances/Pk2/Model.hpp"
#include "Test/Operators/VariationalInstances/Pk2/InputParameterList.hpp"
......@@ -24,37 +24,42 @@ using namespace MoReFEM;
namespace // anonymous
{
struct Fixture
struct LuaFile
{
Fixture();
~Fixture();
using type = TestNS::InitializeTestMoReFEMData<TestNS::Pk2::InputParameterList>;
static const type& StaticInitMoReFEMData();
static std::string GetPath();
static const TestNS::Pk2::Model& GetModel();
};
using fixture_type =
TestNS::Fixture
<
TestNS::Pk2::Model,
TestNS::Pk2::InputParameterList,
LuaFile
>;
} // namespace anonymous
TEST_CASE_METHOD(Fixture, "Unknown and test function unknown are identical")
TEST_CASE_METHOD(fixture_type, "Unknown and test function unknown are identical")
{
GetModel().SameUnknown();
}
TEST_CASE_METHOD(Fixture, "Unknown and test function unknown are different but share the same P1 shape function label")
TEST_CASE_METHOD(fixture_type, "Unknown and test function unknown are different but share the same P1 shape function label")
{
GetModel().UnknownP1TestP1();
}
TEST_CASE_METHOD(Fixture, "Unknown and test function unknown are different; unknown is P2 and test function P1")
TEST_CASE_METHOD(fixture_type, "Unknown and test function unknown are different; unknown is P2 and test function P1")
{
GetModel().UnknownP2TestP1();
}
......@@ -64,43 +69,13 @@ namespace // anonymous
{
const Fixture::type& Fixture::StaticInitMoReFEMData()
{
static auto ptr =
std::make_unique<type>(Utilities::EnvironmentNS::SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Operators/"
"VariationalInstances/Pk2/"
"demo_input_parameter_3D.lua"));
return *ptr;
}
const TestNS::Pk2::Model& Fixture::GetModel()
{
static bool first_call = true;
static auto ptr = std::make_unique<TestNS::Pk2::Model>(StaticInitMoReFEMData().GetMoReFEMData());
if (first_call)
{
ptr->Run(StaticInitMoReFEMData().GetMoReFEMData());
first_call = false;
}
return *ptr;
}
Fixture::Fixture()
{
}
Fixture::~Fixture()
std::string LuaFile::GetPath()
{
return
Utilities::EnvironmentNS::SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Operators/"
"VariationalInstances/Pk2/"
"demo_input_parameter_3D.lua");
}
} // namespace anonymous
target_sources(MoReFEM_test_tools
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/TestLinearAlgebra.cpp" /
PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/TestLinearAlgebra.hpp" /
"${CMAKE_CURRENT_LIST_DIR}/TestLinearAlgebra.hxx" /
"${CMAKE_CURRENT_LIST_DIR}/TestLinearAlgebra.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TestLinearAlgebra.hpp"
"${CMAKE_CURRENT_LIST_DIR}/TestLinearAlgebra.hxx"
"${CMAKE_CURRENT_LIST_DIR}/Fixture.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Fixture.hxx"
"${CMAKE_CURRENT_LIST_DIR}/InitializeTestMoReFEMData.hpp"
"${CMAKE_CURRENT_LIST_DIR}/InitializeTestMoReFEMData.hxx"
)
target_link_libraries(MoReFEM_test_tools ${MOREFEM_MODEL})
......
//! \file
//
//
// Fixture.hpp
// MoReFEM
//
// Created by sebastien on 16/03/2018.
//Copyright © 2018 Inria. All rights reserved.
//
#ifndef MOREFEM_x_TEST_x_TOOLS_x_FIXTURE_HPP_
# define MOREFEM_x_TEST_x_TOOLS_x_FIXTURE_HPP_
# include <memory>
# include <vector>
# include "Test/Tools/InitializeTestMoReFEMData.hpp"
namespace MoReFEM
{
namespace TestNS
{
/*!
* \brief An helper class to build tests with catch.
*
* The goal is to provide in a main different tests:
*
* \code
namespace // anonymous
{
struct LuaFile
{
static std::string GetPath();
};
using fixture_type =
TestNS::Fixture
<
TestNS::Pk2::Model,
TestNS::Pk2::InputParameterList,
LuaFile
>;
} // namespace anonymous
TEST_CASE_METHOD(fixture_type, "Unknown and test function unknown are identical")
{
GetModel().SameUnknown();
}
TEST_CASE_METHOD(fixture_type, "Unknown and test function unknown are different but share the same P1 shape function label")
{
GetModel().UnknownP1TestP1();
}
TEST_CASE_METHOD(fixture_type, "Unknown and test function unknown are different; unknown is P2 and test function P1")
{
GetModel().UnknownP2TestP1();
}
* \endcode
*
* The fixture here is a hack to run once and only once most of the initialization steps (MPI initialization,
* building of the different singletons, etc...).
*
* Basically it nuilds and run the \a Model throughout all of the integration tests.
*
* \attention Contrary to the original intent of the fixture, it does NOT make tabula rasa of the state after
* each test. So the tests should be a independant as possible from one another.
*
* \tparam ModelT Type of the model to build.
* \tparam InputParameterListT Type of the \a InputParameterList used along with the \a Model.
* \tparam LuaFileT An ad hoc class which encapsulates in a \a GetPath() method the path to the Lua file.
*/
template
<
class ModelT,
class InputParameterListT,
class LuaFileT
>
struct Fixture
{
public:
//! Alias to the proper InitializeTestMoReFEMData type.
using initialize_type = TestNS::InitializeTestMoReFEMData<InputParameterListT>;
/*!
* \brief Static method which yields the model considered for the tests.
*
* \return Constant reference to the \a Model.
*/
static const ModelT& GetModel();
public:
/// \name Special members.
///@{
//! Constructor.
explicit Fixture() = default;
//! Destructor.
~Fixture() = default;
//! Copy constructor.
Fixture(const Fixture&) = delete;
//! Move constructor.
Fixture(Fixture&&) = delete;
//! Copy affectation.
Fixture& operator=(const Fixture&) = delete;
//! Move affectation.
Fixture& operator=(Fixture&&) = delete;
///@}
};
} // namespace TestNS
} // namespace MoReFEM
# include "Test/Tools/Fixture.hxx"
#endif // MOREFEM_x_TEST_x_TOOLS_x_FIXTURE_HPP_
//! \file
//
//
// Fixture.hxx
// MoReFEM
//
// Created by sebastien on 16/03/2018.
//Copyright © 2018 Inria. All rights reserved.
//
#ifndef MOREFEM_x_TEST_x_TOOLS_x_FIXTURE_HXX_
# define MOREFEM_x_TEST_x_TOOLS_x_FIXTURE_HXX_
namespace MoReFEM
{
namespace TestNS
{
template
<
class ModelT,
class InputParameterListT,
class LuaFileT
>
const ModelT& Fixture<ModelT, InputParameterListT, LuaFileT>::GetModel()
{
static bool first_call = true;
static initialize_type init(LuaFileT::GetPath());
static ModelT model(init.GetMoReFEMData());
if (first_call)
{
model.Run(init.GetMoReFEMData());
first_call = false;
}
return model;
}
} // namespace TestNS
} // namespace MoReFEM
#endif // MOREFEM_x_TEST_x_TOOLS_x_FIXTURE_HXX_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment