Branch data 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 : 4 : void XReplaceable::testCreateReplaceDescriptor()
43 : : {
44 [ + - ][ + - ]: 4 : uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
45 [ + - ][ + - ]: 4 : uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
46 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(xReplaceDescr.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
47 : 4 : }
48 : :
49 : 4 : void XReplaceable::testReplaceAll()
50 : : {
51 [ + - ][ + - ]: 4 : std::cout << "testReplaceAll" << std::endl;
52 [ + - ][ + - ]: 4 : uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
53 [ + - ][ + - ]: 4 : uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
54 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(xReplaceDescr.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
55 : :
56 [ + - ][ + - ]: 4 : uno::Reference< util::XSearchDescriptor > xSearchDescr = xReplaceable->createSearchDescriptor();
57 [ + - ][ + - ]: 4 : xSearchDescr->setSearchString(maSearchString);
58 : :
59 : : //check that at least one object is there that will be replaced
60 [ + - ][ + - ]: 4 : uno::Reference< uno::XInterface > xElement = xReplaceable->findFirst(xSearchDescr);
61 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(xElement.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
62 : :
63 : : //check that there is none object with the replace string
64 [ + - ][ + - ]: 4 : xSearchDescr->setSearchString(maReplaceString);
65 [ + - ][ + - ]: 4 : xElement = xReplaceable->findFirst(xSearchDescr);
[ + - ]
66 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(!xElement.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
67 : :
68 [ + - ][ + - ]: 4 : xReplaceDescr->setSearchString(maSearchString);
69 [ + - ][ + - ]: 4 : xReplaceDescr->setReplaceString(maReplaceString);
70 : :
71 [ + - ][ + - ]: 4 : xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
[ + - ]
72 : :
73 : : //check that now at least one element is found
74 [ + - ][ + - ]: 4 : xElement = xReplaceable->findFirst(xSearchDescr);
[ + - ]
75 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(xElement.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
76 : :
77 [ + - ][ + - ]: 4 : xSearchDescr->setSearchString(maSearchString);
78 [ + - ][ + - ]: 4 : xElement = xReplaceable->findFirst(xSearchDescr);
[ + - ]
79 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(!xElement.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
80 : :
81 : : //redo the whole thing
82 [ + - ][ + - ]: 4 : xReplaceDescr->setSearchString(maReplaceString);
83 [ + - ][ + - ]: 4 : xReplaceDescr->setReplaceString(maSearchString);
84 : :
85 [ + - ][ + - ]: 4 : xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
[ + - ]
86 : :
87 : : //check that it works
88 [ + - ][ + - ]: 4 : xElement = xReplaceable->findFirst(xSearchDescr);
[ + - ]
89 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(xElement.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
90 : :
91 : : //check that there is none object with the replace string
92 [ + - ][ + - ]: 4 : xSearchDescr->setSearchString(maReplaceString);
93 [ + - ][ + - ]: 4 : xElement = xReplaceable->findFirst(xSearchDescr);
[ + - ]
94 [ + - ][ + - ]: 4 : CPPUNIT_ASSERT(!xElement.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
95 : 4 : }
96 : :
97 [ + - ][ + - ]: 66 : }
98 : :
99 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|