2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
20 import com
.sun
.star
.awt
.XControlModel
;
21 import com
.sun
.star
.awt
.XWindow
;
22 import com
.sun
.star
.awt
.XWindowPeer
;
23 import com
.sun
.star
.drawing
.XControlShape
;
24 import com
.sun
.star
.frame
.XController
;
25 import com
.sun
.star
.frame
.XModel
;
26 import com
.sun
.star
.text
.XTextDocument
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.uno
.XInterface
;
29 import com
.sun
.star
.view
.XControlAccess
;
31 import java
.io
.PrintWriter
;
33 import lib
.StatusException
;
35 import lib
.TestEnvironment
;
36 import lib
.TestParameters
;
38 import util
.FormTools
;
39 import util
.SOfficeFactory
;
40 import util
.WriterTools
;
45 * Test for <code>com.sun.star.awt.Toolkit</code> service.
47 public class Toolkit
extends TestCase
{
48 private static XTextDocument xTextDoc
;
51 protected void initialize(TestParameters Param
, PrintWriter log
) {
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
56 log
.println("creating a textdocument");
57 xTextDoc
= SOF
.createTextDoc(null);
58 } catch (com
.sun
.star
.uno
.Exception e
) {
59 // Some exception occurs.FAILED
60 e
.printStackTrace(log
);
61 throw new StatusException("Couldn't create document", e
);
66 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
67 log
.println(" disposing xTextDoc ");
68 util
.DesktopTools
.closeDoc(xTextDoc
);
72 * Creating a Testenvironment for the interfaces to be tested.
73 * Creates <code>com.sun.star.awt.Toolkit</code> service.
76 public TestEnvironment
createTestEnvironment(TestParameters Param
,
78 throws StatusException
{
79 XInterface oObj
= null;
80 XWindowPeer the_win
= null;
83 //Insert a ControlShape and get the ControlModel
84 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
88 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
90 XControlModel the_Model
= aShape
.getControl();
92 //Try to query XControlAccess
93 XControlAccess the_access
= UnoRuntime
.queryInterface(
95 xTextDoc
.getCurrentController());
96 XController cntrlr
= UnoRuntime
.queryInterface(
98 xTextDoc
.getCurrentController());
100 //now get the toolkit
102 win
= cntrlr
.getFrame().getContainerWindow();
104 the_win
= the_access
.getControl(the_Model
).getPeer();
105 oObj
= (XInterface
) Param
.getMSF().createInstance(
106 "com.sun.star.awt.Toolkit");
107 } catch (com
.sun
.star
.uno
.Exception e
) {
108 log
.println("Couldn't get toolkit");
109 e
.printStackTrace(log
);
110 throw new StatusException("Couldn't get toolkit", e
);
113 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
115 log
.println(" creating a new environment for toolkit object");
117 TestEnvironment tEnv
= new TestEnvironment(oObj
);
119 log
.println("Implementation Name: " + utils
.getImplName(oObj
));
121 tEnv
.addObjRelation("WINPEER", the_win
);
123 tEnv
.addObjRelation("XModel", xModel
);
126 // adding relation for XDataTransferProviderAccess
127 tEnv
.addObjRelation("XDataTransferProviderAccess.XWindow", win
);
130 } // finish method getTestEnvironment
131 } // finish class Toolkit