merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / Toolkit.java
blobed58d7fb706c1875a1bc986173fc76a69187f7c0
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: Toolkit.java,v $
10 * $Revision: 1.8 $
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._toolkit;
32 import com.sun.star.awt.XControlModel;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.awt.XWindowPeer;
35 import com.sun.star.drawing.XControlShape;
36 import com.sun.star.drawing.XShape;
37 import com.sun.star.frame.XController;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.view.XControlAccess;
45 import java.io.PrintWriter;
47 import lib.StatusException;
48 import lib.TestCase;
49 import lib.TestEnvironment;
50 import lib.TestParameters;
52 import util.FormTools;
53 import util.SOfficeFactory;
54 import util.WriterTools;
55 import util.utils;
58 /**
59 * Test for <code>com.sun.star.awt.Toolkit</code> service.
61 public class Toolkit extends TestCase {
62 private static XTextDocument xTextDoc;
64 protected void initialize(TestParameters Param, PrintWriter log) {
65 SOfficeFactory SOF = SOfficeFactory.getFactory(
66 (XMultiServiceFactory) Param.getMSF());
68 try {
69 log.println("creating a textdocument");
70 xTextDoc = SOF.createTextDoc(null);
71 } catch (com.sun.star.uno.Exception e) {
72 // Some exception occures.FAILED
73 e.printStackTrace(log);
74 throw new StatusException("Couldn't create document", e);
78 protected void cleanup(TestParameters tParam, PrintWriter log) {
79 log.println(" disposing xTextDoc ");
80 util.DesktopTools.closeDoc(xTextDoc);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Creates <code>com.sun.star.awt.Toolkit</code> service.
88 public TestEnvironment createTestEnvironment(TestParameters Param,
89 PrintWriter log)
90 throws StatusException {
91 XInterface oObj = null;
92 XWindowPeer the_win = null;
93 XWindow win = null;
95 //Insert a ControlShape and get the ControlModel
96 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
97 4500, 15000, 10000,
98 "CommandButton");
100 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
102 XControlModel the_Model = aShape.getControl();
104 //Try to query XControlAccess
105 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
106 XControlAccess.class,
107 xTextDoc.getCurrentController());
108 XController cntrlr = (XController) UnoRuntime.queryInterface(
109 XController.class,
110 xTextDoc.getCurrentController());
112 //now get the toolkit
113 try {
114 win = cntrlr.getFrame().getContainerWindow();
117 //win = (XWindow) UnoRuntime.queryInterface(XWindow.class, ctrl) ;
118 the_win = the_access.getControl(the_Model).getPeer();
119 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
120 "com.sun.star.awt.Toolkit");
121 } catch (com.sun.star.uno.Exception e) {
122 log.println("Couldn't get toolkit");
123 e.printStackTrace(log);
124 throw new StatusException("Couldn't get toolkit", e);
127 XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, xTextDoc);
129 log.println(" creating a new environment for toolkit object");
131 TestEnvironment tEnv = new TestEnvironment(oObj);
133 log.println("Implementation Name: " + utils.getImplName(oObj));
135 tEnv.addObjRelation("WINPEER", the_win);
137 tEnv.addObjRelation("XModel", xModel);
140 // adding relation for XDataTransferProviderAccess
141 tEnv.addObjRelation("XDataTransferProviderAccess.XWindow", win);
143 return tEnv;
144 } // finish method getTestEnvironment
145 } // finish class Toolkit