bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XText.java
blobb34374ac11676f2331da977baf61a2ed3718d8c2
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 compliant. <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);
83 // get indexaccess to the tablecollection
84 XIndexAccess xIA = info.getCollection();
86 // this comparison works just because it has to be at least one
87 // table at this point regardless which thread inserted it
88 // there is although the possibility that the first threads call
89 // failed, the second not and comparison happens after second threads
90 // otherwise if something fails it should have thrown an exception
91 //tRes.tested("insertTextContent()", xIA.getCount() > 0 );
93 if (xIA != null ) {
94 result = (xIA.getCount()>0);
95 } else {
96 result = true;
99 if (!result) log.println("The TextContent wasn't inserted");
102 // try to insert an invalid TextContent
103 log.println( "test for insertTextContent" );
104 try {
105 oObj.insertTextContent(oCursor, null, false);
106 log.println("The expected Exception doesn't occurred");
107 result &= false;
109 catch( com.sun.star.lang.IllegalArgumentException iaE ){
110 // Some exception.FAILED
111 log.println("Expected Exception occurred");
112 String msg = iaE.getMessage();
113 if (msg.equals("")) {
114 log.println("But there is not detailed message");
115 } else {
116 log.println("Detailed message: "+msg);
119 result &= true;
122 tRes.tested("insertTextContent()", result );
127 * Removes the text contet added before. <p>
128 * Has <b> OK </b> status if the method successfully returns
129 * and no exceptions were thrown. <p>
130 * The following method tests are to be completed successfully before :
131 * <ul>
132 * <li> <code> insertTextContent() </code> : inserts the content
133 * to be removed in this test. </li>
134 * </ul>
136 public void _removeTextContent() {
138 // leads to a method which should be called previously
139 requiredMethod( "insertTextContent()" );
141 // write to log what we try next
142 log.println( "test for removeTextContent" );
143 try {
144 oObj.removeTextContent( (XTextContent)oInt );
146 catch( com.sun.star.container.NoSuchElementException nseE ){
147 // Some exception.FAILED
148 Status.failed( nseE.toString() );
149 return;
152 // no exception occurred so it works
153 tRes.tested( "removeTextContent()", true );
156 } // finish class _XText