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._fwl;
25 
26 import com.sun.star.beans.NamedValue;
27 import com.sun.star.beans.Property;
28 import com.sun.star.beans.PropertyVetoException;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.beans.XPropertySetInfo;
31 import com.sun.star.lang.IllegalArgumentException;
32 import com.sun.star.lang.WrappedTargetException;
33 import com.sun.star.uno.UnoRuntime;
34 import java.io.PrintWriter;
35 import java.util.HashSet;
36 import java.util.Set;
37 
38 import lib.Status;
39 import lib.StatusException;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
43 import util.utils;
44 
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.uno.XInterface;
47 
48 /**
49  * Test for object which is represented by service
50  * <code>com.sun.star.comp.framework.PathSettings</code>. <p>
51  *
52  * Object implements the following interfaces :
53  * <ul>
54  *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
55  *  <li> <code>com::sun::star::util::PathSettings</code></li>
56  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
57  *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
58  * </ul> <p>
59  *
60  * @see com.sun.star.beans.XFastPropertySet
61  * @see com.sun.star.util.PathSettings
62  * @see com.sun.star.beans.XPropertySet
63  * @see com.sun.star.beans.XMultiPropertySet
64  * @see ifc.beans._XFastPropertySet
65  * @see ifc.util._PathSettings
66  * @see ifc.beans._XPropertySet
67  * @see ifc.beans._XMultiPropertySet
68  */
69 public class PathSettings extends TestCase {
70 
71     private static NamedValue[]  m_Properties;
72     private static XPropertySet xPS;
73 
74     /**
75      * restores the old values of the path settings
76      * @param tParam the test parameter
77      * @param log the log writer
78      */
cleanup(TestParameters tParam, PrintWriter log)79     protected void cleanup(TestParameters tParam, PrintWriter log) {
80         log.println("restore old values of path settings...");
81 
82         for (int i=0; i < m_Properties.length; i++){
83             try{
84 
85                 xPS.setPropertyValue(m_Properties[i].Name, m_Properties[i].Value);
86 
87             } catch (com.sun.star.beans.UnknownPropertyException e){
88             } catch (PropertyVetoException e){
89             } catch (IllegalArgumentException e){
90             } catch (WrappedTargetException e){
91             }
92         }
93     }
94     /**
95      * Creating a Testenvironment for the interfaces to be tested.
96      * Creates an instance of the service
97      * <code>com.sun.star.comp.framework.PathSettings</code>.
98      */
createTestEnvironment(TestParameters Param, PrintWriter log)99     protected TestEnvironment createTestEnvironment
100             (TestParameters Param, PrintWriter log) {
101         XInterface oObj = null;
102         Object oInterface = null ;
103 
104         //now get the OButtonControl
105         try {
106             oInterface = ((XMultiServiceFactory)Param.getMSF()).createInstance
107                 ("com.sun.star.comp.framework.PathSettings") ;
108         } catch (com.sun.star.uno.Exception e) {
109             log.println("Couldn't get service");
110             e.printStackTrace(log);
111             throw new StatusException("Couldn't get GridControl", e );
112         }
113 
114         if (oInterface == null) {
115             log.println("Service wasn't created") ;
116             throw new StatusException(Status.failed("Service wasn't created")) ;
117         }
118 
119         oObj = (XInterface) oInterface ;
120         log.println("ImplName: "+utils.getImplName(oObj));
121 
122         log.println( "creating a new environment for object" );
123         TestEnvironment tEnv = new TestEnvironment( oObj );
124 
125         Set exclProps = new HashSet();
126         exclProps.add("UIConfig");
127         tEnv.addObjRelation("XFastPropertySet.ExcludeProps", exclProps);
128         tEnv.addObjRelation("XMultiPropertySet.ExcludeProps", exclProps);
129 
130         saveAllPropertyValues(oObj);
131 
132         return tEnv;
133     } // finish method getTestEnvironment
134 
saveAllPropertyValues(XInterface oObj)135     private void saveAllPropertyValues(XInterface oObj){
136 
137         xPS = (XPropertySet) UnoRuntime.queryInterface(
138                                                 XPropertySet.class, oObj);
139 
140         XPropertySetInfo xPSI = xPS.getPropertySetInfo();
141 
142         Property[] allProperties = xPSI.getProperties();
143         m_Properties = new NamedValue[allProperties.length];
144 
145         for (int i=0; i < allProperties.length; i++){
146             try{
147                 m_Properties[i] = new NamedValue(allProperties[i].Name,
148                                    xPS.getPropertyValue(allProperties[i].Name));
149 
150             } catch (com.sun.star.beans.UnknownPropertyException e){
151             } catch (WrappedTargetException e){
152             }
153         }
154     }
155 
156 }
157 
158