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.XSchema; 30 import com.sun.star.configuration.backend.XSchemaSupplier; 31 32 import lib.MultiMethodTest; 33 import util.XSchemaHandlerImpl; 34 35 public class _XSchemaSupplier extends MultiMethodTest { 36 public XSchemaSupplier oObj; 37 38 public void _getComponentSchema() { 39 boolean res = true; 40 XSchema aSchema = null; 41 42 try { 43 aSchema = oObj.getComponentSchema("org.openoffice.Office.Linguistic"); 44 res &= (aSchema != null); 45 46 if (aSchema == null) { 47 log.println("\treturned Layer is NULL -- FAILED"); 48 } 49 50 res &= checkSchema(aSchema); 51 } catch (com.sun.star.configuration.backend.BackendAccessException e) { 52 log.println("Unexpected Exception (" + e + ") -- FAILED"); 53 res &= false; 54 } catch (com.sun.star.lang.IllegalArgumentException e) { 55 log.println("Unexpected Exception (" + e + ") -- FAILED"); 56 res &= false; 57 } 58 tRes.tested("getComponentSchema()",res); 59 } 60 61 protected boolean checkSchema(XSchema aSchema) { 62 boolean res = false; 63 XSchemaHandlerImpl xSchemaHandlerImpl = new XSchemaHandlerImpl(); 64 log.println("Checking for Exception in case of null argument"); 65 66 try { 67 aSchema.readTemplates(null); 68 log.println("NoException thrown for null argument -- FAILED"); 69 } catch (com.sun.star.lang.NullPointerException e) { 70 log.println("Expected Exception -- OK"); 71 res = true; 72 } catch (com.sun.star.lang.WrappedTargetException e) { 73 log.println("Unexpected Exception (" + e + ") -- FAILED"); 74 } catch (com.sun.star.configuration.backend.MalformedDataException e) { 75 log.println("Unexpected Exception (" + e + ") -- FAILED"); 76 } 77 78 log.println( 79 "checking readComponent with own XSchemaHandler implementation"); 80 81 try { 82 aSchema.readComponent(xSchemaHandlerImpl); 83 84 String implCalled = xSchemaHandlerImpl.getCalls(); 85 int sc = implCalled.indexOf("startComponent"); 86 87 if (sc < 0) { 88 log.println("startComponent wasn't called -- FAILED"); 89 res &= false; 90 } else { 91 log.println("startComponent was called -- OK"); 92 res &= true; 93 } 94 95 int ec = implCalled.indexOf("endComponent"); 96 97 if (ec < 0) { 98 log.println("endComponent wasn't called -- FAILED"); 99 res &= false; 100 } else { 101 log.println("endComponent was called -- OK"); 102 res &= true; 103 } 104 } catch (com.sun.star.lang.NullPointerException e) { 105 log.println("Unexpected Exception (" + e + ") -- FAILED"); 106 res &= false; 107 } catch (com.sun.star.lang.WrappedTargetException e) { 108 log.println("Unexpected Exception (" + e + ") -- FAILED"); 109 res &= false; 110 } catch (com.sun.star.configuration.backend.MalformedDataException e) { 111 log.println("Unexpected Exception (" + e + ") -- FAILED"); 112 res &= false; 113 } 114 115 return res; 116 117 } 118 }