xref: /trunk/main/o3tl/qa/test-cow_wrapper.cxx (revision 18cf0442)
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 "gtest/gtest.h"
26 #include "postextstl.h"
27 
28 #include "cow_wrapper_clients.hxx"
29 
30 using namespace ::o3tl;
31 using namespace ::o3tltests;
32 
33 
34 class cow_wrapper_test : public ::testing::Test
35 {
36 public:
test(T & rTestObj1,T & rTestObj2,T & rTestObj3)37     template< class T > void test( T& rTestObj1, T& rTestObj2, T& rTestObj3 )
38     {
39         ASSERT_TRUE(rTestObj1.is_unique() ) << "rTestObj1 is unique";
40         ASSERT_TRUE(rTestObj2.is_unique() ) << "rTestObj2 is unique";
41         ASSERT_TRUE(rTestObj3.is_unique() ) << "rTestObj3 is unique";
42 
43         ASSERT_TRUE(rTestObj1 != rTestObj2 ) << "rTestObj1 != rTestObj2";
44         ASSERT_TRUE(rTestObj2 != rTestObj3 ) << "rTestObj2 != rTestObj3";
45         ASSERT_TRUE(rTestObj1 != rTestObj3 ) << "rTestObj1 != rTestObj3";
46         ASSERT_TRUE(rTestObj1 < rTestObj2 ) << "rTestObj1 < rTestObj2";
47         ASSERT_TRUE(rTestObj2 < rTestObj3 ) << "rTestObj2 < rTestObj3";
48 
49         rTestObj2 = rTestObj1;
50         rTestObj3 = rTestObj1;
51         ASSERT_TRUE(rTestObj1 == rTestObj2 ) << "rTestObj1 == rTestObj2";
52         ASSERT_TRUE(rTestObj1 == rTestObj3 ) << "rTestObj1 == rTestObj3";
53         ASSERT_TRUE(rTestObj1.use_count() == 3 ) << "rTestObj1.use_count() == 3";
54         ASSERT_TRUE(rTestObj2.use_count() == 3 ) << "rTestObj2.use_count() == 3";
55         ASSERT_TRUE(rTestObj3.use_count() == 3 ) << "rTestObj3.use_count() == 3";
56 
57         rTestObj2.makeUnique();
58         ASSERT_TRUE(rTestObj1 == rTestObj2 ) << "rTestObj1 == rTestObj2";
59         ASSERT_TRUE(rTestObj1 == rTestObj3 ) << "rTestObj1 == rTestObj3";
60         ASSERT_TRUE(rTestObj1.use_count() == 2 ) << "rTestObj1.use_count() == 2";
61         ASSERT_TRUE(rTestObj2.use_count() == 1 ) << "rTestObj2.use_count() == 1";
62         ASSERT_TRUE(rTestObj2.is_unique() ) << "rTestObj2.is_unique()";
63         ASSERT_TRUE(rTestObj3.use_count() == 2 ) << "rTestObj3.use_count() == 2";
64 
65         rTestObj2.swap( rTestObj3 );
66         ASSERT_TRUE(rTestObj1 == rTestObj2 ) << "rTestObj1 == rTestObj2";
67         ASSERT_TRUE(rTestObj1 == rTestObj3 ) << "rTestObj1 == rTestObj3";
68         ASSERT_TRUE(rTestObj1.use_count() == 2 ) << "rTestObj1.use_count() == 2";
69         ASSERT_TRUE(rTestObj2.use_count() == 2 ) << "rTestObj2.use_count() == 2";
70         ASSERT_TRUE(rTestObj3.use_count() == 1 ) << "rTestObj3.use_count() == 1";
71         ASSERT_TRUE(rTestObj3.is_unique() ) << "rTestObj3.is_unique()";
72     }
73 };
74 
TEST_F(cow_wrapper_test,testCowWrapper)75 TEST_F(cow_wrapper_test, testCowWrapper)
76 {
77     // setup
78     cow_wrapper_client1 aTestObj1;
79     cow_wrapper_client1 aTestObj2;
80     cow_wrapper_client1 aTestObj3;
81 
82     cow_wrapper_client2 aTestObj4;
83     cow_wrapper_client2 aTestObj5;
84     cow_wrapper_client2 aTestObj6;
85 
86     cow_wrapper_client3 aTestObj7;
87     cow_wrapper_client3 aTestObj8;
88     cow_wrapper_client3 aTestObj9;
89 
90     {
91         aTestObj1 = cow_wrapper_client1( 1 );
92         aTestObj2.modify( 2 );
93         aTestObj3.modify( 3 );
94 
95         aTestObj4 = cow_wrapper_client2( 4 );
96         aTestObj5.modify( 5 );
97         aTestObj6.modify( 6 );
98 
99         aTestObj7 = cow_wrapper_client3( 7 );
100         aTestObj8.modify( 8 );
101         aTestObj9.modify( 9 );
102     }
103     // all three temporaries are dead now
104 
105     // test
106     test( aTestObj1, aTestObj2, aTestObj3 );
107     test( aTestObj4, aTestObj5, aTestObj6 );
108     test( aTestObj7, aTestObj8, aTestObj9 );
109 }
110