Skip to content

Commit

Permalink
Corrected various tests.
Browse files Browse the repository at this point in the history
improved build under CMake and B2
passes all tests on clang 03 and g++ 6.2
  • Loading branch information
robertramey committed Nov 14, 2018
1 parent feb5372 commit 9e98df0
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 109 deletions.
42 changes: 31 additions & 11 deletions CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ message(STATUS "Boost directories found at ${boost_headers}")
message(STATUS "Boost libraries found at ${boost_stage}")
set(CMAKE_LIBRARY_PATH ${boost_stage})

# list of archive names for which tests should be generated
#set(archive_list text_archive text_warchive binary_archive xml_archive xml_warchive)
set(archive_list text_archive)

# list of tests generated by each function call
set(test_list)

include_directories(BEFORE ${BOOST_ROOT})

###########################
Expand Down Expand Up @@ -210,6 +214,7 @@ function( serialization_test test_name)
endfunction(serialization_test)

function(archive_test test_name)
set(test_list)
set(arglist)
foreach(a IN ITEMS ${ARGN} )
set(arglist ${arglist} ../test/${a}.cpp)
Expand All @@ -219,18 +224,20 @@ function(archive_test test_name)
IN ITEMS ${archive_list}
)
set(amended_test_name ${test_name}_${archive-name})
message(STATUS ${amended_test_name})
add_executable(${amended_test_name} ../test/${test_name}.cpp ${arglist})
set_property(
TARGET ${amended_test_name}
PROPERTY COMPILE_DEFINITIONS BOOST_ARCHIVE_TEST=${archive-name}.hpp
)
message(STATUS ${amended_test_name} " " ${arglist} " " ${archive-name})
target_link_libraries(${amended_test_name} serialization wserialization filesystem)
add_test(${amended_test_name} ${amended_test_name})
set(test_list ${test_list} ${amended_test_name} PARENT_SCOPE)
endforeach()
endfunction(archive_test)

function(polymorphic_archive_test test_name)
set(test_list)
set(arglist)
foreach(a IN ITEMS ${ARGN} )
set(arglist ${arglist} ../test/${a}.cpp)
Expand All @@ -239,14 +246,19 @@ function(polymorphic_archive_test test_name)
archive-name
IN ITEMS ${archive_list}
)
set(amended_test_name ${test_name}_polymorphic_${archive-name})
message(STATUS ${amended_test_name})
set(amended_archive_name polymorphic_${archive-name})
set(amended_test_name ${test_name}_${amended_archive_name})
add_executable(${amended_test_name} ../test/${test_name}.cpp ${arglist})
target_compile_definitions(${amended_test_name} PUBLIC BOOST_ARCHIVE_TEST=polymorphic_${archive-name}.hpp)
set_property(
TARGET ${amended_test_name}
PROPERTY COMPILE_DEFINITIONS BOOST_ARCHIVE_TEST=${amended_archive_name}.hpp
)
message(STATUS ${amended_test_name} " " ${arglist} " " ${amended_archive_name})
target_link_libraries(${amended_test_name} serialization wserialization filesystem)
add_test(${amended_test_name} ${amended_test_name})
set(test_list ${test_list} ${amended_test_name} PARENT_SCOPE)
endforeach()
endfunction(polymorphic_archive_test)
endfunction(archive_test)

enable_testing()

Expand All @@ -256,11 +268,13 @@ target_link_libraries(dll_a serialization)
serialization_test(test_dll_simple)
target_link_libraries(test_dll_simple dll_a serialization)

message(STATUS dll_polymorphic_base)
add_library(dll_polymorphic_base SHARED ../test/polymorphic_base.cpp)
target_link_libraries(dll_polymorphic_base serialization)

message(STATUS dll_polymorphic_derived2)
add_library(dll_polymorphic_derived2 SHARED ../test/polymorphic_derived2.cpp)
target_link_libraries(dll_polymorphic_derived2 serialization)
serialization_test(test_dll_exported)
target_link_libraries(test_dll_exported dll_polymorphic_derived2)
target_link_libraries(dll_polymorphic_derived2 dll_polymorphic_base serialization)

# compile test_dll_plugin.cpp
# Running the following test requires that the test know the directory
Expand Down Expand Up @@ -308,7 +322,6 @@ archive_test(test_map_boost_unordered A)
archive_test(test_mi)
archive_test(test_multiple_ptrs A)
archive_test(test_multiple_inheritance)
archive_test(test_no_rtti polymorphic_base polymorphic_derived1)
archive_test(test_new_operator A)
archive_test(test_non_intrusive)
archive_test(test_non_default_ctor)
Expand Down Expand Up @@ -364,7 +377,14 @@ else()
endif()
endif()

polymorphic_archive_test(test_exported polymorphic_base polymorphic_derived2)
polymorphic_archive_test(test_dll_exported polymorphic_derived1)
foreach(test_name IN ITEMS ${test_list} )
target_link_libraries(${test_name} dll_polymorphic_derived2 dll_polymorphic_base)
message(STATUS " " target_link_libraries " " dll_polymorphic_derived2 " " dll_polymorphic_base)
endforeach()

polymorphic_archive_test(test_no_rtti polymorphic_base polymorphic_derived1 polymorphic_derived2)
polymorphic_archive_test(test_exported polymorphic_base polymorphic_derived1 polymorphic_derived2)
polymorphic_archive_test(test_polymorphic test_polymorphic_A A)
polymorphic_archive_test(test_polymorphic2 test_polymorphic2imp)
polymorphic_archive_test(test_polymorphic_helper)
Expand All @@ -375,7 +395,7 @@ polymorphic_archive_test(test_polymorphic_helper)
####################
# add headers in IDE

# for serialisation
# for serialization

file(GLOB x
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down
2 changes: 1 addition & 1 deletion doc/archive_reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ <h3><a name="usage">Usage</a></h3>
To make this work, the following should be included after the archive
class definition.
<pre><code>
#define BOOST_SERIALIZATION_REGISTER_ARCHIVE(Archive)
BOOST_SERIALIZATION_REGISTER_ARCHIVE(Archive)
</code></pre>
Failure to do this will not inhibit the program from compiling, linking
and executing properly - except in one case. If an instance of a derived
Expand Down
8 changes: 4 additions & 4 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ lib dll_polymorphic_base
lib dll_polymorphic_derived2
:
polymorphic_derived2.cpp
dll_polymorphic_base
../build//boost_serialization
:
<link>shared:<define>BOOST_SERIALIZATION_DYN_LINK=1
Expand Down Expand Up @@ -88,7 +89,6 @@ test-suite "serialization" :
[ test-bsl-run_files test_non_default_ctor2 ]
[ test-bsl-run_files test_null_ptr ]
[ test-bsl-run_files test_nvp : A ]
[ test-bsl-run_files test_no_rtti : polymorphic_base polymorphic_derived1 ]
[ test-bsl-run_files test_object ]
[ test-bsl-run_files test_primitive ]
[ test-bsl-run_files test_priority_queue : A ]
Expand Down Expand Up @@ -117,9 +117,9 @@ test-suite "serialization" :
[ test-bsl-run_files test_shared_ptr_multi_base ]
[ test-bsl-run_files test_shared_ptr_132 : : : [ requires auto_ptr ] ] # BOOST_NO_AUTO_PTR

[ test-bsl-run_polymorphic_files test_dll_exported : : dll_polymorphic_base dll_polymorphic_derived2 ]

[ test-bsl-run_polymorphic_files test_exported : polymorphic_base polymorphic_derived2 ]
[ test-bsl-run_polymorphic_files test_dll_exported : polymorphic_derived1 : dll_polymorphic_base dll_polymorphic_derived2 ]
[ test-bsl-run_polymorphic_files test_no_rtti : polymorphic_base polymorphic_derived1 polymorphic_derived2 ]
[ test-bsl-run_polymorphic_files test_exported : polymorphic_base polymorphic_derived1 polymorphic_derived2 ]
[ test-bsl-run_polymorphic_files test_polymorphic : test_polymorphic_A A ]
[ test-bsl-run_polymorphic_files test_polymorphic2 : test_polymorphic2imp ]
[ test-bsl-run_polymorphic_files test_polymorphic_helper ]
Expand Down
24 changes: 23 additions & 1 deletion test/polymorphic_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,29 @@
#include <boost/serialization/export.hpp>

#define POLYMORPHIC_BASE_EXPORT

#include "polymorphic_base.hpp"

template<class Archive>
POLYMORPHIC_BASE_DLL_DECL void polymorphic_base::serialize(
Archive &ar,
const unsigned int /* file_version */
){}

POLYMORPHIC_BASE_DLL_DECL
polymorphic_base::polymorphic_base(){}
POLYMORPHIC_BASE_DLL_DECL
polymorphic_base::~polymorphic_base(){}

#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>

template
POLYMORPHIC_BASE_DLL_DECL void polymorphic_base::serialize(
boost::archive::polymorphic_oarchive &,
const unsigned int /* file_version */
);
template POLYMORPHIC_BASE_DLL_DECL void polymorphic_base::serialize(
boost::archive::polymorphic_iarchive &,
const unsigned int
);
BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_base)
10 changes: 5 additions & 5 deletions test/polymorphic_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@
#define POLYMORPHIC_BASE_DLL_DECL
#endif

class POLYMORPHIC_BASE_DLL_DECL polymorphic_base
class BOOST_SYMBOL_VISIBLE polymorphic_base
{
friend class boost::serialization::access;
template<class Archive>
void serialize(
POLYMORPHIC_BASE_DLL_DECL void serialize(
Archive & /* ar */,
const unsigned int /* file_version */
){}
);
public:
// note that since this class uses the "no_rtti"
// extended_type_info implementation, it MUST
// implement this function
virtual const char * get_key() const = 0;
virtual ~polymorphic_base(){};
POLYMORPHIC_BASE_DLL_DECL polymorphic_base();
POLYMORPHIC_BASE_DLL_DECL virtual ~polymorphic_base();
};

BOOST_SERIALIZATION_ASSUME_ABSTRACT(polymorphic_base)

// the no_rtti system requires this !!!
BOOST_CLASS_EXPORT_KEY(polymorphic_base)


BOOST_CLASS_TYPE_INFO(
polymorphic_base,
extended_type_info_no_rtti<polymorphic_base>
Expand Down
14 changes: 14 additions & 0 deletions test/polymorphic_derived1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ const char * polymorphic_derived1::get_key() const {
>::type::get_const_instance().get_key();
}

#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>

template
void polymorphic_derived1::serialize(
boost::archive::polymorphic_oarchive &,
const unsigned int /* file_version */
);
template
void polymorphic_derived1::serialize(
boost::archive::polymorphic_iarchive &,
const unsigned int
);

BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived1)
12 changes: 10 additions & 2 deletions test/polymorphic_derived2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
#define POLYMORPHIC_DERIVED2_EXPORT
#include "polymorphic_derived2.hpp"

POLYMORPHIC_DERIVED2_DLL_DECL
template<class Archive>
POLYMORPHIC_DERIVED2_DLL_DECL void polymorphic_derived2::serialize(
Archive &ar,
const unsigned int /* file_version */
){
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
}

const char * polymorphic_derived2::get_key() const {
return "polymorphic_derived2";
}
Expand All @@ -35,7 +42,8 @@ POLYMORPHIC_DERIVED2_DLL_DECL void polymorphic_derived2::serialize(
boost::archive::polymorphic_oarchive &,
const unsigned int /* file_version */
);
template POLYMORPHIC_DERIVED2_DLL_DECL void polymorphic_derived2::serialize(
template
POLYMORPHIC_DERIVED2_DLL_DECL void polymorphic_derived2::serialize(
boost::archive::polymorphic_iarchive &,
const unsigned int
);
Expand Down
5 changes: 2 additions & 3 deletions test/polymorphic_derived2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define POLYMORPHIC_DERIVED2_DLL_DECL
#endif

#define POLYMORPHIC_BASE_IMPORT
#include "polymorphic_base.hpp"

class BOOST_SYMBOL_VISIBLE polymorphic_derived2 :
Expand All @@ -48,9 +49,7 @@ class BOOST_SYMBOL_VISIBLE polymorphic_derived2 :
POLYMORPHIC_DERIVED2_DLL_DECL void serialize(
Archive &ar,
const unsigned int /* file_version */
){
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
}
);
POLYMORPHIC_DERIVED2_DLL_DECL const char * get_key() const;
public:
POLYMORPHIC_DERIVED2_DLL_DECL polymorphic_derived2();
Expand Down
24 changes: 4 additions & 20 deletions test/test_dll_exported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace std{

#include "test_tools.hpp"

//#include <boost/archive/archive_exception.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>

#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
Expand All @@ -49,25 +50,8 @@ namespace std{
#define POLYMORPHIC_BASE_IMPORT
#include "polymorphic_base.hpp"

class polymorphic_derived1 : public polymorphic_base
{
friend class boost::serialization::access;
template<class Archive>
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_KEY(polymorphic_derived1)
BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived1)

// MWerks users can do this to make their code work
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived1)
#define POLYMORPHIC_DERIVED1_IMPORT
#include "polymorphic_derived1.hpp"

#define POLYMORPHIC_DERIVED2_IMPORT
#include "polymorphic_derived2.hpp"
Expand Down
37 changes: 11 additions & 26 deletions test/test_exported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,20 @@ namespace std{
}
#endif

#include <boost/serialization/type_info_implementation.hpp>
#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 "test_tools.hpp"

#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>

#include "test_tools.hpp"

#define POLYMORPHIC_BASE_IMPORT
#include "polymorphic_base.hpp"

class polymorphic_derived1 :
public polymorphic_base
{
friend class boost::serialization::access;
template<class Archive>
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(){}
};

BOOST_CLASS_EXPORT_KEY(polymorphic_derived1)
BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived1)

// MWerks users can do this to make their code work
BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived1)
#define POLYMORPHIC_DERIVED1_IMPORT
#include "polymorphic_derived1.hpp"

#define POLYMORPHIC_DERIVED2_IMPORT
#include "polymorphic_derived2.hpp"
Expand All @@ -62,12 +44,15 @@ void save_exported(const char *testfile)
test_oarchive oa_implementation(os, TEST_ARCHIVE_FLAGS);
boost::archive::polymorphic_oarchive & oa_interface = oa_implementation;

polymorphic_base *rb1 = new polymorphic_derived1;
polymorphic_base *rb2 = new polymorphic_derived2;
const polymorphic_base *rb1 = new polymorphic_derived1;
const polymorphic_base *rb2 = new polymorphic_derived2;

// export will permit correct serialization
// through a pointer to a base class
std::cout << "saving polymorphic_derived1 (no_rtti)\n";
oa_interface << BOOST_SERIALIZATION_NVP(rb1);

std::cout << "saving polymorphic_derived2\n";
oa_interface << BOOST_SERIALIZATION_NVP(rb2);

delete rb1;
Expand Down
Loading

0 comments on commit 9e98df0

Please sign in to comment.