merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _cfgmgr2 / OInnerValueSetUpdateAccess.java
blob9f6c84c2b2313d47105fa7d744ea97b388302d28
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: OInnerValueSetUpdateAccess.java,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
30 package mod._cfgmgr2;
32 import java.io.PrintWriter;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 import util.utils;
39 import com.sun.star.beans.PropertyState;
40 import com.sun.star.beans.PropertyValue;
41 import com.sun.star.container.XNameAccess;
42 import com.sun.star.container.XNameContainer;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 import com.sun.star.util.XChangesBatch;
49 public class OInnerValueSetUpdateAccess extends TestCase {
50 /** Called to create an instance of <code>TestEnvironment</code> with an
51 * object to test and related objects. <br>
53 * An instance of com.sun.star.comp.configuration.ConfigurationProvider
54 * is created at the MultiServiceFactory of the Office<br>
55 * At this an instance of com.sun.star.configuration.ConfigurationAccess is created
56 * and from the resulting XNameAccess the first element is taken.
58 * @param tParam test parameters
59 * @param log writer to log information while testing
61 * @see TestEnvironment
62 * @see #getTestEnvironment()
65 protected TestEnvironment createTestEnvironment(TestParameters tParam,
66 PrintWriter log) {
67 XInterface oObj = null;
69 log.println("creating the Environment");
71 // create some entries for testing, use the ORootElementValueSetUpdateAccess
72 // service for this: see cfgmgr2.ORootElementValueSetUpdateAccess
73 createSomeEntries((XMultiServiceFactory)tParam.getMSF());
75 PropertyValue[] nodeArgs = new PropertyValue[1];
76 PropertyValue nodepath = new PropertyValue();
77 nodepath.Name = "nodepath";
78 nodepath.Value = "/org.openoffice.Office.Common";
79 nodepath.Handle = -1;
80 nodepath.State = PropertyState.DEFAULT_VALUE;
81 nodeArgs[0] = nodepath;
83 try {
84 XInterface Provider = (XInterface) ((XMultiServiceFactory)tParam.getMSF())
85 .createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
86 XMultiServiceFactory pMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
87 XMultiServiceFactory.class,
88 Provider);
89 XNameAccess names = (XNameAccess) UnoRuntime.queryInterface(
90 XNameAccess.class,
91 pMSF.createInstanceWithArguments(
92 "com.sun.star.configuration.ConfigurationUpdateAccess",
93 nodeArgs));
95 oObj = (XInterface) names.getByName("ExternalApps");
97 names = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
98 oObj);
100 String[] theNames = names.getElementNames();
102 log.println("Contains " + theNames.length + " elements");
104 // for (int k = 0; k < theNames.length; k++) {
105 // System.out.println("child " + theNames[k]);
106 // }
107 } catch (com.sun.star.uno.Exception e) {
108 e.printStackTrace();
111 log.println("ImplementationName: " + utils.getImplName(oObj));
113 String[] pNames = new String[] {
114 "file", "ftp", "http", "https", "mailto"
117 String[] pTypes = new String[] {
118 "String", "String", "String", "String", "String"
121 TestEnvironment tEnv = new TestEnvironment(oObj);
123 tEnv.addObjRelation("cannotSwitchParent",
124 "configmgr: BasicElement::setParent: cannot move Entry");
126 String overwriteString = "NewOne";
127 tEnv.addObjRelation("INSTANCE1", overwriteString);
128 tEnv.addObjRelation("NAMEREPLACE", pNames[1]);
129 // for XContainer
130 tEnv.addObjRelation("INSTANCE", overwriteString);
132 tEnv.addObjRelation("HierachicalName", "/org.openoffice.Office");
133 tEnv.addObjRelation("ElementName", "file");
134 tEnv.addObjRelation("NoSetName", "OInnerValueSetInfoAccess");
135 tEnv.addObjRelation("TemplateName", "cfg:value/cfg:any");
136 tEnv.addObjRelation("expectedName", "file");
138 return tEnv;
142 * Create entries in the ExternalApps layer, so there is something to test
143 * @param oObj The test object: used to create some entries.
145 private void createSomeEntries(XMultiServiceFactory xMSF) {
146 PropertyValue[] nodeArgs = new PropertyValue[1];
147 PropertyValue nodepath = new PropertyValue();
148 nodepath.Name = "nodepath";
149 nodepath.Value = "org.openoffice.Office.Common/ExternalApps";
150 nodepath.Handle = -1;
151 nodepath.State = PropertyState.DEFAULT_VALUE;
152 nodeArgs[0] = nodepath;
154 Object oObj = null;
155 try {
156 XInterface Provider = (XInterface) xMSF.createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
157 XMultiServiceFactory pMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
158 XMultiServiceFactory.class,
159 Provider);
160 oObj = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
161 pMSF.createInstanceWithArguments(
162 "com.sun.star.configuration.ConfigurationUpdateAccess",
163 nodeArgs));
165 } catch (com.sun.star.uno.Exception e) {
166 e.printStackTrace();
168 XNameContainer xCont = (XNameContainer)UnoRuntime.queryInterface(XNameContainer.class, oObj);
169 insertOrUpdate(xCont, "file", "just");
170 insertOrUpdate(xCont, "ftp", "some");
171 insertOrUpdate(xCont, "dummy", "arbitrary");
172 insertOrUpdate(xCont, "http", "value");
173 // write the changes into the user layer.
174 XChangesBatch xBatch = (XChangesBatch)UnoRuntime.queryInterface(XChangesBatch.class, oObj);
175 try {
176 xBatch.commitChanges();
178 catch(com.sun.star.lang.WrappedTargetException e) {
179 // ignore: bug will be found with the interface test
184 * Insert a value in a name container or else update it
185 * @param xCont The name conationer to insert or update.
186 * @param name The name of the value.
187 * @param value The value itself.
189 private void insertOrUpdate(XNameContainer xCont, String name, String value) {
190 boolean update = false;
191 try {
192 xCont.insertByName(name, value);
193 System.out.println("##### No Exception!");
195 catch(com.sun.star.lang.IllegalArgumentException e) {
196 // ignore: bug will be found with the interface test
198 catch(com.sun.star.lang.WrappedTargetException e) {
199 // ignore: bug will be found with the interface test
201 catch(com.sun.star.container.ElementExistException e) {
202 update = true;
204 try {
205 if (update)
206 xCont.replaceByName(name, value);
208 catch(com.sun.star.lang.IllegalArgumentException e) {
209 // ignore: bug will be found with the interface test
211 catch(com.sun.star.container.NoSuchElementException e) {
212 // ignore: bug will be found with the interface test
214 catch(com.sun.star.lang.WrappedTargetException e) {
215 // ignore: bug will be found with the interface test