1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sc;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 
33 import com.sun.star.container.XIndexAccess;
34 import com.sun.star.container.XNamed;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.uno.AnyConverter;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.sheet.TableAutoFormat</code>. <p>
44 * In StarCalc application there is a collection of autoformats
45 * for tables (you can select a predefined format for a
46 * table or create your own). This object represents
47 * one of these autoformats. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 *  <li> <code>com::sun::star::container::XNamed</code></li>
51 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
52 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
53 *  <li> <code>com::sun::star::sheet::TableAutoFormat</code></li>
54 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 * </ul>
56 * This object test <b> is NOT </b> designed to be run in several
57 * threads concurently.
58 * @see com.sun.star.container.XNamed
59 * @see com.sun.star.container.XIndexAccess
60 * @see com.sun.star.container.XElementAccess
61 * @see com.sun.star.sheet.TableAutoFormat
62 * @see com.sun.star.beans.XPropertySet
63 * @see ifc.container._XNamed
64 * @see ifc.container._XIndexAccess
65 * @see ifc.container._XElementAccess
66 * @see ifc.sheet._TableAutoFormat
67 * @see ifc.beans._XPropertySet
68 */
69 public class ScAutoFormatObj extends TestCase {
70 
71     /**
72     * Creating a Testenvironment for the interfaces to be tested.
73     * Using SOffice ServiceManager an instance of
74     * <code>com.sun.star.sheet.TableAutoFormatField</code> service
75     * is created. From this collection one Format is retrieved as
76     * object tested.
77     */
createTestEnvironment(TestParameters tParam, PrintWriter log)78     public TestEnvironment createTestEnvironment(TestParameters tParam,
79             PrintWriter log) {
80 
81         XInterface oObj = null;
82         XMultiServiceFactory oMSF = (XMultiServiceFactory)(XMultiServiceFactory)tParam.getMSF();
83         try {
84             XInterface formats = (XInterface)oMSF.createInstance
85                     ("com.sun.star.sheet.TableAutoFormats");
86             XIndexAccess formatsIndex = (XIndexAccess)
87                     UnoRuntime.queryInterface(XIndexAccess.class, formats);
88             oObj = (XInterface) AnyConverter.toObject(
89                     new Type(XInterface.class),formatsIndex.getByIndex
90                                             (formatsIndex.getCount() - 1));
91 
92             XNamed objNamed = (XNamed)
93                 UnoRuntime.queryInterface(XNamed.class, oObj) ;
94             log.println("AutoFormat name is '" + objNamed.getName() + "'") ;
95         } catch (com.sun.star.uno.Exception e) {
96             e.printStackTrace(log);
97             throw new StatusException("Unexpected exception", e);
98         }
99 
100         TestEnvironment tEnv = new TestEnvironment(oObj);
101 
102         return tEnv;
103     }
104 }
105 
106