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.uno; 29 30 import lib.MultiMethodTest; 31 import lib.StatusException; 32 33 import com.sun.star.uno.XInterface; 34 import com.sun.star.uno.XNamingService; 35 36 37 /** 38 * Testing <code>com.sun.star.uno.XNamingService</code> 39 * interface methods. <p> 40 * This test need the following object relations : 41 * <ul> 42 * <li> <code>'XNamingService.RegisterObject'</code> : 43 * object to be registered.</li> 44 * <ul> <p> 45 * Test is <b> NOT </b> multithread compilant. <p> 46 * After test completion object environment has to be recreated. 47 */ 48 public class _XNamingService extends MultiMethodTest { 49 50 public static XNamingService oObj = null; 51 52 private XInterface regObject = null ; 53 54 /** 55 * Retrieves object relation. 56 * @throws StatusException If the relation not found. 57 */ 58 public void before() { 59 regObject = (XInterface) 60 tEnv.getObjRelation("XNamingService.RegisterObject") ; 61 if (regObject == null) 62 throw new StatusException("Can't create object to register", 63 new NullPointerException()) ; 64 } 65 66 /** 67 * Test calls the method and checks that 68 * no exceptions were thrown. <p> 69 * Has <b> OK </b> status if the method successfully returns 70 * and no exceptions were thrown. <p> 71 * The following method tests are to be completed successfully before : 72 */ 73 public void _registerObject() throws StatusException{ 74 try { 75 oObj.registerObject("MyFactory", regObject) ; 76 } catch (com.sun.star.uno.Exception e) { 77 log.println("Exception while registering object :" + e) ; 78 tRes.tested("registerObject()", false) ; 79 return ; 80 } 81 82 tRes.tested("registerObject()", true) ; 83 } 84 85 /** 86 * Test calls the method and checks return value and that 87 * no exceptions were thrown. <p> 88 * Has <b> OK </b> status if the method returns the same object 89 * that was registered and no exceptions were thrown. <p> 90 * The following method tests are to be completed successfully before : 91 * <ul> 92 * <li> <code> registerObject </code> : to get in this test the 93 * object that was registered.</li> 94 * </ul> 95 */ 96 public void _getRegisteredObject() { 97 requiredMethod("registerObject()") ; 98 99 try { 100 Object getObject = oObj.getRegisteredObject("MyFactory") ; 101 102 tRes.tested("getRegisteredObject()" , 103 regObject.equals(getObject)) ; 104 } catch (com.sun.star.uno.Exception e) { 105 log.println("Exception calling method :" + e) ; 106 tRes.tested("getRegisteredObject()", false) ; 107 return ; 108 } 109 } 110 111 /** 112 * Test calls the method and trying to get revoked object. <p> 113 * Has <b> OK </b> status if the method successfully returns 114 * and if the method <code>getRegisteredObject</code> returns NULL or 115 * throws expected exception. <p> 116 * The following method tests are to be completed successfully before : 117 * <ul> 118 * <li> <code> registerObject </code> : to revoke the object registered</li> 119 * </ul> 120 * The following method tests are to be executed before : 121 * <ul> 122 * <li> <code> getRegisteredObject </code> : before object will be 123 * revoked </li> 124 * </ul> 125 */ 126 public void _revokeObject() { 127 requiredMethod("registerObject()") ; 128 executeMethod("getRegisteredObject()") ; 129 130 try { 131 oObj.revokeObject("MyFactory"); 132 log.println("Object was revoked"); 133 } catch (com.sun.star.uno.Exception e) { 134 log.println("Exception revoking object :" + e) ; 135 tRes.tested("revokeObject()", false) ; 136 } 137 138 boolean res = true; 139 140 try { 141 log.println("Trying to getRegistered object ..."); 142 Object objregObj = oObj.getRegisteredObject("MyFactory"); 143 log.println("No exception"); 144 res &= objregObj == null; 145 if (res) { 146 log.println("But NULL was returned"); 147 } 148 } catch(com.sun.star.uno.Exception e) { 149 log.println("Expected exception - OK"); 150 } 151 152 tRes.tested("revokeObject()", res); 153 } 154 } 155 156