SimulatorTimer: add serialization support

This commit is contained in:
Arne Morten Kvarving
2023-01-31 12:09:20 +01:00
parent 4786deeffc
commit f2a14b2d07
5 changed files with 111 additions and 3 deletions

View File

@@ -0,0 +1,72 @@
/*
Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
This file is part of the Open Porous Media project (OPM).
OPM 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 3 of the License, or
(at your option) any later version.
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <opm/common/utility/Serializer.hpp>
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
#include <opm/simulators/utils/SerializationPackers.hpp>
#define BOOST_TEST_MODULE TestRestartSerialization
#define BOOST_TEST_NO_MAIN
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/test/unit_test.hpp>
template<class T>
std::tuple<T,int,int> PackUnpack(T& in)
{
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(in);
size_t pos1 = ser.position();
T out{};
ser.unpack(out);
size_t pos2 = ser.position();
return std::make_tuple(out, pos1, pos2);
}
#define TEST_FOR_TYPE_NAMED_OBJ(TYPE, NAME, OBJ) \
BOOST_AUTO_TEST_CASE(NAME) \
{ \
auto val1 = Opm::TYPE::OBJ(); \
auto val2 = PackUnpack(val1); \
BOOST_CHECK_MESSAGE(std::get<1>(val2) == std::get<2>(val2), "Packed size differ from unpack size for " #TYPE); \
BOOST_CHECK_MESSAGE(val1 == std::get<0>(val2), "Deserialized " #TYPE " differ"); \
}
#define TEST_FOR_TYPE_NAMED(TYPE, NAME) \
TEST_FOR_TYPE_NAMED_OBJ(TYPE, NAME, serializationTestObject)
#define TEST_FOR_TYPE(TYPE) \
TEST_FOR_TYPE_NAMED(TYPE, TYPE)
TEST_FOR_TYPE(SimulatorTimer)
bool init_unit_test_func()
{
return true;
}
int main(int argc, char** argv)
{
return boost::unit_test::unit_test_main(&init_unit_test_func, argc, argv);
}