|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54755 - trunk/libs/serialization/test
From: ramey_at_[hidden]
Date: 2009-07-07 00:04:20
Author: ramey
Date: 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
New Revision: 54755
URL: http://svn.boost.org/trac/boost/changeset/54755
Log:
Fixed misc bugs
void cast
added dll tests
Text files modified:
trunk/libs/serialization/test/A.hpp | 30 +++++++++++++++------
trunk/libs/serialization/test/A.ipp | 9 ++----
trunk/libs/serialization/test/Jamfile.v2 | 45 +++++++++++++++++++++++++++++++--
trunk/libs/serialization/test/base.hpp | 19 ++++++++++---
trunk/libs/serialization/test/derived2.hpp | 20 +++++++++++---
trunk/libs/serialization/test/dll_a.cpp | 4 --
trunk/libs/serialization/test/dll_base.cpp | 18 ++++---------
trunk/libs/serialization/test/dll_derived2.cpp | 36 ++++++++++++++++++---------
trunk/libs/serialization/test/polymorphic_base.cpp | 7 +++++
trunk/libs/serialization/test/polymorphic_base.hpp | 13 ++++++---
trunk/libs/serialization/test/polymorphic_derived2.cpp | 47 +++++++++++++++++++++++++++++------
trunk/libs/serialization/test/polymorphic_derived2.hpp | 33 ++++++++++++++++++------
trunk/libs/serialization/test/test_decl.hpp | 36 ++++++++++++++++++--------
trunk/libs/serialization/test/test_dll_exported.cpp | 40 +++++++++++++++++++++--------
trunk/libs/serialization/test/test_dll_plugin.cpp | 15 +++++++---
trunk/libs/serialization/test/test_dll_simple.cpp | 53 ++++++++++++++++++++++-----------------
trunk/libs/serialization/test/test_exported.cpp | 24 ++++++-----------
trunk/libs/serialization/test/test_shared_ptr.cpp | 1
18 files changed, 309 insertions(+), 141 deletions(-)
Modified: trunk/libs/serialization/test/A.hpp
==============================================================================
--- trunk/libs/serialization/test/A.hpp (original)
+++ trunk/libs/serialization/test/A.hpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -18,6 +18,7 @@
#include <ostream> // for friend output operators
#include <cstddef> // size_t
+#include <string>
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
@@ -41,11 +42,19 @@
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/string.hpp>
-#ifndef DLL_DECL
-#define DLL_DECL
+#include <boost/preprocessor/facilities/empty.hpp>
+
+#include "test_decl.hpp"
+
+#if defined(A_IMPORT)
+ #define DLL_DECL IMPORT_DECL
+#elif defined(A_EXPORT)
+ #define DLL_DECL EXPORT_DECL
+#else
+ #define DLL_DECL(x)
#endif
-class DLL_DECL A
+class DLL_DECL(BOOST_PP_EMPTY()) A
{
private:
friend class boost::serialization::access;
@@ -56,7 +65,7 @@
// reason we can't make abstract.
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
template<class Archive>
- void A::serialize(
+ void serialize(
Archive &ar,
const unsigned int /* file_version */
){
@@ -98,12 +107,13 @@
ar & BOOST_SERIALIZATION_NVP(z);
#endif
}
+ #else
+ template<class Archive>
+ void serialize(
+ Archive &ar,
+ const unsigned int /* file_version */
+ );
#endif
- template<class Archive>
- DLL_DECL void serialize(
- Archive &ar,
- const unsigned int /* file_version */
- );
bool b;
#ifndef BOOST_NO_INT64_T
boost::int64_t f;
@@ -143,4 +153,6 @@
friend std::ostream & operator<<(std::ostream & os, A const & a);
};
+#undef DLL_DECL
+
#endif // BOOST_SERIALIZATION_TEST_A_HPP
Modified: trunk/libs/serialization/test/A.ipp
==============================================================================
--- trunk/libs/serialization/test/A.ipp (original)
+++ trunk/libs/serialization/test/A.ipp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -8,17 +8,14 @@
// See http://www.boost.org for updates, documentation, and revision history.
+#include <boost/detail/workaround.hpp>
#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
-#include "A.hpp"
-
-#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
#include <boost/archive/dinkumware.hpp>
#endif
-#include <boost/serialization/nvp.hpp>
-#include <boost/serialization/string.hpp>
+#include "A.hpp"
template<class Archive>
void A::serialize(
@@ -64,4 +61,4 @@
#endif
}
-#endif // workaround
+#endif // workaround BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
Modified: trunk/libs/serialization/test/Jamfile.v2
==============================================================================
--- trunk/libs/serialization/test/Jamfile.v2 (original)
+++ trunk/libs/serialization/test/Jamfile.v2 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -25,6 +25,40 @@
BOOST_ARCHIVE_LIST = [ modules.peek : BOOST_ARCHIVE_LIST ] ;
+lib dll_a_lib
+ :
+ dll_a.cpp
+ ../build//boost_serialization
+ :
+ <link>shared
+ ;
+
+lib dll_base_lib
+ :
+ dll_base.cpp
+ ../build//boost_serialization
+ :
+ <link>shared
+ ;
+
+lib dll_derived2_lib
+ :
+ dll_derived2.cpp
+ dll_base_lib
+ ../build//boost_serialization
+ :
+ <link>shared
+ ;
+
+lib dll_polymorphic_derived2_lib
+ :
+ polymorphic_derived2.cpp
+ polymorphic_base.cpp
+ ../build//boost_serialization
+ :
+ <link>shared
+ ;
+
test-suite "serialization" :
[ test-bsl-run_files test_array : A ]
[ test-bsl-run_files test_binary ]
@@ -34,11 +68,11 @@
[ test-bsl-run_files test_cyclic_ptrs : A ]
[ test-bsl-run_files test_delete_pointer ]
[ test-bsl-run_files test_deque : A ]
- # [ test-bsl-run_files test_derived ]
+ [ test-bsl-run_files test_derived ]
[ test-bsl-run_files test_derived_class : A ]
[ test-bsl-run_files test_derived_class_ptr : A ]
[ test-bsl-run_files test_diamond ]
- [ test-bsl-run_files test_exported ]
+ [ test-bsl-run_files test_exported : polymorphic_base ]
[ test-bsl-run_files test_class_info_load ]
[ test-bsl-run_files test_class_info_save ]
[ test-bsl-run_files test_object ]
@@ -70,12 +104,17 @@
[ test-bsl-run_files test_new_operator : A ]
[ test-bsl-run_files test_optional ]
[ test-bsl-run_files test_shared_ptr ]
+ [ test-bsl-run_files test_shared_ptr_multi_base ]
[ test-bsl-run_files test_shared_ptr_132 ]
[ test-bsl-run_polymorphic_archive test_polymorphic : test_polymorphic_A A ]
-;
+ ;
if ! $(BOOST_ARCHIVE_LIST) {
test-suite "serialization2" :
+ [ test-bsl-run test_dll_exported : polymorphic_base : dll_polymorphic_derived2_lib : <runtime-link>shared ]
+# [ test-bsl-run test_dll_plugin : : dll_base_lib dll_derived2_lib : <runtime-link>shared ]
+ [ test-bsl-run test_dll_simple : : dll_a_lib : <runtime-link>shared ]
+
[ test-bsl-run test_private_ctor ]
[ test-bsl-run test_reset_object_address : A ]
[ test-bsl-run test_void_cast ]
Modified: trunk/libs/serialization/test/base.hpp
==============================================================================
--- trunk/libs/serialization/test/base.hpp (original)
+++ trunk/libs/serialization/test/base.hpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -18,20 +18,29 @@
#include <boost/serialization/access.hpp>
#include <boost/serialization/assume_abstract.hpp>
+#include <boost/preprocessor/facilities/empty.hpp>
-#ifndef DLL_DECL
-#define DLL_DECL
+#include "test_decl.hpp"
+
+#if defined(BASE_IMPORT)
+ #define DLL_DECL IMPORT_DECL
+#elif defined(BASE_EXPORT)
+ #define DLL_DECL EXPORT_DECL
+#else
+ #define DLL_DECL(x)
#endif
-class DLL_DECL polymorphic_base
+class DLL_DECL(BOOST_PP_EMPTY()) base
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & /* ar */, const unsigned int /* file_version */);
public:
- virtual ~polymorphic_base(){};
+ virtual ~base(){};
};
-BOOST_SERIALIZATION_ASSUME_ABSTRACT(polymorphic_base)
+BOOST_SERIALIZATION_ASSUME_ABSTRACT(base)
+
+#undef DLL_DECL
#endif // BOOST_SERIALIZATION_TEST_BASE_HPP
Modified: trunk/libs/serialization/test/derived2.hpp
==============================================================================
--- trunk/libs/serialization/test/derived2.hpp (original)
+++ trunk/libs/serialization/test/derived2.hpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -19,22 +19,32 @@
#include <boost/serialization/export.hpp>
#include <boost/serialization/access.hpp>
+#define BASE_IMPORT
#include "base.hpp"
-#ifndef DLL_DECL
-#define DLL_DECL
+#include "test_decl.hpp"
+
+#if defined(DERIVED2_IMPORT)
+ #define DLL_DECL IMPORT_DECL
+#elif defined(DERIVED2_EXPORT)
+ #define DLL_DECL EXPORT_DECL
+#else
+ #define DLL_DECL(x)
#endif
-class DLL_DECL polymorphic_derived2 : public polymorphic_base
+class DLL_DECL(BOOST_PP_EMPTY()) derived2 :
+ public base
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int /* file_version */);
public:
- ~polymorphic_derived2(){}
+ ~derived2(){}
};
+#undef DLL_DECL
+
// MWerks users can do this to make their code work
-BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived2)
+BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(base, derived2)
#endif // BOOST_SERIALIZATION_TEST_DERIVED2_HPP
Modified: trunk/libs/serialization/test/dll_a.cpp
==============================================================================
--- trunk/libs/serialization/test/dll_a.cpp (original)
+++ trunk/libs/serialization/test/dll_a.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -8,13 +8,11 @@
// Build a dll which contains the serialization for a class A
// used in testing distribution of serialization code in DLLS
-#include "test_decl.hpp"
-#define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY())
+#define A_EXPORT
#include "A.hpp"
#include "A.ipp"
#include "A.cpp"
-#undef DLL_DECL
// instantiate code for text archives
Modified: trunk/libs/serialization/test/dll_base.cpp
==============================================================================
--- trunk/libs/serialization/test/dll_base.cpp (original)
+++ trunk/libs/serialization/test/dll_base.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -10,17 +10,11 @@
// used in testing distribution of serialization code in DLLS
#include <boost/serialization/export.hpp>
-#include "test_decl.hpp"
-#define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY())
+#define BASE_EXPORT
#include "base.hpp"
-#undef DLL_DECL
-
-// instantiate code for text archives
-
-#include <boost/serialization/nvp.hpp>
template<class Archive>
-void polymorphic_base::serialize(
+void base::serialize(
Archive &ar,
const unsigned int /* file_version */){
}
@@ -43,19 +37,19 @@
// explicit instantiation in this case.
//BOOST_CLASS_EXPORT(polymorphic_base)
-template EXPORT_DECL(void) polymorphic_base::serialize(
+template EXPORT_DECL(void) base::serialize(
boost::archive::text_oarchive & ar,
const unsigned int version
);
-template EXPORT_DECL(void) polymorphic_base::serialize(
+template EXPORT_DECL(void) base::serialize(
boost::archive::text_iarchive & ar,
const unsigned int version
);
-template EXPORT_DECL(void) polymorphic_base::serialize(
+template EXPORT_DECL(void) base::serialize(
boost::archive::polymorphic_oarchive & ar,
const unsigned int version
);
-template EXPORT_DECL(void) polymorphic_base::serialize(
+template EXPORT_DECL(void) base::serialize(
boost::archive::polymorphic_iarchive & ar,
const unsigned int version
);
Modified: trunk/libs/serialization/test/dll_derived2.cpp
==============================================================================
--- trunk/libs/serialization/test/dll_derived2.cpp (original)
+++ trunk/libs/serialization/test/dll_derived2.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -8,35 +8,47 @@
// Build a dll which contains the serialization for a class A
// used in testing distribution of serialization code in DLLS
-#include "test_decl.hpp"
-#define DLL_DECL IMPORT_DECL
-#include "base.hpp"
-#undef DLL_DECL
+#include <boost/serialization/nvp.hpp>
-#define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY())
+#define DERIVED2_EXPORT
#include "derived2.hpp"
-#undef DLL_DECL
-#include <boost/serialization/nvp.hpp>
template<class Archive>
-void polymorphic_derived2::serialize(
+void derived2::serialize(
Archive &ar,
const unsigned int /* file_version */
){
- ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(base);
}
// instantiate code for text archives
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
-// instantiate code for polymorphic archives
+template EXPORT_DECL(void) derived2::serialize(
+ boost::archive::text_oarchive & ar,
+ const unsigned int version
+);
+template EXPORT_DECL(void) derived2::serialize(
+ boost::archive::text_iarchive & ar,
+ const unsigned int version
+);
+
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
+template EXPORT_DECL(void) derived2::serialize(
+ boost::archive::polymorphic_oarchive & ar,
+ const unsigned int version
+);
+template EXPORT_DECL(void) derived2::serialize(
+ boost::archive::polymorphic_iarchive & ar,
+ const unsigned int version
+);
+
// note: export has to be AFTER #includes for all archive classes
#include <boost/serialization/factory.hpp>
-BOOST_SERIALIZATION_FACTORY_0(polymorphic_derived2)
-BOOST_CLASS_EXPORT(polymorphic_derived2)
+BOOST_SERIALIZATION_FACTORY_0(derived2)
+BOOST_CLASS_EXPORT(derived2)
Modified: trunk/libs/serialization/test/polymorphic_base.cpp
==============================================================================
--- trunk/libs/serialization/test/polymorphic_base.cpp (original)
+++ trunk/libs/serialization/test/polymorphic_base.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -12,3 +12,10 @@
#include "polymorphic_base.hpp"
BOOST_CLASS_EXPORT(polymorphic_base)
+
+const char * polymorphic_base::get_key() const{
+ return
+ boost::serialization::type_info_implementation<
+ polymorphic_base
+ >::type::get_const_instance().get_key();
+}
Modified: trunk/libs/serialization/test/polymorphic_base.hpp
==============================================================================
--- trunk/libs/serialization/test/polymorphic_base.hpp (original)
+++ trunk/libs/serialization/test/polymorphic_base.hpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -24,10 +24,15 @@
{
friend class boost::serialization::access;
template<class Archive>
- void serialize(Archive & /* ar */, const unsigned int /* file_version */){
- }
+ void serialize(
+ Archive & /* ar */,
+ const unsigned int /* file_version */
+ ){}
public:
- virtual const char * get_key() const = 0;
+ // note that since this class uses the "no_rtti"
+ // extended_type_info implementation, it MUST
+ // implement this function
+ virtual const char * get_key() const;
virtual ~polymorphic_base(){};
};
@@ -35,7 +40,7 @@
BOOST_CLASS_TYPE_INFO(
polymorphic_base,
- extended_type_info_no_rtti<polymorphic_base>
+ boost::serialization::extended_type_info_no_rtti<polymorphic_base>
)
#endif // POLYMORPHIC_BASE_HPP
Modified: trunk/libs/serialization/test/polymorphic_derived2.cpp
==============================================================================
--- trunk/libs/serialization/test/polymorphic_derived2.cpp (original)
+++ trunk/libs/serialization/test/polymorphic_derived2.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -12,16 +12,47 @@
#include <boost/serialization/extended_type_info_no_rtti.hpp>
#include <boost/serialization/export.hpp>
+#define POLYMORPHIC_DERIVED2_EXPORT
#include "polymorphic_derived2.hpp"
-// note: types which use ...no_rtti MUST be exported
+// instantiate code for text archives
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
+template EXPORT_DECL(void) polymorphic_derived2::serialize(
+ boost::archive::text_oarchive & ar,
+ const unsigned int version
+);
+template EXPORT_DECL(void) polymorphic_derived2::serialize(
+ boost::archive::text_iarchive & ar,
+ const unsigned int version
+);
+
+// instantiate code for polymorphic archives
+#include <boost/archive/polymorphic_iarchive.hpp>
+#include <boost/archive/polymorphic_oarchive.hpp>
+
+template EXPORT_DECL(void) polymorphic_derived2::serialize(
+ boost::archive::polymorphic_oarchive & ar,
+ const unsigned int version
+);
+template EXPORT_DECL(void) polymorphic_derived2::serialize(
+ boost::archive::polymorphic_iarchive & ar,
+ const unsigned int version
+);
+
+// MWerks users can do this to make their code work
+BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived2)
+
+// note: export has to be AFTER #includes for all archive classes
BOOST_CLASS_EXPORT(polymorphic_derived2)
-const char * polymorphic_derived2::get_key() const {
- // use the exported key as the identifier
- return
- boost::serialization::type_info_implementation<
- polymorphic_derived2
- >::type::get_const_instance().get_key();
-}
+// export plug-in not yet working !!!
+#if 0
+#include <boost/serialization/factory.hpp>
+BOOST_SERIALIZATION_FACTORY_0(polymorphic_derived2)
+template
+EXPORT_DECL(polymorphic_derived2 *)
+boost::serialization::factory<polymorphic_derived2, 0>(std::va_list ap);
+#endif
Modified: trunk/libs/serialization/test/polymorphic_derived2.hpp
==============================================================================
--- trunk/libs/serialization/test/polymorphic_derived2.hpp (original)
+++ trunk/libs/serialization/test/polymorphic_derived2.hpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -1,5 +1,5 @@
-#ifndef POLYMORPHIC_DERIVED2_HPP
-#define POLYMORPHIC_DERIVED2_HPP
+#ifndef DERIVED2_HPP
+#define DERIVED2_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
@@ -7,7 +7,7 @@
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// polymorphic_derived1.hpp simple class test
+// derived1.hpp simple class test
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
@@ -24,15 +24,30 @@
#include "polymorphic_base.hpp"
-class polymorphic_derived2 : public polymorphic_base
+#include "test_decl.hpp"
+
+#if defined(POLYMORPHIC_DERIVED2_IMPORT)
+ #define DLL_DECL IMPORT_DECL
+#elif defined(POLYMORPHIC_DERIVED2_EXPORT)
+ #define DLL_DECL EXPORT_DECL
+#else
+ #define DLL_DECL(x)
+#endif
+
+class DLL_DECL(BOOST_PP_EMPTY()) polymorphic_derived2 :
+ public polymorphic_base
{
friend class boost::serialization::access;
template<class Archive>
- void serialize(Archive &ar, const unsigned int /* file_version */){
+ void serialize(
+ Archive &ar,
+ const unsigned int /* file_version */
+ ){
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
}
-public:
- virtual const char * get_key() const ;
+ virtual const char * get_key() const {
+ return "polymorphic_derived2";
+ }
};
// note the mixing of type_info systems is supported.
@@ -41,5 +56,7 @@
boost::serialization::extended_type_info_typeid<polymorphic_derived2>
)
-#endif // POLYMORPHIC_DERIVED2_HPP
+#undef DLL_DECL
+
+#endif // DERIVED2_HPP
Modified: trunk/libs/serialization/test/test_decl.hpp
==============================================================================
--- trunk/libs/serialization/test/test_decl.hpp (original)
+++ trunk/libs/serialization/test/test_decl.hpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -18,27 +18,38 @@
// export if this is our own source, otherwise import:
// usage:
+//
// class header declarations should look something like:
+//
+// #include "test_decl.hpp"
+// #if defined(A_CPP)
+// #define DLL_DECL IMPORT_DECL(BOOST_PP_EMPTY())
+// #else
+// #define DLL_DECL EXPORT_DECL(BOOST_PP_EMPTY())
+// #endif
+//
// class DLL_DECL A {
// ...
// };
//
+// #undef DLL_DECL
+//
// code which includes such headers should look something like:
//
-// #define DLL_DECL IMPORT_DECL
// #include "A.hpp"
-// #undef DLL_DECL
//
-// for declarations used in dlls for exporting, and
-//
-// #define DLL_DECL EXPORT_DECL
+// code which builds dll should like like
+//
+// #define A_CPP
// #include "A.hpp"
-// #include "A.ipp"
-// #undef DLL_DECL
//
-// when a declaration is to be imported.
+// A::A(){
+// ...
+// }
+// ...
+//
+
#include <boost/config.hpp>
-#include <boost/preprocessor/facilities/empty.hpp>
#ifdef BOOST_HAS_DECLSPEC // defined in config system
#if ! defined(EXPORT_DECL)
@@ -50,11 +61,14 @@
#endif
#if ! defined(IMPORT_DECL)
#if defined(__BORLANDC__)
- #define IMPORT_DECL __import
+ #define IMPORT_DECL(T) T __import
#else
- #define IMPORT_DECL __declspec(dllimport)
+ #define IMPORT_DECL(T) __declspec(dllimport) T
#endif
#endif
+#else
+ #define IMPORT_DECL(T)
+ #define EXPORT_DECL(T)
#endif // BOOST_HAS_DECLSPEC
#endif // BOOST_TEST_DECL_HPP
Modified: trunk/libs/serialization/test/test_dll_exported.cpp
==============================================================================
--- trunk/libs/serialization/test/test_dll_exported.cpp (original)
+++ trunk/libs/serialization/test/test_dll_exported.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -1,5 +1,5 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// test_exported.cpp
+// test_dll_exported.cpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
@@ -8,6 +8,22 @@
// should pass compilation and execution
+// This is an overly complex test. The purpose of this test is to
+// demostrate and test the ability to serialize a hiarchy of class
+// through a base class pointer even though those class might be
+// implemente in different dlls and use different extended type info
+// systems.
+//
+// polymorphic_ base is locally declared and defined. It use the
+// "no_rtti" extended type info system.
+
+// polymorphic_derived1 is locally declared and defined. It uses
+// the default "type_id" extended type info system
+
+// polymorphic_derived2 is declared in polymorphic_derived.hpp
+// and defined in dll_polymorphic_derived2. It uses the typeid
+// system.
+
#include <cstddef> // NULL
#include <fstream>
@@ -19,19 +35,19 @@
}
#endif
-#include <boost/archive/archive_exception.hpp>
+// for now, only test with simple text archive
+#define BOOST_ARCHIVE_TEST text_archive.hpp
#include "test_tools.hpp"
-#include "test_decl.hpp"
-#define DLL_DECL IMPORT_DECL
-#include "base.hpp"
-#undef DLL_DECL
+#include <boost/archive/archive_exception.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/type_info_implementation.hpp>
#include <boost/serialization/access.hpp>
+#include "polymorphic_base.hpp"
+
class polymorphic_derived1 : public polymorphic_base
{
friend class boost::serialization::access;
@@ -39,18 +55,20 @@
void serialize(Archive &ar, const unsigned int /* file_version */){
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
}
+ virtual const char * get_key() const {
+ return "polymorphic_derived1";
+ }
public:
virtual ~polymorphic_derived1(){}
};
-BOOST_CLASS_EXPORT(polymorphic_derived1)
-
// MWerks users can do this to make their code work
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived1)
-#define DLL_DECL IMPORT_DECL
-#include "derived2.hpp"
-#undef DLL_DECL
+BOOST_CLASS_EXPORT(polymorphic_derived1)
+
+#define POLYMORPHIC_DERIVED2_IMPORT
+#include "polymorphic_derived2.hpp"
// save exported polymorphic class
void save_exported(const char *testfile)
Modified: trunk/libs/serialization/test/test_dll_plugin.cpp
==============================================================================
--- trunk/libs/serialization/test/test_dll_plugin.cpp (original)
+++ trunk/libs/serialization/test/test_dll_plugin.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -27,12 +27,13 @@
#endif
#include <boost/archive/archive_exception.hpp>
+
+// for now, only test with simple text and polymorphic archive
+#define BOOST_ARCHIVE_TEST polymorphic_text_archive.hpp
#include "test_tools.hpp"
-#include "test_decl.hpp"
-#define DLL_DECL IMPORT_DECL
-#include "base.hpp"
-#undef DLL_DECL
+#include <boost/archive/polymorphic_text_oarchive.hpp>
+#include <boost/archive/polymorphic_text_iarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
@@ -41,6 +42,9 @@
#include <boost/serialization/void_cast.hpp>
#include <boost/serialization/extended_type_info.hpp>
+#include "polymorphic_base.hpp"
+
+// declare and implement a derived class in our own executable
class polymorphic_derived1 : public polymorphic_base
{
friend class boost::serialization::access;
@@ -152,7 +156,8 @@
BOOST_REQUIRE(NULL != testfile);
HINSTANCE hDLL; // Handle to DLL
- hDLL = LoadLibrary("derived2.dll");
+ hDLL = LoadLibrary("dll_polymorphic_derived2.dll");
+ assert(0 != hDLL);
save_exported(testfile);
load_exported(testfile);
FreeLibrary(hDLL);
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-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -22,18 +22,15 @@
}
#endif
+// for now, only test with simple text and polymorphic archive
#include "test_tools.hpp"
-
-#include <boost/archive/text_oarchive.hpp>
-#include <boost/archive/text_iarchive.hpp>
+#include "text_archive.hpp"
#include <boost/archive/polymorphic_text_oarchive.hpp>
#include <boost/archive/polymorphic_text_iarchive.hpp>
-#include "test_decl.hpp"
-#define DLL_DECL IMPORT_DECL
+#define A_IMPORT
#include "A.hpp"
-#undef DLL_DECL
// simple class with text archive compiled in dll
void
@@ -41,7 +38,8 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- A a, a1;
+ const A a;
+ A a1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
@@ -63,15 +61,18 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- A a, a1;
+ const A a;
+ A a1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
- oa << boost::serialization::make_nvp("a", a);
+ boost::archive::polymorphic_oarchive & poa(oa);
+ poa << boost::serialization::make_nvp("a", a);
}
{
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);
}
BOOST_CHECK_EQUAL(a, a1);
@@ -85,7 +86,7 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- A *a = & A();
+ const A *a = & A();
A *a1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
@@ -108,26 +109,26 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- A *a = & A();
+ const A *a = & A();
A *a1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
- oa << boost::serialization::make_nvp("a", a);
+ boost::archive::polymorphic_oarchive & poa(oa);
+ poa << boost::serialization::make_nvp("a", a);
}
{
test_istream is(testfile, TEST_STREAM_FLAGS);
boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
- ia >> boost::serialization::make_nvp("a", a1);
+ boost::archive::polymorphic_iarchive & pia(ia);
+ pia >> boost::serialization::make_nvp("a", a1);
}
BOOST_CHECK_EQUAL(*a, *a1);
std::remove(testfile);
}
-#define DLL_DECL IMPORT_DECL
#include "B.hpp"
-#undef DLL_DECL
// derived class with base text archive compiled in dll
void
@@ -135,7 +136,8 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- B b, b1;
+ const B b;
+ B b1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
@@ -157,16 +159,19 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- B b, b1;
+ const B b;
+ B b1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
- oa << boost::serialization::make_nvp("b", b);
+ boost::archive::polymorphic_oarchive & poa(oa);
+ poa << boost::serialization::make_nvp("b", b);
}
{
test_istream is(testfile, TEST_STREAM_FLAGS);
boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
- ia >> boost::serialization::make_nvp("b", b1);
+ boost::archive::polymorphic_iarchive & pia(ia);
+ pia >> boost::serialization::make_nvp("b", b1);
}
BOOST_CHECK_EQUAL(b, b1);
@@ -179,7 +184,7 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- B *b = & B();
+ const B *b = & B();
B *b1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
@@ -202,17 +207,19 @@
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
- B *b = & B();
+ const B *b = & B();
B *b1;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
- oa << boost::serialization::make_nvp("b", b);
+ boost::archive::polymorphic_oarchive & poa(oa);
+ poa << boost::serialization::make_nvp("b", b);
}
{
test_istream is(testfile, TEST_STREAM_FLAGS);
boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
- ia >> boost::serialization::make_nvp("b", b1);
+ boost::archive::polymorphic_iarchive & pia(ia);
+ pia >> boost::serialization::make_nvp("b", b1);
}
BOOST_CHECK_EQUAL(*b, *b1);
Modified: trunk/libs/serialization/test/test_exported.cpp
==============================================================================
--- trunk/libs/serialization/test/test_exported.cpp (original)
+++ trunk/libs/serialization/test/test_exported.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -22,17 +22,12 @@
#include <boost/serialization/export.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/type_info_implementation.hpp>
+#include <boost/serialization/extended_type_info_typeid.hpp>
#include <boost/archive/archive_exception.hpp>
#include "test_tools.hpp"
-#include "base.hpp"
-
-template<class Archive>
-void polymorphic_base::serialize(
- Archive & /* ar */,
- const unsigned int /* file_version */){
-}
+#include "polymorphic_base.hpp"
class polymorphic_derived1 : public polymorphic_base
{
@@ -41,6 +36,9 @@
void serialize(Archive & ar, const unsigned int /* file_version */){
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
}
+ virtual const char * get_key() const {
+ return "polymorphic_derived1";
+ }
public:
~polymorphic_derived1(){}
};
@@ -50,17 +48,13 @@
// MWerks users can do this to make their code work
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived1)
-#include "derived2.hpp"
+#include "polymorphic_derived2.hpp"
-template<class Archive>
-void polymorphic_derived2::serialize(
- Archive &ar,
- const unsigned int /* file_version */
-){
- ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
-}
BOOST_CLASS_EXPORT(polymorphic_derived2)
+// MWerks users can do this to make their code work
+BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived2)
+
// save exported polymorphic class
void save_exported(const char *testfile)
{
Modified: trunk/libs/serialization/test/test_shared_ptr.cpp
==============================================================================
--- trunk/libs/serialization/test/test_shared_ptr.cpp (original)
+++ trunk/libs/serialization/test/test_shared_ptr.cpp 2009-07-07 00:04:18 EDT (Tue, 07 Jul 2009)
@@ -48,7 +48,6 @@
virtual ~A(){--count;} // default destructor
};
-//BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(A)
BOOST_SERIALIZATION_SHARED_PTR(A)
// B is a subclass of A
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