1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._fwk;
29 
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import java.io.PrintWriter;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.util.XCloseable;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.WriterTools;
41 
42 /**
43  */
44 public class UIElementFactoryManager extends TestCase {
45     Object oObj = null;
46     XTextDocument xTextDoc;
47 
48     /**
49      * Cleanup: close the created document
50      * @param tParam The test parameters.
51      * @param The log writer.
52      * @return The test environment.
53      */
54     protected void cleanup(TestParameters tParam, PrintWriter log) {
55         log.println("    disposing xTextDoc ");
56 
57         try {
58             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
59             XCloseable.class, xTextDoc);
60             closer.close(true);
61         } catch (com.sun.star.util.CloseVetoException e) {
62             log.println("couldn't close document");
63         } catch (com.sun.star.lang.DisposedException e) {
64             log.println("couldn't close document");
65         }
66     }
67 
68     /**
69      * Create test environment:
70      * <ul>
71      * <li>create a text doc</li>
72      * <li>get the model from the text doc</li>
73      * <li>query model for XUIConfigurationManagerSupplier interface</li>
74      * <li>get the manager from the supplier</li>
75      * </ul>
76      * @param tParam The test parameters.
77      * @param The log writer.
78      * @return The test environment.
79      */
80     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
81         TestEnvironment tEnv = null;
82         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
83 
84         log.println("Creating instance...");
85         xTextDoc = WriterTools.createTextDoc(xMSF);
86         try {
87             oObj = xMSF.createInstance("com.sun.star.ui.UIElementFactoryManager");
88         }
89         catch(com.sun.star.uno.Exception e) {
90             throw new StatusException("Cannot create test object.", e);
91         }
92         log.println("TestObject: " + util.utils.getImplName(oObj));
93 
94         tEnv = new TestEnvironment((XInterface)oObj);
95 
96 
97         return tEnv;
98     }
99 }
100 
101 
102