tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XTextCursor.java
blob87369a7ec42683db0471bd06a74bad8d50f47dd4
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 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 ;
52 /**
53 * Stores component's text.
55 @Override
56 public void before() {
57 oObj.gotoStart(false);
58 oObj.gotoEnd(true);
59 oldText = oObj.getString() ;
62 /**
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
69 * empty string.
71 public void _collapseToEnd(){
72 boolean bCol = false;
74 oObj.setString("XTextCursor");
75 oObj.gotoStart(false);
76 oObj.gotoEnd(true);
77 oObj.collapseToEnd();
78 bCol = oObj.getString().equals("");
79 tRes.tested("collapseToEnd()", bCol );
82 /**
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
89 * empty string.
91 public void _collapseToStart(){
92 boolean bCol = false;
93 oObj.setString("XTextCursor");
94 oObj.gotoStart(false);
95 oObj.gotoEnd(true);
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
105 * of characters. <p>
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;
113 short n = 5;
115 oObj.gotoEnd(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
127 * of characters. <p>
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;
135 short n = 5;
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;
154 short n = 1;
156 oObj.gotoEnd(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
165 * text. <p>
167 * Has <b>OK</b> status if some characters to the right
168 * of the current cursor position are the beginning of
169 * the text.
171 public void _gotoRange(){
172 boolean bRange = false;
174 oObj.gotoStart(false);
175 oObj.gotoEnd(true);
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;
194 short n = 1;
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();
217 oObj.gotoEnd(true);
218 bCol &= !oObj.isCollapsed() ;
220 tRes.tested("isCollapsed()", bCol );
224 * Restores the text of the component to the
225 * state it was before this interface test.
227 @Override
228 public void after() {
229 oObj.gotoStart(false);
230 oObj.gotoEnd(true);
231 oObj.setString(oldText) ;
234 } // finish class _XTextCursor