more #139
This commit is contained in:
@@ -24,456 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "structs_specialized.hpp"
|
||||
|
||||
struct BogusBase
|
||||
{
|
||||
template <class Archive>
|
||||
void serialize( Archive & ) {}
|
||||
TEST_SUITE("structs_specialized");
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ) const {}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ) {}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const & ) const { return 0; }
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const & ) {}
|
||||
};
|
||||
|
||||
struct BogusBaseVersioned
|
||||
{
|
||||
template <class Archive>
|
||||
void serialize( Archive &, const std::uint32_t ) {}
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive &, const std::uint32_t ) const {}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive &, const std::uint32_t ) {}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, const std::uint32_t ) const { return 0; }
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const &, const std::uint32_t ) {}
|
||||
};
|
||||
|
||||
struct BogusBasePolymorphic
|
||||
{
|
||||
template <class Archive>
|
||||
void serialize( Archive & ) {}
|
||||
|
||||
virtual void doesNothing() {}
|
||||
};
|
||||
|
||||
class SpecializedMSerialize : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedMSerialize() = default;
|
||||
SpecializedMSerialize( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSerializeVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedMSerializeVersioned() = default;
|
||||
SpecializedMSerializeVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, const std::uint32_t )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplit : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedMSplit() = default;
|
||||
SpecializedMSplit( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void save( Archive & ar ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitVersioned() = default;
|
||||
SpecializedMSplitVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void save( Archive & ar, const std::uint32_t ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, const std::uint32_t )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitPolymorphic : public BogusBasePolymorphic
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitPolymorphic() = default;
|
||||
SpecializedMSplitPolymorphic( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void save( Archive & ar ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitMinimal : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitMinimal() = default;
|
||||
SpecializedMSplitMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const & ) const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const & value )
|
||||
{
|
||||
x = value;
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitVersionedMinimal : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitVersionedMinimal() = default;
|
||||
SpecializedMSplitVersionedMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, const std::uint32_t ) const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const & value, const std::uint32_t )
|
||||
{
|
||||
x = value;
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedNMSerialize : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedNMSerialize() = default;
|
||||
SpecializedNMSerialize( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, SpecializedNMSerialize & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSerializeVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedNMSerializeVersioned() = default;
|
||||
SpecializedNMSerializeVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, SpecializedNMSerializeVersioned & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSplit : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplit() = default;
|
||||
SpecializedNMSplit( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, SpecializedNMSplit & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar, SpecializedNMSplit const & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSplitVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplitVersioned() = default;
|
||||
SpecializedNMSplitVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, SpecializedNMSplitVersioned & s, const std::uint32_t )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar, SpecializedNMSplitVersioned const & s, const std::uint32_t )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSplitMinimal : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplitMinimal() = default;
|
||||
SpecializedNMSplitMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, SpecializedNMSplitMinimal & s, int const & value )
|
||||
{
|
||||
s.x = value;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, SpecializedNMSplitMinimal const & s )
|
||||
{
|
||||
return s.x;
|
||||
}
|
||||
|
||||
class SpecializedNMSplitVersionedMinimal : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplitVersionedMinimal() = default;
|
||||
SpecializedNMSplitVersionedMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, SpecializedNMSplitVersionedMinimal & s, int const & value, const std::uint32_t )
|
||||
{
|
||||
s.x = value;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, SpecializedNMSplitVersionedMinimal const & s, const std::uint32_t )
|
||||
{
|
||||
return s.x;
|
||||
}
|
||||
|
||||
namespace cereal
|
||||
{
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSerialize, cereal::specialization::member_serialize> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSerializeVersioned, cereal::specialization::member_serialize> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplit, cereal::specialization::member_load_save> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitVersioned, cereal::specialization::member_load_save> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitPolymorphic, cereal::specialization::member_load_save> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitMinimal, cereal::specialization::member_load_save_minimal> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitVersionedMinimal, cereal::specialization::member_load_save_minimal> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSerialize, cereal::specialization::non_member_serialize> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSerializeVersioned, cereal::specialization::non_member_serialize> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplit, cereal::specialization::non_member_load_save> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplitVersioned, cereal::specialization::non_member_load_save> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplitMinimal,
|
||||
cereal::specialization::non_member_load_save_minimal> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplitVersionedMinimal,
|
||||
cereal::specialization::non_member_load_save_minimal> {};
|
||||
}
|
||||
|
||||
CEREAL_REGISTER_TYPE(SpecializedMSplitPolymorphic)
|
||||
CEREAL_REGISTER_POLYMORPHIC_RELATION(BogusBasePolymorphic, SpecializedMSplitPolymorphic)
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_structs_specialized()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
SpecializedMSerialize o_iser = { random_value<int>(gen) };
|
||||
SpecializedMSerializeVersioned o_iserv = { random_value<int>(gen) };
|
||||
|
||||
SpecializedMSplit o_ispl = { random_value<int>(gen) };
|
||||
SpecializedMSplitVersioned o_isplv = { random_value<int>(gen) };
|
||||
|
||||
// added re: issue #180
|
||||
std::shared_ptr<BogusBasePolymorphic> o_shared_ispl = std::make_shared<SpecializedMSplitPolymorphic>( random_value<int>(gen) );
|
||||
|
||||
SpecializedMSplitMinimal o_isplm = { random_value<int>(gen) };
|
||||
SpecializedMSplitVersionedMinimal o_isplvm = { random_value<int>(gen) };
|
||||
|
||||
SpecializedNMSerialize o_eser = { random_value<int>(gen) };
|
||||
SpecializedNMSerializeVersioned o_eserv = { random_value<int>(gen) };
|
||||
|
||||
SpecializedNMSplit o_espl = { random_value<int>(gen) };
|
||||
SpecializedNMSplitVersioned o_esplv = { random_value<int>(gen) };
|
||||
|
||||
SpecializedNMSplitMinimal o_esplm = { random_value<int>(gen) };
|
||||
SpecializedNMSplitVersionedMinimal o_esplvm = { random_value<int>(gen) };
|
||||
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar( o_iser, o_iserv,
|
||||
o_ispl, o_isplv, o_shared_ispl,
|
||||
o_isplm, o_isplvm,
|
||||
o_eser, o_eserv,
|
||||
o_espl, o_esplv,
|
||||
o_esplm, o_esplvm );
|
||||
}
|
||||
|
||||
decltype(o_iser) i_iser;
|
||||
decltype(o_iserv) i_iserv;
|
||||
|
||||
decltype(o_ispl) i_ispl;
|
||||
decltype(o_isplv) i_isplv;
|
||||
|
||||
decltype(o_shared_ispl) i_shared_ispl;
|
||||
|
||||
decltype(o_isplm) i_isplm;
|
||||
decltype(o_isplvm) i_isplvm;
|
||||
|
||||
decltype(o_eser) i_eser;
|
||||
decltype(o_eserv) i_eserv;
|
||||
|
||||
decltype(o_espl) i_espl;
|
||||
decltype(o_esplv) i_esplv;
|
||||
|
||||
decltype(o_esplm) i_esplm;
|
||||
decltype(o_esplvm) i_esplvm;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar( i_iser, i_iserv,
|
||||
i_ispl, i_isplv, i_shared_ispl,
|
||||
i_isplm, i_isplvm,
|
||||
i_eser, i_eserv,
|
||||
i_espl, i_esplv,
|
||||
i_esplm, i_esplvm );
|
||||
}
|
||||
|
||||
BOOST_CHECK(i_iser.x == o_iser.x);
|
||||
BOOST_CHECK(i_iserv.x == o_iserv.x);
|
||||
|
||||
BOOST_CHECK(i_ispl.x == o_ispl.x);
|
||||
BOOST_CHECK(i_isplv.x == o_isplv.x);
|
||||
|
||||
BOOST_CHECK_EQUAL(((SpecializedMSplitPolymorphic*)i_shared_ispl.get())->x, ((SpecializedMSplitPolymorphic*)o_shared_ispl.get())->x);
|
||||
|
||||
BOOST_CHECK(i_isplm.x == o_isplm.x);
|
||||
BOOST_CHECK(i_isplvm.x == o_isplvm.x);
|
||||
|
||||
BOOST_CHECK(i_eser.x == o_eser.x);
|
||||
BOOST_CHECK(i_eserv.x == o_eserv.x);
|
||||
|
||||
BOOST_CHECK(i_espl.x == o_espl.x);
|
||||
BOOST_CHECK(i_esplv.x == o_esplv.x);
|
||||
|
||||
BOOST_CHECK(i_esplm.x == o_esplm.x);
|
||||
BOOST_CHECK(i_esplvm.x == o_esplvm.x);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_structs_specialized )
|
||||
TEST_CASE("binary_structs_specialized")
|
||||
{
|
||||
test_structs_specialized<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_structs_specialized )
|
||||
TEST_CASE("portable_binary_structs_specialized")
|
||||
{
|
||||
test_structs_specialized<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_structs_specialized )
|
||||
TEST_CASE("xml_structs_specialized")
|
||||
{
|
||||
test_structs_specialized<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_structs_specialized )
|
||||
TEST_CASE("json_structs_specialized")
|
||||
{
|
||||
test_structs_specialized<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
||||
@@ -0,0 +1,461 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_STRUCTS_MINIMAL_H_
|
||||
#define CEREAL_TEST_STRUCTS_MINIMAL_H_
|
||||
#include "common.hpp"
|
||||
|
||||
struct BogusBase
|
||||
{
|
||||
template <class Archive>
|
||||
void serialize( Archive & ) {}
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ) const {}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ) {}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const & ) const { return 0; }
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const & ) {}
|
||||
};
|
||||
|
||||
struct BogusBaseVersioned
|
||||
{
|
||||
template <class Archive>
|
||||
void serialize( Archive &, const std::uint32_t ) {}
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive &, const std::uint32_t ) const {}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive &, const std::uint32_t ) {}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, const std::uint32_t ) const { return 0; }
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const &, const std::uint32_t ) {}
|
||||
};
|
||||
|
||||
struct BogusBasePolymorphic
|
||||
{
|
||||
template <class Archive>
|
||||
void serialize( Archive & ) {}
|
||||
|
||||
virtual void doesNothing() {}
|
||||
};
|
||||
|
||||
class SpecializedMSerialize : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedMSerialize() = default;
|
||||
SpecializedMSerialize( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSerializeVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedMSerializeVersioned() = default;
|
||||
SpecializedMSerializeVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, const std::uint32_t )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplit : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedMSplit() = default;
|
||||
SpecializedMSplit( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void save( Archive & ar ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitVersioned() = default;
|
||||
SpecializedMSplitVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void save( Archive & ar, const std::uint32_t ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, const std::uint32_t )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitPolymorphic : public BogusBasePolymorphic
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitPolymorphic() = default;
|
||||
SpecializedMSplitPolymorphic( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void save( Archive & ar ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar )
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitMinimal : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitMinimal() = default;
|
||||
SpecializedMSplitMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const & ) const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const & value )
|
||||
{
|
||||
x = value;
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedMSplitVersionedMinimal : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedMSplitVersionedMinimal() = default;
|
||||
SpecializedMSplitVersionedMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, const std::uint32_t ) const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, int const & value, const std::uint32_t )
|
||||
{
|
||||
x = value;
|
||||
}
|
||||
};
|
||||
|
||||
class SpecializedNMSerialize : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedNMSerialize() = default;
|
||||
SpecializedNMSerialize( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, SpecializedNMSerialize & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSerializeVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedNMSerializeVersioned() = default;
|
||||
SpecializedNMSerializeVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, SpecializedNMSerializeVersioned & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSplit : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplit() = default;
|
||||
SpecializedNMSplit( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, SpecializedNMSplit & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar, SpecializedNMSplit const & s )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSplitVersioned : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplitVersioned() = default;
|
||||
SpecializedNMSplitVersioned( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, SpecializedNMSplitVersioned & s, const std::uint32_t )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar, SpecializedNMSplitVersioned const & s, const std::uint32_t )
|
||||
{
|
||||
ar( s.x );
|
||||
}
|
||||
|
||||
class SpecializedNMSplitMinimal : public BogusBase
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplitMinimal() = default;
|
||||
SpecializedNMSplitMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, SpecializedNMSplitMinimal & s, int const & value )
|
||||
{
|
||||
s.x = value;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, SpecializedNMSplitMinimal const & s )
|
||||
{
|
||||
return s.x;
|
||||
}
|
||||
|
||||
class SpecializedNMSplitVersionedMinimal : public BogusBaseVersioned
|
||||
{
|
||||
public:
|
||||
SpecializedNMSplitVersionedMinimal() = default;
|
||||
SpecializedNMSplitVersionedMinimal( int xx ) : x(xx) {}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void load_minimal( Archive const &, SpecializedNMSplitVersionedMinimal & s, int const & value, const std::uint32_t )
|
||||
{
|
||||
s.x = value;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
int save_minimal( Archive const &, SpecializedNMSplitVersionedMinimal const & s, const std::uint32_t )
|
||||
{
|
||||
return s.x;
|
||||
}
|
||||
|
||||
namespace cereal
|
||||
{
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSerialize, cereal::specialization::member_serialize> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSerializeVersioned, cereal::specialization::member_serialize> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplit, cereal::specialization::member_load_save> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitVersioned, cereal::specialization::member_load_save> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitPolymorphic, cereal::specialization::member_load_save> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitMinimal, cereal::specialization::member_load_save_minimal> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedMSplitVersionedMinimal, cereal::specialization::member_load_save_minimal> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSerialize, cereal::specialization::non_member_serialize> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSerializeVersioned, cereal::specialization::non_member_serialize> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplit, cereal::specialization::non_member_load_save> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplitVersioned, cereal::specialization::non_member_load_save> {};
|
||||
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplitMinimal,
|
||||
cereal::specialization::non_member_load_save_minimal> {};
|
||||
template <class Archive> struct specialize<Archive, SpecializedNMSplitVersionedMinimal,
|
||||
cereal::specialization::non_member_load_save_minimal> {};
|
||||
}
|
||||
|
||||
CEREAL_REGISTER_TYPE(SpecializedMSplitPolymorphic)
|
||||
CEREAL_REGISTER_POLYMORPHIC_RELATION(BogusBasePolymorphic, SpecializedMSplitPolymorphic)
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_structs_specialized()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
SpecializedMSerialize o_iser = { random_value<int>(gen) };
|
||||
SpecializedMSerializeVersioned o_iserv = { random_value<int>(gen) };
|
||||
|
||||
SpecializedMSplit o_ispl = { random_value<int>(gen) };
|
||||
SpecializedMSplitVersioned o_isplv = { random_value<int>(gen) };
|
||||
|
||||
// added re: issue #180
|
||||
std::shared_ptr<BogusBasePolymorphic> o_shared_ispl = std::make_shared<SpecializedMSplitPolymorphic>( random_value<int>(gen) );
|
||||
|
||||
SpecializedMSplitMinimal o_isplm = { random_value<int>(gen) };
|
||||
SpecializedMSplitVersionedMinimal o_isplvm = { random_value<int>(gen) };
|
||||
|
||||
SpecializedNMSerialize o_eser = { random_value<int>(gen) };
|
||||
SpecializedNMSerializeVersioned o_eserv = { random_value<int>(gen) };
|
||||
|
||||
SpecializedNMSplit o_espl = { random_value<int>(gen) };
|
||||
SpecializedNMSplitVersioned o_esplv = { random_value<int>(gen) };
|
||||
|
||||
SpecializedNMSplitMinimal o_esplm = { random_value<int>(gen) };
|
||||
SpecializedNMSplitVersionedMinimal o_esplvm = { random_value<int>(gen) };
|
||||
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar( o_iser, o_iserv,
|
||||
o_ispl, o_isplv, o_shared_ispl,
|
||||
o_isplm, o_isplvm,
|
||||
o_eser, o_eserv,
|
||||
o_espl, o_esplv,
|
||||
o_esplm, o_esplvm );
|
||||
}
|
||||
|
||||
decltype(o_iser) i_iser;
|
||||
decltype(o_iserv) i_iserv;
|
||||
|
||||
decltype(o_ispl) i_ispl;
|
||||
decltype(o_isplv) i_isplv;
|
||||
|
||||
decltype(o_shared_ispl) i_shared_ispl;
|
||||
|
||||
decltype(o_isplm) i_isplm;
|
||||
decltype(o_isplvm) i_isplvm;
|
||||
|
||||
decltype(o_eser) i_eser;
|
||||
decltype(o_eserv) i_eserv;
|
||||
|
||||
decltype(o_espl) i_espl;
|
||||
decltype(o_esplv) i_esplv;
|
||||
|
||||
decltype(o_esplm) i_esplm;
|
||||
decltype(o_esplvm) i_esplvm;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar( i_iser, i_iserv,
|
||||
i_ispl, i_isplv, i_shared_ispl,
|
||||
i_isplm, i_isplvm,
|
||||
i_eser, i_eserv,
|
||||
i_espl, i_esplv,
|
||||
i_esplm, i_esplvm );
|
||||
}
|
||||
|
||||
CHECK_EQ(i_iser.x, o_iser.x);
|
||||
CHECK_EQ(i_iserv.x, o_iserv.x);
|
||||
|
||||
CHECK_EQ(i_ispl.x, o_ispl.x);
|
||||
CHECK_EQ(i_isplv.x, o_isplv.x);
|
||||
|
||||
CHECK_EQ(((SpecializedMSplitPolymorphic*)i_shared_ispl.get())->x, doctest::Approx(((SpecializedMSplitPolymorphic*)o_shared_ispl.get())->x));
|
||||
|
||||
CHECK_EQ(i_isplm.x, o_isplm.x);
|
||||
CHECK_EQ(i_isplvm.x, o_isplvm.x);
|
||||
|
||||
CHECK_EQ(i_eser.x, o_eser.x);
|
||||
CHECK_EQ(i_eserv.x, o_eserv.x);
|
||||
|
||||
CHECK_EQ(i_espl.x, o_espl.x);
|
||||
CHECK_EQ(i_esplv.x, o_esplv.x);
|
||||
|
||||
CHECK_EQ(i_esplm.x, o_esplm.x);
|
||||
CHECK_EQ(i_esplvm.x, o_esplvm.x);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_STRUCTS_SPECIALIZED_H_
|
||||
+8
-75
@@ -24,96 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "tuple.hpp"
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_tuple()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
TEST_SUITE("tuple");
|
||||
|
||||
auto rng = [&](){ return random_value<int>(gen); };
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
auto o_podtuple = std::make_tuple( rng(), rng(), rng(), rng() );
|
||||
auto o_podtuple11 = std::make_tuple( rng(), rng(), rng(), rng(), rng(), rng(),
|
||||
rng(), rng(), rng(), rng(), rng() );
|
||||
auto o_isertuple = std::make_tuple( StructInternalSerialize( rng(), rng() ),
|
||||
StructInternalSerialize( rng(), rng() ),
|
||||
StructInternalSerialize( rng(), rng() ),
|
||||
StructInternalSerialize( rng(), rng() ) );
|
||||
auto o_ispltuple = std::make_tuple( StructInternalSplit( rng(), rng() ),
|
||||
StructInternalSplit( rng(), rng() ),
|
||||
StructInternalSplit( rng(), rng() ),
|
||||
StructInternalSplit( rng(), rng() ) );
|
||||
auto o_esertuple = std::make_tuple( StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ) );
|
||||
auto o_espltuple = std::make_tuple( StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ) );
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podtuple);
|
||||
oar(o_podtuple11);
|
||||
oar(o_isertuple);
|
||||
oar(o_ispltuple);
|
||||
oar(o_esertuple);
|
||||
oar(o_espltuple);
|
||||
}
|
||||
|
||||
decltype( o_podtuple ) i_podtuple;
|
||||
decltype( o_podtuple11 ) i_podtuple11;
|
||||
decltype( o_isertuple ) i_isertuple;
|
||||
decltype( o_ispltuple ) i_ispltuple;
|
||||
decltype( o_esertuple ) i_esertuple;
|
||||
decltype( o_espltuple ) i_espltuple;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podtuple);
|
||||
iar(i_podtuple11);
|
||||
iar(i_isertuple);
|
||||
iar(i_ispltuple);
|
||||
iar(i_esertuple);
|
||||
iar(i_espltuple);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( i_podtuple == o_podtuple, true );
|
||||
BOOST_CHECK_EQUAL( i_podtuple11 == o_podtuple11, true );
|
||||
BOOST_CHECK_EQUAL( i_isertuple == o_isertuple, true );
|
||||
BOOST_CHECK_EQUAL( i_ispltuple == o_ispltuple, true );
|
||||
BOOST_CHECK_EQUAL( i_esertuple == o_esertuple, true );
|
||||
BOOST_CHECK_EQUAL( i_espltuple == o_espltuple, true );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_tuple )
|
||||
TEST_CASE("binary_tuple")
|
||||
{
|
||||
test_tuple<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_tuple )
|
||||
TEST_CASE("portable_binary_tuple")
|
||||
{
|
||||
test_tuple<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_tuple )
|
||||
TEST_CASE("xml_tuple")
|
||||
{
|
||||
test_tuple<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_tuple )
|
||||
TEST_CASE("json_tuple")
|
||||
{
|
||||
test_tuple<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_TUPLE_H_
|
||||
#define CEREAL_TEST_TUPLE_H_
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_tuple()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
auto rng = [&](){ return random_value<int>(gen); };
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
auto o_podtuple = std::make_tuple( rng(), rng(), rng(), rng() );
|
||||
auto o_podtuple11 = std::make_tuple( rng(), rng(), rng(), rng(), rng(), rng(),
|
||||
rng(), rng(), rng(), rng(), rng() );
|
||||
auto o_isertuple = std::make_tuple( StructInternalSerialize( rng(), rng() ),
|
||||
StructInternalSerialize( rng(), rng() ),
|
||||
StructInternalSerialize( rng(), rng() ),
|
||||
StructInternalSerialize( rng(), rng() ) );
|
||||
auto o_ispltuple = std::make_tuple( StructInternalSplit( rng(), rng() ),
|
||||
StructInternalSplit( rng(), rng() ),
|
||||
StructInternalSplit( rng(), rng() ),
|
||||
StructInternalSplit( rng(), rng() ) );
|
||||
auto o_esertuple = std::make_tuple( StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ) );
|
||||
auto o_espltuple = std::make_tuple( StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ),
|
||||
StructExternalSerialize( rng(), rng() ) );
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podtuple);
|
||||
oar(o_podtuple11);
|
||||
oar(o_isertuple);
|
||||
oar(o_ispltuple);
|
||||
oar(o_esertuple);
|
||||
oar(o_espltuple);
|
||||
}
|
||||
|
||||
decltype( o_podtuple ) i_podtuple;
|
||||
decltype( o_podtuple11 ) i_podtuple11;
|
||||
decltype( o_isertuple ) i_isertuple;
|
||||
decltype( o_ispltuple ) i_ispltuple;
|
||||
decltype( o_esertuple ) i_esertuple;
|
||||
decltype( o_espltuple ) i_espltuple;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podtuple);
|
||||
iar(i_podtuple11);
|
||||
iar(i_isertuple);
|
||||
iar(i_ispltuple);
|
||||
iar(i_esertuple);
|
||||
iar(i_espltuple);
|
||||
}
|
||||
|
||||
CHECK_EQ( i_podtuple, o_podtuple);
|
||||
CHECK_EQ( i_podtuple11, o_podtuple11);
|
||||
CHECK_EQ( i_isertuple, o_isertuple);
|
||||
CHECK_EQ( i_ispltuple, o_ispltuple);
|
||||
CHECK_EQ( i_esertuple, o_esertuple);
|
||||
CHECK_EQ( i_espltuple, o_espltuple);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_TUPLE_H_
|
||||
@@ -24,134 +24,19 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "unordered_loads.hpp"
|
||||
|
||||
struct unordered_naming
|
||||
{
|
||||
int x;
|
||||
int xx;
|
||||
int y;
|
||||
int z;
|
||||
TEST_SUITE("unordered_loads");
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar ) const
|
||||
{
|
||||
ar( CEREAL_NVP(x),
|
||||
CEREAL_NVP(z),
|
||||
CEREAL_NVP(y),
|
||||
CEREAL_NVP(xx) );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar )
|
||||
{
|
||||
ar( x,
|
||||
CEREAL_NVP(y),
|
||||
CEREAL_NVP(z),
|
||||
CEREAL_NVP(xx) );
|
||||
}
|
||||
|
||||
bool operator==( unordered_naming const & other ) const
|
||||
{
|
||||
return x == other.x && xx == other.xx && y == other.y && z == other.z;
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, unordered_naming const & s)
|
||||
{
|
||||
os << "[x: " << s.x << " xx: " << s.xx << " y: " << s.y << " z: " << s.z << "]";
|
||||
return os;
|
||||
}
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_unordered_loads()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
auto rngB = [&](){ return random_value<int>( gen ) % 2 == 0; };
|
||||
auto rngI = [&](){ return random_value<int>( gen ); };
|
||||
auto rngF = [&](){ return random_value<float>( gen ); };
|
||||
auto rngD = [&](){ return random_value<double>( gen ); };
|
||||
auto rngS = [&](){ return random_basic_string<char>( gen ); };
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
auto const name1 = rngS();
|
||||
auto const name2 = rngS();
|
||||
auto const name3 = rngS();
|
||||
auto const name4 = rngS();
|
||||
auto const name5 = rngS();
|
||||
auto const name6 = rngS();
|
||||
auto const name7 = rngS();
|
||||
|
||||
int o_int1 = rngI();
|
||||
double o_double2 = rngD();
|
||||
std::vector<bool> o_vecbool3 = { rngB(), rngB(), rngB(), rngB(), rngB() };
|
||||
int o_int4 = rngI();
|
||||
int o_int5 = rngI();
|
||||
int o_int6 = rngI();
|
||||
std::pair<float, unordered_naming> o_un7;
|
||||
o_un7.first = rngF();
|
||||
o_un7.second.x = rngI();
|
||||
o_un7.second.xx = rngI();
|
||||
o_un7.second.y = rngI();
|
||||
o_un7.second.z = rngI();
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar( cereal::make_nvp( name1, o_int1 ),
|
||||
cereal::make_nvp( name2, o_double2 ),
|
||||
cereal::make_nvp( name3, o_vecbool3 ),
|
||||
cereal::make_nvp( name4, o_int4 ),
|
||||
cereal::make_nvp( name5, o_int5 ),
|
||||
cereal::make_nvp( name6, o_int6 ),
|
||||
cereal::make_nvp( name7, o_un7 ) );
|
||||
}
|
||||
|
||||
decltype(o_int1) i_int1;
|
||||
decltype(o_double2) i_double2;
|
||||
decltype(o_vecbool3) i_vecbool3;
|
||||
decltype(o_int4) i_int4;
|
||||
decltype(o_int5) i_int5;
|
||||
decltype(o_int6) i_int6;
|
||||
decltype(o_un7) i_un7;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar( cereal::make_nvp( name7, i_un7 ),
|
||||
cereal::make_nvp( name2, i_double2 ),
|
||||
cereal::make_nvp( name4, i_int4 ),
|
||||
cereal::make_nvp( name3, i_vecbool3 ),
|
||||
cereal::make_nvp( name1, i_int1 ),
|
||||
cereal::make_nvp( name5, i_int5 ),
|
||||
i_int6 );
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(o_int1, i_int1);
|
||||
BOOST_CHECK_CLOSE(o_double2 , o_double2, 1e-5);
|
||||
BOOST_CHECK_EQUAL(o_vecbool3.size(), i_vecbool3.size());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_vecbool3.begin(), i_vecbool3.end(), o_vecbool3.begin(), o_vecbool3.end());
|
||||
BOOST_CHECK_EQUAL(o_int4, i_int4);
|
||||
BOOST_CHECK_EQUAL(o_int5, i_int5);
|
||||
BOOST_CHECK_EQUAL(o_int6, i_int6);
|
||||
BOOST_CHECK_EQUAL(o_un7.first, i_un7.first);
|
||||
BOOST_CHECK_EQUAL(o_un7.second, i_un7.second);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_unordered_loads )
|
||||
TEST_CASE("xml_unordered_loads")
|
||||
{
|
||||
test_unordered_loads<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_unordered_loads )
|
||||
TEST_CASE("json_unordered_loads")
|
||||
{
|
||||
test_unordered_loads<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_UNORDERED_LOADS_H_
|
||||
#define CEREAL_TEST_UNORDERED_LOADS_H_
|
||||
#include "common.hpp"
|
||||
|
||||
struct unordered_naming
|
||||
{
|
||||
int x;
|
||||
int xx;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar ) const
|
||||
{
|
||||
ar( CEREAL_NVP(x),
|
||||
CEREAL_NVP(z),
|
||||
CEREAL_NVP(y),
|
||||
CEREAL_NVP(xx) );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar )
|
||||
{
|
||||
ar( x,
|
||||
CEREAL_NVP(y),
|
||||
CEREAL_NVP(z),
|
||||
CEREAL_NVP(xx) );
|
||||
}
|
||||
|
||||
bool operator==( unordered_naming const & other ) const
|
||||
{
|
||||
return x == other.x && xx == other.xx && y == other.y && z == other.z;
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, unordered_naming const & s)
|
||||
{
|
||||
os << "[x: " << s.x << " xx: " << s.xx << " y: " << s.y << " z: " << s.z << "]";
|
||||
return os;
|
||||
}
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_unordered_loads()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
auto rngB = [&](){ return random_value<int>( gen ) % 2 == 0; };
|
||||
auto rngI = [&](){ return random_value<int>( gen ); };
|
||||
auto rngF = [&](){ return random_value<float>( gen ); };
|
||||
auto rngD = [&](){ return random_value<double>( gen ); };
|
||||
auto rngS = [&](){ return random_basic_string<char>( gen ); };
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
auto const name1 = rngS();
|
||||
auto const name2 = rngS();
|
||||
auto const name3 = rngS();
|
||||
auto const name4 = rngS();
|
||||
auto const name5 = rngS();
|
||||
auto const name6 = rngS();
|
||||
auto const name7 = rngS();
|
||||
|
||||
int o_int1 = rngI();
|
||||
double o_double2 = rngD();
|
||||
std::vector<bool> o_vecbool3 = { rngB(), rngB(), rngB(), rngB(), rngB() };
|
||||
int o_int4 = rngI();
|
||||
int o_int5 = rngI();
|
||||
int o_int6 = rngI();
|
||||
std::pair<float, unordered_naming> o_un7;
|
||||
o_un7.first = rngF();
|
||||
o_un7.second.x = rngI();
|
||||
o_un7.second.xx = rngI();
|
||||
o_un7.second.y = rngI();
|
||||
o_un7.second.z = rngI();
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar( cereal::make_nvp( name1, o_int1 ),
|
||||
cereal::make_nvp( name2, o_double2 ),
|
||||
cereal::make_nvp( name3, o_vecbool3 ),
|
||||
cereal::make_nvp( name4, o_int4 ),
|
||||
cereal::make_nvp( name5, o_int5 ),
|
||||
cereal::make_nvp( name6, o_int6 ),
|
||||
cereal::make_nvp( name7, o_un7 ) );
|
||||
}
|
||||
|
||||
decltype(o_int1) i_int1;
|
||||
decltype(o_double2) i_double2;
|
||||
decltype(o_vecbool3) i_vecbool3;
|
||||
decltype(o_int4) i_int4;
|
||||
decltype(o_int5) i_int5;
|
||||
decltype(o_int6) i_int6;
|
||||
decltype(o_un7) i_un7;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar( cereal::make_nvp( name7, i_un7 ),
|
||||
cereal::make_nvp( name2, i_double2 ),
|
||||
cereal::make_nvp( name4, i_int4 ),
|
||||
cereal::make_nvp( name3, i_vecbool3 ),
|
||||
cereal::make_nvp( name1, i_int1 ),
|
||||
cereal::make_nvp( name5, i_int5 ),
|
||||
i_int6 );
|
||||
}
|
||||
|
||||
CHECK_EQ(o_int1, i_int1);
|
||||
CHECK_EQ(o_double2, doctest::Approx(o_double2).epsilon(1e-5));
|
||||
CHECK_EQ(o_vecbool3.size(), i_vecbool3.size());
|
||||
check_collection(i_vecbool3, o_vecbool3);
|
||||
CHECK_EQ(o_int4, i_int4);
|
||||
CHECK_EQ(o_int5, i_int5);
|
||||
CHECK_EQ(o_int6, i_int6);
|
||||
CHECK_EQ(o_un7.first, i_un7.first);
|
||||
CHECK_EQ(o_un7.second, i_un7.second);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_UNORDERED_LOADS_H_
|
||||
Reference in New Issue
Block a user