diff options
Diffstat (limited to 'toolkit/qa/complex')
18 files changed, 1928 insertions, 742 deletions
diff --git a/toolkit/qa/complex/toolkit/CheckAccessibleStatusBar.java b/toolkit/qa/complex/toolkit/AccessibleStatusBar.java index cfb40614beab..d4f2329d8f31 100755 --- a/toolkit/qa/complex/toolkit/CheckAccessibleStatusBar.java +++ b/toolkit/qa/complex/toolkit/AccessibleStatusBar.java @@ -27,12 +27,15 @@ package complex.toolkit; -// import complexlib.ComplexTestCase; -import lib.TestParameters; +import complex.toolkit.accessibility._XAccessibleEventBroadcaster; +import complex.toolkit.accessibility._XAccessibleExtendedComponent; +import complex.toolkit.accessibility._XAccessibleComponent; +import complex.toolkit.accessibility._XAccessibleContext; +import java.util.logging.Logger; +import java.util.logging.Level; import util.SOfficeFactory; import util.AccessibilityTools; import com.sun.star.awt.XWindow; -// import com.sun.star.chart.XChartDocument; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XComponent; import com.sun.star.lang.XServiceInfo; @@ -45,11 +48,8 @@ import com.sun.star.accessibility.AccessibleRole; import com.sun.star.accessibility.XAccessible; import com.sun.star.accessibility.XAccessibleContext; import com.sun.star.awt.XExtendedToolkit; -// import java.io.PrintWriter; -// import org.junit.After; import org.junit.AfterClass; -// import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.openoffice.test.OfficeConnection; @@ -58,26 +58,12 @@ import static org.junit.Assert.*; /** * */ -public class CheckAccessibleStatusBar { +public class AccessibleStatusBar { XInterface testObject = null; XMultiServiceFactory xMSF = null; XWindow xWindow = null; - /** - * The test parameters - */ - private static TestParameters param = null; - -// public String[] getTestMethodNames() { -// return new String[]{"checkDocs"};//WriterDoc", "checkDrawDoc", -//// "checkMathDoc", "checkImpressDoc", "checkCalcDoc"}; -// } - -/* public String getTestObjectName() { - return "com.sun.star.awt.AccessibleStatusBar"; - } -*/ private XMultiServiceFactory getMSF() { final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); @@ -100,41 +86,13 @@ public class CheckAccessibleStatusBar { /** * Check document types */ - @Test public void checkDocs() { - Object doc = param.get("DocType"); - String testDocType; - if (doc == null) - { - testDocType = "all"; - } - else - { - testDocType = (String)doc; - } - - System.out.println("Param was " + doc); - System.out.println("DocType " + testDocType); - if (testDocType.equalsIgnoreCase("writer") || testDocType.equalsIgnoreCase("all")) - { - checkWriterDoc(); - } - if (testDocType.equalsIgnoreCase("math") || testDocType.equalsIgnoreCase("all")) - { - checkMathDoc(); - } - if (testDocType.equalsIgnoreCase("draw") || testDocType.equalsIgnoreCase("all")) - { - checkDrawDoc(); - } - if (testDocType.equalsIgnoreCase("impress") || testDocType.equalsIgnoreCase("all")) - { - checkImpressDoc(); - } - if (testDocType.equalsIgnoreCase("calc") || testDocType.equalsIgnoreCase("all")) - { - checkCalcDoc(); - } - + @Test + public void checkDocs() { + checkWriterDoc(); + checkMathDoc(); + checkDrawDoc(); + checkImpressDoc(); + checkCalcDoc(); } /** @@ -150,7 +108,7 @@ public class CheckAccessibleStatusBar { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -160,7 +118,7 @@ public class CheckAccessibleStatusBar { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -178,7 +136,7 @@ public class CheckAccessibleStatusBar { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -188,7 +146,7 @@ public class CheckAccessibleStatusBar { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -206,7 +164,7 @@ public class CheckAccessibleStatusBar { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -216,7 +174,7 @@ public class CheckAccessibleStatusBar { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -234,7 +192,7 @@ public class CheckAccessibleStatusBar { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -244,7 +202,7 @@ public class CheckAccessibleStatusBar { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -262,7 +220,7 @@ public class CheckAccessibleStatusBar { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -272,7 +230,7 @@ public class CheckAccessibleStatusBar { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -287,12 +245,11 @@ public class CheckAccessibleStatusBar { xWindow = UnoRuntime.queryInterface(XWindow.class, tk.getActiveTopWindow()); shortWait(); - AccessibilityTools at = new AccessibilityTools(); - XAccessible xRoot = at.getAccessibleObject(xWindow); + XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); XAccessibleContext parentContext = null; System.out.println("Get the accessible status bar."); - parentContext = at.getAccessibleObjectForRole( + parentContext = AccessibilityTools.getAccessibleObjectForRole( xRoot, AccessibleRole.STATUS_BAR, ""); shortWait(); System.out.println("...OK."); @@ -309,11 +266,11 @@ public class CheckAccessibleStatusBar { testObject=parentContext; } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } catch(Throwable t) { System.out.println("Got throwable:"); - t.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", t ); } } @@ -354,7 +311,7 @@ public class CheckAccessibleStatusBar { System.out.println("*** Now testing XAccessibleEventBroadcaster ***"); _XAccessibleEventBroadcaster _xAccEvBcast = - new _XAccessibleEventBroadcaster(testObject, "Pfff", xWindow); + new _XAccessibleEventBroadcaster(testObject, xWindow); assertTrue("failed: XAccessibleEventBroadcaster::addEventListener", _xAccEvBcast._addEventListener()); assertTrue("failed: XAccessibleEventBroadcaster::removeEventListener", _xAccEvBcast._removeEventListener()); } @@ -362,12 +319,14 @@ public class CheckAccessibleStatusBar { - @BeforeClass public static void setUpConnection() throws Exception { + @BeforeClass + public static void setUpConnection() throws Exception { System.out.println("setUpConnection()"); connection.setUp(); } - @AfterClass public static void tearDownConnection() + @AfterClass + public static void tearDownConnection() throws InterruptedException, com.sun.star.uno.Exception { System.out.println("tearDownConnection()"); diff --git a/toolkit/qa/complex/toolkit/CheckAccessibleStatusBarItem.java b/toolkit/qa/complex/toolkit/AccessibleStatusBarItem.java index 537654c6aacc..edd84651d45e 100755 --- a/toolkit/qa/complex/toolkit/CheckAccessibleStatusBarItem.java +++ b/toolkit/qa/complex/toolkit/AccessibleStatusBarItem.java @@ -27,14 +27,16 @@ package complex.toolkit; -// import complexlib.ComplexTestCase; -import lib.TestParameters; -// import util.SOfficeFactory; -// import complexlib.ComplexTestCase; +import java.util.logging.Logger; +import java.util.logging.Level; +import complex.toolkit.accessibility._XAccessibleEventBroadcaster; +import complex.toolkit.accessibility._XAccessibleExtendedComponent; +import complex.toolkit.accessibility._XAccessibleText; +import complex.toolkit.accessibility._XAccessibleComponent; +import complex.toolkit.accessibility._XAccessibleContext; import util.SOfficeFactory; import util.AccessibilityTools; import com.sun.star.awt.XWindow; -// import com.sun.star.chart.XChartDocument; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XComponent; import com.sun.star.lang.XServiceInfo; @@ -47,12 +49,9 @@ import com.sun.star.accessibility.AccessibleRole; import com.sun.star.accessibility.XAccessible; import com.sun.star.accessibility.XAccessibleContext; import com.sun.star.awt.XExtendedToolkit; -// import java.io.PrintWriter; -// import org.junit.After; import org.junit.AfterClass; -// import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.openoffice.test.OfficeConnection; @@ -61,35 +60,17 @@ import static org.junit.Assert.*; /** * */ -public class CheckAccessibleStatusBarItem { +public class AccessibleStatusBarItem { XMultiServiceFactory xMSF = null; XAccessibleContext testObject = null; XWindow xWindow = null; - /** - * The test parameters - */ - private static TestParameters param = null; - -// public String[] getTestMethodNames() { -// return new String[]{"checkDocs"};//{"checkWriterDoc", "checkDrawDoc", -//// "checkMathDoc", "checkImpressDoc", "checkCalcDoc"}; -// } - - /** - * Sleeps for 0.5 sec. to allow StarOffice to react on <code> - * reset</code> call. - */ - private void shortWait() { - shortWait(500) ; - } - /** * Sleeps for a certain time. * @param Thread is sleeping for this time in milliseconds. */ - private void shortWait(int time) { + private void shortWait() { try { Thread.sleep(500); } catch (InterruptedException e) { @@ -100,43 +81,14 @@ public class CheckAccessibleStatusBarItem { /** * Check document types */ - @Test public void checkDocs() + @Test + public void checkDocs() { - param = new TestParameters(); - Object doc = param.get("DocType"); - String testDocType; - if (doc == null) - { - testDocType = "all"; - } - else - { - testDocType = (String)doc; - } - - System.out.println("Param was " + doc); - System.out.println("DocType " + testDocType); - if (testDocType.equalsIgnoreCase("writer") || testDocType.equalsIgnoreCase("all")) - { - checkWriterDoc(); - } - if (testDocType.equalsIgnoreCase("math") || testDocType.equalsIgnoreCase("all")) - { - checkMathDoc(); - } - if (testDocType.equalsIgnoreCase("draw") || testDocType.equalsIgnoreCase("all")) - { - checkDrawDoc(); - } - if (testDocType.equalsIgnoreCase("impress") || testDocType.equalsIgnoreCase("all")) - { - checkImpressDoc(); - } - if (testDocType.equalsIgnoreCase("calc") || testDocType.equalsIgnoreCase("all")) - { - checkCalcDoc(); - } - + checkWriterDoc(); + checkMathDoc(); + checkDrawDoc(); + checkImpressDoc(); + checkCalcDoc(); } private XMultiServiceFactory getMSF() @@ -158,7 +110,7 @@ public class CheckAccessibleStatusBarItem { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -168,7 +120,7 @@ public class CheckAccessibleStatusBarItem { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -186,7 +138,7 @@ public class CheckAccessibleStatusBarItem { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -196,7 +148,7 @@ public class CheckAccessibleStatusBarItem { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -214,7 +166,7 @@ public class CheckAccessibleStatusBarItem { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -224,7 +176,7 @@ public class CheckAccessibleStatusBarItem { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -242,7 +194,7 @@ public class CheckAccessibleStatusBarItem { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -252,7 +204,7 @@ public class CheckAccessibleStatusBarItem { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -270,7 +222,7 @@ public class CheckAccessibleStatusBarItem { getTestObject(); } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } runAllInterfaceTests(); @@ -280,7 +232,7 @@ public class CheckAccessibleStatusBarItem { xClose.close(false); } catch(com.sun.star.util.CloseVetoException e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } } } @@ -297,35 +249,25 @@ public class CheckAccessibleStatusBarItem { XWindow.class,tk.getActiveTopWindow()); shortWait(); - AccessibilityTools at = new AccessibilityTools(); - XAccessible xRoot = at.getAccessibleObject(xWindow); + XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); XAccessibleContext parentContext = null; System.out.println("Get the accessible status bar."); - parentContext = at.getAccessibleObjectForRole( + parentContext = AccessibilityTools.getAccessibleObjectForRole( xRoot, AccessibleRole.STATUS_BAR, ""); shortWait(); if ( parentContext == null ) { - System.out.println("Could not get the test object: set the correct focus in the next 30 seconds."); - shortWait(30000); - parentContext = at.getAccessibleObjectForRole( - xRoot, AccessibleRole.STATUS_BAR, ""); - - if ( parentContext == null ) - { - fail("Could not create a test object."); - } + fail("Could not create a test object."); } System.out.println("...OK."); testObject=parentContext; } catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", e ); } catch(Throwable t) { - System.out.println("Got throwable:"); - t.printStackTrace(); + Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, "caught an exception", t ); } } @@ -391,7 +333,7 @@ public class CheckAccessibleStatusBarItem { System.out.println("*** Now testing XAccessibleEventBroadcaster ***"); _XAccessibleEventBroadcaster _xAccEvBcast = - new _XAccessibleEventBroadcaster(object, "Pfff", xWindow); + new _XAccessibleEventBroadcaster(object, xWindow); assertTrue("failed: "+accName+" - XAccessibleEventBroadcaster::addEventListener", _xAccEvBcast._addEventListener()); assertTrue("failed: "+accName+" - XAccessibleEventBroadcaster::removeEventListener", _xAccEvBcast._removeEventListener()); diff --git a/toolkit/qa/complex/toolkit/Assert.java b/toolkit/qa/complex/toolkit/Assert.java new file mode 100755 index 000000000000..93b1a2c490e1 --- /dev/null +++ b/toolkit/qa/complex/toolkit/Assert.java @@ -0,0 +1,234 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + *************************************************************************/ + +package complex.toolkit; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import com.sun.star.uno.UnoRuntime; +import static org.junit.Assert.*; + +/** + * provides assertion capabilities not found in {@link org.junit.Assert} + * @author frank.schoenheit@oracle.com + */ +public class Assert +{ + // -------------------------------------------------------------------------------------------------------- + /** invokes a given method on a given object, and assures a certain exception is caught + * @param i_message + * is the message to print when the check fails + * @param i_object + * is the object to invoke the method on + * @param i_methodName + * is the name of the method to invoke + * @param i_methodArgs + * are the arguments to pass to the method. + * @param i_argClasses + * are the classes to assume for the arguments of the methods + * @param i_expectedExceptionClass + * is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + public static void assertException( final String i_message, final Object i_object, final String i_methodName, + final Class[] i_argClasses, final Object[] i_methodArgs, final Class i_expectedExceptionClass ) + { + Class objectClass = i_object.getClass(); + + boolean noExceptionAllowed = ( i_expectedExceptionClass == null ); + + boolean caughtExpected = noExceptionAllowed ? true : false; + try + { + Method method = impl_getMethod( objectClass, i_methodName, i_argClasses ); + method.invoke(i_object, i_methodArgs ); + } + catch ( NoSuchMethodException e ) + { + StringBuilder message = new StringBuilder(); + message.append( "no such method: " ).append( objectClass.getName() ).append( "." ).append( i_methodName ).append( "( " ); + for ( int i=0; i<i_argClasses.length; ++i ) + { + message.append( i_argClasses[i].getName() ); + if ( i<i_argClasses.length - 1 ) + message.append( ", " ); + } + message.append( " )" ); + fail( message.toString() ); + } + catch ( InvocationTargetException e ) + { + caughtExpected = noExceptionAllowed + ? false + : ( e.getTargetException().getClass().equals( i_expectedExceptionClass ) ); + } + catch( Exception e ) + { + caughtExpected = false; + } + + assertTrue( i_message, caughtExpected ); + } + + /** + * retrieves a method, given by name and parameter signature, from the given class + * + * The method does somewhat more than simply calling {@link Class.getMethod}. In particular, it recognizes + * primitiive parameter types, and attempts to find a method taking the given primitive type, instead of the + * type represented by the parameter class. + * + * For instance, if you have a method <code>foo( int )</code>, {@link Class.getMethod} would not return this + * method when you pass <code>Integer.class</code>. <code>impl_getMethod</code> will recognize this, and + * properly retrieve the method. + * + * Note: <code>impl_getMethod</code> is limited in that it will not try all possible combinations of primitive + * and non-primitive types. That is, a method like <code>foo( int, Integer, int )</code> is likely to not be + * found. + * + * @param i_obbjectClass + * @param i_methodName + * @param i_argClasses + * @return + */ + private static Method impl_getMethod( final Class i_objectClass, final String i_methodName, final Class[] i_argClasses ) throws NoSuchMethodException + { + try + { + return i_objectClass.getMethod( i_methodName, i_argClasses ); + } + catch ( NoSuchMethodException ex ) + { + } + + int substitutedTypes = 0; + int substitutedTypesLastRound = 0; + final Class[][] substitutionTable = new Class[][] { + new Class[] { Long.class, long.class }, + new Class[] { Integer.class, int.class }, + new Class[] { Short.class, short.class }, + new Class[] { Byte.class, byte.class }, + new Class[] { Double.class, double.class }, + new Class[] { Float.class, float.class }, + new Class[] { Character.class, char.class } + }; + do + { + substitutedTypes = 0; + final Class[] argClasses = new Class[ i_argClasses.length ]; + for ( int i=0; i < argClasses.length; ++i ) + { + argClasses[i] = i_argClasses[i]; + if ( substitutedTypes > substitutedTypesLastRound ) + continue; + + for ( int c=0; c<substitutionTable.length; ++c ) + { + if ( i_argClasses[i].equals( substitutionTable[c][0] ) ) + { + argClasses[i] = substitutionTable[c][1]; + ++substitutedTypes; + break; + } + } + } + if ( substitutedTypes == substitutedTypesLastRound ) + throw new NoSuchMethodException(); + substitutedTypesLastRound = substitutedTypes; + + try + { + return i_objectClass.getMethod( i_methodName, argClasses ); + } + catch ( NoSuchMethodException e ) + { + } + } + while ( substitutedTypes > 0 ); + throw new NoSuchMethodException(); + } + + /** invokes a given method on a given object, and assures a certain exception is caught + * @param i_message is the message to print when the check fails + * @param i_object is the object to invoke the method on + * @param i_methodName is the name of the method to invoke + * @param i_methodArgs are the arguments to pass to the method. Those implicitly define + * the classes of the arguments of the method which is called. + * @param i_expectedExceptionClass is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + public static void assertException( final String i_message, final Object i_object, final String i_methodName, + final Object[] i_methodArgs, final Class i_expectedExceptionClass ) + { + Class[] argClasses = new Class[ i_methodArgs.length ]; + for ( int i=0; i<i_methodArgs.length; ++i ) + argClasses[i] = i_methodArgs[i].getClass(); + assertException( i_message, i_object, i_methodName, argClasses, i_methodArgs, i_expectedExceptionClass ); + } + + /** invokes a given method on a given object, and assures a certain exception is caught + * @param i_object is the object to invoke the method on + * @param i_methodName is the name of the method to invoke + * @param i_methodArgs are the arguments to pass to the method. Those implicitly define + * the classes of the arguments of the method which is called. + * @param i_expectedExceptionClass is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + public static void assertException( final Object i_object, final String i_methodName, final Object[] i_methodArgs, + final Class i_expectedExceptionClass ) + { + assertException( + "did not catch the expected exception (" + + ( ( i_expectedExceptionClass == null ) ? "none" : i_expectedExceptionClass.getName() ) + + ") while calling " + i_object.getClass().getName() + "." + i_methodName, + i_object, i_methodName, i_methodArgs, i_expectedExceptionClass ); + } + + /** invokes a given method on a given object, and assures a certain exception is caught + * @param i_object is the object to invoke the method on + * @param i_methodName is the name of the method to invoke + * @param i_methodArgs are the arguments to pass to the method + * @param i_argClasses are the classes to assume for the arguments of the methods + * @param i_expectedExceptionClass is the class of the exception to be caught. If this is null, + * it means that <em>no</em> exception must be throw by invoking the method. + */ + public static void assertException( final Object i_object, final String i_methodName, final Class[] i_argClasses, + final Object[] i_methodArgs, final Class i_expectedExceptionClass ) + { + assertException( + "did not catch the expected exception (" + + ( ( i_expectedExceptionClass == null ) ? "none" : i_expectedExceptionClass.getName() ) + + ") while calling " + i_object.getClass().getName() + "." + i_methodName, + i_object, i_methodName, i_argClasses, i_methodArgs, i_expectedExceptionClass ); + } + + // -------------------------------------------------------------------------------------------------------- + public static void assertException( Object i_object, Class _unoInterfaceClass, String i_methodName, Object[] i_methodArgs, + Class i_expectedExceptionClass ) + { + assertException( UnoRuntime.queryInterface( _unoInterfaceClass, i_object ), i_methodName, + i_methodArgs, i_expectedExceptionClass ); + } +} diff --git a/toolkit/qa/complex/toolkit/CallbackClass.java b/toolkit/qa/complex/toolkit/CallbackClass.java deleted file mode 100644 index 1c9eb68a6d34..000000000000 --- a/toolkit/qa/complex/toolkit/CallbackClass.java +++ /dev/null @@ -1,67 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -package complex.toolkit; - -import com.sun.star.awt.XCallback; -// import lib.MultiMethodTest; -import com.sun.star.lang.XMultiServiceFactory; -// import com.sun.star.uno.XInterface; -// import com.sun.star.uno.UnoRuntime; -// import share.LogWriter; - -/** - * Testing <code>com.sun.star.awt.XRequestCallback</code> - * interface methods : - * <ul> - * <li><code> addCallback()</code></li> - * </ul> <p> - * @see com.sun.star.awt.XRequestCallback - */ -public class CallbackClass implements XCallback{ - - // private LogWriter log; - - private XMultiServiceFactory xMSF; - - - public CallbackClass(XMultiServiceFactory xMSF ) { - - this.xMSF = xMSF; - // this.log = log; - } - - - /** - * Callback method which will be called by the asynchronous - * service where we have added our request before. - */ - public void notify( Object aData ) { - - System.out.println("callback called successfully" ); - } -} diff --git a/toolkit/qa/complex/toolkit/CheckAsyncCallback.java b/toolkit/qa/complex/toolkit/CheckAsyncCallback.java deleted file mode 100644 index 3a1e51729f11..000000000000 --- a/toolkit/qa/complex/toolkit/CheckAsyncCallback.java +++ /dev/null @@ -1,156 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -package complex.toolkit; - -// import complexlib.ComplexTestCase; -import util.SOfficeFactory; -// import complex.toolkit.CallbackClass; -import com.sun.star.awt.XRequestCallback; -import com.sun.star.lang.XMultiServiceFactory; -// import com.sun.star.lang.XComponent; -// import com.sun.star.lang.XServiceInfo; -import com.sun.star.uno.XInterface; -import com.sun.star.uno.UnoRuntime; -// import com.sun.star.awt.XExtendedToolkit; -// import java.io.PrintWriter; - -// import org.junit.After; -import org.junit.AfterClass; -// import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openoffice.test.OfficeConnection; -import static org.junit.Assert.*; - -/** - * - */ -public class CheckAsyncCallback /* extends ComplexTestCase*/ { - - - XInterface testObject = null; - XMultiServiceFactory xMSF = null; - -// public String[] getTestMethodNames() { -// return new String[]{"checkService"}; -// } - -/* public String getTestObjectName() { - return "com.sun.star.awt.AccessibleStatusBar"; - } -*/ - private XMultiServiceFactory getMSF() - { - final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); - return xMSF1; - } - - /** - * Sleeps for 0.5 sec. to allow StarOffice to react on <code> - * reset</code> call. - */ - private void shortWait() { - try { - Thread.sleep(500) ; - } catch (InterruptedException e) { - System.out.println("While waiting :" + e) ; - } - } - - /** - * Check services - */ - @Test public void checkService() { - checkAsyncCallbackService(); - - } - - /** - * Test the interfaces - */ - public void checkAsyncCallbackService() { - runAllInterfaceTests(); - } - - public void getTestObject() { - try { - xMSF = getMSF(); - SOfficeFactory xSOF = SOfficeFactory.getFactory(xMSF); - - XRequestCallback xAsyncCallback = null; - - XInterface xIfc = (XInterface)xMSF.createInstance( - "com.sun.star.awt.AsyncCallback" ); - xAsyncCallback = UnoRuntime.queryInterface(XRequestCallback.class, xIfc); - - testObject=xAsyncCallback; - } - catch(com.sun.star.uno.Exception e) { - e.printStackTrace(); - } - catch(Throwable t) { - System.out.println("Got throwable:"); - t.printStackTrace(); - } - } - - public void runAllInterfaceTests() { - getTestObject(); - System.out.println("*** Now testing XRequestCallback ***"); - _XRequestCallback _xRequestCallback = - new _XRequestCallback(testObject, xMSF ); - assertTrue("failed: XRequestCallback::addCallback", _xRequestCallback._addCallback()); - } - - public void checkCallback() { - getTestObject(); - System.out.println("*** Now testing asynchronous callback service ***"); - XRequestCallback xAsyncCallback = null; - xAsyncCallback = UnoRuntime.queryInterface(XRequestCallback.class, testObject); - CallbackClass aCallbackClass = new CallbackClass( xMSF ); - xAsyncCallback.addCallback( aCallbackClass, null ); - } - - - - @BeforeClass public static void setUpConnection() throws Exception { - System.out.println("setUpConnection()"); - connection.setUp(); - } - - @AfterClass public static void tearDownConnection() - throws InterruptedException, com.sun.star.uno.Exception - { - System.out.println("tearDownConnection()"); - connection.tearDown(); - } - - private static final OfficeConnection connection = new OfficeConnection(); - - -} diff --git a/toolkit/qa/complex/toolkit/GridControl.java b/toolkit/qa/complex/toolkit/GridControl.java new file mode 100755 index 000000000000..a06a52342417 --- /dev/null +++ b/toolkit/qa/complex/toolkit/GridControl.java @@ -0,0 +1,687 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + *************************************************************************/ + +package complex.toolkit; + +import com.sun.star.awt.XControl; +import com.sun.star.awt.XControlContainer; +import com.sun.star.awt.XControlModel; +import com.sun.star.awt.XToolkit; +import com.sun.star.awt.grid.DefaultGridDataModel; +import com.sun.star.awt.grid.XGridColumn; +import com.sun.star.awt.grid.XGridColumnModel; +import com.sun.star.awt.grid.XGridDataModel; +import com.sun.star.awt.grid.XMutableGridDataModel; +import com.sun.star.awt.grid.XSortableMutableGridDataModel; +import com.sun.star.beans.Pair; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.ContainerEvent; +import com.sun.star.container.XContainerListener; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XEventListener; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.XInterface; +import com.sun.star.util.XCloneable; +import complex.toolkit.awtgrid.DummyColumn; +import complex.toolkit.awtgrid.TMutableGridDataModel; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.openoffice.test.OfficeConnection; + +/** is a unit test for the grid control related implementations + * @author frank.schoenheit@sun.com + */ +public class GridControl +{ + // ----------------------------------------------------------------------------------------------------------------- + public GridControl() + { + m_context = m_connection.getComponentContext(); + } + + // ----------------------------------------------------------------------------------------------------------------- + private static void impl_dispose( final Object... i_components ) + { + for ( int i=0; i<i_components.length; ++i ) + { + if ( i_components[i] != null ) + { + final XComponent component = UnoRuntime.queryInterface( XComponent.class, i_components[i] ); + component.dispose(); + } + } + } + + // ----------------------------------------------------------------------------------------------------------------- + private void impl_recreateGridModel() throws Exception + { + impl_dispose( m_gridControlModel, m_columnModel, m_dataModel ); + + // create a grid control model, and ensure it has a proper data and column model already + m_gridControlModel = UnoRuntime.queryInterface( XPropertySet.class, + createInstance( "com.sun.star.awt.grid.UnoControlGridModel" ) ); + assertNotNull( "grid control model does not provide XPropertySet interface", m_gridControlModel ); + + // ensure that the model has default column/data models + m_columnModel = UnoRuntime.queryInterface( XGridColumnModel.class, m_gridControlModel.getPropertyValue( "ColumnModel" ) ); + assertNotNull( "the control model is expected to have an initial column model", m_columnModel ); + final XGridDataModel dataModel = UnoRuntime.queryInterface( XGridDataModel.class, m_gridControlModel.getPropertyValue( "GridDataModel" ) ); + assertNotNull( "the control model is expected to have an initial data model", dataModel ); + m_dataModel = UnoRuntime.queryInterface( XSortableMutableGridDataModel.class, + dataModel ); + assertNotNull( "the out-of-the-box data model should be mutable and sortable", m_dataModel ); + } + + // ----------------------------------------------------------------------------------------------------------------- + @Test + public void testGridControlCloning() throws Exception + { + impl_recreateGridModel(); + + // give the test something to compare, actually + XGridColumnModel columnModel = UnoRuntime.queryInterface( XGridColumnModel.class, + m_gridControlModel.getPropertyValue( "ColumnModel" ) ); + columnModel.setDefaultColumns( 10 ); + + // clone the grid model + final XCloneable cloneable = UnoRuntime.queryInterface( XCloneable.class, m_gridControlModel ); + assertNotNull( "all UnoControlModel's are expected to be cloneable", cloneable ); + + final XInterface clone = cloneable.createClone(); + final XPropertySet clonedProps = UnoRuntime.queryInterface( XPropertySet.class, clone ); + + // TODO: check all those generic properties for equality + + // the data model and the column model should have been cloned, too + // in particular, the clone should not share the sub models with the orignal + final XMutableGridDataModel originalDataModel = UnoRuntime.queryInterface( XMutableGridDataModel.class, + m_gridControlModel.getPropertyValue( "GridDataModel" ) ); + final XMutableGridDataModel clonedDataModel = UnoRuntime.queryInterface( XMutableGridDataModel.class, + clonedProps.getPropertyValue( "GridDataModel" ) ); + assertFalse( "data model should not be shared after cloning", UnoRuntime.areSame( originalDataModel, clonedDataModel ) ); + impl_assertEquality( originalDataModel, clonedDataModel ); + + final XGridColumnModel originalColumnModel = columnModel; + final XGridColumnModel clonedColumnModel = UnoRuntime.queryInterface( XGridColumnModel.class, + clonedProps.getPropertyValue( "ColumnModel" ) ); + assertFalse( "column model should not be shared after cloning", UnoRuntime.areSame( originalColumnModel, clonedColumnModel ) ); + impl_assertEquality( originalColumnModel, clonedColumnModel ); + } + + // ----------------------------------------------------------------------------------------------------------------- + @Test + public void testDisposal() throws Exception + { + impl_recreateGridModel(); + + final int columnCount = 3; + m_columnModel.setDefaultColumns( columnCount ); + + // add disposal listeners to all columns so far + final XGridColumn[] columns = m_columnModel.getColumns(); + assertEquals( "creating default columns resulted in unexpected column count", columnCount, columns.length ); + final DisposeListener[] columnListeners = new DisposeListener[columnCount]; + for ( int i=0; i<columnCount; ++i ) + columnListeners[i] = new DisposeListener( columns[i] ); + + // add another column, and check that upon removal, it is disposed + final int newColumnIndex = m_columnModel.addColumn( m_columnModel.createColumn() ); + final DisposeListener columnListener = new DisposeListener( m_columnModel.getColumn( newColumnIndex ) ); + m_columnModel.removeColumn( newColumnIndex ); + assertTrue( "explicit column removal is expected to dispose the column", columnListener.isDisposed() ); + + // by definition, the grid control model is the owner of both the column and the data model. So, setting + // a new column/data model should implicitly dispose the old models + final DisposeListener oldDataModelListener = new DisposeListener( m_dataModel ); + final DisposeListener oldColumnModelListener = new DisposeListener( m_columnModel ); + + final Object newDataModel = createInstance( "com.sun.star.awt.grid.DefaultGridDataModel" ); + final Object newColumnModel = createInstance( "com.sun.star.awt.grid.DefaultGridColumnModel" ); + final DisposeListener newDataModelListener = new DisposeListener( newDataModel ); + final DisposeListener newColumnModelListener = new DisposeListener( newColumnModel ); + + m_gridControlModel.setPropertyValue( "GridDataModel", newDataModel ); + assertTrue( "setting a new data model failed", impl_areSameInterface( newDataModel, m_gridControlModel.getPropertyValue( "GridDataModel" ) ) ); + m_gridControlModel.setPropertyValue( "ColumnModel", newColumnModel ); + assertTrue( "setting a new column model failed", impl_areSameInterface( newColumnModel, m_gridControlModel.getPropertyValue( "ColumnModel" ) ) ); + + assertTrue( "old data model has not been disposed", oldDataModelListener.isDisposed() ); + assertTrue( "old column model has not been disposed", oldColumnModelListener.isDisposed() ); + for ( int i=0; i<columnCount; ++i ) + assertTrue( "column no. " + i + " has not been disposed", columnListeners[i].isDisposed() ); + + // the same holds if the grid control model itself is disposed - it should dispose the depending models, too + assertFalse( "new data model is already disposed - this is unexpected", newDataModelListener.isDisposed() ); + assertFalse( "new column model is already disposed - this is unexpected", newColumnModelListener.isDisposed() ); + impl_dispose( m_gridControlModel ); + assertTrue( "new data model is not disposed after disposing the grid column model", newDataModelListener.isDisposed() ); + assertTrue( "new column model is not disposed after disposing the grid column model", newColumnModelListener.isDisposed() ); + } + + // ----------------------------------------------------------------------------------------------------------------- + /** + * tests various aspects of the <code>XMutableGridDataModel</code> interface + */ + @Test + public void testMutableGridDataModel() throws Exception + { + impl_recreateGridModel(); + + TMutableGridDataModel test = new TMutableGridDataModel( m_dataModel ); + test.testAddRow(); + test.testAddRows(); + test.testRemoveRow(); + test.testRemoveAllRows(); + test.testUpdateCellData(); + test.testUpdateRowData(); + test.testUpdateRowHeading(); + test.cleanup(); + + // a somehwat less straight-forward test: the data model is expected to implicitly increase its column count + // when you add a row which has more columns than currently known + final XMutableGridDataModel dataModel = DefaultGridDataModel.create( m_context ); + dataModel.addRow( 0, new Object[] { 1 } ); + assertEquals( "unexpected column count after adding the most simple row", 1, dataModel.getColumnCount() ); + dataModel.addRow( 1, new Object[] { 1, 2 } ); + assertEquals( "implicit extension of the column count doesn't work", 2, dataModel.getColumnCount() ); + } + + // ----------------------------------------------------------------------------------------------------------------- + @Test + public void testGridColumnModel() throws Exception + { + impl_recreateGridModel(); + + ColumnModelListener listener = new ColumnModelListener(); + m_columnModel.addContainerListener( listener ); + + // insert default columns into the previously empty model, ensure we get the right notifications + final int defaultColumnsCount = 3; + m_columnModel.setDefaultColumns( defaultColumnsCount ); + impl_assertColumnModelConsistency(); + List< ContainerEvent > events = listener.assertExclusiveInsertionEvents(); + listener.reset(); + assertEquals( "wrong number of events fired by setDefaulColumns", defaultColumnsCount, events.size() ); + for ( int i=0; i<defaultColumnsCount; ++i ) + { + final ContainerEvent event = events.get(i); + final int index = impl_assertInteger( event.Accessor ); + assertEquals( "unexpected Accessor value in insert notification", i, index ); + assertTrue( "wrong column object notified in insert notification", + impl_areSameInterface( event.Element, m_columnModel.getColumn(i) ) ); + } + + // insert some more default columns, ensure that all previously existing columns are removed + final int moreDefaultColumnsCount = 5; + m_columnModel.setDefaultColumns( moreDefaultColumnsCount ); + impl_assertColumnModelConsistency(); + assertEquals( "setting default columns is expected to remove all previously existing columns", + moreDefaultColumnsCount, m_columnModel.getColumnCount() ); + + // in this situation, both removal and insertion events have been notified + final List< ContainerEvent > removalEvents = listener.getRemovalEvents(); + final List< ContainerEvent > insertionEvents = listener.getInsertionEvents(); + listener.reset(); + + // for the removal events, check the indexes + assertEquals( "wrong number of columns removed (or notified) upon setting default columns", + defaultColumnsCount, removalEvents.size() ); + for ( int i=0; i<removalEvents.size(); ++i ) + { + final ContainerEvent event = removalEvents.get(i); + final int removedIndex = impl_assertInteger( event.Accessor ); + + // The implementation is allowed to remove the columns from the beginning, in which case the + // index of the removed column must always be 0, since e.g. the second column has index 0 + // after the first column (which previously had index 0) had been removed. + // Alternatively, the implementation is allowed to remove columns from the end, which means + // that the column index given in the event is steadily increasing. + assertTrue( "unexpected column removal event column index", + ( removedIndex == 0 ) || ( removedIndex == removalEvents.size() - 1 - i ) ); + } + + // for the insertion events, check the indexes as well + assertEquals( "wrong number of insertion events when setting default columns over existing columns", + moreDefaultColumnsCount, insertionEvents.size() ); + for ( int i=0; i<insertionEvents.size(); ++i ) + { + final ContainerEvent event = insertionEvents.get(i); + final int index = impl_assertInteger( event.Accessor ); + assertEquals( i, index ); + } + + // okay, remove all those columns + while ( m_columnModel.getColumnCount() != 0 ) + { + final int columnCount = m_columnModel.getColumnCount(); + final int removeColumnIndex = m_randomGenerator.nextInt( columnCount ); + m_columnModel.removeColumn( removeColumnIndex ); + events = listener.assertExclusiveRemovalEvents(); + listener.reset(); + assertEquals( "removing a single column should notify a single event", 1, events.size() ); + final ContainerEvent event = events.get(0); + final int removalIndex = impl_assertInteger( event.Accessor ); + assertEquals( "removing an arbitrary column does not notify the proper accessor", + removeColumnIndex, removalIndex ); + } + + // calling addColumn with a column not created by the given model/implementatoion should not succeed + boolean caughtExpected = false; + try + { + m_columnModel.addColumn( new DummyColumn() ); + } + catch( final com.sun.star.lang.IllegalArgumentException e ) + { + assertTrue( impl_areSameInterface( e.Context, m_columnModel ) ); + caughtExpected = true; + } + assertTrue( "adding a dummy (self-implemented) grid column to the model should not succeed", caughtExpected ); + + // adding a single column to the end should succeed, properly notify, and still be consistent + final XGridColumn newColumn = m_columnModel.createColumn(); + m_columnModel.addColumn( newColumn ); + impl_assertColumnModelConsistency(); + events = listener.assertExclusiveInsertionEvents(); + listener.reset(); + assertEquals( "addColumn notifies the wrong number of insertion events", 1, events.size() ); + final int insertionIndex = impl_assertInteger( events.get(0).Accessor ); + assertEquals( insertionIndex, newColumn.getIndex() ); + } + + // ----------------------------------------------------------------------------------------------------------------- + @Test + public void testSortableDataModel() throws Exception + { + impl_recreateGridModel(); + + final int colCount = 3; + final int rowCount = 10; + // initialize with some data + final Object[][] data = new Object[][] { + new Object[] { 15, 17, 0 }, + new Object[] { 9, 8, 14 }, + new Object[] { 17, 2, 16 }, + new Object[] { 0, 7, 14 }, + new Object[] { 10, 16, 16 }, + new Object[] { 2, 8, 10 }, + new Object[] { 4, 8, 3 }, + new Object[] { 7, 9, 0 }, + new Object[] { 15, 6, 19 }, + new Object[] { 2, 14, 19 } + }; + final Object[] rowHeadings = new Object[] { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + }; + // ensure consistency of the test data + assertEquals( rowHeadings.length, rowCount ); + assertEquals( data.length, rowCount ); + for ( Object[] rowData : data ) + assertEquals( rowData.length, colCount ); + + // add the test data + m_dataModel.addRows( rowHeadings, data ); + assertEquals( rowCount, m_dataModel.getRowCount() ); + assertEquals( colCount, m_dataModel.getColumnCount() ); + + // sort by each column + for ( int colIndex = 0; colIndex < colCount; ++colIndex ) + { + for ( boolean ascending : new boolean[] { true, false } ) + { + m_dataModel.sortByColumn( colIndex, ascending ); + Pair currentSortOrder = m_dataModel.getCurrentSortOrder(); + assertEquals( "invalid current sort column (column " + colIndex + ")", ((Integer)currentSortOrder.First).intValue(), colIndex ); + assertEquals( "invalid current sort direction", ((Boolean)currentSortOrder.Second).booleanValue(), ascending ); + + /*for ( int i=0; i<rowCount; ++i ) + { + for ( int j=0; j<colCount; ++j ) + System.out.print( m_dataModel.getCellData( j, i ).toString() + ", " ); + System.out.println(); + }*/ + + // verify the data is actually sorted by this column + for ( int rowIndex = 0; rowIndex < rowCount - 1; ++rowIndex ) + { + final Object currentValue = m_dataModel.getCellData( colIndex, rowIndex ); + final int currentIntValue = impl_assertInteger( currentValue ); + final Object nextValue = m_dataModel.getCellData( colIndex, rowIndex + 1 ); + final int nextIntValue = impl_assertInteger( nextValue ); + assertTrue( "data in row " + rowIndex + " is actually not sorted " + ( ascending ? "ascending" : "descending" ), + ascending ? currentIntValue <= nextIntValue + : currentIntValue >= nextIntValue ); + + // ensure the data in the other columns, and the row headings, are sorted as well + final Object rowHeading = m_dataModel.getRowHeading( rowIndex ); + final int unsortedRowIndex = impl_assertInteger( rowHeading ); + for ( int innerColIndex = 0; innerColIndex < colCount; ++innerColIndex ) + { + assertEquals( "sorted row " + rowIndex + ", unsorted row " + unsortedRowIndex + ", col " + innerColIndex + + ": wrong data", + data[unsortedRowIndex][innerColIndex], m_dataModel.getCellData( innerColIndex, rowIndex ) ); + } + } + } + } + } + + // ----------------------------------------------------------------------------------------------------------------- + @Test + public void testModelViewInteraction() throws Exception + { + final List< Object > disposables = new ArrayList< Object >(); + try + { + // create a siple dialog model/control/peer trinity + final XControlModel dialogModel = createInstance( XControlModel.class, "com.sun.star.awt.UnoControlDialogModel" ); + disposables.add( dialogModel ); + final XPropertySet dialogProps = UnoRuntime.queryInterface( XPropertySet.class, dialogModel ); + dialogProps.setPropertyValue( "Width", 200 ); + dialogProps.setPropertyValue( "Height", 100 ); + dialogProps.setPropertyValue( "Title", "Grid Control Unit Test" ); + final XControl dialogControl = createInstance( XControl.class, "com.sun.star.awt.UnoControlDialog" ); + disposables.add( dialogControl ); + dialogControl.setModel( dialogModel ); + dialogControl.createPeer( createInstance( XToolkit.class, "com.sun.star.awt.Toolkit" ), null ); + + // insert a grid control model + final XMultiServiceFactory controlModelFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, + dialogModel ); + XPropertySet gridModelProps = UnoRuntime.queryInterface( XPropertySet.class, + controlModelFactory.createInstance( "com.sun.star.awt.grid.UnoControlGridModel" ) ); + disposables.add( gridModelProps ); + gridModelProps.setPropertyValue( "PositionX", 6 ); + gridModelProps.setPropertyValue( "PositionY", 6 ); + gridModelProps.setPropertyValue( "Width", 188 ); + gridModelProps.setPropertyValue( "Height", 88 ); + final XNameContainer modelContainer = UnoRuntime.queryInterface( XNameContainer.class, dialogModel ); + modelContainer.insertByName( "grid", gridModelProps ); + + // check the respective control has been created + final XControlContainer controlContainer = UnoRuntime.queryInterface( XControlContainer.class, dialogControl ); + final XControl gridControl = controlContainer.getControl( "grid" ); + assertNotNull( "no grid control created in the dialog", gridControl ); + + // in the current implementation (not sure this is a good idea at all), the control (more precise: the peer) + // ensures that if there are no columns in the column model, but in the data model, then the column model + // will implicitly have the needed columns added. + // To ensure that clients which rely on this do not break in the future, check this here. + final XMutableGridDataModel dataModel = UnoRuntime.queryInterface( XMutableGridDataModel.class, + gridModelProps.getPropertyValue( "GridDataModel" ) ); + assertNotNull( dataModel ); + assertEquals( 0, dataModel.getColumnCount() ); + + final XGridColumnModel columnModel = UnoRuntime.queryInterface( XGridColumnModel.class, + gridModelProps.getPropertyValue( "ColumnModel" ) ); + assertNotNull( columnModel ); + assertEquals( 0, columnModel.getColumnCount() ); + + dataModel.addRow( null, new Object[] { 1, 2, 3 } ); + assertEquals( 3, dataModel.getColumnCount() ); + assertEquals( 3, columnModel.getColumnCount() ); + } + finally + { + impl_dispose( disposables.toArray()); + } + } + + // ----------------------------------------------------------------------------------------------------------------- + private int impl_assertInteger( final Object i_object ) + { + assertTrue( i_object instanceof Integer ); + return ((Integer)i_object).intValue(); + } + + // ----------------------------------------------------------------------------------------------------------------- + private void impl_assertColumnModelConsistency() throws IndexOutOfBoundsException + { + for ( int col = 0; col < m_columnModel.getColumnCount(); ++col ) + { + final XGridColumn column = m_columnModel.getColumn( col ); + assertNotNull( column ); + assertEquals( "column/model inconsistency: column " + col + " has a wrong index!", col, column.getIndex() ); + } + + final XGridColumn[] allColumns = m_columnModel.getColumns(); + assertEquals( "getColumns returns the wrong number of column objects", + m_columnModel.getColumnCount(), allColumns.length ); + for ( int col = 0; col < m_columnModel.getColumnCount(); ++col ) + { + assertTrue( "getColumns inconsistency", impl_areSameInterface( allColumns[col], m_columnModel.getColumn(col) ) ); + } + } + + // ----------------------------------------------------------------------------------------------------------------- + private void impl_assertEquality( final XGridDataModel i_reference, final XGridDataModel i_compare ) throws IndexOutOfBoundsException + { + assertNotNull( i_reference ); + assertNotNull( i_compare ); + + assertEquals( "data model comparison: wrong column counts", i_reference.getColumnCount(), i_compare.getColumnCount() ); + assertEquals( "data model comparison: wrong row counts", i_reference.getRowCount(), i_compare.getRowCount() ); + + for ( int row = 0; row < i_reference.getRowCount(); ++row ) + { + assertEquals( "data model comparison: wrong row heading content in row " + row, + i_reference.getRowHeading( row ) ); + for ( int col = 0; col < i_reference.getRowCount(); ++col ) + { + assertEquals( "data model comparison: wrong cell content in cell (" + col + ", " + row + ")", + i_reference.getCellData( col, row ) ); + assertEquals( "data model comparison: wrong tooltip content in cell (" + col + ", " + row + ")", + i_reference.getCellToolTip( col, row ) ); + } + } + } + + // ----------------------------------------------------------------------------------------------------------------- + private void impl_assertEquality( final XGridColumnModel i_reference, final XGridColumnModel i_compare ) throws IndexOutOfBoundsException + { + assertEquals( "column model comparison: wrong column counts", i_reference.getColumnCount(), i_compare.getColumnCount() ); + for ( int col = 0; col < i_reference.getColumnCount(); ++col ) + { + final XGridColumn referenceColumn = i_reference.getColumn( col ); + final XGridColumn compareColumn = i_compare.getColumn( col ); + impl_assertEquality( referenceColumn, compareColumn ); + } + } + + // ----------------------------------------------------------------------------------------------------------------- + private void impl_assertEquality( final XGridColumn i_reference, final XGridColumn i_compare ) + { + final Method[] methods = XGridColumn.class.getMethods(); + for ( int m=0; m<methods.length; ++m ) + { + if ( !methods[m].getName().startsWith( "get" ) ) + continue; + try + { + final Object referenceValue = methods[m].invoke( i_reference ); + final Object compareValue = methods[m].invoke( i_compare ); + assertEquals( "grid column comparison: column attribute '" + methods[m].getName().substring(3) + "' does not match", + referenceValue, compareValue ); + } + catch ( java.lang.Exception ex ) + { + fail( " could not retrieve object attributes: " + ex.toString() ); + } + } + } + + // ----------------------------------------------------------------------------------------------------------------- + private boolean impl_areSameInterface( final Object i_lhs, final Object i_rhs ) + { + final XInterface lhs = UnoRuntime.queryInterface( XInterface.class, i_lhs ); + final XInterface rhs = UnoRuntime.queryInterface( XInterface.class, i_rhs ); + return UnoRuntime.areSame( lhs, rhs ); + } + + // ----------------------------------------------------------------------------------------------------------------- + @BeforeClass + public static void setUpConnection() throws java.lang.Exception + { + System.out.println( "--------------------------------------------------------------------------------" ); + System.out.println( "starting class: " + GridControl.class.getName() ); + System.out.print( "connecting ... " ); + m_connection.setUp(); + System.out.println( "done."); + + final long seed = m_randomGenerator.nextLong(); + m_randomGenerator.setSeed( seed ); + System.out.println( "seeding random number generator with " + seed ); + } + + // ----------------------------------------------------------------------------------------------------------------- + @AfterClass + public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println(); + System.out.println( "tearing down connection" ); + m_connection.tearDown(); + System.out.println( "finished class: " + GridControl.class.getName() ); + System.out.println( "--------------------------------------------------------------------------------" ); + } + + // ----------------------------------------------------------------------------------------------------------------- + public <T> T createInstance( Class<T> i_interfaceClass, final String i_serviceIndentifer ) throws Exception + { + return UnoRuntime.queryInterface( i_interfaceClass, createInstance( i_serviceIndentifer ) ); + } + + // ----------------------------------------------------------------------------------------------------------------- + private Object createInstance( final String i_serviceName ) throws Exception + { + Object instance = m_context.getServiceManager().createInstanceWithContext( i_serviceName, m_context ); + assertNotNull( "could not create an instance of '" + i_serviceName + "'", instance ); + return instance; + } + // ----------------------------------------------------------------------------------------------------------------- + private static final class DisposeListener implements XEventListener + { + DisposeListener( final Object i_component ) + { + m_component = UnoRuntime.queryInterface( XComponent.class, i_component ); + assertNotNull( m_component ); + m_component.addEventListener( this ); + } + + public void disposing( EventObject i_event ) + { + assertTrue( UnoRuntime.areSame( i_event.Source, m_component ) ); + m_isDisposed = true; + } + + final boolean isDisposed() { return m_isDisposed; } + + private final XComponent m_component; + private boolean m_isDisposed; + }; + + // ----------------------------------------------------------------------------------------------------------------- + private static final class ColumnModelListener implements XContainerListener + { + ColumnModelListener() + { + } + + public void elementInserted( ContainerEvent i_event ) + { + m_insertionEvents.add( i_event ); + } + + public void elementRemoved( ContainerEvent i_event ) + { + m_removalEvents.add( i_event ); + } + + public void elementReplaced( ContainerEvent i_event ) + { + m_replacementEvents.add( i_event ); + } + + public void disposing( EventObject eo ) + { + m_isDisposed = true; + } + + private List< ContainerEvent > assertExclusiveInsertionEvents() + { + assertFalse( m_insertionEvents.isEmpty() ); + assertTrue( m_removalEvents.isEmpty() ); + assertTrue( m_replacementEvents.isEmpty() ); + return m_insertionEvents; + } + + private List< ContainerEvent > assertExclusiveRemovalEvents() + { + assertTrue( m_insertionEvents.isEmpty() ); + assertFalse( m_removalEvents.isEmpty() ); + assertTrue( m_replacementEvents.isEmpty() ); + return m_removalEvents; + } + + private void reset() + { + m_insertionEvents = new ArrayList< ContainerEvent >(); + m_removalEvents = new ArrayList< ContainerEvent >(); + m_replacementEvents = new ArrayList< ContainerEvent >(); + } + + private List< ContainerEvent > getInsertionEvents() { return m_insertionEvents; } + private List< ContainerEvent > getRemovalEvents() { return m_removalEvents; } + + final boolean isDisposed() { return m_isDisposed; } + + private List< ContainerEvent > m_insertionEvents = new ArrayList< ContainerEvent >(); + private List< ContainerEvent > m_removalEvents = new ArrayList< ContainerEvent >(); + private List< ContainerEvent > m_replacementEvents = new ArrayList< ContainerEvent >(); + private boolean m_isDisposed = false; + }; + + // ----------------------------------------------------------------------------------------------------------------- + private static final OfficeConnection m_connection = new OfficeConnection(); + private static Random m_randomGenerator = new Random(); + private final XComponentContext m_context; + + private XPropertySet m_gridControlModel; + private XGridColumnModel m_columnModel; + private XSortableMutableGridDataModel m_dataModel; +} diff --git a/toolkit/qa/complex/toolkit/UnitConversion.java b/toolkit/qa/complex/toolkit/UnitConversion.java new file mode 100644 index 000000000000..b4cf8a8e1490 --- /dev/null +++ b/toolkit/qa/complex/toolkit/UnitConversion.java @@ -0,0 +1,247 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.toolkit; + +import com.sun.star.awt.XUnitConversion; +import com.sun.star.uno.UnoRuntime; + +import com.sun.star.awt.XWindow; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.awt.XWindowPeer; + +import util.DesktopTools; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; + +/** + * This complex test is only for testing the com.sun.star.awt.XUnitConversion methods + * These are converter methods to get the size of a well known awt component + * in a com.sun.star.util.MeasureUnit you want. + * You don't need to know the factors to calculate by hand. + * + * @author ll93751 + */ +public class UnitConversion +{ + /** + * returns the delta value between a and b + * @param a + * @param b + * @return + */ + private int delta(int a, int b) + { + final int n = Math.abs(a - b); + return n; + } + + private XUnitConversion m_xConversion = null; + + /** + * Not really a check, + * only a simple test call to convertSizeToLogic(...) with different parameters + * @param _aSize + * @param _aMeasureUnit + * @param _sEinheit + */ + private void checkSize(com.sun.star.awt.Size _aSize, short _aMeasureUnit, String _sEinheit) + { + try + { + com.sun.star.awt.Size aSizeIn = m_xConversion.convertSizeToLogic(_aSize, _aMeasureUnit); + System.out.println("Window size:"); + System.out.println("Width:" + aSizeIn.Width + " " + _sEinheit); + System.out.println("Height:" + aSizeIn.Height + " " + _sEinheit); + System.out.println(""); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + System.out.println("Caught IllegalArgumentException in convertSizeToLogic with '" + _sEinheit + "' " + e.getMessage()); + } + } + + /** + * The real test function + * 1. try to get the XMultiServiceFactory of an already running office. Therefore make sure an (open|star)office is running with + * parameters like -accept="socket,host=localhost,port=8100;urp;" + * 2. try to create an empty window + * 3. try to convert the WindowPeer to an XWindow + * 4. try to resize and move the window to an other position, so we get a well knowing position and size. + * 5. run some more tests + * + * If no test fails, the test is well done and returns with 'PASSED, OK' + * + */ + @Test + public void testXUnitConversion() + { + final XMultiServiceFactory xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + + assertNotNull("failed: There is no office.", xMSF); + + // create a window + XWindowPeer xWindowPeer = DesktopTools.createFloatingWindow(xMSF); + assertNotNull("failed: there is no window peer", xWindowPeer); + + + // resize and move the window to a well known position and size + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xWindowPeer); + assertNotNull("failed: there is no window, cast wrong?", xWindow); + + xWindow.setVisible(Boolean.TRUE); + + int x = 100; + int y = 100; + int width = 640; + int height = 480; + xWindow.setPosSize(x, y, width, height, com.sun.star.awt.PosSize.POSSIZE); + + com.sun.star.awt.Rectangle aRect = xWindow.getPosSize(); + com.sun.star.awt.Point aPoint = new com.sun.star.awt.Point(aRect.X, aRect.Y); + com.sun.star.awt.Size aSize = new com.sun.star.awt.Size(aRect.Width, aRect.Height); + + System.out.println("Window position and size in pixel:"); + System.out.println("X:" + aPoint.X); + System.out.println("Y:" + aPoint.Y); + System.out.println("Width:" + aSize.Width); + System.out.println("Height:" + aSize.Height); + System.out.println(""); + + assertTrue("Window pos size wrong", aSize.Width == width && aSize.Height == height && aPoint.X == x && aPoint.Y == y); + + m_xConversion = UnoRuntime.queryInterface(XUnitConversion.class, xWindowPeer); + + // try to get the position of the window in 1/100mm with the XUnitConversion method + try + { + com.sun.star.awt.Point aPointInMM_100TH = m_xConversion.convertPointToLogic(aPoint, com.sun.star.util.MeasureUnit.MM_100TH); + System.out.println("Window position:"); + System.out.println("X:" + aPointInMM_100TH.X + " 1/100mm"); + System.out.println("Y:" + aPointInMM_100TH.Y + " 1/100mm"); + System.out.println(""); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + fail("failed: IllegalArgumentException caught in convertPointToLogic " + e.getMessage()); + } + + // try to get the size of the window in 1/100mm with the XUnitConversion method + com.sun.star.awt.Size aSizeInMM_100TH = null; + com.sun.star.awt.Size aSizeInMM_10TH = null; + try + { + aSizeInMM_100TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_100TH); + System.out.println("Window size:"); + System.out.println("Width:" + aSizeInMM_100TH.Width + " 1/100mm"); + System.out.println("Height:" + aSizeInMM_100TH.Height + " 1/100mm"); + System.out.println(""); + + // try to get the size of the window in 1/10mm with the XUnitConversion method + + aSizeInMM_10TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_10TH); + System.out.println("Window size:"); + System.out.println("Width:" + aSizeInMM_10TH.Width + " 1/10mm"); + System.out.println("Height:" + aSizeInMM_10TH.Height + " 1/10mm"); + System.out.println(""); + + // check the size with a delta which must be smaller a given difference + assertTrue("Size.Width not correct", delta(aSizeInMM_100TH.Width, aSizeInMM_10TH.Width * 10) < 10); + assertTrue("Size.Height not correct", delta(aSizeInMM_100TH.Height, aSizeInMM_10TH.Height * 10) < 10); + + // new + checkSize(aSize, com.sun.star.util.MeasureUnit.PIXEL, "pixel"); + checkSize(aSize, com.sun.star.util.MeasureUnit.APPFONT, "appfont"); + checkSize(aSize, com.sun.star.util.MeasureUnit.SYSFONT, "sysfont"); + + // simply check some more parameters + checkSize(aSize, com.sun.star.util.MeasureUnit.MM, "mm"); + checkSize(aSize, com.sun.star.util.MeasureUnit.CM, "cm"); + checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_1000TH, "1/1000inch"); + checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_100TH, "1/100inch"); + checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_10TH, "1/10inch"); + checkSize(aSize, com.sun.star.util.MeasureUnit.INCH, "inch"); + // checkSize(aSize, com.sun.star.util.MeasureUnit.M, "m"); + checkSize(aSize, com.sun.star.util.MeasureUnit.POINT, "point"); + checkSize(aSize, com.sun.star.util.MeasureUnit.TWIP, "twip"); + // checkSize(aSize, com.sun.star.util.MeasureUnit.KM, "km"); + // checkSize(aSize, com.sun.star.util.MeasureUnit.PICA, "pica"); + // checkSize(aSize, com.sun.star.util.MeasureUnit.FOOT, "foot"); + // checkSize(aSize, com.sun.star.util.MeasureUnit.MILE, "mile"); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + fail("failed: IllegalArgumentException caught in convertSizeToLogic " + e.getMessage()); + } + + // convert the 1/100mm window size back to pixel + try + { + com.sun.star.awt.Size aNewSize = m_xConversion.convertSizeToPixel(aSizeInMM_100TH, com.sun.star.util.MeasureUnit.MM_100TH); + System.out.println("Window size:"); + System.out.println("Width:" + aNewSize.Width + " pixel"); + System.out.println("Height:" + aNewSize.Height + " pixel"); + + // assure the pixels are the same as we already know + assertTrue("failed: Size from pixel to 1/100mm to pixel", aSize.Width == aNewSize.Width && aSize.Height == aNewSize.Height); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + fail("failed: IllegalArgumentException caught in convertSizeToPixel " + e.getMessage()); + } + + // close the window. + // IMHO a little bit stupid, but the XWindow doesn't support a XCloseable interface + xWindow.dispose(); + } + + @BeforeClass + public static void setUpConnection() throws Exception + { + System.out.println( "--------------------------------------------------------------------------------" ); + System.out.println( "starting class: " + UnitConversion.class.getName() ); + System.out.println( "connecting ..." ); + connection.setUp(); + } + + @AfterClass + public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println(); + System.out.println( "tearing down connection" ); + connection.tearDown(); + System.out.println( "finished class: " + UnitConversion.class.getName() ); + System.out.println( "--------------------------------------------------------------------------------" ); + } + + private static final OfficeConnection connection = new OfficeConnection(); +} diff --git a/toolkit/qa/complex/toolkit/_XRequestCallback.java b/toolkit/qa/complex/toolkit/_XRequestCallback.java deleted file mode 100644 index b9486c04c80a..000000000000 --- a/toolkit/qa/complex/toolkit/_XRequestCallback.java +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -package complex.toolkit; - -import com.sun.star.awt.XRequestCallback; -// import lib.MultiMethodTest; -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.uno.XInterface; -import com.sun.star.uno.UnoRuntime; -// import share.LogWriter; - -/** - * Testing <code>com.sun.star.awt.XRequestCallback</code> - * interface methods : - * <ul> - * <li><code> addCallback()</code></li> - * </ul> <p> - * @see com.sun.star.awt.XRequestCallback - */ -public class _XRequestCallback { - - // private LogWriter log; - - private static final String className = - "com.sun.star.awt.XRequestCallback" ; - - public XRequestCallback oObj = null; - private XMultiServiceFactory xMSF; - - String text = null; - - - public _XRequestCallback(XInterface object, XMultiServiceFactory xMSF ) { - oObj = UnoRuntime.queryInterface(XRequestCallback.class, object); - this.xMSF = xMSF; - // this.log = log; - } - - - /** - * Calls the method and checks returned value. - * Has OK status if returned value is equal to <code>chCount - 1</code>. - * The following method tests are to be executed before: - * <ul> - * <li> <code>addCallback()</code> </li> - * </ul> - * @return - */ - public boolean _addCallback() { - - boolean res = true; - try { - Object a = new Object(); - oObj.addCallback( null, a ); - } catch (com.sun.star.uno.RuntimeException ie) { - res = false; - } - System.out.println("addCallback called" ); - - return res; - } - -} diff --git a/toolkit/qa/complex/toolkit/_XAccessibleComponent.java b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleComponent.java index ae3e293e50fc..7dca37ce18b7 100755 --- a/toolkit/qa/complex/toolkit/_XAccessibleComponent.java +++ b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleComponent.java @@ -25,9 +25,8 @@ * ************************************************************************/ -package complex.toolkit; +package complex.toolkit.accessibility; -// import share.LogWriter; import com.sun.star.awt.Point; import com.sun.star.awt.Rectangle; import com.sun.star.awt.Size; diff --git a/toolkit/qa/complex/toolkit/_XAccessibleContext.java b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleContext.java index de2928fdabe3..14debda92cd8 100755 --- a/toolkit/qa/complex/toolkit/_XAccessibleContext.java +++ b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleContext.java @@ -25,7 +25,7 @@ * ************************************************************************/ -package complex.toolkit; +package complex.toolkit.accessibility; import com.sun.star.lang.Locale; import com.sun.star.uno.XInterface; diff --git a/toolkit/qa/complex/toolkit/_XAccessibleEventBroadcaster.java b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleEventBroadcaster.java index 899028daec87..535c7ce36c68 100755 --- a/toolkit/qa/complex/toolkit/_XAccessibleEventBroadcaster.java +++ b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleEventBroadcaster.java @@ -25,7 +25,7 @@ * ************************************************************************/ -package complex.toolkit; +package complex.toolkit.accessibility; import com.sun.star.lang.EventObject; import com.sun.star.awt.Rectangle; @@ -33,13 +33,11 @@ import com.sun.star.awt.PosSize; import com.sun.star.awt.XWindow; import com.sun.star.accessibility.AccessibleEventObject; import com.sun.star.accessibility.XAccessible; -// import com.sun.star.accessibility.XAccessibleComponent; import com.sun.star.accessibility.XAccessibleEventBroadcaster; import com.sun.star.accessibility.XAccessibleEventListener; import com.sun.star.accessibility.XAccessibleContext; import com.sun.star.uno.XInterface; import com.sun.star.uno.UnoRuntime; -// import share.LogWriter; /** * Testing <code> @@ -62,12 +60,7 @@ import com.sun.star.uno.UnoRuntime; */ public class _XAccessibleEventBroadcaster { - // private LogWriter log; - private static final String className = - "com.sun.star.accessibility.XAccessibleEventBroadcaster" ; - public XAccessibleEventBroadcaster oObj = null; - public String EventMsg = ""; EventProducer prod = null ; EvListener list = new EvListener(); @@ -120,11 +113,9 @@ public class _XAccessibleEventBroadcaster { * @param eventMessage * @param window */ - public _XAccessibleEventBroadcaster(XInterface object, String eventMessage, XWindow window) { + public _XAccessibleEventBroadcaster(XInterface object, XWindow window) { oObj = UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, object); - // this.log = log; prod = new EventProducer(window); - EventMsg = eventMessage; } /** @@ -157,7 +148,6 @@ public class _XAccessibleEventBroadcaster { oObj.removeEventListener(list); } -// System.out.println(EventMsg); return works; } diff --git a/toolkit/qa/complex/toolkit/_XAccessibleExtendedComponent.java b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleExtendedComponent.java index 2ba5c190cf31..551b00acada7 100755 --- a/toolkit/qa/complex/toolkit/_XAccessibleExtendedComponent.java +++ b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleExtendedComponent.java @@ -25,7 +25,7 @@ * ************************************************************************/ -package complex.toolkit; +package complex.toolkit.accessibility; // import lib.MultiMethodTest; import com.sun.star.accessibility.XAccessibleExtendedComponent; diff --git a/toolkit/qa/complex/toolkit/_XAccessibleText.java b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleText.java index 151e6b3f7d0b..a12d93a2d9e2 100755 --- a/toolkit/qa/complex/toolkit/_XAccessibleText.java +++ b/toolkit/qa/complex/toolkit/accessibility/_XAccessibleText.java @@ -25,7 +25,7 @@ * ************************************************************************/ -package complex.toolkit; +package complex.toolkit.accessibility; import com.sun.star.accessibility.XAccessibleText; // import lib.MultiMethodTest; diff --git a/toolkit/qa/complex/toolkit/awtgrid/DummyColumn.java b/toolkit/qa/complex/toolkit/awtgrid/DummyColumn.java new file mode 100755 index 000000000000..11e4a4b19f80 --- /dev/null +++ b/toolkit/qa/complex/toolkit/awtgrid/DummyColumn.java @@ -0,0 +1,180 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + *************************************************************************/ + +package complex.toolkit.awtgrid; + +import com.sun.star.awt.grid.XGridColumn; +import com.sun.star.awt.grid.XGridColumnListener; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XEventListener; +import com.sun.star.style.HorizontalAlignment; +import com.sun.star.util.XCloneable; + +/** + * a dummy implementation of css.awt.grid.XGridColumn + * @author frank.schoenheit@oracle.com + */ +public class DummyColumn implements XGridColumn +{ + public DummyColumn() + { + } + + public Object getIdentifier() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setIdentifier( Object o ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public int getColumnWidth() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setColumnWidth( int i ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public int getMinWidth() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setMinWidth( int i ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public int getMaxWidth() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setMaxWidth( int i ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public boolean getResizeable() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setResizeable( boolean bln ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public int getFlexibility() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setFlexibility( int i ) throws IllegalArgumentException + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public HorizontalAlignment getHorizontalAlign() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setHorizontalAlign( HorizontalAlignment ha ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public String getTitle() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setTitle( String string ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public String getHelpText() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setHelpText( String string ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public int getIndex() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public int getDataColumnIndex() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void setDataColumnIndex( int i ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void addGridColumnListener( XGridColumnListener xl ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void removeGridColumnListener( XGridColumnListener xl ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void dispose() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void addEventListener( XEventListener xl ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public void removeEventListener( XEventListener xl ) + { + throw new UnsupportedOperationException( "Not supported yet." ); + } + + public XCloneable createClone() + { + throw new UnsupportedOperationException( "Not supported yet." ); + } +} diff --git a/toolkit/qa/complex/toolkit/awtgrid/GridDataListener.java b/toolkit/qa/complex/toolkit/awtgrid/GridDataListener.java new file mode 100755 index 000000000000..c31f27796cf1 --- /dev/null +++ b/toolkit/qa/complex/toolkit/awtgrid/GridDataListener.java @@ -0,0 +1,98 @@ +package complex.toolkit.awtgrid; + +import com.sun.star.awt.grid.GridDataEvent; +import com.sun.star.awt.grid.XGridDataListener; +import com.sun.star.lang.EventObject; +import static org.junit.Assert.*; + +final public class GridDataListener implements XGridDataListener +{ + public GridDataListener() + { + } + + public void rowsInserted( GridDataEvent i_event ) + { + assertNull( m_rowInsertionEvent ); + m_rowInsertionEvent = i_event; + } + + public void rowsRemoved( GridDataEvent i_event ) + { + assertNull( m_rowRemovalEvent ); + m_rowRemovalEvent = i_event; + } + + public void dataChanged( GridDataEvent i_event ) + { + assertNull( m_dataChangeEvent ); + m_dataChangeEvent = i_event; + } + + public void rowHeadingChanged( GridDataEvent i_event ) + { + assertNull( m_rowHeadingChangeEvent ); + m_rowHeadingChangeEvent = i_event; + } + + public void disposing( EventObject eo ) + { + m_disposed = true; + } + + public final GridDataEvent assertSingleRowInsertionEvent() + { + assertNotNull( m_rowInsertionEvent ); + assertNull( m_rowRemovalEvent ); + assertNull( m_dataChangeEvent ); + assertNull( m_rowHeadingChangeEvent ); + assertFalse( m_disposed ); + return m_rowInsertionEvent; + } + + public final GridDataEvent assertSingleRowRemovalEvent() + { + assertNull( m_rowInsertionEvent ); + assertNotNull( m_rowRemovalEvent ); + assertNull( m_dataChangeEvent ); + assertNull( m_rowHeadingChangeEvent ); + assertFalse( m_disposed ); + return m_rowRemovalEvent; + } + + public final GridDataEvent assertSingleDataChangeEvent() + { + assertNull( m_rowInsertionEvent ); + assertNull( m_rowRemovalEvent ); + assertNotNull( m_dataChangeEvent ); + assertNull( m_rowHeadingChangeEvent ); + assertFalse( m_disposed ); + return m_dataChangeEvent; + } + + public final GridDataEvent assertSingleRowHeadingChangeEvent() + { + assertNull( m_rowInsertionEvent ); + assertNull( m_rowRemovalEvent ); + assertNull( m_dataChangeEvent ); + assertNotNull( m_rowHeadingChangeEvent ); + assertFalse( m_disposed ); + return m_rowHeadingChangeEvent; + } + + public final boolean isDisposed() + { + return m_disposed; + } + + public final void reset() + { + m_rowInsertionEvent = m_rowRemovalEvent = m_dataChangeEvent = m_rowHeadingChangeEvent = null; + // m_disposed is not reset intentionally + } + private GridDataEvent m_rowInsertionEvent = null; + private GridDataEvent m_rowRemovalEvent = null; + private GridDataEvent m_dataChangeEvent = null; + private GridDataEvent m_rowHeadingChangeEvent = null; + private boolean m_disposed = false; +} diff --git a/toolkit/qa/complex/toolkit/awtgrid/TMutableGridDataModel.java b/toolkit/qa/complex/toolkit/awtgrid/TMutableGridDataModel.java new file mode 100755 index 000000000000..c550dd9a047d --- /dev/null +++ b/toolkit/qa/complex/toolkit/awtgrid/TMutableGridDataModel.java @@ -0,0 +1,314 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + *************************************************************************/ + +package complex.toolkit.awtgrid; + +import java.lang.reflect.Method; +import com.sun.star.awt.grid.GridDataEvent; +import com.sun.star.awt.grid.XMutableGridDataModel; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.IndexOutOfBoundsException; +import static org.junit.Assert.*; +import static complex.toolkit.Assert.*; + +/** test for the <code>css.awt.grid.XMutableGridData</code> interface + * + * @author frank.schoenheit@oracle.com + */ +public class TMutableGridDataModel +{ + public TMutableGridDataModel( final XMutableGridDataModel i_dataModel ) + { + m_dataModel = i_dataModel; + + m_listener = new GridDataListener(); + m_dataModel.addGridDataListener( m_listener ); + } + + /* + * tests the XMutableGridDataModel.addRow method + */ + public void testAddRow() throws IndexOutOfBoundsException + { + m_dataModel.addRow( 1, m_rowValues[0] ); + GridDataEvent event = m_listener.assertSingleRowInsertionEvent(); + m_listener.reset(); + assertEquals( "row insertion: wrong FirstRow (1)", 0, event.FirstRow ); + assertEquals( "row insertion: wrong LastRow (1)", 0, event.LastRow ); + impl_assertRowData( 0 ); + + m_dataModel.addRow( 2, m_rowValues[1] ); + event = m_listener.assertSingleRowInsertionEvent(); + m_listener.reset(); + assertEquals( "row insertion: wrong FirstRow (2)", 1, event.FirstRow ); + assertEquals( "row insertion: wrong LastRow (2)", 1, event.LastRow ); + impl_assertRowData( 1 ); + } + + /** + * tests the XMutableGridDataModel.addRows method + */ + public void testAddRows() throws IndexOutOfBoundsException, IllegalArgumentException + { + assertEquals( "precondition not met: call this directly after testAddRow, please!", 2, m_dataModel.getRowCount() ); + + m_dataModel.addRows( new Object[] { "3", 4.0, "5" }, new Object[][] { m_rowValues[2], m_rowValues[3], m_rowValues[4] } ); + GridDataEvent event = m_listener.assertSingleRowInsertionEvent(); + assertEquals( "row insertion: wrong FirstRow (1)", 2, event.FirstRow ); + assertEquals( "row insertion: wrong LastRow (1)", 4, event.LastRow ); + m_listener.reset(); + + assertEquals( "data model's row count is not adjusted when adding rows", m_rowValues.length, m_dataModel.getRowCount() ); + assertEquals( "data model's column count is not adjusted when adding rows", m_rowValues[0].length, m_dataModel.getColumnCount() ); + for ( int row=0; row<m_rowValues.length; ++row ) + { + for ( int col=0; col<m_rowValues[row].length; ++col ) + { + assertEquals( "added row values are not preserved", + m_rowValues[row][col], m_dataModel.getCellData( col, row ) ); + } + } + + assertException( "addRows is expected to throw when invoked with different-sized arrays", + m_dataModel, "addRows", new Object[] { new Object[0], new Object[1][2] }, IllegalArgumentException.class ); + } + + /** + * tests the XMutableGridDataModel.removeRow method + */ + public void testRemoveRow() throws IndexOutOfBoundsException + { + assertEquals( "precondition not met: call this directly after testAddRows, please!", m_rowValues.length, m_dataModel.getRowCount() ); + + final int rowToRemove = 2; + m_dataModel.removeRow( rowToRemove ); + GridDataEvent event = m_listener.assertSingleRowRemovalEvent(); + assertEquals( "incorrect notification of row removal (FirstRow)", rowToRemove, event.FirstRow ); + assertEquals( "incorrect notification of row removal (LastRow)", rowToRemove, event.LastRow ); + m_listener.reset(); + + assertEquals( "data model's row count does not reflect the removed row", m_rowValues.length - 1, m_dataModel.getRowCount() ); + for ( int row = rowToRemove; row<m_rowValues.length-1; ++row ) + { + for ( int col=0; col<m_rowValues[row].length; ++col ) + { + assertEquals( "unexpected row values after removing a row (col: " + col + ", row: " + row + ")", + m_rowValues[row+1][col], m_dataModel.getCellData( col, row ) ); + } + } + + assertException( "removeRow silently ignores an invalid index (1)", + m_dataModel, "removeRow", new Object[] { -1 }, IndexOutOfBoundsException.class ); + assertException( "removeRow silently ignores an invalid index (2)", + m_dataModel, "removeRow", new Object[] { m_dataModel.getRowCount() }, IndexOutOfBoundsException.class ); + } + + /** + * tests the XMutableGridDataModel.removeAllRows method + */ + public void testRemoveAllRows() + { + assertEquals( "precondition not met: call this directly after testRemoveRow, please!", m_rowValues.length - 1, m_dataModel.getRowCount() ); + + m_dataModel.removeAllRows(); + final GridDataEvent event = m_listener.assertSingleRowRemovalEvent(); + if ( event.FirstRow != -1 ) + { // notifying "-1" is allowed, this means "all rows affected", by definition + assertEquals( "removeAllRows is not notifying properly (1)", 0, event.FirstRow ); + assertEquals( "removeAllRows is not notifying properly (2)", m_rowValues.length - 1, event.LastRow ); + } + m_listener.reset(); + } + + /** + * tests the XMutableGridDataModel.updateCellData method + */ + public void testUpdateCellData() throws IndexOutOfBoundsException, IllegalArgumentException + { + assertEquals( "precondition not met: call this directly after testRemoveAllRows, please!", 0, m_dataModel.getRowCount() ); + + m_dataModel.addRows( new Object[] { 1, 2, 3, 4, 5 }, m_rowValues ); + m_listener.assertSingleRowInsertionEvent(); + m_listener.reset(); + + final Object[][] modifyValues = new Object[][] { + new Object[] { 2, 1, "text" }, + new Object[] { 3, 0, null }, + new Object[] { 0, 4, new Double( 33.0 ) } + }; + for ( int i = 0; i < modifyValues.length; ++i ) + { + final int row = ((Integer)modifyValues[i][0]).intValue(); + final int col = ((Integer)modifyValues[i][1]).intValue(); + final Object value = modifyValues[i][2]; + m_dataModel.updateCellData( col, row, value ); + + final GridDataEvent event = m_listener.assertSingleDataChangeEvent(); + assertEquals( "data change notification: FirstRow is invalid", row, event.FirstRow ); + assertEquals( "data change notification: LastRow is invalid", row, event.LastRow ); + assertEquals( "data change notification: FirstColumn is invalid", col, event.FirstColumn ); + assertEquals( "data change notification: LastColumn is invalid", col, event.LastColumn ); + m_listener.reset(); + + assertEquals( "data change at (" + col + ", " + row + ") not successful", value, m_dataModel.getCellData( col, row ) ); + } + + assertException( "updateCellData silently ignores an invalid index (1)", + m_dataModel, "updateCellData", new Class[] { int.class, int.class, Object.class }, + new Object[] { -1, -1, "text" }, IndexOutOfBoundsException.class ); + assertException( "updateCellData silently ignores an invalid index (2)", + m_dataModel, "updateCellData", new Class[] { int.class, int.class, Object.class }, + new Object[] { 0, m_dataModel.getRowCount(), "text" }, IndexOutOfBoundsException.class ); + assertException( "updateCellData silently ignores an invalid index (3)", + m_dataModel, "updateCellData", new Class[] { int.class, int.class, Object.class }, + new Object[] { m_dataModel.getColumnCount(), 0, "text" }, IndexOutOfBoundsException.class ); + } + + /** + * tests the XMutableGridDataModel.updateRowData method + */ + public void testUpdateRowData() throws IndexOutOfBoundsException, IllegalArgumentException + { + assertEquals( "precondition not met: call this directly after testRemoveAllRows, please!", m_rowValues.length, m_dataModel.getRowCount() ); + + // get data from before the update + final Object[][] preUpdateValues = impl_getCurrentData(); + + // do the update + final int[] colIndexes = new int[] { + 0, 3, 4 + }; + final Object[] values = new Object[] { + 13, null, 42.0 + }; + final int rowToUpdate = 2; + m_dataModel.updateRowData( colIndexes, rowToUpdate, values ); + final GridDataEvent event = m_listener.assertSingleDataChangeEvent(); + assertEquals( "row update notification: FirstRow is invalid", rowToUpdate, event.FirstRow ); + assertEquals( "row update notification: LastRow is invalid", rowToUpdate, event.LastRow ); + assertEquals( "row update notification: FirstColumn is invalid", 0, event.FirstColumn ); + assertEquals( "row update notification: LastColumn is invalid", 4, event.LastColumn ); + m_listener.reset(); + + // reflect the changes made in the pre-update data + for ( int i=0; i<colIndexes.length; ++i ) + { + preUpdateValues[rowToUpdate][colIndexes[i]] = values[i]; + } + + // get data from after the update + final Object[][] postUpdateValues = impl_getCurrentData(); + + // ensure both the manually updated pre-update data and the post-update data are identical + assertArrayEquals( preUpdateValues, postUpdateValues ); + + + assertException( "updateRowData silently ignores an invalid index (1)", + m_dataModel, "updateRowData", new Class[] { int[].class, int.class, Object[].class }, + new Object[] { new int[] { -1 }, 0, new Object[] { "text" } }, IndexOutOfBoundsException.class ); + assertException( "updateRowData silently ignores an invalid index (2)", + m_dataModel, "updateRowData", new Class[] { int[].class, int.class, Object[].class }, + new Object[] { new int[] { 0 }, -1, new Object[] { "" } }, IndexOutOfBoundsException.class ); + assertException( "updateRowData silently ignores different-sized arrays", + m_dataModel, "updateRowData", new Class[] { int[].class, int.class, Object[].class }, + new Object[] { new int[] { 0, 0 }, 0, new Object[] { "" } }, IllegalArgumentException.class ); + } + + /** + * tests the XMutableGridDataModel.updateRowHeading method + */ + public void testUpdateRowHeading() throws IndexOutOfBoundsException + { + assertEquals( "precondition not met: call this directly after testUpdateRowData, please!", m_rowValues.length, m_dataModel.getRowCount() ); + + final Object[] preUpdateHeadings = impl_getCurrentRowHeadings(); + + final int rowToUpdate = 2; + final String valueToUpdate = "some text"; + m_dataModel.updateRowHeading( rowToUpdate, valueToUpdate ); + final GridDataEvent event = m_listener.assertSingleRowHeadingChangeEvent(); + assertEquals( "row heading update notification: FirstRow is invalid", rowToUpdate, event.FirstRow ); + assertEquals( "row heading update notification: FirstRow is invalid", rowToUpdate, event.LastRow ); + m_listener.reset(); + + preUpdateHeadings[rowToUpdate] = valueToUpdate; + + final Object[] postUpdateHeadings = impl_getCurrentRowHeadings(); + assertArrayEquals( preUpdateHeadings, postUpdateHeadings ); + + assertException( "updateRowHeading silently ignores an invalid index", + m_dataModel, "updateRowHeading", new Class[] { int.class, Object.class }, + new Object[] { -1, "" }, IndexOutOfBoundsException.class ); + } + + public void cleanup() + { + m_dataModel.removeGridDataListener( m_listener ); + } + + private Object[][] impl_getCurrentData() throws IndexOutOfBoundsException + { + final int rowCount = m_dataModel.getRowCount(); + final int colCount = m_dataModel.getColumnCount(); + final Object[][] data = new Object[rowCount][colCount]; + for ( int row=0; row<rowCount; ++row ) + { + for ( int col=0; col<colCount; ++col ) + { + data[row][col] = m_dataModel.getCellData( col, row ); + } + } + return data; + } + + private Object[] impl_getCurrentRowHeadings() throws IndexOutOfBoundsException + { + final int rowCount = m_dataModel.getRowCount(); + final Object[] headings = new Object[rowCount]; + for ( int row=0; row<rowCount; ++row ) + headings[row] = m_dataModel.getRowHeading( row ); + return headings; + } + + private void impl_assertRowData( final int i_rowIndex ) throws IndexOutOfBoundsException + { + for ( int i=0; i<m_rowValues[i_rowIndex].length; ++i ) + { + assertEquals( m_rowValues[i_rowIndex][i], m_dataModel.getCellData( i, i_rowIndex ) ); + } + } + + private final XMutableGridDataModel m_dataModel; + private final GridDataListener m_listener; + + private final static Object[][] m_rowValues = new Object[][] { + new Object[] { 1, 2, "3", 4, 5 }, + new Object[] { 2, 3, 4, "5", 6 }, + new Object[] { "3", 4, 5, 6, 7 }, + new Object[] { 4, 5, 6, 7, "8" }, + new Object[] { 5, "6", 7, 8, 9 }, + }; +} diff --git a/toolkit/qa/complex/toolkit/makefile.mk b/toolkit/qa/complex/toolkit/makefile.mk new file mode 100755 index 000000000000..ecb173f9bdac --- /dev/null +++ b/toolkit/qa/complex/toolkit/makefile.mk @@ -0,0 +1,97 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +.IF "$(OOO_JUNIT_JAR)" == "" +nothing .PHONY: + @echo ----------------------------------------------------- + @echo - JUnit not available, not building anything + @echo ----------------------------------------------------- +.ELSE # IF "$(OOO_JUNIT_JAR)" != "" + +PRJ = ../../.. +PRJNAME = toolkit +TARGET = qa_complex_toolkit +PACKAGE = complex/toolkit + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + +#----- compile .java files ----------------------------------------- + +JARFILES = OOoRunnerLight.jar ridl.jar test.jar unoil.jar +EXTRAJARFILES = $(OOO_JUNIT_JAR) + +JAVAFILES = \ + $(JAVATESTFILES) \ + accessibility/_XAccessibleComponent.java \ + accessibility/_XAccessibleContext.java \ + accessibility/_XAccessibleEventBroadcaster.java \ + accessibility/_XAccessibleExtendedComponent.java \ + accessibility/_XAccessibleText.java \ + Assert.java \ + awtgrid/GridDataListener.java \ + awtgrid/TMutableGridDataModel.java \ + awtgrid/DummyColumn.java \ + +#----- create a jar from compiled files ---------------------------- + +JARTARGET = $(TARGET).jar + +#----- JUnit tests class ------------------------------------------- + +JAVATESTFILES = \ + GridControl.java \ + UnitConversion.java \ + + +# disabled for now - the tests fail on at least one platform +# no issue, yet (not sure this is worth it. Don't know who to give the issue to, and don't know whether the test really makes sense) +DISABLED_JAVA_TEST_FILES=\ + AccessibleStatusBar.java\ + AccessibleStatusBarItem.java + + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk + +ALL : ALLTAR + +# --- subsequent tests --------------------------------------------- + +.IF "$(OOO_SUBSEQUENT_TESTS)" != "" + +.INCLUDE: installationtest.mk + +ALLTAR : javatest + + # Sample how to debug + # JAVAIFLAGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9003,suspend=y + +.END # "$(OOO_SUBSEQUENT_TESTS)" == "" + +.END # ELSE "$(OOO_JUNIT_JAR)" != "" diff --git a/toolkit/qa/complex/xunitconversion/XUnitConversionTest.java b/toolkit/qa/complex/xunitconversion/XUnitConversionTest.java deleted file mode 100644 index f9840e4bde6f..000000000000 --- a/toolkit/qa/complex/xunitconversion/XUnitConversionTest.java +++ /dev/null @@ -1,250 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -package complex.xunitconversion; - -import com.sun.star.awt.XUnitConversion; -import com.sun.star.uno.UnoRuntime; - -import com.sun.star.awt.XWindow; -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.awt.XWindowPeer; - -import util.DesktopTools; - -// import org.junit.After; -import org.junit.AfterClass; -// import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openoffice.test.OfficeConnection; -import static org.junit.Assert.*; - -/** - * This complex test is only for testing the com.sun.star.awt.XUnitConversion methods - * These are converter methods to get the size of a well known awt component - * in a com.sun.star.util.MeasureUnit you want. - * You don't need to know the factors to calculate by hand. - * - * @author ll93751 - */ -public class XUnitConversionTest -{ -// public String[] getTestMethodNames() -// { -// return new String[]{"testXUnitConversion"}; // function name of the test method -// } - - /** - * returns the delta value between a and b - * @param a - * @param b - * @return - */ - private int delta(int a, int b) - { - final int n = Math.abs(a - b); - return n; - } - - private XUnitConversion m_xConversion = null; - - /** - * Not really a check, - * only a simple test call to convertSizeToLogic(...) with different parameters - * @param _aSize - * @param _aMeasureUnit - * @param _sEinheit - */ - private void checkSize(com.sun.star.awt.Size _aSize, short _aMeasureUnit, String _sEinheit) - { - try - { - com.sun.star.awt.Size aSizeIn = m_xConversion.convertSizeToLogic(_aSize, _aMeasureUnit); - System.out.println("Window size:"); - System.out.println("Width:" + aSizeIn.Width + " " + _sEinheit); - System.out.println("Height:" + aSizeIn.Height + " " + _sEinheit); - System.out.println(""); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - System.out.println("Caught IllegalArgumentException in convertSizeToLogic with '" + _sEinheit + "' " + e.getMessage()); - } - } - -/** - * The real test function - * 1. try to get the XMultiServiceFactory of an already running office. Therefore make sure an (open|star)office is running with - * parameters like -accept="socket,host=localhost,port=8100;urp;" - * 2. try to create an empty window - * 3. try to convert the WindowPeer to an XWindow - * 4. try to resize and move the window to an other position, so we get a well knowing position and size. - * 5. run some more tests - * - * If no test fails, the test is well done and returns with 'PASSED, OK' - * - */ - @Test public void testXUnitConversion() - { - // XMultiServiceFactory xMSF = (XMultiServiceFactory) param.getMSF(); - final XMultiServiceFactory xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); - - assertNotNull("failed: There is no office.", xMSF); - - // create a window - XWindowPeer xWindowPeer = DesktopTools.createFloatingWindow(xMSF); - assertNotNull("failed: there is no window peer", xWindowPeer); - - - // resize and move the window to a well known position and size - XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xWindowPeer); - assertNotNull("failed: there is no window, cast wrong?", xWindow); - - xWindow.setVisible(Boolean.TRUE); - - int x = 100; - int y = 100; - int width = 640; - int height = 480; - xWindow.setPosSize(x, y, width, height, com.sun.star.awt.PosSize.POSSIZE); - - com.sun.star.awt.Rectangle aRect = xWindow.getPosSize(); - com.sun.star.awt.Point aPoint = new com.sun.star.awt.Point(aRect.X, aRect.Y); - com.sun.star.awt.Size aSize = new com.sun.star.awt.Size(aRect.Width, aRect.Height); - - System.out.println("Window position and size in pixel:"); - System.out.println("X:" + aPoint.X); - System.out.println("Y:" + aPoint.Y); - System.out.println("Width:" + aSize.Width); - System.out.println("Height:" + aSize.Height); - System.out.println(""); - - assertTrue("Window pos size wrong", aSize.Width == width && aSize.Height == height && aPoint.X == x && aPoint.Y == y); - - // XToolkit aToolkit = xWindowPeer.getToolkit(); - m_xConversion = UnoRuntime.queryInterface(XUnitConversion.class, xWindowPeer); - - // try to get the position of the window in 1/100mm with the XUnitConversion method - try - { - com.sun.star.awt.Point aPointInMM_100TH = m_xConversion.convertPointToLogic(aPoint, com.sun.star.util.MeasureUnit.MM_100TH); - System.out.println("Window position:"); - System.out.println("X:" + aPointInMM_100TH.X + " 1/100mm"); - System.out.println("Y:" + aPointInMM_100TH.Y + " 1/100mm"); - System.out.println(""); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - fail("failed: IllegalArgumentException caught in convertPointToLogic " + e.getMessage()); - } - - // try to get the size of the window in 1/100mm with the XUnitConversion method - com.sun.star.awt.Size aSizeInMM_100TH = null; - com.sun.star.awt.Size aSizeInMM_10TH = null; - try - { - aSizeInMM_100TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_100TH); - System.out.println("Window size:"); - System.out.println("Width:" + aSizeInMM_100TH.Width + " 1/100mm"); - System.out.println("Height:" + aSizeInMM_100TH.Height + " 1/100mm"); - System.out.println(""); - - // try to get the size of the window in 1/10mm with the XUnitConversion method - - aSizeInMM_10TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_10TH); - System.out.println("Window size:"); - System.out.println("Width:" + aSizeInMM_10TH.Width + " 1/10mm"); - System.out.println("Height:" + aSizeInMM_10TH.Height + " 1/10mm"); - System.out.println(""); - - // check the size with a delta which must be smaller a given difference - assertTrue("Size.Width not correct", delta(aSizeInMM_100TH.Width, aSizeInMM_10TH.Width * 10) < 10); - assertTrue("Size.Height not correct", delta(aSizeInMM_100TH.Height, aSizeInMM_10TH.Height * 10) < 10); - - // new - checkSize(aSize, com.sun.star.util.MeasureUnit.PIXEL, "pixel"); - checkSize(aSize, com.sun.star.util.MeasureUnit.APPFONT, "appfont"); - checkSize(aSize, com.sun.star.util.MeasureUnit.SYSFONT, "sysfont"); - - // simply check some more parameters - checkSize(aSize, com.sun.star.util.MeasureUnit.MM, "mm"); - checkSize(aSize, com.sun.star.util.MeasureUnit.CM, "cm"); - checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_1000TH, "1/1000inch"); - checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_100TH, "1/100inch"); - checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_10TH, "1/10inch"); - checkSize(aSize, com.sun.star.util.MeasureUnit.INCH, "inch"); - // checkSize(aSize, com.sun.star.util.MeasureUnit.M, "m"); - checkSize(aSize, com.sun.star.util.MeasureUnit.POINT, "point"); - checkSize(aSize, com.sun.star.util.MeasureUnit.TWIP, "twip"); - // checkSize(aSize, com.sun.star.util.MeasureUnit.KM, "km"); - // checkSize(aSize, com.sun.star.util.MeasureUnit.PICA, "pica"); - // checkSize(aSize, com.sun.star.util.MeasureUnit.FOOT, "foot"); - // checkSize(aSize, com.sun.star.util.MeasureUnit.MILE, "mile"); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - fail("failed: IllegalArgumentException caught in convertSizeToLogic " + e.getMessage()); - } - - // convert the 1/100mm window size back to pixel - try - { - com.sun.star.awt.Size aNewSize = m_xConversion.convertSizeToPixel(aSizeInMM_100TH, com.sun.star.util.MeasureUnit.MM_100TH); - System.out.println("Window size:"); - System.out.println("Width:" + aNewSize.Width + " pixel"); - System.out.println("Height:" + aNewSize.Height + " pixel"); - - // assure the pixels are the same as we already know - assertTrue("failed: Size from pixel to 1/100mm to pixel", aSize.Width == aNewSize.Width && aSize.Height == aNewSize.Height); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - fail("failed: IllegalArgumentException caught in convertSizeToPixel " + e.getMessage()); - } - - // close the window. - // IMHO a little bit stupid, but the XWindow doesn't support a XCloseable interface - xWindow.dispose(); - } - - - - @BeforeClass public static void setUpConnection() throws Exception { - System.out.println("setUpConnection()"); - connection.setUp(); - } - - @AfterClass public static void tearDownConnection() - throws InterruptedException, com.sun.star.uno.Exception - { - System.out.println("tearDownConnection()"); - connection.tearDown(); - } - - private static final OfficeConnection connection = new OfficeConnection(); - -} |