1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.container; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir import lib.Status; 32*cdf0e10cSrcweir import lib.StatusException; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 35*cdf0e10cSrcweir import com.sun.star.container.XContainerQuery; 36*cdf0e10cSrcweir import com.sun.star.container.XEnumeration; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /** 40*cdf0e10cSrcweir * Testing <code>com.sun.star.container.XContainerQuery</code> 41*cdf0e10cSrcweir * interface methods : 42*cdf0e10cSrcweir * <ul> 43*cdf0e10cSrcweir * <li><code> createSubSetEnumerationByProperties()</code></li> 44*cdf0e10cSrcweir * <li><code> createSubSetEnumerationByQuery()</code></li> 45*cdf0e10cSrcweir * </ul> 46*cdf0e10cSrcweir * This test needs the following object relations : 47*cdf0e10cSrcweir * <ul> 48*cdf0e10cSrcweir * <li> <code>'XContainerQuery.createSubSetEnumerationByProperties'</code> : 49*cdf0e10cSrcweir * <code>NameValue[]</code> which is a valid argument for 50*cdf0e10cSrcweir * <code>createSubSetEnumerationByProperties()</code>.</li> 51*cdf0e10cSrcweir * <li> <code>'XContainerQuery.createSubSetEnumerationByQuery'</code> : <b>(optional)</b> 52*cdf0e10cSrcweir * Normaly <code>createSubSetEnumerationByProperties()</code> covers all 53*cdf0e10cSrcweir * possible queries. But for special cases, i.e. sorted output, the function 54*cdf0e10cSrcweir * <code>createSubSetEnumerationByQuery()</code> was made. The special cases was not 55*cdf0e10cSrcweir * implemented by default in the implemetation object. So this function could be 56*cdf0e10cSrcweir * marked as <code>optional</code></li> 57*cdf0e10cSrcweir * <ul> <p> 58*cdf0e10cSrcweir * <p> 59*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 60*cdf0e10cSrcweir * @see com.sun.star.container.XContainerQuery 61*cdf0e10cSrcweir */ 62*cdf0e10cSrcweir public class _XContainerQuery extends MultiMethodTest { 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir public XContainerQuery oObj = null; 65*cdf0e10cSrcweir private NamedValue[] m_querySequenze = null; 66*cdf0e10cSrcweir private String[] m_queryStrings = null; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir /** 70*cdf0e10cSrcweir * Retrieves object relations 71*cdf0e10cSrcweir * @throws StatusException If one of relations not found. 72*cdf0e10cSrcweir */ 73*cdf0e10cSrcweir public void before() throws StatusException { 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir m_querySequenze = (NamedValue[]) tEnv.getObjRelation( 76*cdf0e10cSrcweir "XContainerQuery.createSubSetEnumerationByProperties"); 77*cdf0e10cSrcweir if (m_querySequenze == null) { 78*cdf0e10cSrcweir throw new StatusException( 79*cdf0e10cSrcweir Status.failed("Could not get object relation " + 80*cdf0e10cSrcweir "'XContainerQuery.createSubSetEnumerationByProperties'")) ; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir m_queryStrings = (String[]) tEnv.getObjRelation( 84*cdf0e10cSrcweir "XContainerQuery.createSubSetEnumerationByQuery"); 85*cdf0e10cSrcweir if (m_queryStrings == null) { 86*cdf0e10cSrcweir log.println("Could not get object relation " + 87*cdf0e10cSrcweir "'XContainerQuery.createSubSetEnumerationByQuery'"); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir /** 93*cdf0e10cSrcweir * If object relation is available, the function was called with relation 94*cdf0e10cSrcweir * as parameter. The returned <code>XEnumeration</code> must not be null and 95*cdf0e10cSrcweir * elements of it must be valid. 96*cdf0e10cSrcweir * If object relation is not available, the result is always <code>true</coed> 97*cdf0e10cSrcweir */ 98*cdf0e10cSrcweir public void _createSubSetEnumerationByQuery() { 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir boolean bResult = true; 101*cdf0e10cSrcweir if ( m_queryStrings == null ) { 102*cdf0e10cSrcweir log.println("This object does not have an implemetation for this function"); 103*cdf0e10cSrcweir // This is not a bug, because it's a feature for future purposes 104*cdf0e10cSrcweir } else { 105*cdf0e10cSrcweir for (int i = 0; i < m_queryStrings.length; i++){ 106*cdf0e10cSrcweir String queryString = m_queryStrings[i]; 107*cdf0e10cSrcweir XEnumeration subSet = oObj.createSubSetEnumerationByQuery( queryString ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir bResult &= subSet.hasMoreElements(); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir while (subSet.hasMoreElements()) { 112*cdf0e10cSrcweir try{ 113*cdf0e10cSrcweir Object element = subSet.nextElement(); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e){ 116*cdf0e10cSrcweir log.println("Exception occured "); 117*cdf0e10cSrcweir e.printStackTrace(log); 118*cdf0e10cSrcweir bResult = false; 119*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 120*cdf0e10cSrcweir log.println("Exception occured "); 121*cdf0e10cSrcweir e.printStackTrace(log); 122*cdf0e10cSrcweir bResult = false; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir tRes.tested("createSubSetEnumerationByQuery()", bResult); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir /** 132*cdf0e10cSrcweir * The function was called with object relation 133*cdf0e10cSrcweir * as parameter. The returned <code>XEnumeration</code> must not be null and 134*cdf0e10cSrcweir * elements of it must be valid. 135*cdf0e10cSrcweir * 136*cdf0e10cSrcweir */ 137*cdf0e10cSrcweir public void _createSubSetEnumerationByProperties() { 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir boolean bResult = true; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir XEnumeration subSet = oObj.createSubSetEnumerationByProperties( m_querySequenze ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir bResult = subSet.hasMoreElements(); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir while (subSet.hasMoreElements()) { 146*cdf0e10cSrcweir try{ 147*cdf0e10cSrcweir Object element = subSet.nextElement(); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e){ 150*cdf0e10cSrcweir log.println("Exception occured "); 151*cdf0e10cSrcweir e.printStackTrace(log); 152*cdf0e10cSrcweir bResult = false; 153*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 154*cdf0e10cSrcweir log.println("Exception occured "); 155*cdf0e10cSrcweir e.printStackTrace(log); 156*cdf0e10cSrcweir bResult = false; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir tRes.tested("createSubSetEnumerationByProperties()", bResult); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163