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