Ticket #2314: intrusive_ptr.ass.test.patch

File intrusive_ptr.ass.test.patch, 2.0 KB (added by Georg Sauthoff <gsauthof@…>, 13 years ago)
  • libs/smart_ptr/test/intrusive_ptr_test.cpp

    changeset:   2:16736bb12c06
    user:        Georg Sauthoff <gsauthof@techfak.uni-bielefeld.de>
    date:        Thu Aug 06 19:00:38 2009 +0200
    summary:     added assignment tests
    
    diff -r c7740aa5c918 -r 16736bb12c06 libs/smart_ptr/test/intrusive_ptr_test.cpp
    a b  
    269269
    270270void copy_assignment()
    271271{
     272  X *x1 = new X();
     273  X *x2 = new X();
     274  X *t1 = x1;
     275  X *t2 = x2;
     276  boost::intrusive_ptr<X> s1(x1);
     277  boost::intrusive_ptr<X> s2(x2);
     278  boost::intrusive_ptr<X> s3(x1);
     279  boost::intrusive_ptr<X> s4(x2);
     280  boost::intrusive_ptr<X> s5;
     281
     282  s1 = s2;
     283  BOOST_TEST(s1.get() == x2);
     284  BOOST_TEST(s2.get() == x2);
     285  BOOST_TEST(x2->use_count() == 3);
     286
     287  s1 = s3;
     288  BOOST_TEST(s1.get() == x1);
     289  BOOST_TEST(s3.get() == x1);
     290  BOOST_TEST(s2.get() == x2);
     291  BOOST_TEST(x2->use_count() == 2);
     292  BOOST_TEST(x1->use_count() == 2);
     293
     294  s5 = s2;
     295  BOOST_TEST(s5.get() == x2);
     296  BOOST_TEST(s2.get() == x2);
     297  BOOST_TEST(x2->use_count() == 3);
     298
     299  BOOST_TEST(t1 == x1);
     300  BOOST_TEST(t2 == x2);
    272301}
    273302
    274303void conversion_assignment()
    275304{
     305  X *x = new X();
     306  Y *y = new Y();
     307  X *t = y;
     308  boost::intrusive_ptr<X> a;
     309  BOOST_TEST(a.get() == 0);
     310  boost::intrusive_ptr<X> u(x);
     311  BOOST_TEST(u.get() == x);
     312  boost::intrusive_ptr<Y> v(y);
     313  BOOST_TEST(v.get() == y);
     314
     315  a = v;
     316  BOOST_TEST(a.get() == y);
     317  BOOST_TEST(v.get() == y);
     318  BOOST_TEST(y->use_count() == 2);
     319
     320  u = v;
     321  BOOST_TEST(u.get() == y);
     322  BOOST_TEST(v.get() == y);
     323  BOOST_TEST(y->use_count() == 3);
     324
     325  BOOST_TEST(t == y);
    276326}
    277327
    278328void pointer_assignment()
    279329{
     330  X *x = new X();
     331  X *t = x;
     332  boost::intrusive_ptr<X> s;
     333  BOOST_TEST(s.get() == 0);
     334  s = x;
     335  BOOST_TEST(x == t);
     336  BOOST_TEST(s.get() == x);
     337  BOOST_TEST(s->use_count() == 1);
     338
     339  intrusive_ptr_add_ref(x);
     340  X *x2 = new X();
     341  s = x2;
     342  BOOST_TEST(s.get() == x2);
     343  BOOST_TEST(s->use_count() == 1);
     344  BOOST_TEST(x->use_count() == 1);
     345
     346  delete x;
    280347}
    281348
    282349void test()