bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlDateField.java
blob45b22e05b17bb828eca0c4c798dfb5b42e2cc8e5
1 /*
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 .
18 package mod._toolkit;
20 import com.sun.star.awt.XControlModel;
21 import com.sun.star.awt.XDevice;
22 import com.sun.star.awt.XGraphics;
23 import com.sun.star.awt.XTextComponent;
24 import com.sun.star.awt.XToolkit;
25 import com.sun.star.awt.XWindow;
26 import com.sun.star.awt.XWindowPeer;
27 import com.sun.star.drawing.XControlShape;
28 import com.sun.star.frame.XController;
29 import com.sun.star.frame.XFrame;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
34 import com.sun.star.view.XControlAccess;
36 import java.io.PrintWriter;
38 import lib.StatusException;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
43 import util.FormTools;
44 import util.SOfficeFactory;
45 import util.WriterTools;
46 import util.utils;
49 public class UnoControlDateField extends TestCase {
50 private static XTextDocument xTextDoc;
51 private static XTextDocument xTD2;
53 protected void initialize(TestParameters Param, PrintWriter log) {
54 SOfficeFactory SOF = SOfficeFactory.getFactory(
55 (XMultiServiceFactory) Param.getMSF());
57 try {
58 log.println("creating a textdocument");
59 xTextDoc = SOF.createTextDoc(null);
60 xTD2 = WriterTools.createTextDoc(
61 (XMultiServiceFactory) Param.getMSF());
62 } catch (com.sun.star.uno.Exception e) {
63 // Some exception occurs.FAILED
64 e.printStackTrace(log);
65 throw new StatusException("Couldn't create document", e);
69 protected void cleanup(TestParameters tParam, PrintWriter log) {
70 log.println(" disposing xTextDoc ");
72 util.DesktopTools.closeDoc(xTextDoc);
73 util.DesktopTools.closeDoc(xTD2);
76 protected TestEnvironment createTestEnvironment(TestParameters Param,
77 PrintWriter log) {
78 XInterface oObj = null;
79 XWindowPeer the_win = null;
80 XToolkit the_kit = null;
81 XDevice aDevice = null;
82 XGraphics aGraphic = null;
83 XWindow anotherWindow = null;
85 //Insert a ControlShape and get the ControlModel
86 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
87 4500, 15000,
88 10000,
89 "DateField",
90 "UnoControlDateField");
92 WriterTools.getDrawPage(xTextDoc).add(aShape);
94 XControlModel the_Model = aShape.getControl();
96 //Try to query XControlAccess
97 XControlAccess the_access = UnoRuntime.queryInterface(
98 XControlAccess.class,
99 xTextDoc.getCurrentController());
101 //get the DateFieldControl for the needed Object relations
102 try {
103 oObj = the_access.getControl(the_Model);
104 the_win = the_access.getControl(the_Model).getPeer();
105 the_kit = the_win.getToolkit();
106 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
107 aGraphic = aDevice.createGraphics();
108 } catch (Exception e) {
109 log.println("Couldn't get DateFieldControl");
110 e.printStackTrace(log);
111 throw new StatusException("Couldn't get DateFieldControl", e);
114 log.println(
115 "creating a new environment for UnoControlDateField object");
117 TestEnvironment tEnv = new TestEnvironment(oObj);
120 //Adding ObjRelation for XView
121 tEnv.addObjRelation("GRAPHICS", aGraphic);
124 //Adding ObjRelation for XControl
125 tEnv.addObjRelation("CONTEXT", xTextDoc);
126 tEnv.addObjRelation("WINPEER", the_win);
127 tEnv.addObjRelation("TOOLKIT", the_kit);
128 tEnv.addObjRelation("MODEL", the_Model);
130 System.out.println("ImplementationName: " + utils.getImplName(oObj));
132 try {
133 XController aController = xTD2.getCurrentController();
134 XFrame aFrame = aController.getFrame();
135 anotherWindow = aFrame.getComponentWindow();
136 } catch (Exception e) {
137 e.printStackTrace(log);
138 throw new StatusException("Couldn't create XWindow", e);
142 // Object Relation for XWindow
143 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
144 tEnv.addObjRelation("XWindow.ControlShape", aShape);
146 // Adding relation for XTextListener
147 ifc.awt._XTextListener.TestTextListener listener =
148 new ifc.awt._XTextListener.TestTextListener();
149 XTextComponent textComp = UnoRuntime.queryInterface(
150 XTextComponent.class, oObj);
151 textComp.addTextListener(listener);
152 tEnv.addObjRelation("TestTextListener", listener);
154 return tEnv;
155 } // finish method getTestEnvironment
156 } // finish class UnoControlDateField