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