merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _cfgmgr2 / ORootElementGroupUpdateAccess.java
blob4a65729e98d7fd3e430e1cab19cff5f701af04cf
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: ORootElementGroupUpdateAccess.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.beans.XPropertySet;
42 import com.sun.star.container.XNameAccess;
43 import com.sun.star.container.XNameReplace;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 import com.sun.star.util.XChangesBatch;
50 public class ORootElementGroupUpdateAccess extends TestCase {
51 /** Called to create an instance of <code>TestEnvironment</code> with an
52 * object to test and related objects. <br>
54 * An instance of com.sun.star.comp.configuration.ConfigurationProvider
55 * is created at the MultiServiceFactory of the Office<br>
56 * At this an instance of com.sun.star.configuration.ConfigurationAccess is created
57 * and from the resulting XNameAccess the first element is taken.
59 * @param tParam test parameters
60 * @param log writer to log information while testing
62 * @see TestEnvironment
63 * @see #getTestEnvironment()
66 protected TestEnvironment createTestEnvironment(TestParameters tParam,
67 PrintWriter log) {
68 XInterface oObj = null;
69 log.println("creating the Environment");
71 PropertyValue[] nodeArgs = new PropertyValue[1];
72 PropertyValue nodepath = new PropertyValue();
73 nodepath.Name = "nodepath";
74 nodepath.Value = "org.openoffice.Office.Common/Internal";
76 nodepath.Handle = -1;
77 nodepath.State = PropertyState.DEFAULT_VALUE;
78 nodeArgs[0] = nodepath;
80 try {
81 XInterface Provider = (XInterface) ((XMultiServiceFactory)tParam.getMSF())
82 .createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
83 XMultiServiceFactory pMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
84 XMultiServiceFactory.class,
85 Provider);
86 oObj = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
87 pMSF.createInstanceWithArguments(
88 "com.sun.star.configuration.ConfigurationUpdateAccess",
89 nodeArgs));
91 /* helper.ConfigurationRead read = new helper.ConfigurationRead(pMSF, "org.openoffice.Office.Common");
92 String[] subs = read.getRootNodeNames();
93 for (int i=0; i<subs.length; i++)
94 System.out.println("Rootnodes " + subs[i]);
95 subs = read.getSubNodeNames("Internal");
96 for (int i=0; i<subs.length; i++)
97 System.out.println("Rootnodes " + subs[i]);
98 Object subNode = read.getByHierarchicalName("Internal/RecoveryList");
99 util.dbg.getSuppServices(subNode); */
101 } catch (com.sun.star.uno.Exception e) {
102 e.printStackTrace();
105 log.println("ImplementationName: " + utils.getImplName(oObj));
107 TestEnvironment tEnv = new TestEnvironment(oObj);
109 XPropertySet prop = (XPropertySet) UnoRuntime.queryInterface(
110 XPropertySet.class, oObj);
112 Object instance = null;
114 String[] pNames = new String[] {
115 "CurrentTempURL",
116 "DevelopmentChart",
117 "SendCrashMail",
118 "Slot",
119 "UseMailUI"//, "RecoveryList"
122 String[] pTypes = new String[]{
123 "String",
124 "Boolean",
125 "Boolean",
126 "Boolean",
127 "Boolean"
130 tEnv.addObjRelation("PropertyNames", pNames);
131 tEnv.addObjRelation("PropertyTypes", pTypes);
133 // for XHierarchicalNameAccess
134 tEnv.addObjRelation("ElementName", "Slot");
136 tEnv.addObjRelation("XLocalizable.ReadOnly", "Localization is final and can't be changed");
138 tEnv.addObjRelation("XChangesNotifier.ChangesBatch", (XChangesBatch)UnoRuntime.queryInterface(XChangesBatch.class, oObj));
140 // set a new temp directory: use java.io.tmpdir as substitute
141 String newTempURL = util.utils.getFullURL(util.utils.getUsersTempDir());
142 String curTempURL = "";
143 try {
144 curTempURL = (String)prop.getPropertyValue("CurrentTempURL");
146 catch(Exception e) {
147 log.println("Cannot get property for XChangesBatch test: this test is bound to fail.");
148 e.printStackTrace((PrintWriter)log);
150 // fallback 1: get user home
151 if (newTempURL.equalsIgnoreCase(curTempURL)) {
152 newTempURL = util.utils.getFullURL(System.getProperty("user.home"));
153 // fallback 2: get user dir
154 if (newTempURL.equalsIgnoreCase(curTempURL)) {
155 newTempURL = util.utils.getFullURL(System.getProperty("user.dir"));
159 tEnv.addObjRelation("XChangesBatch.ChangeElement", newTempURL);
160 tEnv.addObjRelation("XChangesBatch.OriginalElement", curTempURL);
161 tEnv.addObjRelation("XChangesBatch.PropertyName", "CurrentTempURL");
162 tEnv.addObjRelation("XChangesBatch.PropertySet", prop);
163 tEnv.addObjRelation("XChangesNotifier.ChangeElement", newTempURL);
164 tEnv.addObjRelation("XChangesNotifier.OriginalElement", curTempURL);
165 tEnv.addObjRelation("XChangesNotifier.PropertyName", "CurrentTempURL");
166 tEnv.addObjRelation("XChangesNotifier.PropertySet", prop);
168 tEnv.addObjRelation("expectedName", "RecoveryList");
169 tEnv.addObjRelation("HierachicalName", "/org.openoffice");
171 String overwriteString = new String("ThisIsSenselessForSure");
172 tEnv.addObjRelation("INSTANCE1", overwriteString);
173 tEnv.addObjRelation("NAMEREPLACE", pNames[0]);
175 tEnv.addObjRelation("XContainer.NewValue", overwriteString);
176 tEnv.addObjRelation("XContainer.ElementName", pNames[0]);
177 tEnv.addObjRelation("XContainer.Container", (XNameReplace)UnoRuntime.queryInterface(XNameReplace.class, oObj));
179 tEnv.addObjRelation("NoSetName", "ORootElementGroupInfoAccess");
181 return tEnv;