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