tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / test / source / util / xreplaceable.cxx
blob4e315c6653dabd9143c6429d9501b9dc91881f4b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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/TestAssert.h>
17 #include <iostream>
19 #include <test/callgrind.hxx>
21 using namespace css;
22 using namespace css::uno;
24 namespace apitest
26 void XReplaceable::testCreateReplaceDescriptor()
28 uno::Reference<util::XReplaceable> xReplaceable(init(), UNO_QUERY_THROW);
29 uno::Reference<util::XReplaceDescriptor> xReplaceDescr
30 = xReplaceable->createReplaceDescriptor();
31 CPPUNIT_ASSERT(xReplaceDescr.is());
34 void XReplaceable::testReplaceAll()
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());
42 uno::Reference<util::XSearchDescriptor> xSearchDescr = xReplaceable->createSearchDescriptor();
43 xSearchDescr->setSearchString(maSearchString);
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());
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());
54 xReplaceDescr->setSearchString(maSearchString);
55 xReplaceDescr->setReplaceString(maReplaceString);
57 callgrindStart();
58 xReplaceable->replaceAll(
59 uno::Reference<util::XSearchDescriptor>(xReplaceDescr, UNO_QUERY_THROW));
60 callgrindDump("test:replace_all");
62 //check that now at least one element is found
63 xElement = xReplaceable->findFirst(xSearchDescr);
64 CPPUNIT_ASSERT(xElement.is());
66 xSearchDescr->setSearchString(maSearchString);
67 xElement = xReplaceable->findFirst(xSearchDescr);
68 CPPUNIT_ASSERT(!xElement.is());
70 //redo the whole thing
71 xReplaceDescr->setSearchString(maReplaceString);
72 xReplaceDescr->setReplaceString(maSearchString);
74 xReplaceable->replaceAll(
75 uno::Reference<util::XSearchDescriptor>(xReplaceDescr, UNO_QUERY_THROW));
77 //check that it works
78 xElement = xReplaceable->findFirst(xSearchDescr);
79 CPPUNIT_ASSERT(xElement.is());
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());
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */