Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XText.java
blobf93733bec2a0619824bb5cef1b573a7e5a0a7308
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc.text;
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import util.XInstCreator;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.text.XText;
36 import com.sun.star.text.XTextContent;
37 import com.sun.star.text.XTextCursor;
38 import com.sun.star.uno.XInterface;
39 import lib.StatusException;
41 /**
42 * Testing <code>com.sun.star.text.XText</code>
43 * interface methods :
44 * <ul>
45 * <li><code> insertTextContent()</code></li>
46 * <li><code> removeTextContent()</code></li>
47 * </ul> <p>
48 * This test needs the following object relations :
49 * <ul>
50 * <li> <code>'XTEXTINFO'</code> (of type <code>lib.XInstCreator</code>):
51 * creator which can create instances of <code>XTextContent</code>
52 * implementations. </li>
53 * <ul> <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.text.XText
57 public class _XText extends MultiMethodTest {
59 public static XText oObj = null; // oObj filled by MultiMethodTest
60 XTextCursor oCursor = null; // textcursor
61 XInstCreator info = null; // instance creator
62 XInterface oInt = null; // instance to insert and remove
64 /**
65 * First an instance of text content is created using relation
66 * and inserted into text. Then the number of contents is checked
67 * using the relation. Second a <code>null</code> content is tried
68 * to insert. <p>
70 * Has <b> OK </b> status if in the first case after inserting number
71 * of content objects is greater than zero and in the second
72 * case <code>IllegalArgumentException</code> is thrown. <p>
74 public void _insertTextContent() {
75 boolean result = false;
76 info = (XInstCreator)tEnv.getObjRelation( "XTEXTINFO" );
77 oInt = info.createInstance();
79 // write to log what we try next
80 log.println( "test for createTextCursor()" );
81 oCursor = oObj.createTextCursor();
83 // write to log what we try next
84 log.println( "test for insertTextContent()" );
85 try {
86 oObj.insertTextContent(oCursor, (XTextContent)oInt, false);
88 catch( com.sun.star.lang.IllegalArgumentException iaE ){
89 throw new StatusException("Couldn't insert textcontent",iaE);
90 //Status.failed(iaE.toString());
91 //return;
94 // get indexaccess to the tablecollection
95 XIndexAccess xIA = info.getCollection();
97 // this comparision works just because it has to be at least one
98 // table at this point regardless which thread inserted it
99 // there is although the possibility that the first threads call
100 // failed, the second not and comparision happens after second threads
101 // otherwise if something fails it should have thrown an exception
102 //tRes.tested("insertTextContent()", xIA.getCount() > 0 );
104 if (xIA != null ) {
105 result = (xIA.getCount()>0);
106 } else {
107 result = true;
110 if (!result) log.println("The TextContent wasn't inserted");
113 // try to insert an invalid TextContent
114 log.println( "test for insertTextContent" );
115 try {
116 oObj.insertTextContent(oCursor, null, false);
117 log.println("The expected Exception doesn't occurred");
118 result &= false;
120 catch( com.sun.star.lang.IllegalArgumentException iaE ){
121 // Some exception.FAILED
122 log.println("Expected Exception occurred");
123 String msg = iaE.getMessage();
124 if (msg.equals("")) {
125 log.println("But there is not detailed message");
126 } else {
127 log.println("Detailed message: "+msg);
130 result &= true;
133 tRes.tested("insertTextContent()", result );
138 * Removes the text contet added before. <p>
139 * Has <b> OK </b> status if the method successfully returns
140 * and no exceptions were thrown. <p>
141 * The following method tests are to be completed successfully before :
142 * <ul>
143 * <li> <code> insertTextContent() </code> : inserts the content
144 * to be removed in this test. </li>
145 * </ul>
147 public void _removeTextContent() {
149 // leads to a method which should be called previously
150 requiredMethod( "insertTextContent()" );
152 // write to log what we try next
153 log.println( "test for removeTextContent" );
154 try {
155 oObj.removeTextContent( (XTextContent)oInt );
156 //oObj.removeTextContent( (XTextContent)oInt );
158 catch( com.sun.star.container.NoSuchElementException nseE ){
159 // Some exception.FAILED
160 Status.failed( nseE.toString() );
161 return;
164 // no exception occurred so it works
165 tRes.tested( "removeTextContent()", true );
168 } // finish class _XText