diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-10-19 13:11:25 +0200 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-10-19 13:11:25 +0200 |
commit | 870b17d7ed1397a48ad8699cdaa1847af2344911 (patch) | |
tree | e5dd605b8aed5435112bf438c010f3d5ea67d306 /sfx2/qa | |
parent | 44539872f4525cd7cb104eed0ad63d3f5ca6b212 (diff) |
undoapi: test backend for Impress (doing the same as the Draw test backend)
Diffstat (limited to 'sfx2/qa')
-rwxr-xr-x | sfx2/qa/complex/sfx2/UndoManager.java | 7 | ||||
-rwxr-xr-x | sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java | 204 | ||||
-rwxr-xr-x | sfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java | 196 | ||||
-rwxr-xr-x | sfx2/qa/complex/sfx2/undo/ImpressDocumentTest.java | 46 |
4 files changed, 275 insertions, 178 deletions
diff --git a/sfx2/qa/complex/sfx2/UndoManager.java b/sfx2/qa/complex/sfx2/UndoManager.java index c54697927825..21433cd07336 100755 --- a/sfx2/qa/complex/sfx2/UndoManager.java +++ b/sfx2/qa/complex/sfx2/UndoManager.java @@ -40,6 +40,7 @@ import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import complex.sfx2.undo.DocumentTest; import complex.sfx2.undo.DrawDocumentTest; +import complex.sfx2.undo.ImpressDocumentTest; import java.util.Stack; import org.junit.After; import org.junit.AfterClass; @@ -74,6 +75,12 @@ public class UndoManager impl_checkUndo( DrawDocumentTest.class ); } + @Test + public void checkImpressUndo() throws Exception + { + impl_checkUndo( ImpressDocumentTest.class ); + } + @After public void afterTest() { diff --git a/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java b/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java index cf0d06d3163e..d98e1372dea5 100755 --- a/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java +++ b/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.java @@ -1,32 +1,38 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ +/************************************************************************* + * 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.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 * @author frank.schoenheit@oracle.com */ -public class DrawDocumentTest extends DocumentTestBase +public class DrawDocumentTest extends DrawingOrPresentationDocumentTest { public DrawDocumentTest( XMultiServiceFactory i_orb ) throws com.sun.star.uno.Exception { @@ -37,162 +43,4 @@ public class DrawDocumentTest extends DocumentTestBase { return "drawing document"; } - - public void initializeDocument() throws com.sun.star.uno.Exception - { - // no special initializations needed here - } - - 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 no shapes at all", 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 tpye", 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 ) - throws com.sun.star.uno.Exception - { - 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/DrawingOrPresentationDocumentTest.java b/sfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java new file mode 100755 index 000000000000..916e1908e93d --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java @@ -0,0 +1,196 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +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 + * @author frank.schoenheit@oracle.com + */ +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 tpye", 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 ) + throws com.sun.star.uno.Exception + { + 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 100755 index 000000000000..c15fc760e0c3 --- /dev/null +++ b/sfx2/qa/complex/sfx2/undo/ImpressDocumentTest.java @@ -0,0 +1,46 @@ +/************************************************************************* + * 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.sfx2.undo; + +import com.sun.star.lang.XMultiServiceFactory; +import org.openoffice.test.tools.DocumentType; + +/** + * @author frank.schoenheit@oracle.com + */ +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"; + } +} |