void weak_shared(
    boost::weak_ptr<FIRST>& first, 
    boost::shared_ptr<SECOND>& second
){
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);
    int firstm = first.lock()->m_x;
    int secondm = second->m_x;
    save2(testfile, first, second);

    // Clear the pointers, thereby destroying the objects they contain
    first.reset();
    second.reset();

    load2(testfile, first, second);

    // Check data member
    BOOST_CHECK(firstm == first.lock()->m_x);
    BOOST_CHECK(secondm == second->m_x);
    // Check pointer to vtable
    BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(first.lock()));
    BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(second));

    std::remove(testfile);
}
Ejemplo n.º 2
0
void save_and_load3(
    boost::shared_ptr<A>& first, 
    boost::shared_ptr<A>& second,
    boost::weak_ptr<A>& third
){
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    save3(testfile, first, second, third);

    // Clear the pointers, thereby destroying the objects they contain
    first.reset();
    second.reset();
    third.reset();

    load3(testfile, first, second, third);

    BOOST_CHECK(first == second);
    BOOST_CHECK(first == third.lock());
    std::remove(testfile);
}