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
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.text
.XTextDocument
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
29 import com
.sun
.star
.uno
.XInterface
;
30 import com
.sun
.star
.view
.XControlAccess
;
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
39 import util
.FormTools
;
40 import util
.SOfficeFactory
;
41 import util
.WriterTools
;
46 * Test for <code>com.sun.star.awt.Toolkit</code> service.
48 public class Toolkit
extends TestCase
{
49 private static XTextDocument xTextDoc
;
51 protected void initialize(TestParameters Param
, PrintWriter log
) {
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
53 (XMultiServiceFactory
) Param
.getMSF());
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
);
65 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
66 log
.println(" disposing xTextDoc ");
67 util
.DesktopTools
.closeDoc(xTextDoc
);
71 * Creating a Testenvironment for the interfaces to be tested.
72 * Creates <code>com.sun.star.awt.Toolkit</code> service.
74 public TestEnvironment
createTestEnvironment(TestParameters Param
,
76 throws StatusException
{
77 XInterface oObj
= null;
78 XWindowPeer the_win
= null;
81 //Insert a ControlShape and get the ControlModel
82 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
86 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
88 XControlModel the_Model
= aShape
.getControl();
90 //Try to query XControlAccess
91 XControlAccess the_access
= UnoRuntime
.queryInterface(
93 xTextDoc
.getCurrentController());
94 XController cntrlr
= UnoRuntime
.queryInterface(
96 xTextDoc
.getCurrentController());
100 win
= cntrlr
.getFrame().getContainerWindow();
103 //win = (XWindow) UnoRuntime.queryInterface(XWindow.class, ctrl) ;
104 the_win
= the_access
.getControl(the_Model
).getPeer();
105 oObj
= (XInterface
) ((XMultiServiceFactory
) 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