bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XText.java
blob5163cb7ee9ce3843ee35e792327f8e1296e569e4
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.text;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import util.XInstCreator;
25 import com.sun.star.container.XIndexAccess;
26 import com.sun.star.text.XText;
27 import com.sun.star.text.XTextContent;
28 import com.sun.star.text.XTextCursor;
29 import com.sun.star.uno.XInterface;
30 import lib.StatusException;
32 /**
33 * Testing <code>com.sun.star.text.XText</code>
34 * interface methods :
35 * <ul>
36 * <li><code> insertTextContent()</code></li>
37 * <li><code> removeTextContent()</code></li>
38 * </ul> <p>
39 * This test needs the following object relations :
40 * <ul>
41 * <li> <code>'XTEXTINFO'</code> (of type <code>lib.XInstCreator</code>):
42 * creator which can create instances of <code>XTextContent</code>
43 * implementations. </li>
44 * <ul> <p>
45 * Test is <b> NOT </b> multithread compilant. <p>
46 * @see com.sun.star.text.XText
48 public class _XText extends MultiMethodTest {
50 public static XText oObj = null; // oObj filled by MultiMethodTest
51 XTextCursor oCursor = null; // textcursor
52 XInstCreator info = null; // instance creator
53 XInterface oInt = null; // instance to insert and remove
55 /**
56 * First an instance of text content is created using relation
57 * and inserted into text. Then the number of contents is checked
58 * using the relation. Second a <code>null</code> content is tried
59 * to insert. <p>
61 * Has <b> OK </b> status if in the first case after inserting number
62 * of content objects is greater than zero and in the second
63 * case <code>IllegalArgumentException</code> is thrown. <p>
65 public void _insertTextContent() {
66 boolean result = false;
67 info = (XInstCreator)tEnv.getObjRelation( "XTEXTINFO" );
68 oInt = info.createInstance();
70 // write to log what we try next
71 log.println( "test for createTextCursor()" );
72 oCursor = oObj.createTextCursor();
74 // write to log what we try next
75 log.println( "test for insertTextContent()" );
76 try {
77 oObj.insertTextContent(oCursor, (XTextContent)oInt, false);
79 catch( com.sun.star.lang.IllegalArgumentException iaE ){
80 throw new StatusException("Couldn't insert textcontent",iaE);
81 //Status.failed(iaE.toString());
82 //return;
85 // get indexaccess to the tablecollection
86 XIndexAccess xIA = info.getCollection();
88 // this comparision works just because it has to be at least one
89 // table at this point regardless which thread inserted it
90 // there is although the possibility that the first threads call
91 // failed, the second not and comparision happens after second threads
92 // otherwise if something fails it should have thrown an exception
93 //tRes.tested("insertTextContent()", xIA.getCount() > 0 );
95 if (xIA != null ) {
96 result = (xIA.getCount()>0);
97 } else {
98 result = true;
101 if (!result) log.println("The TextContent wasn't inserted");
104 // try to insert an invalid TextContent
105 log.println( "test for insertTextContent" );
106 try {
107 oObj.insertTextContent(oCursor, null, false);
108 log.println("The expected Exception doesn't occurred");
109 result &= false;
111 catch( com.sun.star.lang.IllegalArgumentException iaE ){
112 // Some exception.FAILED
113 log.println("Expected Exception occurred");
114 String msg = iaE.getMessage();
115 if (msg.equals("")) {
116 log.println("But there is not detailed message");
117 } else {
118 log.println("Detailed message: "+msg);
121 result &= true;
124 tRes.tested("insertTextContent()", result );
129 * Removes the text contet added before. <p>
130 * Has <b> OK </b> status if the method successfully returns
131 * and no exceptions were thrown. <p>
132 * The following method tests are to be completed successfully before :
133 * <ul>
134 * <li> <code> insertTextContent() </code> : inserts the content
135 * to be removed in this test. </li>
136 * </ul>
138 public void _removeTextContent() {
140 // leads to a method which should be called previously
141 requiredMethod( "insertTextContent()" );
143 // write to log what we try next
144 log.println( "test for removeTextContent" );
145 try {
146 oObj.removeTextContent( (XTextContent)oInt );
147 //oObj.removeTextContent( (XTextContent)oInt );
149 catch( com.sun.star.container.NoSuchElementException nseE ){
150 // Some exception.FAILED
151 Status.failed( nseE.toString() );
152 return;
155 // no exception occurred so it works
156 tRes.tested( "removeTextContent()", true );
159 } // finish class _XText