diff options
Diffstat (limited to '')
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java | 113 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java | 257 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/DocumentTest.java | 77 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/DocumentTestBase.java | 44 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java | 35 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java | 207 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/ImpressDocumentTest.java | 35 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java | 121 |
8 files changed, 889 insertions, 0 deletions
diff --git a/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java b/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java new file mode 100644 index 000000000..a0dec8d06 --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java @@ -0,0 +1,113 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import org.openoffice.test.tools.SpreadsheetDocument; +import com.sun.star.table.XCellRange; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.table.XCell; +import com.sun.star.uno.UnoRuntime; +import org.openoffice.test.tools.DocumentType; +import static org.junit.Assert.*; + +/** + * implements the {@link DocumentTest} interface on top of a spreadsheet document + */ +public class CalcDocumentTest extends DocumentTestBase +{ + public CalcDocumentTest( final XMultiServiceFactory i_orb ) throws Exception + { + super( i_orb, DocumentType.CALC ); + } + + public String getDocumentDescription() + { + return "spreadsheet document"; + } + + public void initializeDocument() throws com.sun.star.uno.Exception + { + final XCell cellA1 = getCellA1(); + cellA1.setValue( INIT_VALUE ); + assertEquals( "initializing the cell value didn't work", cellA1.getValue(), INIT_VALUE, 0 ); + + XCellRange range = UnoRuntime.queryInterface( XCellRange.class, + ((SpreadsheetDocument)m_document).getSheet(0) ); + + for ( int i=0; i<12; ++i ) + { + XCell cell = range.getCellByPosition( 1, i ); + cell.setFormula( "" ); + } + } + + public void doSingleModification() throws com.sun.star.uno.Exception + { + final XCell cellA1 = getCellA1(); + assertEquals( "initial cell value not as expected", INIT_VALUE, cellA1.getValue(), 0 ); + cellA1.setValue( MODIFIED_VALUE ); + assertEquals( "modified cell value not as expected", MODIFIED_VALUE, cellA1.getValue(), 0 ); + } + + public void verifyInitialDocumentState() throws com.sun.star.uno.Exception + { + final XCell cellA1 = getCellA1(); + assertEquals( "cell A1 doesn't have its initial value", INIT_VALUE, cellA1.getValue(), 0 ); + + XCellRange range = UnoRuntime.queryInterface( XCellRange.class, + ((SpreadsheetDocument)m_document).getSheet(0) ); + for ( int i=0; i<12; ++i ) + { + final XCell cell = range.getCellByPosition( 1, i ); + assertEquals( "Cell B" + (i+1) + " not having its initial value (an empty string)", "", cell.getFormula() ); + } + } + + public void verifySingleModificationDocumentState() throws com.sun.star.uno.Exception + { + final XCell cellA1 = getCellA1(); + assertEquals( "cell A1 doesn't have the value which we gave it", MODIFIED_VALUE, cellA1.getValue(), 0 ); + } + + public int doMultipleModifications() throws com.sun.star.uno.Exception + { + XCellRange range = UnoRuntime.queryInterface( XCellRange.class, + ((SpreadsheetDocument)m_document).getSheet(0) ); + + final String[] months = new String[] { + "January", "February", "March", "April", "May", "June", "July", "August", + "September", "October", "November", "December" }; + for ( int i=0; i<12; ++i ) + { + final XCell cell = range.getCellByPosition( 1, i ); + cell.setFormula( months[i] ); + } + return 12; + } + + private XCell getCellA1() throws com.sun.star.uno.Exception + { + XCellRange range = UnoRuntime.queryInterface( XCellRange.class, + ((SpreadsheetDocument)m_document).getSheet(0) ); + return range.getCellByPosition( 0, 0 ); + } + + private static final double INIT_VALUE = 100.0; + private static final double MODIFIED_VALUE = 200.0; +} diff --git a/sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java b/sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java new file mode 100644 index 000000000..5d5ea95b2 --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java @@ -0,0 +1,257 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import com.sun.star.chart2.XAxis; +import com.sun.star.chart2.XCoordinateSystem; +import com.sun.star.chart2.XCoordinateSystemContainer; +import com.sun.star.awt.Size; +import com.sun.star.beans.XPropertySet; +import com.sun.star.chart2.XChartDocument; +import com.sun.star.chart2.XDiagram; +import com.sun.star.container.XIndexAccess; +import com.sun.star.document.UndoFailedException; +import com.sun.star.document.XUndoAction; +import com.sun.star.document.XUndoManager; +import com.sun.star.document.XUndoManagerSupplier; +import com.sun.star.drawing.XShape; +import com.sun.star.embed.EmbedStates; +import com.sun.star.embed.EmbedVerbs; +import com.sun.star.embed.XEmbeddedObject; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.text.XTextContent; +import com.sun.star.text.XTextRange; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.view.XSelectionSupplier; +import org.openoffice.test.tools.DocumentType; +import org.openoffice.test.tools.OfficeDocument; +import static org.junit.Assert.*; + +public class ChartDocumentTest implements DocumentTest +{ + public ChartDocumentTest( final XMultiServiceFactory i_orb ) throws com.sun.star.uno.Exception + { + m_textDocument = OfficeDocument.blankDocument( i_orb, DocumentType.WRITER ); + + // create an OLE shape in the document + final XMultiServiceFactory factory = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_textDocument.getDocument() ); + final String shapeServiceName = "com.sun.star.text.TextEmbeddedObject"; + final XPropertySet shapeProps = UnoRuntime.queryInterface( XPropertySet.class, factory.createInstance( shapeServiceName ) ); + shapeProps.setPropertyValue("CLSID", "12dcae26-281f-416f-a234-c3086127382e"); + + final XShape shape = UnoRuntime.queryInterface( XShape.class, shapeProps ); + shape.setSize( new Size( 16000, 9000 ) ); + + final XTextContent chartTextContent = UnoRuntime.queryInterface( XTextContent.class, shapeProps ); + + final XSelectionSupplier selSupplier = UnoRuntime.queryInterface( XSelectionSupplier.class, + m_textDocument.getCurrentView().getController() ); + final Object selection = selSupplier.getSelection(); + final XTextRange textRange = getAssociatedTextRange( selection ); + if ( textRange == null ) + throw new RuntimeException( "can't locate a text range" ); + + // insert the chart + textRange.getText().insertTextContent(textRange, chartTextContent, false); + + // retrieve the chart model + XChartDocument chartDoc = UnoRuntime.queryInterface( XChartDocument.class, shapeProps.getPropertyValue( "Model" ) ); + // insert default chart for the test to use. + com.sun.star.chart2.XChartDocument xCD2 = + UnoRuntime.queryInterface(com.sun.star.chart2.XChartDocument.class, chartDoc); + xCD2.createDefaultChart(); + m_chartDocument = new OfficeDocument( i_orb, chartDoc ); + + // actually activate the object + final XEmbeddedObject embeddedChart = UnoRuntime.queryInterface( XEmbeddedObject.class, + shapeProps.getPropertyValue( "EmbeddedObject" ) ); + embeddedChart.doVerb( EmbedVerbs.MS_OLEVERB_SHOW ); + + final int state = embeddedChart.getCurrentState(); + if ( state != EmbedStates.UI_ACTIVE ) + fail( "unable to activate the embedded chart" ); + } + + public String getDocumentDescription() + { + return "chart document"; + } + + public void initializeDocument() throws com.sun.star.uno.Exception + { + final XPropertySet wallProperties = impl_getWallProperties(); + wallProperties.setPropertyValue( "FillStyle", com.sun.star.drawing.FillStyle.SOLID ); + wallProperties.setPropertyValue( "FillColor", 0x00FFFFFF ); + } + + public void closeDocument() + { + m_textDocument.close(); + } + + private XPropertySet impl_getWallProperties() + { + final XChartDocument chartDoc = UnoRuntime.queryInterface( XChartDocument.class, m_chartDocument.getDocument() ); + final XDiagram diagram = chartDoc.getFirstDiagram(); + final XPropertySet wallProperties = diagram.getWall(); + return wallProperties; + } + + private XPropertySet impl_getYAxisProperties() throws IndexOutOfBoundsException + { + XPropertySet axisProperties = null; + final XChartDocument chartDoc = UnoRuntime.queryInterface( XChartDocument.class, m_chartDocument.getDocument() ); + final XDiagram diagram = chartDoc.getFirstDiagram(); + final XCoordinateSystemContainer coordContainer = UnoRuntime.queryInterface( XCoordinateSystemContainer.class, diagram ); + final XCoordinateSystem[] coordSystems = coordContainer.getCoordinateSystems(); + final XCoordinateSystem coordSystem = coordSystems[0]; + final XAxis primaryYAxis = coordSystem.getAxisByDimension( 1, 0 ); + axisProperties = UnoRuntime.queryInterface( XPropertySet.class, primaryYAxis ); + return axisProperties; + } + + private XUndoManager impl_getUndoManager() + { + final XUndoManagerSupplier undoManagerSupp = UnoRuntime.queryInterface( XUndoManagerSupplier.class, m_chartDocument.getDocument() ); + final XUndoManager undoManager = undoManagerSupp.getUndoManager(); + return undoManager; + } + + public void doSingleModification() throws com.sun.star.uno.Exception + { + final XPropertySet wallProperties = impl_getWallProperties(); + + // simulate an Undo action, as long as the chart implementation doesn't add Undo actions itself + final XUndoManager undoManager = impl_getUndoManager(); + undoManager.addUndoAction( new PropertyUndoAction( wallProperties, "FillColor", 0xCCFF44 ) ); + // (the UndoAction will actually set the property value) + } + + public void verifyInitialDocumentState() throws com.sun.star.uno.Exception + { + final XPropertySet wallProperties = impl_getWallProperties(); + assertEquals( 0x00FFFFFF, ((Integer)wallProperties.getPropertyValue( "FillColor" )).intValue() ); + } + + public void verifySingleModificationDocumentState() throws com.sun.star.uno.Exception + { + final XPropertySet wallProperties = impl_getWallProperties(); + assertEquals( 0xCCFF44, ((Integer)wallProperties.getPropertyValue( "FillColor" )).intValue() ); + } + + public int doMultipleModifications() throws com.sun.star.uno.Exception + { + final XPropertySet axisProperties = impl_getYAxisProperties(); + + final XUndoManager undoManager = impl_getUndoManager(); + undoManager.addUndoAction( new PropertyUndoAction( axisProperties, "LineWidth", 300 ) ); + undoManager.addUndoAction( new PropertyUndoAction( axisProperties, "LineColor", 0x000000 ) ); + + return 2; + } + + public OfficeDocument getDocument() + { + return m_chartDocument; + } + + private XTextRange getAssociatedTextRange( final Object i_object ) throws WrappedTargetException, IndexOutOfBoundsException + { + // possible cases: + // 1. a container of other objects - e.g. selection of 0 to n text portions, or 1 to n drawing objects + final XIndexAccess indexer = UnoRuntime.queryInterface( XIndexAccess.class, i_object ); + if ((indexer != null) && indexer.getCount() > 0) { + final int count = indexer.getCount(); + for (int i = 0; i < count; ++i) { + final XTextRange range = getAssociatedTextRange( indexer.getByIndex(i) ); + if (range != null) { + return range; + } + } + } + // 2. another TextContent, having an anchor we can use + final XTextContent textContent = UnoRuntime.queryInterface(XTextContent.class, i_object); + if (textContent != null) { + final XTextRange range = textContent.getAnchor(); + if (range != null) { + return range; + } + } + + // an object which supports XTextRange directly + final XTextRange range = UnoRuntime.queryInterface(XTextRange.class, i_object); + if (range != null) { + return range; + } + + return null; + } + + private static class PropertyUndoAction implements XUndoAction + { + PropertyUndoAction( final XPropertySet i_component, final String i_propertyName, final Object i_newValue ) throws com.sun.star.uno.Exception + { + m_component = i_component; + m_propertyName = i_propertyName; + m_newValue = i_newValue; + + m_oldValue = i_component.getPropertyValue( m_propertyName ); + i_component.setPropertyValue( m_propertyName, m_newValue ); + } + + public String getTitle() + { + return "some dummy Undo Action"; + } + + public void undo() throws UndoFailedException + { + try + { + m_component.setPropertyValue( m_propertyName, m_oldValue ); + } + catch ( com.sun.star.uno.Exception ex ) + { + throw new UndoFailedException( "", this, ex ); + } + } + + public void redo() throws UndoFailedException + { + try + { + m_component.setPropertyValue( m_propertyName, m_newValue ); + } + catch ( com.sun.star.uno.Exception ex ) + { + throw new UndoFailedException( "", this, ex ); + } + } + + private final XPropertySet m_component; + private final String m_propertyName; + private final Object m_oldValue; + private final Object m_newValue; + } + + private final OfficeDocument m_textDocument; + private final OfficeDocument m_chartDocument; +} diff --git a/sfx2/qa/complex/sfx2/undo/DocumentTest.java b/sfx2/qa/complex/sfx2/undo/DocumentTest.java new file mode 100644 index 000000000..dd5fe4cf7 --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/DocumentTest.java @@ -0,0 +1,77 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import org.openoffice.test.tools.OfficeDocument; + +/** + * wrapper around an OfficeDocument, for running a standardized test procedure (related do Undo functionality) + * on the document. + * + */ +public interface DocumentTest +{ + /** + * returns a human-readable description for the document/type which the tests operates on + */ + public String getDocumentDescription(); + + /** + * initializes the document to a state where the subsequent tests can be ran + */ + public void initializeDocument() throws com.sun.star.uno.Exception; + + /** + * closes the document which the test is based on + */ + public void closeDocument(); + + /** + * does a simple modification to the document, which results in one Undo action being auto-generated + * by the OOo implementation + */ + public void doSingleModification() throws com.sun.star.uno.Exception; + + /** + * verifies the document is in the same state as after {@link #initializeDocument} + */ + public void verifyInitialDocumentState() throws com.sun.star.uno.Exception; + + /** + * verifies the document is in the state as expected after {@link #doSingleModification} + */ + public void verifySingleModificationDocumentState() throws com.sun.star.uno.Exception; + + /** + * does multiple modifications do the document, which would normally result in multiple Undo actions. + * + * The test framework will encapsulate the call into an {@link com.sun.star.document.XUndoManager#enterUndoContext} and + * {@link com.sun.star.document.XUndoManager#leaveUndoContext} call. + * + * @return + * the number of modifications done to the document. The caller assumes (and asserts) that the number + * of actions on the Undo stack equals this number. + */ + public int doMultipleModifications() throws com.sun.star.uno.Exception; + + /** + * returns the document which the test operates on + */ + public OfficeDocument getDocument(); +} diff --git a/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java b/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java new file mode 100644 index 000000000..d7a8c111b --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java @@ -0,0 +1,44 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Exception; +import org.openoffice.test.tools.DocumentType; +import org.openoffice.test.tools.OfficeDocument; + +abstract class DocumentTestBase implements DocumentTest +{ + DocumentTestBase( final XMultiServiceFactory i_orb, final DocumentType i_docType ) throws Exception + { + m_document = OfficeDocument.blankDocument( i_orb, i_docType ); + } + + public OfficeDocument getDocument() + { + return m_document; + } + + public void closeDocument() + { + m_document.close(); + } + + protected final OfficeDocument m_document; +} diff --git a/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java b/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java new file mode 100644 index 000000000..ef4ff7fa0 --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java @@ -0,0 +1,35 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import com.sun.star.lang.XMultiServiceFactory; +import org.openoffice.test.tools.DocumentType; + +public class DrawDocumentTest extends DrawingOrPresentationDocumentTest +{ + public DrawDocumentTest( XMultiServiceFactory i_orb ) throws com.sun.star.uno.Exception + { + super( i_orb, DocumentType.DRAWING ); + } + + public String getDocumentDescription() + { + return "drawing document"; + } +} diff --git a/sfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java b/sfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java new file mode 100644 index 000000000..37b5d0d9c --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java @@ -0,0 +1,207 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import com.sun.star.awt.Rectangle; +import com.sun.star.document.XUndoManager; +import com.sun.star.document.XUndoManagerSupplier; +import com.sun.star.document.XUndoAction; +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +import com.sun.star.beans.XPropertySet; +import com.sun.star.drawing.CircleKind; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import org.openoffice.test.tools.DocumentType; +import static org.junit.Assert.*; + +/** + * implements the {@link DocumentTest} interface on top of a drawing document + */ +public abstract class DrawingOrPresentationDocumentTest extends DocumentTestBase +{ + public DrawingOrPresentationDocumentTest( XMultiServiceFactory i_orb, final DocumentType i_docType ) throws com.sun.star.uno.Exception + { + super( i_orb, i_docType ); + } + + public void initializeDocument() throws com.sun.star.uno.Exception + { + // remove all shapes - Impress has two default shapes in a new doc; just get rid of them + final XShapes firstPageShapes = getFirstPageShapes(); + while ( firstPageShapes.getCount() > 0 ) + firstPageShapes.remove( UnoRuntime.queryInterface( XShape.class, firstPageShapes.getByIndex( 0 ) ) ); + } + + public void doSingleModification() throws com.sun.star.uno.Exception + { + // add a simple centered shape to the first page + Rectangle pagePlayground = impl_getFirstPagePlayground(); + impl_createCircleShape( + ( pagePlayground.X + ( pagePlayground.Width - BIG_CIRCLE_SIZE ) / 2 ), + ( pagePlayground.Y + ( pagePlayground.Height - BIG_CIRCLE_SIZE ) / 2 ), + BIG_CIRCLE_SIZE, + FILL_COLOR + ); + } + + public void verifyInitialDocumentState() throws com.sun.star.uno.Exception + { + final XShapes firstPageShapes = getFirstPageShapes(); + assertEquals( "there should be no shapes at all", 0, firstPageShapes.getCount() ); + } + + public void verifySingleModificationDocumentState() throws com.sun.star.uno.Exception + { + final XShapes firstPageShapes = getFirstPageShapes(); + assertEquals( "there should be one shape, not more, not less", 1, firstPageShapes.getCount() ); + + final Object shape = firstPageShapes.getByIndex(0); + verifyShapeGeometry( shape, BIG_CIRCLE_SIZE, BIG_CIRCLE_SIZE ); + final XPropertySet shapeProps = UnoRuntime.queryInterface( XPropertySet.class, shape ); + assertEquals( "wrong circle type", CIRCLE_TYPE.getValue(), ((CircleKind)shapeProps.getPropertyValue( "CircleKind" )).getValue() ); + //assertEquals( "wrong circle fill color", FILL_COLOR, ((Integer)shapeProps.getPropertyValue( "FillColor" )).intValue() ); + // disable this particular check: A bug in the drawing layer API restores the FillColor to its + // default value upon re-insertion. This is issue #i115080# + } + + public int doMultipleModifications() throws com.sun.star.uno.Exception + { + // add a simple centered shape to the first page + Rectangle pagePlayground = impl_getFirstPagePlayground(); + impl_createCircleShape( + pagePlayground.X, + pagePlayground.Y, + SMALL_CIRCLE_SIZE, + ALTERNATE_FILL_COLOR + ); + impl_createCircleShape( + pagePlayground.X + pagePlayground.Width - SMALL_CIRCLE_SIZE, + pagePlayground.Y, + SMALL_CIRCLE_SIZE, + ALTERNATE_FILL_COLOR + ); + impl_createCircleShape( + pagePlayground.X, + pagePlayground.Y + pagePlayground.Height - SMALL_CIRCLE_SIZE, + SMALL_CIRCLE_SIZE, + ALTERNATE_FILL_COLOR + ); + impl_createCircleShape( + pagePlayground.X + pagePlayground.Width - SMALL_CIRCLE_SIZE, + pagePlayground.Y + pagePlayground.Height - SMALL_CIRCLE_SIZE, + SMALL_CIRCLE_SIZE, + ALTERNATE_FILL_COLOR + ); + return 4; + } + + private void impl_createCircleShape( final int i_x, final int i_y, final int i_size, final int i_color ) throws com.sun.star.uno.Exception + { + final XPropertySet shapeProps = getDocument().createInstance( "com.sun.star.drawing.EllipseShape", XPropertySet.class ); + shapeProps.setPropertyValue( "CircleKind", CIRCLE_TYPE ); + shapeProps.setPropertyValue( "FillColor", i_color ); + + final XShape shape = UnoRuntime.queryInterface( XShape.class, shapeProps ); + final Size shapeSize = new Size( i_size, i_size ); + shape.setSize( shapeSize ); + final Point shapePos = new Point( i_x, i_y ); + shape.setPosition( shapePos ); + + final XShapes pageShapes = UnoRuntime.queryInterface( XShapes.class, getFirstPageShapes() ); + pageShapes.add( shape ); + + // Sadly, Draw/Impress currently do not create Undo actions for programmatic changes to the document. + // Which renders the test here slightly useless ... unless we fake the Undo actions ourself. + final XUndoManagerSupplier suppUndoManager = UnoRuntime.queryInterface( XUndoManagerSupplier.class, getDocument().getDocument() ); + final XUndoManager undoManager = suppUndoManager.getUndoManager(); + undoManager.addUndoAction( new ShapeInsertionUndoAction( shape, pageShapes ) ); + } + + private Rectangle impl_getFirstPagePlayground() throws com.sun.star.uno.Exception + { + final XShapes firstPageShapes = getFirstPageShapes(); + final XPropertySet firstPageProps = UnoRuntime.queryInterface( XPropertySet.class, firstPageShapes ); + final int pageWidth = ((Integer)firstPageProps.getPropertyValue( "Width" )).intValue(); + final int pageHeight = ((Integer)firstPageProps.getPropertyValue( "Height" )).intValue(); + final int borderLeft = ((Integer)firstPageProps.getPropertyValue( "BorderLeft" )).intValue(); + final int borderTop = ((Integer)firstPageProps.getPropertyValue( "BorderTop" )).intValue(); + final int borderRight = ((Integer)firstPageProps.getPropertyValue( "BorderRight" )).intValue(); + final int borderBottom = ((Integer)firstPageProps.getPropertyValue( "BorderBottom" )).intValue(); + return new Rectangle( borderLeft, borderTop, pageWidth - borderLeft - borderRight, pageHeight - borderTop - borderBottom ); + } + + /** + * returns the XShapes interface of the first page of our drawing document + */ + private XShapes getFirstPageShapes() throws com.sun.star.uno.Exception + { + final XDrawPagesSupplier suppPages = UnoRuntime.queryInterface( XDrawPagesSupplier.class, getDocument().getDocument() ); + final XDrawPages pages = suppPages.getDrawPages(); + return UnoRuntime.queryInterface( XShapes.class, pages.getByIndex( 0 ) ); + } + + /** + * verifies the given shape has the given size + */ + private void verifyShapeGeometry( final Object i_shapeObject, final int i_expectedWidth, final int i_expectedHeight ) + { + final XShape shape = UnoRuntime.queryInterface( XShape.class, i_shapeObject ); + final Size shapeSize = shape.getSize(); + assertEquals( "unexpected shape width", i_expectedWidth, shapeSize.Width ); + assertEquals( "unexpected shape height", i_expectedHeight, shapeSize.Height ); + } + + private static class ShapeInsertionUndoAction implements XUndoAction + { + ShapeInsertionUndoAction( final XShape i_shape, final XShapes i_shapeCollection ) + { + m_shape = i_shape; + m_shapeCollection = i_shapeCollection; + } + + public String getTitle() + { + return "insert shape"; + } + + public void undo() + { + m_shapeCollection.remove( m_shape ); + } + + public void redo() + { + m_shapeCollection.add( m_shape ); + } + + private final XShape m_shape; + private final XShapes m_shapeCollection; + } + + private static CircleKind CIRCLE_TYPE = CircleKind.FULL; + private static int FILL_COLOR = 0xCC2244; + private static int ALTERNATE_FILL_COLOR = 0x44CC22; + private static int BIG_CIRCLE_SIZE = 5000; + private static int SMALL_CIRCLE_SIZE = 2000; +} diff --git a/sfx2/qa/complex/sfx2/undo/ImpressDocumentTest.java b/sfx2/qa/complex/sfx2/undo/ImpressDocumentTest.java new file mode 100644 index 000000000..8f9cb5771 --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/ImpressDocumentTest.java @@ -0,0 +1,35 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import com.sun.star.lang.XMultiServiceFactory; +import org.openoffice.test.tools.DocumentType; + +public class ImpressDocumentTest extends DrawingOrPresentationDocumentTest +{ + public ImpressDocumentTest( XMultiServiceFactory i_orb ) throws com.sun.star.uno.Exception + { + super( i_orb, DocumentType.PRESENTATION ); + } + + public String getDocumentDescription() + { + return "presentation document"; + } +} diff --git a/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java b/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java new file mode 100644 index 000000000..624c2d7d2 --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java @@ -0,0 +1,121 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package complex.sfx2.undo; + +import com.sun.star.text.XTextRange; +import com.sun.star.beans.XPropertySet; +import com.sun.star.table.XCell; +import com.sun.star.table.XCellRange; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextTable; +import com.sun.star.text.XText; +import com.sun.star.text.XTextDocument; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import org.openoffice.test.tools.DocumentType; +import static org.junit.Assert.*; + +/** + * implements the {@link DocumentTest} interface on top of a spreadsheet document + */ +public class WriterDocumentTest extends DocumentTestBase +{ + public WriterDocumentTest( final XMultiServiceFactory i_orb ) throws com.sun.star.uno.Exception + { + super( i_orb, DocumentType.WRITER ); + } + + public String getDocumentDescription() + { + return "text document"; + } + + public void initializeDocument() throws com.sun.star.uno.Exception + { + // TODO? + } + + public void doSingleModification() throws com.sun.star.uno.Exception + { + final XTextDocument textDoc = UnoRuntime.queryInterface( XTextDocument.class, getDocument().getDocument() ); + final XText docText = textDoc.getText(); + docText.setString( s_blindText ); + } + + public void verifyInitialDocumentState() throws com.sun.star.uno.Exception + { + final XTextDocument textDoc = UnoRuntime.queryInterface( XTextDocument.class, getDocument().getDocument() ); + final XText docText = textDoc.getText(); + assertEquals( "document should be empty", "", docText.getString() ); + } + + public void verifySingleModificationDocumentState() throws com.sun.star.uno.Exception + { + final XTextDocument textDoc = UnoRuntime.queryInterface( XTextDocument.class, getDocument().getDocument() ); + final XText docText = textDoc.getText(); + assertEquals( "blind text not found", s_blindText, docText.getString() ); + } + + public int doMultipleModifications() throws com.sun.star.uno.Exception + { + final XTextDocument textDoc = UnoRuntime.queryInterface( XTextDocument.class, getDocument().getDocument() ); + final XText docText = textDoc.getText(); + + int expectedUndoActions = 0; + + // create a cursor + final XTextCursor cursor = docText.createTextCursor(); + + // create a table + final XTextTable textTable = UnoRuntime.queryInterface( XTextTable.class, + getDocument().createInstance( "com.sun.star.text.TextTable" ) ); + textTable.initialize( 3, 3 ); + final XPropertySet tableProps = UnoRuntime.queryInterface( XPropertySet.class, textTable ); + tableProps.setPropertyValue( "BackColor", 0xCCFF44 ); + + // insert the table into the doc + docText.insertTextContent( cursor, textTable, false ); + ++expectedUndoActions; //FIXME this will create 2 actions! currently the event is sent for every individual action; should it be sent for top-level actions only? how many internal actions are created is an implementation detail! + ++expectedUndoActions; + + // write some content into the center cell + final XCellRange cellRange = UnoRuntime.queryInterface( XCellRange.class, textTable ); + final XCell centerCell = cellRange.getCellByPosition( 1, 1 ); + final XTextRange cellText = UnoRuntime.queryInterface( XTextRange.class, centerCell ); + cellText.setString( "Undo Manager API Test" ); + ++expectedUndoActions; + + // give it another color + final XPropertySet cellProps = UnoRuntime.queryInterface( XPropertySet.class, centerCell ); + cellProps.setPropertyValue( "BackColor", 0x44CCFF ); + ++expectedUndoActions; + + return expectedUndoActions; + } + + private static final String s_blindText = + "Lorem ipsum dolor. Sit amet penatibus. A cum turpis. Aenean ac eu. " + + "Ligula est urna nulla vestibulum ullamcorper. Nec sit in amet tincidunt mus. " + + "Tellus sagittis mi. Suscipit cursus in vestibulum in eros ipsum felis cursus lectus " + + "nunc quis condimentum in risus nec wisi aenean luctus hendrerit magna habitasse commodo orci. " + + "Nisl etiam quis. Vestibulum justo eleifend aliquet luctus sed turpis volutpat ullamcorper " + + "aliquam penatibus sagittis pede tincidunt egestas. Nibh massa lectus. Sem mattis purus morbi " + + "scelerisque turpis donec urna phasellus. Quis at lacus. Viverra mauris mollis. " + + "Dolor tincidunt condimentum."; +} |