1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package ifc.configuration.backend; 24 25 import com.sun.star.configuration.backend.XSchema; 26 import com.sun.star.configuration.backend.XSchemaSupplier; 27 28 import lib.MultiMethodTest; 29 import util.XSchemaHandlerImpl; 30 31 public class _XSchemaSupplier extends MultiMethodTest { 32 public XSchemaSupplier oObj; 33 _getComponentSchema()34 public void _getComponentSchema() { 35 boolean res = true; 36 XSchema aSchema = null; 37 38 try { 39 aSchema = oObj.getComponentSchema("org.openoffice.Office.Linguistic"); 40 res &= (aSchema != null); 41 42 if (aSchema == null) { 43 log.println("\treturned Layer is NULL -- FAILED"); 44 } 45 46 res &= checkSchema(aSchema); 47 } catch (com.sun.star.configuration.backend.BackendAccessException e) { 48 log.println("Unexpected Exception (" + e + ") -- FAILED"); 49 res &= false; 50 } catch (com.sun.star.lang.IllegalArgumentException e) { 51 log.println("Unexpected Exception (" + e + ") -- FAILED"); 52 res &= false; 53 } 54 tRes.tested("getComponentSchema()",res); 55 } 56 checkSchema(XSchema aSchema)57 protected boolean checkSchema(XSchema aSchema) { 58 boolean res = false; 59 XSchemaHandlerImpl xSchemaHandlerImpl = new XSchemaHandlerImpl(); 60 log.println("Checking for Exception in case of null argument"); 61 62 try { 63 aSchema.readTemplates(null); 64 log.println("NoException thrown for null argument -- FAILED"); 65 } catch (com.sun.star.lang.NullPointerException e) { 66 log.println("Expected Exception -- OK"); 67 res = true; 68 } catch (com.sun.star.lang.WrappedTargetException e) { 69 log.println("Unexpected Exception (" + e + ") -- FAILED"); 70 } catch (com.sun.star.configuration.backend.MalformedDataException e) { 71 log.println("Unexpected Exception (" + e + ") -- FAILED"); 72 } 73 74 log.println( 75 "checking readComponent with own XSchemaHandler implementation"); 76 77 try { 78 aSchema.readComponent(xSchemaHandlerImpl); 79 80 String implCalled = xSchemaHandlerImpl.getCalls(); 81 int sc = implCalled.indexOf("startComponent"); 82 83 if (sc < 0) { 84 log.println("startComponent wasn't called -- FAILED"); 85 res &= false; 86 } else { 87 log.println("startComponent was called -- OK"); 88 res &= true; 89 } 90 91 int ec = implCalled.indexOf("endComponent"); 92 93 if (ec < 0) { 94 log.println("endComponent wasn't called -- FAILED"); 95 res &= false; 96 } else { 97 log.println("endComponent was called -- OK"); 98 res &= true; 99 } 100 } catch (com.sun.star.lang.NullPointerException e) { 101 log.println("Unexpected Exception (" + e + ") -- FAILED"); 102 res &= false; 103 } catch (com.sun.star.lang.WrappedTargetException e) { 104 log.println("Unexpected Exception (" + e + ") -- FAILED"); 105 res &= false; 106 } catch (com.sun.star.configuration.backend.MalformedDataException e) { 107 log.println("Unexpected Exception (" + e + ") -- FAILED"); 108 res &= false; 109 } 110 111 return res; 112 113 } 114 }