1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sd;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.drawing.XDrawPages;
39 import com.sun.star.drawing.XDrawPagesSupplier;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.drawing.DrawPages</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 *  <li> <code>com::sun::star::drawing::XDrawPageExpander</code></li>
51 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
52 *  <li> <code>com::sun::star::drawing::XDrawPageSummarizer</code></li>
53 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
54 *  <li> <code>com::sun::star::drawing::XDrawPages</code></li>
55 * </ul>
56 * @see com.sun.star.drawing.DrawPages
57 * @see com.sun.star.drawing.XDrawPageExpander
58 * @see com.sun.star.container.XIndexAccess
59 * @see com.sun.star.drawing.XDrawPageSummarizer
60 * @see com.sun.star.container.XElementAccess
61 * @see com.sun.star.drawing.XDrawPages
62 * @see ifc.drawing._XDrawPageExpander
63 * @see ifc.container._XIndexAccess
64 * @see ifc.drawing._XDrawPageSummarizer
65 * @see ifc.container._XElementAccess
66 * @see ifc.drawing._XDrawPages
67 */
68 public class SdDrawPagesAccess extends TestCase {
69     XComponent xDrawDoc;
70 
71     /**
72     * Creates Drawing document.
73     */
74     protected void initialize(TestParameters Param, PrintWriter log) {
75         // get a soffice factory object
76         SOfficeFactory SOF = SOfficeFactory.getFactory(
77                                     (XMultiServiceFactory)Param.getMSF());
78 
79         try {
80             log.println( "creating a draw document" );
81             xDrawDoc = SOF.createDrawDoc(null);
82         } catch (com.sun.star.uno.Exception e) {
83             // Some exception occures.FAILED
84             e.printStackTrace(log);
85             throw new StatusException("Couldn't create document", e);
86         }
87     }
88 
89     /**
90     * Disposes Drawing document.
91     */
92     protected void cleanup( TestParameters Param, PrintWriter log) {
93         log.println("disposing xDrawDoc");
94         util.DesktopTools.closeDoc(xDrawDoc);;
95     }
96 
97     /**
98     * Creating a Testenvironment for the interfaces to be tested.
99     * Retrieves the collection of the draw pages from the drawing document using
100     * the interface <code>XDrawPagesSupplier</code>. Inserts two new draw pages.
101     * The retrieved collection is the instance of the service
102     * <code>com.sun.star.drawing.DrawPages</code>.
103     * @see com.sun.star.drawing.DrawPages
104     */
105     public synchronized TestEnvironment createTestEnvironment(
106         TestParameters Param, PrintWriter log) throws StatusException {
107 
108         // creation of testobject here
109         // first we write what we are intend to do to log file
110         log.println( "creating a test environment" );
111 
112         // get the drawpage of drawing here
113         log.println( "getting Drawpages" );
114         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
115             UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
116         XDrawPages oDP = (XDrawPages) oDPS.getDrawPages();
117         oDP.insertNewByIndex(1);
118         oDP.insertNewByIndex(2);
119         XInterface oObj = oDP;
120 
121         log.println( "creating a new environment for drawpage object" );
122         TestEnvironment tEnv = new TestEnvironment( oObj );
123 
124         return tEnv;
125     } // finish method createTestEnvironment
126 
127 
128 }    // finish class SdDrawPagesAccess
129 
130