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