LCOV - code coverage report
Current view: top level - o3tl/qa - test-cow_wrapper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 89 89 100.0 %
Date: 2015-06-13 12:38:46 Functions: 17 18 94.4 %
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           6 : 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           2 :         cow_wrapper_client1 aTestObj2;
     102           2 :         cow_wrapper_client1 aTestObj3;
     103             : 
     104           2 :         cow_wrapper_client2 aTestObj4;
     105           2 :         cow_wrapper_client2 aTestObj5;
     106           2 :         cow_wrapper_client2 aTestObj6;
     107             : 
     108           2 :         cow_wrapper_client3 aTestObj7;
     109           2 :         cow_wrapper_client3 aTestObj8;
     110           2 :         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           2 :         test( aTestObj7, aTestObj8, aTestObj9 );
     140           1 :     }
     141             : 
     142           1 :     void testStaticDefault()
     143             :     {
     144           1 :         cow_wrapper_client4 aTestObj1;
     145           2 :         cow_wrapper_client4 aTestObj2;
     146           2 :         cow_wrapper_client4 aTestObj3(4);
     147             : 
     148           2 :         CPPUNIT_ASSERT_MESSAGE("aTestObj1.is_default()",
     149           1 :                                aTestObj1.is_default() );
     150           2 :         CPPUNIT_ASSERT_MESSAGE("aTestObj2.is_default()",
     151           1 :                                aTestObj2.is_default() );
     152           2 :         CPPUNIT_ASSERT_MESSAGE("!aTestObj3.is_default()",
     153           1 :                                !aTestObj3.is_default() );
     154           1 :         aTestObj1 = aTestObj2;
     155           2 :         CPPUNIT_ASSERT_MESSAGE("aTestObj1.is_default() #2",
     156           1 :                                aTestObj1.is_default() );
     157           2 :         CPPUNIT_ASSERT_MESSAGE("aTestObj2.is_default() #2",
     158           1 :                                aTestObj2.is_default() );
     159           1 :         aTestObj1 = aTestObj3;
     160           2 :         CPPUNIT_ASSERT_MESSAGE("!aTestObj1.is_default()",
     161           2 :                                !aTestObj1.is_default() );
     162           1 :     }
     163             : 
     164             :     // Change the following lines only, if you add, remove or rename
     165             :     // member functions of the current class,
     166             :     // because these macros are need by auto register mechanism.
     167             : 
     168           2 :     CPPUNIT_TEST_SUITE(cow_wrapper_test);
     169           1 :     CPPUNIT_TEST(testCowWrapper);
     170           1 :     CPPUNIT_TEST(testStaticDefault);
     171           5 :     CPPUNIT_TEST_SUITE_END();
     172             : };
     173             : 
     174             : 
     175           1 : CPPUNIT_TEST_SUITE_REGISTRATION(cow_wrapper_test);
     176             : 
     177           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11