Update ooo320-m1
[ooovba.git] / sw / qa / complex / writer / CheckNamedPropertyValues.java
blobc42fc0969c0095fafd506fb7e44a47a3fddc3630
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: CheckNamedPropertyValues.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;
34 import complexlib.ComplexTestCase;
35 import com.sun.star.beans.PropertyValue;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.container.XNameContainer;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.Type;
42 /**
45 public class CheckNamedPropertyValues extends ComplexTestCase {
47 private final String testedServiceName =
48 "com.sun.star.document.NamedPropertyValues";
50 public String[] getTestMethodNames() {
51 return new String[]{"checkNamedPropertyValues"};
54 /* public String getTestObjectName() {
55 return "complex.writer.CheckNamedPropertyValues";
56 } */
58 public void checkNamedPropertyValues() {
59 Object oObj = null;
60 try {
61 XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
62 oObj = xMSF.createInstance(testedServiceName);
63 System.out.println("****************");
64 System.out.println("Service Name:");
65 util.dbg.getSuppServices(oObj);
66 System.out.println("****************");
67 System.out.println("Interfaces:");
68 util.dbg.printInterfaces((XInterface)oObj, true);
70 catch(com.sun.star.uno.Exception e) {
71 e.printStackTrace();
72 failed(e.getMessage());
73 return;
75 XNameContainer xCont = (XNameContainer)UnoRuntime.queryInterface(
76 XNameContainer.class, oObj);
78 assure("XNameContainer 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.hasElements());
95 log.println("Insert a PropertyValue.");
96 xCont.insertByName("prop1", prop1);
97 PropertyValue[]ret = (PropertyValue[])xCont.getByName("prop1");
98 assure("Got the wrong PropertyValue: " +
99 ret[0].Name + " " +(String)ret[0].Value,
100 ret[0].Name.equals(prop1[0].Name) &&
101 ret[0].Value.equals(prop1[0].Value));
102 log.println("Replace the PropertyValue.");
103 xCont.replaceByName("prop1", prop2);
104 ret = (PropertyValue[])xCont.getByName("prop1");
105 assure("Got the wrong PropertyValue: " +
106 ret[0].Name + " " +(String)ret[0].Value,
107 ret[0].Name.equals(prop2[0].Name) &&
108 ret[0].Value.equals(prop2[0].Value));
109 log.println("Remove the PropertyValue.");
110 xCont.removeByName("prop1");
111 assure("Could not remove PropertyValue.", !xCont.hasElements());
112 log.println("Insert again.");
113 xCont.insertByName("prop1", prop1);
114 xCont.insertByName("prop2", prop2);
115 assure("Did not insert PropertyValue.", xCont.hasElements());
116 String[] names = xCont.getElementNames();
117 int count = 0;
118 for (int i=0; i<names.length; i++) {
119 if (names[i].equals("prop1") || names[i].equals("prop2"))
120 count++;
121 else
122 failed("Got a wrong element name: "+names[i]);
124 if (count != 2)
125 failed("Not all element names were returned.");
127 try {
128 log.println("Insert PropertyValue with an existing name.");
129 xCont.insertByName("prop2", prop1);
130 failed("ElementExistException was not thrown.");
132 catch(com.sun.star.lang.IllegalArgumentException e) {
133 log.println("Wrong exception thrown.");
134 failed(e.getMessage());
135 e.printStackTrace();
137 catch(com.sun.star.container.ElementExistException e) {
138 log.println("Expected exception thrown: "+e);
140 catch(com.sun.star.lang.WrappedTargetException e) {
141 log.println("Wrong exception thrown.");
142 failed(e.getMessage());
143 e.printStackTrace();
146 try {
147 log.println("Inserting a wrong argument.");
148 xCont.insertByName("prop3", "Example String");
149 failed("IllegalArgumentException was not thrown.");
151 catch(com.sun.star.lang.IllegalArgumentException e) {
152 log.println("Expected exception thrown: "+e);
154 catch(com.sun.star.container.ElementExistException e) {
155 log.println("Wrong exception thrown.");
156 failed(e.getMessage());
157 e.printStackTrace();
159 catch(com.sun.star.lang.WrappedTargetException e) {
160 log.println("Wrong exception thrown.");
161 failed(e.getMessage());
162 e.printStackTrace();
165 try {
166 log.println("Remove a non-existing element.");
167 xCont.removeByName("prop3");
168 failed("NoSuchElementException was not thrown.");
170 catch(com.sun.star.container.NoSuchElementException e) {
171 log.println("Expected exception thrown: "+e);
173 catch(com.sun.star.lang.WrappedTargetException e) {
174 log.println("Wrong exception thrown.");
175 failed(e.getMessage());
176 e.printStackTrace();
180 catch(com.sun.star.lang.IllegalArgumentException e) {
181 failed(e.getMessage());
182 e.printStackTrace();
184 catch(com.sun.star.container.ElementExistException e) {
185 failed(e.getMessage());
186 e.printStackTrace();
188 catch(com.sun.star.container.NoSuchElementException e) {
189 failed(e.getMessage());
190 e.printStackTrace();
192 catch(com.sun.star.lang.WrappedTargetException e) {
193 failed(e.getMessage());
194 e.printStackTrace();