コード例 #1
0
// This does the tests
int test_main(int /* argc */, char * /* argv */[])
{

    // Both Sub
    boost::shared_ptr<Sub> tc1_sp(new Sub(10));
    boost::weak_ptr<Sub> tc1_wp(tc1_sp);
    shared_weak(tc1_sp, tc1_wp);
    weak_shared(tc1_wp, tc1_sp);
    tc1_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Sub and Base1
    boost::shared_ptr<Sub> tc2_sp(new Sub(10));
    boost::weak_ptr<Base1> tc2_wp(tc2_sp);
    shared_weak(tc2_sp, tc2_wp);
    weak_shared(tc2_wp, tc2_sp);
    tc2_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Sub and Base2
    boost::shared_ptr<Sub> tc3_sp(new Sub(10));
    boost::weak_ptr<Base2> tc3_wp(tc3_sp);
    shared_weak(tc3_sp, tc3_wp);
    weak_shared(tc3_wp, tc3_sp);
    tc3_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Sub and Base3
    boost::shared_ptr<Sub> tc4_sp(new Sub(10));
    boost::weak_ptr<Base3> tc4_wp(tc4_sp);
    shared_weak(tc4_sp, tc4_wp);
    weak_shared(tc4_wp, tc4_sp);
    tc4_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Base1 and Base2
    boost::shared_ptr<Sub> tc5_sp_tmp(new Sub(10));
    boost::shared_ptr<Base1> tc5_sp(tc5_sp_tmp);
    boost::weak_ptr<Base2> tc5_wp(tc5_sp_tmp);
    tc5_sp_tmp.reset();
    shared_weak(tc5_sp, tc5_wp);
    weak_shared(tc5_wp, tc5_sp);
    tc5_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Base2 and Base3
    boost::shared_ptr<Sub> tc6_sp_tmp(new Sub(10));
    boost::shared_ptr<Base2> tc6_sp(tc6_sp_tmp);
    boost::weak_ptr<Base3> tc6_wp(tc6_sp_tmp);
    tc6_sp_tmp.reset();
    shared_weak(tc6_sp, tc6_wp);
    weak_shared(tc6_wp, tc6_sp);
    tc6_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Base3 and Base1
    boost::shared_ptr<Sub> tc7_sp_tmp(new Sub(10));
    boost::shared_ptr<Base3> tc7_sp(tc7_sp_tmp);
    boost::weak_ptr<Base1> tc7_wp(tc7_sp_tmp);
    tc7_sp_tmp.reset();
    shared_weak(tc7_sp, tc7_wp);
    weak_shared(tc7_wp, tc7_sp);
    tc7_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    return EXIT_SUCCESS;
}
コード例 #2
0
bool test(){
    // Both Sub
    SPT<Sub> tc1_sp(new Sub(10));
    WPT<Sub> tc1_wp(tc1_sp);
    shared_weak(tc1_sp, tc1_wp);
    weak_shared(tc1_wp, tc1_sp);
    tc1_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Sub and Base1
    SPT<Sub> tc2_sp(new Sub(10));
    WPT<Base1> tc2_wp(tc2_sp);
    shared_weak(tc2_sp, tc2_wp);
    weak_shared(tc2_wp, tc2_sp);
    tc2_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Sub and Base2
    SPT<Sub> tc3_sp(new Sub(10));
    WPT<Base2> tc3_wp(tc3_sp);
    shared_weak(tc3_sp, tc3_wp);
    weak_shared(tc3_wp, tc3_sp);
    tc3_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Sub and Base3
    SPT<Sub> tc4_sp(new Sub(10));
    WPT<Base3> tc4_wp(tc4_sp);
    shared_weak(tc4_sp, tc4_wp);
    weak_shared(tc4_wp, tc4_sp);
    tc4_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Base1 and Base2
    SPT<Sub> tc5_sp_tmp(new Sub(10));
    SPT<Base1> tc5_sp(tc5_sp_tmp);
    WPT<Base2> tc5_wp(tc5_sp_tmp);
    tc5_sp_tmp.reset();
    shared_weak(tc5_sp, tc5_wp);
    weak_shared(tc5_wp, tc5_sp);
    tc5_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Base2 and Base3
    SPT<Sub> tc6_sp_tmp(new Sub(10));
    SPT<Base2> tc6_sp(tc6_sp_tmp);
    WPT<Base3> tc6_wp(tc6_sp_tmp);
    tc6_sp_tmp.reset();
    shared_weak(tc6_sp, tc6_wp);
    weak_shared(tc6_wp, tc6_sp);
    tc6_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    // Base3 and Base1
    SPT<Sub> tc7_sp_tmp(new Sub(10));
    SPT<Base3> tc7_sp(tc7_sp_tmp);
    WPT<Base1> tc7_wp(tc7_sp_tmp);
    tc7_sp_tmp.reset();
    shared_weak(tc7_sp, tc7_wp);
    weak_shared(tc7_wp, tc7_sp);
    tc7_sp.reset();
    BOOST_CHECK(0 == Sub::count);

    return true;
}