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