bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlDialogModel.java
blob7b34cde668451edd25dcb549aa32b619f494079a
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.XControlModel;
22 import com.sun.star.beans.XPropertySet;
23 import com.sun.star.container.XNameContainer;
24 import com.sun.star.lang.XMultiServiceFactory;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XInterface;
28 import java.io.PrintWriter;
30 import lib.StatusException;
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
35 import util.utils;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.awt.UnoControlDialogModel</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::awt::UnoControlDialogModel</code></li>
44 * <li> <code>com::sun::star::io::XPersistObject</code></li>
45 * <li> <code>com::sun::star::lang::XComponent</code></li>
46 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
47 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
48 * </ul>
49 * This object test <b> is NOT </b> designed to be run in several
50 * threads concurently.
51 * @see com.sun.star.awt.UnoControlDialogModel
52 * @see com.sun.star.io.XPersistObject
53 * @see com.sun.star.lang.XComponent
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.beans.XMultiPropertySet
56 * @see ifc.awt._UnoControlDialogModel
57 * @see ifc.io._XPersistObject
58 * @see ifc.lang._XComponent
59 * @see ifc.beans._XPropertySet
60 * @see ifc.beans._XMultiPropertySet
62 public class UnoControlDialogModel extends TestCase {
63 /**
64 * Creating a Testenvironment for the interfaces to be tested.
65 * Creates an instance of the service
66 * <code>com.sun.star.awt.UnoControlDialogModel</code>.
67 * Object relations created :
68 * <ul>
69 * <li> <code>'OBJNAME'</code> for
70 * {@link ifc.io._XPersistObject} </li>
71 * </ul>
73 @Override
74 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
75 PrintWriter log) {
76 XInterface oObj = null;
77 XInterface dialogModel = null;
78 String _buttonName = "MyButton";
79 String _labelName = "MyLabel";
80 String _labelPrefix = "MyLabelPrefix";
81 XMultiServiceFactory xMultiServiceFactory = null;
83 try {
84 dialogModel = (XInterface) Param.getMSF().createInstance(
85 "com.sun.star.awt.UnoControlDialogModel");
87 // create the dialog model and set the properties
88 XPropertySet xPSetDialog = UnoRuntime.queryInterface(
89 XPropertySet.class, dialogModel);
90 xPSetDialog.setPropertyValue("PositionX", Integer.valueOf(100));
91 xPSetDialog.setPropertyValue("PositionY", Integer.valueOf(100));
92 xPSetDialog.setPropertyValue("Width", Integer.valueOf(150));
93 xPSetDialog.setPropertyValue("Height", Integer.valueOf(100));
94 xPSetDialog.setPropertyValue("Title", "Runtime Dialog Demo");
96 // get the service manager from the dialog model
97 xMultiServiceFactory = UnoRuntime.queryInterface(
98 XMultiServiceFactory.class,
99 dialogModel);
101 // create the button model and set the properties
102 Object buttonModel = xMultiServiceFactory.createInstance(
103 "com.sun.star.awt.UnoControlButtonModel");
104 XPropertySet xPSetButton = UnoRuntime.queryInterface(
105 XPropertySet.class, buttonModel);
106 xPSetButton.setPropertyValue("PositionX", Integer.valueOf(50));
107 xPSetButton.setPropertyValue("PositionY", Integer.valueOf(30));
108 xPSetButton.setPropertyValue("Width", Integer.valueOf(50));
109 xPSetButton.setPropertyValue("Height", Integer.valueOf(14));
110 xPSetButton.setPropertyValue("Name", _buttonName);
111 xPSetButton.setPropertyValue("TabIndex", Short.valueOf((short) 0));
112 xPSetButton.setPropertyValue("Label", "Click Me");
114 // create the label model and set the properties
115 Object labelModel = xMultiServiceFactory.createInstance(
116 "com.sun.star.awt.UnoControlFixedTextModel");
117 XPropertySet xPSetLabel = UnoRuntime.queryInterface(
118 XPropertySet.class, labelModel);
119 xPSetLabel.setPropertyValue("PositionX", Integer.valueOf(40));
120 xPSetLabel.setPropertyValue("PositionY", Integer.valueOf(60));
121 xPSetLabel.setPropertyValue("Width", Integer.valueOf(100));
122 xPSetLabel.setPropertyValue("Height", Integer.valueOf(14));
123 xPSetLabel.setPropertyValue("Name", _labelName);
124 xPSetLabel.setPropertyValue("TabIndex", Short.valueOf((short) 1));
125 xPSetLabel.setPropertyValue("Label", _labelPrefix);
127 // insert the control models into the dialog model
128 XNameContainer xNameCont = UnoRuntime.queryInterface(
129 XNameContainer.class,
130 dialogModel);
131 xNameCont.insertByName(_buttonName, buttonModel);
132 xNameCont.insertByName(_labelName, labelModel);
134 // create the dialog control and set the model
135 XControl dialog = UnoRuntime.queryInterface(
136 XControl.class,
137 Param.getMSF().createInstance(
138 "com.sun.star.awt.UnoControlDialog"));
139 XControl xControl = UnoRuntime.queryInterface(
140 XControl.class, dialog);
141 XControlModel xControlModel = UnoRuntime.queryInterface(
142 XControlModel.class,
143 dialogModel);
144 xControl.setModel(xControlModel);
145 } catch (Exception e) {
146 throw new StatusException("Could no create test object", e);
149 oObj = dialogModel;
151 log.println("creating a new environment for object");
153 UnoRuntime.queryInterface(
154 XMultiServiceFactory.class, oObj);
156 TestEnvironment tEnv = new TestEnvironment(oObj);
158 try {
159 // XNameReplace
160 tEnv.addObjRelation("INSTANCE1",
161 xMultiServiceFactory.createInstance(
162 "com.sun.star.awt.UnoControlFixedTextModel"));
165 //XContainer
166 tEnv.addObjRelation("INSTANCE",
167 xMultiServiceFactory.createInstance(
168 "com.sun.star.awt.UnoControlFixedTextModel"));
169 } catch (com.sun.star.uno.Exception e) {
170 log.println("Could not add object relations 'INSTANCEn'");
171 e.printStackTrace(log);
174 tEnv.addObjRelation("OBJNAME", "stardiv.vcl.controlmodel.Dialog");
175 System.out.println("ImplementationName: " + utils.getImplName(oObj));
177 return tEnv;
178 } // finish method getTestEnvironment