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 24 package ifc.lang; 25 26 import lib.MultiMethodTest; 27 28 import com.sun.star.lang.XInitialization; 29 30 /** 31 * Testing <code>com.sun.star.lang.XInitialization</code> 32 * interface methods. <p> 33 * This test needs the following object relations : 34 * <ul> 35 * <li> <code>'XInitialization.args'</code> (of type <code>Object[]</code>): 36 * (<b>Optional</b>) : argument for <code>initialize</code> 37 * method. If ommitet zero length array is used. </li> 38 * <ul> <p> 39 * Test is multithread compilant. <p> 40 * Till the present time there was no need to recreate environment 41 * after this test completion. 42 */ 43 public class _XInitialization extends MultiMethodTest { 44 45 public static XInitialization oObj = null; 46 47 /** 48 * Test calls the method with 0 length array and checks that 49 * no exceptions were thrown. <p> 50 * Has <b> OK </b> status if no exceptions were thrown. <p> 51 */ _initialize()52 public void _initialize() { 53 boolean result = true ; 54 55 try { 56 XInitialization xInit = (XInitialization) tEnv.getObjRelation("XInitialization.xIni"); 57 if (xInit == null) xInit = oObj; 58 59 log.println("calling method with valid arguments..."); 60 Object[] args = (Object[]) tEnv.getObjRelation("XInitialization.args"); 61 if (args==null) { 62 System.out.println("Using new Object[0] as Argument"); 63 xInit.initialize(new Object[0]); 64 } else { 65 xInit.initialize(args); 66 } 67 68 // try to call the method with invalid parameters 69 Object[] ExArgs = (Object[]) tEnv.getObjRelation("XInitialization.ExceptionArgs"); 70 if (ExArgs !=null) { 71 log.println("calling method with in-valid arguments..."); 72 try{ 73 result = false; 74 xInit.initialize(ExArgs); 75 } catch (com.sun.star.uno.Exception e) { 76 log.println("Expected Exception 'com.sun.star.uno.Exception' occured -> OK") ; 77 result = true ; 78 } catch (com.sun.star.uno.RuntimeException e) { 79 log.println("Expected Exception 'com.sun.star.uno.RuntimeException' occured -> OK") ; 80 result = true ; 81 } catch (Exception e) { 82 log.println("Un-Expected Exception occured -> FALSE") ; 83 log.println(e.toString()); 84 e.printStackTrace(); 85 } 86 } 87 88 } catch (com.sun.star.uno.Exception e) { 89 log.println("Exception occured while method calling.") ; 90 log.println(e) ; 91 result = false ; 92 } 93 94 tRes.tested("initialize()", result) ; 95 } // finished _initialize() 96 97 /** 98 * Disposes object environment. 99 */ after()100 public void after() { 101 disposeEnvironment() ; 102 } 103 104 } // finished class _XInitialization 105 106 107