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.ControlCharacter;
29 import com.sun.star.text.XPageCursor;
30 import com.sun.star.text.XText;
31 import com.sun.star.text.XTextCursor;
32 import com.sun.star.text.XTextDocument;
33 
34 
35 /**
36  * Testing <code>com.sun.star.text.XPageCursor</code>
37  * interface methods :
38  * <ul>
39  *  <li><code> jumpToFirstPage()</code></li>
40  *  <li><code> jumpToLastPage()</code></li>
41  *  <li><code> jumpToPage()</code></li>
42  *  <li><code> getPage()</code></li>
43  *  <li><code> jumpToNextPage()</code></li>
44  *  <li><code> jumpToPreviousPage()</code></li>
45  *  <li><code> jumpToEndOfPage()</code></li>
46  *  <li><code> jumpToStartOfPage()</code></li>
47  * </ul> <p>
48  * This test needs the following object relations :
49  * <ul>
50  *  <li> <code>'TEXTDOC'</code> (of type <code>XTextDocument</code>):
51  *   is used to insert text to document to fill at least two pages. </li>
52  * <ul> <p>
53  * Test is <b> NOT </b> multithread compilant. <p>
54  * @see com.sun.star.text.XPageCursor
55  */
56 public class _XPageCursor extends MultiMethodTest {
57 
58     public XPageCursor oObj = null;     // oObj filled by MultiMethodTest
59     short count = 0;
60 
61     /**
62      * First adds text to the document using relation to fill at least two
63      * pages. Then obtains the number of current page. <p>
64      *
65      * Has <b>OK</b> status if the returned value is positive.
66      */
_getPage()67     public void _getPage(){
68         log.println( "test for getPage()" );
69         XTextDocument myText = (XTextDocument)tEnv.getObjRelation( "TEXTDOC" );
70         XText aText = myText.getText();
71         XTextCursor myCursor = aText.createTextCursor();
72 
73         try{
74             for (int i = 0; i < 10; i++){
75                 for (int j = 0; j < 20; j++){
76                     aText.insertString(myCursor, "The quick brown fox ",false);
77                     aText.insertString(myCursor, "jumps over the lazy dog ",
78                         false);
79                 }
80                 aText.insertControlCharacter(myCursor,
81                     ControlCharacter.PARAGRAPH_BREAK, false);
82             }
83         } catch(com.sun.star.lang.IllegalArgumentException e) {
84             log.println( "Exception :"  );
85             e.printStackTrace(log);
86         }
87 
88         count = oObj.getPage();
89         tRes.tested("getPage()", count > 0 );
90     }
91 
92     /**
93      * Test calls the method. <p>
94      * Has <b> OK </b> status if the method returns
95      * <code>true</code> value.
96      */
_jumpToEndOfPage()97     public void _jumpToEndOfPage(){
98         log.println( "test for jumpToEndOfPage()" );
99         tRes.tested("jumpToEndOfPage()", oObj.jumpToEndOfPage());
100     }
101 
102     /**
103      * Test calls the method. <p>
104      * Has <b> OK </b> status if the method returns
105      * <code>true</code> value.
106      */
_jumpToFirstPage()107     public void _jumpToFirstPage(){
108         log.println( "test for jumpToFirstPage()" );
109         tRes.tested("jumpToFirstPage()", oObj.jumpToFirstPage());
110     }
111 
112     /**
113      * Test calls the method. <p>
114      * Has <b> OK </b> status if the method returns
115      * <code>true</code> value.
116      */
_jumpToLastPage()117     public void _jumpToLastPage(){
118         log.println( "test for jumpToLastPage()" );
119         tRes.tested("jumpToLastPage()", oObj.jumpToLastPage());
120     }
121 
122     /**
123      * Firts jumps to the first page to have at least one
124      * next page, then call the method. <p>
125      * Has <b> OK </b> status if the method returns
126      * <code>true</code> value.
127      */
_jumpToNextPage()128     public void _jumpToNextPage(){
129         oObj.jumpToFirstPage() ;
130         log.println( "test for jumpToNextPage()" );
131         tRes.tested("jumpToNextPage()", oObj.jumpToNextPage());
132     }
133 
134     /**
135      * Tries to jump to the page with number 1. <p>
136      * Has <b> OK </b> status if the method returns
137      * <code>true</code> value.
138      */
_jumpToPage()139     public void _jumpToPage(){
140         short n = 1;
141         log.println( "test for jumpToPage()" );
142         tRes.tested("jumpToPage()", oObj.jumpToPage(n));
143     }
144 
145     /**
146      * Firts jumps to the last page to have at least one
147      * previous page, then call the method. <p>
148      * Has <b> OK </b> status if the method returns
149      * <code>true</code> value.
150      */
_jumpToPreviousPage()151     public void _jumpToPreviousPage(){
152         log.println( "test for jumpToPreviousPage()" );
153         oObj.jumpToLastPage();
154         tRes.tested("jumpToPreviousPage()", oObj.jumpToPreviousPage());
155     }
156 
157     /**
158      * Test calls the method. <p>
159      * Has <b> OK </b> status if the method returns
160      * <code>true</code> value.
161      */
_jumpToStartOfPage()162     public void _jumpToStartOfPage(){
163         log.println( "test for jumpToStartOfPage()" );
164         tRes.tested("jumpToStartOfPage()", oObj.jumpToStartOfPage());
165     }
166 }  // finish class _XPageCursor
167 
168