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 package ifc.configuration.backend; 28 29 import com.sun.star.configuration.backend.XBackend; 30 import com.sun.star.configuration.backend.XLayer; 31 import com.sun.star.configuration.backend.XUpdateHandler; 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.uno.UnoRuntime; 34 import com.sun.star.util.XStringSubstitution; 35 36 import lib.MultiMethodTest; 37 38 import util.XLayerHandlerImpl; 39 40 41 public class _XBackend extends MultiMethodTest { 42 public XBackend oObj; 43 44 public void _getOwnUpdateHandler() { 45 boolean res = true; 46 47 String noUpdate = (String) tEnv.getObjRelation("noUpdate"); 48 49 if (noUpdate != null) { 50 log.println(noUpdate); 51 tRes.tested("getOwnUpdateHandler()", res); 52 53 return; 54 } 55 56 try { 57 XUpdateHandler aHandler = oObj.getOwnUpdateHandler( 58 "org.openoffice.Office.Linguistic"); 59 res &= (aHandler != null); 60 61 if (aHandler == null) { 62 log.println("\treturned Layer is NULL -- FAILED"); 63 } 64 } catch (com.sun.star.configuration.backend.BackendAccessException e) { 65 log.println("unexpected Exception " + e + " -- FAILED"); 66 res = false; 67 } catch (com.sun.star.lang.IllegalArgumentException e) { 68 log.println("unexpected Exception " + e + " -- FAILED"); 69 res = false; 70 } catch (com.sun.star.lang.NoSupportException e) { 71 log.println("unexpected Exception " + e + " -- FAILED"); 72 res = false; 73 } 74 75 tRes.tested("getOwnUpdateHandler()", res); 76 } 77 78 public void _getUpdateHandler() { 79 boolean res = true; 80 81 String noUpdate = (String) tEnv.getObjRelation("noUpdate"); 82 83 if (noUpdate != null) { 84 log.println(noUpdate); 85 tRes.tested("getUpdateHandler()", res); 86 87 return; 88 } 89 90 try { 91 XUpdateHandler aHandler = oObj.getUpdateHandler( 92 "org.openoffice.Office.TypeDetection", 93 "illegal"); 94 log.println("Exception expected -- FAILED"); 95 res = false; 96 } catch (com.sun.star.configuration.backend.BackendAccessException e) { 97 log.println("expected Exception -- OK"); 98 } catch (com.sun.star.lang.IllegalArgumentException e) { 99 log.println("unexpected Exception -- FAILED"); 100 res = false; 101 } catch (com.sun.star.lang.NoSupportException e) { 102 log.println("unexpected Exception " + e + " -- FAILED"); 103 res = false; 104 } 105 106 try { 107 XStringSubstitution sts = createStringSubstitution( 108 (XMultiServiceFactory) tParam.getMSF()); 109 String ent = sts.getSubstituteVariableValue("$(inst)") + 110 "/share/registry"; 111 XUpdateHandler aHandler = oObj.getUpdateHandler( 112 "org.openoffice.Office.Jobs", 113 ent); 114 115 if (aHandler == null) { 116 log.println("\treturned Layer is NULL -- FAILED"); 117 } 118 } catch (com.sun.star.configuration.backend.BackendAccessException e) { 119 log.println("unexpected Exception -- FAILED"); 120 res = false; 121 } catch (com.sun.star.lang.IllegalArgumentException e) { 122 log.println("unexpected Exception -- FAILED"); 123 res = false; 124 } catch (com.sun.star.lang.NoSupportException e) { 125 log.println("unexpected Exception " + e + " -- FAILED"); 126 res = false; 127 } catch (com.sun.star.container.NoSuchElementException e) { 128 log.println("unexpected Exception " + e + " -- FAILED"); 129 res = false; 130 } 131 132 tRes.tested("getUpdateHandler()", res); 133 } 134 135 public void _listLayers() { 136 boolean res = true; 137 138 try { 139 XStringSubstitution sts = createStringSubstitution( 140 (XMultiServiceFactory) tParam.getMSF()); 141 String ent = sts.getSubstituteVariableValue("$(inst)") + 142 "/share/registry"; 143 XLayer[] Layers = oObj.listLayers( 144 "org.openoffice.Office.Linguistic", ent); 145 146 for (int i = 0; i < Layers.length; i++) { 147 log.println("Checking Layer " + i); 148 res &= checkLayer(Layers[i]); 149 } 150 } catch (com.sun.star.configuration.backend.BackendAccessException e) { 151 log.println("unexpected Exception " + e + " -- FAILED"); 152 res = false; 153 } catch (com.sun.star.lang.IllegalArgumentException e) { 154 log.println("unexpected Exception " + e + " -- FAILED"); 155 res = false; 156 } catch (com.sun.star.container.NoSuchElementException e) { 157 log.println("unexpected Exception " + e + " -- FAILED"); 158 res = false; 159 } 160 161 tRes.tested("listLayers()", res); 162 } 163 164 public void _listOwnLayers() { 165 boolean res = true; 166 167 try { 168 XLayer[] Layers = oObj.listOwnLayers( 169 "org.openoffice.Office.Common"); 170 171 for (int i = 0; i < Layers.length; i++) { 172 log.println("Checking Layer " + i); 173 res &= checkLayer(Layers[i]); 174 } 175 if (Layers.length==0) { 176 System.out.println("No Layers found -- FAILED"); 177 res &= false; 178 } 179 } catch (com.sun.star.configuration.backend.BackendAccessException e) { 180 log.println("unexpected Exception " + e + " -- FAILED"); 181 res = false; 182 } catch (com.sun.star.lang.IllegalArgumentException e) { 183 log.println("unexpected Exception " + e + " -- FAILED"); 184 res = false; 185 } 186 187 tRes.tested("listOwnLayers()", res); 188 } 189 190 protected boolean checkLayer(XLayer aLayer) { 191 boolean res = false; 192 193 log.println("Checking for Exception in case of null argument"); 194 195 try { 196 aLayer.readData(null); 197 } catch (com.sun.star.lang.NullPointerException e) { 198 log.println("Expected Exception -- OK"); 199 res = true; 200 } catch (com.sun.star.lang.WrappedTargetException e) { 201 log.println("Unexpected Exception (" + e + ") -- FAILED"); 202 } catch (com.sun.star.configuration.backend.MalformedDataException e) { 203 log.println("Unexpected Exception (" + e + ") -- FAILED"); 204 } 205 206 log.println("checking read data with own XLayerHandler implementation"); 207 208 try { 209 XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl(); 210 aLayer.readData(xLayerHandler); 211 212 String implCalled = xLayerHandler.getCalls(); 213 log.println(implCalled); 214 215 int sl = implCalled.indexOf("startLayer"); 216 217 if (sl < 0) { 218 log.println("startLayer wasn't called -- FAILED"); 219 res &= false; 220 } else { 221 log.println("startLayer was called -- OK"); 222 res &= true; 223 } 224 225 int el = implCalled.indexOf("endLayer"); 226 227 if (el < 0) { 228 log.println("endLayer wasn't called -- FAILED"); 229 res &= false; 230 } else { 231 log.println("endLayer was called -- OK"); 232 res &= true; 233 } 234 } catch (com.sun.star.lang.NullPointerException e) { 235 log.println("Unexpected Exception (" + e + ") -- FAILED"); 236 res &= false; 237 } catch (com.sun.star.lang.WrappedTargetException e) { 238 log.println("Unexpected Exception (" + e + ") -- FAILED"); 239 res &= false; 240 } catch (com.sun.star.configuration.backend.MalformedDataException e) { 241 log.println("Unexpected Exception (" + e + ") -- FAILED"); 242 res &= false; 243 } 244 245 return res; 246 } 247 248 public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) { 249 Object xPathSubst = null; 250 251 try { 252 xPathSubst = xMSF.createInstance( 253 "com.sun.star.util.PathSubstitution"); 254 } catch (com.sun.star.uno.Exception e) { 255 e.printStackTrace(); 256 } 257 258 if (xPathSubst != null) { 259 return (XStringSubstitution) UnoRuntime.queryInterface( 260 XStringSubstitution.class, xPathSubst); 261 } else { 262 return null; 263 } 264 } 265 }