xref: /trunk/main/o3tl/qa/test-cow_wrapper.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
131682d32SAndrew Rist /**************************************************************
231682d32SAndrew Rist  *
331682d32SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
431682d32SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
531682d32SAndrew Rist  * distributed with this work for additional information
631682d32SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
731682d32SAndrew Rist  * to you under the Apache License, Version 2.0 (the
831682d32SAndrew Rist  * "License"); you may not use this file except in compliance
931682d32SAndrew Rist  * with the License.  You may obtain a copy of the License at
1031682d32SAndrew Rist  *
1131682d32SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1231682d32SAndrew Rist  *
1331682d32SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1431682d32SAndrew Rist  * software distributed under the License is distributed on an
1531682d32SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1631682d32SAndrew Rist  * KIND, either express or implied.  See the License for the
1731682d32SAndrew Rist  * specific language governing permissions and limitations
1831682d32SAndrew Rist  * under the License.
1931682d32SAndrew Rist  *
2031682d32SAndrew Rist  *************************************************************/
2131682d32SAndrew Rist 
22cdf0e10cSrcweir // autogenerated file with codegen.pl
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "preextstl.h"
25*18cf0442SDamjan Jovanovic #include "gtest/gtest.h"
26cdf0e10cSrcweir #include "postextstl.h"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "cow_wrapper_clients.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::o3tl;
31cdf0e10cSrcweir using namespace ::o3tltests;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34*18cf0442SDamjan Jovanovic class cow_wrapper_test : public ::testing::Test
35cdf0e10cSrcweir {
36cdf0e10cSrcweir public:
test(T & rTestObj1,T & rTestObj2,T & rTestObj3)37cdf0e10cSrcweir     template< class T > void test( T& rTestObj1, T& rTestObj2, T& rTestObj3 )
38cdf0e10cSrcweir     {
39*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1.is_unique() ) << "rTestObj1 is unique";
40*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj2.is_unique() ) << "rTestObj2 is unique";
41*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj3.is_unique() ) << "rTestObj3 is unique";
42cdf0e10cSrcweir 
43*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 != rTestObj2 ) << "rTestObj1 != rTestObj2";
44*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj2 != rTestObj3 ) << "rTestObj2 != rTestObj3";
45*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 != rTestObj3 ) << "rTestObj1 != rTestObj3";
46*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 < rTestObj2 ) << "rTestObj1 < rTestObj2";
47*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj2 < rTestObj3 ) << "rTestObj2 < rTestObj3";
48cdf0e10cSrcweir 
49cdf0e10cSrcweir         rTestObj2 = rTestObj1;
50cdf0e10cSrcweir         rTestObj3 = rTestObj1;
51*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 == rTestObj2 ) << "rTestObj1 == rTestObj2";
52*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 == rTestObj3 ) << "rTestObj1 == rTestObj3";
53*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1.use_count() == 3 ) << "rTestObj1.use_count() == 3";
54*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj2.use_count() == 3 ) << "rTestObj2.use_count() == 3";
55*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj3.use_count() == 3 ) << "rTestObj3.use_count() == 3";
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         rTestObj2.makeUnique();
58*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 == rTestObj2 ) << "rTestObj1 == rTestObj2";
59*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 == rTestObj3 ) << "rTestObj1 == rTestObj3";
60*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1.use_count() == 2 ) << "rTestObj1.use_count() == 2";
61*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj2.use_count() == 1 ) << "rTestObj2.use_count() == 1";
62*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj2.is_unique() ) << "rTestObj2.is_unique()";
63*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj3.use_count() == 2 ) << "rTestObj3.use_count() == 2";
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         rTestObj2.swap( rTestObj3 );
66*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 == rTestObj2 ) << "rTestObj1 == rTestObj2";
67*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1 == rTestObj3 ) << "rTestObj1 == rTestObj3";
68*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj1.use_count() == 2 ) << "rTestObj1.use_count() == 2";
69*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj2.use_count() == 2 ) << "rTestObj2.use_count() == 2";
70*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj3.use_count() == 1 ) << "rTestObj3.use_count() == 1";
71*18cf0442SDamjan Jovanovic         ASSERT_TRUE(rTestObj3.is_unique() ) << "rTestObj3.is_unique()";
72cdf0e10cSrcweir     }
73*18cf0442SDamjan Jovanovic };
74cdf0e10cSrcweir 
TEST_F(cow_wrapper_test,testCowWrapper)75*18cf0442SDamjan Jovanovic TEST_F(cow_wrapper_test, testCowWrapper)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     // setup
78cdf0e10cSrcweir     cow_wrapper_client1 aTestObj1;
79cdf0e10cSrcweir     cow_wrapper_client1 aTestObj2;
80cdf0e10cSrcweir     cow_wrapper_client1 aTestObj3;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     cow_wrapper_client2 aTestObj4;
83cdf0e10cSrcweir     cow_wrapper_client2 aTestObj5;
84cdf0e10cSrcweir     cow_wrapper_client2 aTestObj6;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     cow_wrapper_client3 aTestObj7;
87cdf0e10cSrcweir     cow_wrapper_client3 aTestObj8;
88cdf0e10cSrcweir     cow_wrapper_client3 aTestObj9;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         aTestObj1 = cow_wrapper_client1( 1 );
92cdf0e10cSrcweir         aTestObj2.modify( 2 );
93cdf0e10cSrcweir         aTestObj3.modify( 3 );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         aTestObj4 = cow_wrapper_client2( 4 );
96cdf0e10cSrcweir         aTestObj5.modify( 5 );
97cdf0e10cSrcweir         aTestObj6.modify( 6 );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         aTestObj7 = cow_wrapper_client3( 7 );
100cdf0e10cSrcweir         aTestObj8.modify( 8 );
101cdf0e10cSrcweir         aTestObj9.modify( 9 );
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir     // all three temporaries are dead now
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // test
106cdf0e10cSrcweir     test( aTestObj1, aTestObj2, aTestObj3 );
107cdf0e10cSrcweir     test( aTestObj4, aTestObj5, aTestObj6 );
108cdf0e10cSrcweir     test( aTestObj7, aTestObj8, aTestObj9 );
109cdf0e10cSrcweir }
110