bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XTextCursor.java
blob25102914b15860681dd2b5506beef9dc52d6d159
1 /*
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 .
19 package ifc.text;
21 import lib.MultiMethodTest;
23 import com.sun.star.text.XTextCursor;
26 /**
27 * Testing <code>com.sun.star.text.XTextCursor</code>
28 * interface methods :
29 * <ul>
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>
38 * </ul> <p>
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 ;
52 /**
53 * Stores component's text.
55 public void before() {
56 oObj.gotoStart(false);
57 oObj.gotoEnd(true);
58 oldText = oObj.getString() ;
61 /**
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
68 * empty string.
70 public void _collapseToEnd(){
71 boolean bCol = false;
73 oObj.setString("XTextCursor");
74 oObj.gotoStart(false);
75 oObj.gotoEnd(true);
76 oObj.collapseToEnd();
77 bCol = oObj.getString().equals("");
78 tRes.tested("collapseToEnd()", bCol );
81 /**
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
88 * empty string.
90 public void _collapseToStart(){
91 boolean bCol = false;
92 oObj.setString("XTextCursor");
93 oObj.gotoStart(false);
94 oObj.gotoEnd(true);
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
104 * of characters. <p>
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;
112 short n = 5;
114 oObj.gotoEnd(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
126 * of characters. <p>
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;
134 short n = 5;
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;
153 short n = 1;
155 oObj.gotoEnd(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
164 * text. <p>
166 * Has <b>OK</b> status if some characters to the right
167 * of the current cursor position are the beginning of
168 * the text.
170 public void _gotoRange(){
171 boolean bRange = false;
173 oObj.gotoStart(false);
174 oObj.gotoEnd(true);
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;
193 short n = 1;
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();
216 oObj.gotoEnd(true);
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);
228 oObj.gotoEnd(true);
229 oObj.setString(oldText) ;
232 } // finish class _XTextCursor