bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XStorable.java
blob86a4eabc11f23b78a63efdb1bf1002246a08ea5b
1 /*
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 .
19 package ifc.frame;
21 import lib.MultiMethodTest;
22 import util.utils;
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;
29 /**
30 * Testing <code>com.sun.star.frame.XStorable</code>
31 * interface methods:
32 * <ul>
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>
39 * </ul><p>
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
45 String storeUrl;
46 boolean stored;
48 /**
49 * Test calls the method. <p>
50 * Has <b> OK </b> status in three cases:
51 * <ol>
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>
60 * </ol><p>
61 * The following method tests are to be completed successfully before :
62 * <ul>
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
65 * URL</li>
66 * </ul>
68 public void _getLocation() {
69 if (oObj.hasLocation()) {
70 // if it has location it should know it
71 tRes.tested("getLocation()", oObj.getLocation() != null);
72 } else {
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()));
80 } else {
81 // if not - it should not have a location
82 tRes.tested("getLocation()", oObj.getLocation() == null);
87 /**
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 :
92 * <ul>
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
95 * URL</li>
96 * </ul>
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());
103 } else {
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. )
113 * <p>
114 * The following method tests are to be completed successfully before :
115 * <ul>
116 * <li> <code> store() </code> : stores data to the URL from which it
117 * was loaded </li>
118 * </ul>
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());
135 if (url != null) {
136 url += "xstorable.store.as.test";
137 log.println("store as '" + url + "'");
138 try {
139 oObj.storeAsURL(url, new PropertyValue[0]);
140 storeUrl = url;
141 tRes.tested("storeAsURL()", true);
142 } catch (IOException e) {
143 log.println("Couldn't store as "+url+" : "+e.getMessage());
144 e.printStackTrace(log);
145 storeUrl = null;
146 tRes.tested("storeAsURL()", false);
148 } else {
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());
163 if (url != null) {
164 url += "xstorable.store.as.test";
165 log.println("store to '" + url + "'");
166 try {
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);
174 } else {
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:
182 * <ol>
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>
186 * </ol>
188 public void _store() {
189 IOException ioE = null;
191 try {
192 oObj.store();
193 stored = true;
194 } catch (IOException e) {
195 stored = false;
196 ioE = e;
198 if (oObj.hasLocation() && !oObj.isReadonly()) {
199 tRes.tested("store()", stored);
200 if (!stored) {
201 log.println("Couldn't store : " + ioE.getMessage());
202 ioE.printStackTrace(log);
204 } else {
205 tRes.tested("store()", !stored);
206 if (stored) {
207 if (!oObj.hasLocation()) {
208 log.println("Shouldn't store successfully"
209 + " a document without location");
210 } else {
211 log.println("Shouldn't store successfully"
212 + " a read-only document");
218 }// finished class _XStorable