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.container; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.container.XSet; 33 import com.sun.star.lang.XMultiServiceFactory; 34 35 /** 36 * Testing <code>com.sun.star.container.XSet</code> 37 * interface methods : 38 * <ul> 39 * <li><code> has()</code></li> 40 * <li><code> insert()</code></li> 41 * <li><code> remove()</code></li> 42 * </ul> <p> 43 * Test is <b> NOT </b> multithread compilant. <p> 44 * @see com.sun.star.container.XSet 45 */ 46 public class _XSet extends MultiMethodTest { 47 48 public static XSet oObj = null; 49 50 private Object element = null ; 51 private boolean hasResult = true ; 52 53 /** 54 * Inserts the element stored and removed before. <p> 55 * Has <b> OK </b> status if <code>has()</code> method returns 56 * <code>true</code>. 57 * The following method tests are to be completed successfully before : 58 * <ul> 59 * <li> <code> remove() </code> : element from set is stored and 60 * removed </li> 61 * </ul> 62 */ 63 public void _insert() { 64 boolean res = true ; 65 try { 66 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 67 element = xMSF.createInstance( 68 "com.sun.star.reflection.TypeDescriptionProvider"); 69 70 71 oObj.insert(element) ; 72 73 if (!oObj.has(element)) { 74 res = false ; 75 log.println("After adding element method has()" + 76 " returned false") ; 77 hasResult = false ; 78 } 79 } catch (com.sun.star.container.ElementExistException e) { 80 e.printStackTrace(log) ; 81 res = false ; 82 } catch (com.sun.star.lang.IllegalArgumentException e) { 83 e.printStackTrace(log) ; 84 res = false ; 85 } 86 catch(com.sun.star.uno.Exception e) { 87 e.printStackTrace(log); 88 res = false; 89 } 90 91 tRes.tested("insert()", res) ; 92 } 93 94 /** 95 * Through <code>XEnumeration</code> interface an element from the set 96 * is retrieved. Then this element removed.<p> 97 * Has <b> OK </b> status if after removing <code>has()</code> method 98 * returns false. 99 */ 100 public void _remove() { 101 requiredMethod("insert()"); 102 boolean res = true ; 103 104 try { 105 106 // get an element to be removed/inserted 107 108 oObj.remove(element) ; 109 110 if (oObj.has(element)) { 111 res = false ; 112 log.println("After removing element method has()" + 113 " returned true") ; 114 hasResult = false ; 115 } 116 117 118 119 } catch (com.sun.star.container.NoSuchElementException e) { 120 e.printStackTrace(log) ; 121 res = false ; 122 } catch (com.sun.star.lang.IllegalArgumentException e) { 123 e.printStackTrace(log) ; 124 res = false ; 125 } 126 127 tRes.tested("remove()", res) ; 128 } 129 130 /** 131 * Does nothing. Testing performed in previous methods.<p> 132 * Has <b> OK </b> status if after <code>remove()</code> call 133 * methods returned <code>false</code>, and after <code>remove()</code> 134 * call methods returned <code>true</code>. 135 * The following method tests are to be completed successfully before : 136 * <ul> 137 * <li> <code> insert() </code> : here the method is checked </li> 138 * <li> <code> remove() </code> : here the method is checked </li> 139 * </ul> 140 */ 141 public void _has() { 142 143 requiredMethod("insert()") ; 144 requiredMethod("remove()") ; 145 146 tRes.tested("has()", hasResult) ; 147 } 148 149 } // finished class _XSet 150 151