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
.XText
;
26 import com
.sun
.star
.text
.XTextCursor
;
27 import com
.sun
.star
.text
.XTextDocument
;
28 import com
.sun
.star
.text
.XTextRangeCompare
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
30 import com
.sun
.star
.uno
.XInterface
;
33 * Testing <code>com.sun.star.text.XTextRangeCompare</code>
36 * <li><code> compareRegionStarts()</code></li>
37 * <li><code> compareRegionEnds()</code></li>
39 * This test needs the following object relations :
41 * <li> <code>'TEXTDOC'</code> <b>optional</b>
42 * (must implement <code>XTextDocument</code>):
43 * can be used to obtain <code>Text</code> of the document from
44 * which cursors can be created.
45 * If the relation does not exist, the relation <code>TEXT</code>
46 * must be specified. </li>
47 * <li> <code>'TEXT'</code> <b>optional</b>
48 * (of type <code>XText</code>):
49 * used to create text cursor.
50 * If the relation does not exist, the relation <code>TEXTDOC</code>
51 * must be specified. </li>
53 * Test is <b> NOT </b> multithread compliant. <p>
54 * @see com.sun.star.text.XTextRangeCompare
56 public class _XTextRangeCompare
extends MultiMethodTest
{
61 public XTextRangeCompare oObj
= null;
62 String nameStr
= null;
63 XTextCursor cursor1
= null;
64 XTextCursor cursor2
= null;
68 * Retrieves <code>XText</code> interface from relation 'TEXTDOC'
70 * @throws StatusException If neither 'TEXTDOC' nor 'TEXT'
74 public void before() {
75 nameStr
= this.getClass().getName();
77 XInterface oIfc
= (XInterface
)tEnv
.getObjRelation("TEXTDOC");
79 XTextDocument oTDoc
= UnoRuntime
.queryInterface(
80 XTextDocument
.class, oIfc
);
81 oText
= oTDoc
.getText();
83 XText aText
= (XText
) tEnv
.getObjRelation("TEXT");
89 throw new StatusException(Status
.failed
90 ("Neither 'TEXTDOC' nor 'TEXT' relation not found")) ;
95 * One cursor is created and to its position a paragraph
96 * inserted, then the first five characters were selected.
97 * A second cursor was created and the last 7 characters
100 * Has <b>OK</b> status if the compare returns 1, i.e.
101 * the second cursor end is before the first.
103 public void _compareRegionEnds() {
104 boolean bResult
= false;
106 log
.println( "testing compareRegionEnds()" );
109 cursor1
= oText
.createTextCursor();
110 oText
.insertString(cursor1
, nameStr
, false);
112 cursor1
.gotoStart(false);
113 cursor1
.goRight((short)5, true);
114 cursor2
= oText
.createTextCursor();
115 cursor2
.gotoEnd(false);
116 cursor2
.goLeft((short)7, true);
118 log
.println("hole text: '" + oText
.getString() + "'");
119 log
.println("cursor1: '"+cursor1
.getString() + "'");
120 log
.println("cursor2: '"+cursor2
.getString() + "'");
121 log
.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
123 n
= oObj
.compareRegionEnds(cursor1
, cursor2
);
125 log
.println( "Result (short) : " + n
);
126 }catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
127 log
.println( "Exception: " + e
);
128 e
.printStackTrace(log
);
131 if (n
== 1){bResult
= true;}
132 tRes
.tested( "compareRegionEnds()", bResult
);
136 * One cursor is created and to its position a paragraph
137 * inserted, then the first five characters were selected.
138 * A second cursor was created and the last 7 characters
141 * Has <b>OK</b> status if the compare returns 1, i.e.
142 * the second cursor start is before the first.
144 public void _compareRegionStarts() {
145 boolean bResult
= false;
149 cursor1
= oText
.createTextCursor();
150 oText
.insertString(cursor1
, nameStr
, false);
152 cursor1
.gotoStart(false);
153 cursor1
.goRight((short)5, true);
154 cursor2
= oText
.createTextCursor();
155 cursor2
.gotoEnd(false);
156 cursor2
.goLeft((short)7, true);
158 log
.println("hole text: '" + oText
.getString() + "'");
159 log
.println("cursor1: '"+cursor1
.getString() + "'");
160 log
.println("cursor2: '"+cursor2
.getString() + "'");
161 log
.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
162 n
= oObj
.compareRegionStarts(cursor1
, cursor2
);
164 log
.println( "Result (short) : " + n
);
165 }catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
166 log
.println( "Exception: " + e
);
167 e
.printStackTrace(log
);
169 if (n
== 1){bResult
= true;}
170 tRes
.tested( "compareRegionStarts()", bResult
);