Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlDateField.java
blobf9abc3c69523596b198a5671acd1553b563c64ab
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.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.FormTools;
41 import util.SOfficeFactory;
42 import util.WriterTools;
43 import util.utils;
46 public class UnoControlDateField extends TestCase {
47 private static XTextDocument xTextDoc;
48 private static XTextDocument xTD2;
50 @Override
51 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
52 SOfficeFactory SOF = SOfficeFactory.getFactory(
53 Param.getMSF());
55 log.println("creating a textdocument");
56 xTextDoc = SOF.createTextDoc(null);
57 xTD2 = WriterTools.createTextDoc(
58 Param.getMSF());
61 @Override
62 protected void cleanup(TestParameters tParam, PrintWriter log) {
63 log.println(" disposing xTextDoc ");
65 util.DesktopTools.closeDoc(xTextDoc);
66 util.DesktopTools.closeDoc(xTD2);
69 @Override
70 protected TestEnvironment createTestEnvironment(TestParameters Param,
71 PrintWriter log) throws Exception {
72 XInterface oObj = null;
73 XWindowPeer the_win = null;
74 XToolkit the_kit = null;
75 XDevice aDevice = null;
76 XGraphics aGraphic = null;
77 XWindow anotherWindow = null;
79 //Insert a ControlShape and get the ControlModel
80 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
81 4500, 15000,
82 10000,
83 "DateField",
84 "UnoControlDateField");
86 WriterTools.getDrawPage(xTextDoc).add(aShape);
88 XControlModel the_Model = aShape.getControl();
90 //Try to query XControlAccess
91 XControlAccess the_access = UnoRuntime.queryInterface(
92 XControlAccess.class,
93 xTextDoc.getCurrentController());
95 //get the DateFieldControl for the needed Object relations
96 oObj = the_access.getControl(the_Model);
97 the_win = the_access.getControl(the_Model).getPeer();
98 the_kit = the_win.getToolkit();
99 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
100 aGraphic = aDevice.createGraphics();
102 log.println(
103 "creating a new environment for UnoControlDateField object");
105 TestEnvironment tEnv = new TestEnvironment(oObj);
108 //Adding ObjRelation for XView
109 tEnv.addObjRelation("GRAPHICS", aGraphic);
112 //Adding ObjRelation for XControl
113 tEnv.addObjRelation("CONTEXT", xTextDoc);
114 tEnv.addObjRelation("WINPEER", the_win);
115 tEnv.addObjRelation("TOOLKIT", the_kit);
116 tEnv.addObjRelation("MODEL", the_Model);
118 System.out.println("ImplementationName: " + utils.getImplName(oObj));
120 XController aController = xTD2.getCurrentController();
121 XFrame aFrame = aController.getFrame();
122 anotherWindow = aFrame.getComponentWindow();
125 // Object Relation for XWindow
126 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
127 tEnv.addObjRelation("XWindow.ControlShape", aShape);
129 // Adding relation for XTextListener
130 ifc.awt._XTextListener.TestTextListener listener =
131 new ifc.awt._XTextListener.TestTextListener();
132 XTextComponent textComp = UnoRuntime.queryInterface(
133 XTextComponent.class, oObj);
134 textComp.addTextListener(listener);
135 tEnv.addObjRelation("TestTextListener", listener);
137 return tEnv;
138 } // finish method getTestEnvironment
139 } // finish class UnoControlDateField