merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _cfgmgr2 / OSetElementSetInfoAccess.java
blob3586fed643fb92a5b23b340bfae97cfb573727d1
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: OSetElementSetInfoAccess.java,v $
10 * $Revision: 1.5 $
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.XHierarchicalNameAccess;
42 import com.sun.star.container.XNameAccess;
43 import com.sun.star.container.XNameContainer;
44 import com.sun.star.container.XNameReplace;
45 import com.sun.star.lang.XComponent;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.lang.XSingleServiceFactory;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
52 public class OSetElementSetInfoAccess 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,
69 PrintWriter log) {
70 XInterface oObj = null;
71 Object instance = null;
72 Object instance1 = null;
73 log.println("creating the Environment");
75 PropertyValue[] nodeArgs = new PropertyValue[1];
76 PropertyValue nodepath = new PropertyValue();
77 nodepath.Name = "nodepath";
78 nodepath.Value = "org.openoffice.Office.Labels/Manufacturer";
79 nodepath.Handle = -1;
80 nodepath.State = PropertyState.DEFAULT_VALUE;
81 nodeArgs[0] = nodepath;
83 String hierarchicalElementName = "Labels['Avery A4']";
84 String elementName = "Avery A4";
86 XNameReplace xChangeView = null;
87 XNameContainer xContainer = null;
88 XHierarchicalNameAccess xHierachNameAccess = null;
89 try {
90 XInterface Provider = (XInterface) ((XMultiServiceFactory)tParam.getMSF())
91 .createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
92 XMultiServiceFactory pMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
93 XMultiServiceFactory.class,
94 Provider);
95 xHierachNameAccess = (XHierarchicalNameAccess) UnoRuntime.queryInterface(
96 XHierarchicalNameAccess.class,
97 pMSF.createInstanceWithArguments(
98 "com.sun.star.configuration.ConfigurationAccess",
99 nodeArgs));
101 oObj = (XInterface) xHierachNameAccess.getByHierarchicalName(hierarchicalElementName);
103 // craete a changeable view.
104 XHierarchicalNameAccess changeableNames = (XHierarchicalNameAccess) UnoRuntime.queryInterface(XHierarchicalNameAccess.class,
105 pMSF.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", nodeArgs));
107 XInterface xInt = (XInterface) changeableNames.getByHierarchicalName(hierarchicalElementName);
108 xChangeView = (XNameReplace)UnoRuntime.queryInterface(XNameReplace.class, xInt);
109 XSingleServiceFactory jobsFac = (XSingleServiceFactory) UnoRuntime.queryInterface(
110 XSingleServiceFactory.class, xChangeView);
111 instance1 = jobsFac.createInstance();
113 } catch (com.sun.star.uno.Exception e) {
114 e.printStackTrace();
117 log.println("ImplementationName: " + utils.getImplName(oObj));
119 TestEnvironment tEnv = new TestEnvironment(oObj);
121 XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(
122 XNameAccess.class, oObj);
124 String[] pNames = xNameAccess.getElementNames();
126 tEnv.addObjRelation("ElementName", pNames[0]);
128 tEnv.addObjRelation("cannotSwitchParent",
129 "configmgr: BasicElement::setParent: cannot move Entry");
131 tEnv.addObjRelation("XContainer.NewValue", instance1);
132 tEnv.addObjRelation("XContainer.ElementName", "L0");
133 tEnv.addObjRelation("XContainer.Container", xChangeView);
135 // dispose the owner of the test object
136 tEnv.addObjRelation("XComponent.DisposeThis", (XComponent)
137 UnoRuntime.queryInterface(XComponent.class, xHierachNameAccess));
139 tEnv.addObjRelation("expectedName", pNames[0]);
140 tEnv.addObjRelation("HierachicalName", "/org.openoffice.Office");
141 tEnv.addObjRelation("NAMEREPLACE", pNames[0]);
142 tEnv.addObjRelation("NoSetName", "OInnerTreeSetInfoAccess");
143 tEnv.addObjRelation("TemplateName", "org.openoffice.Office.Labels/LabelType");
144 tEnv.addObjRelation("TemplateInstance", "org.openoffice.Office.Labels/Labels");
146 return tEnv;