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 lib.MultiMethodTest; 27 import util.utils; 28 29 import com.sun.star.beans.PropertyValue; 30 import com.sun.star.frame.XStorable; 31 import com.sun.star.io.IOException; 32 import com.sun.star.lang.XMultiServiceFactory; 33 34 /** 35 * Testing <code>com.sun.star.frame.XStorable</code> 36 * interface methods: 37 * <ul> 38 * <li><code> getLocation() </code></li> 39 * <li><code> hasLocation() </code></li> 40 * <li><code> isReadonly() </code></li> 41 * <li><code> storeAsURL() </code></li> 42 * <li><code> storeToURL() </code></li> 43 * <li><code> store() </code></li> 44 * </ul><p> 45 * Test is <b> NOT </b> multithread compilant. <p> 46 * @see com.sun.star.frame.XStorable 47 */ 48 public class _XStorable extends MultiMethodTest { 49 public XStorable oObj = null; // oObj filled by MultiMethodTest 50 String storeUrl; 51 boolean stored; 52 53 /** 54 * Test calls the method. <p> 55 * Has <b> OK </b> status in three cases: 56 * <ol> 57 * <li>An object has location stored in. Then if method does not return 58 * null, it has <b> OK </b> status</li> 59 * <li>An object has no location stored in. Then method storeAsURL() is 60 * called, and if url is not null and equals to a url where component 61 * was stored, method has <b> OK </b> status</li> 62 * <li>An object has no location stored in. Then method storeAsURL() is 63 * called, and if url is null and method returns null too, method 64 * has <b> OK </b> status </li> 65 * </ol><p> 66 * The following method tests are to be completed successfully before : 67 * <ul> 68 * <li> <code> storeAsURL() </code> : stores the object's persistent data 69 * to a URL and lets the object become the representation of this new 70 * URL</li> 71 * </ul> 72 */ 73 public void _getLocation() { 74 if (oObj.hasLocation()) { 75 // if it has location it should know it 76 tRes.tested("getLocation()", oObj.getLocation() != null); 77 } else { 78 // else try to obtain location 79 requiredMethod("storeAsURL()"); 80 if (storeUrl != null) { 81 // if stored succesfully - check location 82 log.println(oObj.getLocation() + "--" + storeUrl); 83 tRes.tested("getLocation()", 84 storeUrl.equals(oObj.getLocation())); 85 } else { 86 // if not - it should not have a location 87 tRes.tested("getLocation()", oObj.getLocation() == null); 88 } 89 } 90 } 91 92 /** 93 * Test calls the method, then result is checked. <p> 94 * Has <b> OK </b> status if stored url is not null and method does not 95 * return null or if stored url is null and the method returns null.<p> 96 * The following method tests are to be completed successfully before : 97 * <ul> 98 * <li> <code> storeAsURL() </code>: stores the object's persistent data 99 * to a URL and lets the object become the representation of this new 100 * URL</li> 101 * </ul> 102 */ 103 public void _hasLocation() { 104 requiredMethod("storeAsURL()"); 105 if (storeUrl != null) { 106 // if stored succesfully - it should have a location 107 tRes.tested("hasLocation()", oObj.hasLocation()); 108 } else { 109 // if not - it should not 110 tRes.tested("hasLocation()", !oObj.hasLocation()); 111 } 112 } 113 114 /** 115 * Test calls the method. <p> 116 * Has <b> OK </b> status if value, returned by the method is not equal to 117 * 'stored' variable. ( If it's readonly it should not have been stored. ) 118 * <p> 119 * The following method tests are to be completed successfully before : 120 * <ul> 121 * <li> <code> store() </code> : stores data to the URL from which it 122 * was loaded </li> 123 * </ul> 124 */ 125 public void _isReadonly() { 126 requiredMethod("store()"); 127 tRes.tested("isReadonly()", oObj.isReadonly() != stored); 128 } 129 130 /** 131 * Object is stored into temporary directory. <p> 132 * Has <b> OK </b> status if the method successfully returns 133 * and no exceptions were thrown. 134 */ 135 public void _storeAsURL() { 136 // getting an url to store 137 String url = (String) utils.getOfficeTemp( 138 (XMultiServiceFactory)tParam.getMSF()); 139 140 if (url != null) { 141 url += "xstorable.store.as.test"; 142 log.println("store as '" + url + "'"); 143 try { 144 oObj.storeAsURL(url, new PropertyValue[0]); 145 storeUrl = url; 146 tRes.tested("storeAsURL()", true); 147 } catch (IOException e) { 148 log.println("Couldn't store as "+url+" : "+e.getMessage()); 149 e.printStackTrace(log); 150 storeUrl = null; 151 tRes.tested("storeAsURL()", false); 152 } 153 } else { 154 log.println("an url to store is not found"); 155 } 156 } 157 158 /** 159 * Object is stored into temporary directory. <p> 160 * Has <b> OK </b> status if the method successfully returns 161 * and no exceptions were thrown. 162 */ 163 public void _storeToURL() { 164 // getting an url to store 165 String url = (String) utils.getOfficeTemp( 166 (XMultiServiceFactory)tParam.getMSF()); 167 168 if (url != null) { 169 url += "xstorable.store.as.test"; 170 log.println("store to '" + url + "'"); 171 try { 172 oObj.storeToURL(url, new PropertyValue[0]); 173 tRes.tested("storeToURL()", true); 174 } catch (IOException e) { 175 log.println("Couldn't store to "+url+" : "+e.getMessage()); 176 e.printStackTrace(log); 177 tRes.tested("storeToURL()", false); 178 } 179 } else { 180 log.println("an url to store is not found"); 181 } 182 } 183 184 /** 185 * Test calls the method. Then result is checked.<p> 186 * Has <b> OK </b> status if: 187 * <ol> 188 * <li>component was stored, object is not readonly and has location</li> 189 * <li>exception occured because of component is readonly 190 * and wasn't stored</li> 191 * </ol> 192 */ 193 public void _store() { 194 IOException ioE = null; 195 196 try { 197 oObj.store(); 198 stored = true; 199 } catch (IOException e) { 200 stored = false; 201 ioE = e; 202 } 203 if (oObj.hasLocation() && !oObj.isReadonly()) { 204 tRes.tested("store()", stored); 205 if (!stored) { 206 log.println("Couldn't store : " + ioE.getMessage()); 207 ioE.printStackTrace(log); 208 } 209 } else { 210 tRes.tested("store()", !stored); 211 if (stored) { 212 if (!oObj.hasLocation()) { 213 log.println("Shouldn't store successfully" 214 + " a document without location"); 215 } else { 216 log.println("Shouldn't store successfully" 217 + " a read-only document"); 218 } 219 } 220 } 221 } 222 223 }// finished class _XStorable 224 225