LibreOffice Module test (master)  1
xreplaceable.cxx
Go to the documentation of this file.
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 
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/TestAssert.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 void XReplaceable::testCreateReplaceDescriptor()
27 {
28  uno::Reference<util::XReplaceable> xReplaceable(init(), UNO_QUERY_THROW);
29  uno::Reference<util::XReplaceDescriptor> xReplaceDescr
30  = xReplaceable->createReplaceDescriptor();
31  CPPUNIT_ASSERT(xReplaceDescr.is());
32 }
33 
34 void XReplaceable::testReplaceAll()
35 {
36  std::cout << "testReplaceAll" << std::endl;
37  uno::Reference<util::XReplaceable> xReplaceable(init(), UNO_QUERY_THROW);
38  uno::Reference<util::XReplaceDescriptor> xReplaceDescr
39  = xReplaceable->createReplaceDescriptor();
40  CPPUNIT_ASSERT(xReplaceDescr.is());
41 
42  uno::Reference<util::XSearchDescriptor> xSearchDescr = xReplaceable->createSearchDescriptor();
43  xSearchDescr->setSearchString(maSearchString);
44 
45  //check that at least one object is there that will be replaced
46  uno::Reference<uno::XInterface> xElement = xReplaceable->findFirst(xSearchDescr);
47  CPPUNIT_ASSERT(xElement.is());
48 
49  //check that there is none object with the replace string
50  xSearchDescr->setSearchString(maReplaceString);
51  xElement = xReplaceable->findFirst(xSearchDescr);
52  CPPUNIT_ASSERT(!xElement.is());
53 
54  xReplaceDescr->setSearchString(maSearchString);
55  xReplaceDescr->setReplaceString(maReplaceString);
56 
58  xReplaceable->replaceAll(
59  uno::Reference<util::XSearchDescriptor>(xReplaceDescr, UNO_QUERY_THROW));
60  callgrindDump("test:replace_all");
61 
62  //check that now at least one element is found
63  xElement = xReplaceable->findFirst(xSearchDescr);
64  CPPUNIT_ASSERT(xElement.is());
65 
66  xSearchDescr->setSearchString(maSearchString);
67  xElement = xReplaceable->findFirst(xSearchDescr);
68  CPPUNIT_ASSERT(!xElement.is());
69 
70  //redo the whole thing
71  xReplaceDescr->setSearchString(maReplaceString);
72  xReplaceDescr->setReplaceString(maSearchString);
73 
74  xReplaceable->replaceAll(
75  uno::Reference<util::XSearchDescriptor>(xReplaceDescr, UNO_QUERY_THROW));
76 
77  //check that it works
78  xElement = xReplaceable->findFirst(xSearchDescr);
79  CPPUNIT_ASSERT(xElement.is());
80 
81  //check that there is none object with the replace string
82  xSearchDescr->setSearchString(maReplaceString);
83  xElement = xReplaceable->findFirst(xSearchDescr);
84  CPPUNIT_ASSERT(!xElement.is());
85 }
86 }
87 
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void callgrindStart()
Definition: callgrind.cxx:21
void callgrindDump(const char *name)
Definition: callgrind.cxx:27
FILE * init(int, char **)