1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.document;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.document.XStandaloneDocumentInfo;
32 import com.sun.star.io.IOException;
33 import com.sun.star.uno.UnoRuntime;
34 
35 /**
36 * Testing <code>com.sun.star.document.XStandaloneDocumentInfo</code>
37 * interface methods. <p>
38 * This test needs the following object relations :
39 * <ul>
40 *  <li> <code>'DOCURL'</code> (of type <code>String</code>):
41 *   URL of document which info is loaded.</li>
42 * <ul> <p>
43 * Test is <b> NOT </b> multithread compilant. <p>
44 * @see com.sun.star.document.XStandaloneDocumentInfo
45 */
46 public class _XStandaloneDocumentInfo extends MultiMethodTest {
47 
48     public XStandaloneDocumentInfo oObj = null;
49     String url = null;
50 
before()51     protected void before() {
52         url = (String)tEnv.getObjRelation("DOCURL");
53         if (url == null) {
54             throw new StatusException
55                 (Status.failed("Relation 'DOCURL' not found"));
56         }
57     }
58 
59     String oldProp = null;
60     String newProp = null;
61     /**
62     * Sets new value of the property 'Author' and calls the method. <p>
63     * Has <b> OK </b> status if no exception occured.
64     */
_storeIntoURL()65     public void _storeIntoURL() {
66         try {
67             oObj.loadFromURL(url);
68             XPropertySet propSet = (XPropertySet)
69                 UnoRuntime.queryInterface(XPropertySet.class, oObj);
70             oldProp = (String)propSet.getPropertyValue("Author");
71             newProp = oldProp + "_";
72             propSet.setPropertyValue("Author", newProp);
73 
74             oObj.storeIntoURL(url);
75             tRes.tested("storeIntoURL()", true);
76         } catch (IOException e) {
77             log.println("Couldn't store to " + url
78                     + " : " + e.getMessage());
79             e.printStackTrace(log);
80             tRes.tested("storeIntoURL()", false);
81         } catch(com.sun.star.lang.WrappedTargetException e) {
82             log.println("Couldn't get/set property 'Author':" + e);
83             tRes.tested("storeIntoURL()", false);
84         } catch(com.sun.star.beans.UnknownPropertyException e) {
85             log.println("Couldn't get/set property 'Author':" + e);
86             tRes.tested("storeIntoURL()", false);
87         } catch(com.sun.star.lang.IllegalArgumentException e) {
88             log.println("Couldn't get/set property 'Author':" + e);
89             tRes.tested("storeIntoURL()", false);
90         } catch(com.sun.star.beans.PropertyVetoException e) {
91             log.println("Couldn't get/set property 'Author':" + e);
92             tRes.tested("storeIntoURL()", false);
93         }
94     }
95 
96     /**
97     * Calls the method and checks value of the property 'Author'. <p>
98     * Has <b> OK </b> status if no exception occured and value of the property
99     * 'Author' is equal to value that was set in the method
100     * <code>storeIntoURL</code>.
101     */
_loadFromURL()102     public void _loadFromURL() {
103         requiredMethod("storeIntoURL()");
104         try {
105             oObj.loadFromURL(url);
106             XPropertySet propSet = (XPropertySet)
107                 UnoRuntime.queryInterface(XPropertySet.class, oObj);
108             String resProp = (String)propSet.getPropertyValue("Author");
109             log.println("Was: '" + oldProp + "',Set: '" + newProp +
110                         "', New: " + resProp + "'");
111             tRes.tested("loadFromURL()", resProp.equals(newProp) );
112         } catch (IOException e) {
113             log.println("Couldn't load from " + url
114                     + " : " + e.getMessage());
115             e.printStackTrace(log);
116             tRes.tested("loadFromURL()", false);
117         } catch(com.sun.star.lang.WrappedTargetException e) {
118             log.println("Couldn't get/set property 'Author':" + e);
119             tRes.tested("loadFromURL()", false);
120         } catch(com.sun.star.beans.UnknownPropertyException e) {
121             log.println("Couldn't get/set property 'Author':" + e);
122             tRes.tested("loadFromURL()", false);
123         }
124     }
125 
126 }  // finish class _XStandaloneDocumentInfo
127 
128