Ticket #9601: 0001-Cleaned-up-some-tab-space-for-consistency.patch

File 0001-Cleaned-up-some-tab-space-for-consistency.patch, 5.2 KB (added by Brandon Kohn, 9 years ago)

Added new cycle unit-test with multiple base types.

  • test/Jamfile.v2

    From bed43d7010457543500c84cd40568ba157807b83 Mon Sep 17 00:00:00 2001
    From: Brandon Kohn <blkohn@hotmail.com>
    Date: Thu, 23 Jan 2014 14:01:32 -0500
    Subject: [PATCH] Cleaned up some tab/space for consistency. Added new cycle
     test with multiple base types.
    
    ---
     test/Jamfile.v2                                |   5 +-
     test/test_cyclic_ptrs_multiple_inheritance.cpp | 146 +++++++++++++++++++++++++
     2 files changed, 149 insertions(+), 2 deletions(-)
     create mode 100644 test/test_cyclic_ptrs_multiple_inheritance.cpp
    
    diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
    index 84f12dd..c16567c 100644
    a b test-suite "serialization" :  
    6262     [ test-bsl-run_files test_complex ]
    6363     [ test-bsl-run_files test_contained_class : A ]
    6464     [ test-bsl-run_files test_cyclic_ptrs : A ]
    65          [ test-bsl-run_files test_cyclic_ptrs_trac9601 ]
     65     [ test-bsl-run_files test_cyclic_ptrs_trac9601 ]
     66     [ test-bsl-run_files test_cyclic_ptrs_multiple_inheritance ]
    6667     [ test-bsl-run_files test_delete_pointer ]
    6768     [ test-bsl-run_files test_deque : A ]
    6869     [ test-bsl-run_files test_derived ]
    if ! $(BOOST_ARCHIVE_LIST) {  
    122123       
    123124        [ test-bsl-run-no-lib test_iterators ]
    124125        [ test-bsl-run-no-lib test_iterators_base64 ]
    125             [ test-bsl-run-no-lib test_inclusion ]
     126        [ test-bsl-run-no-lib test_inclusion ]
    126127        [ test-bsl-run-no-lib test_smart_cast ]
    127128       
    128129        [ test-bsl-run-no-lib test_utf8_codecvt
  • new file test/test_cyclic_ptrs_multiple_inheritance.cpp

    diff --git a/test/test_cyclic_ptrs_multiple_inheritance.cpp b/test/test_cyclic_ptrs_multiple_inheritance.cpp
    new file mode 100644
    index 0000000..a655767
    - +  
     1///////////////////////////////////////////////////////////////////////////////
     2// test_cyclic_ptrs_multiple_inheritance.cpp
     3//
     4//  (C) Copyright 2014
     5//  Brandon Kohn
     6//
     7//  Distributed under the Boost Software License, Version 1.0. (See
     8//  accompanying file LICENSE_1_0.txt or copy at
     9//  http://www.boost.org/LICENSE_1_0.txt)
     10//
     11#include <boost/config.hpp>
     12
     13#include "test_tools.hpp"
     14
     15#include <boost/serialization/nvp.hpp>
     16#include <boost/serialization/version.hpp>
     17#include <boost/serialization/base_object.hpp>
     18#include <boost/serialization/export.hpp>
     19
     20#include <cstdio> // remove
     21#include <fstream>
     22#include <memory> // auto_ptr
     23
     24#if defined(BOOST_NO_STDC_NAMESPACE)
     25namespace std {
     26    using ::remove;
     27}
     28#endif
     29
     30struct base_a;
     31struct base_b;
     32struct common_ab;
     33
     34struct base_a
     35{
     36    base_a(base_b * ptr = reinterpret_cast<base_b*>(0xDEADBEEF))
     37    : ptr_a(ptr)
     38    {}
     39
     40    virtual ~base_a(){}
     41
     42    base_b * ptr_a;
     43
     44    template <typename Archive>
     45    void serialize(Archive& ar, const unsigned int /*v*/)
     46    {
     47        ar & BOOST_SERIALIZATION_NVP(ptr_a);
     48    }
     49};
     50
     51BOOST_CLASS_VERSION(base_a,1)
     52
     53struct base_b
     54{
     55    base_b(base_a * ptr = reinterpret_cast<base_a*>(0xDEADDEAD))
     56    : ptr_b(ptr)
     57    {}
     58
     59    virtual ~base_b(){}
     60
     61    base_a * ptr_b;
     62
     63    template <typename Archive>
     64    void serialize(Archive& ar, const unsigned int /*v*/)
     65    {
     66        ar & BOOST_SERIALIZATION_NVP(ptr_b);
     67    }
     68};
     69
     70BOOST_CLASS_VERSION(base_b,1)
     71
     72struct common_ab : base_a, base_b
     73{
     74    common_ab()
     75    : base_a()
     76    , base_b()
     77    , ptr(reinterpret_cast<common_ab*>(0xBAADF00D))
     78    {}
     79
     80    virtual ~common_ab(){}
     81
     82    common_ab * ptr;
     83
     84    template <typename Archive>
     85    void serialize(Archive& ar, const unsigned int /*v*/)
     86    {
     87        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(base_a);
     88        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(base_b);
     89        ar & BOOST_SERIALIZATION_NVP(ptr);
     90    }
     91};
     92
     93BOOST_CLASS_VERSION(common_ab,1)
     94BOOST_CLASS_EXPORT(common_ab)
     95
     96//! Create an instance of common_ab where all ptr member variables point to the single instance.
     97std::auto_ptr<common_ab> make_common()
     98{
     99    std::auto_ptr<common_ab> p(new common_ab());
     100    p->ptr = p.get();
     101    p->ptr_a = static_cast<base_b*>(p.get());
     102    p->ptr_b = static_cast<base_a*>(p.get());
     103    return p;
     104}
     105
     106int test_main( int /* argc */, char* /* argv */[] )
     107{
     108    const char * testfile = boost::archive::tmpnam(0);
     109    BOOST_REQUIRE(0 != testfile);
     110
     111    //! Write it.
     112    {
     113        std::auto_ptr<common_ab> store(make_common());
     114         
     115        test_ostream os(testfile, TEST_STREAM_FLAGS);
     116        test_oarchive ar(os, TEST_ARCHIVE_FLAGS);
     117
     118        common_ab* pPtrHldr = store.get();
     119        ar << BOOST_SERIALIZATION_NVP(pPtrHldr);
     120    }
     121
     122    //! Read it.
     123    {
     124        common_ab* pPtrHldr = reinterpret_cast<common_ab*>(0xBAADBAAD);
     125
     126        test_istream is(testfile, TEST_STREAM_FLAGS);
     127        test_iarchive ar(is, TEST_ARCHIVE_FLAGS);
     128
     129        ar >> BOOST_SERIALIZATION_NVP(pPtrHldr);
     130
     131        BOOST_CHECK(0 != pPtrHldr);
     132        if (0 != pPtrHldr)
     133        {
     134            //! Check that all the ptrs are the same object.
     135            BOOST_CHECK(pPtrHldr->ptr == pPtrHldr);
     136            BOOST_CHECK(pPtrHldr->ptr_a == static_cast<base_b*>(pPtrHldr));
     137            BOOST_CHECK(pPtrHldr->ptr_b == static_cast<base_a*>(pPtrHldr));
     138        }
     139
     140        delete pPtrHldr;
     141    }
     142
     143    std::remove(testfile);
     144
     145    return EXIT_SUCCESS;
     146}