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.MultiPropertyTest;
27 
28 import com.sun.star.container.XNamed;
29 import com.sun.star.drawing.XDrawPage;
30 import com.sun.star.uno.UnoRuntime;
31 import util.ValueChanger;
32 
33 /**
34 * Testing <code>com.sun.star.drawing.DrawingDocumentDrawView</code>
35 * service properties :
36 * <ul>
37 *  <li><code> IsMasterPageMode</code></li>
38 *  <li><code> IsLayerMode</code></li>
39 * </ul> <p>
40 * This test needs the following object relations :
41 * <ul>
42 *  <li> <code>'DrawPage'</code> (of type <code>XDrawPage</code>):
43 *   a draw page which will be current page. </li>
44 * <ul> <p>
45 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
46 * @see com.sun.star.drawing.DrawingDocumentDrawView
47 */
48 public class _DrawingDocumentDrawView extends MultiPropertyTest {
49 
50     XDrawPage drawPage = null;
51     static String test_name = "For DrawingDocumentDrawView";
52 
before()53     protected void before() {
54         drawPage = (XDrawPage)tEnv.getObjRelation("DrawPage");
55         XNamed xNamed = (XNamed)
56             UnoRuntime.queryInterface(XNamed.class, drawPage);
57         xNamed.setName(test_name);
58     }
59 
60     /**
61     * Property tester which returns new <code>XDrawPage</code> object
62     * and compares draw pages.
63     */
64     protected PropertyTester CurPageTester = new PropertyTester() {
65         protected Object getNewValue(String propName, Object oldValue) {
66             return drawPage;
67         }
68 
69         protected boolean compare(Object obj1, Object obj2) {
70             XNamed named1 = (XNamed)UnoRuntime.queryInterface(XNamed.class, obj1);
71             XNamed named2 = (XNamed)UnoRuntime.queryInterface(XNamed.class, obj2);
72             boolean res = false;
73 
74             if (named1 != null && named2 != null) {
75                 String name1 = named1.getName();
76                 String name2 = named2.getName();
77                 res = name1.equals(name2);
78             } else {
79                 log.println("Interface XNamed not supported");
80             }
81 
82             return res;
83         }
84 
85         protected String toString(Object obj) {
86             XNamed named = (XNamed)UnoRuntime.queryInterface(XNamed.class, obj);
87             String res = (named == null) ? "null" : named.getName();
88             return res;
89         }
90     } ;
91 
_CurrentPage()92     public void _CurrentPage() {
93         log.println("Testing with custom Property tester");
94         Object oldCurPage = null;
95         try {
96             oldCurPage = oObj.getPropertyValue("CurrentPage");
97         } catch(com.sun.star.lang.WrappedTargetException e) {
98             e.printStackTrace(log);
99         } catch(com.sun.star.beans.UnknownPropertyException e) {
100             e.printStackTrace(log);
101         }
102 
103         testProperty("CurrentPage", CurPageTester);
104 
105         try {
106             log.println("Back old current page");
107             oObj.setPropertyValue("CurrentPage", oldCurPage);
108         } catch(com.sun.star.lang.WrappedTargetException e) {
109             e.printStackTrace(log);
110         } catch(com.sun.star.beans.UnknownPropertyException e) {
111             e.printStackTrace(log);
112         } catch(com.sun.star.lang.IllegalArgumentException e) {
113             e.printStackTrace(log);
114         } catch(com.sun.star.beans.PropertyVetoException e) {
115             e.printStackTrace(log);
116         }
117     }
118 
_IsMasterPageMode()119     public void _IsMasterPageMode() {
120         testProperty("IsMasterPageMode");
121         try {
122             oObj.setPropertyValue("IsMasterPageMode", new Boolean(false));
123         } catch(com.sun.star.lang.WrappedTargetException e) {
124             e.printStackTrace(log);
125         } catch(com.sun.star.beans.UnknownPropertyException e) {
126             e.printStackTrace(log);
127         } catch(com.sun.star.lang.IllegalArgumentException e) {
128             e.printStackTrace(log);
129         } catch(com.sun.star.beans.PropertyVetoException e) {
130             e.printStackTrace(log);
131         }
132     }
133 
_IsLayerMode()134     public void _IsLayerMode() {
135         testProperty("IsLayerMode");
136         try {
137             oObj.setPropertyValue("IsLayerMode", new Boolean(false));
138         } catch(com.sun.star.lang.WrappedTargetException e) {
139             e.printStackTrace(log);
140         } catch(com.sun.star.beans.UnknownPropertyException e) {
141             e.printStackTrace(log);
142         } catch(com.sun.star.lang.IllegalArgumentException e) {
143             e.printStackTrace(log);
144         } catch(com.sun.star.beans.PropertyVetoException e) {
145             e.printStackTrace(log);
146         }
147     }
148 
_ZoomType()149     public void _ZoomType() {
150         Object oldValue=null;
151         Object newValue=null;
152         try {
153             oldValue = oObj.getPropertyValue("ZoomValue");
154             Object oldZoom = oObj.getPropertyValue("ZoomType");
155             Object newZoom = ValueChanger.changePValue(oldZoom);
156             oObj.setPropertyValue("ZoomType", newZoom);
157             newValue = oObj.getPropertyValue("ZoomValue");
158         } catch(com.sun.star.lang.WrappedTargetException e) {
159             e.printStackTrace(log);
160         } catch(com.sun.star.beans.UnknownPropertyException e) {
161             e.printStackTrace(log);
162         } catch(com.sun.star.lang.IllegalArgumentException e) {
163             e.printStackTrace(log);
164         } catch(com.sun.star.beans.PropertyVetoException e) {
165             e.printStackTrace(log);
166         }
167         log.println("oldZoomValue: "+oldValue);
168         log.println("newZoomValue: "+newValue);
169         tRes.tested("ZoomType",(!oldValue.equals(newValue)));
170     }
171 
172 }
173 
174