Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2011 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <test/util/xreplaceable.hxx>
30 :
31 : #include <com/sun/star/util/XReplaceable.hpp>
32 : #include <com/sun/star/util/XReplaceDescriptor.hpp>
33 : #include <com/sun/star/util/XSearchDescriptor.hpp>
34 : #include "cppunit/extensions/HelperMacros.h"
35 :
36 : #include <iostream>
37 :
38 : using namespace com::sun::star::uno;
39 :
40 : namespace apitest {
41 :
42 0 : void XReplaceable::testCreateReplaceDescriptor()
43 : {
44 0 : uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
45 0 : uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
46 0 : CPPUNIT_ASSERT(xReplaceDescr.is());
47 0 : }
48 :
49 0 : void XReplaceable::testReplaceAll()
50 : {
51 0 : std::cout << "testReplaceAll" << std::endl;
52 0 : uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
53 0 : uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
54 0 : CPPUNIT_ASSERT(xReplaceDescr.is());
55 :
56 0 : uno::Reference< util::XSearchDescriptor > xSearchDescr = xReplaceable->createSearchDescriptor();
57 0 : xSearchDescr->setSearchString(maSearchString);
58 :
59 : //check that at least one object is there that will be replaced
60 0 : uno::Reference< uno::XInterface > xElement = xReplaceable->findFirst(xSearchDescr);
61 0 : CPPUNIT_ASSERT(xElement.is());
62 :
63 : //check that there is none object with the replace string
64 0 : xSearchDescr->setSearchString(maReplaceString);
65 0 : xElement = xReplaceable->findFirst(xSearchDescr);
66 0 : CPPUNIT_ASSERT(!xElement.is());
67 :
68 0 : xReplaceDescr->setSearchString(maSearchString);
69 0 : xReplaceDescr->setReplaceString(maReplaceString);
70 :
71 0 : xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
72 :
73 : //check that now at least one element is found
74 0 : xElement = xReplaceable->findFirst(xSearchDescr);
75 0 : CPPUNIT_ASSERT(xElement.is());
76 :
77 0 : xSearchDescr->setSearchString(maSearchString);
78 0 : xElement = xReplaceable->findFirst(xSearchDescr);
79 0 : CPPUNIT_ASSERT(!xElement.is());
80 :
81 : //redo the whole thing
82 0 : xReplaceDescr->setSearchString(maReplaceString);
83 0 : xReplaceDescr->setReplaceString(maSearchString);
84 :
85 0 : xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
86 :
87 : //check that it works
88 0 : xElement = xReplaceable->findFirst(xSearchDescr);
89 0 : CPPUNIT_ASSERT(xElement.is());
90 :
91 : //check that there is none object with the replace string
92 0 : xSearchDescr->setSearchString(maReplaceString);
93 0 : xElement = xReplaceable->findFirst(xSearchDescr);
94 0 : CPPUNIT_ASSERT(!xElement.is());
95 0 : }
96 :
97 0 : }
98 :
99 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|