Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ONavigationBarControl.java
blob837fb706caef00681a7b3c111f52fe0e87ad7567
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.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.view.XControlAccess;
42 import util.DesktopTools;
44 public class ONavigationBarControl extends TestCase {
45 XTextDocument xTextDoc;
47 /**
48 * Creates a text document.
50 @Override
51 protected void initialize(TestParameters Param, PrintWriter log) {
52 SOfficeFactory SOF = SOfficeFactory.getFactory(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 @Override
68 protected void cleanup(TestParameters tParam, PrintWriter log) {
69 log.println(" disposing xTextDoc ");
71 DesktopTools.closeDoc(xTextDoc);
74 /**
75 * Creates two components and inserts them to the form of
76 * text document. One component
77 * (<code>com.sun.star.form.component.CommandButton</code>) is created
78 * for testing, another to be passed as relation. Using a controller
79 * of the text document the controller of the first component is
80 * obtained and returned in environment as a test object. <p>
82 * Object relations created :
83 * <ul>
84 * <li> <code>'GRAPHICS'</code> for
85 * {@link ifc.awt._XView} : a graphics component
86 * created using screen device of the window peer of
87 * the controller tested. </li>
88 * <li> <code>'CONTEXT'</code> for
89 * {@link ifc.awt._XControl} : the text document
90 * where the component is inserted. </li>
91 * <li> <code>'WINPEER'</code> for
92 * {@link ifc.awt._XControl} : Window peer of the
93 * controller tested. </li>
94 * <li> <code>'TOOLKIT'</code> for
95 * {@link ifc.awt._XControl} : toolkit of the component.</li>
96 * <li> <code>'MODEL'</code> for
97 * {@link ifc.awt._XControl} : the model of the controller.</li>
98 * <li> <code>'XWindow.AnotherWindow'</code> for
99 * {@link ifc.awt._XWindow} : the controller of another
100 * component. </li>
101 * </ul>
103 @Override
104 protected TestEnvironment createTestEnvironment(TestParameters Param,
105 PrintWriter log) {
106 XInterface oObj = null;
107 XWindowPeer the_win = null;
108 XToolkit the_kit = null;
109 XDevice aDevice = null;
110 XGraphics aGraphic = null;
111 XControl aControl = null;
113 //Insert a ControlShape and get the ControlModel
114 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
115 4500, 15000, 10000,
116 "NavigationToolBar");
118 WriterTools.getDrawPage(xTextDoc).add(aShape);
120 XControlModel the_Model = aShape.getControl();
122 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
123 4500, 5000, 10000,
124 "TextField");
126 WriterTools.getDrawPage(xTextDoc).add(aShape2);
128 XControlModel the_Model2 = aShape2.getControl();
130 //Try to query XControlAccess
131 XControlAccess the_access = UnoRuntime.queryInterface(
132 XControlAccess.class,
133 xTextDoc.getCurrentController());
135 //now get the OButtonControl
136 try {
137 oObj = the_access.getControl(the_Model);
138 aControl = the_access.getControl(the_Model2);
139 the_win = the_access.getControl(the_Model).getPeer();
140 the_kit = the_win.getToolkit();
141 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
142 aGraphic = aDevice.createGraphics();
143 } catch (com.sun.star.container.NoSuchElementException e) {
144 log.println("Couldn't get ONavigationBarControl");
145 e.printStackTrace(log);
146 throw new StatusException("Couldn't get ONavigationBarControl", e);
149 log.println("creating a new environment for ONavigationBarControl object");
151 TestEnvironment tEnv = new TestEnvironment(oObj);
154 //Adding ObjRelation for XView
155 tEnv.addObjRelation("GRAPHICS", aGraphic);
158 //Adding ObjRelation for XControl
159 tEnv.addObjRelation("CONTEXT", xTextDoc);
160 tEnv.addObjRelation("WINPEER", the_win);
161 tEnv.addObjRelation("TOOLKIT", the_kit);
162 tEnv.addObjRelation("MODEL", the_Model);
164 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
165 aControl);
167 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
168 tEnv.addObjRelation("XWindow.ControlShape", aShape);
170 return tEnv;
171 } // finish method getTestEnvironment
172 } // finish class ONavigationBarControl