bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / TabController.java
blobb7029193df791091bed0bdddfbc02c7a011ca515
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.XControl;
21 import com.sun.star.awt.XControlContainer;
22 import com.sun.star.awt.XControlModel;
23 import com.sun.star.awt.XTabControllerModel;
24 import com.sun.star.drawing.XControlShape;
25 import com.sun.star.form.XForm;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.text.XTextDocument;
28 import com.sun.star.uno.AnyConverter;
29 import com.sun.star.uno.Type;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
32 import com.sun.star.view.XControlAccess;
34 import java.io.PrintWriter;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
41 import util.FormTools;
42 import util.WriterTools;
43 import util.utils;
46 public class TabController extends TestCase {
47 private static XTextDocument xTextDoc = null;
49 protected void initialize(TestParameters param, PrintWriter log) {
50 try {
51 log.println("creating a textdocument");
52 xTextDoc = WriterTools.createTextDoc(
53 (XMultiServiceFactory) param.getMSF());
54 } catch (Exception e) {
55 // Some exception occurs.FAILED
56 e.printStackTrace(log);
57 throw new StatusException("Couldn't create document", e);
61 protected void cleanup(TestParameters param, PrintWriter log) {
62 log.println("disposing xTextDoc");
63 util.DesktopTools.closeDoc(xTextDoc);
66 public TestEnvironment createTestEnvironment(TestParameters param,
67 PrintWriter log) {
68 XInterface oObj = null;
69 XControl xCtrl1 = null;
70 XTabControllerModel tabCtrlModel = null;
71 XControlContainer aCtrlContainer = null;
74 // create object relations
75 FormTools.insertForm(xTextDoc,
76 FormTools.getForms(WriterTools.getDrawPage(
77 xTextDoc)), "MyForm");
79 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
80 4500, 15000,
81 10000,
82 "CommandButton",
83 "UnoControlButton");
84 WriterTools.getDrawPage(xTextDoc).add(aShape);
86 XControlModel model = aShape.getControl();
87 XControlAccess access = UnoRuntime.queryInterface(
88 XControlAccess.class,
89 xTextDoc.getCurrentController());
91 try {
92 xCtrl1 = access.getControl(model);
93 } catch (Exception e) {
96 XForm form = null;
98 try {
99 form = (XForm) AnyConverter.toObject(new Type(XForm.class),
100 (FormTools.getForms(
101 WriterTools.getDrawPage(
102 xTextDoc)))
103 .getByName("MyForm"));
104 } catch (Exception e) {
105 log.println("Couldn't get Form");
106 e.printStackTrace(log);
109 tabCtrlModel = UnoRuntime.queryInterface(
110 XTabControllerModel.class, form);
112 aCtrlContainer = UnoRuntime.queryInterface(
113 XControlContainer.class, xCtrl1.getContext());
115 // create object
116 try {
117 oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance(
118 "com.sun.star.awt.TabController");
119 } catch (Exception e) {
122 TestEnvironment tEnv = new TestEnvironment(oObj);
124 String objName = "TabController";
125 tEnv.addObjRelation("OBJNAME", "toolkit." + objName);
126 tEnv.addObjRelation("MODEL", tabCtrlModel);
127 tEnv.addObjRelation("CONTAINER", aCtrlContainer);
128 System.out.println("ImplementationName: " + utils.getImplName(oObj));
130 return tEnv;