1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._fwl;
29 
30 import com.sun.star.beans.NamedValue;
31 import com.sun.star.beans.Property;
32 import com.sun.star.beans.PropertyVetoException;
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.beans.XPropertySetInfo;
35 import com.sun.star.lang.IllegalArgumentException;
36 import com.sun.star.lang.WrappedTargetException;
37 import com.sun.star.uno.UnoRuntime;
38 import java.io.PrintWriter;
39 import java.util.HashSet;
40 import java.util.Set;
41 
42 import lib.Status;
43 import lib.StatusException;
44 import lib.TestCase;
45 import lib.TestEnvironment;
46 import lib.TestParameters;
47 import util.utils;
48 
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.uno.XInterface;
51 
52 /**
53  * Test for object which is represented by service
54  * <code>com.sun.star.comp.framework.PathSettings</code>. <p>
55  *
56  * Object implements the following interfaces :
57  * <ul>
58  *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
59  *  <li> <code>com::sun::star::util::PathSettings</code></li>
60  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
61  *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
62  * </ul> <p>
63  *
64  * @see com.sun.star.beans.XFastPropertySet
65  * @see com.sun.star.util.PathSettings
66  * @see com.sun.star.beans.XPropertySet
67  * @see com.sun.star.beans.XMultiPropertySet
68  * @see ifc.beans._XFastPropertySet
69  * @see ifc.util._PathSettings
70  * @see ifc.beans._XPropertySet
71  * @see ifc.beans._XMultiPropertySet
72  */
73 public class PathSettings extends TestCase {
74 
75     private static NamedValue[]  m_Properties;
76     private static XPropertySet xPS;
77 
78     /**
79      * restores the old values of the path settings
80      * @param tParam the test parameter
81      * @param log the log writer
82      */
83     protected void cleanup(TestParameters tParam, PrintWriter log) {
84         log.println("restore old values of path settings...");
85 
86         for (int i=0; i < m_Properties.length; i++){
87             try{
88 
89                 xPS.setPropertyValue(m_Properties[i].Name, m_Properties[i].Value);
90 
91             } catch (com.sun.star.beans.UnknownPropertyException e){
92             } catch (PropertyVetoException e){
93             } catch (IllegalArgumentException e){
94             } catch (WrappedTargetException e){
95             }
96         }
97     }
98     /**
99      * Creating a Testenvironment for the interfaces to be tested.
100      * Creates an instance of the service
101      * <code>com.sun.star.comp.framework.PathSettings</code>.
102      */
103     protected TestEnvironment createTestEnvironment
104             (TestParameters Param, PrintWriter log) {
105         XInterface oObj = null;
106         Object oInterface = null ;
107 
108         //now get the OButtonControl
109         try {
110             oInterface = ((XMultiServiceFactory)Param.getMSF()).createInstance
111                 ("com.sun.star.comp.framework.PathSettings") ;
112         } catch (com.sun.star.uno.Exception e) {
113             log.println("Couldn't get service");
114             e.printStackTrace(log);
115             throw new StatusException("Couldn't get GridControl", e );
116         }
117 
118         if (oInterface == null) {
119             log.println("Service wasn't created") ;
120             throw new StatusException(Status.failed("Service wasn't created")) ;
121         }
122 
123         oObj = (XInterface) oInterface ;
124         log.println("ImplName: "+utils.getImplName(oObj));
125 
126         log.println( "creating a new environment for object" );
127         TestEnvironment tEnv = new TestEnvironment( oObj );
128 
129         Set exclProps = new HashSet();
130         exclProps.add("UIConfig");
131         tEnv.addObjRelation("XFastPropertySet.ExcludeProps", exclProps);
132         tEnv.addObjRelation("XMultiPropertySet.ExcludeProps", exclProps);
133 
134         saveAllPropertyValues(oObj);
135 
136         return tEnv;
137     } // finish method getTestEnvironment
138 
139     private void saveAllPropertyValues(XInterface oObj){
140 
141         xPS = (XPropertySet) UnoRuntime.queryInterface(
142                                                 XPropertySet.class, oObj);
143 
144         XPropertySetInfo xPSI = xPS.getPropertySetInfo();
145 
146         Property[] allProperties = xPSI.getProperties();
147         m_Properties = new NamedValue[allProperties.length];
148 
149         for (int i=0; i < allProperties.length; i++){
150             try{
151                 m_Properties[i] = new NamedValue(allProperties[i].Name,
152                                    xPS.getPropertyValue(allProperties[i].Name));
153 
154             } catch (com.sun.star.beans.UnknownPropertyException e){
155             } catch (WrappedTargetException e){
156             }
157         }
158     }
159 
160 }
161 
162