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
;
29 * Testing <code>com.sun.star.frame.XStorable</code>
32 * <li><code> getLocation() </code></li>
33 * <li><code> hasLocation() </code></li>
34 * <li><code> isReadonly() </code></li>
35 * <li><code> storeAsURL() </code></li>
36 * <li><code> storeToURL() </code></li>
37 * <li><code> store() </code></li>
39 * Test is <b> NOT </b> multithread compliant. <p>
40 * @see com.sun.star.frame.XStorable
42 public class _XStorable
extends MultiMethodTest
{
43 public XStorable oObj
= null; // oObj filled by MultiMethodTest
48 * Test calls the method. <p>
49 * Has <b> OK </b> status in three cases:
51 * <li>An object has location stored in. Then if method does not return
52 * null, it has <b> OK </b> status</li>
53 * <li>An object has no location stored in. Then method storeAsURL() is
54 * called, and if url is not null and equals to a url where component
55 * was stored, method has <b> OK </b> status</li>
56 * <li>An object has no location stored in. Then method storeAsURL() is
57 * called, and if url is null and method returns null too, method
58 * has <b> OK </b> status </li>
60 * The following method tests are to be completed successfully before :
62 * <li> <code> storeAsURL() </code> : stores the object's persistent data
63 * to a URL and lets the object become the representation of this new
67 public void _getLocation() {
68 if (oObj
.hasLocation()) {
69 // if it has location it should know it
70 tRes
.tested("getLocation()", oObj
.getLocation() != null);
72 // else try to obtain location
73 requiredMethod("storeAsURL()");
74 if (storeUrl
!= null) {
75 // if stored successfully - check location
76 log
.println(oObj
.getLocation() + "--" + storeUrl
);
77 tRes
.tested("getLocation()",
78 storeUrl
.equals(oObj
.getLocation()));
80 // if not - it should not have a location
81 tRes
.tested("getLocation()", oObj
.getLocation() == null);
87 * Test calls the method, then result is checked. <p>
88 * Has <b> OK </b> status if stored url is not null and method does not
89 * return null or if stored url is null and the method returns null.<p>
90 * The following method tests are to be completed successfully before :
92 * <li> <code> storeAsURL() </code>: stores the object's persistent data
93 * to a URL and lets the object become the representation of this new
97 public void _hasLocation() {
98 requiredMethod("storeAsURL()");
99 if (storeUrl
!= null) {
100 // if stored successfully - it should have a location
101 tRes
.tested("hasLocation()", oObj
.hasLocation());
103 // if not - it should not
104 tRes
.tested("hasLocation()", !oObj
.hasLocation());
109 * Test calls the method. <p>
110 * Has <b> OK </b> status if value, returned by the method is not equal to
111 * 'stored' variable. ( If it's readonly it should not have been stored. )
113 * The following method tests are to be completed successfully before :
115 * <li> <code> store() </code> : stores data to the URL from which it
119 public void _isReadonly() {
120 requiredMethod("store()");
121 tRes
.tested("isReadonly()", oObj
.isReadonly() != stored
);
125 * Object is stored into temporary directory. <p>
126 * Has <b> OK </b> status if the method successfully returns
127 * and no exceptions were thrown.
129 public void _storeAsURL() {
130 // getting a url to store
131 String url
= utils
.getOfficeTemp(
135 url
+= "xstorable.store.as.test";
136 log
.println("store as '" + url
+ "'");
138 oObj
.storeAsURL(url
, new PropertyValue
[0]);
140 tRes
.tested("storeAsURL()", true);
141 } catch (IOException e
) {
142 log
.println("Couldn't store as "+url
+" : "+e
.getMessage());
143 e
.printStackTrace(log
);
145 tRes
.tested("storeAsURL()", false);
148 log
.println("a url to store is not found");
153 * Object is stored into temporary directory. <p>
154 * Has <b> OK </b> status if the method successfully returns
155 * and no exceptions were thrown.
157 public void _storeToURL() {
158 // getting a url to store
159 String url
= utils
.getOfficeTemp(
163 url
+= "xstorable.store.as.test";
164 log
.println("store to '" + url
+ "'");
166 oObj
.storeToURL(url
, new PropertyValue
[0]);
167 tRes
.tested("storeToURL()", true);
168 } catch (IOException e
) {
169 log
.println("Couldn't store to "+url
+" : "+e
.getMessage());
170 e
.printStackTrace(log
);
171 tRes
.tested("storeToURL()", false);
174 log
.println("a url to store is not found");
179 * Test calls the method. Then result is checked.<p>
180 * Has <b> OK </b> status if:
182 * <li>component was stored, object is not readonly and has location</li>
183 * <li>exception occurred because of component is readonly
184 * and wasn't stored</li>
187 public void _store() {
188 IOException ioE
= null;
193 } catch (IOException e
) {
197 if (oObj
.hasLocation() && !oObj
.isReadonly()) {
198 tRes
.tested("store()", stored
);
200 log
.println("Couldn't store : " + ioE
.getMessage());
201 ioE
.printStackTrace(log
);
204 tRes
.tested("store()", !stored
);
206 if (!oObj
.hasLocation()) {
207 log
.println("Shouldn't store successfully"
208 + " a document without location");
210 log
.println("Shouldn't store successfully"
211 + " a read-only document");
217 }// finished class _XStorable