LCOV - code coverage report
Current view: top level - o3tl/qa - test-cow_wrapper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 89 89 100.0 %
Date: 2014-11-03 Functions: 14 15 93.3 %
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          12 : class cow_wrapper_test : public CppUnit::TestFixture
      33             : {
      34             : public:
      35           6 :     template< class T > void test( T& rTestObj1, T& rTestObj2, T& rTestObj3 )
      36             :     {
      37           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 is unique",
      38             :                                rTestObj1.is_unique() );
      39           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2 is unique",
      40             :                                rTestObj2.is_unique() );
      41           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3 is unique",
      42             :                                rTestObj3.is_unique() );
      43             : 
      44           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj2",
      45             :                                rTestObj1 != rTestObj2 );
      46           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2 != rTestObj3",
      47             :                                rTestObj2 != rTestObj3 );
      48           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj3",
      49             :                                rTestObj1 != rTestObj3 );
      50           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 < rTestObj2",
      51             :                                rTestObj1 < rTestObj2 );
      52           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2 < rTestObj3",
      53             :                                rTestObj2 < rTestObj3 );
      54             : 
      55           6 :         rTestObj2 = rTestObj1;
      56           6 :         rTestObj3 = rTestObj1;
      57           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
      58             :                                rTestObj1 == rTestObj2 );
      59           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
      60             :                                rTestObj1 == rTestObj3 );
      61           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 3",
      62             :                                rTestObj1.use_count() == 3 );
      63           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 3",
      64             :                                rTestObj2.use_count() == 3 );
      65           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 3",
      66             :                                rTestObj3.use_count() == 3 );
      67             : 
      68           6 :         rTestObj2.makeUnique();
      69           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
      70             :                                rTestObj1 == rTestObj2 );
      71           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
      72             :                                rTestObj1 == rTestObj3 );
      73           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
      74             :                                rTestObj1.use_count() == 2 );
      75           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 1",
      76             :                                rTestObj2.use_count() == 1 );
      77           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.is_unique()",
      78             :                                rTestObj2.is_unique() );
      79           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 2",
      80             :                                rTestObj3.use_count() == 2 );
      81             : 
      82           6 :         rTestObj2.swap( rTestObj3 );
      83           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
      84             :                                rTestObj1 == rTestObj2 );
      85           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
      86             :                                rTestObj1 == rTestObj3 );
      87           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
      88             :                                rTestObj1.use_count() == 2 );
      89           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 2",
      90             :                                rTestObj2.use_count() == 2 );
      91           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 1",
      92             :                                rTestObj3.use_count() == 1 );
      93           6 :         CPPUNIT_ASSERT_MESSAGE("rTestObj3.is_unique()",
      94             :                                rTestObj3.is_unique() );
      95           6 :     }
      96             : 
      97           2 :     void testCowWrapper()
      98             :     {
      99             :         // setup
     100           2 :         cow_wrapper_client1 aTestObj1;
     101           4 :         cow_wrapper_client1 aTestObj2;
     102           4 :         cow_wrapper_client1 aTestObj3;
     103             : 
     104           4 :         cow_wrapper_client2 aTestObj4;
     105           4 :         cow_wrapper_client2 aTestObj5;
     106           4 :         cow_wrapper_client2 aTestObj6;
     107             : 
     108           4 :         cow_wrapper_client3 aTestObj7;
     109           4 :         cow_wrapper_client3 aTestObj8;
     110           4 :         cow_wrapper_client3 aTestObj9;
     111             : 
     112             :         {
     113           2 :             aTestObj1 = cow_wrapper_client1( 1 );
     114           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj1.queryUnmodified(), 1);
     115           2 :             aTestObj2.modify( 2 );
     116           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj2.queryUnmodified(), 2);
     117           2 :             aTestObj3.modify( 3 );
     118           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj3.queryUnmodified(), 3);
     119             : 
     120           2 :             aTestObj4 = cow_wrapper_client2( 4 );
     121           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj4.queryUnmodified(), 4);
     122           2 :             aTestObj5.modify( 5 );
     123           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj5.queryUnmodified(), 5);
     124           2 :             aTestObj6.modify( 6 );
     125           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj6.queryUnmodified(), 6);
     126             : 
     127           2 :             aTestObj7 = cow_wrapper_client3( 7 );
     128           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj7.queryUnmodified(), 7);
     129           2 :             aTestObj8.modify( 8 );
     130           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj8.queryUnmodified(), 8);
     131           2 :             aTestObj9.modify( 9 );
     132           2 :             CPPUNIT_ASSERT_EQUAL(aTestObj9.queryUnmodified(), 9);
     133             :         }
     134             :         // all three temporaries are dead now
     135             : 
     136             :         // test
     137           2 :         test( aTestObj1, aTestObj2, aTestObj3 );
     138           2 :         test( aTestObj4, aTestObj5, aTestObj6 );
     139           4 :         test( aTestObj7, aTestObj8, aTestObj9 );
     140           2 :     }
     141             : 
     142           2 :     void testStaticDefault()
     143             :     {
     144           2 :         cow_wrapper_client4 aTestObj1;
     145           4 :         cow_wrapper_client4 aTestObj2;
     146           4 :         cow_wrapper_client4 aTestObj3(4);
     147             : 
     148           4 :         CPPUNIT_ASSERT_MESSAGE("aTestObj1.is_default()",
     149           2 :                                aTestObj1.is_default() );
     150           4 :         CPPUNIT_ASSERT_MESSAGE("aTestObj2.is_default()",
     151           2 :                                aTestObj2.is_default() );
     152           4 :         CPPUNIT_ASSERT_MESSAGE("!aTestObj3.is_default()",
     153           2 :                                !aTestObj3.is_default() );
     154           2 :         aTestObj1 = aTestObj2;
     155           4 :         CPPUNIT_ASSERT_MESSAGE("aTestObj1.is_default() #2",
     156           2 :                                aTestObj1.is_default() );
     157           4 :         CPPUNIT_ASSERT_MESSAGE("aTestObj2.is_default() #2",
     158           2 :                                aTestObj2.is_default() );
     159           2 :         aTestObj1 = aTestObj3;
     160           4 :         CPPUNIT_ASSERT_MESSAGE("!aTestObj1.is_default()",
     161           4 :                                !aTestObj1.is_default() );
     162           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(cow_wrapper_test);
     169           2 :     CPPUNIT_TEST(testCowWrapper);
     170           2 :     CPPUNIT_TEST(testStaticDefault);
     171           4 :     CPPUNIT_TEST_SUITE_END();
     172             : };
     173             : 
     174             : 
     175           2 : CPPUNIT_TEST_SUITE_REGISTRATION(cow_wrapper_test);
     176             : 
     177           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10