bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ONavigationBarControl.java
blobe99c832bd6d318d24dace534d85703570585fc84
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._forms;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.FormTools;
27 import util.SOfficeFactory;
28 import util.WriterTools;
30 import com.sun.star.awt.XControl;
31 import com.sun.star.awt.XControlModel;
32 import com.sun.star.awt.XDevice;
33 import com.sun.star.awt.XGraphics;
34 import com.sun.star.awt.XToolkit;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.awt.XWindowPeer;
37 import com.sun.star.drawing.XControlShape;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.view.XControlAccess;
43 import util.DesktopTools;
45 public class ONavigationBarControl extends TestCase {
46 XTextDocument xTextDoc;
48 /**
49 * Creates a text document.
51 protected void initialize(TestParameters Param, PrintWriter log) {
52 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF());
54 try {
55 log.println("creating a textdocument");
56 xTextDoc = SOF.createTextDoc(null);
57 } catch (com.sun.star.uno.Exception e) {
58 // Some exception occurs.FAILED
59 e.printStackTrace(log);
60 throw new StatusException("Couldn't create document", e);
64 /**
65 * Disposes the text document created before
67 protected void cleanup(TestParameters tParam, PrintWriter log) {
68 log.println(" disposing xTextDoc ");
70 DesktopTools.closeDoc(xTextDoc);
73 /**
74 * Creates two components and inserts them to the form of
75 * text document. One component
76 * (<code>com.sun.star.form.component.CommandButton</code>) is created
77 * for testing, another to be passed as relation. Using a controller
78 * of the text document the controller of the first component is
79 * obtained and returned in environment as a test object. <p>
81 * Object relations created :
82 * <ul>
83 * <li> <code>'GRAPHICS'</code> for
84 * {@link ifc.awt._XView} : a graphics component
85 * created using screen device of the window peer of
86 * the controller tested. </li>
87 * <li> <code>'CONTEXT'</code> for
88 * {@link ifc.awt._XControl} : the text document
89 * where the component is inserted. </li>
90 * <li> <code>'WINPEER'</code> for
91 * {@link ifc.awt._XControl} : Window peer of the
92 * controller tested. </li>
93 * <li> <code>'TOOLKIT'</code> for
94 * {@link ifc.awt._XControl} : toolkit of the component.</li>
95 * <li> <code>'MODEL'</code> for
96 * {@link ifc.awt._XControl} : the model of the controller.</li>
97 * <li> <code>'XWindow.AnotherWindow'</code> for
98 * {@link ifc.awt._XWindow} : the controller of another
99 * component. </li>
100 * </ul>
102 protected TestEnvironment createTestEnvironment(TestParameters Param,
103 PrintWriter log) {
104 XInterface oObj = null;
105 XWindowPeer the_win = null;
106 XToolkit the_kit = null;
107 XDevice aDevice = null;
108 XGraphics aGraphic = null;
109 XControl aControl = null;
111 //Insert a ControlShape and get the ControlModel
112 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
113 4500, 15000, 10000,
114 "NavigationToolBar");
116 WriterTools.getDrawPage(xTextDoc).add(aShape);
118 XControlModel the_Model = aShape.getControl();
120 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
121 4500, 5000, 10000,
122 "TextField");
124 WriterTools.getDrawPage(xTextDoc).add(aShape2);
126 XControlModel the_Model2 = aShape2.getControl();
128 //Try to query XControlAccess
129 XControlAccess the_access = UnoRuntime.queryInterface(
130 XControlAccess.class,
131 xTextDoc.getCurrentController());
133 //now get the OButtonControl
134 try {
135 oObj = the_access.getControl(the_Model);
136 aControl = the_access.getControl(the_Model2);
137 the_win = the_access.getControl(the_Model).getPeer();
138 the_kit = the_win.getToolkit();
139 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
140 aGraphic = aDevice.createGraphics();
141 } catch (com.sun.star.container.NoSuchElementException e) {
142 log.println("Couldn't get ONavigationBarControl");
143 e.printStackTrace(log);
144 throw new StatusException("Couldn't get ONavigationBarControl", e);
147 log.println("creating a new environment for ONavigationBarControl object");
149 TestEnvironment tEnv = new TestEnvironment(oObj);
152 //Adding ObjRelation for XView
153 tEnv.addObjRelation("GRAPHICS", aGraphic);
156 //Adding ObjRelation for XControl
157 tEnv.addObjRelation("CONTEXT", xTextDoc);
158 tEnv.addObjRelation("WINPEER", the_win);
159 tEnv.addObjRelation("TOOLKIT", the_kit);
160 tEnv.addObjRelation("MODEL", the_Model);
162 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
163 aControl);
165 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
166 tEnv.addObjRelation("XWindow.ControlShape", aShape);
168 return tEnv;
169 } // finish method getTestEnvironment
170 } // finish class ONavigationBarControl