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.frame;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.beans.PropertyState;
29 import com.sun.star.beans.PropertyValue;
30 import com.sun.star.frame.XComponentLoader;
31 import com.sun.star.lang.XComponent;
32 
33 
34 /**
35 * Testing <code>com.sun.star.frame.XComponentLoader</code>
36 * interface methods:
37 * <ul>
38 *  <li><code> loadComponentFromURL() </code></li>
39 * </ul><p>
40 * Test is <b> NOT </b> multithread compilant. <p>
41 * @see com.sun.star.frame.XComponentLoader
42 */
43 public class _XComponentLoader extends MultiMethodTest {
44     public XComponentLoader oObj = null; // oObj filled by MultiMethodTest
45 
46     /**
47     * Method which tests the objects ability to load a
48     * component from URL. All available components are loaded by turns. <p>
49     * Has <b> OK </b> status if the method successfully returns
50     * and no exceptions were thrown. <p>
51     * @see XComponent
52     */
_loadComponentFromURL()53     public void _loadComponentFromURL() {
54         boolean result = true;
55 
56         log.println("testing loadComponentFromURL() ... ");
57         try {
58             PropertyValue [] szEmptyArgs = new PropertyValue [0];
59             String frameName = "_blank";
60             XComponent oDoc = null;
61 
62             log.println("load writer doc that contains links");
63             PropertyValue [] szArgs = new PropertyValue [1];
64             PropertyValue Arg = new PropertyValue();
65             Arg.Name = "UpdateDocMode";
66             Arg.Value = new Short(com.sun.star.document.UpdateDocMode.NO_UPDATE);
67             szArgs[0]=Arg;
68             String url = util.utils.getFullTestURL("Writer_link.sxw");
69             log.println("try to load '" + url + "'");
70             oDoc = oObj.loadComponentFromURL(
71                             url, frameName, 0, szArgs);
72 
73             try {
74                 Thread.sleep(500);
75             }
76             catch (InterruptedException ex) {
77             }
78 
79             oDoc.dispose();
80 
81             url = util.utils.getFullTestURL("Calc_Link.sxc");
82             log.println("try to load '" + url + "'");
83             oDoc = oObj.loadComponentFromURL(
84                             url, frameName, 0, szArgs);
85 
86             try {
87                 Thread.sleep(500);
88             }
89             catch (InterruptedException ex) {
90             }
91 
92             oDoc.dispose();
93 
94 
95 
96             log.println("load a blank impress doc");
97             Arg.Name = "OpenFlags";
98             Arg.Value = "S";
99             Arg.Handle = -1;
100             Arg.State = PropertyState.DEFAULT_VALUE;
101             szArgs[0]=Arg;
102             oDoc = oObj.loadComponentFromURL(
103                             "private:factory/simpress", frameName, 0, szArgs );
104 
105             log.println("disposing impress doc");
106             oDoc.dispose();
107 
108             log.println("load a blank writer doc");
109             oDoc = oObj.loadComponentFromURL(
110                         "private:factory/swriter", frameName, 0, szEmptyArgs );
111 
112             log.println("disposing writer doc");
113             oDoc.dispose();
114 
115             log.println("load a blank calc doc");
116             oDoc = oObj.loadComponentFromURL(
117                         "private:factory/scalc", frameName, 0, szEmptyArgs );
118 
119             log.println("disposing calc doc");
120             oDoc.dispose();
121 
122             log.println("load a blank draw doc");
123             oDoc = oObj.loadComponentFromURL(
124                         "private:factory/sdraw", frameName, 0, szEmptyArgs );
125 
126             log.println("disposing draw doc");
127             oDoc.dispose();
128 
129             log.println("load a blank math doc");
130             oDoc = oObj.loadComponentFromURL(
131                         "private:factory/smath", frameName, 0, szEmptyArgs );
132 
133             log.println("disposing math doc");
134             oDoc.dispose();
135 
136         }
137         catch (com.sun.star.lang.IllegalArgumentException e) {
138             log.println("Exception occured while loading");
139             e.printStackTrace(log);
140             result=false;
141         }
142         catch (com.sun.star.io.IOException e) {
143             log.println("Exception occured while loading");
144             e.printStackTrace(log);
145             result=false;
146         }
147 
148         tRes.tested("loadComponentFromURL()", result);
149         return;
150     }
151 
152 }
153 
154