2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc
.container
;
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.beans
.NamedValue
;
26 import com
.sun
.star
.container
.XContainerQuery
;
27 import com
.sun
.star
.container
.XEnumeration
;
31 * Testing <code>com.sun.star.container.XContainerQuery</code>
34 * <li><code> createSubSetEnumerationByProperties()</code></li>
35 * <li><code> createSubSetEnumerationByQuery()</code></li>
37 * This test needs the following object relations :
39 * <li> <code>'XContainerQuery.createSubSetEnumerationByProperties'</code> :
40 * <code>NameValue[]</code> which is a valid argument for
41 * <code>createSubSetEnumerationByProperties()</code>.</li>
42 * <li> <code>'XContainerQuery.createSubSetEnumerationByQuery'</code> : <b>(optional)</b>
43 * Normaly <code>createSubSetEnumerationByProperties()</code> covers all
44 * possible queries. But for special cases, i.e. sorted output, the function
45 * <code>createSubSetEnumerationByQuery()</code> was made. The special cases was not
46 * implemented by default in the implemetation object. So this function could be
47 * marked as <code>optional</code></li>
50 * Test is <b> NOT </b> multithread compilant. <p>
51 * @see com.sun.star.container.XContainerQuery
53 public class _XContainerQuery
extends MultiMethodTest
{
55 public XContainerQuery oObj
= null;
56 private NamedValue
[] m_querySequenze
= null;
57 private String
[] m_queryStrings
= null;
61 * Retrieves object relations
62 * @throws StatusException If one of relations not found.
64 public void before() throws StatusException
{
66 m_querySequenze
= (NamedValue
[]) tEnv
.getObjRelation(
67 "XContainerQuery.createSubSetEnumerationByProperties");
68 if (m_querySequenze
== null) {
69 throw new StatusException(
70 Status
.failed("Could not get object relation " +
71 "'XContainerQuery.createSubSetEnumerationByProperties'")) ;
74 m_queryStrings
= (String
[]) tEnv
.getObjRelation(
75 "XContainerQuery.createSubSetEnumerationByQuery");
76 if (m_queryStrings
== null) {
77 log
.println("Could not get object relation " +
78 "'XContainerQuery.createSubSetEnumerationByQuery'");
84 * If object relation is available, the function was called with relation
85 * as parameter. The returned <code>XEnumeration</code> must not be null and
86 * elements of it must be valid.
87 * If object relation is not available, the result is always <code>true</coed>
89 public void _createSubSetEnumerationByQuery() {
91 boolean bResult
= true;
92 if ( m_queryStrings
== null ) {
93 log
.println("This object does not have an implemetation for this function");
94 // This is not a bug, because it's a feature for future purposes
96 for (int i
= 0; i
< m_queryStrings
.length
; i
++){
97 String queryString
= m_queryStrings
[i
];
98 XEnumeration subSet
= oObj
.createSubSetEnumerationByQuery( queryString
);
100 bResult
&= subSet
.hasMoreElements();
102 while (subSet
.hasMoreElements()) {
104 subSet
.nextElement();
106 } catch (com
.sun
.star
.container
.NoSuchElementException e
){
107 log
.println("Exception occurred ");
108 e
.printStackTrace(log
);
110 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
111 log
.println("Exception occurred ");
112 e
.printStackTrace(log
);
119 tRes
.tested("createSubSetEnumerationByQuery()", bResult
);
123 * The function was called with object relation
124 * as parameter. The returned <code>XEnumeration</code> must not be null and
125 * elements of it must be valid.
128 public void _createSubSetEnumerationByProperties() {
130 boolean bResult
= true;
132 XEnumeration subSet
= oObj
.createSubSetEnumerationByProperties( m_querySequenze
);
134 bResult
= subSet
.hasMoreElements();
136 while (subSet
.hasMoreElements()) {
138 subSet
.nextElement();
140 } catch (com
.sun
.star
.container
.NoSuchElementException e
){
141 log
.println("Exception occurred ");
142 e
.printStackTrace(log
);
144 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
145 log
.println("Exception occurred ");
146 e
.printStackTrace(log
);
151 tRes
.tested("createSubSetEnumerationByProperties()", bResult
);