1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XContainerQuery.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc
.container
;
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.beans
.NamedValue
;
38 import com
.sun
.star
.container
.XContainerQuery
;
39 import com
.sun
.star
.container
.XEnumeration
;
43 * Testing <code>com.sun.star.container.XContainerQuery</code>
46 * <li><code> createSubSetEnumerationByProperties()</code></li>
47 * <li><code> createSubSetEnumerationByQuery()</code></li>
49 * This test needs the following object relations :
51 * <li> <code>'XContainerQuery.createSubSetEnumerationByProperties'</code> :
52 * <code>NameValue[]</code> which is a valid argument for
53 * <code>createSubSetEnumerationByProperties()</code>.</li>
54 * <li> <code>'XContainerQuery.createSubSetEnumerationByQuery'</code> : <b>(optional)</b>
55 * Normaly <code>createSubSetEnumerationByProperties()</code> covers all
56 * possible queries. But for special cases, i.e. sorted output, the function
57 * <code>createSubSetEnumerationByQuery()</code> was made. The special cases was not
58 * implemented by default in the implemetation object. So this function could be
59 * marked as <code>optional</code></li>
62 * Test is <b> NOT </b> multithread compilant. <p>
63 * @see com.sun.star.container.XContainerQuery
65 public class _XContainerQuery
extends MultiMethodTest
{
67 public XContainerQuery oObj
= null;
68 private NamedValue
[] m_querySequenze
= null;
69 private String
[] m_queryStrings
= null;
73 * Retrieves object relations
74 * @throws StatusException If one of relations not found.
76 public void before() throws StatusException
{
78 m_querySequenze
= (NamedValue
[]) tEnv
.getObjRelation(
79 "XContainerQuery.createSubSetEnumerationByProperties");
80 if (m_querySequenze
== null) {
81 throw new StatusException(
82 Status
.failed("Could not get object relation " +
83 "'XContainerQuery.createSubSetEnumerationByProperties'")) ;
86 m_queryStrings
= (String
[]) tEnv
.getObjRelation(
87 "XContainerQuery.createSubSetEnumerationByQuery");
88 if (m_queryStrings
== null) {
89 log
.println("Could not get object relation " +
90 "'XContainerQuery.createSubSetEnumerationByQuery'");
96 * If object relation is available, the function was called with relation
97 * as parameter. The returned <code>XEnumeration</code> must not be null and
98 * elements of it must be valid.
99 * If object relation is not available, the result is always <code>true</coed>
101 public void _createSubSetEnumerationByQuery() {
103 boolean bResult
= true;
104 if ( m_queryStrings
== null ) {
105 log
.println("This object does not have an implemetation for this function");
106 // This is not a bug, because it's a feature for future purposes
108 for (int i
= 0; i
< m_queryStrings
.length
; i
++){
109 String queryString
= m_queryStrings
[i
];
110 XEnumeration subSet
= oObj
.createSubSetEnumerationByQuery( queryString
);
112 bResult
&= subSet
.hasMoreElements();
114 while (subSet
.hasMoreElements()) {
116 Object element
= subSet
.nextElement();
118 } catch (com
.sun
.star
.container
.NoSuchElementException e
){
119 log
.println("Exception occured ");
120 e
.printStackTrace(log
);
122 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
123 log
.println("Exception occured ");
124 e
.printStackTrace(log
);
131 tRes
.tested("createSubSetEnumerationByQuery()", bResult
);
135 * The function was called with object relation
136 * as parameter. The returned <code>XEnumeration</code> must not be null and
137 * elements of it must be valid.
140 public void _createSubSetEnumerationByProperties() {
142 boolean bResult
= true;
144 XEnumeration subSet
= oObj
.createSubSetEnumerationByProperties( m_querySequenze
);
146 bResult
= subSet
.hasMoreElements();
148 while (subSet
.hasMoreElements()) {
150 Object element
= subSet
.nextElement();
152 } catch (com
.sun
.star
.container
.NoSuchElementException e
){
153 log
.println("Exception occured ");
154 e
.printStackTrace(log
);
156 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
157 log
.println("Exception occured ");
158 e
.printStackTrace(log
);
163 tRes
.tested("createSubSetEnumerationByProperties()", bResult
);