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