1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.container;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.beans.NamedValue;
31cdf0e10cSrcweir import com.sun.star.container.XContainerQuery;
32cdf0e10cSrcweir import com.sun.star.container.XEnumeration;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * Testing <code>com.sun.star.container.XContainerQuery</code>
37cdf0e10cSrcweir * interface methods :
38cdf0e10cSrcweir * <ul>
39cdf0e10cSrcweir *  <li><code> createSubSetEnumerationByProperties()</code></li>
40cdf0e10cSrcweir *  <li><code> createSubSetEnumerationByQuery()</code></li>
41cdf0e10cSrcweir * </ul>
42cdf0e10cSrcweir * This test needs the following object relations :
43cdf0e10cSrcweir * <ul>
44cdf0e10cSrcweir *  <li> <code>'XContainerQuery.createSubSetEnumerationByProperties'</code> :
45cdf0e10cSrcweir *    <code>NameValue[]</code> which is a valid argument for
46cdf0e10cSrcweir *     <code>createSubSetEnumerationByProperties()</code>.</li>
47cdf0e10cSrcweir *  <li> <code>'XContainerQuery.createSubSetEnumerationByQuery'</code> : <b>(optional)</b>
48cdf0e10cSrcweir *     Normaly <code>createSubSetEnumerationByProperties()</code> covers all
49cdf0e10cSrcweir *    possible queries. But for special cases, i.e. sorted output, the function
50cdf0e10cSrcweir *    <code>createSubSetEnumerationByQuery()</code> was made. The special cases was not
51cdf0e10cSrcweir *    implemented by default in the implemetation object. So this function could be
52cdf0e10cSrcweir *    marked as <code>optional</code></li>
53cdf0e10cSrcweir * <ul> <p>
54cdf0e10cSrcweir * <p>
55cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
56cdf0e10cSrcweir * @see com.sun.star.container.XContainerQuery
57cdf0e10cSrcweir */
58cdf0e10cSrcweir public class _XContainerQuery extends MultiMethodTest {
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     public XContainerQuery oObj = null;
61cdf0e10cSrcweir     private NamedValue[] m_querySequenze = null;
62cdf0e10cSrcweir     private String[] m_queryStrings = null;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /**
66cdf0e10cSrcweir     * Retrieves object relations
67cdf0e10cSrcweir     * @throws StatusException If one of relations not found.
68cdf0e10cSrcweir     */
69cdf0e10cSrcweir     public void before() throws StatusException {
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         m_querySequenze = (NamedValue[]) tEnv.getObjRelation(
72cdf0e10cSrcweir                         "XContainerQuery.createSubSetEnumerationByProperties");
73cdf0e10cSrcweir         if (m_querySequenze == null) {
74cdf0e10cSrcweir             throw new StatusException(
75cdf0e10cSrcweir                 Status.failed("Could not get object relation " +
76cdf0e10cSrcweir                 "'XContainerQuery.createSubSetEnumerationByProperties'")) ;
77cdf0e10cSrcweir         }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         m_queryStrings = (String[]) tEnv.getObjRelation(
80cdf0e10cSrcweir                         "XContainerQuery.createSubSetEnumerationByQuery");
81cdf0e10cSrcweir         if (m_queryStrings == null) {
82cdf0e10cSrcweir             log.println("Could not get object relation " +
83cdf0e10cSrcweir                         "'XContainerQuery.createSubSetEnumerationByQuery'");
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     /**
89cdf0e10cSrcweir      * If object relation is available, the function was called with relation
90cdf0e10cSrcweir      * as parameter. The returned <code>XEnumeration</code> must not be null and
91cdf0e10cSrcweir      * elements of it must be valid.
92cdf0e10cSrcweir      * If object relation is not available, the result is always <code>true</coed>
93cdf0e10cSrcweir     */
94cdf0e10cSrcweir     public void _createSubSetEnumerationByQuery() {
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         boolean bResult = true;
97cdf0e10cSrcweir         if ( m_queryStrings == null ) {
98cdf0e10cSrcweir             log.println("This object does not have an implemetation for this function");
99cdf0e10cSrcweir             // This is not a bug, because it's a feature for future purposes
100cdf0e10cSrcweir         } else {
101cdf0e10cSrcweir             for (int i = 0; i < m_queryStrings.length; i++){
102cdf0e10cSrcweir                 String queryString = m_queryStrings[i];
103cdf0e10cSrcweir                 XEnumeration subSet = oObj.createSubSetEnumerationByQuery( queryString );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir                 bResult &= subSet.hasMoreElements();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir                 while (subSet.hasMoreElements()) {
108cdf0e10cSrcweir                     try{
109cdf0e10cSrcweir                     Object element = subSet.nextElement();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir                     } catch (com.sun.star.container.NoSuchElementException e){
112cdf0e10cSrcweir                         log.println("Exception occured ");
113cdf0e10cSrcweir                         e.printStackTrace(log);
114cdf0e10cSrcweir                         bResult = false;
115cdf0e10cSrcweir                     } catch (com.sun.star.lang.WrappedTargetException e){
116cdf0e10cSrcweir                         log.println("Exception occured ");
117cdf0e10cSrcweir                         e.printStackTrace(log);
118cdf0e10cSrcweir                         bResult = false;
119cdf0e10cSrcweir                     }
120cdf0e10cSrcweir                 }
121cdf0e10cSrcweir             }
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         tRes.tested("createSubSetEnumerationByQuery()", bResult);
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     /**
128cdf0e10cSrcweir      * The function was called with object relation
129cdf0e10cSrcweir      * as parameter. The returned <code>XEnumeration</code> must not be null and
130cdf0e10cSrcweir      * elements of it must be valid.
131cdf0e10cSrcweir      *
132cdf0e10cSrcweir      */
133cdf0e10cSrcweir     public void _createSubSetEnumerationByProperties() {
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         boolean bResult = true;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         XEnumeration subSet = oObj.createSubSetEnumerationByProperties( m_querySequenze );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         bResult = subSet.hasMoreElements();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         while (subSet.hasMoreElements()) {
142cdf0e10cSrcweir             try{
143cdf0e10cSrcweir             Object element = subSet.nextElement();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             } catch (com.sun.star.container.NoSuchElementException e){
146cdf0e10cSrcweir                 log.println("Exception occured ");
147cdf0e10cSrcweir                 e.printStackTrace(log);
148cdf0e10cSrcweir                 bResult = false;
149cdf0e10cSrcweir             } catch (com.sun.star.lang.WrappedTargetException e){
150cdf0e10cSrcweir                 log.println("Exception occured ");
151cdf0e10cSrcweir                 e.printStackTrace(log);
152cdf0e10cSrcweir                 bResult = false;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         tRes.tested("createSubSetEnumerationByProperties()", bResult);
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir }
159