summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsfx2/qa/complex/sfx2/UndoManager.java78
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/ChartDocumentTest.java272
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DocumentTest.java5
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DocumentTestBase.java5
4 files changed, 328 insertions, 32 deletions
diff --git a/sfx2/qa/complex/sfx2/UndoManager.java b/sfx2/qa/complex/sfx2/UndoManager.java
index a99d70836ad4..545e3d6fd6b6 100755
--- a/sfx2/qa/complex/sfx2/UndoManager.java
+++ b/sfx2/qa/complex/sfx2/UndoManager.java
@@ -51,11 +51,9 @@ import com.sun.star.document.XUndoAction;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.XEventListener;
-import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.openoffice.test.tools.OfficeDocument;
import com.sun.star.document.XUndoManagerSupplier;
-import complex.sfx2.undo.CalcDocumentTest;
import com.sun.star.document.XUndoManager;
import com.sun.star.document.XUndoManagerListener;
import com.sun.star.drawing.XControlShape;
@@ -77,6 +75,8 @@ import com.sun.star.uno.XComponentContext;
import com.sun.star.util.InvalidStateException;
import com.sun.star.util.NotLockedException;
import com.sun.star.view.XControlAccess;
+import complex.sfx2.undo.CalcDocumentTest;
+import complex.sfx2.undo.ChartDocumentTest;
import complex.sfx2.undo.DocumentTest;
import complex.sfx2.undo.DrawDocumentTest;
import complex.sfx2.undo.ImpressDocumentTest;
@@ -106,6 +106,7 @@ public class UndoManager
@Before
public void beforeTest() throws com.sun.star.uno.Exception
{
+ m_currentTestCase = null;
m_currentDocument = null;
m_undoListener = null;
@@ -118,35 +119,47 @@ public class UndoManager
}
// -----------------------------------------------------------------------------------------------------------------
- @Test
+// @Test
public void checkWriterUndo() throws Exception
{
- impl_checkUndo( WriterDocumentTest.class, true );
+ m_currentTestCase = new WriterDocumentTest( getORB() );
+ impl_checkUndo( true );
}
// -----------------------------------------------------------------------------------------------------------------
- @Test
+// @Test
public void checkCalcUndo() throws Exception
{
- impl_checkUndo( CalcDocumentTest.class, false );
+ m_currentTestCase = new CalcDocumentTest( getORB() );
+ impl_checkUndo( false );
}
// -----------------------------------------------------------------------------------------------------------------
- @Test
+// @Test
public void checkDrawUndo() throws Exception
{
- impl_checkUndo( DrawDocumentTest.class, false );
+ m_currentTestCase = new DrawDocumentTest( getORB() );
+ impl_checkUndo( false );
}
// -----------------------------------------------------------------------------------------------------------------
- @Test
+// @Test
public void checkImpressUndo() throws Exception
{
- impl_checkUndo( ImpressDocumentTest.class, false );
+ m_currentTestCase = new ImpressDocumentTest( getORB() );
+ impl_checkUndo( false );
}
// -----------------------------------------------------------------------------------------------------------------
@Test
+ public void checkChartUndo() throws Exception
+ {
+ m_currentTestCase = new ChartDocumentTest( getORB() );
+ impl_checkUndo( false );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+// @Test
public void checkBrokenScripts() throws com.sun.star.uno.Exception, InterruptedException
{
System.out.println( "testing: broken scripts" );
@@ -226,7 +239,7 @@ public class UndoManager
}
// -----------------------------------------------------------------------------------------------------------------
- @Test
+// @Test
public void checkSerialization() throws com.sun.star.uno.Exception, InterruptedException
{
System.out.println( "testing: request serialization" );
@@ -282,7 +295,9 @@ public class UndoManager
@After
public void afterTest()
{
- if ( m_currentDocument != null )
+ if ( m_currentTestCase != null )
+ m_currentTestCase.closeDocument();
+ else if ( m_currentDocument != null )
m_currentDocument.close();
m_callbackFactory.dispose();
}
@@ -598,29 +613,27 @@ public class UndoManager
};
// -----------------------------------------------------------------------------------------------------------------
- private void impl_checkUndo( final Class i_testClass, final boolean i_fakeTestForNow ) throws Exception
+ private void impl_checkUndo( final boolean i_fakeTestForNow ) throws Exception
{
- final Constructor ctor = i_testClass.getConstructor( XMultiServiceFactory.class );
- final DocumentTest test = (DocumentTest)ctor.newInstance( getORB() );
- System.out.println( "testing: " + test.getDocumentDescription() );
- m_currentDocument = test.getDocument();
- test.initializeDocument();
- test.verifyInitialDocumentState();
+ System.out.println( "testing: " + m_currentTestCase.getDocumentDescription() );
+ m_currentDocument = m_currentTestCase.getDocument();
+ m_currentTestCase.initializeDocument();
+ m_currentTestCase.verifyInitialDocumentState();
if ( i_fakeTestForNow )
{
// Writer does not yet have an UndoManager in the current phase of the implementation. Once it has, we
// this complete branch, which barely tests anything (except perhaps the DocumentTest implementation),
// can vanish.
- test.doSingleModification();
- test.verifySingleModificationDocumentState();
- test.getDocument().getCurrentView().dispatch( ".uno:Undo" );
- test.verifyInitialDocumentState();
- final int expectedUndoSteps = test.doMultipleModifications();
+ m_currentTestCase.doSingleModification();
+ m_currentTestCase.verifySingleModificationDocumentState();
+ m_currentTestCase.getDocument().getCurrentView().dispatch( ".uno:Undo" );
+ m_currentTestCase.verifyInitialDocumentState();
+ final int expectedUndoSteps = m_currentTestCase.doMultipleModifications();
for ( int i=0; i<expectedUndoSteps; ++i )
- test.getDocument().getCurrentView().dispatch( ".uno:Undo" );
- test.verifyInitialDocumentState();
- test.getDocument().close();
+ m_currentTestCase.getDocument().getCurrentView().dispatch( ".uno:Undo" );
+ m_currentTestCase.verifyInitialDocumentState();
+ m_currentTestCase.getDocument().close();
return;
}
@@ -632,12 +645,12 @@ public class UndoManager
m_undoListener = new UndoListener();
undoManager.addUndoManagerListener( m_undoListener );
- impl_testSingleModification( test, undoManager );
- impl_testMultipleModifications( test, undoManager );
- impl_testCustomUndoActions( test, undoManager );
- impl_testLocking( test, undoManager );
+ impl_testSingleModification( m_currentTestCase, undoManager );
+ impl_testMultipleModifications( m_currentTestCase, undoManager );
+ impl_testCustomUndoActions( m_currentTestCase, undoManager );
+ impl_testLocking( m_currentTestCase, undoManager );
impl_testNestedContexts( undoManager );
- impl_testErrorHandling( test, undoManager );
+ impl_testErrorHandling( m_currentTestCase, undoManager );
impl_testContextHandling( undoManager );
impl_testStackHandling( undoManager );
impl_testClearance( undoManager );
@@ -1442,6 +1455,7 @@ public class UndoManager
}
private static final OfficeConnection m_connection = new OfficeConnection();
+ private DocumentTest m_currentTestCase;
private OfficeDocument m_currentDocument;
private UndoListener m_undoListener;
private CallbackComponentFactory m_callbackFactory = null;
diff --git a/sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java b/sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java
new file mode 100755
index 000000000000..787272d69a45
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java
@@ -0,0 +1,272 @@
+/*************************************************************************
+ * 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.Size;
+import com.sun.star.beans.NamedValue;
+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.VerbDescriptor;
+import com.sun.star.embed.WrongStateException;
+import com.sun.star.embed.XEmbeddedObject;
+import com.sun.star.embed.XStateChangeBroadcaster;
+import com.sun.star.embed.XStateChangeListener;
+import com.sun.star.lang.EventObject;
+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.*;
+
+/**
+ * @author frank.schoenheit@oracle.com
+ */
+public class ChartDocumentTest implements DocumentTest
+{
+ public ChartDocumentTest( final XMultiServiceFactory i_orb ) throws com.sun.star.uno.Exception, InterruptedException
+ {
+ m_textDocument = OfficeDocument.blankDocument( i_orb, DocumentType.WRITER );
+
+ // create a 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" ) );
+ m_chartDocument = new OfficeDocument( i_orb, chartDoc );
+
+ final XEmbeddedObject embeddedChart = UnoRuntime.queryInterface( XEmbeddedObject.class,
+ shapeProps.getPropertyValue( "EmbeddedObject" ) );
+ final XStateChangeBroadcaster stateBroadcaster = UnoRuntime.queryInterface( XStateChangeBroadcaster.class, embeddedChart );
+ stateBroadcaster.addStateChangeListener( new ChartStateListener() );
+
+ // activate the chart
+ selSupplier.select( shape );
+
+ // some Writer-internal processes, which are a pre-condition for being able to successfully dispatch
+ // the ObjectMenu command, run asynchronously, without a chance of being notified when they're finished :(
+ // So, wait a little, again ...
+ synchronized ( embeddedChart ) { embeddedChart.wait( 500 ); }
+ // ... and check if those processes are finished
+ final VerbDescriptor[] verbs = embeddedChart.getSupportedVerbs();
+ boolean canActivate = true;
+ for ( int i=0; i<verbs.length && !canActivate; ++i )
+ if ( verbs[i].VerbID == EmbedVerbs.MS_OLEVERB_SHOW )
+ canActivate = true;
+ assertTrue( "cannot activate OLE object", canActivate );
+
+ // actually
+ m_textDocument.getCurrentView().dispatch( ".uno:ObjectMenue", new NamedValue[] { new NamedValue( "VerbID", EmbedVerbs.MS_OLEVERB_SHOW ) } );
+
+ // the dispatch happens asynchronously, so wait a little (at most 1 seconds) until the chart really has been activated
+ synchronized ( m_chartActivatedCondition ) { m_chartActivatedCondition.wait( 1000 ); }
+ 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
+ {
+ // TODO?
+ }
+
+ public void closeDocument()
+ {
+ m_textDocument.close();
+ }
+
+ public void doSingleModification() throws com.sun.star.uno.Exception
+ {
+ final XChartDocument chartDoc = UnoRuntime.queryInterface( XChartDocument.class, m_chartDocument.getDocument() );
+ final XDiagram diagram = chartDoc.getFirstDiagram();
+ final XPropertySet wallProperties = diagram.getWall();
+
+ // simulate an Undo action, as long as the chart implementation doesn't add Undo actions itself
+ final XUndoManagerSupplier undoManagerSupp = UnoRuntime.queryInterface( XUndoManagerSupplier.class, m_chartDocument.getDocument() );
+ final XUndoManager undoManager = undoManagerSupp.getUndoManager();
+ undoManager.addUndoAction( new PropertyUndoAction( wallProperties, "FillColor", 0xCCFF44 ) );
+ }
+
+ public void verifyInitialDocumentState() throws com.sun.star.uno.Exception
+ {
+ // TODO
+ }
+
+ public void verifySingleModificationDocumentState() throws com.sun.star.uno.Exception
+ {
+ // TODO
+ }
+
+ public int doMultipleModifications() throws com.sun.star.uno.Exception
+ {
+ // TODO
+ return 0;
+ }
+
+ 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 class ChartStateListener implements XStateChangeListener
+ {
+ public void changingState( EventObject i_event, int i_oldState, int i_newState ) throws WrongStateException
+ {
+ }
+
+ public void stateChanged( EventObject i_event, int i_oldState, int i_newState )
+ {
+ if ( i_newState != EmbedStates.UI_ACTIVE )
+ return;
+ synchronized ( m_chartActivatedCondition )
+ {
+ m_chartActivatedCondition.notifyAll();
+ }
+ }
+
+ public void disposing( EventObject i_event ) { }
+ };
+
+ private final OfficeDocument m_textDocument;
+ private final OfficeDocument m_chartDocument;
+ private final Object m_chartActivatedCondition = new Object();
+}
diff --git a/sfx2/qa/complex/sfx2/undo/DocumentTest.java b/sfx2/qa/complex/sfx2/undo/DocumentTest.java
index 431e64ab0197..d6de90884673 100755
--- a/sfx2/qa/complex/sfx2/undo/DocumentTest.java
+++ b/sfx2/qa/complex/sfx2/undo/DocumentTest.java
@@ -21,6 +21,11 @@ public interface DocumentTest
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
*/
diff --git a/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java b/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java
index 147ef587b3bc..11adc80c2e85 100755
--- a/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java
+++ b/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java
@@ -20,5 +20,10 @@ abstract class DocumentTestBase implements DocumentTest
return m_document;
}
+ public void closeDocument()
+ {
+ m_document.close();
+ }
+
protected final OfficeDocument m_document;
}