summaryrefslogtreecommitdiff
path: root/sfx2/qa
diff options
context:
space:
mode:
authorFrank Schoenheit [fs] <frank.schoenheit@sun.com>2010-10-15 23:39:05 +0200
committerFrank Schoenheit [fs] <frank.schoenheit@sun.com>2010-10-15 23:39:05 +0200
commit63f1445c73f54fe9adcc0c0cb0aae6c7e639c8a2 (patch)
tree390174096c3deb5647b5e81d85338a1b990cea55 /sfx2/qa
parent7c1bc8c31291669c2254592d7e30222a511d3a8a (diff)
undoapi: API and Impl tweaks
Diffstat (limited to 'sfx2/qa')
-rwxr-xr-xsfx2/qa/complex/sfx2/UndoManager.java39
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/CalcDocumentTest.java21
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DocumentTest.java8
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DocumentTestBase.java7
4 files changed, 58 insertions, 17 deletions
diff --git a/sfx2/qa/complex/sfx2/UndoManager.java b/sfx2/qa/complex/sfx2/UndoManager.java
index a78f93a1aca9..72bc34a7c6fe 100755
--- a/sfx2/qa/complex/sfx2/UndoManager.java
+++ b/sfx2/qa/complex/sfx2/UndoManager.java
@@ -120,7 +120,12 @@ public class UndoManager
public void leftUndoContext( UndoManagerEvent i_event )
{
- assertEquals( "undo context order is suspicious", m_activeUndoContexts.pop(), i_event.UndoActionTitle );
+ assertEquals( "nested undo context descriptions do not match", m_activeUndoContexts.pop(), i_event.UndoActionTitle );
+ }
+
+ public void disposing( EventObject i_event )
+ {
+ m_isDisposed = true;
}
int getUndoActionsAdded() { return m_undoActionsAdded; }
@@ -128,6 +133,7 @@ public class UndoManager
int getRedoActionCount() { return m_redoCount; }
String getCurrentUndoContextTitle() { return m_activeUndoContexts.peek(); }
int getUndoContextDepth() { return m_activeUndoContexts.size(); }
+ boolean isDisposed() { return m_isDisposed; }
void reset()
{
@@ -138,6 +144,7 @@ public class UndoManager
private int m_undoActionsAdded = 0;
private int m_undoCount = 0;
private int m_redoCount = 0;
+ private boolean m_isDisposed = false;
private Stack< String >
m_activeUndoContexts = new Stack<String>();
};
@@ -156,12 +163,32 @@ public class UndoManager
final UndoListener listener = new UndoListener();
undoManager.addUndoManagerListener( listener );
- // do a single modification, undo it, and check the document state is as expected
+ // do a single modification to the document
test.doSingleModification();
+ test.verifySingleModificationDocumentState();
+
+ // undo the modification, ensure the listener got the proper notifications
+ assertEquals( "We did not yet do a undo!", 0, listener.getUndoActionCount() );
undoManager.undo();
- test.verifyInitialDocumentState();
- // ensure the listener has been notified of the Undo operation
assertEquals( "A simple undo does not result in the proper Undo count.", 1, listener.getUndoActionCount() );
+
+ // verify the document is in its initial state, again
+ test.verifyInitialDocumentState();
+
+ // redo the modification, ensure the listener got the proper notifications
+ assertEquals( "did not yet do a redo!", 0, listener.getRedoActionCount() );
+ undoManager.redo();
+ assertEquals( "did a redo, but got no notification of it!", 1, listener.getRedoActionCount() );
+
+ // ensure the document is in the proper state, again
+ test.verifySingleModificationDocumentState();
+
+ // now do an Undo via the UI (aka the dispatch API), and see if this works, and notifies the listener as
+ // expected
+ test.getDocument().getCurrentView().dispatch( ".uno:Undo" );
+ test.verifyInitialDocumentState();
+ assertEquals( "UI-Undo does not notify the listener", 2, listener.getUndoActionCount() );
+
listener.reset();
// do multiple changes in a row, after entering an Undo context
@@ -184,6 +211,10 @@ public class UndoManager
test.verifyInitialDocumentState();
listener.reset();
+
+ m_currentDocument.close();
+ assertTrue( "document is closed, but the UndoManagerListener has not been notified of the disposal", listener.isDisposed() );
+ m_currentDocument = null;
}
private XComponentContext getContext()
diff --git a/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java b/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java
index 03f2b3ade019..16d813bdaeb8 100755
--- a/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java
+++ b/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java
@@ -6,13 +6,13 @@ 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 org.openoffice.test.tools.OfficeDocument;
import static org.junit.Assert.*;
/**
+ * implements the {@link DocumentTest} interface on top of a spreadsheet document
* @author frank.schoenheit@oracle.com
*/
-public class CalcDocumentTest extends DocumentTestBase implements DocumentTest
+public class CalcDocumentTest extends DocumentTestBase
{
public CalcDocumentTest( final XMultiServiceFactory i_orb ) throws Exception
{
@@ -43,15 +43,15 @@ public class CalcDocumentTest extends DocumentTestBase implements DocumentTest
public void doSingleModification() throws com.sun.star.uno.Exception
{
final XCell cellA1 = getCellA1();
- assertEquals( "initial cell value not as expected", cellA1.getValue(), INIT_VALUE, 0 );
+ assertEquals( "initial cell value not as expected", INIT_VALUE, cellA1.getValue(), 0 );
cellA1.setValue( MODIFIED_VALUE );
- assertEquals( "modified cell value not as expected", cellA1.getValue(), MODIFIED_VALUE, 0 );
+ 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 didn't restore its value", cellA1.getValue(), INIT_VALUE, 0 );
+ assertEquals( "cell A1 didn't restore its value", INIT_VALUE, cellA1.getValue(), 0 );
XCellRange range = UnoRuntime.queryInterface( XCellRange.class,
((SpreadsheetDocument)m_document).getSheet(0) );
@@ -62,6 +62,12 @@ public class CalcDocumentTest extends DocumentTestBase implements DocumentTest
}
}
+ 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,
@@ -78,11 +84,6 @@ public class CalcDocumentTest extends DocumentTestBase implements DocumentTest
return 12;
}
- public OfficeDocument getDocument()
- {
- return m_document;
- }
-
private XCell getCellA1() throws com.sun.star.uno.Exception
{
XCellRange range = UnoRuntime.queryInterface( XCellRange.class,
diff --git a/sfx2/qa/complex/sfx2/undo/DocumentTest.java b/sfx2/qa/complex/sfx2/undo/DocumentTest.java
index f9339c8146b9..431e64ab0197 100755
--- a/sfx2/qa/complex/sfx2/undo/DocumentTest.java
+++ b/sfx2/qa/complex/sfx2/undo/DocumentTest.java
@@ -1,7 +1,5 @@
package complex.sfx2.undo;
-import com.sun.star.document.XUndoAction;
-import com.sun.star.document.XUndoManager;
import org.openoffice.test.tools.OfficeDocument;
/**
@@ -34,6 +32,12 @@ public interface DocumentTest
public void verifyInitialDocumentState() throws com.sun.star.uno.Exception;
/**
+ * verifies the document is in the state as expected after {@link #doSingleModification}
+ * @throws com.sun.star.uno.Exception
+ */
+ 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 XUndoManager.enterUndoContext()} and
diff --git a/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java b/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java
index ba895973a2dc..147ef587b3bc 100755
--- a/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java
+++ b/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java
@@ -8,12 +8,17 @@ import org.openoffice.test.tools.OfficeDocument;
/**
* @author frank.schoenheit@oracle.com
*/
-class DocumentTestBase
+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;
+ }
+
protected final OfficeDocument m_document;
}