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

Generated by: LCOV version 1.10