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