Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XContainerQuery.java
blob68cacca00a454090ff948593aabd02e4be80120b
1 /*
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;
22 import lib.Status;
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;
30 /**
31 * Testing <code>com.sun.star.container.XContainerQuery</code>
32 * interface methods :
33 * <ul>
34 * <li><code> createSubSetEnumerationByProperties()</code></li>
35 * <li><code> createSubSetEnumerationByQuery()</code></li>
36 * </ul>
37 * This test needs the following object relations :
38 * <ul>
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 * Normally <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 implementation object. So this function could be
47 * marked as <code>optional</code></li>
48 * <ul> <p>
49 * <p>
50 * Test is <b> NOT </b> multithread compliant. <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;
60 /**
61 * Retrieves object relations
62 * @throws StatusException If one of relations not found.
64 @Override
65 public void before() throws StatusException {
67 m_querySequenze = (NamedValue[]) tEnv.getObjRelation(
68 "XContainerQuery.createSubSetEnumerationByProperties");
69 if (m_querySequenze == null) {
70 throw new StatusException(
71 Status.failed("Could not get object relation " +
72 "'XContainerQuery.createSubSetEnumerationByProperties'")) ;
75 m_queryStrings = (String[]) tEnv.getObjRelation(
76 "XContainerQuery.createSubSetEnumerationByQuery");
77 if (m_queryStrings == null) {
78 log.println("Could not get object relation " +
79 "'XContainerQuery.createSubSetEnumerationByQuery'");
84 /**
85 * If object relation is available, the function was called with relation
86 * as parameter. The returned <code>XEnumeration</code> must not be null and
87 * elements of it must be valid.
88 * If object relation is not available, the result is always <code>true</code>
90 public void _createSubSetEnumerationByQuery() {
92 boolean bResult = true;
93 if ( m_queryStrings == null ) {
94 log.println("This object does not have an implementation for this function");
95 // This is not a bug, because it's a feature for future purposes
96 } else {
97 for (int i = 0; i < m_queryStrings.length; i++){
98 String queryString = m_queryStrings[i];
99 XEnumeration subSet = oObj.createSubSetEnumerationByQuery( queryString );
101 bResult &= subSet.hasMoreElements();
103 while (subSet.hasMoreElements()) {
104 try{
105 subSet.nextElement();
107 } catch (com.sun.star.container.NoSuchElementException e){
108 log.println("Exception occurred ");
109 e.printStackTrace(log);
110 bResult = false;
111 } catch (com.sun.star.lang.WrappedTargetException e){
112 log.println("Exception occurred ");
113 e.printStackTrace(log);
114 bResult = false;
120 tRes.tested("createSubSetEnumerationByQuery()", bResult);
124 * The function was called with object relation
125 * as parameter. The returned <code>XEnumeration</code> must not be null and
126 * elements of it must be valid.
129 public void _createSubSetEnumerationByProperties() {
131 boolean bResult = true;
133 XEnumeration subSet = oObj.createSubSetEnumerationByProperties( m_querySequenze );
135 bResult = subSet.hasMoreElements();
137 while (subSet.hasMoreElements()) {
138 try{
139 subSet.nextElement();
141 } catch (com.sun.star.container.NoSuchElementException e){
142 log.println("Exception occurred ");
143 e.printStackTrace(log);
144 bResult = false;
145 } catch (com.sun.star.lang.WrappedTargetException e){
146 log.println("Exception occurred ");
147 e.printStackTrace(log);
148 bResult = false;
152 tRes.tested("createSubSetEnumerationByProperties()", bResult);