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 .
20 import java
.io
.PrintWriter
;
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
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.util
.XCloseable
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.form.Forms</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::container::XNameReplace</code></li>
43 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
44 * <li> <code>com::sun::star::container::XNameContainer</code></li>
45 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
46 * <li> <code>com::sun::star::container::XElementAccess</code></li>
47 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
48 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
49 * <li> <code>com::sun::star::container::XNameAccess</code></li>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
55 * @see com.sun.star.container.XNameReplace
56 * @see com.sun.star.container.XIndexReplace
57 * @see com.sun.star.container.XNameContainer
58 * @see com.sun.star.container.XIndexAccess
59 * @see com.sun.star.container.XElementAccess
60 * @see com.sun.star.container.XEnumerationAccess
61 * @see com.sun.star.container.XIndexContainer
62 * @see com.sun.star.container.XNameAccess
63 * @see ifc.container._XNameReplace
64 * @see ifc.container._XIndexReplace
65 * @see ifc.container._XNameContainer
66 * @see ifc.container._XIndexAccess
67 * @see ifc.container._XElementAccess
68 * @see ifc.container._XEnumerationAccess
69 * @see ifc.container._XIndexContainer
70 * @see ifc.container._XNameAccess
72 public class OFormsCollection
extends TestCase
{
76 * Creates Drawing document.
78 protected void initialize(TestParameters tParam
, PrintWriter log
) {
79 log
.println("creating a draw document");
80 xDrawDoc
= DrawTools
.createDrawDoc(((XMultiServiceFactory
) tParam
.getMSF()));
84 * Disposes drawing document.
86 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
87 log
.println(" disposing xDrawDoc ");
90 XCloseable closer
= UnoRuntime
.queryInterface(
91 XCloseable
.class, xDrawDoc
);
93 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
94 log
.println("couldn't close document");
95 } catch (com
.sun
.star
.lang
.DisposedException e
) {
96 log
.println("couldn't close document");
101 * Adds some controls to the 'Standard' form of a draw page,
102 * then adds an empty form to a collection of forms. Then
103 * returns the collection as a test object. <p>
104 * Object relations created :
106 * <li> <code>'INSTANCE1' ... 'INSTANCEN'</code> for
107 * <code>XNameReplace, XNameContainer, XIndexReplace,
108 * XIndexContainer </code> : objects to be inserted
109 * or replaced with in interface tests. Number of relations
110 * depends on number of interface test threads. For each
111 * thread there must be an individual element. </li>
112 * <li> <code>'XNameContainer.AllowDuplicateNames'</code> :
113 * if this relation exists then container elements can have duplicate
114 * names. In case of forms' collection forms can have equal names.</li>
117 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
119 XInterface oObj
= null;
120 XDrawPage oDP
= null;
123 // creation of testobject here
124 // first we write what we are intend to do to log file
125 log
.println("creating a test environment");
127 oDP
= DrawTools
.getDrawPage(xDrawDoc
, 0);
129 (DrawTools
.getShapes(oDP
))
130 .add(FormTools
.createControlShape(xDrawDoc
, 2000, 1500, 1000, 1000,
132 (DrawTools
.getShapes(oDP
))
133 .add(FormTools
.createControlShape(xDrawDoc
, 3000, 4500, 15000,
134 1000, "CommandButton"));
135 (DrawTools
.getShapes(oDP
))
136 .add(FormTools
.createControlShape(xDrawDoc
, 5000, 3500, 7500, 5000,
139 oObj
= FormTools
.getForms(oDP
);
140 FormTools
.insertForm(xDrawDoc
, (XNameContainer
) oObj
, "SecondForm");
142 log
.println("creating a new environment for drawpage object");
144 TestEnvironment tEnv
= new TestEnvironment(oObj
);
147 // INSTANCEn : _XNameContainer; _XNameReplace
148 log
.println("adding INSTANCEn as obj relation to environment");
150 XComponent xComp
= UnoRuntime
.queryInterface(
151 XComponent
.class, xDrawDoc
);
153 if (Param
.get("THRCNT")!= null) {
154 THRCNT
= Integer
.parseInt((String
) Param
.get("THRCNT"));
157 for (int n
= 1; n
< (THRCNT
+ 1); n
++) {
158 log
.println("adding INSTANCE" + n
+
159 " as obj relation to environment");
160 tEnv
.addObjRelation("INSTANCE" + n
,
161 FormTools
.createControl(xComp
, "Form"));
165 // adding indicator that this collection can have duplicate
166 // elements with the same names for XNameContainer test.
167 tEnv
.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
169 tEnv
.addObjRelation("INSTANCE", FormTools
.createControl(xComp
, "Form"));
170 tEnv
.addObjRelation("INSTANCE2",
171 FormTools
.createControl(xComp
, "Form"));
174 } // finish method getTestEnvironment
175 } // finish class OFormsCollection