1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XStorable.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
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
;
42 * Testing <code>com.sun.star.frame.XStorable</code>
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>
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
61 * Test calls the method. <p>
62 * Has <b> OK </b> status in three cases:
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>
73 * The following method tests are to be completed successfully before :
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
80 public void _getLocation() {
81 if (oObj
.hasLocation()) {
82 // if it has location it should know it
83 tRes
.tested("getLocation()", oObj
.getLocation() != null);
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()));
93 // if not - it should not have a location
94 tRes
.tested("getLocation()", oObj
.getLocation() == null);
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 :
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
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());
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. )
126 * The following method tests are to be completed successfully before :
128 * <li> <code> store() </code> : stores data to the URL from which it
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());
148 url
+= "xstorable.store.as.test";
149 log
.println("store as '" + url
+ "'");
151 oObj
.storeAsURL(url
, new PropertyValue
[0]);
153 tRes
.tested("storeAsURL()", true);
154 } catch (IOException e
) {
155 log
.println("Couldn't store as "+url
+" : "+e
.getMessage());
156 e
.printStackTrace(log
);
158 tRes
.tested("storeAsURL()", false);
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());
176 url
+= "xstorable.store.as.test";
177 log
.println("store to '" + url
+ "'");
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);
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:
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>
200 public void _store() {
201 IOException ioE
= null;
206 } catch (IOException e
) {
210 if (oObj
.hasLocation() && !oObj
.isReadonly()) {
211 tRes
.tested("store()", stored
);
213 log
.println("Couldn't store : " + ioE
.getMessage());
214 ioE
.printStackTrace(log
);
217 tRes
.tested("store()", !stored
);
219 if (!oObj
.hasLocation()) {
220 log
.println("Shouldn't store successfully"
221 + " a document without location");
223 log
.println("Shouldn't store successfully"
224 + " a read-only document");
230 }// finished class _XStorable