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.text; 29 30 import lib.MultiPropertyTest; 31 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.sdbc.XConnection; 34 import com.sun.star.sdbc.XResultSet; 35 import com.sun.star.uno.UnoRuntime; 36 37 public class _MailMerge extends MultiPropertyTest { 38 39 /** 40 * Custom tester for properties which contains URLs. 41 * Switches between two valid folders 42 */ 43 protected PropertyTester URLTester = new PropertyTester() { 44 protected Object getNewValue(String propName, Object oldValue) { 45 if (oldValue.equals(util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()))) 46 return util.utils.getFullTestURL(""); else 47 return util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()); 48 } 49 } ; 50 51 /** 52 * Custom tester for properties which contains document URLs. 53 * Switches between two document URLs. 54 */ 55 protected PropertyTester DocumentURLTester = new PropertyTester() { 56 protected Object getNewValue(String propName, Object oldValue) { 57 if (oldValue.equals(util.utils.getFullTestURL("MailMerge.sxw"))) 58 return util.utils.getFullTestURL("sForm.sxw"); else 59 return util.utils.getFullTestURL("MailMerge.sxw"); 60 } 61 } ; 62 /** 63 * Tested with custom property tester. 64 */ 65 public void _ResultSet() { 66 String propName = "ResultSet"; 67 try{ 68 69 log.println("try to get value from property..."); 70 XResultSet oldValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,oObj.getPropertyValue(propName)); 71 72 log.println("try to get value from object relation..."); 73 XResultSet newValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,tEnv.getObjRelation("MailMerge.XResultSet")); 74 75 log.println("set property to a new value..."); 76 oObj.setPropertyValue(propName, newValue); 77 78 log.println("get the new value..."); 79 XResultSet getValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,oObj.getPropertyValue(propName)); 80 81 tRes.tested(propName, this.compare(newValue, getValue)); 82 } catch (com.sun.star.beans.PropertyVetoException e){ 83 log.println("could not set property '"+ propName +"' to a new value!"); 84 tRes.tested(propName, false); 85 } catch (com.sun.star.lang.IllegalArgumentException e){ 86 log.println("could not set property '"+ propName +"' to a new value!"); 87 tRes.tested(propName, false); 88 } catch (com.sun.star.beans.UnknownPropertyException e){ 89 if (this.isOptional(propName)){ 90 // skipping optional property test 91 log.println("Property '" + propName 92 + "' is optional and not supported"); 93 tRes.tested(propName,true); 94 95 } else { 96 log.println("could not get property '"+ propName +"' from XPropertySet!"); 97 tRes.tested(propName, false); 98 } 99 } catch (com.sun.star.lang.WrappedTargetException e){ 100 log.println("could not get property '"+ propName +"' from XPropertySet!"); 101 tRes.tested(propName, false); 102 } 103 } 104 105 /** 106 * Tested with custom property tester. 107 */ 108 109 public void _ActiveConnection() { 110 String propName = "ActiveConnection"; 111 try{ 112 113 log.println("try to get value from property..."); 114 XConnection oldValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,oObj.getPropertyValue(propName)); 115 116 log.println("try to get value from object relation..."); 117 XConnection newValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,tEnv.getObjRelation("MailMerge.XConnection")); 118 119 log.println("set property to a new value..."); 120 oObj.setPropertyValue(propName, newValue); 121 122 log.println("get the new value..."); 123 XConnection getValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,oObj.getPropertyValue(propName)); 124 125 tRes.tested(propName, this.compare(newValue, getValue)); 126 } catch (com.sun.star.beans.PropertyVetoException e){ 127 log.println("could not set property '"+ propName +"' to a new value! " + e.toString()); 128 tRes.tested(propName, false); 129 } catch (com.sun.star.lang.IllegalArgumentException e){ 130 log.println("could not set property '"+ propName +"' to a new value! " + e.toString()); 131 tRes.tested(propName, false); 132 } catch (com.sun.star.beans.UnknownPropertyException e){ 133 if (this.isOptional(propName)){ 134 // skipping optional property test 135 log.println("Property '" + propName 136 + "' is optional and not supported"); 137 tRes.tested(propName,true); 138 139 } else { 140 log.println("could not get property '"+ propName +"' from XPropertySet!"); 141 tRes.tested(propName, false); 142 } 143 } catch (com.sun.star.lang.WrappedTargetException e){ 144 log.println("could not get property '"+ propName +"' from XPropertySet!"); 145 tRes.tested(propName, false); 146 } 147 } 148 149 /** 150 * Tested with custom property tester. 151 */ 152 public void _DocumentURL() { 153 log.println("Testing with custom Property tester") ; 154 testProperty("DocumentURL", DocumentURLTester) ; 155 } 156 157 /** 158 * Tested with custom property tester. 159 */ 160 public void _OutputURL() { 161 log.println("Testing with custom Property tester") ; 162 testProperty("OutputURL", URLTester) ; 163 } 164 165 /** 166 * Forces environment recreation. 167 */ 168 protected void after() { 169 disposeEnvironment(); 170 } 171 172 173 } //finish class _MailMerge 174 175