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
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
33 import com
.sun
.star
.util
.XCloseable
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.form.Forms</code>. <p>
39 * Object implements the following interfaces :
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>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurrently.
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
{
75 * Creates Drawing document.
78 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
79 log
.println("creating a draw document");
80 xDrawDoc
= DrawTools
.createDrawDoc(tParam
.getMSF());
84 * Disposes drawing document.
87 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
88 log
.println(" disposing xDrawDoc ");
91 XCloseable closer
= UnoRuntime
.queryInterface(
92 XCloseable
.class, xDrawDoc
);
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 :
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>
119 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
121 throws com
.sun
.star
.uno
.Exception
123 XInterface oObj
= null;
124 XDrawPage oDP
= null;
127 // creation of testobject here
128 // first we write what we are intend to do to log file
129 log
.println("creating a test environment");
131 oDP
= DrawTools
.getDrawPage(xDrawDoc
, 0);
133 (DrawTools
.getShapes(oDP
))
134 .add(FormTools
.createControlShape(xDrawDoc
, 2000, 1500, 1000, 1000,
136 (DrawTools
.getShapes(oDP
))
137 .add(FormTools
.createControlShape(xDrawDoc
, 3000, 4500, 15000,
138 1000, "CommandButton"));
139 (DrawTools
.getShapes(oDP
))
140 .add(FormTools
.createControlShape(xDrawDoc
, 5000, 3500, 7500, 5000,
143 oObj
= FormTools
.getForms(oDP
);
144 FormTools
.insertForm(xDrawDoc
, (XNameContainer
) oObj
, "SecondForm");
146 log
.println("creating a new environment for drawpage object");
148 TestEnvironment tEnv
= new TestEnvironment(oObj
);
151 // INSTANCEn : _XNameContainer; _XNameReplace
152 log
.println("adding INSTANCEn as obj relation to environment");
154 XComponent xComp
= UnoRuntime
.queryInterface(
155 XComponent
.class, xDrawDoc
);
157 if (Param
.get("THRCNT")!= null) {
158 THRCNT
= Integer
.parseInt((String
) Param
.get("THRCNT"));
161 for (int n
= 1; n
< (THRCNT
+ 1); n
++) {
162 log
.println("adding INSTANCE" + n
+
163 " as obj relation to environment");
164 tEnv
.addObjRelation("INSTANCE" + n
,
165 FormTools
.createControl(xComp
, "Form"));
169 // adding indicator that this collection can have duplicate
170 // elements with the same names for XNameContainer test.
171 tEnv
.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
173 tEnv
.addObjRelation("INSTANCE", FormTools
.createControl(xComp
, "Form"));
174 tEnv
.addObjRelation("INSTANCE2",
175 FormTools
.createControl(xComp
, "Form"));
178 } // finish method getTestEnvironment
179 } // finish class OFormsCollection