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