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: CheckXModuleManager.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 ************************************************************************/
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
;
47 //-----------------------------------------------
48 /** @short todo document me
50 public class CheckXModuleManager
extends ComplexTestCase
52 //-------------------------------------------
55 //-------------------------------------------
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 //-------------------------------------------
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()
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
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(
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.
119 throws java
.lang
.Exception
121 XCloseable xClose
= (XCloseable
)UnoRuntime
.queryInterface(
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" );
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
;
222 String sFoundModule
= "";
223 String sFoundDocService
= "";
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
;
254 String sFactoryURL
= "";
258 if (lModuleProps
[i
].Name
.equals("ooSetupFactoryEmptyDocumentURL"))
260 sFactoryURL
= AnyConverter
.toString(lModuleProps
[i
].Value
);
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
,
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.");