1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.text;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.text.XAutoTextContainer;
29 import com.sun.star.text.XAutoTextGroup;
30 
31 /**
32  * Testing <code>com.sun.star.text.XAutoTextContainer</code>
33  * interface methods :
34  * <ul>
35  *  <li><code> insertNewByName()</code></li>
36  *  <li><code> removeByName()</code></li>
37  * </ul> <p>
38  * Test is <b> NOT </b> multithread compilant. <p>
39  * @see com.sun.star.text.XAutoTextContainer
40  */
41 public class _XAutoTextContainer  extends MultiMethodTest {
42     public XAutoTextContainer oObj = null;
43     // every Thread must insert it's own AutoTextContainer:
44     public String Name = "";
45 
46     /**
47      * First removes old element from container with the specified name
48      * if it exists. Then tries to add a new group with the specified
49      * name. <p>
50      *
51      * Has <b>OK</b> status if not <code>null</code>
52      * <code>AutoTextGroup</code> instance is returned.
53      */
_insertNewByName()54     public void _insertNewByName() {
55         System.out.println("Starting: insertNewByName");
56         boolean result = true;
57         Name = "XAutoTextContainerx" + Thread.currentThread().getName();
58         Name = Name.replace('-','x');
59         Name = Name.replace(':','x');
60         Name = Name.replace('.','x');
61         XAutoTextGroup oGroup = null;
62         //first clear the container
63         log.println("remove old elements in container");
64         System.out.println("remove old elements in container");
65         try {
66             oObj.removeByName(Name);
67             log.println("old elements removed -> OK");
68             System.out.println("old elements removed -> OK");
69         } catch (com.sun.star.container.NoSuchElementException e) {
70             log.println("no old elements available -> OK");
71             System.out.println("no old elements available -> OK");
72         }
73 
74         // insert an element
75         log.println("insertNewByName");
76         try {
77             System.out.println("Inserting element with name '" + Name + "'");
78             log.println("Inserting element with name '" + Name + "'");
79             oGroup = oObj.insertNewByName(Name);
80             System.out.println("done");
81         } catch (com.sun.star.container.ElementExistException e) {
82             log.println("insertNewByName(): " + e);
83             result &= false;
84         } catch (com.sun.star.lang.IllegalArgumentException e) {
85             log.println("insertNewByName(): " + e);
86             result &= false;
87         }
88 
89         result &= ( oGroup != null );
90         tRes.tested("insertNewByName()", result);
91     } // end insertNewByName()
92 
93     /**
94      * First removes element by name which was added before,
95      * then tries to remove the element with the same name again. <p>
96      *
97      * Has <b> OK </b> status if in the first case no exceptions
98      * were thrown, and in the second case
99      * <code>NoSuchElementException</code> was thrown. <p>
100      *
101      * The following method tests are to be completed successfully before :
102      * <ul>
103      *  <li> <code> insertNewByName() </code> : new element inserted here.</li>
104      * </ul>
105      */
_removeByName()106     public void _removeByName() {
107         requiredMethod("insertNewByName()");
108 
109         boolean result = true;
110         // remove the element
111         log.println("removeByName()");
112         try {
113             log.println("Removing element with name '" + Name + "'");
114             oObj.removeByName(Name);
115             result &= true;
116         } catch (com.sun.star.container.NoSuchElementException e) {
117             result = false;
118             log.println("removeByName(): " + e + " -> FAILD");
119         }
120 
121         log.println("2nd removeByName()");
122         try {
123             oObj.removeByName(Name);
124             log.println("No exceptions were thrown -> FAILED");
125             result = false ;
126         } catch (com.sun.star.container.NoSuchElementException e) {
127             log.println("2nd removeByName(): -> OK");
128             result &= true;
129         }
130 
131         tRes.tested("removeByName()", result);
132 
133     } // end removeByName()
134 
135 }    /// finish class XAutoTextContainer
136 
137 
138