Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit f008214c authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1525 Add a template parameter to Model fixture so that we don'tneed to define a mock Run() method.

parent ed927caa
......@@ -100,9 +100,6 @@ namespace MoReFEM
//! Accessor to the path to the program-wise ascii file.
const std::string& GetProgramWiseAsciiFile() const noexcept;
void Run() { }
private:
//! Global vector which is used in the tests.
......
......@@ -45,7 +45,8 @@ namespace // anonymous
TestNS::FixtureNS::Model
<
TestNS::PetscNS::VectorIONS::Model,
LuaFile
LuaFile,
TestNS::FixtureNS::call_run_method_at_first_call::no
>;
......
......@@ -26,6 +26,10 @@ namespace MoReFEM
{
//! Whether a Run() method should be called at first call or not.
enum class call_run_method_at_first_call { no, yes };
/*!
* \brief An helper class to build tests with Boost test.
*
......@@ -73,11 +77,15 @@ namespace MoReFEM
*
* \tparam ModelT Type of the model to build.
* \tparam LuaFileT An ad hoc class which encapsulates in a \a GetPath() method the path to the Lua file.
* \tparam call_run_method_at_first_call Whether a Run() method should be called at first call or not. In fact when C++ 20 is out a concept
* checking whether Run() exists or not would be more elegant than this explicit template parameter. Should be yes in the cases an actual \a Model
* derived from \a Model class is used (see PetscVectorIO test for a counter-example).
*/
template
<
class ModelT,
class LuaFileT
class LuaFileT,
call_run_method_at_first_call CallRunMethodT = call_run_method_at_first_call::yes
>
struct Model : public Environment
{
......
......@@ -23,9 +23,10 @@ namespace MoReFEM
template
<
class ModelT,
class LuaFileT
class LuaFileT,
call_run_method_at_first_call CallRunMethodT
>
Model<ModelT, LuaFileT>::Model()
Model<ModelT, LuaFileT, CallRunMethodT>::Model()
{
static bool first_call = true;
......@@ -49,18 +50,22 @@ namespace MoReFEM
template
<
class ModelT,
class LuaFileT
class LuaFileT,
call_run_method_at_first_call CallRunMethodT
>
const ModelT& Model<ModelT, LuaFileT>::GetModel()
const ModelT& Model<ModelT, LuaFileT, CallRunMethodT>::GetModel()
{
static bool first_call = true;
static ModelT model(GetMoReFEMData());
if (first_call)
if constexpr (CallRunMethodT == call_run_method_at_first_call::yes)
{
model.Run();
first_call = false;
static bool first_call = true;
if (first_call)
{
model.Run();
first_call = false;
}
}
return model;
......@@ -70,10 +75,11 @@ namespace MoReFEM
template
<
class ModelT,
class LuaFileT
class LuaFileT,
call_run_method_at_first_call CallRunMethodT
>
const typename Model<ModelT, LuaFileT>::morefem_data_type&
Model<ModelT, LuaFileT>::GetMoReFEMData()
const typename Model<ModelT, LuaFileT, CallRunMethodT>::morefem_data_type&
Model<ModelT, LuaFileT, CallRunMethodT>::GetMoReFEMData()
{
static initialize_type init(LuaFileT::GetPath());
......
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