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.XDrawPagesSupplier;
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.DrawPages</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 *  <li> <code>com::sun::star::drawing::XDrawPageExpander</code></li>
47 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
48 *  <li> <code>com::sun::star::drawing::XDrawPageSummarizer</code></li>
49 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
50 *  <li> <code>com::sun::star::drawing::XDrawPages</code></li>
51 * </ul>
52 * @see com.sun.star.drawing.DrawPages
53 * @see com.sun.star.drawing.XDrawPageExpander
54 * @see com.sun.star.container.XIndexAccess
55 * @see com.sun.star.drawing.XDrawPageSummarizer
56 * @see com.sun.star.container.XElementAccess
57 * @see com.sun.star.drawing.XDrawPages
58 * @see ifc.drawing._XDrawPageExpander
59 * @see ifc.container._XIndexAccess
60 * @see ifc.drawing._XDrawPageSummarizer
61 * @see ifc.container._XElementAccess
62 * @see ifc.drawing._XDrawPages
63 */
64 public class SdDrawPagesAccess extends TestCase {
65     XComponent xDrawDoc;
66 
67     /**
68     * Creates Drawing document.
69     */
70     protected void initialize(TestParameters Param, PrintWriter log) {
71         // get a soffice factory object
72         SOfficeFactory SOF = SOfficeFactory.getFactory(
73                                     (XMultiServiceFactory)Param.getMSF());
74 
75         try {
76             log.println( "creating a draw document" );
77             xDrawDoc = SOF.createDrawDoc(null);
78         } catch (com.sun.star.uno.Exception e) {
79             // Some exception occures.FAILED
80             e.printStackTrace(log);
81             throw new StatusException("Couldn't create document", e);
82         }
83     }
84 
85     /**
86     * Disposes Drawing document.
87     */
88     protected void cleanup( TestParameters Param, PrintWriter log) {
89         log.println("disposing xDrawDoc");
90         util.DesktopTools.closeDoc(xDrawDoc);;
91     }
92 
93     /**
94     * Creating a Testenvironment for the interfaces to be tested.
95     * Retrieves the collection of the draw pages from the drawing document using
96     * the interface <code>XDrawPagesSupplier</code>. Inserts two new draw pages.
97     * The retrieved collection is the instance of the service
98     * <code>com.sun.star.drawing.DrawPages</code>.
99     * @see com.sun.star.drawing.DrawPages
100     */
101     public synchronized TestEnvironment createTestEnvironment(
102         TestParameters Param, PrintWriter log) throws StatusException {
103 
104         // creation of testobject here
105         // first we write what we are intend to do to log file
106         log.println( "creating a test environment" );
107 
108         // get the drawpage of drawing here
109         log.println( "getting Drawpages" );
110         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
111             UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
112         XDrawPages oDP = (XDrawPages) oDPS.getDrawPages();
113         oDP.insertNewByIndex(1);
114         oDP.insertNewByIndex(2);
115         XInterface oObj = oDP;
116 
117         log.println( "creating a new environment for drawpage object" );
118         TestEnvironment tEnv = new TestEnvironment( oObj );
119 
120         return tEnv;
121     } // finish method createTestEnvironment
122 
123 
124 }    // finish class SdDrawPagesAccess
125 
126