1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.text; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.text.XAutoTextContainer; 33 import com.sun.star.text.XAutoTextGroup; 34 35 /** 36 * Testing <code>com.sun.star.text.XAutoTextContainer</code> 37 * interface methods : 38 * <ul> 39 * <li><code> insertNewByName()</code></li> 40 * <li><code> removeByName()</code></li> 41 * </ul> <p> 42 * Test is <b> NOT </b> multithread compilant. <p> 43 * @see com.sun.star.text.XAutoTextContainer 44 */ 45 public class _XAutoTextContainer extends MultiMethodTest { 46 public XAutoTextContainer oObj = null; 47 // every Thread must insert it's own AutoTextContainer: 48 public String Name = ""; 49 50 /** 51 * First removes old element from container with the specified name 52 * if it exists. Then tries to add a new group with the specified 53 * name. <p> 54 * 55 * Has <b>OK</b> status if not <code>null</code> 56 * <code>AutoTextGroup</code> instance is returned. 57 */ 58 public void _insertNewByName() { 59 System.out.println("Starting: insertNewByName"); 60 boolean result = true; 61 Name = "XAutoTextContainerx" + Thread.currentThread().getName(); 62 Name = Name.replace('-','x'); 63 Name = Name.replace(':','x'); 64 Name = Name.replace('.','x'); 65 XAutoTextGroup oGroup = null; 66 //first clear the container 67 log.println("remove old elements in container"); 68 System.out.println("remove old elements in container"); 69 try { 70 oObj.removeByName(Name); 71 log.println("old elements removed -> OK"); 72 System.out.println("old elements removed -> OK"); 73 } catch (com.sun.star.container.NoSuchElementException e) { 74 log.println("no old elements available -> OK"); 75 System.out.println("no old elements available -> OK"); 76 } 77 78 // insert an element 79 log.println("insertNewByName"); 80 try { 81 System.out.println("Inserting element with name '" + Name + "'"); 82 log.println("Inserting element with name '" + Name + "'"); 83 oGroup = oObj.insertNewByName(Name); 84 System.out.println("done"); 85 } catch (com.sun.star.container.ElementExistException e) { 86 log.println("insertNewByName(): " + e); 87 result &= false; 88 } catch (com.sun.star.lang.IllegalArgumentException e) { 89 log.println("insertNewByName(): " + e); 90 result &= false; 91 } 92 93 result &= ( oGroup != null ); 94 tRes.tested("insertNewByName()", result); 95 } // end insertNewByName() 96 97 /** 98 * First removes element by name which was added before, 99 * then tries to remove the element with the same name again. <p> 100 * 101 * Has <b> OK </b> status if in the first case no exceptions 102 * were thrown, and in the second case 103 * <code>NoSuchElementException</code> was thrown. <p> 104 * 105 * The following method tests are to be completed successfully before : 106 * <ul> 107 * <li> <code> insertNewByName() </code> : new element inserted here.</li> 108 * </ul> 109 */ 110 public void _removeByName() { 111 requiredMethod("insertNewByName()"); 112 113 boolean result = true; 114 // remove the element 115 log.println("removeByName()"); 116 try { 117 log.println("Removing element with name '" + Name + "'"); 118 oObj.removeByName(Name); 119 result &= true; 120 } catch (com.sun.star.container.NoSuchElementException e) { 121 result = false; 122 log.println("removeByName(): " + e + " -> FAILD"); 123 } 124 125 log.println("2nd removeByName()"); 126 try { 127 oObj.removeByName(Name); 128 log.println("No exceptions were thrown -> FAILED"); 129 result = false ; 130 } catch (com.sun.star.container.NoSuchElementException e) { 131 log.println("2nd removeByName(): -> OK"); 132 result &= true; 133 } 134 135 tRes.tested("removeByName()", result); 136 137 } // end removeByName() 138 139 } /// finish class XAutoTextContainer 140 141 142