Commit e5d026e4 authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Add unit test for serialization.

parent 5e73cf2b
...@@ -31,6 +31,10 @@ DEFINE_TEST(exception) ...@@ -31,6 +31,10 @@ DEFINE_TEST(exception)
DEFINE_TEST(exception-factory) DEFINE_TEST(exception-factory)
DEFINE_TEST(timer) DEFINE_TEST(timer)
ADD_UNIT_TEST(serialization serialization.cc serialization-test.cc)
TARGET_INCLUDE_DIRECTORIES(serialization PRIVATE ${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(serialization ${PROJECT_NAME})
SET(HPP_LOGGINGDIR "${CMAKE_CURRENT_BINARY_DIR}") SET(HPP_LOGGINGDIR "${CMAKE_CURRENT_BINARY_DIR}")
CONFIG_FILES(run_debug.sh) CONFIG_FILES(run_debug.sh)
ADD_EXECUTABLE(debug debug.cc) ADD_EXECUTABLE(debug debug.cc)
......
// Copyright (c) 2020, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-util.
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util 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 Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include <sstream>
#include "config.h"
#include "common.hh"
#include "serialization.hh"
#include <boost/archive/polymorphic_xml_iarchive.hpp>
#include <boost/archive/polymorphic_xml_oarchive.hpp>
int run_test ()
{
std::stringstream ss;
Foo foo(10);
Bar bar(20);
{
boost::archive::polymorphic_xml_oarchive oa(ss);
oa << boost::serialization::make_nvp("foo", foo);
oa << boost::serialization::make_nvp("bar", bar);
}
Foo* foo_r = NULL;
Bar* bar_r = NULL;
{
boost::archive::polymorphic_xml_iarchive ia(ss);
ia >> boost::serialization::make_nvp("foo", foo_r);
ia >> boost::serialization::make_nvp("bar", bar_r);
}
if (foo_r == NULL || foo_r->i_ != foo.i_) return TEST_FAILED;
if (bar_r == NULL || bar_r->i_ != bar.i_) return TEST_FAILED;
return TEST_SUCCEED;
}
GENERATE_TEST ()
// Copyright (c) 2020, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-util.
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util 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 Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include <hpp/util/serialization.hh>
#include "serialization.hh"
BOOST_CLASS_EXPORT(Foo)
template<class Archive>
void Foo::serialize(Archive & ar, const unsigned int version)
{
(void) version;
ar & hpp::serialization::make_nvp("i", i_);
}
HPP_SERIALIZATION_IMPLEMENT(Foo);
BOOST_CLASS_EXPORT(Bar)
template<class Archive>
void Bar::load(Archive & ar, const unsigned int version)
{
(void) version;
ar & hpp::serialization::make_nvp("i", i_);
}
template<class Archive>
void Bar::save(Archive & ar, const unsigned int version) const
{
(void) version;
ar & hpp::serialization::make_nvp("i", i_);
}
HPP_SERIALIZATION_SPLIT_IMPLEMENT(Bar);
// Copyright (c) 2020, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-util.
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util 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 Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include <hpp/util/serialization-fwd.hh>
class Foo {
public:
Foo(int i) : i_ (i) {};
int i_;
private:
Foo() {}
HPP_SERIALIZABLE();
};
class Bar {
public:
Bar(int i) : i_ (i) {};
int i_;
private:
Bar() {}
HPP_SERIALIZABLE_SPLIT();
};
Supports Markdown
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