Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58271 - trunk/libs/serialization/test
From: ramey_at_[hidden]
Date: 2009-12-10 12:42:29


Author: ramey
Date: 2009-12-10 12:42:29 EST (Thu, 10 Dec 2009)
New Revision: 58271
URL: http://svn.boost.org/trac/boost/changeset/58271

Log:
1. Fixed memory leak in shared_ptr loading
2. Fixed error in polymorphic archive implementation
Added:
   trunk/libs/serialization/test/test_polymorphic2.cpp (contents, props changed)
   trunk/libs/serialization/test/test_polymorphic2.hpp (contents, props changed)
   trunk/libs/serialization/test/test_polymorphic2imp.cpp (contents, props changed)

Added: trunk/libs/serialization/test/test_polymorphic2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/test/test_polymorphic2.cpp 2009-12-10 12:42:29 EST (Thu, 10 Dec 2009)
@@ -0,0 +1,31 @@
+#include <fstream>
+
+#include "test_tools.hpp"
+
+#include "test_polymorphic2.hpp"
+
+int test_main(int /*argc*/, char* /*argv*/[])
+{
+ A *a = new B();
+ a->i = 3;
+
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa_implementation(os, TEST_ARCHIVE_FLAGS);
+ boost::archive::polymorphic_oarchive & opa = oa_implementation;
+ opa << BOOST_SERIALIZATION_NVP(a);
+ }
+ A *loaded = 0;
+ {
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia_implementation(is, TEST_ARCHIVE_FLAGS);
+ boost::archive::polymorphic_iarchive & ipa = ia_implementation;
+ ipa >> BOOST_SERIALIZATION_NVP(loaded);
+ }
+ BOOST_CHECK(a->i == loaded->i);
+ delete a;
+ delete loaded;
+ return EXIT_SUCCESS;
+}

Added: trunk/libs/serialization/test/test_polymorphic2.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/test/test_polymorphic2.hpp 2009-12-10 12:42:29 EST (Thu, 10 Dec 2009)
@@ -0,0 +1,34 @@
+namespace boost {
+namespace archive {
+ class polymorphic_oarchive;
+ class polymorphic_iarchive;
+}
+}
+
+struct A {
+public:
+ A() {}
+ virtual ~A() {}
+
+ void serialize(
+ boost::archive::polymorphic_oarchive &ar,
+ const unsigned int /*version*/
+ );
+ void serialize(
+ boost::archive::polymorphic_iarchive &ar,
+ const unsigned int /*version*/
+ );
+
+ int i;
+};
+
+struct B : A {
+ void serialize(
+ boost::archive::polymorphic_oarchive &ar,
+ const unsigned int /*version*/
+ );
+ void serialize(
+ boost::archive::polymorphic_iarchive &ar,
+ const unsigned int /*version*/
+ );
+};

Added: trunk/libs/serialization/test/test_polymorphic2imp.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/test/test_polymorphic2imp.cpp 2009-12-10 12:42:29 EST (Thu, 10 Dec 2009)
@@ -0,0 +1,35 @@
+
+#include <boost/serialization/export.hpp>
+#include <boost/archive/polymorphic_oarchive.hpp>
+#include <boost/archive/polymorphic_iarchive.hpp>
+
+#include "test_polymorphic2.hpp"
+
+void A::serialize(
+ boost::archive::polymorphic_oarchive &ar,
+ const unsigned int /*version*/
+){
+ ar & BOOST_SERIALIZATION_NVP(i);
+}
+void A::serialize(
+ boost::archive::polymorphic_iarchive &ar,
+ const unsigned int /*version*/
+){
+ ar & BOOST_SERIALIZATION_NVP(i);
+}
+// note: only the most derived classes need be exported
+// BOOST_CLASS_EXPORT(A)
+
+void B::serialize(
+ boost::archive::polymorphic_oarchive &ar,
+ const unsigned int /*version*/
+){
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
+}
+void B::serialize(
+ boost::archive::polymorphic_iarchive &ar,
+ const unsigned int /*version*/
+){
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
+}
+BOOST_CLASS_EXPORT(B)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk