merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / text / _XAutoTextContainer.java
blobb20d9afead1a8629e4c866ed1b4e1f96b728b733
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAutoTextContainer.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.text;
33 import lib.MultiMethodTest;
35 import com.sun.star.text.XAutoTextContainer;
36 import com.sun.star.text.XAutoTextGroup;
38 /**
39 * Testing <code>com.sun.star.text.XAutoTextContainer</code>
40 * interface methods :
41 * <ul>
42 * <li><code> insertNewByName()</code></li>
43 * <li><code> removeByName()</code></li>
44 * </ul> <p>
45 * Test is <b> NOT </b> multithread compilant. <p>
46 * @see com.sun.star.text.XAutoTextContainer
48 public class _XAutoTextContainer extends MultiMethodTest {
49 public XAutoTextContainer oObj = null;
50 // every Thread must insert it's own AutoTextContainer:
51 public String Name = "";
53 /**
54 * First removes old element from container with the specified name
55 * if it exists. Then tries to add a new group with the specified
56 * name. <p>
58 * Has <b>OK</b> status if not <code>null</code>
59 * <code>AutoTextGroup</code> instance is returned.
61 public void _insertNewByName() {
62 System.out.println("Starting: insertNewByName");
63 boolean result = true;
64 Name = "XAutoTextContainerx" + Thread.currentThread().getName();
65 Name = Name.replace('-','x');
66 Name = Name.replace(':','x');
67 Name = Name.replace('.','x');
68 XAutoTextGroup oGroup = null;
69 //first clear the container
70 log.println("remove old elements in container");
71 System.out.println("remove old elements in container");
72 try {
73 oObj.removeByName(Name);
74 log.println("old elements removed -> OK");
75 System.out.println("old elements removed -> OK");
76 } catch (com.sun.star.container.NoSuchElementException e) {
77 log.println("no old elements available -> OK");
78 System.out.println("no old elements available -> OK");
81 // insert an element
82 log.println("insertNewByName");
83 try {
84 System.out.println("Inserting element with name '" + Name + "'");
85 log.println("Inserting element with name '" + Name + "'");
86 oGroup = oObj.insertNewByName(Name);
87 System.out.println("done");
88 } catch (com.sun.star.container.ElementExistException e) {
89 log.println("insertNewByName(): " + e);
90 result &= false;
91 } catch (com.sun.star.lang.IllegalArgumentException e) {
92 log.println("insertNewByName(): " + e);
93 result &= false;
96 result &= ( oGroup != null );
97 tRes.tested("insertNewByName()", result);
98 } // end insertNewByName()
101 * First removes element by name which was added before,
102 * then tries to remove the element with the same name again. <p>
104 * Has <b> OK </b> status if in the first case no exceptions
105 * were thrown, and in the second case
106 * <code>NoSuchElementException</code> was thrown. <p>
108 * The following method tests are to be completed successfully before :
109 * <ul>
110 * <li> <code> insertNewByName() </code> : new element inserted here.</li>
111 * </ul>
113 public void _removeByName() {
114 requiredMethod("insertNewByName()");
116 boolean result = true;
117 // remove the element
118 log.println("removeByName()");
119 try {
120 log.println("Removing element with name '" + Name + "'");
121 oObj.removeByName(Name);
122 result &= true;
123 } catch (com.sun.star.container.NoSuchElementException e) {
124 result = false;
125 log.println("removeByName(): " + e + " -> FAILD");
128 log.println("2nd removeByName()");
129 try {
130 oObj.removeByName(Name);
131 log.println("No exceptions were thrown -> FAILED");
132 result = false ;
133 } catch (com.sun.star.container.NoSuchElementException e) {
134 log.println("2nd removeByName(): -> OK");
135 result &= true;
138 tRes.tested("removeByName()", result);
140 } // end removeByName()
142 } /// finish class XAutoTextContainer