LCOV - code coverage report
Current view: top level - test/source/util - xreplaceable.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 37 100.0 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.0 %
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             : 
      10             : #include <test/util/xreplaceable.hxx>
      11             : 
      12             : #include <com/sun/star/util/XReplaceable.hpp>
      13             : #include <com/sun/star/util/XReplaceDescriptor.hpp>
      14             : #include <com/sun/star/util/XSearchDescriptor.hpp>
      15             : #include "cppunit/extensions/HelperMacros.h"
      16             : 
      17             : #include <iostream>
      18             : 
      19             : #include <test/callgrind.hxx>
      20             : 
      21             : using namespace css;
      22             : using namespace css::uno;
      23             : 
      24             : namespace apitest {
      25             : 
      26           2 : void XReplaceable::testCreateReplaceDescriptor()
      27             : {
      28           2 :     uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
      29           4 :     uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
      30           4 :     CPPUNIT_ASSERT(xReplaceDescr.is());
      31           2 : }
      32             : 
      33           2 : void XReplaceable::testReplaceAll()
      34             : {
      35           2 :     std::cout << "testReplaceAll" << std::endl;
      36           2 :     uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
      37           4 :     uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
      38           2 :     CPPUNIT_ASSERT(xReplaceDescr.is());
      39             : 
      40           4 :     uno::Reference< util::XSearchDescriptor > xSearchDescr = xReplaceable->createSearchDescriptor();
      41           2 :     xSearchDescr->setSearchString(maSearchString);
      42             : 
      43             :     //check that at least one object is there that will be replaced
      44           4 :     uno::Reference< uno::XInterface > xElement = xReplaceable->findFirst(xSearchDescr);
      45           2 :     CPPUNIT_ASSERT(xElement.is());
      46             : 
      47             :     //check that there is none object with the replace string
      48           2 :     xSearchDescr->setSearchString(maReplaceString);
      49           2 :     xElement = xReplaceable->findFirst(xSearchDescr);
      50           2 :     CPPUNIT_ASSERT(!xElement.is());
      51             : 
      52           2 :     xReplaceDescr->setSearchString(maSearchString);
      53           2 :     xReplaceDescr->setReplaceString(maReplaceString);
      54             : 
      55           2 :     callgrindStart();
      56           2 :     xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
      57           2 :     callgrindDump("replaceAll");
      58             : 
      59             :     //check that now at least one element is found
      60           2 :     xElement = xReplaceable->findFirst(xSearchDescr);
      61           2 :     CPPUNIT_ASSERT(xElement.is());
      62             : 
      63           2 :     xSearchDescr->setSearchString(maSearchString);
      64           2 :     xElement = xReplaceable->findFirst(xSearchDescr);
      65           2 :     CPPUNIT_ASSERT(!xElement.is());
      66             : 
      67             :     //redo the whole thing
      68           2 :     xReplaceDescr->setSearchString(maReplaceString);
      69           2 :     xReplaceDescr->setReplaceString(maSearchString);
      70             : 
      71           2 :     xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
      72             : 
      73             :     //check that it works
      74           2 :     xElement = xReplaceable->findFirst(xSearchDescr);
      75           2 :     CPPUNIT_ASSERT(xElement.is());
      76             : 
      77             :     //check that there is none object with the replace string
      78           2 :     xSearchDescr->setSearchString(maReplaceString);
      79           2 :     xElement = xReplaceable->findFirst(xSearchDescr);
      80           4 :     CPPUNIT_ASSERT(!xElement.is());
      81           2 : }
      82             : 
      83          90 : }
      84             : 
      85             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11