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