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