1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OSetElementGroupInfoAccess.java,v $
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 ************************************************************************/
32 import java
.io
.PrintWriter
;
35 import lib
.TestEnvironment
;
36 import lib
.TestParameters
;
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
.container
.XNameReplace
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.lang
.XSingleServiceFactory
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
49 import com
.sun
.star
.util
.XChangesBatch
;
52 public class OSetElementGroupInfoAccess
extends TestCase
{
53 /** Called to create an instance of <code>TestEnvironment</code> with an
54 * object to test and related objects. <br>
56 * An instance of com.sun.star.comp.configuration.ConfigurationProvider
57 * is created at the MultiServiceFactory of the Office<br>
58 * At this an instance of com.sun.star.configuration.ConfigurationAccess is created
59 * and from the resulting XNameAccess the first element is taken.
61 * @param tParam test parameters
62 * @param log writer to log information while testing
64 * @see TestEnvironment
65 * @see #getTestEnvironment()
68 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
70 XInterface oObj
= null;
71 log
.println("creating the Environment");
73 PropertyValue
[] nodeArgs
= new PropertyValue
[1];
74 PropertyValue nodepath
= new PropertyValue();
75 nodepath
.Name
= "nodepath";
76 nodepath
.Value
= "org.openoffice.Office.Common/Menus";
78 nodepath
.State
= PropertyState
.DEFAULT_VALUE
;
79 nodeArgs
[0] = nodepath
;
81 XNameAccess xHierachNameAccess
= null;
82 XNameReplace xChangeView
= null;
83 XComponent xDisposeComponent
= null;
86 XInterface Provider
= (XInterface
) ((XMultiServiceFactory
)tParam
.getMSF())
87 .createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
88 XMultiServiceFactory pMSF
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
89 XMultiServiceFactory
.class,
92 xHierachNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class,
93 pMSF
.createInstanceWithArguments(
94 "com.sun.star.configuration.ConfigurationAccess", nodeArgs
));
96 XInterface oInnerSetInfoAccess
= (XInterface
) xHierachNameAccess
.getByName("New");
98 XNameAccess names
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class,
101 String
[] theNames
= names
.getElementNames();
103 log
.println("Contains " + theNames
.length
+ " elements");
105 xDisposeComponent
= (XComponent
)
106 UnoRuntime
.queryInterface(XComponent
.class, xHierachNameAccess
);
108 String
[] elnames
= names
.getElementNames();
110 log
.println("use node 'm0'");
111 oObj
= (XInterface
) names
.getByName("m0");
115 log
.println("create ConfigurationUpdateAccess to modify the object...");
117 xHierachNameAccess
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class,
118 pMSF
.createInstanceWithArguments(
119 "com.sun.star.configuration.ConfigurationUpdateAccess",
122 oInnerSetInfoAccess
= (XInterface
) xHierachNameAccess
.getByName("New");
124 names
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class,
125 oInnerSetInfoAccess
);
127 log
.println("use node 'm0'");
129 XInterface xInt
= (XInterface
) names
.getByName("m0");
130 xChangeView
= (XNameReplace
) UnoRuntime
.queryInterface(XNameReplace
.class,
133 } catch (com
.sun
.star
.uno
.Exception e
) {
137 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
139 String
[] pNames
= new String
[] { "ImageIdentifier", "Title", "URL", "TargetName" };
141 String
[] pTypes
= new String
[] { "String", "String", "String", "String" };
143 TestEnvironment tEnv
= new TestEnvironment(oObj
);
145 tEnv
.addObjRelation("cannotSwitchParent",
146 "configmgr: BasicElement::setParent: cannot move Entry");
148 tEnv
.addObjRelation("HierachicalName", "/org.openoffice.Office");
149 tEnv
.addObjRelation("ElementName", "Title");
150 tEnv
.addObjRelation("NoSetName", "OInnerValueSetInfoAccess");
151 tEnv
.addObjRelation("TemplateName", "cfg:value/cfg:any");
152 tEnv
.addObjRelation("expectedName", "ImageIdentifier");
154 tEnv
.addObjRelation("XContainer.NewValue", "aValue");
155 tEnv
.addObjRelation("XContainer.ElementName", "TargetName");
156 tEnv
.addObjRelation("XContainer.Container", xChangeView
);
158 // dispose the owner of the test object
159 tEnv
.addObjRelation("XComponent.DisposeThis", xDisposeComponent
);
161 tEnv
.addObjRelation("PropertyNames", pNames
);
162 tEnv
.addObjRelation("PropertyTypes", pTypes
);
163 tEnv
.addObjRelation("allReadOnly",
164 "all Properties of OSetElementGroupInfoAccess are read Only");
166 tEnv
.addObjRelation("TemplateInstance", "org.openoffice.Office.Common/MenuType");
171 * Create entries in the ExternalApps layer, so there is something to test
172 * @param oObj The test object: used to create some entries.
174 private void createSomeEntries(XInterface xObj
) {
175 XNameContainer xCont
= (XNameContainer
)UnoRuntime
.queryInterface(XNameContainer
.class, xObj
);
176 insertOrUpdate(xCont
, "file", xObj
);
177 // insertOrUpdate(xCont, "ftp", "some");
178 // insertOrUpdate(xCont, "dummy", "arbitrary");
179 // insertOrUpdate(xCont, "http", "value");
180 // write the changes into the user layer.
181 XChangesBatch xBatch
= (XChangesBatch
)UnoRuntime
.queryInterface(XChangesBatch
.class, xObj
);
183 xBatch
.commitChanges();
185 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
186 // ignore: bug will be found with the interface test
191 * Insert a value in a name container or else update it
192 * @param xCont The name conationer to insert or update.
193 * @param name The name of the value.
194 * @param value The value itself.
196 private void insertOrUpdate(XNameContainer xCont
, String name
, XInterface value
) {
197 boolean update
= false;
198 XSingleServiceFactory xFac
= (XSingleServiceFactory
) UnoRuntime
.queryInterface(
199 XSingleServiceFactory
.class,
203 xCont
.insertByName(name
, xFac
.createInstance());
205 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
206 log
.println("ERROR: " + e
.toString());
207 // ignore: bug will be found with the interface test
209 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
210 log
.println("ERROR: " + e
.toString());
211 // ignore: bug will be found with the interface test
213 catch(com
.sun
.star
.container
.ElementExistException e
) {
216 catch(com
.sun
.star
.uno
.Exception e
) {
217 log
.println("could not create Instance: " + e
.toString());
222 xCont
.replaceByName(name
, xFac
.createInstance());
224 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
225 // ignore: bug will be found with the interface test
227 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
228 // ignore: bug will be found with the interface test
230 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
231 // ignore: bug will be found with the interface test
233 catch(com
.sun
.star
.uno
.Exception e
) {
234 log
.println("could not create Instance: " + e
.toString());