xref: /AOO41X/main/qadevOOo/tests/java/ifc/drawing/_XDrawView.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 ifc.drawing;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XDrawPages;
34 import com.sun.star.drawing.XDrawView;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 
38 /**
39 * Testing <code>com.sun.star.drawing.XDrawView</code>
40 * interface methods :
41 * <ul>
42 *  <li><code> setCurrentPage()</code></li>
43 *  <li><code> getCurrentPage()</code></li>
44 * </ul> <p>
45 * This test needs the following object relations :
46 * <ul>
47 *  <li> <code>'Pages'</code> (of type <code>XDrawPages</code>):
48 *   needed to have the access to pages collection.</li>
49 * <ul> <p>
50 * Test is <b> NOT </b> multithread compilant. <p>
51 * @see com.sun.star.drawing.XDrawView
52 */
53 public class _XDrawView extends MultiMethodTest {
54 
55     public XDrawView oObj = null;
56     public XDrawPage the_page = null;
57 
58     /**
59      * This methods gets the current DrawPage.<p>
60      * Has <b> OK </b> status if the returned DrawPage
61      * isn't empty.
62      */
63     public void _getCurrentPage(){
64         the_page = oObj.getCurrentPage();
65         tRes.tested("getCurrentPage()",the_page != null);
66     } // end getCurrentPage
67 
68     /**
69      * This methods sets the current DrawPage<br>
70      * First a new DrawPage is inserted in the document.
71      * Then this DrawPage is set as current Page.
72      * Has <b> OK </b> status if the getCurrentPage() method returns
73      * the DrawPage that was previously set.
74      * @see ifc.drawing._XDrawPages
75      * The following method tests are to be completed successfully before :
76      * <ul>
77      *  <li> <code> getCurrentPage() </code> </li>
78      * </ul>
79      */
80     public void _setCurrentPage(){
81         requiredMethod("getCurrentPage()");
82         try {
83             XDrawPages the_pages = (XDrawPages) tEnv.getObjRelation("Pages");
84             the_pages.insertNewByIndex(0);
85             XDrawPage newPage = (XDrawPage) AnyConverter.toObject(
86                             new Type(XDrawPage.class),the_pages.getByIndex(1));
87             oObj.setCurrentPage(newPage);
88             XDrawPage getting = oObj.getCurrentPage();
89             boolean eq = newPage.equals(getting);
90             if (!eq) {
91                 log.println("Getting: "+getting.hasElements());
92                 log.println("Expected: "+newPage.hasElements());
93             }
94             //back to the previous page
95             oObj.setCurrentPage(the_page);
96             tRes.tested("setCurrentPage()",eq);
97         } catch (com.sun.star.lang.WrappedTargetException ex) {
98             log.println("Exception occured while checking 'setCurrentPage()'");
99             ex.printStackTrace(log);
100             tRes.tested("setCurrentPage()",false);
101         } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
102             log.println("Exception occured while checking 'setCurrentPage()'");
103             ex.printStackTrace(log);
104             tRes.tested("setCurrentPage()",false);
105         } catch (com.sun.star.lang.IllegalArgumentException ex) {
106             log.println("Exception occured while checking 'setCurrentPage()'");
107             ex.printStackTrace(log);
108             tRes.tested("setCurrentPage()",false);
109         }
110     } // end setCurrentPage
111 
112 } // end DrawView
113 
114