xref: /AOO41X/main/qadevOOo/tests/java/ifc/text/_XTextCursor.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.text;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.text.XTextCursor;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /**
32cdf0e10cSrcweir  * Testing <code>com.sun.star.text.XTextCursor</code>
33cdf0e10cSrcweir  * interface methods :
34cdf0e10cSrcweir  * <ul>
35cdf0e10cSrcweir  *  <li><code> collapseToStart()</code></li>
36cdf0e10cSrcweir  *  <li><code> collapseToEnd()</code></li>
37cdf0e10cSrcweir  *  <li><code> isCollapsed()</code></li>
38cdf0e10cSrcweir  *  <li><code> goLeft()</code></li>
39cdf0e10cSrcweir  *  <li><code> goRight()</code></li>
40cdf0e10cSrcweir  *  <li><code> gotoStart()</code></li>
41cdf0e10cSrcweir  *  <li><code> gotoEnd()</code></li>
42cdf0e10cSrcweir  *  <li><code> gotoRange()</code></li>
43cdf0e10cSrcweir  * </ul> <p>
44cdf0e10cSrcweir  *
45cdf0e10cSrcweir  * During this test the component text is changed,
46cdf0e10cSrcweir  * that's why it must be stored before methods' tests,
47cdf0e10cSrcweir  * and restored after. <p>
48cdf0e10cSrcweir  *
49cdf0e10cSrcweir  * Test is <b> NOT </b> multithread compilant. <p>
50cdf0e10cSrcweir  * @see com.sun.star.text.XTextCursor
51cdf0e10cSrcweir  */
52cdf0e10cSrcweir public class _XTextCursor extends MultiMethodTest {
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     public XTextCursor oObj = null;     // oObj filled by MultiMethodTest
55cdf0e10cSrcweir     String oldText = null ;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     /**
58cdf0e10cSrcweir      * Stores component's text.
59cdf0e10cSrcweir      */
before()60cdf0e10cSrcweir     public void before() {
61cdf0e10cSrcweir         oObj.gotoStart(false);
62cdf0e10cSrcweir         oObj.gotoEnd(true);
63cdf0e10cSrcweir         oldText = oObj.getString() ;
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /**
67cdf0e10cSrcweir      * First some text is set (for component to has at least some
68cdf0e10cSrcweir      * text), cursor is expanded to the whole text (to be not collapsed),
69cdf0e10cSrcweir      * the <code>collapseToEnd</code> is called. Then current cursor
70cdf0e10cSrcweir      * text is examined. <p>
71cdf0e10cSrcweir      *
72cdf0e10cSrcweir      * Has <b>OK</b> status if the current cursor text is an
73cdf0e10cSrcweir      * empty string.
74cdf0e10cSrcweir      */
_collapseToEnd()75cdf0e10cSrcweir     public void _collapseToEnd(){
76cdf0e10cSrcweir         boolean bCol = false;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         oObj.setString("XTextCursor");
79cdf0e10cSrcweir         oObj.gotoStart(false);
80cdf0e10cSrcweir         oObj.gotoEnd(true);
81cdf0e10cSrcweir         oObj.collapseToEnd();
82cdf0e10cSrcweir         bCol = oObj.getString().equals("");
83cdf0e10cSrcweir         tRes.tested("collapseToEnd()", bCol );
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     /**
87cdf0e10cSrcweir      * First some text is set (for component to has at least some
88cdf0e10cSrcweir      * text), cursor is expanded to the whole text (to be not collapsed),
89cdf0e10cSrcweir      * the <code>collapseToStart</code> is called. Then current cursor
90cdf0e10cSrcweir      * text is examined. <p>
91cdf0e10cSrcweir      *
92cdf0e10cSrcweir      * Has <b>OK</b> status if the current cursor text is an
93cdf0e10cSrcweir      * empty string.
94cdf0e10cSrcweir      */
_collapseToStart()95cdf0e10cSrcweir     public void _collapseToStart(){
96cdf0e10cSrcweir         boolean bCol = false;
97cdf0e10cSrcweir         oObj.setString("XTextCursor");
98cdf0e10cSrcweir         oObj.gotoStart(false);
99cdf0e10cSrcweir         oObj.gotoEnd(true);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         oObj.collapseToStart();
102cdf0e10cSrcweir         bCol = oObj.getString().equals("");
103cdf0e10cSrcweir         tRes.tested("collapseToStart()", bCol );
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /**
107cdf0e10cSrcweir      * First the cursor is moved to the end of text (to have a space
108cdf0e10cSrcweir      * for left cursor moving, and moves the cursor left by a number
109cdf0e10cSrcweir      * of characters. <p>
110cdf0e10cSrcweir      *
111cdf0e10cSrcweir      * Has <b>OK</b> status if the method returns <code>true</code>,
112cdf0e10cSrcweir      * and the current cursor string has the same length as number
113cdf0e10cSrcweir      * of characters the cursor was moved by.
114cdf0e10cSrcweir      */
_goLeft()115cdf0e10cSrcweir     public void _goLeft(){
116cdf0e10cSrcweir         boolean bLeft = false;
117cdf0e10cSrcweir         short n = 5;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         oObj.gotoEnd(false);
120cdf0e10cSrcweir         bLeft = oObj.goLeft(n, true);
121cdf0e10cSrcweir         String gStr = oObj.getString() ;
122cdf0e10cSrcweir         log.println("'" + gStr + "'") ;
123cdf0e10cSrcweir         bLeft &= gStr.length() == n ;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         tRes.tested("goLeft()", bLeft );
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     /**
129cdf0e10cSrcweir      * First the cursor is moved to the start of text (to have a space
130cdf0e10cSrcweir      * for right cursor moving, and moves the cursor right by a number
131cdf0e10cSrcweir      * of characters. <p>
132cdf0e10cSrcweir      *
133cdf0e10cSrcweir      * Has <b>OK</b> status if the method returns <code>true</code>,
134cdf0e10cSrcweir      * and the current cursor string has the same length as number
135cdf0e10cSrcweir      * of characters the cursor was moved by.
136cdf0e10cSrcweir      */
_goRight()137cdf0e10cSrcweir     public void _goRight(){
138cdf0e10cSrcweir         boolean bRight = false;
139cdf0e10cSrcweir         short n = 5;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         oObj.gotoStart(false);
142cdf0e10cSrcweir         bRight = oObj.goRight(n, true);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         String gStr = oObj.getString() ;
145cdf0e10cSrcweir         log.println("'" + gStr + "'") ;
146cdf0e10cSrcweir         bRight &= gStr.length() == n ;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         tRes.tested("goRight()", bRight );
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     /**
152cdf0e10cSrcweir      * Test calls the method. <p>
153cdf0e10cSrcweir      * Has <b> OK </b> status if the method <code>goRight()</code>
154cdf0e10cSrcweir      * returns <code>false</code> (cursor can't move to the right).
155cdf0e10cSrcweir      */
_gotoEnd()156cdf0e10cSrcweir     public void _gotoEnd(){
157cdf0e10cSrcweir         boolean bEnd = false;
158cdf0e10cSrcweir         short n = 1;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         oObj.gotoEnd(false);
161cdf0e10cSrcweir         bEnd = !oObj.goRight(n, false) ;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         tRes.tested("gotoEnd()", bEnd );
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     /**
167cdf0e10cSrcweir      * First the whole text is set to a string, and cursor
168cdf0e10cSrcweir      * is moved to the range situated at the start of the
169cdf0e10cSrcweir      * text. <p>
170cdf0e10cSrcweir      *
171cdf0e10cSrcweir      * Has <b>OK</b> status if some characters to the right
172cdf0e10cSrcweir      * of the current cursor position are the beginning of
173cdf0e10cSrcweir      * the text.
174cdf0e10cSrcweir      */
_gotoRange()175cdf0e10cSrcweir     public void _gotoRange(){
176cdf0e10cSrcweir         boolean bRange = false;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         oObj.gotoStart(false);
179cdf0e10cSrcweir         oObj.gotoEnd(true);
180cdf0e10cSrcweir         oObj.setString("XTextCursor,XTextCursor");
181cdf0e10cSrcweir         oObj.gotoRange(oObj.getStart(),false);
182cdf0e10cSrcweir         oObj.goRight((short) 5, true);
183cdf0e10cSrcweir         bRange = oObj.getString().equals("XText");
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         if (!bRange) log.println("getString() returned '" +
186cdf0e10cSrcweir             oObj.getString() + "'") ;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         tRes.tested("gotoRange()", bRange );
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     /**
192cdf0e10cSrcweir      * Test calls the method. <p>
193cdf0e10cSrcweir      * Has <b> OK </b> status if the method <code>goLeft()</code>
194cdf0e10cSrcweir      * returns <code>false</code> (cursor can't move to the left).
195cdf0e10cSrcweir      */
_gotoStart()196cdf0e10cSrcweir     public void _gotoStart(){
197cdf0e10cSrcweir         boolean bStart = false;
198cdf0e10cSrcweir         short n = 1;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         oObj.gotoStart(false);
201cdf0e10cSrcweir         bStart = !oObj.goLeft(n, false) ;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         tRes.tested("gotoStart()", bStart );
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     /**
207cdf0e10cSrcweir      * First the cusor is moved to start without expanding
208cdf0e10cSrcweir      * (must be collapsed), and then it's expanded to the
209cdf0e10cSrcweir      * whole text (must not be collapsed). <p>
210cdf0e10cSrcweir      *
211cdf0e10cSrcweir      * Has <b>OK</b> status if in the first case method
212cdf0e10cSrcweir      * <code>isCollapsed</code> returns <code>true</code>,
213cdf0e10cSrcweir      * and in the second <code>false</code>
214cdf0e10cSrcweir      */
_isCollapsed()215cdf0e10cSrcweir     public void _isCollapsed(){
216cdf0e10cSrcweir         boolean bCol = false;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         oObj.gotoStart(false);
219cdf0e10cSrcweir         bCol = oObj.isCollapsed();
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         oObj.gotoEnd(true);
222cdf0e10cSrcweir         bCol &= !oObj.isCollapsed() ;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir         tRes.tested("isCollapsed()", bCol );
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     /**
228cdf0e10cSrcweir      * Restores the text of the component to the
229cdf0e10cSrcweir      * state it was before this interafce test.
230cdf0e10cSrcweir      */
after()231cdf0e10cSrcweir     public void after() {
232cdf0e10cSrcweir         oObj.gotoStart(false);
233cdf0e10cSrcweir         oObj.gotoEnd(true);
234cdf0e10cSrcweir         oObj.setString(oldText) ;
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir }  // finish class _XTextCursor
238cdf0e10cSrcweir 
239