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
|
|
| 269 | 269 | |
| 270 | 270 | void copy_assignment() |
| 271 | 271 | { |
| | 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); |
| 272 | 301 | } |
| 273 | 302 | |
| 274 | 303 | void conversion_assignment() |
| 275 | 304 | { |
| | 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); |
| 276 | 326 | } |
| 277 | 327 | |
| 278 | 328 | void pointer_assignment() |
| 279 | 329 | { |
| | 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; |
| 280 | 347 | } |
| 281 | 348 | |
| 282 | 349 | void test() |