Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XAutoTextContainer.java
blob59134280eeae2e28380c3d600ae4aeab63587e62
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;
23 import com.sun.star.text.XAutoTextContainer;
24 import com.sun.star.text.XAutoTextGroup;
26 /**
27 * Testing <code>com.sun.star.text.XAutoTextContainer</code>
28 * interface methods :
29 * <ul>
30 * <li><code> insertNewByName()</code></li>
31 * <li><code> removeByName()</code></li>
32 * </ul> <p>
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 = "";
41 /**
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
44 * name. <p>
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");
60 try {
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");
69 // insert an element
70 log.println("insertNewByName");
71 try {
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);
78 result &= false;
79 } catch (com.sun.star.lang.IllegalArgumentException e) {
80 log.println("insertNewByName(): " + e);
81 result &= false;
84 result &= ( oGroup != null );
85 tRes.tested("insertNewByName()", result);
86 } // end insertNewByName()
88 /**
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 :
97 * <ul>
98 * <li> <code> insertNewByName() </code> : new element inserted here.</li>
99 * </ul>
101 public void _removeByName() {
102 requiredMethod("insertNewByName()");
104 boolean result = true;
105 // remove the element
106 log.println("removeByName()");
107 try {
108 log.println("Removing element with name '" + Name + "'");
109 oObj.removeByName(Name);
110 result &= true;
111 } catch (com.sun.star.container.NoSuchElementException e) {
112 result = false;
113 log.println("removeByName(): " + e + " -> FAILD");
116 log.println("2nd removeByName()");
117 try {
118 oObj.removeByName(Name);
119 log.println("No exceptions were thrown -> FAILED");
120 result = false ;
121 } catch (com.sun.star.container.NoSuchElementException e) {
122 log.println("2nd removeByName(): -> OK");
123 result &= true;
126 tRes.tested("removeByName()", result);
128 } // end removeByName()
130 } /// finish class XAutoTextContainer