1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 package ifc.lang; 20 21 import lib.MultiMethodTest; 22 23 import com.sun.star.lang.XInitialization; 24 25 /** 26 * Testing <code>com.sun.star.lang.XInitialization</code> 27 * interface methods. <p> 28 * This test needs the following object relations : 29 * <ul> 30 * <li> <code>'XInitialization.args'</code> (of type <code>Object[]</code>): 31 * (<b>Optional</b>) : argument for <code>initialize</code> 32 * method. If omitted zero length array is used. </li> 33 * <ul> <p> 34 * Test is multithread compliant. <p> 35 * Till the present time there was no need to recreate environment 36 * after this test completion. 37 */ 38 public class _XInitialization extends MultiMethodTest { 39 40 public static XInitialization oObj = null; 41 42 /** 43 * Test calls the method with 0 length array and checks that 44 * no exceptions were thrown. <p> 45 * Has <b> OK </b> status if no exceptions were thrown. <p> 46 */ _initialize()47 public void _initialize() { 48 boolean result = true ; 49 50 try { 51 XInitialization xInit = (XInitialization) tEnv.getObjRelation("XInitialization.xIni"); 52 if (xInit == null) xInit = oObj; 53 54 log.println("calling method with valid arguments..."); 55 Object[] args = (Object[]) tEnv.getObjRelation("XInitialization.args"); 56 if (args==null) { 57 System.out.println("Using new Object[0] as Argument"); 58 xInit.initialize(new Object[0]); 59 } else { 60 xInit.initialize(args); 61 } 62 63 // try to call the method with invalid parameters 64 Object[] ExArgs = (Object[]) tEnv.getObjRelation("XInitialization.ExceptionArgs"); 65 if (ExArgs !=null) { 66 log.println("calling method with in-valid arguments..."); 67 try{ 68 result = false; 69 xInit.initialize(ExArgs); 70 } catch (com.sun.star.uno.Exception e) { 71 log.println("Expected Exception 'com.sun.star.uno.Exception' occurred -> OK") ; 72 result = true ; 73 } catch (com.sun.star.uno.RuntimeException e) { 74 log.println("Expected Exception 'com.sun.star.uno.RuntimeException' occurred -> OK") ; 75 result = true ; 76 } catch (Exception e) { 77 log.println("Un-Expected Exception occurred -> FALSE") ; 78 log.println(e.toString()); 79 e.printStackTrace(); 80 } 81 } 82 83 } catch (com.sun.star.uno.Exception e) { 84 log.println("Exception occurred while method calling.") ; 85 log.println(e) ; 86 result = false ; 87 } 88 89 tRes.tested("initialize()", result) ; 90 } // finished _initialize() 91 92 /** 93 * Disposes object environment. 94 */ 95 @Override after()96 public void after() { 97 disposeEnvironment() ; 98 } 99 100 } // finished class _XInitialization 101 102 103