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 import lib.Status; 32 import lib.StatusException; 33 34 import com.sun.star.beans.NamedValue; 35 import com.sun.star.container.XContainerQuery; 36 import com.sun.star.container.XEnumeration; 37 38 39 /** 40 * Testing <code>com.sun.star.container.XContainerQuery</code> 41 * interface methods : 42 * <ul> 43 * <li><code> createSubSetEnumerationByProperties()</code></li> 44 * <li><code> createSubSetEnumerationByQuery()</code></li> 45 * </ul> 46 * This test needs the following object relations : 47 * <ul> 48 * <li> <code>'XContainerQuery.createSubSetEnumerationByProperties'</code> : 49 * <code>NameValue[]</code> which is a valid argument for 50 * <code>createSubSetEnumerationByProperties()</code>.</li> 51 * <li> <code>'XContainerQuery.createSubSetEnumerationByQuery'</code> : <b>(optional)</b> 52 * Normaly <code>createSubSetEnumerationByProperties()</code> covers all 53 * possible queries. But for special cases, i.e. sorted output, the function 54 * <code>createSubSetEnumerationByQuery()</code> was made. The special cases was not 55 * implemented by default in the implemetation object. So this function could be 56 * marked as <code>optional</code></li> 57 * <ul> <p> 58 * <p> 59 * Test is <b> NOT </b> multithread compilant. <p> 60 * @see com.sun.star.container.XContainerQuery 61 */ 62 public class _XContainerQuery extends MultiMethodTest { 63 64 public XContainerQuery oObj = null; 65 private NamedValue[] m_querySequenze = null; 66 private String[] m_queryStrings = null; 67 68 69 /** 70 * Retrieves object relations 71 * @throws StatusException If one of relations not found. 72 */ 73 public void before() throws StatusException { 74 75 m_querySequenze = (NamedValue[]) tEnv.getObjRelation( 76 "XContainerQuery.createSubSetEnumerationByProperties"); 77 if (m_querySequenze == null) { 78 throw new StatusException( 79 Status.failed("Could not get object relation " + 80 "'XContainerQuery.createSubSetEnumerationByProperties'")) ; 81 } 82 83 m_queryStrings = (String[]) tEnv.getObjRelation( 84 "XContainerQuery.createSubSetEnumerationByQuery"); 85 if (m_queryStrings == null) { 86 log.println("Could not get object relation " + 87 "'XContainerQuery.createSubSetEnumerationByQuery'"); 88 } 89 } 90 91 92 /** 93 * If object relation is available, the function was called with relation 94 * as parameter. The returned <code>XEnumeration</code> must not be null and 95 * elements of it must be valid. 96 * If object relation is not available, the result is always <code>true</coed> 97 */ 98 public void _createSubSetEnumerationByQuery() { 99 100 boolean bResult = true; 101 if ( m_queryStrings == null ) { 102 log.println("This object does not have an implemetation for this function"); 103 // This is not a bug, because it's a feature for future purposes 104 } else { 105 for (int i = 0; i < m_queryStrings.length; i++){ 106 String queryString = m_queryStrings[i]; 107 XEnumeration subSet = oObj.createSubSetEnumerationByQuery( queryString ); 108 109 bResult &= subSet.hasMoreElements(); 110 111 while (subSet.hasMoreElements()) { 112 try{ 113 Object element = subSet.nextElement(); 114 115 } catch (com.sun.star.container.NoSuchElementException e){ 116 log.println("Exception occured "); 117 e.printStackTrace(log); 118 bResult = false; 119 } catch (com.sun.star.lang.WrappedTargetException e){ 120 log.println("Exception occured "); 121 e.printStackTrace(log); 122 bResult = false; 123 } 124 } 125 } 126 } 127 128 tRes.tested("createSubSetEnumerationByQuery()", bResult); 129 } 130 131 /** 132 * The function was called with object relation 133 * as parameter. The returned <code>XEnumeration</code> must not be null and 134 * elements of it must be valid. 135 * 136 */ 137 public void _createSubSetEnumerationByProperties() { 138 139 boolean bResult = true; 140 141 XEnumeration subSet = oObj.createSubSetEnumerationByProperties( m_querySequenze ); 142 143 bResult = subSet.hasMoreElements(); 144 145 while (subSet.hasMoreElements()) { 146 try{ 147 Object element = subSet.nextElement(); 148 149 } catch (com.sun.star.container.NoSuchElementException e){ 150 log.println("Exception occured "); 151 e.printStackTrace(log); 152 bResult = false; 153 } catch (com.sun.star.lang.WrappedTargetException e){ 154 log.println("Exception occured "); 155 e.printStackTrace(log); 156 bResult = false; 157 } 158 } 159 160 tRes.tested("createSubSetEnumerationByProperties()", bResult); 161 } 162 } 163