bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlDateField.java
blob3e6fb99b21a410608494d34453d1252dbd14c97b
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.text.XTextDocument;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import com.sun.star.view.XControlAccess;
35 import java.io.PrintWriter;
37 import lib.StatusException;
38 import lib.TestCase;
39 import lib.TestEnvironment;
40 import lib.TestParameters;
42 import util.FormTools;
43 import util.SOfficeFactory;
44 import util.WriterTools;
45 import util.utils;
48 public class UnoControlDateField extends TestCase {
49 private static XTextDocument xTextDoc;
50 private static XTextDocument xTD2;
52 @Override
53 protected void initialize(TestParameters Param, PrintWriter log) {
54 SOfficeFactory SOF = SOfficeFactory.getFactory(
55 Param.getMSF());
57 try {
58 log.println("creating a textdocument");
59 xTextDoc = SOF.createTextDoc(null);
60 xTD2 = WriterTools.createTextDoc(
61 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 @Override
70 protected void cleanup(TestParameters tParam, PrintWriter log) {
71 log.println(" disposing xTextDoc ");
73 util.DesktopTools.closeDoc(xTextDoc);
74 util.DesktopTools.closeDoc(xTD2);
77 @Override
78 protected TestEnvironment createTestEnvironment(TestParameters Param,
79 PrintWriter log) {
80 XInterface oObj = null;
81 XWindowPeer the_win = null;
82 XToolkit the_kit = null;
83 XDevice aDevice = null;
84 XGraphics aGraphic = null;
85 XWindow anotherWindow = null;
87 //Insert a ControlShape and get the ControlModel
88 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
89 4500, 15000,
90 10000,
91 "DateField",
92 "UnoControlDateField");
94 WriterTools.getDrawPage(xTextDoc).add(aShape);
96 XControlModel the_Model = aShape.getControl();
98 //Try to query XControlAccess
99 XControlAccess the_access = UnoRuntime.queryInterface(
100 XControlAccess.class,
101 xTextDoc.getCurrentController());
103 //get the DateFieldControl for the needed Object relations
104 try {
105 oObj = the_access.getControl(the_Model);
106 the_win = the_access.getControl(the_Model).getPeer();
107 the_kit = the_win.getToolkit();
108 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
109 aGraphic = aDevice.createGraphics();
110 } catch (Exception e) {
111 log.println("Couldn't get DateFieldControl");
112 e.printStackTrace(log);
113 throw new StatusException("Couldn't get DateFieldControl", e);
116 log.println(
117 "creating a new environment for UnoControlDateField object");
119 TestEnvironment tEnv = new TestEnvironment(oObj);
122 //Adding ObjRelation for XView
123 tEnv.addObjRelation("GRAPHICS", aGraphic);
126 //Adding ObjRelation for XControl
127 tEnv.addObjRelation("CONTEXT", xTextDoc);
128 tEnv.addObjRelation("WINPEER", the_win);
129 tEnv.addObjRelation("TOOLKIT", the_kit);
130 tEnv.addObjRelation("MODEL", the_Model);
132 System.out.println("ImplementationName: " + utils.getImplName(oObj));
134 try {
135 XController aController = xTD2.getCurrentController();
136 XFrame aFrame = aController.getFrame();
137 anotherWindow = aFrame.getComponentWindow();
138 } catch (Exception e) {
139 e.printStackTrace(log);
140 throw new StatusException("Couldn't create XWindow", e);
144 // Object Relation for XWindow
145 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
146 tEnv.addObjRelation("XWindow.ControlShape", aShape);
148 // Adding relation for XTextListener
149 ifc.awt._XTextListener.TestTextListener listener =
150 new ifc.awt._XTextListener.TestTextListener();
151 XTextComponent textComp = UnoRuntime.queryInterface(
152 XTextComponent.class, oObj);
153 textComp.addTextListener(listener);
154 tEnv.addObjRelation("TestTextListener", listener);
156 return tEnv;
157 } // finish method getTestEnvironment
158 } // finish class UnoControlDateField