Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / container / _XSet.java
blob743a894f5d047f579796b86ac1b491fd2bff8012
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;
23 import com.sun.star.container.XSet;
24 import com.sun.star.lang.XMultiServiceFactory;
26 /**
27 * Testing <code>com.sun.star.container.XSet</code>
28 * interface methods :
29 * <ul>
30 * <li><code> has()</code></li>
31 * <li><code> insert()</code></li>
32 * <li><code> remove()</code></li>
33 * </ul> <p>
34 * Test is <b> NOT </b> multithread compliant. <p>
35 * @see com.sun.star.container.XSet
37 public class _XSet extends MultiMethodTest {
39 public static XSet oObj = null;
41 private Object element = null ;
42 private boolean hasResult = true ;
44 /**
45 * Inserts the element stored and removed before. <p>
46 * Has <b> OK </b> status if <code>has()</code> method returns
47 * <code>true</code>.
48 * The following method tests are to be completed successfully before :
49 * <ul>
50 * <li> <code> remove() </code> : element from set is stored and
51 * removed </li>
52 * </ul>
54 public void _insert() {
55 boolean res = true ;
56 try {
57 XMultiServiceFactory xMSF = tParam.getMSF();
58 element = xMSF.createInstance(
59 "com.sun.star.reflection.TypeDescriptionProvider");
62 oObj.insert(element) ;
64 if (!oObj.has(element)) {
65 res = false ;
66 log.println("After adding element method has()" +
67 " returned false") ;
68 hasResult = false ;
70 } catch (com.sun.star.container.ElementExistException e) {
71 e.printStackTrace(log) ;
72 res = false ;
73 } catch (com.sun.star.lang.IllegalArgumentException e) {
74 e.printStackTrace(log) ;
75 res = false ;
77 catch(com.sun.star.uno.Exception e) {
78 e.printStackTrace(log);
79 res = false;
82 tRes.tested("insert()", res) ;
85 /**
86 * Through <code>XEnumeration</code> interface an element from the set
87 * is retrieved. Then this element removed.<p>
88 * Has <b> OK </b> status if after removing <code>has()</code> method
89 * returns false.
91 public void _remove() {
92 requiredMethod("insert()");
93 boolean res = true ;
95 try {
97 // get an element to be removed/inserted
99 oObj.remove(element) ;
101 if (oObj.has(element)) {
102 res = false ;
103 log.println("After removing element method has()" +
104 " returned true") ;
105 hasResult = false ;
110 } catch (com.sun.star.container.NoSuchElementException e) {
111 e.printStackTrace(log) ;
112 res = false ;
113 } catch (com.sun.star.lang.IllegalArgumentException e) {
114 e.printStackTrace(log) ;
115 res = false ;
118 tRes.tested("remove()", res) ;
122 * Does nothing. Testing performed in previous methods.<p>
123 * Has <b> OK </b> status if after <code>remove()</code> call
124 * methods returned <code>false</code>, and after <code>remove()</code>
125 * call methods returned <code>true</code>.
126 * The following method tests are to be completed successfully before :
127 * <ul>
128 * <li> <code> insert() </code> : here the method is checked </li>
129 * <li> <code> remove() </code> : here the method is checked </li>
130 * </ul>
132 public void _has() {
134 requiredMethod("insert()") ;
135 requiredMethod("remove()") ;
137 tRes.tested("has()", hasResult) ;
140 } // finished class _XSet