Esempio n. 1
0
void test_deque()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(int ii=0; ii<100; ++ii)
  {
    std::deque<int> o_poddeque(100);
    for(auto & elem : o_poddeque)
      elem = random_value<int>(gen);

    std::deque<StructInternalSerialize> o_iserdeque(100);
    for(auto & elem : o_iserdeque)
      elem = StructInternalSerialize( random_value<int>(gen), random_value<int>(gen) );

    std::deque<StructInternalSplit> o_ispldeque(100);
    for(auto & elem : o_ispldeque)
      elem = StructInternalSplit( random_value<int>(gen), random_value<int>(gen) );

    std::deque<StructExternalSerialize> o_eserdeque(100);
    for(auto & elem : o_eserdeque)
      elem = StructExternalSerialize( random_value<int>(gen), random_value<int>(gen) );

    std::deque<StructExternalSplit> o_espldeque(100);
    for(auto & elem : o_espldeque)
      elem = StructExternalSplit( random_value<int>(gen), random_value<int>(gen) );

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_poddeque);
      oar(o_iserdeque);
      oar(o_ispldeque);
      oar(o_eserdeque);
      oar(o_espldeque);
    }

    std::deque<int> i_poddeque;
    std::deque<StructInternalSerialize> i_iserdeque;
    std::deque<StructInternalSplit>     i_ispldeque;
    std::deque<StructExternalSerialize> i_eserdeque;
    std::deque<StructExternalSplit>     i_espldeque;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_poddeque);
      iar(i_iserdeque);
      iar(i_ispldeque);
      iar(i_eserdeque);
      iar(i_espldeque);
    }

    CHECK_EQ(i_poddeque.size(),  o_poddeque.size());
    CHECK_EQ(i_iserdeque.size(), o_iserdeque.size());
    CHECK_EQ(i_ispldeque.size(), o_ispldeque.size());
    CHECK_EQ(i_eserdeque.size(), o_eserdeque.size());
    CHECK_EQ(i_espldeque.size(), o_espldeque.size());

    check_collection(i_poddeque,  o_poddeque );
    check_collection(i_iserdeque, o_iserdeque);
    check_collection(i_ispldeque, o_ispldeque);
    check_collection(i_eserdeque, o_eserdeque);
    check_collection(i_espldeque, o_espldeque);
  }
}
Esempio n. 2
0
void test_polymorphic()
{
  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 rngL = [&](){ return random_value<long>( gen ); };
  auto rngF = [&](){ return random_value<float>( gen ); };
  auto rngD = [&](){ return random_value<double>( gen ); };

  for(int ii=0; ii<100; ++ii)
  {
    std::shared_ptr<PolyBase> o_shared = std::make_shared<PolyDerived>( rngI(), rngF(), rngB(), rngD() );
    std::weak_ptr<PolyBase>   o_weak = o_shared;
    std::unique_ptr<PolyBase> o_unique( new PolyDerived( rngI(), rngF(), rngB(), rngD() ) );

    std::shared_ptr<PolyBaseA> o_sharedA = std::make_shared<PolyDerivedD>( random_basic_string<char>(gen),
                                                                           rngD(), rngI(), rngL() );

    std::weak_ptr<PolyBaseA>   o_weakA = o_sharedA;
    std::unique_ptr<PolyBaseA> o_uniqueA( new PolyDerivedD( random_basic_string<char>(gen),
                                                            rngD(), rngI(), rngL() ) );

    auto pda = std::make_shared<PolyDerivedLA>( rngI() );
    pda->vec.emplace_back( std::make_shared<PolyDerivedLA>( rngI() ) );
    std::shared_ptr<PolyLA>   o_sharedLA = pda;

    std::ostringstream os;
    {
      OArchive oar(os);

      oar( o_shared, o_weak, o_unique );
      oar( o_sharedLA );

      oar( o_sharedA, o_weakA, o_uniqueA );
    }

    decltype(o_shared) i_shared;
    decltype(o_weak) i_weak;
    decltype(o_unique) i_unique;

    decltype(o_sharedLA) i_sharedLA;

    decltype(o_sharedA) i_sharedA;
    decltype(o_weakA) i_weakA;
    decltype(o_uniqueA) i_uniqueA;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar( i_shared, i_weak, i_unique );
      iar( i_sharedLA );
      iar( i_sharedA, i_weakA, i_uniqueA );
    }

    auto i_locked = i_weak.lock();
    auto o_locked = o_weak.lock();

    auto i_sharedLA2 = i_sharedLA->shared_from_this();

    auto i_lockedA = i_weakA.lock();
    auto o_lockedA = o_weakA.lock();

    BOOST_CHECK_EQUAL(i_shared.get(), i_locked.get());
    BOOST_CHECK_EQUAL(*((PolyDerived*)i_shared.get()), *((PolyDerived*)o_shared.get()));
    BOOST_CHECK_EQUAL(*((PolyDerived*)i_shared.get()), *((PolyDerived*)i_locked.get()));
    BOOST_CHECK_EQUAL(*((PolyDerived*)i_locked.get()), *((PolyDerived*)o_locked.get()));
    BOOST_CHECK_EQUAL(*((PolyDerived*)i_unique.get()), *((PolyDerived*)o_unique.get()));

    BOOST_CHECK_EQUAL(*((PolyDerivedLA*)i_sharedLA.get()), *((PolyDerivedLA*)o_sharedLA.get()));
    BOOST_CHECK_EQUAL(*((PolyDerivedLA*)i_sharedLA2.get()), *((PolyDerivedLA*)o_sharedLA.get()));

    BOOST_CHECK_EQUAL(i_sharedA.get(), i_lockedA.get());
    BOOST_CHECK_EQUAL(*dynamic_cast<PolyDerivedD*>(i_sharedA.get()), *dynamic_cast<PolyDerivedD*>(o_sharedA.get()));
    BOOST_CHECK_EQUAL(*dynamic_cast<PolyDerivedD*>(i_sharedA.get()), *dynamic_cast<PolyDerivedD*>(i_lockedA.get()));
    BOOST_CHECK_EQUAL(*dynamic_cast<PolyDerivedD*>(i_lockedA.get()), *dynamic_cast<PolyDerivedD*>(o_lockedA.get()));
    BOOST_CHECK_EQUAL(*dynamic_cast<PolyDerivedD*>(i_uniqueA.get()), *dynamic_cast<PolyDerivedD*>(o_uniqueA.get()));
  }
}
Esempio n. 3
0
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);
  }
}
Esempio n. 4
0
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);
  }
}
Esempio n. 5
0
int main( int argc, char **argv )
{
    foo = new Foo;

    TestThread threads[NTHREADS];
    lunchbox::Clock clock;
    for( size_t i=0; i<NTHREADS; ++i )
        TEST( threads[i].start( ));

    for( size_t i=0; i<NTHREADS; ++i )
        TEST( threads[i].join( ));

    const float time = clock.getTimef();
    std::cout << time << " ms for " << 3*NREFS << " lunchbox::RefPtr operations"
              << " in " << NTHREADS << " threads (" 
              << time/(3*NREFS*NTHREADS)*1000000 << "ns/op)" << std::endl;

    TEST( foo->getRefCount() == 1 );

#ifdef LUNCHBOX_USE_BOOST
    bFoo = new Foo;
    BThread bThreads[NTHREADS];
    clock.reset();
    for( size_t i=0; i<NTHREADS; ++i )
        TEST( bThreads[i].start( ));

    for( size_t i=0; i<NTHREADS; ++i )
        TEST( bThreads[i].join( ));

    const float bTime = clock.getTimef();
    std::cout << bTime << " ms for " << 3*NREFS << " boost::intrusive_ptr ops "
              << "in " << NTHREADS << " threads ("
              << bTime/(3*NREFS*NTHREADS)*1000000 << "ns/op)" << std::endl;

    TEST( bFoo->getRefCount() == 1 );

    boost::intrusive_ptr< Foo > boostFoo( foo.get( ));
    TEST( foo->getRefCount() == 2 );
    
    boostFoo = 0;
    TEST( foo->getRefCount() == 1 );

    bBar = BarPtr( new Bar );
    BarThread barThreads[NTHREADS];

    clock.reset();
    for( size_t i=0; i<NTHREADS; ++i )
        TEST( barThreads[i].start( ));

    for( size_t i=0; i<NTHREADS; ++i )
        TEST( barThreads[i].join( ));

    const float barTime = clock.getTimef();
    std::cout << barTime << " ms for " << 3*NREFS <<" boost::shared_ptr ops in "
              << NTHREADS << " threads (" << barTime/(3*NREFS*NTHREADS)*1000000
              << "ns/op)" << std::endl;

    bBar = boost::make_shared< Bar >();
    clock.reset();
    for( size_t i=0; i<NTHREADS; ++i )
        TEST( barThreads[i].start( ));

    for( size_t i=0; i<NTHREADS; ++i )
        TEST( barThreads[i].join( ));

    const float barTime2 = clock.getTimef();
    std::cout << barTime2 << " ms for " << 3*NREFS<<" boost::shared_ptr ops in "
              << NTHREADS << " threads (" << barTime2/(3*NREFS*NTHREADS)*1000000
              << "ns/op) using make_shared" << std::endl;

    foo = 0;

    FooPtr inFoo1 = new Foo;
    TEST( inFoo1->getRefCount() == 1 );
    FooPtr inFoo2 = inFoo1;
    TEST( inFoo2->getRefCount() == 2 );
    FooPtr outFoo1;
    std::stringstream stream;
    boost::archive::text_oarchive oar( stream );
    oar & inFoo1;
    boost::archive::text_iarchive iar( stream );
    iar & outFoo1;
    TEST( outFoo1->getRefCount() == 1 );
    FooPtr outFoo2 = outFoo1;
    TEST( outFoo2->getRefCount() == 2 );
#endif

    return EXIT_SUCCESS;
}
Esempio n. 6
0
void test_vector()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(int ii=0; ii<100; ++ii)
  {
    std::vector<int> o_podvector(100);
    for(auto & elem : o_podvector)
      elem = random_value<int>(gen);

    std::vector<bool> o_boolvector; o_boolvector.resize(100);
    for( size_t i = 0; i < 100; ++i )
      o_boolvector[i] = (random_value<int>(gen) % 2) == 0;

    std::vector<StructInternalSerialize> o_iservector(100);
    for(auto & elem : o_iservector)
      elem = StructInternalSerialize( random_value<int>(gen), random_value<int>(gen) );

    std::vector<StructInternalSplit> o_isplvector(100);
    for(auto & elem : o_isplvector)
      elem = StructInternalSplit( random_value<int>(gen), random_value<int>(gen) );

    std::vector<StructExternalSerialize> o_eservector(100);
    for(auto & elem : o_eservector)
      elem = StructExternalSerialize( random_value<int>(gen), random_value<int>(gen) );

    std::vector<StructExternalSplit> o_esplvector(100);
    for(auto & elem : o_esplvector)
      elem = StructExternalSplit( random_value<int>(gen), random_value<int>(gen) );

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_podvector);
      oar(o_boolvector);
      oar(o_iservector);
      oar(o_isplvector);
      oar(o_eservector);
      oar(o_esplvector);
    }

    std::vector<int> i_podvector;
    std::vector<bool> i_boolvector;
    std::vector<StructInternalSerialize> i_iservector;
    std::vector<StructInternalSplit>     i_isplvector;
    std::vector<StructExternalSerialize> i_eservector;
    std::vector<StructExternalSplit>     i_esplvector;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_podvector);
      iar(i_boolvector);
      iar(i_iservector);
      iar(i_isplvector);
      iar(i_eservector);
      iar(i_esplvector);
    }

    BOOST_CHECK_EQUAL(i_podvector.size(),  o_podvector.size());
    BOOST_CHECK_EQUAL(i_boolvector.size(),  o_boolvector.size());
    BOOST_CHECK_EQUAL(i_iservector.size(), o_iservector.size());
    BOOST_CHECK_EQUAL(i_isplvector.size(), o_isplvector.size());
    BOOST_CHECK_EQUAL(i_eservector.size(), o_eservector.size());
    BOOST_CHECK_EQUAL(i_esplvector.size(), o_esplvector.size());

    BOOST_CHECK_EQUAL_COLLECTIONS(i_podvector.begin(),    i_podvector.end(),    o_podvector.begin(),  o_podvector.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_boolvector.begin(),    i_boolvector.end(),    o_boolvector.begin(),  o_boolvector.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_iservector.begin(),   i_iservector.end(),   o_iservector.begin(), o_iservector.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_isplvector.begin(),   i_isplvector.end(),   o_isplvector.begin(), o_isplvector.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_eservector.begin(),   i_eservector.end(),   o_eservector.begin(), o_eservector.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_esplvector.begin(),   i_esplvector.end(),   o_esplvector.begin(), o_esplvector.end());
  }
}
Esempio n. 7
0
template <class IArchive, class OArchive> inline
void test_valarray()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for (int ii = 0; ii<100; ++ii)
  {
    std::valarray<int> o_podvalarray(100);
    for (auto & elem : o_podvalarray)
      elem = random_value<int>(gen);

    std::valarray<StructInternalSerialize> o_iservalarray(100);
    for (auto & elem : o_iservalarray)
      elem = StructInternalSerialize(random_value<int>(gen), random_value<int>(gen));

    std::valarray<StructInternalSplit> o_isplvalarray(100);
    for (auto & elem : o_isplvalarray)
      elem = StructInternalSplit(random_value<int>(gen), random_value<int>(gen));

    std::valarray<StructExternalSerialize> o_eservalarray(100);
    for (auto & elem : o_eservalarray)
      elem = StructExternalSerialize(random_value<int>(gen), random_value<int>(gen));

    std::valarray<StructExternalSplit> o_esplvalarray(100);
    for (auto & elem : o_esplvalarray)
      elem = StructExternalSplit(random_value<int>(gen), random_value<int>(gen));

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_podvalarray);
      oar(o_iservalarray);
      oar(o_isplvalarray);
      oar(o_eservalarray);
      oar(o_esplvalarray);
    }

    std::valarray<int> i_podvalarray;
    std::valarray<StructInternalSerialize> i_iservalarray;
    std::valarray<StructInternalSplit>     i_isplvalarray;
    std::valarray<StructExternalSerialize> i_eservalarray;
    std::valarray<StructExternalSplit>     i_esplvalarray;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_podvalarray);
      iar(i_iservalarray);
      iar(i_isplvalarray);
      iar(i_eservalarray);
      iar(i_esplvalarray);
    }

    CHECK_EQ(i_podvalarray.size(), o_podvalarray.size());
    CHECK_EQ(i_iservalarray.size(), o_iservalarray.size());
    CHECK_EQ(i_isplvalarray.size(), o_isplvalarray.size());
    CHECK_EQ(i_eservalarray.size(), o_eservalarray.size());
    CHECK_EQ(i_esplvalarray.size(), o_esplvalarray.size());

    check_collection(i_podvalarray , o_podvalarray );
    check_collection(i_iservalarray, o_iservalarray);
    check_collection(i_isplvalarray, o_isplvalarray);
    check_collection(i_eservalarray, o_eservalarray);
    check_collection(i_esplvalarray, o_esplvalarray);
  }
}
Esempio n. 8
0
 static void load( std::istringstream & is, T & data )
 {
   cereal::BinaryInputArchive iar(is);
   iar(data);
 }
Esempio n. 9
0
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) };

    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_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_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_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(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);
  }
}
Esempio n. 10
0
void test_memory_load_construct()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(int ii=0; ii<100; ++ii)
  {
    auto o_shared1 = std::make_shared<OneLA>( random_value<int>(gen) );
    auto o_shared2 = std::make_shared<TwoLA>( random_value<int>(gen) );
    std::unique_ptr<OneLA> o_unique1( new OneLA( random_value<int>(gen) ) );
    std::unique_ptr<TwoLA> o_unique2( new TwoLA( random_value<int>(gen) ) );
    auto o_shared3 = std::make_shared<ThreeLA>( random_value<int>(gen) );
    auto o_shared1v = std::make_shared<OneLAVersioned>( random_value<int>(gen) );
    auto o_shared2v = std::make_shared<TwoLAVersioned>( random_value<int>(gen) );

    std::ostringstream os;
    {
      OArchive oar(os);

      oar( o_shared1 );
      oar( o_shared2 );
      oar( o_unique1 );
      oar( o_unique2 );
      oar( o_shared3 );
      oar( o_shared1v );
      oar( o_shared2v );
    }

    o_shared3->shared_from_this(); // tests github issue #68

    decltype(o_shared1) i_shared1;
    decltype(o_shared2) i_shared2;
    decltype(o_unique1) i_unique1;
    decltype(o_unique2) i_unique2;
    decltype(o_shared3) i_shared3;
    decltype(o_shared1v) i_shared1v;
    decltype(o_shared2v) i_shared2v;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar( i_shared1 );
      iar( i_shared2 );
      iar( i_unique1 );
      iar( i_unique2 );
      iar( i_shared3 );
      iar( i_shared1v );
      iar( i_shared2v );
    }

    BOOST_CHECK_EQUAL( *o_shared1, *i_shared1 );
    BOOST_CHECK_EQUAL( *o_shared2, *i_shared2 );
    BOOST_CHECK_EQUAL( *o_unique1, *i_unique1 );
    BOOST_CHECK_EQUAL( *o_unique2, *i_unique2 );
    BOOST_CHECK_EQUAL( *o_shared3, *i_shared3 );
    BOOST_CHECK_EQUAL( *o_shared1v, *i_shared1v );
    BOOST_CHECK_EQUAL(i_shared1v->v, 13u);
    BOOST_CHECK_EQUAL( *o_shared2v, *i_shared2v );
    BOOST_CHECK_EQUAL(i_shared2v->v, 1u);

    auto i_shared3_2 = i_shared3->shared_from_this();
    BOOST_CHECK_EQUAL( *o_shared3, *i_shared3_2 );
  }
}
Esempio n. 11
0
template <class IArchive, class OArchive> inline
void test_unordered_map()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(int ii=0; ii<100; ++ii)
  {
    std::unordered_map<std::string, int> o_podunordered_map;
    for(int j=0; j<100; ++j)
      o_podunordered_map.insert({random_value<std::string>(gen), random_value<int>(gen)});

    std::unordered_map<uint16_t, StructInternalSerialize> o_iserunordered_map;
    for(int j=0; j<100; ++j)
      o_iserunordered_map.insert({random_value<uint16_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});

    std::unordered_map<uint16_t, StructInternalSplit> o_isplunordered_map;
    for(int j=0; j<100; ++j)
      o_isplunordered_map.insert({random_value<uint16_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});

    std::unordered_map<uint32_t, StructExternalSerialize> o_eserunordered_map;
    for(int j=0; j<100; ++j)
      o_eserunordered_map.insert({random_value<uint32_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});

    std::unordered_map<int8_t, StructExternalSplit> o_esplunordered_map;
    for(int j=0; j<100; ++j)
      o_esplunordered_map.insert({random_value<char>(gen),  { random_value<int>(gen), random_value<int>(gen) }});

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_podunordered_map);
      oar(o_iserunordered_map);
      oar(o_isplunordered_map);
      oar(o_eserunordered_map);
      oar(o_esplunordered_map);
    }

    std::unordered_map<std::string, int> i_podunordered_map;
    std::unordered_map<uint16_t, StructInternalSerialize>   i_iserunordered_map;
    std::unordered_map<uint16_t, StructInternalSplit>        i_isplunordered_map;
    std::unordered_map<uint32_t, StructExternalSerialize> i_eserunordered_map;
    std::unordered_map<int8_t, StructExternalSplit>       i_esplunordered_map;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_podunordered_map);
      iar(i_iserunordered_map);
      iar(i_isplunordered_map);
      iar(i_eserunordered_map);
      iar(i_esplunordered_map);
    }

    for(auto const & p : i_podunordered_map)
    {
      auto v = o_podunordered_map.find(p.first);
      CHECK_NE(v, o_podunordered_map.end());
      CHECK_EQ(p.second, v->second);
    }

    for(auto const & p : i_iserunordered_map)
    {
      auto v = o_iserunordered_map.find(p.first);
      CHECK_NE(v, o_iserunordered_map.end());
      CHECK_EQ(p.second, v->second);
    }

    for(auto const & p : i_isplunordered_map)
    {
      auto v = o_isplunordered_map.find(p.first);
      CHECK_NE(v, o_isplunordered_map.end());
      CHECK_EQ(p.second, v->second);
    }

    for(auto const & p : i_eserunordered_map)
    {
      auto v = o_eserunordered_map.find(p.first);
      CHECK_NE(v, o_eserunordered_map.end());
      CHECK_EQ(p.second, v->second);
    }

    for(auto const & p : i_esplunordered_map)
    {
      auto v = o_esplunordered_map.find(p.first);
      CHECK_NE(v, o_esplunordered_map.end());
      CHECK_EQ(p.second, v->second);
    }
  }
}
Esempio n. 12
0
void test_atomic()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(int ii=0; ii<100; ++ii)
  {
    std::atomic<bool> o_ab(std::uniform_int_distribution<int>(0,1)(gen));
    std::atomic<signed char> o_asc(std::uniform_int_distribution<signed char>(
      std::numeric_limits<signed char>::min(),
      std::numeric_limits<signed char>::max()
    )(gen));
    std::atomic<unsigned short> o_aus(std::uniform_int_distribution<unsigned short>(
      std::numeric_limits<unsigned short>::min(),
      std::numeric_limits<unsigned short>::max()
    )(gen));
    std::atomic<int> o_asi(std::uniform_int_distribution<int>(
      std::numeric_limits<int>::min(),
      std::numeric_limits<int>::max()
    )(gen));
    std::atomic<long> o_asl(std::uniform_int_distribution<long>(
      std::numeric_limits<long>::min(),
      std::numeric_limits<long>::max()
    )(gen));
    std::atomic<unsigned long long> o_aull(std::uniform_int_distribution<unsigned long long>(
      std::numeric_limits<unsigned long long>::min(),
      std::numeric_limits<unsigned long long>::max()
    )(gen));

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_ab);
      oar(o_asc);
      oar(o_aus);
      oar(o_asi);
      oar(o_asl);
      oar(o_aull);
    }

    std::atomic<bool> i_ab;
    std::atomic<signed char> i_asc;
    std::atomic<unsigned short> i_aus;
    std::atomic<int> i_asi;
    std::atomic<long> i_asl;
    std::atomic<unsigned long long> i_aull;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_ab);
      iar(i_asc);
      iar(i_aus);
      iar(i_asi);
      iar(i_asl);
      iar(i_aull);
    }

    BOOST_CHECK_EQUAL(o_ab.load(),i_ab.load());
    BOOST_CHECK_EQUAL(o_asc.load(),i_asc.load());
    BOOST_CHECK_EQUAL(o_aus.load(),i_aus.load());
    BOOST_CHECK_EQUAL(o_asi.load(),i_asi.load());
    BOOST_CHECK_EQUAL(o_asl.load(),i_asl.load());
    BOOST_CHECK_EQUAL(o_aull.load(),i_aull.load());
  }
}
Esempio n. 13
0
 static void load( std::istringstream & is, T & data )
 {
   boost::archive::binary_iarchive iar(is);
   iar & data;
 }
Esempio n. 14
0
template <class IArchive, class OArchive> inline
void test_map()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(int ii=0; ii<100; ++ii)
  {
    std::map<size_t, std::vector<StructInternalSerialize>> o_vectormap;
    for(int j=0; j<10; ++j)
    {
      size_t id = random_value<size_t>(gen);
      for(int k=0; k<100; ++k)
        o_vectormap[id].emplace_back(random_value<int>(gen), random_value<int>(gen));
    }

    std::map<std::string, int> o_podmap;
    for(int j=0; j<100; ++j)
      o_podmap.insert({random_value<std::string>(gen), random_value<int>(gen)});

    std::map<int, StructInternalSerialize> o_isermap;
    for(int j=0; j<100; ++j)
      o_isermap.insert({random_value<int>(gen), { random_value<int>(gen), random_value<int>(gen) }});

    std::map<int, StructInternalSplit> o_isplmap;
    for(int j=0; j<100; ++j)
      o_isplmap.insert({random_value<int>(gen), { random_value<int>(gen), random_value<int>(gen) }});

    std::map<uint32_t, StructExternalSerialize> o_esermap;
    for(int j=0; j<100; ++j)
      o_esermap.insert({random_value<uint32_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});

    std::map<int8_t, StructExternalSplit> o_esplmap;
    for(int j=0; j<100; ++j)
      o_esplmap.insert({random_value<char>(gen),  { random_value<int>(gen), random_value<int>(gen) }});

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_vectormap);
      oar(o_podmap);
      oar(o_isermap);
      oar(o_isplmap);
      oar(o_esermap);
      oar(o_esplmap);
    }

    std::map<size_t, std::vector<StructInternalSerialize>> i_vectormap;
    std::map<std::string, int> i_podmap;
    std::map<int, StructInternalSerialize>   i_isermap;
    std::map<int, StructInternalSplit>        i_isplmap;
    std::map<uint32_t, StructExternalSerialize> i_esermap;
    std::map<int8_t, StructExternalSplit>       i_esplmap;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_vectormap);
      iar(i_podmap);
      iar(i_isermap);
      iar(i_isplmap);
      iar(i_esermap);
      iar(i_esplmap);
    }

    CHECK_EQ(i_vectormap.size(), o_vectormap.size());
    auto o_v_it = o_vectormap.begin();
    auto i_v_it = i_vectormap.begin();
    for(;o_v_it != o_vectormap.end(); ++o_v_it, ++i_v_it)
    {
      CHECK_EQ(i_v_it->second.size(), o_v_it->second.size());
      check_collection(i_v_it->second, o_v_it->second);
    }

    check_collection(i_podmap,  o_podmap);
    check_collection(i_isermap, o_isermap);
    check_collection(i_isplmap, o_isplmap);
    check_collection(i_esermap, o_esermap);
    check_collection(i_esplmap, o_esplmap);
  }
}
Esempio n. 15
0
void test_pod()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(size_t i=0; i<100; ++i)
  {
    bool          const o_bool   = random_value<uint8_t>(gen) % 2 ? true : false;
    char          const o_char   = random_value<char>(gen);
    unsigned char const o_uchar  = random_value<unsigned char>(gen);
    uint8_t       const o_uint8  = random_value<uint8_t>(gen);
    int8_t        const o_int8   = random_value<int8_t>(gen);
    uint16_t      const o_uint16 = random_value<uint16_t>(gen);
    int16_t       const o_int16  = random_value<int16_t>(gen);
    uint32_t      const o_uint32 = random_value<uint32_t>(gen);
    int32_t       const o_int32  = random_value<int32_t>(gen);
    uint64_t      const o_uint64 = random_value<uint64_t>(gen);
    int64_t       const o_int64  = random_value<int64_t>(gen);
    float         const o_float  = random_value<float>(gen);
    double        const o_double = random_value<double>(gen);

    long double const o_long_double = random_value<long double>(gen);
    long const o_long = random_value<long>(gen);
    unsigned long const o_ulong = random_value<unsigned long>(gen);
    long long const o_long_long = random_value<long long>(gen);
    unsigned long long const o_ulong_long = random_value<unsigned long long>(gen);

    std::ostringstream os;
    {
      OArchive oar(os);
      oar(o_bool);
      oar(o_char);
      oar(o_uchar);
      oar(o_uint8);
      oar(o_int8);
      oar(o_uint16);
      oar(o_int16);
      oar(o_uint32);
      oar(o_int32);
      oar(o_uint64);
      oar(o_int64);
      oar(o_float);
      oar(o_double);
      oar(o_long_double);
      oar(o_long);
      oar(o_ulong);
      oar(o_long_long);
      oar(o_ulong_long);
    }

    bool          i_bool                       = false;
    char          i_char                       = 0;
    unsigned char i_uchar                      = 0;
    uint8_t       i_uint8                      = 0;
    int8_t        i_int8                       = 0;
    uint16_t      i_uint16                     = 0;
    int16_t       i_int16                      = 0;
    uint32_t      i_uint32                     = 0;
    int32_t       i_int32                      = 0;
    uint64_t      i_uint64                     = 0;
    int64_t       i_int64                      = 0;
    float         i_float                      = 0;
    double        i_double                     = 0;

    long double i_long_double       = 0;
    long i_long                     = 0;
    unsigned long i_ulong           = 0;
    long long i_long_long           = 0;
    unsigned long long i_ulong_long = 0;

    std::istringstream is(os.str());
    {
      IArchive iar(is);
      iar(i_bool);
      iar(i_char);
      iar(i_uchar);
      iar(i_uint8);
      iar(i_int8);
      iar(i_uint16);
      iar(i_int16);
      iar(i_uint32);
      iar(i_int32);
      iar(i_uint64);
      iar(i_int64);
      iar(i_float);
      iar(i_double);
      iar(i_long_double);
      iar(i_long);
      iar(i_ulong);
      iar(i_long_long);
      iar(i_ulong_long);
    }

    BOOST_CHECK_EQUAL(i_bool   , o_bool);
    BOOST_CHECK_EQUAL(i_char   , o_char);
    BOOST_CHECK_EQUAL(i_uchar  , o_uchar);
    BOOST_CHECK_EQUAL(i_uint8  , o_uint8);
    BOOST_CHECK_EQUAL(i_int8   , o_int8);
    BOOST_CHECK_EQUAL(i_uint16 , o_uint16);
    BOOST_CHECK_EQUAL(i_int16  , o_int16);
    BOOST_CHECK_EQUAL(i_uint32 , o_uint32);
    BOOST_CHECK_EQUAL(i_int32  , o_int32);
    BOOST_CHECK_EQUAL(i_uint64 , o_uint64);
    BOOST_CHECK_EQUAL(i_int64  , o_int64);
    BOOST_CHECK_CLOSE(i_float  , o_float,  (float)1e-5);
    BOOST_CHECK_CLOSE(i_double , o_double, 1e-5);

    BOOST_CHECK_CLOSE(i_long_double, o_long_double, 1e-5);
    BOOST_CHECK_EQUAL(i_long,        o_long);
    BOOST_CHECK_EQUAL(i_ulong,       o_ulong);
    BOOST_CHECK_EQUAL(i_long_long,   o_long_long);
    BOOST_CHECK_EQUAL(i_ulong_long,  o_ulong_long);
  }
}
Esempio n. 16
0
void test_stack()
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(int ii=0; ii<100; ++ii)
  {
    std::stack<int> o_podstack;
    for(int j=0; j<100; ++j)
      o_podstack.push(random_value<int>(gen));

    std::stack<StructInternalSerialize> o_iserstack;
    for(int j=0; j<100; ++j)
      o_iserstack.push({ random_value<int>(gen), random_value<int>(gen) });

    std::stack<StructInternalSplit> o_isplstack;
    for(int j=0; j<100; ++j)
      o_isplstack.push({ random_value<int>(gen), random_value<int>(gen) });

    std::stack<StructExternalSerialize> o_eserstack;
    for(int j=0; j<100; ++j)
      o_eserstack.push({ random_value<int>(gen), random_value<int>(gen) });

    std::stack<StructExternalSplit> o_esplstack;
    for(int j=0; j<100; ++j)
      o_esplstack.push({ random_value<int>(gen), random_value<int>(gen) });

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_podstack);
      oar(o_iserstack);
      oar(o_isplstack);
      oar(o_eserstack);
      oar(o_esplstack);
    }

    std::stack<int> i_podstack;
    std::stack<StructInternalSerialize> i_iserstack;
    std::stack<StructInternalSplit>     i_isplstack;
    std::stack<StructExternalSerialize> i_eserstack;
    std::stack<StructExternalSplit>     i_esplstack;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_podstack);
      iar(i_iserstack);
      iar(i_isplstack);
      iar(i_eserstack);
      iar(i_esplstack);
    }

    auto & i_podstack_c  = cereal::stack_detail::container(i_podstack);
    auto & i_iserstack_c = cereal::stack_detail::container(i_iserstack);
    auto & i_isplstack_c = cereal::stack_detail::container(i_isplstack);
    auto & i_eserstack_c = cereal::stack_detail::container(i_eserstack);
    auto & i_esplstack_c = cereal::stack_detail::container(i_esplstack);

    auto & o_podstack_c  = cereal::stack_detail::container(o_podstack);
    auto & o_iserstack_c = cereal::stack_detail::container(o_iserstack);
    auto & o_isplstack_c = cereal::stack_detail::container(o_isplstack);
    auto & o_eserstack_c = cereal::stack_detail::container(o_eserstack);
    auto & o_esplstack_c = cereal::stack_detail::container(o_esplstack);

    BOOST_CHECK_EQUAL_COLLECTIONS(i_podstack_c.begin(),    i_podstack_c.end(),    o_podstack_c.begin(),  o_podstack_c.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_iserstack_c.begin(),   i_iserstack_c.end(),   o_iserstack_c.begin(), o_iserstack_c.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_isplstack_c.begin(),   i_isplstack_c.end(),   o_isplstack_c.begin(), o_isplstack_c.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_eserstack_c.begin(),   i_eserstack_c.end(),   o_eserstack_c.begin(), o_eserstack_c.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(i_esplstack_c.begin(),   i_esplstack_c.end(),   o_esplstack_c.begin(), o_esplstack_c.end());
  }
}
Esempio n. 17
0
void test_chrono()
{
  for(int ii=0; ii<100; ++ii)
  {
    auto o_timePoint1 = std::chrono::system_clock::now();
    #ifndef CEREAL_OLDER_GCC
    auto o_timePoint2 = std::chrono::steady_clock::now();
    #endif // CEREAL_OLDER_GCC
    auto o_timePoint3 = std::chrono::high_resolution_clock::now();

    auto o_duration1 = std::chrono::system_clock::now() - o_timePoint1;
    #ifndef CEREAL_OLDER_GCC
    auto o_duration2 = std::chrono::steady_clock::now() - o_timePoint2;
    #endif // CEREAL_OLDER_GCC
    auto o_duration3 = std::chrono::high_resolution_clock::now() - o_timePoint3;

    std::ostringstream os;
    {
      OArchive oar(os);

      oar(o_timePoint1);
      #ifndef CEREAL_OLDER_GCC
      oar(o_timePoint2);
      #endif // CEREAL_OLDER_GCC
      oar(o_timePoint3);
      oar(o_duration1);
      #ifndef CEREAL_OLDER_GCC
      oar(o_duration2);
      #endif // CEREAL_OLDER_GCC
      oar(o_duration3);
    }

    decltype(o_timePoint1) i_timePoint1;
    #ifndef CEREAL_OLDER_GCC
    decltype(o_timePoint2) i_timePoint2;
    #endif // CEREAL_OLDER_GCC
    decltype(o_timePoint3) i_timePoint3;
    decltype(o_duration1) i_duration1;
    #ifndef CEREAL_OLDER_GCC
    decltype(o_duration2) i_duration2;
    #endif // CEREAL_OLDER_GCC
    decltype(o_duration3) i_duration3;

    std::istringstream is(os.str());
    {
      IArchive iar(is);

      iar(i_timePoint1);
      #ifndef CEREAL_OLDER_GCC
      iar(i_timePoint2);
      #endif // CEREAL_OLDER_GCC
      iar(i_timePoint3);
      iar(i_duration1);
      #ifndef CEREAL_OLDER_GCC
      iar(i_duration2);
      #endif // CEREAL_OLDER_GCC
      iar(i_duration3);
    }

    BOOST_CHECK( o_timePoint1 == i_timePoint1 );
    #ifndef CEREAL_OLDER_GCC
    BOOST_CHECK( o_timePoint2 == i_timePoint2 );
    #endif // CEREAL_OLDER_GCC
    BOOST_CHECK( o_timePoint3 == i_timePoint3 );
    BOOST_CHECK( o_duration1 == i_duration1 );
    #ifndef CEREAL_OLDER_GCC
    BOOST_CHECK( o_duration2 == i_duration2 );
    #endif // CEREAL_OLDER_GCC
    BOOST_CHECK( o_duration3 == i_duration3 );
  }
}