Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55325 - trunk/libs/serialization/test
From: ramey_at_[hidden]
Date: 2009-07-31 17:04:57


Author: ramey
Date: 2009-07-31 17:04:56 EDT (Fri, 31 Jul 2009)
New Revision: 55325
URL: http://svn.boost.org/trac/boost/changeset/55325

Log:
Fix test_no_rtti test
extended_type_info system not based on type_id
Added:
   trunk/libs/serialization/test/test_multiple_inheritance.cpp (contents, props changed)
Text files modified:
   trunk/libs/serialization/test/Jamfile.v2 | 3 ++-
   trunk/libs/serialization/test/polymorphic_derived1.cpp | 4 ++--
   trunk/libs/serialization/test/test_diamond.cpp | 4 ++--
   trunk/libs/serialization/test/test_dll_simple.cpp | 14 +++++++++-----
   trunk/libs/serialization/test/test_no_rtti.cpp | 25 ++++++++++++++++++++++---
   5 files changed, 37 insertions(+), 13 deletions(-)

Modified: trunk/libs/serialization/test/Jamfile.v2
==============================================================================
--- trunk/libs/serialization/test/Jamfile.v2 (original)
+++ trunk/libs/serialization/test/Jamfile.v2 2009-07-31 17:04:56 EDT (Fri, 31 Jul 2009)
@@ -82,8 +82,9 @@
      [ test-bsl-run_files test_map : A ]
      [ test-bsl-run_files test_mi ]
      [ test-bsl-run_files test_multiple_ptrs : A ]
+ [ test-bsl-run_files test_multiple_inheritance ]
      [ test-bsl-run_files test_no_rtti
- : polymorphic_base polymorphic_derived1 polymorphic_derived2
+ : polymorphic_base polymorphic_derived1
      ]
      [ test-bsl-run_files test_non_intrusive ]
      [ test-bsl-run_files test_non_default_ctor ]

Modified: trunk/libs/serialization/test/polymorphic_derived1.cpp
==============================================================================
--- trunk/libs/serialization/test/polymorphic_derived1.cpp (original)
+++ trunk/libs/serialization/test/polymorphic_derived1.cpp 2009-07-31 17:04:56 EDT (Fri, 31 Jul 2009)
@@ -14,11 +14,11 @@
 
 #include "polymorphic_derived1.hpp"
 
-BOOST_CLASS_EXPORT(polymorphic_derived1)
-
 const char * polymorphic_derived1::get_key() const {
     return
         boost::serialization::type_info_implementation<
             polymorphic_derived1
>::type::get_const_instance().get_key();
 }
+
+BOOST_CLASS_EXPORT(polymorphic_derived1)

Modified: trunk/libs/serialization/test/test_diamond.cpp
==============================================================================
--- trunk/libs/serialization/test/test_diamond.cpp (original)
+++ trunk/libs/serialization/test/test_diamond.cpp 2009-07-31 17:04:56 EDT (Fri, 31 Jul 2009)
@@ -1,12 +1,12 @@
 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
 // test_diamond.cpp
 
-// (C) Copyright 2002 Vladimir Prus.
+// (C) Copyright 2002-2009 Vladimir Prus and Robert Ramey.
 // Use, modification and distribution is subject to 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)
 
-// test of serialization library for diamond intheritence situations
+// test of serialization library for diamond inheritence situations
 
 #include <cstddef> // NULL
 #include <fstream>

Modified: trunk/libs/serialization/test/test_dll_simple.cpp
==============================================================================
--- trunk/libs/serialization/test/test_dll_simple.cpp (original)
+++ trunk/libs/serialization/test/test_dll_simple.cpp 2009-07-31 17:04:56 EDT (Fri, 31 Jul 2009)
@@ -73,7 +73,7 @@
         test_istream is(testfile, TEST_STREAM_FLAGS);
         boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
         boost::archive::polymorphic_iarchive & pia(ia);
- ia >> boost::serialization::make_nvp("a", a1);
+ pia >> boost::serialization::make_nvp("a", a1);
     }
     BOOST_CHECK_EQUAL(a, a1);
 
@@ -86,7 +86,7 @@
     const char * testfile = boost::archive::tmpnam(NULL);
     BOOST_REQUIRE(NULL != testfile);
 
- const A *a = & A();
+ const A *a = new A;
     A *a1;
     {
         test_ostream os(testfile, TEST_STREAM_FLAGS);
@@ -101,6 +101,7 @@
     BOOST_CHECK_EQUAL(*a, *a1);
 
     std::remove(testfile);
+ delete a;
 }
 
 // simple class pointer with polymorphic archive compiled in dll
@@ -109,7 +110,7 @@
     const char * testfile = boost::archive::tmpnam(NULL);
     BOOST_REQUIRE(NULL != testfile);
 
- const A *a = & A();
+ const A *a = new A;
     A *a1;
     {
         test_ostream os(testfile, TEST_STREAM_FLAGS);
@@ -126,6 +127,7 @@
     BOOST_CHECK_EQUAL(*a, *a1);
 
     std::remove(testfile);
+ delete a;
 }
 
 #include "B.hpp"
@@ -184,7 +186,7 @@
     const char * testfile = boost::archive::tmpnam(NULL);
     BOOST_REQUIRE(NULL != testfile);
 
- const B *b = & B();
+ const B *b = new B;
     B *b1;
     {
         test_ostream os(testfile, TEST_STREAM_FLAGS);
@@ -199,6 +201,7 @@
     BOOST_CHECK_EQUAL(*b, *b1);
 
     std::remove(testfile);
+ delete b;
 }
 
 // derived class pointer with base polymorphic archive compiled in dll
@@ -207,7 +210,7 @@
     const char * testfile = boost::archive::tmpnam(NULL);
     BOOST_REQUIRE(NULL != testfile);
 
- const B *b = & B();
+ const B *b = new B;
     B *b1;
     {
         test_ostream os(testfile, TEST_STREAM_FLAGS);
@@ -224,6 +227,7 @@
     BOOST_CHECK_EQUAL(*b, *b1);
 
     std::remove(testfile);
+ delete b;
 }
 
 

Added: trunk/libs/serialization/test/test_multiple_inheritance.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/test/test_multiple_inheritance.cpp 2009-07-31 17:04:56 EDT (Fri, 31 Jul 2009)
@@ -0,0 +1,125 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_multiple_inheritance.cpp
+
+// (C) Copyright 2009 Robert Ramey.
+// Use, modification and distribution is subject to 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)
+
+// test of serialization library for multiple inheritence situations
+
+#include <cassert>
+#include <fstream>
+
+#include <boost/config.hpp>
+#include <cstdio> // remove
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::remove;
+}
+#endif
+
+#include "test_tools.hpp"
+
+#include <boost/serialization/access.hpp>
+#include <boost/serialization/base_object.hpp>
+#include <boost/serialization/nvp.hpp>
+#include <boost/serialization/export.hpp>
+
+struct Base1 {
+ int m_x;
+ Base1(){}
+ Base1(int x) : m_x(1 + x) {}
+ virtual ~Base1() {}
+ bool operator==(Base1 & rhs) const {
+ return m_x == rhs.m_x;
+ }
+ // serialize
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /* file_version */) {
+ ar & BOOST_SERIALIZATION_NVP(m_x);
+ }
+};
+
+//BOOST_CLASS_EXPORT(Base1)
+
+struct Base2 {
+ int m_x;
+ Base2(){}
+ Base2(int x) : m_x(2 + x) {}
+ virtual ~Base2() {}
+ bool operator==(Base2 & rhs) const {
+ return m_x == rhs.m_x;
+ }
+ // serialize
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /* file_version */) {
+ ar & BOOST_SERIALIZATION_NVP(m_x);
+ }
+};
+
+//BOOST_CLASS_EXPORT(Base2)
+
+struct Sub :
+ public Base1,
+ public Base2
+{
+ int m_x;
+ Sub(){}
+ Sub(int x) :
+ Base1(x),
+ Base2(x),
+ m_x(x)
+ {}
+ bool operator==(Sub & rhs) const {
+ if(! Base2::operator==(rhs))
+ return false;
+ if(! Base1::operator==(rhs))
+ return false;
+ return m_x == rhs.m_x;
+ }
+ virtual ~Sub() {}
+
+ // serialize
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive &ar, const unsigned int /* file_version */)
+ {
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base1);
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base2);
+ ar & BOOST_SERIALIZATION_NVP(m_x);
+ }
+};
+
+BOOST_CLASS_EXPORT(Sub)
+
+int
+test_main( int /* argc */, char* /* argv */[] )
+{
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+ Base2 * pb2;
+ {
+ // serialize
+ pb2 = new Sub(2);
+
+ test_ostream ofs(testfile);
+ test_oarchive oa(ofs);
+ oa << boost::serialization::make_nvp("Base2", pb2);
+ }
+ Base2 * pb2_1;
+ {
+ // de-serialize
+ test_istream ifs(testfile);
+ test_iarchive ia(ifs);
+ ia >> boost::serialization::make_nvp("Base2", pb2_1);
+ }
+ Sub *s1 = dynamic_cast<Sub *>(pb2);
+ BOOST_CHECK(0 != s1);
+ Sub *s2 = dynamic_cast<Sub *>(pb2_1);
+ BOOST_CHECK(0 != s2);
+ BOOST_CHECK(*s1 == *s2);
+ return EXIT_SUCCESS;
+}

Modified: trunk/libs/serialization/test/test_no_rtti.cpp
==============================================================================
--- trunk/libs/serialization/test/test_no_rtti.cpp (original)
+++ trunk/libs/serialization/test/test_no_rtti.cpp 2009-07-31 17:04:56 EDT (Fri, 31 Jul 2009)
@@ -16,6 +16,7 @@
 
 #include <cstddef>
 #include <fstream>
+#include <iostream>
 
 #include <boost/config.hpp>
 #include <cstdio> // remove
@@ -35,11 +36,23 @@
 
 #include <boost/serialization/type_info_implementation.hpp>
 #include <boost/serialization/extended_type_info_no_rtti.hpp>
+#include <boost/serialization/export.hpp>
+#include <boost/serialization/nvp.hpp>
 
 #include "polymorphic_base.hpp"
 #include "polymorphic_derived1.hpp"
-#define POLYMORPHIC_DERIVED2_IMPORT
+
 #include "polymorphic_derived2.hpp"
+BOOST_CLASS_EXPORT(polymorphic_derived2)
+
+template void polymorphic_derived2::serialize(
+ test_oarchive & ar,
+ const unsigned int version
+);
+template void polymorphic_derived2::serialize(
+ test_iarchive & ar,
+ const unsigned int version
+);
 
 // save derived polymorphic class
 void save_derived(const char *testfile)
@@ -50,7 +63,9 @@
     polymorphic_derived1 *rd1 = new polymorphic_derived1;
     polymorphic_derived2 *rd2 = new polymorphic_derived2;
 
+ std::cout << "saving polymorphic_derived1 (no_rtti)\n";
     oa << BOOST_SERIALIZATION_NVP(rd1);
+ std::cout << "saving polymorphic_derived2\n";
     oa << BOOST_SERIALIZATION_NVP(rd2);
 
     // the above opereration registers the derived classes as a side
@@ -58,7 +73,9 @@
     // a base class pointer.
     polymorphic_base *rb1 = rd1;
     polymorphic_base *rb2 = rd2;
+ std::cout << "saving polymorphic_derived1 (no_rtti) through base (no_rtti)\n";
     oa << BOOST_SERIALIZATION_NVP(rb1);
+ std::cout << "saving polymorphic_derived2 through base (no_rtti)\n";
     oa << BOOST_SERIALIZATION_NVP(rb2);
 
     delete rd1;
@@ -74,6 +91,7 @@
     polymorphic_derived1 *rd1 = NULL;
     polymorphic_derived2 *rd2 = NULL;
 
+ std::cout << "loading polymorphic_derived1 (no_rtti)\n";
     ia >> BOOST_SERIALIZATION_NVP(rd1);
 
     BOOST_CHECK_MESSAGE(
@@ -88,8 +106,8 @@
         "restored pointer d1 not of correct type"
     );
 
+ std::cout << "loading polymorphic_derived2\n";
     ia >> BOOST_SERIALIZATION_NVP(rd2);
-
     BOOST_CHECK_MESSAGE(
         boost::serialization::type_info_implementation<
             polymorphic_derived2
@@ -101,13 +119,13 @@
         ,
         "restored pointer d2 not of correct type"
     );
-
     polymorphic_base *rb1 = NULL;
     polymorphic_base *rb2 = NULL;
 
     // the above opereration registers the derived classes as a side
     // effect. Hence, instances can now be correctly serialized through
     // a base class pointer.
+ std::cout << "loading polymorphic_derived1 (no_rtti) through base (no_rtti)\n";
     ia >> BOOST_SERIALIZATION_NVP(rb1);
 
     BOOST_CHECK_MESSAGE(
@@ -127,6 +145,7 @@
         "restored pointer b1 not of correct type"
     );
 
+ std::cout << "loading polymorphic_derived2 through base (no_rtti)\n";
     ia >> BOOST_SERIALIZATION_NVP(rb2);
 
     BOOST_CHECK_MESSAGE(


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