diff options
Diffstat (limited to 'toolkit/qa')
-rw-r--r-- | toolkit/qa/complex/toolkit/GridControl.java | 155 |
1 files changed, 99 insertions, 56 deletions
diff --git a/toolkit/qa/complex/toolkit/GridControl.java b/toolkit/qa/complex/toolkit/GridControl.java index 62ebdd0954f4..fc2c444226b1 100644 --- a/toolkit/qa/complex/toolkit/GridControl.java +++ b/toolkit/qa/complex/toolkit/GridControl.java @@ -33,6 +33,7 @@ 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.XGridControl; import com.sun.star.awt.grid.XGridDataModel; import com.sun.star.awt.grid.XMutableGridDataModel; import com.sun.star.awt.grid.XSortableMutableGridDataModel; @@ -59,6 +60,8 @@ import java.util.List; import java.util.Random; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; import org.openoffice.test.OfficeConnection; @@ -432,63 +435,88 @@ public class GridControl // ----------------------------------------------------------------------------------------------------------------- @Test - public void testModelViewInteraction() throws Exception + public void testView() throws Exception { - final List< Object > disposables = new ArrayList< Object >(); - try - { - // create a simple 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()); - } + final XControl control = impl_createDialogWithGridControl(); + final XPropertySet gridModelProps = + UnoRuntime.queryInterface( XPropertySet.class, control.getModel() ); + + // 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() ); + + final int columnCount = 3; + final int rowCount = 2; + dataModel.addRow( null, new Object[] { 1, 2, 3 } ); + dataModel.addRow( null, new Object[] { 6, 5, 4 } ); + + assertEquals( columnCount, dataModel.getColumnCount() ); + assertEquals( columnCount, columnModel.getColumnCount() ); + + // some cursor traveling + final XGridControl gridControl = UnoRuntime.queryInterface( XGridControl.class, control ); + gridControl.goToCell( 0, 0 ); + assertEquals( "wrong 'current column' (1)", 0, gridControl.getCurrentColumn() ); + assertEquals( "wrong 'current row' (1)", 0, gridControl.getCurrentRow() ); + gridControl.goToCell( columnCount - 1, rowCount - 1 ); + assertEquals( "wrong 'current column' (2)", dataModel.getColumnCount() - 1, gridControl.getCurrentColumn() ); + assertEquals( "wrong 'current row' (2)", dataModel.getRowCount() - 1, gridControl.getCurrentRow() ); + + // removing the last column, while the active cell is in this very last column, is expected to adjust + // the active cell + columnModel.removeColumn( columnCount - 1 ); + assertEquals( "removed the last and active column, active column was not adjusted!", + columnCount - 2, gridControl.getCurrentColumn() ); + // same holds for rows + dataModel.removeRow( rowCount - 1 ); + assertEquals( "removed the last and active row, active row was not adjusted!", + rowCount - 2, gridControl.getCurrentRow() ); + } + + // ----------------------------------------------------------------------------------------------------------------- + private XControl impl_createDialogWithGridControl() throws Exception + { + // create a simple dialog model/control/peer trinity + final XControlModel dialogModel = createInstance( XControlModel.class, "com.sun.star.awt.UnoControlDialogModel" ); + m_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" ); + m_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 ); + final XPropertySet gridModelProps = UnoRuntime.queryInterface( XPropertySet.class, + controlModelFactory.createInstance( "com.sun.star.awt.grid.UnoControlGridModel" ) ); + m_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 ); + + return gridControl; } // ----------------------------------------------------------------------------------------------------------------- @@ -583,6 +611,20 @@ public class GridControl } // ----------------------------------------------------------------------------------------------------------------- + @Before + public void initTestCase() + { + m_disposables.clear(); + } + + // ----------------------------------------------------------------------------------------------------------------- + @After + public void cleanupTestCase() + { + impl_dispose( m_disposables.toArray() ); + } + + // ----------------------------------------------------------------------------------------------------------------- @BeforeClass public static void setUpConnection() throws java.lang.Exception { @@ -709,4 +751,5 @@ public class GridControl private XPropertySet m_gridControlModel; private XGridColumnModel m_columnModel; private XSortableMutableGridDataModel m_dataModel; + private final List< Object > m_disposables = new ArrayList< Object >(); } |