1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XText.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import util
.XInstCreator
;
37 import com
.sun
.star
.container
.XIndexAccess
;
38 import com
.sun
.star
.text
.XText
;
39 import com
.sun
.star
.text
.XTextContent
;
40 import com
.sun
.star
.text
.XTextCursor
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import lib
.StatusException
;
45 * Testing <code>com.sun.star.text.XText</code>
48 * <li><code> insertTextContent()</code></li>
49 * <li><code> removeTextContent()</code></li>
51 * This test needs the following object relations :
53 * <li> <code>'XTEXTINFO'</code> (of type <code>lib.XInstCreator</code>):
54 * creator which can create instances of <code>XTextContent</code>
55 * implementations. </li>
57 * Test is <b> NOT </b> multithread compilant. <p>
58 * @see com.sun.star.text.XText
60 public class _XText
extends MultiMethodTest
{
62 public static XText oObj
= null; // oObj filled by MultiMethodTest
63 XTextCursor oCursor
= null; // textcursor
64 XInstCreator info
= null; // instance creator
65 XInterface oInt
= null; // instance to insert and remove
68 * First an instance of text content is created using relation
69 * and inserted into text. Then the number of contents is checked
70 * using the relation. Second a <code>null</code> content is tried
73 * Has <b> OK </b> status if in the first case after inserting number
74 * of content objects is greater than zero and in the second
75 * case <code>IllegalArgumentException</code> is thrown. <p>
77 public void _insertTextContent() {
78 boolean result
= false;
79 info
= (XInstCreator
)tEnv
.getObjRelation( "XTEXTINFO" );
80 oInt
= info
.createInstance();
82 // write to log what we try next
83 log
.println( "test for createTextCursor()" );
84 oCursor
= oObj
.createTextCursor();
86 // write to log what we try next
87 log
.println( "test for insertTextContent()" );
89 oObj
.insertTextContent(oCursor
, (XTextContent
)oInt
, false);
91 catch( com
.sun
.star
.lang
.IllegalArgumentException iaE
){
92 throw new StatusException("Couldn't insert textcontent",iaE
);
93 //Status.failed(iaE.toString());
97 // get indexaccess to the tablecollection
98 XIndexAccess xIA
= info
.getCollection();
100 // this comparision works just because it has to be at least one
101 // table at this point regardless which thread inserted it
102 // there is although the possibility that the first threads call
103 // failed, the second not and comparision happens after second threads
104 // otherwise if something fails it should have thrown an exception
105 //tRes.tested("insertTextContent()", xIA.getCount() > 0 );
108 result
= (xIA
.getCount()>0);
113 if (!result
) log
.println("The TextContent wasn't inserted");
116 // try to insert an invalid TextContent
117 log
.println( "test for insertTextContent" );
119 oObj
.insertTextContent(oCursor
, null, false);
120 log
.println("The expected Exception doesn't occured");
123 catch( com
.sun
.star
.lang
.IllegalArgumentException iaE
){
124 // Some exception.FAILED
125 log
.println("Expected Exception occured");
126 String msg
= iaE
.getMessage();
127 if (msg
.equals("")) {
128 log
.println("But there is not detailed message");
130 log
.println("Detailed message: "+msg
);
136 tRes
.tested("insertTextContent()", result
);
141 * Removes the text contet added before. <p>
142 * Has <b> OK </b> status if the method successfully returns
143 * and no exceptions were thrown. <p>
144 * The following method tests are to be completed successfully before :
146 * <li> <code> insertTextContent() </code> : inserts the content
147 * to be removed in this test. </li>
150 public void _removeTextContent() {
152 // leads to a method which should be called previously
153 requiredMethod( "insertTextContent()" );
155 // write to log what we try next
156 log
.println( "test for removeTextContent" );
158 oObj
.removeTextContent( (XTextContent
)oInt
);
159 //oObj.removeTextContent( (XTextContent)oInt );
161 catch( com
.sun
.star
.container
.NoSuchElementException nseE
){
162 // Some exception.FAILED
163 Status
.failed( nseE
.toString() );
167 // no exception occured so it works
168 tRes
.tested( "removeTextContent()", true );
171 } // finish class _XText