summaryrefslogtreecommitdiff
path: root/sfx2/qa/complex
diff options
context:
space:
mode:
authorFrank Schoenheit [fs] <frank.schoenheit@sun.com>2010-10-21 13:51:14 +0200
committerFrank Schoenheit [fs] <frank.schoenheit@sun.com>2010-10-21 13:51:14 +0200
commit17bdbe63b4927237df7fe0270bb673b75d5d535a (patch)
tree7513d5ba398d59906d1e430381dc4c8c6dbf48ce /sfx2/qa/complex
parent9d30575ba6c67b4383461ef44ed9b2aae266aa3c (diff)
undoapi: implement a test backend for Writer. Not fully integrated into the test framework, yet, since Writer does not yet support XUndoManager/Supplier
Diffstat (limited to 'sfx2/qa/complex')
-rwxr-xr-xsfx2/qa/complex/sfx2/UndoManager.java32
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/WriterDocumentTest.java103
2 files changed, 131 insertions, 4 deletions
diff --git a/sfx2/qa/complex/sfx2/UndoManager.java b/sfx2/qa/complex/sfx2/UndoManager.java
index 7e5c231da91c..6c200ca96a95 100755
--- a/sfx2/qa/complex/sfx2/UndoManager.java
+++ b/sfx2/qa/complex/sfx2/UndoManager.java
@@ -43,6 +43,7 @@ import com.sun.star.util.InvalidStateException;
import complex.sfx2.undo.DocumentTest;
import complex.sfx2.undo.DrawDocumentTest;
import complex.sfx2.undo.ImpressDocumentTest;
+import complex.sfx2.undo.WriterDocumentTest;
import java.util.Stack;
import org.junit.After;
import org.junit.AfterClass;
@@ -66,21 +67,27 @@ public class UndoManager
}
@Test
+ public void checkWriterUndo() throws Exception
+ {
+ impl_checkUndo( WriterDocumentTest.class, true );
+ }
+
+ @Test
public void checkCalcUndo() throws Exception
{
- impl_checkUndo( CalcDocumentTest.class );
+ impl_checkUndo( CalcDocumentTest.class, false );
}
@Test
public void checkDrawUndo() throws Exception
{
- impl_checkUndo( DrawDocumentTest.class );
+ impl_checkUndo( DrawDocumentTest.class, false );
}
@Test
public void checkImpressUndo() throws Exception
{
- impl_checkUndo( ImpressDocumentTest.class );
+ impl_checkUndo( ImpressDocumentTest.class, false );
}
@After
@@ -197,7 +204,7 @@ public class UndoManager
private String m_mostRecentlyRedone = null;
};
- private void impl_checkUndo( final Class i_testClass ) throws Exception
+ private void impl_checkUndo( final Class i_testClass, final boolean i_fakeTestForNow ) throws Exception
{
final Constructor ctor = i_testClass.getConstructor( XMultiServiceFactory.class );
final DocumentTest test = (DocumentTest)ctor.newInstance( getORB() );
@@ -206,6 +213,23 @@ public class UndoManager
test.initializeDocument();
test.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();
+ for ( int i=0; i<expectedUndoSteps; ++i )
+ test.getDocument().getCurrentView().dispatch( ".uno:Undo" );
+ test.verifyInitialDocumentState();
+ test.getDocument().close();
+ return;
+ }
+
final XUndoManager undoManager = getUndoManager( test.getDocument() );
undoManager.clear();
assertFalse( "clearing the Undo manager should result in the impossibility to undo anything", undoManager.isUndoPossible() );
diff --git a/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java b/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java
new file mode 100755
index 000000000000..100d36382d39
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java
@@ -0,0 +1,103 @@
+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
+ * @author frank.schoenheit@oracle.com
+ */
+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;
+
+ // 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.";
+}