summaryrefslogtreecommitdiff
path: root/framework/qa/complex
diff options
context:
space:
mode:
authorRĂ¼diger Timm <rt@openoffice.org>2007-07-24 12:27:52 +0000
committerRĂ¼diger Timm <rt@openoffice.org>2007-07-24 12:27:52 +0000
commitf9e335dc2d75ed2781f8729bc4a08828587fe762 (patch)
tree6719a518f333bf208efcbde26c09eba59665f681 /framework/qa/complex
parent6bde155a09de982ef21e9bfe9f8230ddd31a17c2 (diff)
INTEGRATION: CWS complextest1 (1.1.2); FILE ADDED
2007/06/22 14:13:04 sg 1.1.2.1: #i78662# distributed complex tests for framework
Diffstat (limited to 'framework/qa/complex')
-rwxr-xr-xframework/qa/complex/path_settings/PathSettingsTest.java492
1 files changed, 492 insertions, 0 deletions
diff --git a/framework/qa/complex/path_settings/PathSettingsTest.java b/framework/qa/complex/path_settings/PathSettingsTest.java
new file mode 100755
index 0000000000..7682c9a659
--- /dev/null
+++ b/framework/qa/complex/path_settings/PathSettingsTest.java
@@ -0,0 +1,492 @@
+/*************************************************************************
+ *
+ * $RCSfile: PathSettingsTest.java,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Date: 2007-07-24 13:27:52 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2002 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+package complex.path_settings;
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.XFastPropertySet;
+import com.sun.star.beans.XMultiPropertySet;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.XPropertiesChangeListener;
+import com.sun.star.beans.XPropertyChangeListener;
+import com.sun.star.beans.XVetoableChangeListener;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+import complexlib.ComplexTestCase;
+
+public class PathSettingsTest extends ComplexTestCase {
+
+ private static XMultiServiceFactory xMSF;
+
+ // the test object: an instance of the tested service
+ private static Object oObj = null;
+ // the properties of the service
+ private static Property[] props = null;
+ private static String[] propNames = null;
+ private static String[] availablePropNames = new String[]{
+ "Addin",
+ "AutoCorrect",
+ "Autotext",
+ "Backup",
+ "Basic",
+ "Bitmap",
+ "Config",
+ "Dictionary",
+ "Favorite",
+ "Filter",
+ "Gallery",
+ "Help",
+ "Linguistic",
+ "Module",
+ "Palette",
+ "Plugin",
+ "Temp",
+ "Template",
+ "UIConfig",
+ "UserConfig",
+ "UserDictionary",
+ "Work",
+};
+ private static String[] propVals = null;
+
+ /**
+ * A function to tell the framework, which test functions are available.
+ * Right now, it's only 'checkComplexTemplateState'.
+ * @return All test methods.
+ */
+ public String[] getTestMethodNames() {
+ return new String[]{"checkXFastPropertySet",
+ "checkXMultiPropertySet",
+ "checkXPropertySet"
+ };
+ }
+
+ /**
+ * Initialize before the tests start: this has to be done only once.
+ * This methods sets the 'oObj' and 'props' variables.
+ */
+ public void before() {
+ try {
+ xMSF = (XMultiServiceFactory)param.getMSF();
+// oObj = xMSF.createInstance("com.sun.star.util.PathSettings");
+ oObj = xMSF.createInstance("com.sun.star.comp.framework.PathSettings");
+ System.out.println("Implementation: " + util.utils.getImplName(oObj));
+ System.out.println("Service: ");
+ util.dbg.getSuppServices(oObj);
+ if (oObj == null) throw new com.sun.star.uno.Exception();
+ XPropertySet xProp = (XPropertySet)
+ UnoRuntime.queryInterface(XPropertySet.class, oObj);
+
+ props = xProp.getPropertySetInfo().getProperties();
+ propNames = new String[props.length];
+ propVals = new String[props.length];
+
+ // get intitial values and create new ones
+ log.println("\n---- All properties ----");
+ for (int i = 1; i < props.length; i++) {
+ propNames[i] = props[i].Name;
+ Object o = xProp.getPropertyValue(propNames[i]);
+ System.out.println("#### Object: " + o.getClass().getName() + " - " + o.toString());
+ propVals[i] = AnyConverter.toString(o);
+ System.out.println("#### String " + propVals[i]);
+ log.println("Property Name: " + propNames[i]);
+ log.println("Property Value: " + propVals[i]);
+ }
+ log.println("---- Finish showing properties ----\n");
+ }
+ catch(com.sun.star.uno.Exception e) {
+ e.printStackTrace();
+ log.println(e.getClass().getName());
+ log.println("Message: " + e.getMessage());
+ failed("Could not create an instance of the test object.");
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ failed("What exception?");
+ }
+ }
+
+ /**
+ * This tests the XFastPropertySet interface implementation.
+ */
+ public void checkXFastPropertySet()
+ {
+ log.println("---- Testing the XFastPropertySet interface ----");
+
+ // creating instances
+ XFastPropertySet xFPS = (XFastPropertySet)
+ UnoRuntime.queryInterface(XFastPropertySet.class, oObj);
+
+ String name = null;
+ // do for all properties
+ for (int i = 0; i < props.length; i++) {
+ try {
+ Property property = props[i];
+ name = property.Name;
+ int handle = property.Handle;
+
+ // get property name and initial value
+ log.println("Test property with name: " + name);
+ String val = (String)xFPS.getFastPropertyValue(handle);
+ log.println("Property has initial value: '" + val + "'");
+
+ // set to a new correct value
+ String newVal = changeToCorrectValue(val);
+ log.println("Try to change to correct value '" + newVal + "'");
+ xFPS.setFastPropertyValue(handle, newVal);
+
+ // check the change
+ String checkVal = (String)xFPS.getFastPropertyValue(handle);
+ assure("Did not change value on property " + name + ".", checkVal.equals(newVal));
+
+ newVal = changeToIncorrectValue(val);
+ log.println("Try to change to incorrect value '" + newVal + "'");
+ try {
+ xFPS.setFastPropertyValue(handle, newVal);
+ }
+ catch(com.sun.star.lang.IllegalArgumentException e) {
+ log.println("Correctly thrown Exception caught.");
+ }
+
+ // check if changed
+ checkVal = (String)xFPS.getFastPropertyValue(handle);
+ assure("Value did change on property " + name + " though it should not have.",
+ !checkVal.equals(newVal));
+
+ // set back to initial setting
+ xFPS.setFastPropertyValue(handle, val);
+
+ // check if changed
+ checkVal = (String)xFPS.getFastPropertyValue(handle);
+ assure("Did not change value back to original on property "
+ + name, checkVal.equals(val));
+ log.println("Test of property " + name + " finished\n");
+ }
+ catch(com.sun.star.uno.Exception e) {
+// e.printStackTrace();
+ log.println(e.getClass().getName());
+ log.println("Message: " + e.getMessage());
+ failed("Unexpected exception on property " + name + ".");
+ continue;
+ }
+ }
+ log.println("---- Test of XFastPropertySet finished ----\n");
+ }
+
+
+ // ____________________
+ /**
+ * This tests the XMultiPropertySet interface implementation.
+ */
+ public void checkXMultiPropertySet()
+ {
+ log.println("---- Testing the XMultiPropertySet interface ----");
+ XMultiPropertySet xMPS = (XMultiPropertySet)
+ UnoRuntime.queryInterface(XMultiPropertySet.class, oObj);
+
+ String[] correctVals = new String[props.length];
+ String[] incorrectVals = new String[props.length];
+
+ // get intitial values and create new ones
+ for (int i = 0; i < props.length; i++) {
+ correctVals[i] = changeToCorrectValue(propVals[i]);
+ incorrectVals[i] = changeToIncorrectValue(propVals[i]);
+ }
+
+ try {
+ // add a change listener
+ MyChangeListener mListener = new MyChangeListener();
+ xMPS.addPropertiesChangeListener(propNames, mListener);
+
+ // first change props to correct values
+ log.println("Change to correct values.");
+ xMPS.setPropertyValues(propNames, correctVals);
+ assure("Could not change to correct values with XMultiPropoertySet.",
+ verifyPropertySet(xMPS,propNames,correctVals)>0);
+
+ // second, change to incorrect values: expect an exception
+ log.println("Try to change to incorrect values.");
+ try {
+ xMPS.setPropertyValues(propNames, incorrectVals);
+ }
+ catch(com.sun.star.lang.IllegalArgumentException r) {
+ log.println("Correctly thrown Exception caught.");
+ }
+ assure("Did change to incorrect values with XMultiPropertySet," +
+ " but should not have.",
+ verifyPropertySet(xMPS,propNames,correctVals)>0);
+
+ // third, change back to initial values
+ log.println("Change back to initial values.");
+ xMPS.setPropertyValues(propNames, propVals);
+ assure("Could not change back to initial values with" +
+ " XMultiPropertySet.",
+ verifyPropertySet(xMPS,propNames,propVals)>0);
+
+ // fire the event for the listener
+ log.println("Fire event.");
+ xMPS.firePropertiesChangeEvent(propNames, mListener);
+ assure("Event was not fired on XMultiPropertySet.",
+ mListener.changePropertiesEventFired());
+ }
+ catch(com.sun.star.uno.Exception e) {
+// e.printStackTrace();
+ log.println(e.getClass().getName());
+ log.println("Message: " + e.getMessage());
+ failed("Unexpected exception on XMultiPropertySet.");
+ }
+
+ // test finished
+ log.println("---- Test of XMultiPropertySet finished ----\n");
+ }
+
+ /**
+ * Verify if the values of xProp are the same as vals.
+ * @param xProp A XMultiPropertySet.
+ * @param propNames An array with property names.
+ * @param vals An array with values of the properties
+ * @return -1 if none are equal, 1 if all are equal, 0 if some were equal
+ * and some not.
+ * @throws com.sun.star.lang.IllegalArgumentException
+ */
+ private int verifyPropertySet(XMultiPropertySet xProp,
+ String[] propNames, String[] vals)
+ {
+ int ret=0;
+ if (vals.length != propNames.length) {
+ log.println("Length of array parameters must be equal.");
+ return ret;
+ }
+ for (int i = 0; i < vals.length; i++) {
+ Object[] objs = xProp.getPropertyValues(new String[]{propNames[i]});
+ String retVal = (String)objs[0];
+ boolean nCheck = retVal.equals(vals[i]);
+ if (!nCheck) {
+ log.println("Property '" + propNames[i] +
+ "' was supposed to have value:");
+ log.println(vals[i]);
+ log.println("but has value:");
+ log.println(retVal);
+ }
+ // initialize
+ if (i==0) {
+ ret = nCheck?1:-1;
+ continue;
+ }
+ // return 0 if equal state changes compared to initial value
+ if ((nCheck && ret<0) || (!nCheck && ret>0)) {
+ ret = 0;
+ }
+ }
+ return ret;
+ }
+
+
+ // ____________________
+ /**
+ * This tests the XPropertySet interface implementation.
+ */
+ public void checkXPropertySet()
+ {
+ log.println("---- Testing the XPropertySet interface ----");
+
+ XPropertySet xPS = (XPropertySet)
+ UnoRuntime.queryInterface(XPropertySet.class, oObj);
+
+ MyChangeListener mListener1 = new MyChangeListener();
+ MyChangeListener mListener2 = new MyChangeListener();
+
+ for (int i=0; i<props.length; i++) {
+ // adding listeners
+ String name = propNames[i];
+ log.println("Testing property '" + name + "'");
+ try {
+ log.println("Add 2 Listeners.");
+ xPS.addPropertyChangeListener(name, mListener1);
+ xPS.addVetoableChangeListener(name, mListener1);
+ xPS.addPropertyChangeListener(name, mListener2);
+ xPS.addVetoableChangeListener(name, mListener2);
+
+ // change the property
+ log.println("Change value.");
+ String changeVal = changeToCorrectValue(propVals[i]);
+ xPS.setPropertyValue(name, changeVal);
+ String newVal = (String)xPS.getPropertyValue(name);
+
+ assure("Value did not change on property " + name + ".",
+ newVal.equals(changeVal));
+
+ assure("Listener 1 was not called.", checkListener(mListener1), true);
+ assure("Listener 2 was not called.", checkListener(mListener2), true);
+
+ mListener1.resetListener();
+ mListener2.resetListener();
+
+ log.println("Remove Listener 1.");
+
+ xPS.removePropertyChangeListener(name, mListener1);
+ xPS.removeVetoableChangeListener(name, mListener1);
+
+ // change the property
+ log.println("Change value back.");
+ xPS.setPropertyValue(name, propVals[i]);
+ newVal = (String)xPS.getPropertyValue(name);
+ assure("Value did not change on property " + name,
+ newVal.equals(propVals[i]));
+
+ assure("Listener was called, although it was removed on" +
+ " property " + name + ".", !checkListener(mListener1), true);
+ assure("Listener 2 was not called on property " + name + ".",
+ checkListener(mListener2), true);
+ }
+ catch(com.sun.star.uno.Exception e) {
+ e.printStackTrace();
+ log.println(e.getClass().getName());
+ log.println("Message: " + e.getMessage());
+ failed("Unexpcted exception on property " + name);
+ continue;
+ }
+ log.println("Finish testing property '" + propNames[i] + "'\n");
+ }
+ log.println("---- Test of XPropertySet finished ----\n");
+
+ }
+
+ private boolean checkListener(MyChangeListener ml) {
+ return ml.changePropertyEventFired() ||
+ ml.changePropertiesEventFired() ||
+ ml.vetoableChangeEventFired();
+ }
+
+ // ____________________
+ /**
+ * Change the given String to a correct path URL.
+ * @return The changed path URL.
+ */
+ private String changeToCorrectValue(String path) {
+ // the simplest possiblity
+ if ( path == null || path.equals("") ) {
+ return "file:///tmp";
+ }
+ return path + "/tmp";
+ }
+
+
+ /**
+ * Change the given String to an incorrect path URL.
+ * @return The changed path URL.
+ */
+ private String changeToIncorrectValue(String path) {
+ // the simplest possiblity
+ return "fileblablabla";
+ }
+
+
+ /**
+ * Listener implementation which sets a flag when
+ * listener was called.
+ */
+ public class MyChangeListener implements XPropertiesChangeListener,
+ XPropertyChangeListener,
+ XVetoableChangeListener {
+
+ private boolean propChanged = false;
+ private boolean propertiesChanged = false;
+ private boolean disposeCalled = false;
+ private boolean vetoableChanged = false;
+
+ public void propertiesChange(
+ com.sun.star.beans.PropertyChangeEvent[] e) {
+ propertiesChanged = true;
+ }
+
+ public void vetoableChange(com.sun.star.beans.PropertyChangeEvent pE)
+ throws com.sun.star.beans.PropertyVetoException {
+ vetoableChanged = true;
+ }
+
+ public void propertyChange(com.sun.star.beans.PropertyChangeEvent pE) {
+ propChanged = true;
+ }
+
+ public void disposing(com.sun.star.lang.EventObject eventObject) {
+ disposeCalled = true;
+ }
+
+ public void resetListener() {
+ propChanged = false;
+ propertiesChanged = false;
+ disposeCalled = false;
+ vetoableChanged = false;
+ }
+
+ public boolean changePropertyEventFired() {
+ return propChanged;
+ }
+ public boolean changePropertiesEventFired() {
+ return propertiesChanged;
+ }
+ public boolean vetoableChangeEventFired() {
+ return vetoableChanged;
+ }
+
+ };
+}