bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OFormsCollection.java
blob14f7d6c531e366ddd50b5d9451ce401083ab0fa7
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.TestCase;
23 import lib.TestEnvironment;
24 import lib.TestParameters;
25 import util.DrawTools;
26 import util.FormTools;
28 import com.sun.star.container.XNameContainer;
29 import com.sun.star.drawing.XDrawPage;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import com.sun.star.util.XCloseable;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.form.Forms</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li> <code>com::sun::star::container::XNameReplace</code></li>
42 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
43 * <li> <code>com::sun::star::container::XNameContainer</code></li>
44 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
45 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
47 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
48 * <li> <code>com::sun::star::container::XNameAccess</code></li>
49 * </ul>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurently.
54 * @see com.sun.star.container.XNameReplace
55 * @see com.sun.star.container.XIndexReplace
56 * @see com.sun.star.container.XNameContainer
57 * @see com.sun.star.container.XIndexAccess
58 * @see com.sun.star.container.XElementAccess
59 * @see com.sun.star.container.XEnumerationAccess
60 * @see com.sun.star.container.XIndexContainer
61 * @see com.sun.star.container.XNameAccess
62 * @see ifc.container._XNameReplace
63 * @see ifc.container._XIndexReplace
64 * @see ifc.container._XNameContainer
65 * @see ifc.container._XIndexAccess
66 * @see ifc.container._XElementAccess
67 * @see ifc.container._XEnumerationAccess
68 * @see ifc.container._XIndexContainer
69 * @see ifc.container._XNameAccess
71 public class OFormsCollection extends TestCase {
72 XComponent xDrawDoc;
74 /**
75 * Creates Drawing document.
77 @Override
78 protected void initialize(TestParameters tParam, PrintWriter log) {
79 log.println("creating a draw document");
80 xDrawDoc = DrawTools.createDrawDoc((tParam.getMSF()));
83 /**
84 * Disposes drawing document.
86 @Override
87 protected void cleanup(TestParameters tParam, PrintWriter log) {
88 log.println(" disposing xDrawDoc ");
90 try {
91 XCloseable closer = UnoRuntime.queryInterface(
92 XCloseable.class, xDrawDoc);
93 closer.close(true);
94 } catch (com.sun.star.util.CloseVetoException e) {
95 log.println("couldn't close document");
96 } catch (com.sun.star.lang.DisposedException e) {
97 log.println("couldn't close document");
102 * Adds some controls to the 'Standard' form of a draw page,
103 * then adds an empty form to a collection of forms. Then
104 * returns the collection as a test object. <p>
105 * Object relations created :
106 * <ul>
107 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for
108 * <code>XNameReplace, XNameContainer, XIndexReplace,
109 * XIndexContainer </code> : objects to be inserted
110 * or replaced with in interface tests. Number of relations
111 * depends on number of interface test threads. For each
112 * thread there must be an individual element. </li>
113 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> :
114 * if this relation exists then container elements can have duplicate
115 * names. In case of forms' collection forms can have equal names.</li>
116 * </ul>
118 @Override
119 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
120 PrintWriter log) {
121 XInterface oObj = null;
122 XDrawPage oDP = null;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log.println("creating a test environment");
129 oDP = DrawTools.getDrawPage(xDrawDoc, 0);
131 (DrawTools.getShapes(oDP))
132 .add(FormTools.createControlShape(xDrawDoc, 2000, 1500, 1000, 1000,
133 "CheckBox"));
134 (DrawTools.getShapes(oDP))
135 .add(FormTools.createControlShape(xDrawDoc, 3000, 4500, 15000,
136 1000, "CommandButton"));
137 (DrawTools.getShapes(oDP))
138 .add(FormTools.createControlShape(xDrawDoc, 5000, 3500, 7500, 5000,
139 "TextField"));
141 oObj = FormTools.getForms(oDP);
142 FormTools.insertForm(xDrawDoc, (XNameContainer) oObj, "SecondForm");
144 log.println("creating a new environment for drawpage object");
146 TestEnvironment tEnv = new TestEnvironment(oObj);
149 // INSTANCEn : _XNameContainer; _XNameReplace
150 log.println("adding INSTANCEn as obj relation to environment");
152 XComponent xComp = UnoRuntime.queryInterface(
153 XComponent.class, xDrawDoc);
154 int THRCNT = 1;
155 if (Param.get("THRCNT")!= null) {
156 THRCNT = Integer.parseInt((String) Param.get("THRCNT"));
159 for (int n = 1; n < (THRCNT + 1); n++) {
160 log.println("adding INSTANCE" + n +
161 " as obj relation to environment");
162 tEnv.addObjRelation("INSTANCE" + n,
163 FormTools.createControl(xComp, "Form"));
167 // adding indicator that this collection can have duplicate
168 // elements with the same names for XNameContainer test.
169 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
171 tEnv.addObjRelation("INSTANCE", FormTools.createControl(xComp, "Form"));
172 tEnv.addObjRelation("INSTANCE2",
173 FormTools.createControl(xComp, "Form"));
175 return tEnv;
176 } // finish method getTestEnvironment
177 } // finish class OFormsCollection