Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XStorable.java
blob6c476d15225505633481b10c03613fa467875d76
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;
28 /**
29 * Testing <code>com.sun.star.frame.XStorable</code>
30 * interface methods:
31 * <ul>
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>
38 * </ul><p>
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
44 String storeUrl;
45 boolean stored;
47 /**
48 * Test calls the method. <p>
49 * Has <b> OK </b> status in three cases:
50 * <ol>
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>
59 * </ol><p>
60 * The following method tests are to be completed successfully before :
61 * <ul>
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
64 * URL</li>
65 * </ul>
67 public void _getLocation() {
68 if (oObj.hasLocation()) {
69 // if it has location it should know it
70 tRes.tested("getLocation()", oObj.getLocation() != null);
71 } else {
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()));
79 } else {
80 // if not - it should not have a location
81 tRes.tested("getLocation()", oObj.getLocation() == null);
86 /**
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 :
91 * <ul>
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
94 * URL</li>
95 * </ul>
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());
102 } else {
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. )
112 * <p>
113 * The following method tests are to be completed successfully before :
114 * <ul>
115 * <li> <code> store() </code> : stores data to the URL from which it
116 * was loaded </li>
117 * </ul>
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 an url to store
131 String url = utils.getOfficeTemp(
132 tParam.getMSF());
134 if (url != null) {
135 url += "xstorable.store.as.test";
136 log.println("store as '" + url + "'");
137 try {
138 oObj.storeAsURL(url, new PropertyValue[0]);
139 storeUrl = url;
140 tRes.tested("storeAsURL()", true);
141 } catch (IOException e) {
142 log.println("Couldn't store as "+url+" : "+e.getMessage());
143 e.printStackTrace(log);
144 storeUrl = null;
145 tRes.tested("storeAsURL()", false);
147 } else {
148 log.println("an 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 an url to store
159 String url = utils.getOfficeTemp(
160 tParam.getMSF());
162 if (url != null) {
163 url += "xstorable.store.as.test";
164 log.println("store to '" + url + "'");
165 try {
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);
173 } else {
174 log.println("an url to store is not found");
179 * Test calls the method. Then result is checked.<p>
180 * Has <b> OK </b> status if:
181 * <ol>
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>
185 * </ol>
187 public void _store() {
188 IOException ioE = null;
190 try {
191 oObj.store();
192 stored = true;
193 } catch (IOException e) {
194 stored = false;
195 ioE = e;
197 if (oObj.hasLocation() && !oObj.isReadonly()) {
198 tRes.tested("store()", stored);
199 if (!stored) {
200 log.println("Couldn't store : " + ioE.getMessage());
201 ioE.printStackTrace(log);
203 } else {
204 tRes.tested("store()", !stored);
205 if (stored) {
206 if (!oObj.hasLocation()) {
207 log.println("Shouldn't store successfully"
208 + " a document without location");
209 } else {
210 log.println("Shouldn't store successfully"
211 + " a read-only document");
217 }// finished class _XStorable