Revision 499, 1.0 kB
(checked in by vbarta, 15 years ago)
|
standartized testsuite source file names
|
Line | |
---|
1 | #include "shared_ptr.h" |
---|
2 | #include "UnitTest++.h" |
---|
3 | #include <vector> |
---|
4 | |
---|
5 | class Foo { |
---|
6 | private: |
---|
7 | int x; |
---|
8 | |
---|
9 | public: |
---|
10 | Foo ( int x ) : x ( x ) { } |
---|
11 | |
---|
12 | int get_x() const { |
---|
13 | return x; |
---|
14 | } |
---|
15 | |
---|
16 | void set_x ( int nx ) { |
---|
17 | x = nx; |
---|
18 | } |
---|
19 | }; |
---|
20 | |
---|
21 | typedef std::vector<bdm::shared_ptr<Foo> > TFooVector; |
---|
22 | |
---|
23 | TEST ( test_shared_ptr ) { |
---|
24 | TFooVector v; |
---|
25 | |
---|
26 | bdm::shared_ptr<Foo> zero; |
---|
27 | CHECK_EQUAL ( 0l, zero.use_count() ); |
---|
28 | bdm::shared_ptr<Foo> z2 ( zero ); |
---|
29 | CHECK_EQUAL ( 0l, z2.use_count() ); |
---|
30 | |
---|
31 | bdm::shared_ptr<Foo> one ( new Foo ( 1 ) ); |
---|
32 | v.push_back ( one ); |
---|
33 | CHECK ( !one.unique() ); |
---|
34 | |
---|
35 | v.push_back ( one ); |
---|
36 | v.push_back ( bdm::shared_ptr<Foo> ( new Foo ( 2 ) ) ); |
---|
37 | CHECK_EQUAL ( static_cast<TFooVector::size_type> ( 3 ), v.size() ); |
---|
38 | |
---|
39 | CHECK ( v[0] == v[1] ); |
---|
40 | CHECK ( v[1] != v[2] ); |
---|
41 | |
---|
42 | Foo c ( * ( v[0] ) ); |
---|
43 | CHECK_EQUAL ( 1, c.get_x() ); |
---|
44 | |
---|
45 | Foo *p = v[1].get(); |
---|
46 | CHECK_EQUAL ( 1, p->get_x() ); |
---|
47 | p->set_x ( 12 ); |
---|
48 | CHECK_EQUAL ( 12, one->get_x() ); |
---|
49 | |
---|
50 | CHECK ( v[2].unique() ); |
---|
51 | CHECK_EQUAL ( 2, v[2]->get_x() ); |
---|
52 | } |
---|