merge the formfield patch from ooo-build
[ooovba.git] / framework / qa / complex / ModuleManager / CheckXModuleManager.java
blob3570e3fc54210431beb29792cb7e0c2f001c71b8
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: CheckXModuleManager.java,v $
10 * $Revision: 1.3 $
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.ModuleManager;
33 import com.sun.star.beans.*;
34 import com.sun.star.frame.*;
35 import com.sun.star.lang.*;
36 import com.sun.star.uno.*;
37 import com.sun.star.util.*;
38 import com.sun.star.container.*;
40 import complexlib.ComplexTestCase;
42 import helper.URLHelper;
44 import java.lang.*;
45 import java.util.*;
47 //-----------------------------------------------
48 /** @short todo document me
50 public class CheckXModuleManager extends ComplexTestCase
52 //-------------------------------------------
53 // some const
55 //-------------------------------------------
56 // member
58 /** points to the global uno service manager. */
59 private XMultiServiceFactory m_xSmgr = null;
61 /** the module manager for testing. */
62 private XModuleManager m_xMM = null;
64 /** a special frame used to load documents there. */
65 private XComponentLoader m_xLoader = null;
67 //-------------------------------------------
68 // test environment
70 //-------------------------------------------
71 /** @short A function to tell the framework,
72 which test functions are available.
74 @return All test methods.
75 @todo Think about selection of tests from outside ...
77 public String[] getTestMethodNames()
79 return new String[]
81 "checkModuleIdentification" ,
82 "checkModuleConfigurationReadable" ,
83 "checkModuleConfigurationWriteable",
84 "checkModuleConfigurationQueries"
88 //-------------------------------------------
89 /** @short Create the environment for following tests.
91 @descr Use either a component loader from desktop or
92 from frame
94 public void before()
95 throws java.lang.Exception
97 // get uno service manager from global test environment
98 m_xSmgr = (XMultiServiceFactory)param.getMSF();
100 // create module manager
101 m_xMM = (XModuleManager)UnoRuntime.queryInterface(
102 XModuleManager.class,
103 m_xSmgr.createInstance("com.sun.star.frame.ModuleManager"));
105 // create desktop instance to create a special frame to load documents there.
106 XFrame xDesktop = (XFrame)UnoRuntime.queryInterface(
107 XFrame.class,
108 m_xSmgr.createInstance("com.sun.star.frame.Desktop"));
110 m_xLoader = (XComponentLoader)UnoRuntime.queryInterface(
111 XComponentLoader.class,
112 xDesktop.findFrame("_blank", 0));
115 //-------------------------------------------
116 /** @short close the environment.
118 public void after()
119 throws java.lang.Exception
121 XCloseable xClose = (XCloseable)UnoRuntime.queryInterface(
122 XCloseable.class,
123 m_xLoader);
124 xClose.close(false);
126 m_xLoader = null;
127 m_xMM = null;
128 m_xSmgr = null;
131 //-------------------------------------------
132 /** @todo document me
134 public void checkModuleIdentification()
135 throws java.lang.Exception
137 impl_identifyModulesBasedOnDocs("com.sun.star.text.TextDocument" );
138 impl_identifyModulesBasedOnDocs("com.sun.star.text.WebDocument" );
139 impl_identifyModulesBasedOnDocs("com.sun.star.text.GlobalDocument" );
140 impl_identifyModulesBasedOnDocs("com.sun.star.formula.FormulaProperties" );
141 impl_identifyModulesBasedOnDocs("com.sun.star.sheet.SpreadsheetDocument" );
142 impl_identifyModulesBasedOnDocs("com.sun.star.drawing.DrawingDocument" );
143 impl_identifyModulesBasedOnDocs("com.sun.star.presentation.PresentationDocument");
144 impl_identifyModulesBasedOnDocs("com.sun.star.sdb.OfficeDatabaseDocument" );
145 impl_identifyModulesBasedOnDocs("com.sun.star.chart.ChartDocument" );
148 //-------------------------------------------
149 /** @todo document me
151 public void checkModuleConfigurationReadable()
152 throws java.lang.Exception
156 //-------------------------------------------
157 /** @todo document me
159 public void checkModuleConfigurationWriteable()
160 throws java.lang.Exception
162 // modules supporting real documents
163 impl_checkReadOnlyPropsOfModule("com.sun.star.text.TextDocument" );
164 impl_checkReadOnlyPropsOfModule("com.sun.star.text.WebDocument" );
165 impl_checkReadOnlyPropsOfModule("com.sun.star.text.GlobalDocument" );
166 impl_checkReadOnlyPropsOfModule("com.sun.star.formula.FormulaProperties" );
167 impl_checkReadOnlyPropsOfModule("com.sun.star.sheet.SpreadsheetDocument" );
168 impl_checkReadOnlyPropsOfModule("com.sun.star.drawing.DrawingDocument" );
169 impl_checkReadOnlyPropsOfModule("com.sun.star.presentation.PresentationDocument");
170 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.OfficeDatabaseDocument" );
171 impl_checkReadOnlyPropsOfModule("com.sun.star.chart.ChartDocument" );
173 // other modules
174 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.FormDesign" );
175 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.TextReportDesign" );
176 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.RelationDesign" );
177 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.QueryDesign" );
178 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.TableDesign" );
179 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.DataSourceBrowser");
180 impl_checkReadOnlyPropsOfModule("com.sun.star.frame.Bibliography" );
181 impl_checkReadOnlyPropsOfModule("com.sun.star.script.BasicIDE" );
182 impl_checkReadOnlyPropsOfModule("com.sun.star.frame.StartModule" );
185 //-------------------------------------------
186 /** @todo document me
188 public void checkModuleConfigurationQueries()
189 throws java.lang.Exception
191 impl_searchModulesByDocumentService("com.sun.star.text.TextDocument" );
192 impl_searchModulesByDocumentService("com.sun.star.text.WebDocument" );
193 impl_searchModulesByDocumentService("com.sun.star.text.GlobalDocument" );
194 impl_searchModulesByDocumentService("com.sun.star.formula.FormulaProperties" );
195 impl_searchModulesByDocumentService("com.sun.star.sheet.SpreadsheetDocument" );
196 impl_searchModulesByDocumentService("com.sun.star.drawing.DrawingDocument" );
197 impl_searchModulesByDocumentService("com.sun.star.presentation.PresentationDocument");
198 impl_searchModulesByDocumentService("com.sun.star.sdb.OfficeDatabaseDocument" );
199 impl_searchModulesByDocumentService("com.sun.star.chart.ChartDocument" );
202 //-------------------------------------------
203 /** @todo document me
205 private void impl_searchModulesByDocumentService(String sDocumentService)
206 throws java.lang.Exception
208 log.println("search modules matching document service '"+sDocumentService+"' ...");
210 NamedValue[] lProps = new NamedValue[1];
211 lProps[0] = new NamedValue();
212 lProps[0].Name = "ooSetupFactoryDocumentService";
213 lProps[0].Value = sDocumentService;
215 XContainerQuery xMM = (XContainerQuery)UnoRuntime.queryInterface(XContainerQuery.class, m_xMM);
216 XEnumeration xResult = xMM.createSubSetEnumerationByProperties(lProps);
217 while(xResult.hasMoreElements())
219 PropertyValue[] lModuleProps = (PropertyValue[])AnyConverter.toArray(xResult.nextElement());
220 int c = lModuleProps.length;
221 int i = 0;
222 String sFoundModule = "";
223 String sFoundDocService = "";
224 for (i=0; i<c; ++i)
226 if (lModuleProps[i].Name.equals("ooSetupFactoryModuleIdentifier"))
227 sFoundModule = AnyConverter.toString(lModuleProps[i].Value);
228 if (lModuleProps[i].Name.equals("ooSetupFactoryDocumentService"))
229 sFoundDocService = AnyConverter.toString(lModuleProps[i].Value);
232 if (sFoundModule.length() < 1)
233 failed("Miss module identifier in result set. Returned data are incomplete.");
235 if ( ! sFoundDocService.equals(sDocumentService))
236 failed("Query returned wrong module '"+sFoundModule+"' with DocumentService='"+sFoundDocService+"'.");
238 log.println("Found module '"+sFoundModule+"'.");
242 //-------------------------------------------
243 /** @todo document me
245 private void impl_identifyModulesBasedOnDocs(String sModule)
246 throws java.lang.Exception
248 log.println("check identification of module '"+sModule+"' ...");
250 XNameAccess xMM = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, m_xMM);
251 PropertyValue[] lModuleProps = (PropertyValue[])AnyConverter.toArray(xMM.getByName(sModule));
252 int c = lModuleProps.length;
253 int i = 0;
254 String sFactoryURL = "";
256 for (i=0; i<c; ++i)
258 if (lModuleProps[i].Name.equals("ooSetupFactoryEmptyDocumentURL"))
260 sFactoryURL = AnyConverter.toString(lModuleProps[i].Value);
261 break;
265 PropertyValue[] lArgs = new PropertyValue[1];
266 lArgs[0] = new PropertyValue();
267 lArgs[0].Name = "Hidden";
268 lArgs[0].Value = Boolean.TRUE;
270 XComponent xModel = m_xLoader.loadComponentFromURL(sFactoryURL, "_self", 0, lArgs);
271 XFrame xFrame = (XFrame)UnoRuntime.queryInterface(XFrame.class, m_xLoader);
272 XController xController = xFrame.getController();
274 String sModuleFrame = m_xMM.identify(xFrame );
275 String sModuleController = m_xMM.identify(xController);
276 String sModuleModel = m_xMM.identify(xModel );
278 if ( ! sModuleFrame.equals(sModule))
279 failed("Identification of module '"+sModule+"' failed if frame was used as entry point.");
280 if ( ! sModuleController.equals(sModule))
281 failed("Identification of module '"+sModule+"' failed if controller was used as entry point.");
282 if ( ! sModuleModel.equals(sModule))
283 failed("Identification of module '"+sModule+"' failed if model was used as entry point.");
286 //-------------------------------------------
287 /** @todo document me
289 private void impl_checkReadOnlyPropsOfModule(String sModule)
290 throws java.lang.Exception
292 XNameReplace xWrite = (XNameReplace)UnoRuntime.queryInterface(XNameReplace.class, m_xMM);
294 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryDocumentService" , "test");
295 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryActualFilter" , "test");
296 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryActualTemplateFilter", "test");
297 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryEmptyDocumentURL" , "test");
300 //-------------------------------------------
301 /** @todo document me
303 private void impl_checkReadOnlyPropOfModule(XNameReplace xMM ,
304 String sModule ,
305 String sPropName ,
306 Object aPropValue )
307 throws java.lang.Exception
309 PropertyValue[] lChanges = new PropertyValue[1];
310 lChanges[0] = new PropertyValue();
311 lChanges[0].Name = sPropName;
312 lChanges[0].Value = aPropValue;
314 // Note: Exception is expected !
315 log.println("check readonly state of module '"+sModule+"' for property '"+sPropName+"' ...");
318 xMM.replaceByName(sModule, lChanges);
319 failed("Was able to write READONLY property '"+sPropName+"' of module '"+sModule+"' configuration.");
321 catch(Throwable ex)