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.reflection; 25 26 import com.sun.star.lang.XMultiServiceFactory; 27 import com.sun.star.reflection.XIdlClass; 28 import com.sun.star.reflection.XIdlReflection; 29 import com.sun.star.uno.TypeClass; 30 import lib.MultiMethodTest; 31 32 /** 33 * Testing <code>com.sun.star.reflection.XIdlReflection</code> 34 * interface methods : 35 * <ul> 36 * <li><code> forName()</code></li> 37 * <li><code> getType()</code></li> 38 * </ul> <p> 39 * @see com.sun.star.reflection.XIdlReflection 40 */ 41 public class _XIdlReflection extends MultiMethodTest{ 42 public XIdlReflection oObj = null; 43 protected final static String typeName = "com.sun.star.container.XNameAccess"; 44 45 /** 46 * Test calls the method and checks returned interface 47 * <code>com.sun.star.container.XNameAccess</code>: gets the name and the 48 * type and checks it. <p> 49 * Has <b> OK </b> status if returned name is equal to the name of the 50 * interface that was passed as parameter in the method call and if returned 51 * type is equal to <code>com.sun.star.uno.TypeClass.INTERFACE</code>. <p> 52 */ _forName()53 public void _forName() { 54 boolean result = true; 55 XIdlClass cls = oObj.forName(typeName); 56 57 if (cls != null) { 58 log.println("Class name: " + cls.getName()); 59 result &= cls.getTypeClass() == TypeClass.INTERFACE; 60 result &= typeName.equals(cls.getName()); 61 } else { 62 log.println("Method returned null"); 63 result = false; 64 } 65 66 tRes.tested("forName()", result); 67 } 68 69 /** 70 * Test creates the instance of <code>com.sun.star.io.Pipe</code>, 71 * calls the method using this instance as parameter and checks returned 72 * value. <p> 73 * Has <b> OK </b> status if the instance was created successfully, if 74 * returned value isn't null and no exceptions were thrown. <p> 75 */ _getType()76 public void _getType() { 77 boolean result = true; 78 Object obj = null; 79 80 try { 81 obj = ((XMultiServiceFactory)tParam.getMSF()). 82 createInstance("com.sun.star.io.Pipe") ; 83 } catch (com.sun.star.uno.Exception e) { 84 log.println("Can't create object"); 85 tRes.tested("getType()", false); 86 return; 87 } 88 89 if (obj == null) { 90 result = false; 91 log.println("Object wasn't created !"); 92 tRes.tested("getType()", false); 93 } 94 95 XIdlClass cls = oObj.getType(obj); 96 97 log.println("The name is " + cls.getName()); 98 99 tRes.tested("getType()", cls != null); 100 } 101 } 102 103 104