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 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.text
.XAutoTextContainer
;
24 import com
.sun
.star
.text
.XAutoTextGroup
;
27 * Testing <code>com.sun.star.text.XAutoTextContainer</code>
30 * <li><code> insertNewByName()</code></li>
31 * <li><code> removeByName()</code></li>
33 * Test is <b> NOT </b> multithread compliant. <p>
34 * @see com.sun.star.text.XAutoTextContainer
36 public class _XAutoTextContainer
extends MultiMethodTest
{
37 public XAutoTextContainer oObj
= null;
38 // every Thread must insert it's own AutoTextContainer:
39 public String Name
= "";
42 * First removes old element from container with the specified name
43 * if it exists. Then tries to add a new group with the specified
46 * Has <b>OK</b> status if not <code>null</code>
47 * <code>AutoTextGroup</code> instance is returned.
49 public void _insertNewByName() {
50 System
.out
.println("Starting: insertNewByName");
51 boolean result
= true;
52 Name
= "XAutoTextContainerx" + Thread
.currentThread().getName();
53 Name
= Name
.replace('-','x');
54 Name
= Name
.replace(':','x');
55 Name
= Name
.replace('.','x');
56 XAutoTextGroup oGroup
= null;
57 //first clear the container
58 log
.println("remove old elements in container");
59 System
.out
.println("remove old elements in container");
61 oObj
.removeByName(Name
);
62 log
.println("old elements removed -> OK");
63 System
.out
.println("old elements removed -> OK");
64 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
65 log
.println("no old elements available -> OK");
66 System
.out
.println("no old elements available -> OK");
70 log
.println("insertNewByName");
72 System
.out
.println("Inserting element with name '" + Name
+ "'");
73 log
.println("Inserting element with name '" + Name
+ "'");
74 oGroup
= oObj
.insertNewByName(Name
);
75 System
.out
.println("done");
76 } catch (com
.sun
.star
.container
.ElementExistException e
) {
77 log
.println("insertNewByName(): " + e
);
79 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
80 log
.println("insertNewByName(): " + e
);
84 result
&= ( oGroup
!= null );
85 tRes
.tested("insertNewByName()", result
);
86 } // end insertNewByName()
89 * First removes element by name which was added before,
90 * then tries to remove the element with the same name again. <p>
92 * Has <b> OK </b> status if in the first case no exceptions
93 * were thrown, and in the second case
94 * <code>NoSuchElementException</code> was thrown. <p>
96 * The following method tests are to be completed successfully before :
98 * <li> <code> insertNewByName() </code> : new element inserted here.</li>
101 public void _removeByName() {
102 requiredMethod("insertNewByName()");
104 boolean result
= true;
105 // remove the element
106 log
.println("removeByName()");
108 log
.println("Removing element with name '" + Name
+ "'");
109 oObj
.removeByName(Name
);
111 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
113 log
.println("removeByName(): " + e
+ " -> FAILD");
116 log
.println("2nd removeByName()");
118 oObj
.removeByName(Name
);
119 log
.println("No exceptions were thrown -> FAILED");
121 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
122 log
.println("2nd removeByName(): -> OK");
126 tRes
.tested("removeByName()", result
);
128 } // end removeByName()
130 } /// finish class XAutoTextContainer