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