merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / uno / _XNamingService.java
blobe5d7f9ff3f6729718d1bbed958943f4a8b49c70d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XNamingService.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.uno;
33 import lib.MultiMethodTest;
34 import lib.StatusException;
36 import com.sun.star.uno.XInterface;
37 import com.sun.star.uno.XNamingService;
40 /**
41 * Testing <code>com.sun.star.uno.XNamingService</code>
42 * interface methods. <p>
43 * This test need the following object relations :
44 * <ul>
45 * <li> <code>'XNamingService.RegisterObject'</code> :
46 * object to be registered.</li>
47 * <ul> <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * After test completion object environment has to be recreated.
51 public class _XNamingService extends MultiMethodTest {
53 public static XNamingService oObj = null;
55 private XInterface regObject = null ;
57 /**
58 * Retrieves object relation.
59 * @throws StatusException If the relation not found.
61 public void before() {
62 regObject = (XInterface)
63 tEnv.getObjRelation("XNamingService.RegisterObject") ;
64 if (regObject == null)
65 throw new StatusException("Can't create object to register",
66 new NullPointerException()) ;
69 /**
70 * Test calls the method and checks that
71 * no exceptions were thrown. <p>
72 * Has <b> OK </b> status if the method successfully returns
73 * and no exceptions were thrown. <p>
74 * The following method tests are to be completed successfully before :
76 public void _registerObject() throws StatusException{
77 try {
78 oObj.registerObject("MyFactory", regObject) ;
79 } catch (com.sun.star.uno.Exception e) {
80 log.println("Exception while registering object :" + e) ;
81 tRes.tested("registerObject()", false) ;
82 return ;
85 tRes.tested("registerObject()", true) ;
88 /**
89 * Test calls the method and checks return value and that
90 * no exceptions were thrown. <p>
91 * Has <b> OK </b> status if the method returns the same object
92 * that was registered and no exceptions were thrown. <p>
93 * The following method tests are to be completed successfully before :
94 * <ul>
95 * <li> <code> registerObject </code> : to get in this test the
96 * object that was registered.</li>
97 * </ul>
99 public void _getRegisteredObject() {
100 requiredMethod("registerObject()") ;
102 try {
103 Object getObject = oObj.getRegisteredObject("MyFactory") ;
105 tRes.tested("getRegisteredObject()" ,
106 regObject.equals(getObject)) ;
107 } catch (com.sun.star.uno.Exception e) {
108 log.println("Exception calling method :" + e) ;
109 tRes.tested("getRegisteredObject()", false) ;
110 return ;
115 * Test calls the method and trying to get revoked object. <p>
116 * Has <b> OK </b> status if the method successfully returns
117 * and if the method <code>getRegisteredObject</code> returns NULL or
118 * throws expected exception. <p>
119 * The following method tests are to be completed successfully before :
120 * <ul>
121 * <li> <code> registerObject </code> : to revoke the object registered</li>
122 * </ul>
123 * The following method tests are to be executed before :
124 * <ul>
125 * <li> <code> getRegisteredObject </code> : before object will be
126 * revoked </li>
127 * </ul>
129 public void _revokeObject() {
130 requiredMethod("registerObject()") ;
131 executeMethod("getRegisteredObject()") ;
133 try {
134 oObj.revokeObject("MyFactory");
135 log.println("Object was revoked");
136 } catch (com.sun.star.uno.Exception e) {
137 log.println("Exception revoking object :" + e) ;
138 tRes.tested("revokeObject()", false) ;
141 boolean res = true;
143 try {
144 log.println("Trying to getRegistered object ...");
145 Object objregObj = oObj.getRegisteredObject("MyFactory");
146 log.println("No exception");
147 res &= objregObj == null;
148 if (res) {
149 log.println("But NULL was returned");
151 } catch(com.sun.star.uno.Exception e) {
152 log.println("Expected exception - OK");
155 tRes.tested("revokeObject()", res);