merge the formfield patch from ooo-build
[ooovba.git] / sw / qa / complex / writer / CheckIndexedPropertyValues.java
blob870fbebcddc799584e90836a3f42a2b7f4aead0f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CheckIndexedPropertyValues.java,v $
10 * $Revision: 1.4 $
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 complex.writer;
33 import complexlib.ComplexTestCase;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.uno.XInterface;
36 import com.sun.star.beans.PropertyValue;
37 import com.sun.star.container.XIndexContainer;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.Type;
41 /**
42 * Test the com.sun.star.document.IndexedPropertyValues service
44 public class CheckIndexedPropertyValues extends ComplexTestCase {
46 private final String testedServiceName =
47 "com.sun.star.document.IndexedPropertyValues";
48 public String[] getTestMethodNames() {
49 return new String[]{"checkIndexedPropertyValues"};
52 /* public String getTestObjectName() {
53 return testedServiceName;
56 public void checkIndexedPropertyValues() {
57 Object oObj = null;
58 try {
59 // print information about the service
60 XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
61 oObj = xMSF.createInstance(testedServiceName);
62 System.out.println("****************");
63 System.out.println("Service Name:");
64 util.dbg.getSuppServices(oObj);
65 System.out.println("****************");
66 System.out.println("Interfaces:");
67 util.dbg.printInterfaces((XInterface)oObj, true);
69 catch(com.sun.star.uno.Exception e) {
70 System.out.println("Cannot create object.");
71 e.printStackTrace();
72 failed(e.getMessage());
73 return;
75 XIndexContainer xCont = (XIndexContainer)UnoRuntime.queryInterface(
76 XIndexContainer.class, oObj);
78 assure("XIndexContainer was queried but returned null.",
79 (xCont != null));
80 PropertyValue[] prop1 = new PropertyValue[1];
81 prop1[0] = new PropertyValue();
82 prop1[0].Name = "Jupp";
83 prop1[0].Value = "GoodGuy";
85 PropertyValue[] prop2 = new PropertyValue[1];
86 prop2[0] = new PropertyValue();
87 prop2[0].Name = "Horst";
88 prop2[0].Value = "BadGuy";
90 try {
91 Type t = xCont.getElementType();
92 log.println("Insertable Type: " + t.getTypeName());
93 assure("Initial container is not empty: " + xCont.getCount(), xCont.getCount()==0);
94 log.println("Inserting a PropertyValue.");
95 xCont.insertByIndex(0, prop1);
96 PropertyValue[]ret = (PropertyValue[])xCont.getByIndex(0);
97 assure("Got the wrong PropertyValue: " +
98 ret[0].Name + " " +(String)ret[0].Value,
99 ret[0].Name.equals(prop1[0].Name) &&
100 ret[0].Value.equals(prop1[0].Value));
101 log.println("Replace the PropertyValue.");
102 xCont.replaceByIndex(0, prop2);
103 ret = (PropertyValue[])xCont.getByIndex(0);
104 assure("Got the wrong PropertyValue: " +
105 ret[0].Name + " " +(String)ret[0].Value,
106 ret[0].Name.equals(prop2[0].Name) &&
107 ret[0].Value.equals(prop2[0].Value));
108 log.println("Remove the PropertyValue.");
109 xCont.removeByIndex(0);
110 assure("Could not remove PropertyValue.",
111 !xCont.hasElements() && xCont.getCount()==0);
112 log.println("Insert again.");
113 xCont.insertByIndex(0, prop1);
114 xCont.insertByIndex(1, prop2);
115 assure("Did not insert PropertyValue.",
116 xCont.hasElements() && xCont.getCount()==2);
118 try {
119 log.println("Insert with wrong index.");
120 xCont.insertByIndex(25, prop2);
121 failed("IllegalArgumentException was not thrown.");
123 catch(com.sun.star.lang.IllegalArgumentException e) {
124 log.println("Wrong exception thrown.");
125 failed(e.getMessage());
126 e.printStackTrace();
128 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
129 log.println("Expected exception thrown: "+e);
131 catch(com.sun.star.lang.WrappedTargetException e) {
132 log.println("Wrong exception thrown.");
133 failed(e.getMessage());
134 e.printStackTrace();
137 try {
138 log.println("Remove non-existing index.");
139 xCont.removeByIndex(25);
140 failed("IndexOutOfBoundsException was not thrown.");
142 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
143 log.println("Expected exception thrown: "+e);
145 catch(com.sun.star.lang.WrappedTargetException e) {
146 log.println("Wrong exception thrown.");
147 failed(e.getMessage());
148 e.printStackTrace();
151 try {
152 log.println("Insert wrong argument.");
153 xCont.insertByIndex(2, "Example String");
154 failed("IllegalArgumentException was not thrown.");
156 catch(com.sun.star.lang.IllegalArgumentException e) {
157 log.println("Expected exception thrown: " + e);
159 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
160 log.println("Wrong exception thrown.");
161 failed(e.getMessage());
162 e.printStackTrace();
164 catch(com.sun.star.lang.WrappedTargetException e) {
165 log.println("Wrong exception thrown.");
166 failed(e.getMessage());
167 e.printStackTrace();
171 catch(com.sun.star.lang.IllegalArgumentException e) {
172 failed(e.getMessage());
173 e.printStackTrace();
175 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
176 failed(e.getMessage());
177 e.printStackTrace();
179 catch(com.sun.star.lang.WrappedTargetException e) {
180 failed(e.getMessage());
181 e.printStackTrace();