xref: /aoo4110/main/o3tl/qa/test-cow_wrapper.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // autogenerated file with codegen.pl
23 
24 #include "preextstl.h"
25 #include "cppunit/TestAssert.h"
26 #include "cppunit/TestFixture.h"
27 #include "cppunit/extensions/HelperMacros.h"
28 #include "cppunit/plugin/TestPlugIn.h"
29 #include "postextstl.h"
30 
31 #include "cow_wrapper_clients.hxx"
32 
33 using namespace ::o3tl;
34 using namespace ::o3tltests;
35 
36 
37 class cow_wrapper_test : public CppUnit::TestFixture
38 {
39 public:
test(T & rTestObj1,T & rTestObj2,T & rTestObj3)40     template< class T > void test( T& rTestObj1, T& rTestObj2, T& rTestObj3 )
41     {
42         CPPUNIT_ASSERT_MESSAGE("rTestObj1 is unique",
43                                rTestObj1.is_unique() );
44         CPPUNIT_ASSERT_MESSAGE("rTestObj2 is unique",
45                                rTestObj2.is_unique() );
46         CPPUNIT_ASSERT_MESSAGE("rTestObj3 is unique",
47                                rTestObj3.is_unique() );
48 
49         CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj2",
50                                rTestObj1 != rTestObj2 );
51         CPPUNIT_ASSERT_MESSAGE("rTestObj2 != rTestObj3",
52                                rTestObj2 != rTestObj3 );
53         CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj3",
54                                rTestObj1 != rTestObj3 );
55         CPPUNIT_ASSERT_MESSAGE("rTestObj1 < rTestObj2",
56                                rTestObj1 < rTestObj2 );
57         CPPUNIT_ASSERT_MESSAGE("rTestObj2 < rTestObj3",
58                                rTestObj2 < rTestObj3 );
59 
60         rTestObj2 = rTestObj1;
61         rTestObj3 = rTestObj1;
62         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
63                                rTestObj1 == rTestObj2 );
64         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
65                                rTestObj1 == rTestObj3 );
66         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 3",
67                                rTestObj1.use_count() == 3 );
68         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 3",
69                                rTestObj2.use_count() == 3 );
70         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 3",
71                                rTestObj3.use_count() == 3 );
72 
73         rTestObj2.makeUnique();
74         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
75                                rTestObj1 == rTestObj2 );
76         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
77                                rTestObj1 == rTestObj3 );
78         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
79                                rTestObj1.use_count() == 2 );
80         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 1",
81                                rTestObj2.use_count() == 1 );
82         CPPUNIT_ASSERT_MESSAGE("rTestObj2.is_unique()",
83                                rTestObj2.is_unique() );
84         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 2",
85                                rTestObj3.use_count() == 2 );
86 
87         rTestObj2.swap( rTestObj3 );
88         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
89                                rTestObj1 == rTestObj2 );
90         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
91                                rTestObj1 == rTestObj3 );
92         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
93                                rTestObj1.use_count() == 2 );
94         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 2",
95                                rTestObj2.use_count() == 2 );
96         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 1",
97                                rTestObj3.use_count() == 1 );
98         CPPUNIT_ASSERT_MESSAGE("rTestObj3.is_unique()",
99                                rTestObj3.is_unique() );
100     }
101 
testCowWrapper()102     void testCowWrapper()
103     {
104         // setup
105         cow_wrapper_client1 aTestObj1;
106         cow_wrapper_client1 aTestObj2;
107         cow_wrapper_client1 aTestObj3;
108 
109         cow_wrapper_client2 aTestObj4;
110         cow_wrapper_client2 aTestObj5;
111         cow_wrapper_client2 aTestObj6;
112 
113         cow_wrapper_client3 aTestObj7;
114         cow_wrapper_client3 aTestObj8;
115         cow_wrapper_client3 aTestObj9;
116 
117         {
118             aTestObj1 = cow_wrapper_client1( 1 );
119             aTestObj2.modify( 2 );
120             aTestObj3.modify( 3 );
121 
122             aTestObj4 = cow_wrapper_client2( 4 );
123             aTestObj5.modify( 5 );
124             aTestObj6.modify( 6 );
125 
126             aTestObj7 = cow_wrapper_client3( 7 );
127             aTestObj8.modify( 8 );
128             aTestObj9.modify( 9 );
129         }
130         // all three temporaries are dead now
131 
132         // test
133         test( aTestObj1, aTestObj2, aTestObj3 );
134         test( aTestObj4, aTestObj5, aTestObj6 );
135         test( aTestObj7, aTestObj8, aTestObj9 );
136     }
137 
138     // Change the following lines only, if you add, remove or rename
139     // member functions of the current class,
140     // because these macros are need by auto register mechanism.
141 
142     CPPUNIT_TEST_SUITE(cow_wrapper_test);
143     CPPUNIT_TEST(testCowWrapper);
144     CPPUNIT_TEST_SUITE_END();
145 };
146 
147 // -----------------------------------------------------------------------------
148 CPPUNIT_TEST_SUITE_REGISTRATION(cow_wrapper_test);
149 
150 CPPUNIT_PLUGIN_IMPLEMENT();
151