xref: /AOO41X/main/framework/qa/complex/path_settings/PathSettingsTest.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package complex.path_settings;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import com.sun.star.beans.Property;
30*cdf0e10cSrcweir import com.sun.star.beans.PropertyVetoException;
31*cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException;
32*cdf0e10cSrcweir import com.sun.star.beans.XFastPropertySet;
33*cdf0e10cSrcweir import com.sun.star.beans.XMultiPropertySet;
34*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
35*cdf0e10cSrcweir import com.sun.star.beans.XPropertiesChangeListener;
36*cdf0e10cSrcweir import com.sun.star.beans.XPropertyChangeListener;
37*cdf0e10cSrcweir import com.sun.star.beans.XVetoableChangeListener;
38*cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetException;
39*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
40*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
41*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir // ---------- junit imports -----------------
44*cdf0e10cSrcweir import java.util.ArrayList;
45*cdf0e10cSrcweir import java.util.StringTokenizer;
46*cdf0e10cSrcweir import java.util.logging.Level;
47*cdf0e10cSrcweir import java.util.logging.Logger;
48*cdf0e10cSrcweir import org.junit.After;
49*cdf0e10cSrcweir import org.junit.AfterClass;
50*cdf0e10cSrcweir import org.junit.Before;
51*cdf0e10cSrcweir import org.junit.BeforeClass;
52*cdf0e10cSrcweir import org.junit.Test;
53*cdf0e10cSrcweir import org.openoffice.test.OfficeConnection;
54*cdf0e10cSrcweir import static org.junit.Assert.*;
55*cdf0e10cSrcweir // ------------------------------------------
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir public class PathSettingsTest
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     private static XMultiServiceFactory xMSF;
61*cdf0e10cSrcweir     // the test object: an instance of the tested service
62*cdf0e10cSrcweir     private static Object aPathSettings = null;
63*cdf0e10cSrcweir     // the properties of the service
64*cdf0e10cSrcweir     private static Property[] xPropertyInfoOfPathSettings = null;
65*cdf0e10cSrcweir     private static String[] aPathSettingNames = null;
66*cdf0e10cSrcweir     private static String[] availablePropNames = new String[]
67*cdf0e10cSrcweir     {
68*cdf0e10cSrcweir         "Addin",
69*cdf0e10cSrcweir         "AutoCorrect",
70*cdf0e10cSrcweir         "AutoText",
71*cdf0e10cSrcweir         "Backup",
72*cdf0e10cSrcweir         "Basic",
73*cdf0e10cSrcweir         "Bitmap",
74*cdf0e10cSrcweir         "Config",
75*cdf0e10cSrcweir         "Dictionary",
76*cdf0e10cSrcweir         "Favorite",
77*cdf0e10cSrcweir         "Filter",
78*cdf0e10cSrcweir         "Fingerprint",
79*cdf0e10cSrcweir         "Gallery",
80*cdf0e10cSrcweir         "Graphic",
81*cdf0e10cSrcweir         "Help",
82*cdf0e10cSrcweir         "Linguistic",
83*cdf0e10cSrcweir         "Module",
84*cdf0e10cSrcweir         "Palette",
85*cdf0e10cSrcweir         "Plugin",
86*cdf0e10cSrcweir         "Storage",
87*cdf0e10cSrcweir         "Temp",
88*cdf0e10cSrcweir         "Template",
89*cdf0e10cSrcweir         "UIConfig",
90*cdf0e10cSrcweir         "UserConfig",
91*cdf0e10cSrcweir         "Work",
92*cdf0e10cSrcweir     };
93*cdf0e10cSrcweir     // every path name from availablePropNames exist in this characteristics
94*cdf0e10cSrcweir     // name
95*cdf0e10cSrcweir     // name_internal
96*cdf0e10cSrcweir     // name_user
97*cdf0e10cSrcweir     // name_writable
98*cdf0e10cSrcweir     private static String[] availablePropNameExtensions = new String[]
99*cdf0e10cSrcweir     {
100*cdf0e10cSrcweir         "",
101*cdf0e10cSrcweir         "_internal",
102*cdf0e10cSrcweir         "_user",
103*cdf0e10cSrcweir         "_writable"
104*cdf0e10cSrcweir     };
105*cdf0e10cSrcweir     private static String[] aPathSettingValues = null;
106*cdf0e10cSrcweir     ArrayList<Property> aListOfWorkingProperty;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     /**
109*cdf0e10cSrcweir      * A function to tell the framework, which test functions are available.
110*cdf0e10cSrcweir      * Right now, it's only 'checkComplexTemplateState'.
111*cdf0e10cSrcweir      * @return All test methods.
112*cdf0e10cSrcweir      */
113*cdf0e10cSrcweir //    public String[] getTestMethodNames() {
114*cdf0e10cSrcweir //        return new String[]{"checkXFastPropertySet",
115*cdf0e10cSrcweir //                            "checkXMultiPropertySet",
116*cdf0e10cSrcweir //                            "checkXPropertySet"
117*cdf0e10cSrcweir //                        };
118*cdf0e10cSrcweir //    }
119*cdf0e10cSrcweir     /**
120*cdf0e10cSrcweir      * Initialize before the tests start: this has to be done only once.
121*cdf0e10cSrcweir      * This methods sets the 'aPathSettings' and 'xPropertyInfoOfPathSettings' variables.
122*cdf0e10cSrcweir      */
123*cdf0e10cSrcweir     @Before
124*cdf0e10cSrcweir     public void before()
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         try
127*cdf0e10cSrcweir         {
128*cdf0e10cSrcweir             xMSF = getMSF();
129*cdf0e10cSrcweir //            aPathSettings = xMSF.createInstance("com.sun.star.util.PathSettings");
130*cdf0e10cSrcweir             aPathSettings = xMSF.createInstance("com.sun.star.comp.framework.PathSettings");
131*cdf0e10cSrcweir             assertNotNull("Can't instantiate com.sun.star.util.PathSettings.", aPathSettings);
132*cdf0e10cSrcweir //            System.out.println("Implementation: " + util.utils.getImplName(aPathSettings));
133*cdf0e10cSrcweir //            System.out.println("Service:        ");
134*cdf0e10cSrcweir             util.dbg.getSuppServices(aPathSettings);
135*cdf0e10cSrcweir             final XPropertySet xPropSet_of_PathSettings = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings);
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir             xPropertyInfoOfPathSettings = xPropSet_of_PathSettings.getPropertySetInfo().getProperties();
138*cdf0e10cSrcweir             aPathSettingNames = new String[xPropertyInfoOfPathSettings.length];
139*cdf0e10cSrcweir             aPathSettingValues = new String[xPropertyInfoOfPathSettings.length];
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir             aListOfWorkingProperty = new ArrayList<Property>();
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir             // get intitial values and create new ones
144*cdf0e10cSrcweir             for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++)
145*cdf0e10cSrcweir             {
146*cdf0e10cSrcweir                 final String sName = xPropertyInfoOfPathSettings[i].Name;
147*cdf0e10cSrcweir                 // System.out.println(sName);
148*cdf0e10cSrcweir                 aPathSettingNames[i] = sName;
149*cdf0e10cSrcweir                 Object o = xPropSet_of_PathSettings.getPropertyValue(sName);
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir                 String sValue = convertToString(o);
152*cdf0e10cSrcweir                 aPathSettingValues[i] = sValue;
153*cdf0e10cSrcweir                 aListOfWorkingProperty.add(xPropertyInfoOfPathSettings[i]);
154*cdf0e10cSrcweir             }
155*cdf0e10cSrcweir         }
156*cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
157*cdf0e10cSrcweir         {
158*cdf0e10cSrcweir             System.out.println(e.getClass().getName());
159*cdf0e10cSrcweir             System.out.println("Message: " + e.getMessage());
160*cdf0e10cSrcweir             // fail("Could not create an instance of the test object.");
161*cdf0e10cSrcweir         }
162*cdf0e10cSrcweir         catch (Exception e)
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir             fail("What exception?");
165*cdf0e10cSrcweir         }
166*cdf0e10cSrcweir     }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     private String convertToString(Object o)
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         String sValue = "";
171*cdf0e10cSrcweir         try
172*cdf0e10cSrcweir         {
173*cdf0e10cSrcweir             if (AnyConverter.isString(o))
174*cdf0e10cSrcweir             {
175*cdf0e10cSrcweir                 sValue = AnyConverter.toString(o);
176*cdf0e10cSrcweir             }
177*cdf0e10cSrcweir             else if (AnyConverter.isArray(o))
178*cdf0e10cSrcweir             {
179*cdf0e10cSrcweir                 Object oValueList = AnyConverter.toArray(o);
180*cdf0e10cSrcweir                 String[] aValueList = (String[]) oValueList;
181*cdf0e10cSrcweir                 String sValues = "";
182*cdf0e10cSrcweir                 for (int j = 0; j < aValueList.length; j++)
183*cdf0e10cSrcweir                 {
184*cdf0e10cSrcweir                     if (sValues.length() > 0)
185*cdf0e10cSrcweir                     {
186*cdf0e10cSrcweir                         sValues += ";";
187*cdf0e10cSrcweir                     }
188*cdf0e10cSrcweir                     sValues += aValueList[j];
189*cdf0e10cSrcweir                 }
190*cdf0e10cSrcweir                 sValue = sValues;
191*cdf0e10cSrcweir             }
192*cdf0e10cSrcweir             else
193*cdf0e10cSrcweir             {
194*cdf0e10cSrcweir                 System.out.println("Can't convert Object to String");
195*cdf0e10cSrcweir             }
196*cdf0e10cSrcweir         }
197*cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
198*cdf0e10cSrcweir         {
199*cdf0e10cSrcweir             /* ignore */
200*cdf0e10cSrcweir         }
201*cdf0e10cSrcweir         return sValue;
202*cdf0e10cSrcweir     }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     /**
205*cdf0e10cSrcweir      * Simple existance test, if this fails, the Lists must update
206*cdf0e10cSrcweir      */
207*cdf0e10cSrcweir     @Test
208*cdf0e10cSrcweir     public void checkInternalListConsistence()
209*cdf0e10cSrcweir     {
210*cdf0e10cSrcweir         // check if all Properties are in the internal test list
211*cdf0e10cSrcweir         for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++)
212*cdf0e10cSrcweir         {
213*cdf0e10cSrcweir             final String sName = xPropertyInfoOfPathSettings[i].Name;
214*cdf0e10cSrcweir             boolean bOccur = checkIfNameExistsInList(sName, availablePropNames, availablePropNameExtensions);
215*cdf0e10cSrcweir             assertTrue("TEST IS WRONG, Name:='" + sName + "' doesn't exist in internal Test list.", bOccur);
216*cdf0e10cSrcweir         }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         // check if all properties in the internal list also exist in real life
219*cdf0e10cSrcweir         for (int i = 0; i < availablePropNames.length; i++)
220*cdf0e10cSrcweir         {
221*cdf0e10cSrcweir             final String aListName = availablePropNames[i];
222*cdf0e10cSrcweir             for (int j = 0; j < availablePropNameExtensions.length; j++)
223*cdf0e10cSrcweir             {
224*cdf0e10cSrcweir                 final String aSubListName = availablePropNameExtensions[j];
225*cdf0e10cSrcweir                 final String aName = aListName + aSubListName;
226*cdf0e10cSrcweir                 boolean bOccur = checkIfNameExistsInList(aName, aPathSettingNames, new String[]
227*cdf0e10cSrcweir                         {
228*cdf0e10cSrcweir                             ""
229*cdf0e10cSrcweir                         } /* list must not empty! */);
230*cdf0e10cSrcweir                 assertTrue("TEST IS WRONG, Name:='" + aName + "' from the internal test list do not occur in real life path settings.", bOccur);
231*cdf0e10cSrcweir             }
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     /**
236*cdf0e10cSrcweir      * Simple O(n^n) check if a given String (_sNameMustOccur) exist in the given list(+SubList) values.
237*cdf0e10cSrcweir      * @param _sNameMustOccur
238*cdf0e10cSrcweir      * @param _aList
239*cdf0e10cSrcweir      * @param _aSubList
240*cdf0e10cSrcweir      * @return true, if name occur
241*cdf0e10cSrcweir      */
242*cdf0e10cSrcweir     private boolean checkIfNameExistsInList(String _sNameMustOccur, String[] _aList, String[] _aSubList)
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         for (int i = 0; i < _aList.length; i++)
245*cdf0e10cSrcweir         {
246*cdf0e10cSrcweir             final String aListName = _aList[i];
247*cdf0e10cSrcweir             for (int j = 0; j < _aSubList.length; j++)
248*cdf0e10cSrcweir             {
249*cdf0e10cSrcweir                 final String aSubListName = _aSubList[j];
250*cdf0e10cSrcweir                 final String aName = aListName + aSubListName;
251*cdf0e10cSrcweir                 if (aName.equals(_sNameMustOccur))
252*cdf0e10cSrcweir                 {
253*cdf0e10cSrcweir                     return true;
254*cdf0e10cSrcweir                 }
255*cdf0e10cSrcweir             }
256*cdf0e10cSrcweir         }
257*cdf0e10cSrcweir         return false;
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     private String getPropertyValueAsString(String _sName)
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir         final XPropertySet xPropSet_of_PathSettings = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings);
263*cdf0e10cSrcweir         String sValue = "";
264*cdf0e10cSrcweir         {
265*cdf0e10cSrcweir             Object o;
266*cdf0e10cSrcweir             try
267*cdf0e10cSrcweir             {
268*cdf0e10cSrcweir                 o = xPropSet_of_PathSettings.getPropertyValue(_sName);
269*cdf0e10cSrcweir                 sValue = convertToString(o);
270*cdf0e10cSrcweir             }
271*cdf0e10cSrcweir             catch (UnknownPropertyException ex)
272*cdf0e10cSrcweir             {
273*cdf0e10cSrcweir             }
274*cdf0e10cSrcweir             catch (WrappedTargetException ex)
275*cdf0e10cSrcweir             {
276*cdf0e10cSrcweir             }
277*cdf0e10cSrcweir         }
278*cdf0e10cSrcweir         return sValue;
279*cdf0e10cSrcweir     }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     /**
282*cdf0e10cSrcweir      * Shows the path settings
283*cdf0e10cSrcweir      * @throws UnknownPropertyException
284*cdf0e10cSrcweir      * @throws WrappedTargetException
285*cdf0e10cSrcweir      */
286*cdf0e10cSrcweir     @Test
287*cdf0e10cSrcweir     public void showPathSettings() throws UnknownPropertyException, WrappedTargetException
288*cdf0e10cSrcweir     {
289*cdf0e10cSrcweir         System.out.println("\n---- All properties ----");
290*cdf0e10cSrcweir         final XPropertySet xPropSet_of_PathSettings = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings);
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir //        for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++)
293*cdf0e10cSrcweir         for (int i = 0; i < aListOfWorkingProperty.size(); i++)
294*cdf0e10cSrcweir         {
295*cdf0e10cSrcweir             final String sName = aListOfWorkingProperty.get(i).Name;
296*cdf0e10cSrcweir             // aPathSettingWorkingNames[i] = sName;
297*cdf0e10cSrcweir //            System.out.print("PathSettings: Name:=");
298*cdf0e10cSrcweir             System.out.print(sName);
299*cdf0e10cSrcweir             Object o = xPropSet_of_PathSettings.getPropertyValue(sName);
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir             // System.out.println("#### Object: '" + o.getClass().getName() + "'  -  '" + o.toString() + "'");
302*cdf0e10cSrcweir             try
303*cdf0e10cSrcweir             {
304*cdf0e10cSrcweir                 final String sValue = AnyConverter.toString(o);
305*cdf0e10cSrcweir                 // aPathSettingValues[i] = sValue;
306*cdf0e10cSrcweir                 // System.out.println("#### String " + sValue);
307*cdf0e10cSrcweir                 // System.out.println("Property Name: " + sName);
308*cdf0e10cSrcweir                 // System.out.println("Property Value: " + sValue);
309*cdf0e10cSrcweir //                System.out.print(" ==> ");
310*cdf0e10cSrcweir //                System.out.print(sValue);
311*cdf0e10cSrcweir             }
312*cdf0e10cSrcweir             catch (com.sun.star.uno.Exception e)
313*cdf0e10cSrcweir             {
314*cdf0e10cSrcweir //                System.out.print(" FAILED ");
315*cdf0e10cSrcweir             }
316*cdf0e10cSrcweir             System.out.println();
317*cdf0e10cSrcweir         }
318*cdf0e10cSrcweir         System.out.println("---- Finish showing properties ----\n");
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     private boolean checkPaths(Object _o, Object _o2)
322*cdf0e10cSrcweir     {
323*cdf0e10cSrcweir         String sLeftPath = "";
324*cdf0e10cSrcweir         String sRightPath = "";
325*cdf0e10cSrcweir         if (AnyConverter.isArray(_o))
326*cdf0e10cSrcweir         {
327*cdf0e10cSrcweir             try
328*cdf0e10cSrcweir             {
329*cdf0e10cSrcweir                 Object oValues = AnyConverter.toArray(_o);
330*cdf0e10cSrcweir                 sLeftPath = convertToString(oValues);
331*cdf0e10cSrcweir             }
332*cdf0e10cSrcweir             catch (com.sun.star.lang.IllegalArgumentException e)
333*cdf0e10cSrcweir             {
334*cdf0e10cSrcweir             }
335*cdf0e10cSrcweir         }
336*cdf0e10cSrcweir         else if (AnyConverter.isString(_o))
337*cdf0e10cSrcweir         {
338*cdf0e10cSrcweir             try
339*cdf0e10cSrcweir             {
340*cdf0e10cSrcweir                 sLeftPath = AnyConverter.toString(_o);
341*cdf0e10cSrcweir             }
342*cdf0e10cSrcweir             catch (com.sun.star.lang.IllegalArgumentException e)
343*cdf0e10cSrcweir             {
344*cdf0e10cSrcweir             }
345*cdf0e10cSrcweir         }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir         if (AnyConverter.isArray(_o2))
348*cdf0e10cSrcweir         {
349*cdf0e10cSrcweir             try
350*cdf0e10cSrcweir             {
351*cdf0e10cSrcweir                 Object oValues = AnyConverter.toArray(_o2);
352*cdf0e10cSrcweir                 sRightPath = convertToString(oValues);
353*cdf0e10cSrcweir             }
354*cdf0e10cSrcweir             catch (com.sun.star.lang.IllegalArgumentException e)
355*cdf0e10cSrcweir             {
356*cdf0e10cSrcweir             }
357*cdf0e10cSrcweir         }
358*cdf0e10cSrcweir         else if (AnyConverter.isString(_o2))
359*cdf0e10cSrcweir         {
360*cdf0e10cSrcweir             try
361*cdf0e10cSrcweir             {
362*cdf0e10cSrcweir                 sRightPath = AnyConverter.toString(_o2);
363*cdf0e10cSrcweir             }
364*cdf0e10cSrcweir             catch (com.sun.star.lang.IllegalArgumentException e)
365*cdf0e10cSrcweir             {
366*cdf0e10cSrcweir             }
367*cdf0e10cSrcweir         }
368*cdf0e10cSrcweir         return checkPaths(sLeftPath, sRightPath);
369*cdf0e10cSrcweir     }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir     /**
372*cdf0e10cSrcweir      * Check 2 given paths if the _aOtherPath exists in _aPath, _aPath could be a list separated by ';'
373*cdf0e10cSrcweir      * @param _aPath
374*cdf0e10cSrcweir      * @param _aOtherPath
375*cdf0e10cSrcweir      * @return true, if _aOtherPath found
376*cdf0e10cSrcweir      */
377*cdf0e10cSrcweir     private boolean checkPaths(String _aPath, String _aOtherPath)
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir         if (_aOtherPath.contains(";"))
380*cdf0e10cSrcweir         {
381*cdf0e10cSrcweir             StringTokenizer aToken = new StringTokenizer(_aOtherPath, ";");
382*cdf0e10cSrcweir             int nCount = 0;
383*cdf0e10cSrcweir             int nFound = 0;
384*cdf0e10cSrcweir             while (aToken.hasMoreElements())
385*cdf0e10cSrcweir             {
386*cdf0e10cSrcweir                 String sPath = (String)aToken.nextElement();
387*cdf0e10cSrcweir                 nCount ++;
388*cdf0e10cSrcweir                 if (checkPaths(_aPath, sPath))
389*cdf0e10cSrcweir                 {
390*cdf0e10cSrcweir                     nFound++;
391*cdf0e10cSrcweir                 }
392*cdf0e10cSrcweir             }
393*cdf0e10cSrcweir             if (nFound == nCount)
394*cdf0e10cSrcweir             {
395*cdf0e10cSrcweir                 return true;
396*cdf0e10cSrcweir             }
397*cdf0e10cSrcweir         }
398*cdf0e10cSrcweir         else if(_aPath.contains(";"))
399*cdf0e10cSrcweir         {
400*cdf0e10cSrcweir             StringTokenizer aToken = new StringTokenizer(_aPath, ";");
401*cdf0e10cSrcweir             while (aToken.hasMoreElements())
402*cdf0e10cSrcweir             {
403*cdf0e10cSrcweir                 String sToken = (String)aToken.nextElement();
404*cdf0e10cSrcweir                 if (sToken.equals(_aOtherPath))
405*cdf0e10cSrcweir                 {
406*cdf0e10cSrcweir                     return true;
407*cdf0e10cSrcweir                 }
408*cdf0e10cSrcweir             }
409*cdf0e10cSrcweir             return false;
410*cdf0e10cSrcweir         }
411*cdf0e10cSrcweir         else if (_aPath.equals(_aOtherPath))
412*cdf0e10cSrcweir         {
413*cdf0e10cSrcweir             return true;
414*cdf0e10cSrcweir         }
415*cdf0e10cSrcweir         return false;
416*cdf0e10cSrcweir     }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     /**
419*cdf0e10cSrcweir      * This tests the XFastPropertySet interface implementation.
420*cdf0e10cSrcweir      */
421*cdf0e10cSrcweir     @Test
422*cdf0e10cSrcweir     public void checkXFastPropertySet()
423*cdf0e10cSrcweir     {
424*cdf0e10cSrcweir         System.out.println("---- Testing the XFastPropertySet interface ----");
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir         // do for all properties
428*cdf0e10cSrcweir         // xPropertyInfoOfPathSettings.length
429*cdf0e10cSrcweir         for (int i = 0; i < aListOfWorkingProperty.size(); i++)
430*cdf0e10cSrcweir         {
431*cdf0e10cSrcweir             final Property property = aListOfWorkingProperty.get(i); // xPropertyInfoOfPathSettings[i];
432*cdf0e10cSrcweir             String name = property.Name;
433*cdf0e10cSrcweir             // get property name and initial value
434*cdf0e10cSrcweir             System.out.println("Test property with name: " + name);
435*cdf0e10cSrcweir             boolean bResult;
436*cdf0e10cSrcweir             if (name.endsWith("_writable"))
437*cdf0e10cSrcweir             {
438*cdf0e10cSrcweir                 bResult = checkStringProperty(property);
439*cdf0e10cSrcweir             }
440*cdf0e10cSrcweir             else if (name.endsWith("_user"))
441*cdf0e10cSrcweir             {
442*cdf0e10cSrcweir                 bResult = checkStringListProperty(property);
443*cdf0e10cSrcweir             }
444*cdf0e10cSrcweir             else if (name.endsWith("_internal"))
445*cdf0e10cSrcweir             {
446*cdf0e10cSrcweir                 bResult = checkStringListProperty(property);
447*cdf0e10cSrcweir             }
448*cdf0e10cSrcweir             else
449*cdf0e10cSrcweir             {
450*cdf0e10cSrcweir                 // old path settings
451*cdf0e10cSrcweir                 bResult = checkStringProperty(property);
452*cdf0e10cSrcweir             }
453*cdf0e10cSrcweir             System.out.print(" Test of property " + name + " finished");
454*cdf0e10cSrcweir             if (bResult)
455*cdf0e10cSrcweir             {
456*cdf0e10cSrcweir                 System.out.println(" [ok]");
457*cdf0e10cSrcweir             }
458*cdf0e10cSrcweir             else
459*cdf0e10cSrcweir             {
460*cdf0e10cSrcweir                 System.out.println(" [FAILED]");
461*cdf0e10cSrcweir             }
462*cdf0e10cSrcweir             System.out.println();
463*cdf0e10cSrcweir         }
464*cdf0e10cSrcweir         System.out.println("---- Test of XFastPropertySet finished ----\n");
465*cdf0e10cSrcweir     }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir     private boolean checkStringListProperty(Property property)
468*cdf0e10cSrcweir     {
469*cdf0e10cSrcweir         // creating instances
470*cdf0e10cSrcweir         boolean bResult = true;
471*cdf0e10cSrcweir         XFastPropertySet xFPS = UnoRuntime.queryInterface(XFastPropertySet.class, aPathSettings);
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir         String name = property.Name;
474*cdf0e10cSrcweir         int handle = property.Handle;
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir         Object oValue;
477*cdf0e10cSrcweir         try
478*cdf0e10cSrcweir         {
479*cdf0e10cSrcweir             oValue = xFPS.getFastPropertyValue(handle);
480*cdf0e10cSrcweir         }
481*cdf0e10cSrcweir         catch (UnknownPropertyException ex)
482*cdf0e10cSrcweir         {
483*cdf0e10cSrcweir             return false;
484*cdf0e10cSrcweir         }
485*cdf0e10cSrcweir         catch (WrappedTargetException ex)
486*cdf0e10cSrcweir         {
487*cdf0e10cSrcweir             return false;
488*cdf0e10cSrcweir         }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir         if (!AnyConverter.isArray(oValue))
491*cdf0e10cSrcweir         {
492*cdf0e10cSrcweir             System.out.println(" Internal error, type wrong. PathSetting property with name:" + name + " should be an array.");
493*cdf0e10cSrcweir             return false;
494*cdf0e10cSrcweir         }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir         String val;
497*cdf0e10cSrcweir         try
498*cdf0e10cSrcweir         {
499*cdf0e10cSrcweir             Object oValues = AnyConverter.toArray(oValue);
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir             final String[] aValues = (String[])oValues;
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir             // aNewValues contains a deep copy of aValues
505*cdf0e10cSrcweir             String[] aNewValues = new String[aValues.length];
506*cdf0e10cSrcweir             System.arraycopy(aValues, 0, aNewValues, 0, aValues.length);
507*cdf0e10cSrcweir             if (aValues.length > 0)
508*cdf0e10cSrcweir             {
509*cdf0e10cSrcweir                 val = aValues[0];
510*cdf0e10cSrcweir             }
511*cdf0e10cSrcweir             else
512*cdf0e10cSrcweir             {
513*cdf0e10cSrcweir                 val = null;
514*cdf0e10cSrcweir                 aNewValues = new String[1]; // create a String list
515*cdf0e10cSrcweir             }
516*cdf0e10cSrcweir             System.out.println(" Property has initial value: '" + val + "'");
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir             // set to a new correct value
519*cdf0e10cSrcweir             String newVal = changeToCorrectValue(val);
520*cdf0e10cSrcweir             assertFalse("newVal must not equal val.", newVal.equals(val));
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir             System.out.println(" Try to change to a correct value '" + newVal + "'");
523*cdf0e10cSrcweir             aNewValues[0] = newVal;
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir             try
526*cdf0e10cSrcweir             {
527*cdf0e10cSrcweir                 try
528*cdf0e10cSrcweir                 {
529*cdf0e10cSrcweir                     xFPS.setFastPropertyValue(handle, aNewValues);
530*cdf0e10cSrcweir                 }
531*cdf0e10cSrcweir                 catch (com.sun.star.lang.WrappedTargetException e)
532*cdf0e10cSrcweir                 {
533*cdf0e10cSrcweir                     System.out.println(" FAIL: setFastPropertyValue(handle:=" + handle + ", name:='" + name + "')" + e.getMessage());
534*cdf0e10cSrcweir                     bResult = false;
535*cdf0e10cSrcweir                 }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir                 // Property_internal can't change we will not arrive bejond this line
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir                 // check the change
540*cdf0e10cSrcweir                 Object oObj = xFPS.getFastPropertyValue(handle);
541*cdf0e10cSrcweir                 if (!checkPaths(oObj, aNewValues))
542*cdf0e10cSrcweir                 {
543*cdf0e10cSrcweir                     System.out.println(" FAIL: Did not change value on property " + name + ".");
544*cdf0e10cSrcweir                     bResult = false;
545*cdf0e10cSrcweir                 }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir                 // set back to initial setting
548*cdf0e10cSrcweir                 System.out.println(" Try to check");
549*cdf0e10cSrcweir                 try
550*cdf0e10cSrcweir                 {
551*cdf0e10cSrcweir                     xFPS.setFastPropertyValue(handle, oValue);
552*cdf0e10cSrcweir                 }
553*cdf0e10cSrcweir                 catch (com.sun.star.beans.PropertyVetoException e)
554*cdf0e10cSrcweir                 {
555*cdf0e10cSrcweir                     // should not occur
556*cdf0e10cSrcweir                     System.out.println(" FAIL: PropertyVetoException caught: " + e.getMessage());
557*cdf0e10cSrcweir                     bResult = false;
558*cdf0e10cSrcweir                 }
559*cdf0e10cSrcweir             }
560*cdf0e10cSrcweir             catch (com.sun.star.beans.PropertyVetoException e)
561*cdf0e10cSrcweir             {
562*cdf0e10cSrcweir                 if (!name.endsWith("_internal"))
563*cdf0e10cSrcweir                 {
564*cdf0e10cSrcweir                     // should not occur
565*cdf0e10cSrcweir                    System.out.println(" FAIL: PropertyVetoException caught: " + e.getMessage());
566*cdf0e10cSrcweir                    bResult = false;
567*cdf0e10cSrcweir                 }
568*cdf0e10cSrcweir                 else
569*cdf0e10cSrcweir                 {
570*cdf0e10cSrcweir                    System.out.println(" OK: PropertyVetoException caught: " + e.getMessage() + " it seems not allowed to change internal values.");
571*cdf0e10cSrcweir                 }
572*cdf0e10cSrcweir             }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir             // check if changed
575*cdf0e10cSrcweir             Object checkVal3 = xFPS.getFastPropertyValue(handle);
576*cdf0e10cSrcweir             if (!checkPaths(checkVal3, oValues))
577*cdf0e10cSrcweir             {
578*cdf0e10cSrcweir                 System.out.println(" FAIL: Can't change value back to original on property " + name);
579*cdf0e10cSrcweir                 bResult = false;
580*cdf0e10cSrcweir             }
581*cdf0e10cSrcweir         }
582*cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
583*cdf0e10cSrcweir         {
584*cdf0e10cSrcweir             System.out.println(" FAIL: getFastPropertyValue(handle:=" + handle + ", name:='" + name + "')" + e.getMessage());
585*cdf0e10cSrcweir             bResult = false;
586*cdf0e10cSrcweir         }
587*cdf0e10cSrcweir         return bResult;
588*cdf0e10cSrcweir     }
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir     private boolean checkStringProperty(Property property)
591*cdf0e10cSrcweir     {
592*cdf0e10cSrcweir         boolean bResult = true;
593*cdf0e10cSrcweir         XFastPropertySet xFPS = UnoRuntime.queryInterface(XFastPropertySet.class, aPathSettings);
594*cdf0e10cSrcweir         String name = property.Name;
595*cdf0e10cSrcweir         int handle = property.Handle;
596*cdf0e10cSrcweir         Object oValue;
597*cdf0e10cSrcweir         try
598*cdf0e10cSrcweir         {
599*cdf0e10cSrcweir             oValue = xFPS.getFastPropertyValue(handle);
600*cdf0e10cSrcweir         }
601*cdf0e10cSrcweir         catch (UnknownPropertyException ex)
602*cdf0e10cSrcweir         {
603*cdf0e10cSrcweir             return false;
604*cdf0e10cSrcweir         }
605*cdf0e10cSrcweir         catch (WrappedTargetException ex)
606*cdf0e10cSrcweir         {
607*cdf0e10cSrcweir             return false;
608*cdf0e10cSrcweir         }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir         try
612*cdf0e10cSrcweir         {
613*cdf0e10cSrcweir             String val = "";
614*cdf0e10cSrcweir             val = AnyConverter.toString(oValue);
615*cdf0e10cSrcweir             System.out.println(" Property has initial value: '" + val + "'");
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir             // set to a new correct value
618*cdf0e10cSrcweir             String newVal = changeToCorrectValue(val);
619*cdf0e10cSrcweir             System.out.println(" Try to change to a correct value '" + newVal + "'");
620*cdf0e10cSrcweir             xFPS.setFastPropertyValue(handle, newVal);
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir             // check the change
623*cdf0e10cSrcweir             String checkVal = (String) xFPS.getFastPropertyValue(handle);
624*cdf0e10cSrcweir             if (!checkPaths(checkVal, newVal))
625*cdf0e10cSrcweir             {
626*cdf0e10cSrcweir                 System.out.println("  FAIL: Did not change value on property " + name + ".");
627*cdf0e10cSrcweir                 bResult = false;
628*cdf0e10cSrcweir             }
629*cdf0e10cSrcweir             newVal = changeToIncorrectValue(val);
630*cdf0e10cSrcweir             System.out.println(" Try to change to incorrect value '" + newVal + "'");
631*cdf0e10cSrcweir             try
632*cdf0e10cSrcweir             {
633*cdf0e10cSrcweir                 xFPS.setFastPropertyValue(handle, newVal);
634*cdf0e10cSrcweir             }
635*cdf0e10cSrcweir             catch (com.sun.star.lang.IllegalArgumentException e)
636*cdf0e10cSrcweir             {
637*cdf0e10cSrcweir                 System.out.println("  Correctly thrown Exception caught.");
638*cdf0e10cSrcweir             }
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir             // check if changed
641*cdf0e10cSrcweir             String checkVal2 = (String) xFPS.getFastPropertyValue(handle);
642*cdf0e10cSrcweir             if (!checkPaths(checkVal2, checkVal))
643*cdf0e10cSrcweir             {
644*cdf0e10cSrcweir                 System.out.println("  FAIL: Value did change on property " + name + " though it should not have.");
645*cdf0e10cSrcweir                 bResult = false;
646*cdf0e10cSrcweir             }
647*cdf0e10cSrcweir             else
648*cdf0e10cSrcweir             {
649*cdf0e10cSrcweir                 System.out.println("  OK: Incorrect value was not set.");
650*cdf0e10cSrcweir             }
651*cdf0e10cSrcweir             // set back to initial setting
652*cdf0e10cSrcweir             System.out.println(" Set back to initial value.");
653*cdf0e10cSrcweir             try
654*cdf0e10cSrcweir             {
655*cdf0e10cSrcweir                 xFPS.setFastPropertyValue(handle, val);
656*cdf0e10cSrcweir             }
657*cdf0e10cSrcweir             catch (com.sun.star.lang.IllegalArgumentException e)
658*cdf0e10cSrcweir             {
659*cdf0e10cSrcweir                 System.out.println("  IllegalArgumentException caught: " + e.getMessage());
660*cdf0e10cSrcweir                 bResult = false;
661*cdf0e10cSrcweir             }
662*cdf0e10cSrcweir             // check if changed
663*cdf0e10cSrcweir             String checkVal3 = (String) xFPS.getFastPropertyValue(handle);
664*cdf0e10cSrcweir             if (!checkVal3.equals(val))
665*cdf0e10cSrcweir             {
666*cdf0e10cSrcweir                 if (!checkPaths(checkVal3, val))
667*cdf0e10cSrcweir                 {
668*cdf0e10cSrcweir                     System.out.println("  FAIL: Can't change value back to original on property " + name);
669*cdf0e10cSrcweir                     System.out.println("  Value is: " + checkVal3);
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir                     bResult = false;
672*cdf0e10cSrcweir                 }
673*cdf0e10cSrcweir                 else
674*cdf0e10cSrcweir                 {
675*cdf0e10cSrcweir                     System.out.println("  OK: the pathsettings contains the original path.");
676*cdf0e10cSrcweir                     System.out.println("         Value is: " + checkVal3);
677*cdf0e10cSrcweir                     System.out.println("  Value should be: " + val);
678*cdf0e10cSrcweir                 }
679*cdf0e10cSrcweir             }
680*cdf0e10cSrcweir             else
681*cdf0e10cSrcweir             {
682*cdf0e10cSrcweir                 System.out.println("  OK: Change value back to original on property " + name);
683*cdf0e10cSrcweir             }
684*cdf0e10cSrcweir         }
685*cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
686*cdf0e10cSrcweir         {
687*cdf0e10cSrcweir             System.out.println(" FAIL: getFastPropertyValue(handle:=" + handle + ", name:='" + name + "')" + e.getMessage());
688*cdf0e10cSrcweir             bResult = false;
689*cdf0e10cSrcweir         }
690*cdf0e10cSrcweir         return bResult;
691*cdf0e10cSrcweir     }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir     // ____________________
694*cdf0e10cSrcweir     /**
695*cdf0e10cSrcweir      * This tests the XMultiPropertySet interface implementation.
696*cdf0e10cSrcweir      */
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir     // The test checkXMultiPropertySet() has been marked as outdated!
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir //    @Test
701*cdf0e10cSrcweir //    public void checkXMultiPropertySet()
702*cdf0e10cSrcweir //    {
703*cdf0e10cSrcweir //        System.out.println("---- Testing the XMultiPropertySet interface ----");
704*cdf0e10cSrcweir //        XMultiPropertySet xMPS = UnoRuntime.queryInterface(XMultiPropertySet.class, aPathSettings);
705*cdf0e10cSrcweir //
706*cdf0e10cSrcweir //        // xPropertyInfoOfPathSettings.length
707*cdf0e10cSrcweir //        String[] propertiesToTest = new String[1];
708*cdf0e10cSrcweir //        propertiesToTest[0] = availablePropNames[0];
709*cdf0e10cSrcweir //
710*cdf0e10cSrcweir //        String[] correctVals = new String[propertiesToTest.length];
711*cdf0e10cSrcweir //        String[] incorrectVals = new String[propertiesToTest.length];
712*cdf0e10cSrcweir //
713*cdf0e10cSrcweir //        String[] aPathSettingWorkingNames = null;
714*cdf0e10cSrcweir //        aPathSettingWorkingNames = new String[propertiesToTest.length];
715*cdf0e10cSrcweir //
716*cdf0e10cSrcweir //        // get intitial values and create new ones
717*cdf0e10cSrcweir //        for (int i = 0; i < propertiesToTest.length; i++)
718*cdf0e10cSrcweir //        {
719*cdf0e10cSrcweir //            // Property aProp = aListOfWorkingProperty.get(i);
720*cdf0e10cSrcweir //            final String sName = propertiesToTest[i];
721*cdf0e10cSrcweir //            final String sValue = getPropertyValueAsString(sName);
722*cdf0e10cSrcweir //            aPathSettingWorkingNames[i] = sName;
723*cdf0e10cSrcweir //            correctVals[i] = changeToCorrectValue(sValue);
724*cdf0e10cSrcweir //            incorrectVals[i] = changeToIncorrectValue(sValue);
725*cdf0e10cSrcweir //        }
726*cdf0e10cSrcweir //
727*cdf0e10cSrcweir //        try
728*cdf0e10cSrcweir //        {
729*cdf0e10cSrcweir //            // add a change listener
730*cdf0e10cSrcweir //            MyChangeListener mListener = new MyChangeListener();
731*cdf0e10cSrcweir //            xMPS.addPropertiesChangeListener(aPathSettingWorkingNames, mListener);
732*cdf0e10cSrcweir //
733*cdf0e10cSrcweir //            // first change xPropertyInfoOfPathSettings to correct values
734*cdf0e10cSrcweir //            System.out.println("Change to correct values.");
735*cdf0e10cSrcweir //            xMPS.setPropertyValues(aPathSettingWorkingNames, correctVals);
736*cdf0e10cSrcweir //            assertTrue("Could not change to correct values with XMultiPropertySet.",
737*cdf0e10cSrcweir //                    verifyPropertySet(xMPS, aPathSettingWorkingNames, correctVals) > 0);
738*cdf0e10cSrcweir //
739*cdf0e10cSrcweir //            // second, change to incorrect values: expect an exception
740*cdf0e10cSrcweir //            System.out.println("Try to change to incorrect values.");
741*cdf0e10cSrcweir //            try
742*cdf0e10cSrcweir //            {
743*cdf0e10cSrcweir //                xMPS.setPropertyValues(aPathSettingWorkingNames, incorrectVals);
744*cdf0e10cSrcweir //            }
745*cdf0e10cSrcweir //            catch (com.sun.star.lang.IllegalArgumentException r)
746*cdf0e10cSrcweir //            {
747*cdf0e10cSrcweir //                System.out.println("Correctly thrown Exception caught.");
748*cdf0e10cSrcweir //            }
749*cdf0e10cSrcweir //            assertTrue("Did change to incorrect values with XMultiPropertySet,"
750*cdf0e10cSrcweir //                    + " but should not have.",
751*cdf0e10cSrcweir //                    verifyPropertySet(xMPS, aPathSettingWorkingNames, correctVals) > 0);
752*cdf0e10cSrcweir //
753*cdf0e10cSrcweir //            // third, change back to initial values
754*cdf0e10cSrcweir //            System.out.println("Change back to initial values.");
755*cdf0e10cSrcweir //            xMPS.setPropertyValues(aPathSettingWorkingNames, aPathSettingValues);
756*cdf0e10cSrcweir //            assertTrue("Could not change back to initial values with"
757*cdf0e10cSrcweir //                    + " XMultiPropertySet.",
758*cdf0e10cSrcweir //                    verifyPropertySet(xMPS, aPathSettingWorkingNames, aPathSettingValues) > 0);
759*cdf0e10cSrcweir //
760*cdf0e10cSrcweir //            // fire the event for the listener
761*cdf0e10cSrcweir //            System.out.println("Fire event.");
762*cdf0e10cSrcweir //            xMPS.firePropertiesChangeEvent(aPathSettingWorkingNames, mListener);
763*cdf0e10cSrcweir //            assertTrue("Event was not fired on XMultiPropertySet.",
764*cdf0e10cSrcweir //                    mListener.changePropertiesEventFired());
765*cdf0e10cSrcweir //        }
766*cdf0e10cSrcweir //        catch (com.sun.star.uno.Exception e)
767*cdf0e10cSrcweir //        {
768*cdf0e10cSrcweir ////            e.printStackTrace();
769*cdf0e10cSrcweir //            System.out.println(e.getClass().getName());
770*cdf0e10cSrcweir //            System.out.println("Message: " + e.getMessage());
771*cdf0e10cSrcweir //            fail("Unexpected exception on XMultiPropertySet.");
772*cdf0e10cSrcweir //        }
773*cdf0e10cSrcweir //
774*cdf0e10cSrcweir //        // test finished
775*cdf0e10cSrcweir //        System.out.println("---- Test of XMultiPropertySet finished ----\n");
776*cdf0e10cSrcweir //    }
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir     /**
779*cdf0e10cSrcweir      * Verify if the values of xPropSet_of_PathSettings are the same as vals.
780*cdf0e10cSrcweir      * @param xPropSet_of_PathSettings A XMultiPropertySet.
781*cdf0e10cSrcweir      * @param aPathSettingWorkingNames An array with property names.
782*cdf0e10cSrcweir      * @param vals An array with values of the properties
783*cdf0e10cSrcweir      * @return -1 if none are equal, 1 if all are equal, 0 if some were equal
784*cdf0e10cSrcweir      * and some not.
785*cdf0e10cSrcweir      * @throws com.sun.star.lang.IllegalArgumentException
786*cdf0e10cSrcweir      */
787*cdf0e10cSrcweir //    private int verifyPropertySet(XMultiPropertySet xProp,
788*cdf0e10cSrcweir //            String[] propNames, String[] vals)
789*cdf0e10cSrcweir //    {
790*cdf0e10cSrcweir //        int ret = 0;
791*cdf0e10cSrcweir //        if (vals.length != propNames.length)
792*cdf0e10cSrcweir //        {
793*cdf0e10cSrcweir //            System.out.println("Length of array parameters must be equal.");
794*cdf0e10cSrcweir //            return ret;
795*cdf0e10cSrcweir //        }
796*cdf0e10cSrcweir //        for (int i = 0; i < vals.length; i++)
797*cdf0e10cSrcweir //        {
798*cdf0e10cSrcweir //            Object[] objs = xProp.getPropertyValues(new String[]
799*cdf0e10cSrcweir //                    {
800*cdf0e10cSrcweir //                        propNames[i]
801*cdf0e10cSrcweir //                    });
802*cdf0e10cSrcweir //            String retVal = (String) objs[0];
803*cdf0e10cSrcweir //            boolean nCheck = retVal.equals(vals[i]);
804*cdf0e10cSrcweir //            if (!nCheck)
805*cdf0e10cSrcweir //            {
806*cdf0e10cSrcweir //                System.out.println("Property '" + propNames[i]
807*cdf0e10cSrcweir //                        + "' was supposed to have value:");
808*cdf0e10cSrcweir //                System.out.println(vals[i]);
809*cdf0e10cSrcweir //                System.out.println("but has value:");
810*cdf0e10cSrcweir //                System.out.println(retVal);
811*cdf0e10cSrcweir //            }
812*cdf0e10cSrcweir //            // initialize
813*cdf0e10cSrcweir //            if (i == 0)
814*cdf0e10cSrcweir //            {
815*cdf0e10cSrcweir //                ret = nCheck ? 1 : -1;
816*cdf0e10cSrcweir //                continue;
817*cdf0e10cSrcweir //            }
818*cdf0e10cSrcweir //            // return 0 if equal state changes compared to initial value
819*cdf0e10cSrcweir //            if ((nCheck && ret < 0) || (!nCheck && ret > 0))
820*cdf0e10cSrcweir //            {
821*cdf0e10cSrcweir //                ret = 0;
822*cdf0e10cSrcweir //            }
823*cdf0e10cSrcweir //        }
824*cdf0e10cSrcweir //        return ret;
825*cdf0e10cSrcweir //    }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir     // ____________________
828*cdf0e10cSrcweir     /**
829*cdf0e10cSrcweir      * This tests the XPropertySet interface implementation.
830*cdf0e10cSrcweir      */
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir // The test checkXPropertySet() has been marked as outdated!
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir //    @Test
836*cdf0e10cSrcweir //    public void checkXPropertySet()
837*cdf0e10cSrcweir //    {
838*cdf0e10cSrcweir //        System.out.println("---- Testing the XPropertySet interface ----");
839*cdf0e10cSrcweir //
840*cdf0e10cSrcweir //        XPropertySet xPS = UnoRuntime.queryInterface(XPropertySet.class, aPathSettings);
841*cdf0e10cSrcweir //
842*cdf0e10cSrcweir //        MyChangeListener mListener1 = new MyChangeListener();
843*cdf0e10cSrcweir //        MyChangeListener mListener2 = new MyChangeListener();
844*cdf0e10cSrcweir //
845*cdf0e10cSrcweir //        for (int i = 0; i < xPropertyInfoOfPathSettings.length; i++)
846*cdf0e10cSrcweir //        {
847*cdf0e10cSrcweir //            // adding listeners
848*cdf0e10cSrcweir //            String name = aPathSettingNames[i];
849*cdf0e10cSrcweir //            System.out.println("Testing property '" + name + "'");
850*cdf0e10cSrcweir //            try
851*cdf0e10cSrcweir //            {
852*cdf0e10cSrcweir //                System.out.println("Add 2 Listeners.");
853*cdf0e10cSrcweir //                xPS.addPropertyChangeListener(name, mListener1);
854*cdf0e10cSrcweir //                xPS.addVetoableChangeListener(name, mListener1);
855*cdf0e10cSrcweir //                xPS.addPropertyChangeListener(name, mListener2);
856*cdf0e10cSrcweir //                xPS.addVetoableChangeListener(name, mListener2);
857*cdf0e10cSrcweir //
858*cdf0e10cSrcweir //                // change the property
859*cdf0e10cSrcweir //                System.out.println("Change value.");
860*cdf0e10cSrcweir //                String changeVal = changeToCorrectValue(aPathSettingValues[i]);
861*cdf0e10cSrcweir //                xPS.setPropertyValue(name, changeVal);
862*cdf0e10cSrcweir //                String newVal = (String) xPS.getPropertyValue(name);
863*cdf0e10cSrcweir //
864*cdf0e10cSrcweir //                assertTrue("Value did not change on property " + name + ".",
865*cdf0e10cSrcweir //                        newVal.equals(changeVal));
866*cdf0e10cSrcweir //
867*cdf0e10cSrcweir //                assertTrue("Listener 1 was not called.", checkListener(mListener1));
868*cdf0e10cSrcweir //                assertTrue("Listener 2 was not called.", checkListener(mListener2));
869*cdf0e10cSrcweir //
870*cdf0e10cSrcweir //                mListener1.resetListener();
871*cdf0e10cSrcweir //                mListener2.resetListener();
872*cdf0e10cSrcweir //
873*cdf0e10cSrcweir //                System.out.println("Remove Listener 1.");
874*cdf0e10cSrcweir //
875*cdf0e10cSrcweir //                xPS.removePropertyChangeListener(name, mListener1);
876*cdf0e10cSrcweir //                xPS.removeVetoableChangeListener(name, mListener1);
877*cdf0e10cSrcweir //
878*cdf0e10cSrcweir //                // change the property
879*cdf0e10cSrcweir //                System.out.println("Change value back.");
880*cdf0e10cSrcweir //                xPS.setPropertyValue(name, aPathSettingValues[i]);
881*cdf0e10cSrcweir //                newVal = (String) xPS.getPropertyValue(name);
882*cdf0e10cSrcweir //                assertTrue("Value did not change on property " + name,
883*cdf0e10cSrcweir //                        newVal.equals(aPathSettingValues[i]));
884*cdf0e10cSrcweir //
885*cdf0e10cSrcweir //                assertTrue("Listener was called, although it was removed on"
886*cdf0e10cSrcweir //                        + " property " + name + ".", !checkListener(mListener1));
887*cdf0e10cSrcweir //                assertTrue("Listener 2 was not called on property " + name + ".",
888*cdf0e10cSrcweir //                        checkListener(mListener2));
889*cdf0e10cSrcweir //            }
890*cdf0e10cSrcweir //            catch (com.sun.star.uno.Exception e)
891*cdf0e10cSrcweir //            {
892*cdf0e10cSrcweir //                System.out.println(e.getClass().getName());
893*cdf0e10cSrcweir //                System.out.println("Message: " + e.getMessage());
894*cdf0e10cSrcweir //                fail("Unexpcted exception on property " + name);
895*cdf0e10cSrcweir //            }
896*cdf0e10cSrcweir //            System.out.println("Finish testing property '" + aPathSettingNames[i] + "'\n");
897*cdf0e10cSrcweir //        }
898*cdf0e10cSrcweir //        System.out.println("---- Test of XPropertySet finished ----\n");
899*cdf0e10cSrcweir //
900*cdf0e10cSrcweir //    }
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir //    private boolean checkListener(MyChangeListener ml)
903*cdf0e10cSrcweir //    {
904*cdf0e10cSrcweir //        return ml.changePropertyEventFired()
905*cdf0e10cSrcweir //                || ml.changePropertiesEventFired()
906*cdf0e10cSrcweir //                || ml.vetoableChangeEventFired();
907*cdf0e10cSrcweir //    }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir     // ____________________
910*cdf0e10cSrcweir     /**
911*cdf0e10cSrcweir      * Change the given String to a correct path URL.
912*cdf0e10cSrcweir      * @return The changed path URL.
913*cdf0e10cSrcweir      */
914*cdf0e10cSrcweir     private String changeToCorrectValue(String path)
915*cdf0e10cSrcweir     {
916*cdf0e10cSrcweir         // the simplest possiblity
917*cdf0e10cSrcweir         if (path == null || path.equals(""))
918*cdf0e10cSrcweir         {
919*cdf0e10cSrcweir             String sTempDir = System.getProperty("java.io.tmpdir");
920*cdf0e10cSrcweir             sTempDir = util.utils.getFullURL(sTempDir);
921*cdf0e10cSrcweir             return sTempDir; // "file:///tmp";
922*cdf0e10cSrcweir         }
923*cdf0e10cSrcweir         return graphical.FileHelper.appendPath(path, "tmp");
924*cdf0e10cSrcweir     }
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir     /**
927*cdf0e10cSrcweir      * Change the given String to an incorrect path URL.
928*cdf0e10cSrcweir      * @return The changed path URL.
929*cdf0e10cSrcweir      */
930*cdf0e10cSrcweir     private String changeToIncorrectValue(String path)
931*cdf0e10cSrcweir     {
932*cdf0e10cSrcweir         // return an illegal path
933*cdf0e10cSrcweir         return "fileblablabla";
934*cdf0e10cSrcweir     }
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir     /**
937*cdf0e10cSrcweir      * Listener implementation which sets a flag when
938*cdf0e10cSrcweir      * listener was called.
939*cdf0e10cSrcweir      */
940*cdf0e10cSrcweir     public class MyChangeListener implements XPropertiesChangeListener,
941*cdf0e10cSrcweir             XPropertyChangeListener,
942*cdf0e10cSrcweir             XVetoableChangeListener
943*cdf0e10cSrcweir     {
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir         private boolean propChanged = false;
946*cdf0e10cSrcweir         private boolean propertiesChanged = false;
947*cdf0e10cSrcweir         private boolean disposeCalled = false;
948*cdf0e10cSrcweir         private boolean vetoableChanged = false;
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir         public void propertiesChange(
951*cdf0e10cSrcweir                 com.sun.star.beans.PropertyChangeEvent[] e)
952*cdf0e10cSrcweir         {
953*cdf0e10cSrcweir             propertiesChanged = true;
954*cdf0e10cSrcweir         }
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir         public void vetoableChange(com.sun.star.beans.PropertyChangeEvent pE)
957*cdf0e10cSrcweir                 throws com.sun.star.beans.PropertyVetoException
958*cdf0e10cSrcweir         {
959*cdf0e10cSrcweir             vetoableChanged = true;
960*cdf0e10cSrcweir         }
961*cdf0e10cSrcweir 
962*cdf0e10cSrcweir         public void propertyChange(com.sun.star.beans.PropertyChangeEvent pE)
963*cdf0e10cSrcweir         {
964*cdf0e10cSrcweir             propChanged = true;
965*cdf0e10cSrcweir         }
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir         public void disposing(com.sun.star.lang.EventObject eventObject)
968*cdf0e10cSrcweir         {
969*cdf0e10cSrcweir             disposeCalled = true;
970*cdf0e10cSrcweir         }
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir         public void resetListener()
973*cdf0e10cSrcweir         {
974*cdf0e10cSrcweir             propChanged = false;
975*cdf0e10cSrcweir             propertiesChanged = false;
976*cdf0e10cSrcweir             disposeCalled = false;
977*cdf0e10cSrcweir             vetoableChanged = false;
978*cdf0e10cSrcweir         }
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir         public boolean changePropertyEventFired()
981*cdf0e10cSrcweir         {
982*cdf0e10cSrcweir             return propChanged;
983*cdf0e10cSrcweir         }
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir         public boolean changePropertiesEventFired()
986*cdf0e10cSrcweir         {
987*cdf0e10cSrcweir             return propertiesChanged;
988*cdf0e10cSrcweir         }
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir         public boolean vetoableChangeEventFired()
991*cdf0e10cSrcweir         {
992*cdf0e10cSrcweir             return vetoableChanged;
993*cdf0e10cSrcweir         }
994*cdf0e10cSrcweir     }
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir     private XMultiServiceFactory getMSF()
997*cdf0e10cSrcweir     {
998*cdf0e10cSrcweir         final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
999*cdf0e10cSrcweir         return xMSF1;
1000*cdf0e10cSrcweir     }
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir     // setup and close connections
1003*cdf0e10cSrcweir     @BeforeClass
1004*cdf0e10cSrcweir     public static void setUpConnection() throws Exception
1005*cdf0e10cSrcweir     {
1006*cdf0e10cSrcweir         System.out.println("setUpConnection()");
1007*cdf0e10cSrcweir         connection.setUp();
1008*cdf0e10cSrcweir     }
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir     @AfterClass
1011*cdf0e10cSrcweir     public static void tearDownConnection()
1012*cdf0e10cSrcweir             throws InterruptedException, com.sun.star.uno.Exception
1013*cdf0e10cSrcweir     {
1014*cdf0e10cSrcweir         System.out.println("tearDownConnection()");
1015*cdf0e10cSrcweir         connection.tearDown();
1016*cdf0e10cSrcweir     }
1017*cdf0e10cSrcweir     private static final OfficeConnection connection = new OfficeConnection();
1018*cdf0e10cSrcweir }
1019