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