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 com
.sun
.star
.text
.XTextCursor
;
27 * Testing <code>com.sun.star.text.XTextCursor</code>
30 * <li><code> collapseToStart()</code></li>
31 * <li><code> collapseToEnd()</code></li>
32 * <li><code> isCollapsed()</code></li>
33 * <li><code> goLeft()</code></li>
34 * <li><code> goRight()</code></li>
35 * <li><code> gotoStart()</code></li>
36 * <li><code> gotoEnd()</code></li>
37 * <li><code> gotoRange()</code></li>
40 * During this test the component text is changed,
41 * that's why it must be stored before methods' tests,
42 * and restored after. <p>
44 * Test is <b> NOT </b> multithread compliant. <p>
45 * @see com.sun.star.text.XTextCursor
47 public class _XTextCursor
extends MultiMethodTest
{
49 public XTextCursor oObj
= null; // oObj filled by MultiMethodTest
50 String oldText
= null ;
53 * Stores component's text.
56 public void before() {
57 oObj
.gotoStart(false);
59 oldText
= oObj
.getString() ;
63 * First some text is set (for component to has at least some
64 * text), cursor is expanded to the whole text (to be not collapsed),
65 * the <code>collapseToEnd</code> is called. Then current cursor
66 * text is examined. <p>
68 * Has <b>OK</b> status if the current cursor text is an
71 public void _collapseToEnd(){
74 oObj
.setString("XTextCursor");
75 oObj
.gotoStart(false);
78 bCol
= oObj
.getString().equals("");
79 tRes
.tested("collapseToEnd()", bCol
);
83 * First some text is set (for component to has at least some
84 * text), cursor is expanded to the whole text (to be not collapsed),
85 * the <code>collapseToStart</code> is called. Then current cursor
86 * text is examined. <p>
88 * Has <b>OK</b> status if the current cursor text is an
91 public void _collapseToStart(){
93 oObj
.setString("XTextCursor");
94 oObj
.gotoStart(false);
97 oObj
.collapseToStart();
98 bCol
= oObj
.getString().equals("");
99 tRes
.tested("collapseToStart()", bCol
);
103 * First the cursor is moved to the end of text (to have a space
104 * for left cursor moving, and moves the cursor left by a number
107 * Has <b>OK</b> status if the method returns <code>true</code>,
108 * and the current cursor string has the same length as number
109 * of characters the cursor was moved by.
111 public void _goLeft(){
112 boolean bLeft
= false;
116 bLeft
= oObj
.goLeft(n
, true);
117 String gStr
= oObj
.getString() ;
118 log
.println("'" + gStr
+ "'") ;
119 bLeft
&= gStr
.length() == n
;
121 tRes
.tested("goLeft()", bLeft
);
125 * First the cursor is moved to the start of text (to have a space
126 * for right cursor moving, and moves the cursor right by a number
129 * Has <b>OK</b> status if the method returns <code>true</code>,
130 * and the current cursor string has the same length as number
131 * of characters the cursor was moved by.
133 public void _goRight(){
134 boolean bRight
= false;
137 oObj
.gotoStart(false);
138 bRight
= oObj
.goRight(n
, true);
140 String gStr
= oObj
.getString() ;
141 log
.println("'" + gStr
+ "'") ;
142 bRight
&= gStr
.length() == n
;
144 tRes
.tested("goRight()", bRight
);
148 * Test calls the method. <p>
149 * Has <b> OK </b> status if the method <code>goRight()</code>
150 * returns <code>false</code> (cursor can't move to the right).
152 public void _gotoEnd(){
153 boolean bEnd
= false;
157 bEnd
= !oObj
.goRight(n
, false) ;
159 tRes
.tested("gotoEnd()", bEnd
);
163 * First the whole text is set to a string, and cursor
164 * is moved to the range situated at the start of the
167 * Has <b>OK</b> status if some characters to the right
168 * of the current cursor position are the beginning of
171 public void _gotoRange(){
172 boolean bRange
= false;
174 oObj
.gotoStart(false);
176 oObj
.setString("XTextCursor,XTextCursor");
177 oObj
.gotoRange(oObj
.getStart(),false);
178 oObj
.goRight((short) 5, true);
179 bRange
= oObj
.getString().equals("XText");
181 if (!bRange
) log
.println("getString() returned '" +
182 oObj
.getString() + "'") ;
184 tRes
.tested("gotoRange()", bRange
);
188 * Test calls the method. <p>
189 * Has <b> OK </b> status if the method <code>goLeft()</code>
190 * returns <code>false</code> (cursor can't move to the left).
192 public void _gotoStart(){
193 boolean bStart
= false;
196 oObj
.gotoStart(false);
197 bStart
= !oObj
.goLeft(n
, false) ;
199 tRes
.tested("gotoStart()", bStart
);
203 * First the cursor is moved to start without expanding
204 * (must be collapsed), and then it's expanded to the
205 * whole text (must not be collapsed). <p>
207 * Has <b>OK</b> status if in the first case method
208 * <code>isCollapsed</code> returns <code>true</code>,
209 * and in the second <code>false</code>
211 public void _isCollapsed(){
212 boolean bCol
= false;
214 oObj
.gotoStart(false);
215 bCol
= oObj
.isCollapsed();
218 bCol
&= !oObj
.isCollapsed() ;
220 tRes
.tested("isCollapsed()", bCol
);
224 * Restores the text of the component to the
225 * state it was before this interafce test.
228 public void after() {
229 oObj
.gotoStart(false);
231 oObj
.setString(oldText
) ;
234 } // finish class _XTextCursor