1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <test/util/xreplaceable.hxx>
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"
19 #include <test/callgrind.hxx>
22 using namespace css::uno
;
26 void XReplaceable::testCreateReplaceDescriptor()
28 uno::Reference
< util::XReplaceable
> xReplaceable(init(), UNO_QUERY_THROW
);
29 uno::Reference
< util::XReplaceDescriptor
> xReplaceDescr
= xReplaceable
->createReplaceDescriptor();
30 CPPUNIT_ASSERT(xReplaceDescr
.is());
33 void XReplaceable::testReplaceAll()
35 std::cout
<< "testReplaceAll" << std::endl
;
36 uno::Reference
< util::XReplaceable
> xReplaceable(init(), UNO_QUERY_THROW
);
37 uno::Reference
< util::XReplaceDescriptor
> xReplaceDescr
= xReplaceable
->createReplaceDescriptor();
38 CPPUNIT_ASSERT(xReplaceDescr
.is());
40 uno::Reference
< util::XSearchDescriptor
> xSearchDescr
= xReplaceable
->createSearchDescriptor();
41 xSearchDescr
->setSearchString(maSearchString
);
43 //check that at least one object is there that will be replaced
44 uno::Reference
< uno::XInterface
> xElement
= xReplaceable
->findFirst(xSearchDescr
);
45 CPPUNIT_ASSERT(xElement
.is());
47 //check that there is none object with the replace string
48 xSearchDescr
->setSearchString(maReplaceString
);
49 xElement
= xReplaceable
->findFirst(xSearchDescr
);
50 CPPUNIT_ASSERT(!xElement
.is());
52 xReplaceDescr
->setSearchString(maSearchString
);
53 xReplaceDescr
->setReplaceString(maReplaceString
);
56 xReplaceable
->replaceAll(uno::Reference
< util::XSearchDescriptor
>(xReplaceDescr
, UNO_QUERY_THROW
));
57 callgrindDump("replaceAll");
59 //check that now at least one element is found
60 xElement
= xReplaceable
->findFirst(xSearchDescr
);
61 CPPUNIT_ASSERT(xElement
.is());
63 xSearchDescr
->setSearchString(maSearchString
);
64 xElement
= xReplaceable
->findFirst(xSearchDescr
);
65 CPPUNIT_ASSERT(!xElement
.is());
67 //redo the whole thing
68 xReplaceDescr
->setSearchString(maReplaceString
);
69 xReplaceDescr
->setReplaceString(maSearchString
);
71 xReplaceable
->replaceAll(uno::Reference
< util::XSearchDescriptor
>(xReplaceDescr
, UNO_QUERY_THROW
));
74 xElement
= xReplaceable
->findFirst(xSearchDescr
);
75 CPPUNIT_ASSERT(xElement
.is());
77 //check that there is none object with the replace string
78 xSearchDescr
->setSearchString(maReplaceString
);
79 xElement
= xReplaceable
->findFirst(xSearchDescr
);
80 CPPUNIT_ASSERT(!xElement
.is());
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */