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