2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
24 import com
.sun
.star
.beans
.PropertyValue
;
25 import com
.sun
.star
.frame
.XStorable
;
26 import com
.sun
.star
.io
.IOException
;
27 import com
.sun
.star
.lang
.XMultiServiceFactory
;
30 * Testing <code>com.sun.star.frame.XStorable</code>
33 * <li><code> getLocation() </code></li>
34 * <li><code> hasLocation() </code></li>
35 * <li><code> isReadonly() </code></li>
36 * <li><code> storeAsURL() </code></li>
37 * <li><code> storeToURL() </code></li>
38 * <li><code> store() </code></li>
40 * Test is <b> NOT </b> multithread compilant. <p>
41 * @see com.sun.star.frame.XStorable
43 public class _XStorable
extends MultiMethodTest
{
44 public XStorable oObj
= null; // oObj filled by MultiMethodTest
49 * Test calls the method. <p>
50 * Has <b> OK </b> status in three cases:
52 * <li>An object has location stored in. Then if method does not return
53 * null, it has <b> OK </b> status</li>
54 * <li>An object has no location stored in. Then method storeAsURL() is
55 * called, and if url is not null and equals to a url where component
56 * was stored, method has <b> OK </b> status</li>
57 * <li>An object has no location stored in. Then method storeAsURL() is
58 * called, and if url is null and method returns null too, method
59 * has <b> OK </b> status </li>
61 * The following method tests are to be completed successfully before :
63 * <li> <code> storeAsURL() </code> : stores the object's persistent data
64 * to a URL and lets the object become the representation of this new
68 public void _getLocation() {
69 if (oObj
.hasLocation()) {
70 // if it has location it should know it
71 tRes
.tested("getLocation()", oObj
.getLocation() != null);
73 // else try to obtain location
74 requiredMethod("storeAsURL()");
75 if (storeUrl
!= null) {
76 // if stored successfully - check location
77 log
.println(oObj
.getLocation() + "--" + storeUrl
);
78 tRes
.tested("getLocation()",
79 storeUrl
.equals(oObj
.getLocation()));
81 // if not - it should not have a location
82 tRes
.tested("getLocation()", oObj
.getLocation() == null);
88 * Test calls the method, then result is checked. <p>
89 * Has <b> OK </b> status if stored url is not null and method does not
90 * return null or if stored url is null and the method returns null.<p>
91 * The following method tests are to be completed successfully before :
93 * <li> <code> storeAsURL() </code>: stores the object's persistent data
94 * to a URL and lets the object become the representation of this new
98 public void _hasLocation() {
99 requiredMethod("storeAsURL()");
100 if (storeUrl
!= null) {
101 // if stored successfully - it should have a location
102 tRes
.tested("hasLocation()", oObj
.hasLocation());
104 // if not - it should not
105 tRes
.tested("hasLocation()", !oObj
.hasLocation());
110 * Test calls the method. <p>
111 * Has <b> OK </b> status if value, returned by the method is not equal to
112 * 'stored' variable. ( If it's readonly it should not have been stored. )
114 * The following method tests are to be completed successfully before :
116 * <li> <code> store() </code> : stores data to the URL from which it
120 public void _isReadonly() {
121 requiredMethod("store()");
122 tRes
.tested("isReadonly()", oObj
.isReadonly() != stored
);
126 * Object is stored into temporary directory. <p>
127 * Has <b> OK </b> status if the method successfully returns
128 * and no exceptions were thrown.
130 public void _storeAsURL() {
131 // getting an url to store
132 String url
= utils
.getOfficeTemp(
133 (XMultiServiceFactory
)tParam
.getMSF());
136 url
+= "xstorable.store.as.test";
137 log
.println("store as '" + url
+ "'");
139 oObj
.storeAsURL(url
, new PropertyValue
[0]);
141 tRes
.tested("storeAsURL()", true);
142 } catch (IOException e
) {
143 log
.println("Couldn't store as "+url
+" : "+e
.getMessage());
144 e
.printStackTrace(log
);
146 tRes
.tested("storeAsURL()", false);
149 log
.println("an url to store is not found");
154 * Object is stored into temporary directory. <p>
155 * Has <b> OK </b> status if the method successfully returns
156 * and no exceptions were thrown.
158 public void _storeToURL() {
159 // getting an url to store
160 String url
= utils
.getOfficeTemp(
161 (XMultiServiceFactory
)tParam
.getMSF());
164 url
+= "xstorable.store.as.test";
165 log
.println("store to '" + url
+ "'");
167 oObj
.storeToURL(url
, new PropertyValue
[0]);
168 tRes
.tested("storeToURL()", true);
169 } catch (IOException e
) {
170 log
.println("Couldn't store to "+url
+" : "+e
.getMessage());
171 e
.printStackTrace(log
);
172 tRes
.tested("storeToURL()", false);
175 log
.println("an url to store is not found");
180 * Test calls the method. Then result is checked.<p>
181 * Has <b> OK </b> status if:
183 * <li>component was stored, object is not readonly and has location</li>
184 * <li>exception occurred because of component is readonly
185 * and wasn't stored</li>
188 public void _store() {
189 IOException ioE
= null;
194 } catch (IOException e
) {
198 if (oObj
.hasLocation() && !oObj
.isReadonly()) {
199 tRes
.tested("store()", stored
);
201 log
.println("Couldn't store : " + ioE
.getMessage());
202 ioE
.printStackTrace(log
);
205 tRes
.tested("store()", !stored
);
207 if (!oObj
.hasLocation()) {
208 log
.println("Shouldn't store successfully"
209 + " a document without location");
211 log
.println("Shouldn't store successfully"
212 + " a read-only document");
218 }// finished class _XStorable