1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.configuration.backend; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.configuration.backend.XBackend; 26cdf0e10cSrcweir import com.sun.star.configuration.backend.XLayer; 27cdf0e10cSrcweir import com.sun.star.configuration.backend.XUpdateHandler; 28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 30cdf0e10cSrcweir import com.sun.star.util.XStringSubstitution; 31cdf0e10cSrcweir 32cdf0e10cSrcweir import lib.MultiMethodTest; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import util.XLayerHandlerImpl; 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir public class _XBackend extends MultiMethodTest { 38cdf0e10cSrcweir public XBackend oObj; 39cdf0e10cSrcweir _getOwnUpdateHandler()40cdf0e10cSrcweir public void _getOwnUpdateHandler() { 41cdf0e10cSrcweir boolean res = true; 42cdf0e10cSrcweir 43cdf0e10cSrcweir String noUpdate = (String) tEnv.getObjRelation("noUpdate"); 44cdf0e10cSrcweir 45cdf0e10cSrcweir if (noUpdate != null) { 46cdf0e10cSrcweir log.println(noUpdate); 47cdf0e10cSrcweir tRes.tested("getOwnUpdateHandler()", res); 48cdf0e10cSrcweir 49cdf0e10cSrcweir return; 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir try { 53cdf0e10cSrcweir XUpdateHandler aHandler = oObj.getOwnUpdateHandler( 54cdf0e10cSrcweir "org.openoffice.Office.Linguistic"); 55cdf0e10cSrcweir res &= (aHandler != null); 56cdf0e10cSrcweir 57cdf0e10cSrcweir if (aHandler == null) { 58cdf0e10cSrcweir log.println("\treturned Layer is NULL -- FAILED"); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir } catch (com.sun.star.configuration.backend.BackendAccessException e) { 61cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 62cdf0e10cSrcweir res = false; 63cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 64cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 65cdf0e10cSrcweir res = false; 66cdf0e10cSrcweir } catch (com.sun.star.lang.NoSupportException e) { 67cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 68cdf0e10cSrcweir res = false; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir tRes.tested("getOwnUpdateHandler()", res); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir _getUpdateHandler()74cdf0e10cSrcweir public void _getUpdateHandler() { 75cdf0e10cSrcweir boolean res = true; 76cdf0e10cSrcweir 77cdf0e10cSrcweir String noUpdate = (String) tEnv.getObjRelation("noUpdate"); 78cdf0e10cSrcweir 79cdf0e10cSrcweir if (noUpdate != null) { 80cdf0e10cSrcweir log.println(noUpdate); 81cdf0e10cSrcweir tRes.tested("getUpdateHandler()", res); 82cdf0e10cSrcweir 83cdf0e10cSrcweir return; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir try { 87cdf0e10cSrcweir XUpdateHandler aHandler = oObj.getUpdateHandler( 88cdf0e10cSrcweir "org.openoffice.Office.TypeDetection", 89cdf0e10cSrcweir "illegal"); 90cdf0e10cSrcweir log.println("Exception expected -- FAILED"); 91cdf0e10cSrcweir res = false; 92cdf0e10cSrcweir } catch (com.sun.star.configuration.backend.BackendAccessException e) { 93cdf0e10cSrcweir log.println("expected Exception -- OK"); 94cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 95cdf0e10cSrcweir log.println("unexpected Exception -- FAILED"); 96cdf0e10cSrcweir res = false; 97cdf0e10cSrcweir } catch (com.sun.star.lang.NoSupportException e) { 98cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 99cdf0e10cSrcweir res = false; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir try { 103cdf0e10cSrcweir XStringSubstitution sts = createStringSubstitution( 104cdf0e10cSrcweir (XMultiServiceFactory) tParam.getMSF()); 105cdf0e10cSrcweir String ent = sts.getSubstituteVariableValue("$(inst)") + 106cdf0e10cSrcweir "/share/registry"; 107cdf0e10cSrcweir XUpdateHandler aHandler = oObj.getUpdateHandler( 108cdf0e10cSrcweir "org.openoffice.Office.Jobs", 109cdf0e10cSrcweir ent); 110cdf0e10cSrcweir 111cdf0e10cSrcweir if (aHandler == null) { 112cdf0e10cSrcweir log.println("\treturned Layer is NULL -- FAILED"); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } catch (com.sun.star.configuration.backend.BackendAccessException e) { 115cdf0e10cSrcweir log.println("unexpected Exception -- FAILED"); 116cdf0e10cSrcweir res = false; 117cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 118cdf0e10cSrcweir log.println("unexpected Exception -- FAILED"); 119cdf0e10cSrcweir res = false; 120cdf0e10cSrcweir } catch (com.sun.star.lang.NoSupportException e) { 121cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 122cdf0e10cSrcweir res = false; 123cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 124cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 125cdf0e10cSrcweir res = false; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir tRes.tested("getUpdateHandler()", res); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir _listLayers()131cdf0e10cSrcweir public void _listLayers() { 132cdf0e10cSrcweir boolean res = true; 133cdf0e10cSrcweir 134cdf0e10cSrcweir try { 135cdf0e10cSrcweir XStringSubstitution sts = createStringSubstitution( 136cdf0e10cSrcweir (XMultiServiceFactory) tParam.getMSF()); 137cdf0e10cSrcweir String ent = sts.getSubstituteVariableValue("$(inst)") + 138cdf0e10cSrcweir "/share/registry"; 139cdf0e10cSrcweir XLayer[] Layers = oObj.listLayers( 140cdf0e10cSrcweir "org.openoffice.Office.Linguistic", ent); 141cdf0e10cSrcweir 142cdf0e10cSrcweir for (int i = 0; i < Layers.length; i++) { 143cdf0e10cSrcweir log.println("Checking Layer " + i); 144cdf0e10cSrcweir res &= checkLayer(Layers[i]); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } catch (com.sun.star.configuration.backend.BackendAccessException e) { 147cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 148cdf0e10cSrcweir res = false; 149cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 150cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 151cdf0e10cSrcweir res = false; 152cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 153cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 154cdf0e10cSrcweir res = false; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir tRes.tested("listLayers()", res); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir _listOwnLayers()160cdf0e10cSrcweir public void _listOwnLayers() { 161cdf0e10cSrcweir boolean res = true; 162cdf0e10cSrcweir 163cdf0e10cSrcweir try { 164cdf0e10cSrcweir XLayer[] Layers = oObj.listOwnLayers( 165cdf0e10cSrcweir "org.openoffice.Office.Common"); 166cdf0e10cSrcweir 167cdf0e10cSrcweir for (int i = 0; i < Layers.length; i++) { 168cdf0e10cSrcweir log.println("Checking Layer " + i); 169cdf0e10cSrcweir res &= checkLayer(Layers[i]); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir if (Layers.length==0) { 172cdf0e10cSrcweir System.out.println("No Layers found -- FAILED"); 173cdf0e10cSrcweir res &= false; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } catch (com.sun.star.configuration.backend.BackendAccessException e) { 176cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 177cdf0e10cSrcweir res = false; 178cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 179cdf0e10cSrcweir log.println("unexpected Exception " + e + " -- FAILED"); 180cdf0e10cSrcweir res = false; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir tRes.tested("listOwnLayers()", res); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir checkLayer(XLayer aLayer)186cdf0e10cSrcweir protected boolean checkLayer(XLayer aLayer) { 187cdf0e10cSrcweir boolean res = false; 188cdf0e10cSrcweir 189cdf0e10cSrcweir log.println("Checking for Exception in case of null argument"); 190cdf0e10cSrcweir 191cdf0e10cSrcweir try { 192cdf0e10cSrcweir aLayer.readData(null); 193cdf0e10cSrcweir } catch (com.sun.star.lang.NullPointerException e) { 194cdf0e10cSrcweir log.println("Expected Exception -- OK"); 195cdf0e10cSrcweir res = true; 196cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 197cdf0e10cSrcweir log.println("Unexpected Exception (" + e + ") -- FAILED"); 198cdf0e10cSrcweir } catch (com.sun.star.configuration.backend.MalformedDataException e) { 199cdf0e10cSrcweir log.println("Unexpected Exception (" + e + ") -- FAILED"); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir log.println("checking read data with own XLayerHandler implementation"); 203cdf0e10cSrcweir 204cdf0e10cSrcweir try { 205cdf0e10cSrcweir XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl(); 206cdf0e10cSrcweir aLayer.readData(xLayerHandler); 207cdf0e10cSrcweir 208cdf0e10cSrcweir String implCalled = xLayerHandler.getCalls(); 209cdf0e10cSrcweir log.println(implCalled); 210cdf0e10cSrcweir 211cdf0e10cSrcweir int sl = implCalled.indexOf("startLayer"); 212cdf0e10cSrcweir 213cdf0e10cSrcweir if (sl < 0) { 214cdf0e10cSrcweir log.println("startLayer wasn't called -- FAILED"); 215cdf0e10cSrcweir res &= false; 216cdf0e10cSrcweir } else { 217cdf0e10cSrcweir log.println("startLayer was called -- OK"); 218cdf0e10cSrcweir res &= true; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir int el = implCalled.indexOf("endLayer"); 222cdf0e10cSrcweir 223cdf0e10cSrcweir if (el < 0) { 224cdf0e10cSrcweir log.println("endLayer wasn't called -- FAILED"); 225cdf0e10cSrcweir res &= false; 226cdf0e10cSrcweir } else { 227cdf0e10cSrcweir log.println("endLayer was called -- OK"); 228cdf0e10cSrcweir res &= true; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } catch (com.sun.star.lang.NullPointerException e) { 231cdf0e10cSrcweir log.println("Unexpected Exception (" + e + ") -- FAILED"); 232cdf0e10cSrcweir res &= false; 233cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 234cdf0e10cSrcweir log.println("Unexpected Exception (" + e + ") -- FAILED"); 235cdf0e10cSrcweir res &= false; 236cdf0e10cSrcweir } catch (com.sun.star.configuration.backend.MalformedDataException e) { 237cdf0e10cSrcweir log.println("Unexpected Exception (" + e + ") -- FAILED"); 238cdf0e10cSrcweir res &= false; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir return res; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir createStringSubstitution(XMultiServiceFactory xMSF)244cdf0e10cSrcweir public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) { 245cdf0e10cSrcweir Object xPathSubst = null; 246cdf0e10cSrcweir 247cdf0e10cSrcweir try { 248cdf0e10cSrcweir xPathSubst = xMSF.createInstance( 249cdf0e10cSrcweir "com.sun.star.util.PathSubstitution"); 250cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 251cdf0e10cSrcweir e.printStackTrace(); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir if (xPathSubst != null) { 255cdf0e10cSrcweir return (XStringSubstitution) UnoRuntime.queryInterface( 256cdf0e10cSrcweir XStringSubstitution.class, xPathSubst); 257cdf0e10cSrcweir } else { 258cdf0e10cSrcweir return null; 259cdf0e10cSrcweir } 260cdf0e10cSrcweir } 261cdf0e10cSrcweir }