From 7f084e8ae89313811c45f94125504e16d3a9d958 Mon Sep 17 00:00:00 2001 From: Brandon Kohn Date: Wed, 22 Jan 2014 17:56:16 -0500 Subject: [PATCH] Added unit-test for regression testing of trac9601 issue. --- test/Jamfile.v2 | 1 + test/test_cyclic_ptrs_trac9601.cpp | 83 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/test_cyclic_ptrs_trac9601.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e335860..84f12dd 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -62,6 +62,7 @@ test-suite "serialization" : [ test-bsl-run_files test_complex ] [ test-bsl-run_files test_contained_class : A ] [ test-bsl-run_files test_cyclic_ptrs : A ] + [ test-bsl-run_files test_cyclic_ptrs_trac9601 ] [ test-bsl-run_files test_delete_pointer ] [ test-bsl-run_files test_deque : A ] [ test-bsl-run_files test_derived ] diff --git a/test/test_cyclic_ptrs_trac9601.cpp b/test/test_cyclic_ptrs_trac9601.cpp new file mode 100644 index 0000000..5b4c3f1 --- /dev/null +++ b/test/test_cyclic_ptrs_trac9601.cpp @@ -0,0 +1,83 @@ +/////////////////////////////////////////////////////////////////////////////// +// test_cyclic_ptrs_trac9601.cpp +// +// (C) Copyright 2014 +// Brandon Kohn +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#include + +#include "test_tools.hpp" + +#include +#include + +#include // remove +#include +#include // auto_ptr + +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std { + using ::remove; +} +#endif + +struct pointer_holder +{ + pointer_holder(pointer_holder* ptr = 0) + : ptr(ptr) + {} + + pointer_holder* ptr; + + template + void serialize(Archive& ar, const unsigned int /*v*/) + { + ar & BOOST_SERIALIZATION_NVP(ptr); + } +}; + +BOOST_CLASS_VERSION(pointer_holder,1) + +int test_main( int /* argc */, char* /* argv */[] ) +{ + const char * testfile = boost::archive::tmpnam(0); + BOOST_REQUIRE(0 != testfile); + + //! Write it. + { + std::auto_ptr store(new pointer_holder()); + store->ptr = store.get(); + + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive ar(os, TEST_ARCHIVE_FLAGS); + + pointer_holder* pPtrHldr = store.get(); + ar << BOOST_SERIALIZATION_NVP(pPtrHldr); + } + + //! Read it. + { + pointer_holder* pPtrHldr = reinterpret_cast(0xBAADF00D); + + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ar(is, TEST_ARCHIVE_FLAGS); + + ar >> BOOST_SERIALIZATION_NVP(pPtrHldr); + + BOOST_CHECK(0 != pPtrHldr); + if (0 != pPtrHldr) + { + BOOST_CHECK(pPtrHldr->ptr == pPtrHldr); + } + + delete pPtrHldr; + } + + std::remove(testfile); + + return EXIT_SUCCESS; +} -- 1.8.0.msysgit.0