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 compilant. <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.
55 public void before() {
56 oObj
.gotoStart(false);
58 oldText
= oObj
.getString() ;
62 * First some text is set (for component to has at least some
63 * text), cursor is expanded to the whole text (to be not collapsed),
64 * the <code>collapseToEnd</code> is called. Then current cursor
65 * text is examined. <p>
67 * Has <b>OK</b> status if the current cursor text is an
70 public void _collapseToEnd(){
73 oObj
.setString("XTextCursor");
74 oObj
.gotoStart(false);
77 bCol
= oObj
.getString().equals("");
78 tRes
.tested("collapseToEnd()", bCol
);
82 * First some text is set (for component to has at least some
83 * text), cursor is expanded to the whole text (to be not collapsed),
84 * the <code>collapseToStart</code> is called. Then current cursor
85 * text is examined. <p>
87 * Has <b>OK</b> status if the current cursor text is an
90 public void _collapseToStart(){
92 oObj
.setString("XTextCursor");
93 oObj
.gotoStart(false);
96 oObj
.collapseToStart();
97 bCol
= oObj
.getString().equals("");
98 tRes
.tested("collapseToStart()", bCol
);
102 * First the cursor is moved to the end of text (to have a space
103 * for left cursor moving, and moves the cursor left by a number
106 * Has <b>OK</b> status if the method returns <code>true</code>,
107 * and the current cursor string has the same length as number
108 * of characters the cursor was moved by.
110 public void _goLeft(){
111 boolean bLeft
= false;
115 bLeft
= oObj
.goLeft(n
, true);
116 String gStr
= oObj
.getString() ;
117 log
.println("'" + gStr
+ "'") ;
118 bLeft
&= gStr
.length() == n
;
120 tRes
.tested("goLeft()", bLeft
);
124 * First the cursor is moved to the start of text (to have a space
125 * for right cursor moving, and moves the cursor right by a number
128 * Has <b>OK</b> status if the method returns <code>true</code>,
129 * and the current cursor string has the same length as number
130 * of characters the cursor was moved by.
132 public void _goRight(){
133 boolean bRight
= false;
136 oObj
.gotoStart(false);
137 bRight
= oObj
.goRight(n
, true);
139 String gStr
= oObj
.getString() ;
140 log
.println("'" + gStr
+ "'") ;
141 bRight
&= gStr
.length() == n
;
143 tRes
.tested("goRight()", bRight
);
147 * Test calls the method. <p>
148 * Has <b> OK </b> status if the method <code>goRight()</code>
149 * returns <code>false</code> (cursor can't move to the right).
151 public void _gotoEnd(){
152 boolean bEnd
= false;
156 bEnd
= !oObj
.goRight(n
, false) ;
158 tRes
.tested("gotoEnd()", bEnd
);
162 * First the whole text is set to a string, and cursor
163 * is moved to the range situated at the start of the
166 * Has <b>OK</b> status if some characters to the right
167 * of the current cursor position are the beginning of
170 public void _gotoRange(){
171 boolean bRange
= false;
173 oObj
.gotoStart(false);
175 oObj
.setString("XTextCursor,XTextCursor");
176 oObj
.gotoRange(oObj
.getStart(),false);
177 oObj
.goRight((short) 5, true);
178 bRange
= oObj
.getString().equals("XText");
180 if (!bRange
) log
.println("getString() returned '" +
181 oObj
.getString() + "'") ;
183 tRes
.tested("gotoRange()", bRange
);
187 * Test calls the method. <p>
188 * Has <b> OK </b> status if the method <code>goLeft()</code>
189 * returns <code>false</code> (cursor can't move to the left).
191 public void _gotoStart(){
192 boolean bStart
= false;
195 oObj
.gotoStart(false);
196 bStart
= !oObj
.goLeft(n
, false) ;
198 tRes
.tested("gotoStart()", bStart
);
202 * First the cusor is moved to start without expanding
203 * (must be collapsed), and then it's expanded to the
204 * whole text (must not be collapsed). <p>
206 * Has <b>OK</b> status if in the first case method
207 * <code>isCollapsed</code> returns <code>true</code>,
208 * and in the second <code>false</code>
210 public void _isCollapsed(){
211 boolean bCol
= false;
213 oObj
.gotoStart(false);
214 bCol
= oObj
.isCollapsed();
217 bCol
&= !oObj
.isCollapsed() ;
219 tRes
.tested("isCollapsed()", bCol
);
223 * Restores the text of the component to the
224 * state it was before this interafce test.
226 public void after() {
227 oObj
.gotoStart(false);
229 oObj
.setString(oldText
) ;
232 } // finish class _XTextCursor