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.frame; 25 26 import com.sun.star.beans.PropertyValue; 27 28 import com.sun.star.frame.XModuleManager; 29 import lib.MultiMethodTest; 30 import lib.Status; 31 import lib.StatusException; 32 33 import com.sun.star.lang.IllegalArgumentException; 34 import com.sun.star.frame.UnknownModuleException; 35 36 37 /** 38 * Testing <code>com.sun.star.frame.XModuleManager</code> 39 * interface methods: 40 * <ul> 41 * <li><code> identify() </code></li> 42 * </ul><p> 43 * This test needs the following object relations : 44 * <ul> 45 * <li> <code>'XModuleManager.XFrame'</code> (of type <code>PropertyValue[]</code>): 46 * PropertyValue[n].Value : a XFrame 47 * PropertyValue[n].Name : the expected return value of <code>idendify()</code></li> 48 * <li> <code>'XModuleManager.XController'</code> (of type <code>PropertyValue[]</code>): 49 * PropertyValue[n].Value : a XController 50 * PropertyValue[n].Name : the expected return value of <code>idendify()</code></li> 51 * <li> <code>'XModuleManager.XModel'</code> (of type <code>PropertyValue[]</code>): 52 * PropertyValue[n].Value : a XFrame 53 * PropertyValue[n].Name : the expected return value of <code>idendify()</code></li> 54 * </ul> <p> 55 * Test is <b> NOT </b> multithread compilant. <p> 56 * @see com.sun.star.frame.XModuleManager 57 */ 58 public class _XModuleManager extends MultiMethodTest { 59 /** Test calls the method. <p> 60 * The onject relations <CODE>XModuleManager.XFrame</CODE>, 61 * <CODE>XModuleManager.XController</CODE> and <CODE>XModuleManager.XModel</CODE> 62 * are sequenzes of <CODE>PropertyValue</CODE>. The value of a PropertyValue 63 * containes a <CODE>XFrame</CODE>, <CODE>XController</CODE> or a 64 * <CODE>XModel</CODE>. The name of the PropertyValue contains the expected return 65 * value of method <CODE>indetify()</CODE> if the method was called with 66 * coresponding value.<p> 67 * As enhancement the method <CODE>identify()</CODE> was called with incvalid 68 * parameter. In this case the thrown exceptions was catched. 69 */ 70 public XModuleManager oObj = null; 71 /** 72 * Test calls the method. <p> 73 * Has <b> OK </b> status if the method returns expected values, that's equal to 74 * previously obtained object relation 'Frame'. 75 * The following method tests are to be completed successfully before: 76 * <ul> 77 * <li> <code> attachFrame() </code> : attachs frame obtained object 78 * relation 'Frame' </li> 79 * </ul> 80 */ 81 82 private PropertyValue[] xFrameSeq = null; 83 private PropertyValue[] xControllerSeq = null; 84 private PropertyValue[] xModelSeq = null; 85 /** Retrieves object relations. */ 86 87 public void before() { 88 89 xFrameSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XFrame") ; 90 91 if (xFrameSeq == null) throw new StatusException 92 (Status.failed("Relation 'xFrameSeq' not found.")) ; 93 94 95 xControllerSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XController") ; 96 97 if (xControllerSeq == null) throw new StatusException 98 (Status.failed("Relation 'xControllerSeq' not found.")) ; 99 100 101 xModelSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XModel") ; 102 103 if (xModelSeq == null) throw new StatusException 104 (Status.failed("Relation 'xModelSeq' not found.")) ; 105 } 106 107 /** The method <CODE>identify()</CODE> was tesed for every entry in sequeze of 108 * object relations. 109 */ 110 public void _identify() { 111 boolean ok = true; 112 log.println("testing frame sequenze..."); 113 ok &= testSequenze(xFrameSeq); 114 log.println("testing controller sequenze..."); 115 ok &= testSequenze(xControllerSeq); 116 log.println("testing model sequenze..."); 117 ok &= testSequenze(xModelSeq); 118 tRes.tested("identify()", ok); 119 120 log.println("testing invalid objects..."); 121 try{ 122 oObj.identify(oObj); 123 } catch (IllegalArgumentException e){ 124 log.println("expected exception."); 125 } catch (UnknownModuleException e){ 126 log.println("expected exception."); 127 } 128 } 129 130 private boolean testSequenze(PropertyValue[] sequenze){ 131 boolean ok = true; 132 for (int i = 0 ; i < sequenze.length; i++){ 133 try{ 134 log.println("testing '" + sequenze[i].Name + "'"); 135 if (oObj.identify(sequenze[i].Value).equals( 136 sequenze[i].Name)){ 137 ok &= ok; 138 }else{ 139 log.println("failure: returned value: '" + 140 oObj.identify(sequenze[i].Value) + 141 "' ,expected value: '" + sequenze[i].Name + "'"); 142 ok = false; 143 } 144 } catch (IllegalArgumentException e){ 145 log.println("Could not get value of sequenze '" + 146 sequenze[i].Name + "'"); 147 return false; 148 149 } catch (UnknownModuleException e){ 150 log.println("Could not indetify value of sequenze '" + 151 sequenze[i].Name + "'"); 152 return false; 153 } 154 } 155 return ok; 156 } 157 158 } 159 160