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 import lib.Status; 28 29 import com.sun.star.text.ControlCharacter; 30 import com.sun.star.text.XSimpleText; 31 import com.sun.star.text.XTextCursor; 32 33 /** 34 * Testing <code>com.sun.star.text.XSimpleText</code> 35 * interface methods : 36 * <ul> 37 * <li><code> createTextCursor()</code></li> 38 * <li><code> createTextCursorByRange()</code></li> 39 * <li><code> insertString()</code></li> 40 * <li><code> insertControlCharacter()</code></li> 41 * </ul> <p> 42 * Test is <b> NOT </b> multithread compilant. <p> 43 * @see com.sun.star.text.XSimpleText 44 */ 45 public class _XSimpleText extends MultiMethodTest { 46 47 XTextCursor oCursor = null; 48 public XSimpleText oObj = null; 49 50 /** 51 * Creates text cursor. <p> 52 * Has <b> OK </b> status if not null value returned. <p> 53 */ _createTextCursor()54 public void _createTextCursor() { 55 56 log.println( "Testing createTextCursor()" ); 57 oCursor = oObj.createTextCursor(); 58 tRes.tested( "createTextCursor()", oCursor != null ); 59 } 60 61 /** 62 * Inserts a string at the cursor position.<p> 63 * Has <b> OK </b> status if the whole result string has a string 64 * inserted as its substring. <p> 65 * The following method tests are to be completed successfully before : 66 * <ul> 67 * <li> <code> createTextCursor() </code> : to have a cursor 68 * where text should be inserted. </li> 69 * </ul> 70 */ _insertString()71 public void _insertString() { 72 requiredMethod("createTextCursor()"); 73 log.println( "Testing insertString" ); 74 String sStr = getInterfaceName() ; 75 oObj.insertString( oCursor, sStr, false ); 76 String gStr = oObj.getText().getString() ; 77 78 tRes.tested( "insertString()", gStr != null && 79 gStr.indexOf(sStr) >= 0) ; 80 } 81 82 /** 83 * Inserts paragraph break character into text and then checks 84 * if this character is present in the result string. <p> 85 * Has <b> OK </b> status if the result string has 86 * paragraph break character. <p> 87 * The following method tests are to be completed successfully before : 88 * <ul> 89 * <li> <code> createTextCursor </code> : to have a cursor object. </li> 90 * </ul> 91 */ _insertControlCharacter()92 public void _insertControlCharacter() { 93 boolean bOK = true; 94 95 requiredMethod("createTextCursor()"); 96 log.println( "Testing insertControlCharacter()" ); 97 try { 98 oObj.insertControlCharacter( oCursor, 99 ControlCharacter.PARAGRAPH_BREAK, false); 100 oObj.insertControlCharacter( oCursor, 101 ControlCharacter.LINE_BREAK, false); 102 oObj.insertString(oObj.createTextCursor(),"newLine",false); 103 } 104 catch(com.sun.star.lang.IllegalArgumentException e ) { 105 // Some exception.FAILED 106 Status.failed( e.toString() ); 107 bOK = false; 108 } 109 String gStr = oObj.getString() ; 110 111 tRes.tested( "insertControlCharacter()", bOK && gStr != null && 112 gStr.indexOf("\n") > -1); 113 } 114 115 /** 116 * Creates another text cursor using existing cursor's range. <p> 117 * Has <b> OK </b> status if not null value returned. <p> 118 * The following method tests are to be completed successfully before : 119 * <ul> 120 * <li> <code> createTextCursor </code> : to have a cursor object. </li> 121 * </ul> 122 */ _createTextCursorByRange()123 public void _createTextCursorByRange() { 124 125 requiredMethod("createTextCursor()"); 126 oCursor.gotoStart(false); 127 log.println( "Testing createTextCursorByRange()" ); 128 XTextCursor oTCursor = oObj.createTextCursorByRange(oCursor); 129 tRes.tested("createTextCursorByRange()", oTCursor != null) ; 130 } 131 } // finish class _XSimpleText 132 133