xref: /AOO41X/main/qadevOOo/tests/java/ifc/text/_XSimpleText.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.text;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import com.sun.star.text.ControlCharacter;
30cdf0e10cSrcweir import com.sun.star.text.XSimpleText;
31cdf0e10cSrcweir import com.sun.star.text.XTextCursor;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /**
34cdf0e10cSrcweir * Testing <code>com.sun.star.text.XSimpleText</code>
35cdf0e10cSrcweir * interface methods :
36cdf0e10cSrcweir * <ul>
37cdf0e10cSrcweir *  <li><code> createTextCursor()</code></li>
38cdf0e10cSrcweir *  <li><code> createTextCursorByRange()</code></li>
39cdf0e10cSrcweir *  <li><code> insertString()</code></li>
40cdf0e10cSrcweir *  <li><code> insertControlCharacter()</code></li>
41cdf0e10cSrcweir * </ul> <p>
42cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
43cdf0e10cSrcweir * @see com.sun.star.text.XSimpleText
44cdf0e10cSrcweir */
45cdf0e10cSrcweir public class _XSimpleText extends MultiMethodTest {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     XTextCursor oCursor = null;
48cdf0e10cSrcweir     public XSimpleText oObj = null;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     /**
51cdf0e10cSrcweir     * Creates text cursor. <p>
52cdf0e10cSrcweir     * Has <b> OK </b> status if not null value returned. <p>
53cdf0e10cSrcweir     */
_createTextCursor()54cdf0e10cSrcweir     public void _createTextCursor() {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         log.println( "Testing createTextCursor()" );
57cdf0e10cSrcweir         oCursor = oObj.createTextCursor();
58cdf0e10cSrcweir         tRes.tested( "createTextCursor()", oCursor != null );
59cdf0e10cSrcweir     }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     /**
62cdf0e10cSrcweir     * Inserts a string at the cursor position.<p>
63cdf0e10cSrcweir     * Has <b> OK </b> status if the whole result string has a string
64cdf0e10cSrcweir     * inserted as its substring. <p>
65cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
66cdf0e10cSrcweir     * <ul>
67cdf0e10cSrcweir     *  <li> <code> createTextCursor() </code> : to have a cursor
68cdf0e10cSrcweir     *   where text should be inserted. </li>
69cdf0e10cSrcweir     * </ul>
70cdf0e10cSrcweir     */
_insertString()71cdf0e10cSrcweir     public void _insertString() {
72cdf0e10cSrcweir         requiredMethod("createTextCursor()");
73cdf0e10cSrcweir         log.println( "Testing insertString" );
74cdf0e10cSrcweir         String sStr = getInterfaceName() ;
75cdf0e10cSrcweir         oObj.insertString( oCursor, sStr, false );
76cdf0e10cSrcweir         String gStr = oObj.getText().getString() ;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         tRes.tested( "insertString()", gStr != null &&
79cdf0e10cSrcweir             gStr.indexOf(sStr) >= 0) ;
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /**
83cdf0e10cSrcweir     * Inserts paragraph break character into text and then checks
84cdf0e10cSrcweir     * if this character is present in the result string. <p>
85cdf0e10cSrcweir     * Has <b> OK </b> status if the result string has
86cdf0e10cSrcweir     * paragraph break character. <p>
87cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
88cdf0e10cSrcweir     * <ul>
89cdf0e10cSrcweir     *  <li> <code> createTextCursor </code> : to have a cursor object. </li>
90cdf0e10cSrcweir     * </ul>
91cdf0e10cSrcweir     */
_insertControlCharacter()92cdf0e10cSrcweir     public void _insertControlCharacter() {
93cdf0e10cSrcweir         boolean bOK = true;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         requiredMethod("createTextCursor()");
96cdf0e10cSrcweir         log.println( "Testing insertControlCharacter()" );
97cdf0e10cSrcweir         try {
98cdf0e10cSrcweir             oObj.insertControlCharacter( oCursor,
99cdf0e10cSrcweir                 ControlCharacter.PARAGRAPH_BREAK, false);
100cdf0e10cSrcweir             oObj.insertControlCharacter( oCursor,
101cdf0e10cSrcweir                 ControlCharacter.LINE_BREAK, false);
102cdf0e10cSrcweir             oObj.insertString(oObj.createTextCursor(),"newLine",false);
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir         catch(com.sun.star.lang.IllegalArgumentException e ) {
105cdf0e10cSrcweir             // Some exception.FAILED
106cdf0e10cSrcweir             Status.failed( e.toString() );
107cdf0e10cSrcweir             bOK = false;
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir         String gStr = oObj.getString() ;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         tRes.tested( "insertControlCharacter()", bOK && gStr != null &&
112cdf0e10cSrcweir             gStr.indexOf("\n") > -1);
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     /**
116cdf0e10cSrcweir     * Creates another text cursor using existing cursor's range. <p>
117cdf0e10cSrcweir     * Has <b> OK </b> status if not null value returned. <p>
118cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
119cdf0e10cSrcweir     * <ul>
120cdf0e10cSrcweir     *  <li> <code> createTextCursor </code> : to have a cursor object. </li>
121cdf0e10cSrcweir     * </ul>
122cdf0e10cSrcweir     */
_createTextCursorByRange()123cdf0e10cSrcweir     public void _createTextCursorByRange() {
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         requiredMethod("createTextCursor()");
126cdf0e10cSrcweir         oCursor.gotoStart(false);
127cdf0e10cSrcweir         log.println( "Testing createTextCursorByRange()" );
128cdf0e10cSrcweir         XTextCursor oTCursor = oObj.createTextCursorByRange(oCursor);
129cdf0e10cSrcweir         tRes.tested("createTextCursorByRange()", oTCursor != null) ;
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir }  // finish class _XSimpleText
132cdf0e10cSrcweir 
133