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 mod._sd;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.document.XLinkTargetSupplier;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.document.LinkTargets</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 *  <li> <code>com::sun::star::container::XNameAccess</code></li>
46 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
47 * </ul>
48 * @see com.sun.star.document.LinkTargets
49 * @see com.sun.star.container.XNameAccess
50 * @see com.sun.star.container.XElementAccess
51 * @see ifc.container._XNameAccess
52 * @see ifc.container._XElementAccess
53 */
54 public class SdDocLinkTargets extends TestCase {
55     XComponent xDrawDoc;
56 
57     /**
58     * Creates Drawing document.
59     */
initialize(TestParameters Param, PrintWriter log)60     protected void initialize(TestParameters Param, PrintWriter log) {
61         // get a soffice factory object
62         SOfficeFactory SOF = SOfficeFactory.getFactory(
63                                 (XMultiServiceFactory)Param.getMSF());
64 
65         try {
66             log.println( "creating a draw document" );
67             xDrawDoc = SOF.createDrawDoc(null);
68         } catch (com.sun.star.uno.Exception e) {
69             // Some exception occures.FAILED
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73     }
74 
75     /**
76     * Disposes Drawing document.
77     */
cleanup( TestParameters Param, PrintWriter log)78     protected void cleanup( TestParameters Param, PrintWriter log) {
79         log.println("disposing xDrawDoc");
80         util.DesktopTools.closeDoc(xDrawDoc);
81     }
82 
83     /**
84     * Creating a Testenvironment for the interfaces to be tested.
85     * Retrieves the possible links to childrens of the drawing document using
86     * the interface <code>XLinkTargetSupplier</code>. The retrieved collection
87     * is the instance of the service <code>com.sun.star.document.LinkTargets</code>.
88     * @see com.sun.star.document.XLinkTargetSupplier
89     * @see com.sun.star.document.LinkTargets
90     */
createTestEnvironment( TestParameters Param, PrintWriter log)91     public TestEnvironment createTestEnvironment(
92         TestParameters Param, PrintWriter log) throws StatusException {
93 
94         // get the Links here
95         log.println( "getting Links" );
96         XLinkTargetSupplier oLTS = (XLinkTargetSupplier)
97             UnoRuntime.queryInterface(XLinkTargetSupplier.class,xDrawDoc);
98         XInterface oObj = oLTS.getLinks();
99 
100         log.println( "creating a new environment for drawpage object" );
101         TestEnvironment tEnv = new TestEnvironment( oObj );
102 
103         return tEnv;
104     } // finish method createTestEnvironment
105 
106 }    // finish class SdDocLinkTargets
107 
108