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._sd;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.drawing.XDrawPages;
35 import com.sun.star.drawing.XMasterPagesSupplier;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.lang.XMultiServiceFactory;
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.drawing.MasterPages</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
47 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
48 *  <li> <code>com::sun::star::drawing::XDrawPages</code></li>
49 * </ul>
50 * @see com.sun.star.drawing.MasterPages
51 * @see com.sun.star.container.XIndexAccess
52 * @see com.sun.star.container.XElementAccess
53 * @see com.sun.star.drawing.XDrawPages
54 * @see ifc.container._XIndexAccess
55 * @see ifc.container._XElementAccess
56 * @see ifc.drawing._XDrawPages
57 */
58 public class SdMasterPagesAccess extends TestCase {
59     XComponent xDrawDoc;
60 
61     /**
62     * Creates Drawing document.
63     */
initialize(TestParameters Param, PrintWriter log)64     protected void initialize(TestParameters Param, PrintWriter log) {
65         // get a soffice factory object
66         SOfficeFactory SOF = SOfficeFactory.getFactory(
67                                     (XMultiServiceFactory)Param.getMSF());
68 
69         try {
70             log.println( "creating a draw document" );
71             xDrawDoc = SOF.createDrawDoc(null);
72          } catch (com.sun.star.uno.Exception e) {
73             // Some exception occures.FAILED
74             e.printStackTrace( log );
75             throw new StatusException( "Couldn't create document", e );
76          }
77     }
78 
79     /**
80     * Disposes Drawing document.
81     */
cleanup( TestParameters Param, PrintWriter log)82     protected void cleanup( TestParameters Param, PrintWriter log) {
83         log.println("disposing xDrawDoc");
84         util.DesktopTools.closeDoc(xDrawDoc);
85     }
86 
87     /**
88     * Creating a Testenvironment for the interfaces to be tested.
89     * Retrieves the collection of the master pages from the document using the
90     * interface <code>XMasterPagesSupplier</code>. Inserts two new draw pages.
91     * The retrieved collection is the instance of the service
92     * <code>com.sun.star.drawing.MasterPages</code>.
93     * @see com.sun.star.drawing.XMasterPagesSupplier
94     * @see com.sun.star.drawing.MasterPages
95     */
createTestEnvironment( TestParameters Param, PrintWriter log)96     public synchronized TestEnvironment createTestEnvironment(
97         TestParameters Param, PrintWriter log) throws StatusException {
98 
99         log.println( "creating a test environment" );
100 
101         // get the MasterPages here
102         log.println( "getting MasterPages" );
103         XMasterPagesSupplier oMPS = (XMasterPagesSupplier)
104             UnoRuntime.queryInterface( XMasterPagesSupplier.class, xDrawDoc);
105         XDrawPages oMP = oMPS.getMasterPages();
106         log.println( "insert MasterPages" );
107         oMP.insertNewByIndex(1);
108         oMP.insertNewByIndex(2);
109         XInterface oObj = oMP;
110 
111         log.println( "creating a new environment for MasterPagesAccess object" );
112         TestEnvironment tEnv = new TestEnvironment( oObj );
113 
114         return tEnv;
115     } // finish method createTestEnvironment
116 
117 }    // finish class SdMasterPagesAccess
118 
119