2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.text
.XTextRange
;
26 import com
.sun
.star
.text
.XTextRangeMover
;
29 * Testing <code>com.sun.star.text.XTextRangeMover</code>
32 * <li><code> moveTextRange()</code></li>
34 * This test needs the following object relations :
36 * <li> <code>'RangeForMove'</code> (of type <code>XTextRange</code>):
37 * the range to be moved. </li>
38 * <li> <code>'XTextRange'</code> (of type <code>XTextRange</code>):
39 * the range that includes moving range. </li>
41 * Test is <b> NOT </b> multithread compliant. <p>
42 * @see com.sun.star.text.XTextRangeMover
44 public class _XTextRangeMover
extends MultiMethodTest
{
46 public XTextRangeMover oObj
= null;
48 XTextRange xTextRange
= null;
49 XTextRange oMoveRange
= null;
52 * Moves the range obtained from relation 'RangeForMove' by 1 paragraph
53 * and compares index of moved string in the whole text obtained
54 * from relation 'XTextRange'. <p>
55 * Has <b>OK</b> status if index of moved range is changed after method call.
57 public void _moveTextRange(){
58 oMoveRange
= (XTextRange
) tEnv
.getObjRelation("RangeForMove");
59 xTextRange
= (XTextRange
) tEnv
.getObjRelation("XTextRange");
61 if (oMoveRange
== null) {
62 throw new StatusException(
63 Status
.failed("Couldn't get relation 'RangeForMove'"));
66 if (xTextRange
== null) {
67 throw new StatusException(
68 Status
.failed("Couldn't get relation 'XTextRange'"));
71 log
.println("Content before moving:");
72 log
.println(xTextRange
.getString());
73 log
.println("Text range for moving:");
74 log
.println(oMoveRange
.getString());
75 int indexBefore
= xTextRange
.getString().indexOf(oMoveRange
.getString());
76 oObj
.moveTextRange(oMoveRange
,(short) 1);
77 log
.println("Content after moving:");
78 log
.println(xTextRange
.getString());
79 int indexAfter
= xTextRange
.getString().indexOf(oMoveRange
.getString());
81 boolean res
= indexBefore
!= indexAfter
;
82 log
.println("Index before moving:" + indexBefore
);
83 log
.println("Index after moving:" + indexAfter
);
85 tRes
.tested("moveTextRange()", res
);