LCOV - code coverage report
Current view: top level - libreoffice/o3tl/qa - test-cow_wrapper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 69 100.0 %
Date: 2012-12-27 Functions: 13 14 92.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include "cppunit/TestAssert.h"
      22             : #include "cppunit/TestFixture.h"
      23             : #include "cppunit/extensions/HelperMacros.h"
      24             : #include "cppunit/plugin/TestPlugIn.h"
      25             : 
      26             : #include "cow_wrapper_clients.hxx"
      27             : 
      28             : using namespace ::o3tl;
      29             : using namespace ::o3tltests;
      30             : 
      31             : 
      32           3 : class cow_wrapper_test : public CppUnit::TestFixture
      33             : {
      34             : public:
      35           3 :     template< class T > void test( T& rTestObj1, T& rTestObj2, T& rTestObj3 )
      36             :     {
      37           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 is unique",
      38             :                                rTestObj1.is_unique() );
      39           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2 is unique",
      40             :                                rTestObj2.is_unique() );
      41           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3 is unique",
      42             :                                rTestObj3.is_unique() );
      43             : 
      44           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj2",
      45             :                                rTestObj1 != rTestObj2 );
      46           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2 != rTestObj3",
      47             :                                rTestObj2 != rTestObj3 );
      48           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj3",
      49             :                                rTestObj1 != rTestObj3 );
      50           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 < rTestObj2",
      51             :                                rTestObj1 < rTestObj2 );
      52           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2 < rTestObj3",
      53             :                                rTestObj2 < rTestObj3 );
      54             : 
      55           3 :         rTestObj2 = rTestObj1;
      56           3 :         rTestObj3 = rTestObj1;
      57           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
      58             :                                rTestObj1 == rTestObj2 );
      59           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
      60             :                                rTestObj1 == rTestObj3 );
      61           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 3",
      62             :                                rTestObj1.use_count() == 3 );
      63           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 3",
      64             :                                rTestObj2.use_count() == 3 );
      65           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 3",
      66             :                                rTestObj3.use_count() == 3 );
      67             : 
      68           3 :         rTestObj2.makeUnique();
      69           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
      70             :                                rTestObj1 == rTestObj2 );
      71           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
      72             :                                rTestObj1 == rTestObj3 );
      73           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
      74             :                                rTestObj1.use_count() == 2 );
      75           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 1",
      76             :                                rTestObj2.use_count() == 1 );
      77           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.is_unique()",
      78             :                                rTestObj2.is_unique() );
      79           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 2",
      80             :                                rTestObj3.use_count() == 2 );
      81             : 
      82           3 :         rTestObj2.swap( rTestObj3 );
      83           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
      84             :                                rTestObj1 == rTestObj2 );
      85           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
      86             :                                rTestObj1 == rTestObj3 );
      87           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
      88             :                                rTestObj1.use_count() == 2 );
      89           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 2",
      90             :                                rTestObj2.use_count() == 2 );
      91           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 1",
      92             :                                rTestObj3.use_count() == 1 );
      93           3 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.is_unique()",
      94             :                                rTestObj3.is_unique() );
      95           3 :     }
      96             : 
      97           1 :     void testCowWrapper()
      98             :     {
      99             :         // setup
     100           1 :         cow_wrapper_client1 aTestObj1;
     101           1 :         cow_wrapper_client1 aTestObj2;
     102           1 :         cow_wrapper_client1 aTestObj3;
     103             : 
     104           1 :         cow_wrapper_client2 aTestObj4;
     105           1 :         cow_wrapper_client2 aTestObj5;
     106           1 :         cow_wrapper_client2 aTestObj6;
     107             : 
     108           1 :         cow_wrapper_client3 aTestObj7;
     109           1 :         cow_wrapper_client3 aTestObj8;
     110           1 :         cow_wrapper_client3 aTestObj9;
     111             : 
     112             :         {
     113           1 :             aTestObj1 = cow_wrapper_client1( 1 );
     114           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj1.queryUnmodified(), 1);
     115           1 :             aTestObj2.modify( 2 );
     116           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj2.queryUnmodified(), 2);
     117           1 :             aTestObj3.modify( 3 );
     118           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj3.queryUnmodified(), 3);
     119             : 
     120           1 :             aTestObj4 = cow_wrapper_client2( 4 );
     121           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj4.queryUnmodified(), 4);
     122           1 :             aTestObj5.modify( 5 );
     123           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj5.queryUnmodified(), 5);
     124           1 :             aTestObj6.modify( 6 );
     125           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj6.queryUnmodified(), 6);
     126             : 
     127           1 :             aTestObj7 = cow_wrapper_client3( 7 );
     128           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj7.queryUnmodified(), 7);
     129           1 :             aTestObj8.modify( 8 );
     130           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj8.queryUnmodified(), 8);
     131           1 :             aTestObj9.modify( 9 );
     132           1 :             CPPUNIT_ASSERT_EQUAL(aTestObj9.queryUnmodified(), 9);
     133             :         }
     134             :         // all three temporaries are dead now
     135             : 
     136             :         // test
     137           1 :         test( aTestObj1, aTestObj2, aTestObj3 );
     138           1 :         test( aTestObj4, aTestObj5, aTestObj6 );
     139           1 :         test( aTestObj7, aTestObj8, aTestObj9 );
     140           1 :     }
     141             : 
     142             :     // Change the following lines only, if you add, remove or rename
     143             :     // member functions of the current class,
     144             :     // because these macros are need by auto register mechanism.
     145             : 
     146           2 :     CPPUNIT_TEST_SUITE(cow_wrapper_test);
     147           1 :     CPPUNIT_TEST(testCowWrapper);
     148           2 :     CPPUNIT_TEST_SUITE_END();
     149             : };
     150             : 
     151             : // -----------------------------------------------------------------------------
     152           1 : CPPUNIT_TEST_SUITE_REGISTRATION(cow_wrapper_test);
     153             : 
     154           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10