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
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.lang
.XComponent
;
29 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
30 import com
.sun
.star
.uno
.AnyConverter
;
31 import com
.sun
.star
.uno
.Type
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.TableAutoFormats</code>. <p>
38 * In StarCalc application there is a collection of autoformats
39 * for tables (you can select a predefined format for a
40 * table or create your own). The object represents
41 * this collection. <p>
42 * Object implements the following interfaces :
44 * <li> <code>com::sun::star::container::XNameAccess</code></li>
45 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * <li> <code>com::sun::star::container::XNameReplace</code></li>
47 * <li> <code>com::sun::star::container::XNameContainer</code></li>
49 * This object test <b> is NOT </b> designed to be run in several
50 * threads concurently.
51 * @see com.sun.star.container.XNameAccess
52 * @see com.sun.star.container.XElementAccess
53 * @see com.sun.star.container.XNameReplace
54 * @see com.sun.star.container.XNameContainer
55 * @see ifc.container._XNameAccess
56 * @see ifc.container._XElementAccess
57 * @see ifc.container._XNameReplace
58 * @see ifc.container._XNameContainer
60 public class ScAutoFormatsObj
extends TestCase
{
61 private XSpreadsheetDocument xSheetDoc
= null;
62 static SOfficeFactory SOF
= null;
65 * Creates Spreadsheet document.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
69 SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
72 log
.println( "creating a Spreadsheet document" );
73 xSheetDoc
= SOF
.createCalcDoc(null);
74 } catch ( com
.sun
.star
.uno
.Exception e
) {
75 // Some exception occurs.FAILED
76 e
.printStackTrace( log
);
77 throw new StatusException( "Couldn't create document", e
);
82 * Disposes Spreadsheet document.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xSheetDoc " );
87 XComponent oComp
= UnoRuntime
.queryInterface
88 (XComponent
.class, xSheetDoc
) ;
89 util
.DesktopTools
.closeDoc(oComp
);
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.sheet.TableAutoFormats</code>.
97 * Object relations created :
99 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
100 * {@link ifc.container._XNameContainer},
101 * {@link ifc.container._XNameReplace} N relations
102 * which represents objects to be inserted - one
103 * object for each interface thread. </li>
107 public synchronized TestEnvironment createTestEnvironment
108 (TestParameters Param
, PrintWriter log
)
109 throws StatusException
{
111 XInterface oObj
= null;
114 // creation of testobject here
116 XComponent xComp
= UnoRuntime
.queryInterface
117 (XComponent
.class, xSheetDoc
);
118 oObj
= (XInterface
) AnyConverter
.toObject(
119 new Type(XInterface
.class),Param
.getMSF().createInstance
120 ("com.sun.star.sheet.TableAutoFormats"));
121 Object secondInstance
= SOF
.createInstance
122 (xComp
, "com.sun.star.sheet.TableAutoFormat");
124 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;
126 //adding ObjRelation for XNameContainer
127 tEnv
.addObjRelation("SecondInstance",secondInstance
);
129 // INSTANCEn : _XNameContainer; _XNameReplace
130 log
.println( "adding INSTANCEn as mod relation to environment" );
132 if ((String
)Param
.get("THRCNT") != null) {
133 Integer
.parseInt((String
)Param
.get("THRCNT"));
135 for (int n
= 1; n
< (THRCNT
+1) ;n
++ ) {
136 log
.println( "adding INSTANCE" + n
137 +" as mod relation to environment" );
138 tEnv
.addObjRelation("INSTANCE" + n
, SOF
.createInstance(xComp
,
139 "com.sun.star.sheet.TableAutoFormat"));
143 } catch (com
.sun
.star
.uno
.Exception e
) {
144 log
.println ("Exception occurred while creating test Object.");
145 e
.printStackTrace(log
);
146 throw new StatusException("Couldn't create test object", e
);
150 } // finish class ScAutoFormatsObj