Debian Codegraph @

framework/qa/complex/ModuleManager/CheckXModuleManager.java

raw
1 /*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19 package complex.ModuleManager;
20
21 import com.sun.star.beans.*;
22 import com.sun.star.frame.*;
23 import com.sun.star.lang.*;
24 import com.sun.star.uno.AnyConverter;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.util.*;
27 import com.sun.star.container.*;
28
29
30
31 // ---------- junit imports -----------------
32 import org.junit.After;
33 import org.junit.AfterClass;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.openoffice.test.OfficeConnection;
38 import static org.junit.Assert.*;
39
40
41
42 /** @short todo document me
43 */
44 public class CheckXModuleManager
45 {
46
47 // some const
48
49
50 // member
51
52 /** points to the global uno service manager. */
53 private XMultiServiceFactory m_xSmgr = null;
54
55 /** the module manager for testing. */
56 private XModuleManager m_xMM = null;
57
58 /** a special frame used to load documents there. */
59 private XComponentLoader m_xLoader = null;
60
61
62 // test environment
63
64
65 /** @short Create the environment for following tests.
66
67 @descr Use either a component loader from desktop or
68 from frame
69 */
70 @Before public void before()
71 throws java.lang.Exception
72 {
73 // get uno service manager from global test environment
74 m_xSmgr = getMSF();
75
76 // create module manager
77 m_xMM = UnoRuntime.queryInterface(XModuleManager.class, m_xSmgr.createInstance("com.sun.star.frame.ModuleManager"));
78
79 // create desktop instance to create a special frame to load documents there.
80 XFrame xDesktop = UnoRuntime.queryInterface(XFrame.class, m_xSmgr.createInstance("com.sun.star.frame.Desktop"));
81
82 m_xLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop.findFrame("_blank", 0));
83 }
84
85
86 /** @short close the environment.
87 */
88 @After public void after()
89 throws java.lang.Exception
90 {
91 XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xLoader);
92 xClose.close(false);
93
94 m_xLoader = null;
95 m_xMM = null;
96 m_xSmgr = null;
97 }
98
99
100 /** @todo document me
101 */
102 @Test public void checkModuleIdentification()
103 throws java.lang.Exception
104 {
105 impl_identifyModulesBasedOnDocs("com.sun.star.text.TextDocument" );
106 impl_identifyModulesBasedOnDocs("com.sun.star.text.WebDocument" );
107 impl_identifyModulesBasedOnDocs("com.sun.star.text.GlobalDocument" );
108 impl_identifyModulesBasedOnDocs("com.sun.star.formula.FormulaProperties" );
109 impl_identifyModulesBasedOnDocs("com.sun.star.sheet.SpreadsheetDocument" );
110 impl_identifyModulesBasedOnDocs("com.sun.star.drawing.DrawingDocument" );
111 impl_identifyModulesBasedOnDocs("com.sun.star.presentation.PresentationDocument");
112 impl_identifyModulesBasedOnDocs("com.sun.star.sdb.OfficeDatabaseDocument" );
113 // TODO: fails
114 // impl_identifyModulesBasedOnDocs("com.sun.star.chart.ChartDocument" );
115 }
116
117
118 /** @todo document me
119 */
120 @Test public void checkModuleConfigurationReadable()
121 throws java.lang.Exception
122 {
123 }
124
125
126 /** @todo document me
127 */
128 @Test public void checkModuleConfigurationWriteable()
129 throws java.lang.Exception
130 {
131 // modules supporting real documents
132 impl_checkReadOnlyPropsOfModule("com.sun.star.text.TextDocument" );
133 impl_checkReadOnlyPropsOfModule("com.sun.star.text.WebDocument" );
134 impl_checkReadOnlyPropsOfModule("com.sun.star.text.GlobalDocument" );
135 impl_checkReadOnlyPropsOfModule("com.sun.star.formula.FormulaProperties" );
136 impl_checkReadOnlyPropsOfModule("com.sun.star.sheet.SpreadsheetDocument" );
137 impl_checkReadOnlyPropsOfModule("com.sun.star.drawing.DrawingDocument" );
138 impl_checkReadOnlyPropsOfModule("com.sun.star.presentation.PresentationDocument");
139 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.OfficeDatabaseDocument" );
140 impl_checkReadOnlyPropsOfModule("com.sun.star.chart.ChartDocument" );
141
142 // other modules
143 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.FormDesign" );
144 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.TextReportDesign" );
145 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.RelationDesign" );
146 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.QueryDesign" );
147 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.TableDesign" );
148 impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.DataSourceBrowser");
149 impl_checkReadOnlyPropsOfModule("com.sun.star.frame.Bibliography" );
150 impl_checkReadOnlyPropsOfModule("com.sun.star.script.BasicIDE" );
151 impl_checkReadOnlyPropsOfModule("com.sun.star.frame.StartModule" );
152 }
153
154
155 /** @todo document me
156 */
157 @Test public void checkModuleConfigurationQueries()
158 throws java.lang.Exception
159 {
160 impl_searchModulesByDocumentService("com.sun.star.text.TextDocument" );
161 impl_searchModulesByDocumentService("com.sun.star.text.WebDocument" );
162 impl_searchModulesByDocumentService("com.sun.star.text.GlobalDocument" );
163 impl_searchModulesByDocumentService("com.sun.star.formula.FormulaProperties" );
164 impl_searchModulesByDocumentService("com.sun.star.sheet.SpreadsheetDocument" );
165 impl_searchModulesByDocumentService("com.sun.star.drawing.DrawingDocument" );
166 impl_searchModulesByDocumentService("com.sun.star.presentation.PresentationDocument");
167 impl_searchModulesByDocumentService("com.sun.star.sdb.OfficeDatabaseDocument" );
168 impl_searchModulesByDocumentService("com.sun.star.chart.ChartDocument" );
169 }
170
171
172 /** @todo document me
173 */
174 private void impl_searchModulesByDocumentService(String sDocumentService)
175 throws java.lang.Exception
176 {
177 System.out.println("search modules matching document service '"+sDocumentService+"' ...");
178
179 NamedValue[] lProps = new NamedValue[1];
180 lProps[0] = new NamedValue();
181 lProps[0].Name = "ooSetupFactoryDocumentService";
182 lProps[0].Value = sDocumentService;
183
184 XContainerQuery xMM = UnoRuntime.queryInterface(XContainerQuery.class, m_xMM);
185 XEnumeration xResult = xMM.createSubSetEnumerationByProperties(lProps);
186 while(xResult.hasMoreElements())
187 {
188 PropertyValue[] lModuleProps = (PropertyValue[])AnyConverter.toArray(xResult.nextElement());
189 int c = lModuleProps.length;
190 int i = 0;
191 String sFoundModule = "";
192 String sFoundDocService = "";
193 for (i=0; i<c; ++i)
194 {
195 if (lModuleProps[i].Name.equals("ooSetupFactoryModuleIdentifier"))
196 {
197 sFoundModule = AnyConverter.toString(lModuleProps[i].Value);
198 }
199 if (lModuleProps[i].Name.equals("ooSetupFactoryDocumentService"))
200 {
201 sFoundDocService = AnyConverter.toString(lModuleProps[i].Value);
202 }
203 }
204
205 if (sFoundModule.length() < 1)
206 {
207 fail("Miss module identifier in result set. Returned data are incomplete.");
208 }
209
210 if ( ! sFoundDocService.equals(sDocumentService))
211 {
212 fail("Query returned wrong module '" + sFoundModule + "' with DocumentService='" + sFoundDocService + "'.");
213 }
214
215 System.out.println("Found module '"+sFoundModule+"'.");
216 }
217 }
218
219
220 /** @todo document me
221 */
222 private void impl_identifyModulesBasedOnDocs(String sModule)
223 throws java.lang.Exception
224 {
225 System.out.println("check identification of module '"+sModule+"' ...");
226
227 XNameAccess xMM = UnoRuntime.queryInterface(XNameAccess.class, m_xMM);
228 PropertyValue[] lModuleProps = (PropertyValue[])AnyConverter.toArray(xMM.getByName(sModule));
229 int c = lModuleProps.length;
230 int i = 0;
231 String sFactoryURL = "";
232
233 for (i=0; i<c; ++i)
234 {
235 if (lModuleProps[i].Name.equals("ooSetupFactoryEmptyDocumentURL"))
236 {
237 sFactoryURL = AnyConverter.toString(lModuleProps[i].Value);
238 break;
239 }
240 }
241
242 PropertyValue[] lArgs = new PropertyValue[1];
243 lArgs[0] = new PropertyValue();
244 lArgs[0].Name = "Hidden";
245 lArgs[0].Value = Boolean.TRUE;
246
247 XComponent xModel = m_xLoader.loadComponentFromURL(sFactoryURL, "_self", 0, lArgs);
248 XFrame xFrame = UnoRuntime.queryInterface(XFrame.class, m_xLoader);
249 XController xController = xFrame.getController();
250
251 String sModuleFrame = m_xMM.identify(xFrame );
252 String sModuleController = m_xMM.identify(xController);
253 String sModuleModel = m_xMM.identify(xModel );
254
255 if ( ! sModuleFrame.equals(sModule))
256 {
257 fail("Identification of module '" + sModule + "' failed if frame was used as entry point.");
258 }
259 if ( ! sModuleController.equals(sModule))
260 {
261 fail("Identification of module '" + sModule + "' failed if controller was used as entry point.");
262 }
263 if ( ! sModuleModel.equals(sModule))
264 {
265 fail("Identification of module '" + sModule + "' failed if model was used as entry point.");
266 }
267 }
268
269
270 /** @todo document me
271 */
272 private void impl_checkReadOnlyPropsOfModule(String sModule)
273 throws java.lang.Exception
274 {
275 XNameReplace xWrite = UnoRuntime.queryInterface(XNameReplace.class, m_xMM);
276
277 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryDocumentService" , "test");
278 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryActualFilter" , "test");
279 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryActualTemplateFilter", "test");
280 impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryEmptyDocumentURL" , "test");
281 }
282
283
284 /** @todo document me
285 */
286 private void impl_checkReadOnlyPropOfModule(XNameReplace xMM ,
287 String sModule ,
288 String sPropName ,
289 Object aPropValue )
290 throws java.lang.Exception
291 {
292 PropertyValue[] lChanges = new PropertyValue[1];
293 lChanges[0] = new PropertyValue();
294 lChanges[0].Name = sPropName;
295 lChanges[0].Value = aPropValue;
296
297 // Note: Exception is expected !
298 System.out.println("check readonly state of module '"+sModule+"' for property '"+sPropName+"' ...");
299 try
300 {
301 xMM.replaceByName(sModule, lChanges);
302 fail("Was able to write READONLY property '"+sPropName+"' of module '"+sModule+"' configuration.");
303 }
304 catch(Throwable ex)
305 {}
306 }
307
308
309
310 private XMultiServiceFactory getMSF()
311 {
312 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
313 }
314
315 // setup and close connections
316 @BeforeClass public static void setUpConnection() throws Exception {
317 System.out.println("setUpConnection()");
318 connection.setUp();
319 }
320
321 @AfterClass public static void tearDownConnection()
322 throws InterruptedException, com.sun.star.uno.Exception
323 {
324 System.out.println("tearDownConnection()");
325 connection.tearDown();
326 }
327
328 private static final OfficeConnection connection = new OfficeConnection();
329
330 }