summaryrefslogtreecommitdiff
path: root/sfx2/qa
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/qa')
-rw-r--r--sfx2/qa/complex/sfx2/DocumentInfo.java (renamed from sfx2/qa/complex/docinfo/DocumentProperties.java)19
-rw-r--r--sfx2/qa/complex/sfx2/DocumentMetadataAccess.java (renamed from sfx2/qa/complex/framework/DocumentMetadataAccessTest.java)201
-rw-r--r--sfx2/qa/complex/sfx2/DocumentProperties.java (renamed from sfx2/qa/complex/framework/DocumentPropertiesTest.java)34
-rw-r--r--sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java (renamed from sfx2/qa/complex/framework/CheckGlobalEventBroadcaster_writer1.java)14
-rw-r--r--sfx2/qa/complex/sfx2/StandaloneDocumentInfo.java (renamed from sfx2/qa/complex/standalonedocumentinfo/StandaloneDocumentInfoUnitTest.java)26
-rwxr-xr-xsfx2/qa/complex/sfx2/UndoManager.java1464
-rw-r--r--sfx2/qa/complex/sfx2/makefile.mk84
-rw-r--r--sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest.java (renamed from sfx2/qa/complex/standalonedocumentinfo/StandaloneDocumentInfoTest.java)2
-rw-r--r--sfx2/qa/complex/sfx2/standalonedocinfo/Test01.java (renamed from sfx2/qa/complex/standalonedocumentinfo/Test01.java)4
-rw-r--r--sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper.java (renamed from sfx2/qa/complex/standalonedocumentinfo/TestHelper.java)2
-rw-r--r--sfx2/qa/complex/sfx2/testdocuments/CUSTOM.odt (renamed from sfx2/qa/complex/framework/testdocuments/CUSTOM.odt)bin1021 -> 1021 bytes
-rw-r--r--sfx2/qa/complex/sfx2/testdocuments/TEST.odt (renamed from sfx2/qa/complex/framework/testdocuments/TEST.odt)bin13803 -> 13803 bytes
-rw-r--r--sfx2/qa/complex/sfx2/testdocuments/TESTRDFA.odt (renamed from sfx2/qa/complex/framework/testdocuments/TESTRDFA.odt)bin7540 -> 7540 bytes
-rw-r--r--sfx2/qa/complex/sfx2/testdocuments/empty.rdf (renamed from sfx2/qa/complex/framework/testdocuments/empty.rdf)0
-rw-r--r--sfx2/qa/complex/sfx2/tools/DialogThread.java (renamed from sfx2/qa/complex/framework/DialogThread.java)19
-rw-r--r--sfx2/qa/complex/sfx2/tools/TestDocument.java (renamed from sfx2/qa/complex/framework/TestDocument.java)4
-rw-r--r--sfx2/qa/complex/sfx2/tools/WriterHelper.java (renamed from sfx2/qa/complex/framework/WriterHelper.java)34
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/CalcDocumentTest.java96
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/ChartDocumentTest.java277
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DocumentTest.java61
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DocumentTestBase.java29
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DrawDocumentTest.java46
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/DrawingOrPresentationDocumentTest.java196
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/ImpressDocumentTest.java46
-rwxr-xr-xsfx2/qa/complex/sfx2/undo/WriterDocumentTest.java104
-rw-r--r--sfx2/qa/complex/tests.sce3
26 files changed, 2581 insertions, 184 deletions
diff --git a/sfx2/qa/complex/docinfo/DocumentProperties.java b/sfx2/qa/complex/sfx2/DocumentInfo.java
index 0c4eb44c4a35..ca7ae8b1dda0 100644
--- a/sfx2/qa/complex/docinfo/DocumentProperties.java
+++ b/sfx2/qa/complex/sfx2/DocumentInfo.java
@@ -24,9 +24,9 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.docinfo;
+package complex.sfx2;
-import com.sun.star.beans.*;
+import com.sun.star.beans.PropertyAttribute;
import com.sun.star.beans.Property;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertyContainer;
@@ -49,22 +49,17 @@ import util.WriterTools;
import org.junit.After;
import org.junit.AfterClass;
-// import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openoffice.test.OfficeConnection;
import static org.junit.Assert.*;
-public class DocumentProperties
+public class DocumentInfo
{
-
XMultiServiceFactory m_xMSF = null;
XTextDocument xTextDoc = null;
XTextDocument xTextDocSecond = null;
-// public String[] getTestMethodNames() {
-// return new String[] {"checkDocInfo", "cleanup"};
-// }
@Test public void checkDocInfo()
{
m_xMSF = getMSF();
@@ -349,14 +344,18 @@ public class DocumentProperties
// setup and close connections
@BeforeClass public static void setUpConnection() throws Exception
{
- System.out.println("setUpConnection()");
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "starting class: " + DocumentInfo.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.setUp();
}
@AfterClass public static void tearDownConnection()
throws InterruptedException, com.sun.star.uno.Exception
{
- System.out.println("tearDownConnection()");
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "finishing class: " + DocumentInfo.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.tearDown();
}
private static final OfficeConnection connection = new OfficeConnection();
diff --git a/sfx2/qa/complex/framework/DocumentMetadataAccessTest.java b/sfx2/qa/complex/sfx2/DocumentMetadataAccess.java
index 3f61cb21b3dd..d145b9028473 100644
--- a/sfx2/qa/complex/framework/DocumentMetadataAccessTest.java
+++ b/sfx2/qa/complex/sfx2/DocumentMetadataAccess.java
@@ -25,9 +25,27 @@
*
************************************************************************/
-package complex.framework;
+package complex.sfx2;
// import complexlib.ComplexTestCase;
+import com.sun.star.beans.Pair;
+import com.sun.star.rdf.Literal;
+import com.sun.star.rdf.XLiteral;
+import com.sun.star.rdf.XNamedGraph;
+import com.sun.star.rdf.BlankNode;
+import com.sun.star.rdf.XQuerySelectResult;
+import com.sun.star.rdf.XNode;
+import com.sun.star.rdf.XDocumentRepository;
+import com.sun.star.rdf.XMetadatable;
+import com.sun.star.rdf.Statement;
+import com.sun.star.rdf.FileFormat;
+import com.sun.star.rdf.URIs;
+import com.sun.star.rdf.URI;
+import com.sun.star.rdf.XDocumentMetadataAccess;
+import com.sun.star.rdf.XRepositorySupplier;
+import com.sun.star.rdf.XRepository;
+import com.sun.star.rdf.XBlankNode;
+import com.sun.star.rdf.XURI;
import helper.StreamSimulator;
import com.sun.star.uno.UnoRuntime;
@@ -41,7 +59,6 @@ import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.WrappedTargetRuntimeException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.PropertyValue;
-import com.sun.star.beans.Pair;
import com.sun.star.beans.StringPair;
import com.sun.star.container.XEnumerationAccess;
import com.sun.star.container.XEnumeration;
@@ -51,7 +68,7 @@ import com.sun.star.frame.XStorable;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XText;
-import com.sun.star.rdf.*;
+import complex.sfx2.tools.TestDocument;
import lib.TestParameters;
@@ -73,7 +90,7 @@ import static org.junit.Assert.*;
*
* @author mst
*/
-public class DocumentMetadataAccessTest
+public class DocumentMetadataAccess
{
XMultiServiceFactory xMSF;
XComponentContext xContext;
@@ -196,22 +213,22 @@ public class DocumentMetadataAccessTest
PropertyValue[] loadProps = new PropertyValue[1];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "Hidden";
- loadProps[0].Value = new Boolean(true);
+ loadProps[0].Value = true;
xComp = util.DesktopTools.openNewDoc(xMSF, "swriter", loadProps);
XTextDocument xText = UnoRuntime.queryInterface(XTextDocument.class, xComp);
- XRepositorySupplier xRS = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
- assertNotNull("xRS null", xRS);
- XDocumentMetadataAccess xDMA = UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xRS);
- assertNotNull("xDMA null", xDMA);
- xRep = xRS.getRDFRepository();
+ XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
+ assertNotNull("xRS null", xRepoSupplier);
+ XDocumentMetadataAccess xDocMDAccess = UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xRepoSupplier);
+ assertNotNull("xDMA null", xDocMDAccess);
+ xRep = xRepoSupplier.getRDFRepository();
assertNotNull("xRep null", xRep);
System.out.println("...done");
System.out.println("Checking that new repository is initialized...");
- XURI xBaseURI = (XURI) xDMA;
+ XURI xBaseURI = (XURI) xDocMDAccess;
String baseURI = xBaseURI.getStringValue();
assertNotNull("new: baseURI", xBaseURI );
assertTrue("new: baseURI", !xBaseURI.getStringValue().equals(""));
@@ -235,79 +252,79 @@ public class DocumentMetadataAccessTest
XMetadatable xM = (XMetadatable) xTR;
try {
- xDMA.getElementByURI(null);
+ xDocMDAccess.getElementByURI(null);
fail("getElementByURI: null allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.getMetadataGraphsWithType(null);
+ xDocMDAccess.getMetadataGraphsWithType(null);
fail("getMetadataGraphsWithType: null URI allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("", new XURI[0]);
+ xDocMDAccess.addMetadataFile("", new XURI[0]);
fail("addMetadataFile: empty filename allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("/foo", new XURI[0]);
+ xDocMDAccess.addMetadataFile("/foo", new XURI[0]);
fail("addMetadataFile: absolute filename allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("fo\"o", new XURI[0]);
+ xDocMDAccess.addMetadataFile("fo\"o", new XURI[0]);
fail("addMetadataFile: invalid filename allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("../foo", new XURI[0]);
+ xDocMDAccess.addMetadataFile("../foo", new XURI[0]);
fail("addMetadataFile: filename with .. allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("foo/../../bar", new XURI[0]);
+ xDocMDAccess.addMetadataFile("foo/../../bar", new XURI[0]);
fail("addMetadataFile: filename with nest .. allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("foo/././bar", new XURI[0]);
+ xDocMDAccess.addMetadataFile("foo/././bar", new XURI[0]);
fail("addMetadataFile: filename with nest . allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("content.xml", new XURI[0]);
+ xDocMDAccess.addMetadataFile("content.xml", new XURI[0]);
fail("addMetadataFile: content.xml allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("styles.xml", new XURI[0]);
+ xDocMDAccess.addMetadataFile("styles.xml", new XURI[0]);
fail("addMetadataFile: styles.xml allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("meta.xml", new XURI[0]);
+ xDocMDAccess.addMetadataFile("meta.xml", new XURI[0]);
fail("addMetadataFile: meta.xml allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addMetadataFile("settings.xml", new XURI[0]);
+ xDocMDAccess.addMetadataFile("settings.xml", new XURI[0]);
fail("addMetadataFile: settings.xml allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.importMetadataFile(FileFormat.RDF_XML, null, "foo",
+ xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, null, "foo",
foo, new XURI[0]);
fail("importMetadataFile: null stream allowed");
} catch (IllegalArgumentException e) {
@@ -317,7 +334,7 @@ public class DocumentMetadataAccessTest
final String sEmptyRDF = TestDocument.getUrl("empty.rdf");
try {
XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
- xDMA.importMetadataFile(FileFormat.RDF_XML, xFooIn, "",
+ xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "",
foo, new XURI[0]);
fail("importMetadataFile: empty filename allowed");
} catch (IllegalArgumentException e) {
@@ -326,7 +343,7 @@ public class DocumentMetadataAccessTest
try {
XInputStream xFooIn =
new StreamSimulator(sEmptyRDF, true, param);
- xDMA.importMetadataFile(FileFormat.RDF_XML, xFooIn, "meta.xml",
+ xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "meta.xml",
foo, new XURI[0]);
fail("importMetadataFile: meta.xml filename allowed");
} catch (IllegalArgumentException e) {
@@ -335,7 +352,7 @@ public class DocumentMetadataAccessTest
try {
XInputStream xFooIn =
new StreamSimulator(sEmptyRDF, true, param);
- xDMA.importMetadataFile(FileFormat.RDF_XML,
+ xDocMDAccess.importMetadataFile(FileFormat.RDF_XML,
xFooIn, "foo", null, new XURI[0]);
fail("importMetadataFile: null base URI allowed");
} catch (IllegalArgumentException e) {
@@ -344,62 +361,62 @@ public class DocumentMetadataAccessTest
try {
XInputStream xFooIn =
new StreamSimulator(sEmptyRDF, true, param);
- xDMA.importMetadataFile(FileFormat.RDF_XML,
+ xDocMDAccess.importMetadataFile(FileFormat.RDF_XML,
xFooIn, "foo", rdf_type, new XURI[0]);
fail("importMetadataFile: non-absolute base URI allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.removeMetadataFile(null);
+ xDocMDAccess.removeMetadataFile(null);
fail("removeMetadataFile: null URI allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addContentOrStylesFile("");
+ xDocMDAccess.addContentOrStylesFile("");
fail("addContentOrStylesFile: empty filename allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addContentOrStylesFile("/content.xml");
+ xDocMDAccess.addContentOrStylesFile("/content.xml");
fail("addContentOrStylesFile: absolute filename allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.addContentOrStylesFile("foo.rdf");
+ xDocMDAccess.addContentOrStylesFile("foo.rdf");
fail("addContentOrStylesFile: invalid filename allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.removeContentOrStylesFile("");
+ xDocMDAccess.removeContentOrStylesFile("");
fail("removeContentOrStylesFile: empty filename allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.loadMetadataFromStorage(null, foo, null);
+ xDocMDAccess.loadMetadataFromStorage(null, foo, null);
fail("loadMetadataFromStorage: null storage allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.storeMetadataToStorage(null/*, base*/);
+ xDocMDAccess.storeMetadataToStorage(null/*, base*/);
fail("storeMetadataToStorage: null storage allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.loadMetadataFromMedium(new PropertyValue[0]);
+ xDocMDAccess.loadMetadataFromMedium(new PropertyValue[0]);
fail("loadMetadataFromMedium: empty medium allowed");
} catch (IllegalArgumentException e) {
// ignore
}
try {
- xDMA.storeMetadataToMedium(new PropertyValue[0]);
+ xDocMDAccess.storeMetadataToMedium(new PropertyValue[0]);
fail("storeMetadataToMedium: empty medium allowed");
} catch (IllegalArgumentException e) {
// ignore
@@ -409,26 +426,26 @@ public class DocumentMetadataAccessTest
System.out.println("Checking file addition/removal...");
- xDMA.removeContentOrStylesFile(contentPath);
+ xDocMDAccess.removeContentOrStylesFile(contentPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("removeContentOrStylesFile (content)",
eq(xStmtsEnum, new Statement[] {
manifestStmts[0], manifestStmts[2], manifestStmts[4]
}));
- xDMA.addContentOrStylesFile(contentPath);
+ xDocMDAccess.addContentOrStylesFile(contentPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("addContentOrStylesFile (content)",
eq(xStmtsEnum, manifestStmts));
- xDMA.removeContentOrStylesFile(stylesPath);
+ xDocMDAccess.removeContentOrStylesFile(stylesPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("removeContentOrStylesFile (styles)",
eq(xStmtsEnum, new Statement[] {
manifestStmts[0], manifestStmts[1], manifestStmts[3]
}));
- xDMA.addContentOrStylesFile(stylesPath);
+ xDocMDAccess.addContentOrStylesFile(stylesPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("addContentOrStylesFile (styles)",
eq(xStmtsEnum, manifestStmts));
@@ -441,19 +458,19 @@ public class DocumentMetadataAccessTest
new Statement(xFoo, rdf_type, pkg_MetadataFile, manifest);
Statement xM_FooTypeBar =
new Statement(xFoo, rdf_type, bar, manifest);
- xDMA.addMetadataFile(fooPath, new XURI[] { bar });
+ xDocMDAccess.addMetadataFile(fooPath, new XURI[] { bar });
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("addMetadataFile",
eq(xStmtsEnum, merge(manifestStmts, new Statement[] {
xM_BaseHaspartFoo, xM_FooTypeMetadata, xM_FooTypeBar
})));
- XURI[] graphsBar = xDMA.getMetadataGraphsWithType(bar);
+ XURI[] graphsBar = xDocMDAccess.getMetadataGraphsWithType(bar);
assertTrue("getMetadataGraphsWithType",
graphsBar.length == 1 && eq(graphsBar[0], xFoo));
- xDMA.removeMetadataFile(xFoo);
+ xDocMDAccess.removeMetadataFile(xFoo);
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("removeMetadataFile",
eq(xStmtsEnum, manifestStmts));
@@ -468,7 +485,7 @@ public class DocumentMetadataAccessTest
XURI uri;
XMetadatable xMeta;
- xMeta = xDMA.getElementByURI(xMeta1);
+ xMeta = xDocMDAccess.getElementByURI(xMeta1);
assertTrue("getElementByURI: null", null != xMeta);
String XmlId = xMeta.getMetadataReference().Second;
String XmlId1 = xMeta1.getMetadataReference().Second;
@@ -483,7 +500,7 @@ public class DocumentMetadataAccessTest
fooBarPath);
Statement[] metadataStmts = getMetadataFileStmts(xBaseURI,
fooBarPath);
- xDMA.addMetadataFile(fooBarPath, new XURI[0]);
+ xDocMDAccess.addMetadataFile(fooBarPath, new XURI[0]);
xStmtsEnum = xRep.getStatements(null, null, null);
assertTrue("addMetadataFile",
eq(xStmtsEnum, merge(manifestStmts, metadataStmts )));
@@ -520,15 +537,15 @@ public class DocumentMetadataAccessTest
xStmtsEnum = xRep.getStatements(null, null, null);
XURI[] graphs = xRep.getGraphNames();
- xDMA.storeMetadataToMedium(args);
+ xDocMDAccess.storeMetadataToMedium(args);
// this should re-init
- xDMA.loadMetadataFromMedium(argsEmptyNoContent);
- xRep = xRS.getRDFRepository();
+ xDocMDAccess.loadMetadataFromMedium(argsEmptyNoContent);
+ xRep = xRepoSupplier.getRDFRepository();
assertTrue("xRep null", null != xRep);
assertTrue("baseURI still tdoc?",
- !baseURI.equals(xDMA.getStringValue()));
- Statement[] manifestStmts2 = getManifestStmts((XURI) xDMA);
+ !baseURI.equals(xDocMDAccess.getStringValue()));
+ Statement[] manifestStmts2 = getManifestStmts((XURI) xDocMDAccess);
xStmtsEnum = xRep.getStatements(null, null, null);
// there is no content or styles file in here, so we have just
// the package stmt
@@ -536,29 +553,29 @@ public class DocumentMetadataAccessTest
eq(xStmtsEnum, new Statement[] { manifestStmts2[0] }));
// this should re-init
- xDMA.loadMetadataFromMedium(argsEmpty);
- xRep = xRS.getRDFRepository();
+ xDocMDAccess.loadMetadataFromMedium(argsEmpty);
+ xRep = xRepoSupplier.getRDFRepository();
assertTrue("xRep null", null != xRep);
assertTrue("baseURI still tdoc?",
- !baseURI.equals(xDMA.getStringValue()));
- Statement[] manifestStmts3 = getManifestStmts((XURI) xDMA);
+ !baseURI.equals(xDocMDAccess.getStringValue()));
+ Statement[] manifestStmts3 = getManifestStmts((XURI) xDocMDAccess);
xStmtsEnum = xRep.getStatements(null, null, null);
assertTrue("loadMetadataFromMedium (no metadata)",
eq(xStmtsEnum, manifestStmts3));
- xDMA.loadMetadataFromMedium(args);
- xRep = xRS.getRDFRepository();
+ xDocMDAccess.loadMetadataFromMedium(args);
+ xRep = xRepoSupplier.getRDFRepository();
assertTrue("xRep null", null != xRep);
- Statement[] manifestStmts4 = getManifestStmts((XURI) xDMA);
- Statement[] metadataStmts4 = getMetadataFileStmts((XURI) xDMA,
+ Statement[] manifestStmts4 = getManifestStmts((XURI) xDocMDAccess);
+ Statement[] metadataStmts4 = getMetadataFileStmts((XURI) xDocMDAccess,
fooBarPath);
xStmtsEnum = xRep.getStatements(null, null, null);
assertTrue("some graph(s) not reloaded",
graphs.length == xRep.getGraphNames().length);
- XURI xFoobar4 = URI.createNS(xContext, xDMA.getStringValue(),
+ XURI xFoobar4 = URI.createNS(xContext, xDocMDAccess.getStringValue(),
fooBarPath);
Statement xFoobar_FooBarFoo4 =
new Statement(foo, bar, foo, xFoobar4);
@@ -572,7 +589,7 @@ public class DocumentMetadataAccessTest
String f = tempDir + "TESTPARA.odt";
- XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xRS);
+ XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xRepoSupplier);
xStor.storeToURL(f, new PropertyValue[0]);
@@ -656,17 +673,17 @@ public class DocumentMetadataAccessTest
PropertyValue[] loadProps = new PropertyValue[1];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "Hidden";
- loadProps[0].Value = new Boolean(true);
+ loadProps[0].Value = true;
xComp = util.DesktopTools.loadDoc(xMSF, file, loadProps);
- XRepositorySupplier xRS = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
- assertTrue("xRS null", null != xRS);
+ XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
+ assertTrue("xRS null", null != xRepoSupplier);
- XDocumentRepository xRep = UnoRuntime.queryInterface(XDocumentRepository.class, xRS.getRDFRepository());
- assertTrue("xRep null", null != xRep);
+ XDocumentRepository xDocRepository = UnoRuntime.queryInterface(XDocumentRepository.class, xRepoSupplier.getRDFRepository());
+ assertTrue("xRep null", null != xDocRepository);
XTextDocument xTextDoc = UnoRuntime.queryInterface(XTextDocument.class, xComp);
@@ -684,7 +701,7 @@ public class DocumentMetadataAccessTest
Statement x_FooBarLit1 = new Statement(foo, bar, mkLit("1"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 1",
!result.Second &&
eq(result.First, new Statement[] {
@@ -693,7 +710,7 @@ public class DocumentMetadataAccessTest
Statement x_FooBarLit2 = new Statement(foo, bar, mkLit("2"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 2",
!result.Second &&
eq(result.First, new Statement[] {
@@ -703,7 +720,7 @@ public class DocumentMetadataAccessTest
Statement x_BlankBarLit3 =
new Statement(blank1, bar, mkLit("3"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 3",
!result.Second &&
eq(result.First, new Statement[] {
@@ -714,7 +731,7 @@ public class DocumentMetadataAccessTest
Statement x_BlankBarLit4 =
new Statement(blank2, bar, mkLit("4"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 4",
!result.Second &&
eq(result.First, new Statement[] {
@@ -725,7 +742,7 @@ public class DocumentMetadataAccessTest
Statement x_BlankBarLit5 =
new Statement(blank1, bar, mkLit("5"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 5",
!result.Second &&
eq(result.First, new Statement[] {
@@ -741,7 +758,7 @@ public class DocumentMetadataAccessTest
Statement x_FooBarLit6 = new Statement(foo, bar, mkLit("6"), null);
Statement x_FooBazLit6 = new Statement(foo, baz, mkLit("6"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 6",
!result.Second &&
eq(result.First, new Statement[] {
@@ -752,7 +769,7 @@ public class DocumentMetadataAccessTest
Statement x_FooBazLit7 = new Statement(foo, baz, mkLit("7"), null);
Statement x_FooFooLit7 = new Statement(foo, foo, mkLit("7"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 7",
!result.Second &&
eq(result.First, new Statement[] {
@@ -765,7 +782,7 @@ public class DocumentMetadataAccessTest
Statement x_FooBarLittype = new Statement(foo, bar, lit_type, null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 8",
result.Second &&
eq(result.First, new Statement[] {
@@ -773,7 +790,7 @@ public class DocumentMetadataAccessTest
}));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 9",
result.Second &&
eq(result.First, new Statement[] {
@@ -781,7 +798,7 @@ public class DocumentMetadataAccessTest
}));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 10",
result.Second &&
eq(result.First, new Statement[] {
@@ -791,7 +808,7 @@ public class DocumentMetadataAccessTest
Statement x_FooBarLit11
= new Statement(foo, bar, mkLit("11", bar), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 11",
!result.Second &&
eq(result.First, new Statement[] {
@@ -802,7 +819,7 @@ public class DocumentMetadataAccessTest
Statement x_FileBarLit12 =
new Statement(xFile, bar, mkLit("12"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 12",
!result.Second &&
eq(result.First, new Statement[] {
@@ -810,7 +827,7 @@ public class DocumentMetadataAccessTest
}));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 13",
result.Second &&
eq(result.First, new Statement[] {
@@ -820,7 +837,7 @@ public class DocumentMetadataAccessTest
Statement x_FooLabelLit14 =
new Statement(foo, rdfs_label, mkLit("14"), null);
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 14",
result.Second &&
eq(result.First, new Statement[] {
@@ -828,33 +845,33 @@ public class DocumentMetadataAccessTest
}));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 15", eq(result.First, new Statement[] { } ));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 16", eq(result.First, new Statement[] { } ));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 17", eq(result.First, new Statement[] { } ));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 18", eq(result.First, new Statement[] { } ));
xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 19", eq(result.First, new Statement[] { } ));
xPara = UnoRuntime.queryInterface(
XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 20", eq(result.First, new Statement[] { } ));
xPara = UnoRuntime.queryInterface(
XMetadatable.class, xEnum.nextElement());
- result = xRep.getStatementRDFa(xPara);
+ result = xDocRepository.getStatementRDFa(xPara);
assertTrue("RDFa: 21", eq(result.First, new Statement[] { } ));
System.out.println("...done");
@@ -889,7 +906,7 @@ public class DocumentMetadataAccessTest
public void report(Exception e) {
System.out.println("Exception occurred:");
- e.printStackTrace();
+ e.printStackTrace(System.out);
report2(e);
fail();
}
@@ -1275,14 +1292,18 @@ public class DocumentMetadataAccessTest
// setup and close connections
@BeforeClass public static void setUpConnection() throws Exception {
- System.out.println("setUpConnection()");
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "starting class: " + DocumentMetadataAccess.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.setUp();
}
@AfterClass public static void tearDownConnection()
throws InterruptedException, com.sun.star.uno.Exception
{
- System.out.println("tearDownConnection() DocumentMetadataAccessTest");
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "finishing class: " + DocumentMetadataAccess.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.tearDown();
}
diff --git a/sfx2/qa/complex/framework/DocumentPropertiesTest.java b/sfx2/qa/complex/sfx2/DocumentProperties.java
index 20a0746c8322..01ccaa21619b 100644
--- a/sfx2/qa/complex/framework/DocumentPropertiesTest.java
+++ b/sfx2/qa/complex/sfx2/DocumentProperties.java
@@ -25,9 +25,10 @@
*
************************************************************************/
-package complex.framework;
+package complex.sfx2;
+import complex.sfx2.tools.TestDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.XInitialization;
@@ -53,7 +54,6 @@ import com.sun.star.document.XDocumentProperties;
import org.junit.After;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openoffice.test.OfficeConnection;
@@ -66,12 +66,8 @@ import static org.junit.Assert.*;
*
* @author mst
*/
-public class DocumentPropertiesTest
+public class DocumentProperties
{
-// public String[] getTestMethodNames () {
-// return new String[] { "check", "cleanup" };
-// }
-
@After public void cleanup() {
// nothing to do
}
@@ -80,7 +76,7 @@ public class DocumentPropertiesTest
class Listener implements XModifyListener {
private boolean m_Called;
- public Listener() {
+ Listener() {
m_Called = false;
}
@@ -235,8 +231,7 @@ public class DocumentPropertiesTest
new NamedValue("PageCount", new Integer(1))));
XPropertyContainer udpc = xDP.getUserDefinedProperties();
- XPropertySet udps = (XPropertySet) UnoRuntime.queryInterface(
- XPropertySet.class, udpc);
+ XPropertySet udps = UnoRuntime.queryInterface( XPropertySet.class, udpc );
assertTrue("UserDefined 1", "Dies ist ein wichtiger Hinweis"
.equals(udps.getPropertyValue("Hinweis")));
assertTrue("UserDefined 2", ("Kann Spuren von N"
@@ -366,8 +361,7 @@ public class DocumentPropertiesTest
dur.Seconds = 555;
dur.MilliSeconds = 444;
- udpc.addProperty("Frobnicate", PropertyAttribute.REMOVEABLE,
- new Boolean(b));
+ udpc.addProperty("Frobnicate", PropertyAttribute.REMOVEABLE, b);
udpc.addProperty("FrobDuration", PropertyAttribute.REMOVEABLE, dur);
udpc.addProperty("FrobDuration2", PropertyAttribute.REMOVEABLE, t);
udpc.addProperty("FrobEndDate", PropertyAttribute.REMOVEABLE, date);
@@ -433,8 +427,7 @@ public class DocumentPropertiesTest
System.out.println("Checking user-defined meta-data from stored file...");
udpc = xDP.getUserDefinedProperties();
- udps = (XPropertySet) UnoRuntime.queryInterface(
- XPropertySet.class, udpc);
+ udps = UnoRuntime.queryInterface( XPropertySet.class, udpc );
assertTrue("UserDefined bool", new Boolean(b).equals(
udps.getPropertyValue("Frobnicate")));
@@ -467,8 +460,7 @@ public class DocumentPropertiesTest
System.out.println("Checking notification listener interface...");
Listener listener = new Listener();
- XModifyBroadcaster xMB = (XModifyBroadcaster)
- UnoRuntime.queryInterface(XModifyBroadcaster.class, xDP);
+ XModifyBroadcaster xMB = UnoRuntime.queryInterface( XModifyBroadcaster.class, xDP );
xMB.addModifyListener(listener);
xDP.setAuthor("not me");
assertTrue("Listener Author", listener.reset());
@@ -542,20 +534,24 @@ public class DocumentPropertiesTest
private XMultiServiceFactory getMSF()
{
- final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
+ final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface( XMultiServiceFactory.class, connection.getComponentContext().getServiceManager() );
return xMSF1;
}
// setup and close connections
@BeforeClass public static void setUpConnection() throws Exception {
- System.out.println("setUpConnection()");
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "starting class: " + DocumentProperties.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.setUp();
}
@AfterClass public static void tearDownConnection()
throws InterruptedException, com.sun.star.uno.Exception
{
- System.out.println("tearDownConnection() DocumentPropertiesTest");
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "finishing class: " + DocumentProperties.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.tearDown();
}
diff --git a/sfx2/qa/complex/framework/CheckGlobalEventBroadcaster_writer1.java b/sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java
index c6dc073095b1..41bd66ccb5b9 100644
--- a/sfx2/qa/complex/framework/CheckGlobalEventBroadcaster_writer1.java
+++ b/sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java
@@ -24,7 +24,7 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.framework;
+package complex.sfx2;
import com.sun.star.awt.XWindow;
import com.sun.star.document.XEventBroadcaster;
@@ -33,7 +33,7 @@ import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
-import complex.framework.DocHelper.WriterHelper;
+import complex.sfx2.tools.WriterHelper;
import java.util.ArrayList;
@@ -53,7 +53,7 @@ import static org.junit.Assert.*;
* it will add an XEventListener and verify the Events
* raised when opening/changing and closing Office Documents
*/
-public class CheckGlobalEventBroadcaster_writer1 {
+public class GlobalEventBroadcaster {
XMultiServiceFactory m_xMSF = null;
XEventBroadcaster m_xEventBroadcaster = null;
ArrayList notifyEvents = new ArrayList();
@@ -61,12 +61,6 @@ public class CheckGlobalEventBroadcaster_writer1 {
XSpreadsheetDocument xSheetDoc;
XEventListener m_xEventListener = new EventListenerImpl();
-// public String[] getTestMethodNames() {
-// return new String[] {
-// "initialize", "checkWriter", "cleanup"
-// };
-// }
-
@Before public void initialize() {
m_xMSF = getMSF();
System.out.println("check wether there is a valid MultiServiceFactory");
@@ -79,7 +73,6 @@ public class CheckGlobalEventBroadcaster_writer1 {
"Create an instance of com.sun.star.frame.GlobalEventBroadcaster");
Object GlobalEventBroadcaster = null;
- Object dispatcher = null;
try {
GlobalEventBroadcaster = m_xMSF.createInstance(
@@ -116,7 +109,6 @@ public class CheckGlobalEventBroadcaster_writer1 {
WriterHelper wHelper = new WriterHelper(m_xMSF);
String[] expected;
- boolean locRes = true;
System.out.println("opening an empty writer doc");
notifyEvents.clear();
{
diff --git a/sfx2/qa/complex/standalonedocumentinfo/StandaloneDocumentInfoUnitTest.java b/sfx2/qa/complex/sfx2/StandaloneDocumentInfo.java
index 29fcaba8cb7a..1e9cbb1f4738 100644
--- a/sfx2/qa/complex/standalonedocumentinfo/StandaloneDocumentInfoUnitTest.java
+++ b/sfx2/qa/complex/sfx2/StandaloneDocumentInfo.java
@@ -24,10 +24,12 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.standalonedocumentinfo;
+package complex.sfx2;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
+import complex.sfx2.standalonedocinfo.StandaloneDocumentInfoTest;
+import complex.sfx2.standalonedocinfo.Test01;
import org.junit.After;
import org.junit.AfterClass;
@@ -40,18 +42,9 @@ import static org.junit.Assert.*;
/* Document here
*/
-public class StandaloneDocumentInfoUnitTest {
+public class StandaloneDocumentInfo {
private XMultiServiceFactory m_xMSF = null;
-// public String[] getTestMethodNames() {
-// return new String[] {
-// "ExecuteTest01"};
-// }
-
-// public String[] getTestObjectNames() {
-// return new String[] {"StandaloneDocumentInfoUnitTest"};
-// }
-
@Before public void before() {
try {
m_xMSF = getMSF();
@@ -82,15 +75,20 @@ public class StandaloneDocumentInfoUnitTest {
}
// setup and close connections
- @BeforeClass public static void setUpConnection() throws Exception {
- System.out.println("setUpConnection()");
+ @BeforeClass public static void setUpConnection() throws Exception
+ {
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "starting class: " + StandaloneDocumentInfo.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.setUp();
}
@AfterClass public static void tearDownConnection()
throws InterruptedException, com.sun.star.uno.Exception
{
- System.out.println("tearDownConnection()");
+ System.out.println( "------------------------------------------------------------" );
+ System.out.println( "finishing class: " + StandaloneDocumentInfo.class.getName() );
+ System.out.println( "------------------------------------------------------------" );
connection.tearDown();
}
diff --git a/sfx2/qa/complex/sfx2/UndoManager.java b/sfx2/qa/complex/sfx2/UndoManager.java
new file mode 100755
index 000000000000..ab1b9de910b8
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/UndoManager.java
@@ -0,0 +1,1464 @@
+/*************************************************************************
+ *
+ * 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;
+
+import com.sun.star.accessibility.XAccessible;
+import com.sun.star.accessibility.XAccessibleAction;
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.awt.XControl;
+import com.sun.star.awt.XControlModel;
+import com.sun.star.beans.NamedValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.container.XChild;
+import com.sun.star.container.XIndexContainer;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.container.XNameReplace;
+import com.sun.star.container.XSet;
+import com.sun.star.document.EmptyUndoStackException;
+import com.sun.star.document.UndoContextNotClosedException;
+import com.sun.star.document.UndoFailedException;
+import com.sun.star.document.UndoManagerEvent;
+import com.sun.star.document.XEmbeddedScripts;
+import com.sun.star.document.XEventsSupplier;
+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.InvocationTargetException;
+import org.openoffice.test.tools.OfficeDocument;
+import com.sun.star.document.XUndoManagerSupplier;
+import com.sun.star.document.XUndoManager;
+import com.sun.star.document.XUndoManagerListener;
+import com.sun.star.drawing.XControlShape;
+import com.sun.star.drawing.XDrawPage;
+import com.sun.star.drawing.XDrawPageSupplier;
+import com.sun.star.drawing.XShapes;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.script.ScriptEventDescriptor;
+import com.sun.star.script.XEventAttacherManager;
+import com.sun.star.script.XLibraryContainer;
+import com.sun.star.task.XJob;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.UnoRuntime;
+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;
+import complex.sfx2.undo.WriterDocumentTest;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Stack;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.openoffice.test.OfficeConnection;
+import org.openoffice.test.tools.DocumentType;
+import org.openoffice.test.tools.SpreadsheetDocument;
+
+/**
+ * Unit test for the UndoManager API
+ *
+ * @author frank.schoenheit@oracle.com
+ */
+public class UndoManager
+{
+ // -----------------------------------------------------------------------------------------------------------------
+ @Before
+ public void beforeTest() throws com.sun.star.uno.Exception
+ {
+ m_currentTestCase = null;
+ m_currentDocument = null;
+ m_undoListener = null;
+
+ // at our service factory, insert a new factory for our CallbackComponent
+ // this will allow the Basic code in our test documents to call back into this test case
+ // here, by just instantiating this service
+ final XSet globalFactory = UnoRuntime.queryInterface( XSet.class, getORB() );
+ m_callbackFactory = new CallbackComponentFactory();
+ globalFactory.insert( m_callbackFactory );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @Test
+ public void checkWriterUndo() throws Exception
+ {
+ m_currentTestCase = new WriterDocumentTest( getORB() );
+ impl_checkUndo();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @Test
+ public void checkCalcUndo() throws Exception
+ {
+ m_currentTestCase = new CalcDocumentTest( getORB() );
+ impl_checkUndo();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @Test
+ public void checkDrawUndo() throws Exception
+ {
+ m_currentTestCase = new DrawDocumentTest( getORB() );
+ impl_checkUndo();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @Test
+ public void checkImpressUndo() throws Exception
+ {
+ m_currentTestCase = new ImpressDocumentTest( getORB() );
+ impl_checkUndo();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @Test
+ public void checkChartUndo() throws Exception
+ {
+ m_currentTestCase = new ChartDocumentTest( getORB() );
+ impl_checkUndo();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @Test
+ public void checkBrokenScripts() throws com.sun.star.uno.Exception, InterruptedException
+ {
+ System.out.println( "testing: broken scripts" );
+
+ m_currentDocument = OfficeDocument.blankDocument( getORB(), DocumentType.CALC );
+ m_undoListener = new UndoListener();
+ getUndoManager().addUndoManagerListener( m_undoListener );
+
+ impl_setupBrokenBasicScript();
+ final String scriptURI = "vnd.sun.star.script:default.callbacks.brokenScript?language=Basic&location=document";
+
+ // .............................................................................................................
+ // scenario 1: Pressing a button which is bound to execute the script
+ // (This is one of the many cases where SfxObjectShell::CallXScript is invoked)
+
+ // set up the button
+ final XPropertySet buttonModel = impl_setupButton();
+ buttonModel.setPropertyValue( "Label", "exec broken script" );
+ impl_assignScript( buttonModel, "XActionListener", "actionPerformed",
+ scriptURI );
+
+ // switch the doc's view to form alive mode (so the button will actually work)
+ m_currentDocument.getCurrentView().dispatch( ".uno:SwitchControlDesignMode" );
+
+ // click the button
+ m_callbackCalled = false;
+ impl_clickButton( buttonModel );
+ // the macro is executed asynchronously by the button, so wait at most 2 seconds for the callback to be
+ // triggered
+ impl_waitFor( m_callbackCondition, 2000 );
+ // check the callback has actually been called
+ assertTrue( "clicking the test button did not work as expected - basic script not called", m_callbackCalled );
+
+ // again, since the script is executed asynchronously, we might arrive here while its execution
+ // is not completely finished. Give OOo another (at most) 2 seconds to finish it.
+ m_undoListener.waitForAllContextsClosed( 20000 );
+ // assure that the Undo Context Depth of the doc is still "0": The Basic script entered such a
+ // context, and didn't close it (thus it is broken), but the application framework should have
+ // auto-closed the context after the macro finished.
+ assertEquals( "undo context was not auto-closed as expected", 0, m_undoListener.getCurrentUndoContextDepth() );
+
+ // .............................................................................................................
+ // scenario 2: dispatching the script URL. Technically, this is equivalent to configuring the
+ // script into a menu or toolbar, and selecting the respective menu/toolbar item
+ m_callbackCalled = false;
+ m_currentDocument.getCurrentView().dispatch( scriptURI );
+ assertTrue( "dispatching the Script URL did not work as expected - basic script not called", m_callbackCalled );
+ // same as above: The script didn't close the context, but the OOo framework should have
+ assertEquals( "undo context was not auto-closed as expected", 0, m_undoListener.getCurrentUndoContextDepth() );
+
+ // .............................................................................................................
+ // scenario 3: assigning the script to some document event, and triggering this event
+ final XEventsSupplier eventSupplier = UnoRuntime.queryInterface( XEventsSupplier.class, m_currentDocument.getDocument() );
+ final XNameReplace events = UnoRuntime.queryInterface( XNameReplace.class, eventSupplier.getEvents() );
+ final NamedValue[] scriptDescriptor = new NamedValue[] {
+ new NamedValue( "EventType", "Script" ),
+ new NamedValue( "Script", scriptURI )
+ };
+ events.replaceByName( "OnViewCreated", scriptDescriptor );
+
+ // The below doesn't work: event notification is broken in m96, see http://www.openoffice.org/issues/show_bug.cgi?id=116313
+/* m_callbackCalled = false;
+ m_currentDocument.getCurrentView().dispatch( ".uno:NewWindow" );
+ assertTrue( "triggering an event did not work as expected - basic script not called", m_callbackCalled );
+ // same as above: The script didn't close the context, but the OOo framework should have
+ assertEquals( "undo context was not auto-closed as expected", 0, m_undoListener.getCurrentUndoContextDepth() );
+ */
+
+ // .............................................................................................................
+ // scenario 4: let the script enter an Undo context, but not close it, as usual.
+ // Additionally, let the script close the document - the OOo framework code which cares for
+ // auto-closing of Undo contexts should survive this, ideally ...
+ m_closeAfterCallback = true;
+ m_callbackCalled = false;
+ m_currentDocument.getCurrentView().dispatch( scriptURI );
+ assertTrue( m_callbackCalled );
+ assertTrue( "The Basic script should have closed the document.", m_undoListener.isDisposed() );
+ m_currentDocument = null;
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @Test
+ public void checkSerialization() throws com.sun.star.uno.Exception, InterruptedException
+ {
+ System.out.println( "testing: request serialization" );
+
+ m_currentDocument = OfficeDocument.blankDocument( getORB(), DocumentType.CALC );
+ final XUndoManager undoManager = getUndoManager();
+
+ final int threadCount = 10;
+ final int actionsPerThread = 10;
+ final int actionCount = threadCount * actionsPerThread;
+
+ // add some actions to the UndoManager, each knowing its position on the stack
+ final Object lock = new Object();
+ final Integer actionsUndone[] = new Integer[] { 0 };
+ for ( int i=actionCount; i>0; )
+ undoManager.addUndoAction( new CountingUndoAction( --i, lock, actionsUndone ) );
+
+ // some concurrent threads which undo the actions
+ Thread[] threads = new Thread[threadCount];
+ for ( int i=0; i<threadCount; ++i )
+ {
+ threads[i] = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ for ( int j=0; j<actionsPerThread; ++j )
+ {
+ try { undoManager.undo(); }
+ catch ( final Exception e )
+ {
+ fail( "Those dummy actions are not expected to fail." );
+ return;
+ }
+ }
+ }
+ };
+ }
+
+ // start the threads
+ for ( int i=0; i<threadCount; ++i )
+ threads[i].start();
+
+ // wait for them to be finished
+ for ( int i=0; i<threadCount; ++i )
+ threads[i].join();
+
+ // ensure all actions have been undone
+ assertEquals( "not all actions have been undone", actionCount, actionsUndone[0].intValue() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @After
+ public void afterTest()
+ {
+ if ( m_currentTestCase != null )
+ m_currentTestCase.closeDocument();
+ else if ( m_currentDocument != null )
+ m_currentDocument.close();
+ m_currentTestCase = null;
+ m_currentDocument = null;
+ m_callbackFactory.dispose();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ /**
+ * returns the undo manager belonging to a given document
+ * @return
+ */
+ private XUndoManager getUndoManager()
+ {
+ final XUndoManagerSupplier suppUndo = UnoRuntime.queryInterface( XUndoManagerSupplier.class, m_currentDocument.getDocument() );
+ final XUndoManager undoManager = suppUndo.getUndoManager();
+ assertTrue( UnoRuntime.areSame( undoManager.getParent(), m_currentDocument.getDocument() ) );
+ return undoManager;
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_waitFor( final Object i_condition, final int i_milliSeconds ) throws InterruptedException
+ {
+ synchronized( i_condition )
+ {
+ i_condition.wait( i_milliSeconds );
+ }
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_setupBrokenBasicScript()
+ {
+ try
+ {
+ final XEmbeddedScripts embeddedScripts = UnoRuntime.queryInterface( XEmbeddedScripts.class, m_currentDocument.getDocument() );
+ final XLibraryContainer basicLibs = embeddedScripts.getBasicLibraries();
+ final XNameContainer basicLib = basicLibs.createLibrary( "default" );
+
+ final String brokenScriptCode =
+ "Option Explicit\n" +
+ "\n" +
+ "Sub brokenScript\n" +
+ " Dim callback as Object\n" +
+ " ThisComponent.UndoManager.enterUndoContext( \"" + getCallbackUndoContextTitle() + "\" )\n" +
+ "\n" +
+ " callback = createUnoService( \"" + getCallbackComponentServiceName() + "\" )\n" +
+ " Dim emptyArgs() as new com.sun.star.beans.NamedValue\n" +
+ " Dim result as String\n" +
+ " result = callback.execute( emptyArgs() )\n" +
+ " If result = \"close\" Then\n" +
+ " ThisComponent.close( TRUE )\n" +
+ " End If\n" +
+ "End Sub\n" +
+ "\n";
+
+ basicLib.insertByName( "callbacks", brokenScriptCode );
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ fail( "caught an exception while setting up the script: " + e.toString() );
+ }
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private XPropertySet impl_setupButton() throws com.sun.star.uno.Exception
+ {
+ // let the document create a shape
+ final XMultiServiceFactory docAsFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class,
+ m_currentDocument.getDocument() );
+ final XControlShape xShape = UnoRuntime.queryInterface( XControlShape.class,
+ docAsFactory.createInstance( "com.sun.star.drawing.ControlShape" ) );
+
+ // position and size of the shape
+ xShape.setSize( new Size( 28 * 100, 10 * 100 ) );
+ xShape.setPosition( new Point( 10 * 100, 10 * 100 ) );
+
+ // create the form component (the model of a form control)
+ final String sQualifiedComponentName = "com.sun.star.form.component.CommandButton";
+ final XControlModel controlModel = UnoRuntime.queryInterface( XControlModel.class,
+ getORB().createInstance( sQualifiedComponentName ) );
+
+ // knitt both
+ xShape.setControl( controlModel );
+
+ // add the shape to the shapes collection of the document
+ SpreadsheetDocument spreadsheetDoc = (SpreadsheetDocument)m_currentDocument;
+ final XDrawPageSupplier suppDrawPage = UnoRuntime.queryInterface( XDrawPageSupplier.class,
+ spreadsheetDoc.getSheet( 0 ) );
+ final XDrawPage insertIntoPage = suppDrawPage.getDrawPage();
+
+ final XShapes sheetShapes = UnoRuntime.queryInterface( XShapes.class, insertIntoPage );
+ sheetShapes.add( xShape );
+
+ return UnoRuntime.queryInterface( XPropertySet.class, controlModel );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_assignScript( final XPropertySet i_controlModel, final String i_interfaceName,
+ final String i_interfaceMethod, final String i_scriptURI )
+ {
+ try
+ {
+ final XChild modelAsChild = UnoRuntime.queryInterface( XChild.class, i_controlModel );
+ final XIndexContainer parentForm = UnoRuntime.queryInterface( XIndexContainer.class, modelAsChild.getParent() );
+
+ final XEventAttacherManager manager = UnoRuntime.queryInterface( XEventAttacherManager.class, parentForm );
+
+ int containerPosition = -1;
+ for ( int i = 0; i < parentForm.getCount(); ++i )
+ {
+ final XPropertySet child = UnoRuntime.queryInterface( XPropertySet.class, parentForm.getByIndex( i ) );
+ if ( UnoRuntime.areSame( child, i_controlModel ) )
+ {
+ containerPosition = i;
+ break;
+ }
+ }
+ assertFalse( "could not find the given control model within its parent", containerPosition == -1 );
+ manager.registerScriptEvent( containerPosition, new ScriptEventDescriptor(
+ i_interfaceName,
+ i_interfaceMethod,
+ "",
+ "Script",
+ i_scriptURI
+ ) );
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ fail( "caught an exception while assigning the script event to the button: " + e.toString() );
+ }
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_clickButton( final XPropertySet i_buttonModel ) throws NoSuchElementException, IndexOutOfBoundsException
+ {
+ final XControlAccess controlAccess = UnoRuntime.queryInterface( XControlAccess.class,
+ m_currentDocument.getCurrentView().getController() );
+ final XControl control = controlAccess.getControl( UnoRuntime.queryInterface( XControlModel.class, i_buttonModel ) );
+ final XAccessible accessible = UnoRuntime.queryInterface( XAccessible.class, control );
+ final XAccessibleAction controlActions = UnoRuntime.queryInterface( XAccessibleAction.class, accessible.getAccessibleContext() );
+ for ( int i=0; i<controlActions.getAccessibleActionCount(); ++i )
+ {
+ if ( controlActions.getAccessibleActionDescription(i).equals( "click" ) )
+ {
+ controlActions.doAccessibleAction(i);
+ return;
+ }
+ }
+ fail( "did not find the accessible action named 'click'" );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private static class UndoListener implements XUndoManagerListener
+ {
+ public void undoActionAdded( UndoManagerEvent i_event )
+ {
+ assertFalse( "|undoActionAdded| called after document was disposed", m_isDisposed );
+
+ ++m_undoActionsAdded;
+ m_mostRecentlyAddedAction = i_event.UndoActionTitle;
+ }
+
+ public void actionUndone( UndoManagerEvent i_event )
+ {
+ assertFalse( "|actionUndone| called after document was disposed", m_isDisposed );
+
+ ++m_undoCount;
+ m_mostRecentlyUndone = i_event.UndoActionTitle;
+ }
+
+ public void actionRedone( UndoManagerEvent i_event )
+ {
+ assertFalse( "|actionRedone| called after document was disposed", m_isDisposed );
+
+ ++m_redoCount;
+ }
+
+ public void allActionsCleared( EventObject eo )
+ {
+ assertFalse( "|allActionsCleared| called after document was disposed", m_isDisposed );
+
+ m_wasCleared = true;
+ }
+
+ public void redoActionsCleared( EventObject eo )
+ {
+ assertFalse( "|redoActionsCleared| called after document was disposed", m_isDisposed );
+
+ m_redoWasCleared = true;
+ }
+
+ public void resetAll( EventObject i_event )
+ {
+ assertFalse( "|resetAll| called after document was disposed", m_isDisposed );
+
+ m_managerWasReset = true;
+ m_activeUndoContexts.clear();
+ }
+
+ public void enteredContext( UndoManagerEvent i_event )
+ {
+ assertFalse( "|enteredContext| called after document was disposed", m_isDisposed );
+
+ m_activeUndoContexts.push( i_event.UndoActionTitle );
+ assertEquals( "different opinions on the context nesting level (after entering)",
+ m_activeUndoContexts.size(), i_event.UndoContextDepth );
+ }
+
+ public void enteredHiddenContext( UndoManagerEvent i_event )
+ {
+ assertFalse( "|enteredHiddenContext| called after document was disposed", m_isDisposed );
+
+ m_activeUndoContexts.push( i_event.UndoActionTitle );
+ assertEquals( "different opinions on the context nesting level (after entering hidden)",
+ m_activeUndoContexts.size(), i_event.UndoContextDepth );
+ }
+
+ public void leftContext( UndoManagerEvent i_event )
+ {
+ assertFalse( "|leftContext| called after document was disposed", m_isDisposed );
+
+ assertEquals( "nested undo context descriptions do not match", m_activeUndoContexts.pop(), i_event.UndoActionTitle );
+ assertEquals( "different opinions on the context nesting level (after leaving)",
+ m_activeUndoContexts.size(), i_event.UndoContextDepth );
+ m_leftContext = true;
+ impl_notifyContextDepth();
+ }
+
+ public void leftHiddenContext( UndoManagerEvent i_event )
+ {
+ assertFalse( "|leftHiddenContext| called after document was disposed", m_isDisposed );
+ assertEquals( "|leftHiddenContext| is not expected to notify an action title", 0, i_event.UndoActionTitle.length() );
+
+ m_activeUndoContexts.pop();
+ assertEquals( "different opinions on the context nesting level (after leaving)",
+ m_activeUndoContexts.size(), i_event.UndoContextDepth );
+ m_leftHiddenContext = true;
+ impl_notifyContextDepth();
+ }
+
+ public void cancelledContext( UndoManagerEvent i_event )
+ {
+ assertFalse( "|cancelledContext| called after document was disposed", m_isDisposed );
+ assertEquals( "|cancelledContext| is not expected to notify an action title", 0, i_event.UndoActionTitle.length() );
+
+ m_activeUndoContexts.pop();
+ assertEquals( "different opinions on the context nesting level (after cancelling)",
+ m_activeUndoContexts.size(), i_event.UndoContextDepth );
+ m_cancelledContext = true;
+ impl_notifyContextDepth();
+ }
+
+ public void disposing( EventObject i_event )
+ {
+ m_isDisposed = true;
+ }
+
+ public void waitForAllContextsClosed( final int i_milliSeconds ) throws InterruptedException
+ {
+ synchronized ( m_allContextsClosedCondition )
+ {
+ if ( m_activeUndoContexts.empty() )
+ return;
+ m_allContextsClosedCondition.wait( i_milliSeconds );
+ }
+ }
+
+ private void impl_notifyContextDepth()
+ {
+ synchronized ( m_allContextsClosedCondition )
+ {
+ if ( m_activeUndoContexts.empty() )
+ {
+ m_allContextsClosedCondition.notifyAll();
+ }
+ }
+ }
+
+ private int getUndoActionsAdded() { return m_undoActionsAdded; }
+ private int getUndoActionCount() { return m_undoCount; }
+ private int getRedoActionCount() { return m_redoCount; }
+ private String getCurrentUndoContextTitle() { return m_activeUndoContexts.peek(); }
+ private String getMostRecentlyAddedActionTitle() { return m_mostRecentlyAddedAction; };
+ private String getMostRecentlyUndoneTitle() { return m_mostRecentlyUndone; }
+ private int getCurrentUndoContextDepth() { return m_activeUndoContexts.size(); }
+ private boolean isDisposed() { return m_isDisposed; }
+ private boolean wasContextLeft() { return m_leftContext; }
+ private boolean wasHiddenContextLeft() { return m_leftHiddenContext; }
+ private boolean hasContextBeenCancelled() { return m_cancelledContext; }
+ private boolean wereStacksCleared() { return m_wasCleared; }
+ private boolean wasRedoStackCleared() { return m_redoWasCleared; }
+ private boolean wasManagerReset() { return m_managerWasReset; }
+
+ void reset()
+ {
+ m_undoActionsAdded = m_undoCount = m_redoCount = 0;
+ m_activeUndoContexts.clear();
+ m_mostRecentlyAddedAction = m_mostRecentlyUndone = null;
+ // m_isDisposed is not cleared, intentionally
+ m_leftContext = m_leftHiddenContext = m_cancelledContext = m_wasCleared = m_redoWasCleared = m_managerWasReset = false;
+ }
+
+ private int m_undoActionsAdded = 0;
+ private int m_undoCount = 0;
+ private int m_redoCount = 0;
+ private boolean m_isDisposed = false;
+ private boolean m_leftContext = false;
+ private boolean m_leftHiddenContext = false;
+ private boolean m_cancelledContext = false;
+ private boolean m_wasCleared = false;
+ private boolean m_redoWasCleared = false;
+ private boolean m_managerWasReset = false;
+ private Stack< String >
+ m_activeUndoContexts = new Stack<String>();
+ private String m_mostRecentlyAddedAction = null;
+ private String m_mostRecentlyUndone = null;
+ private final Object m_allContextsClosedCondition = new Object();
+ };
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_checkUndo() throws Exception
+ {
+ System.out.println( "testing: " + m_currentTestCase.getDocumentDescription() );
+ m_currentDocument = m_currentTestCase.getDocument();
+ m_currentTestCase.initializeDocument();
+ m_currentTestCase.verifyInitialDocumentState();
+
+ final XUndoManager undoManager = getUndoManager();
+ undoManager.clear();
+ assertFalse( "clearing the Undo manager should result in the impossibility to undo anything", undoManager.isUndoPossible() );
+ assertFalse( "clearing the Undo manager should result in the impossibility to redo anything", undoManager.isRedoPossible() );
+
+ m_undoListener = new UndoListener();
+ undoManager.addUndoManagerListener( m_undoListener );
+
+ impl_testSingleModification( undoManager );
+ impl_testMultipleModifications( undoManager );
+ impl_testCustomUndoActions( undoManager );
+ impl_testLocking( undoManager );
+ impl_testNestedContexts( undoManager );
+ impl_testErrorHandling( undoManager );
+ impl_testContextHandling( undoManager );
+ impl_testStackHandling( undoManager );
+ impl_testClearance( undoManager );
+ impl_testHiddenContexts( undoManager );
+
+ // close the document, ensure the Undo manager listener gets notified
+ m_currentTestCase.closeDocument();
+ m_currentTestCase = null;
+ m_currentDocument = null;
+ assertTrue( "document is closed, but the UndoManagerListener has not been notified of the disposal", m_undoListener.isDisposed() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testSingleModification( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ m_currentTestCase.doSingleModification();
+ m_currentTestCase.verifySingleModificationDocumentState();
+
+ // undo the modification, ensure the listener got the proper notifications
+ assertEquals( "We did not yet do a undo!", 0, m_undoListener.getUndoActionCount() );
+ i_undoManager.undo();
+ assertEquals( "A simple undo does not result in the proper Undo count.",
+ 1, m_undoListener.getUndoActionCount() );
+
+ // verify the document is in its initial state, again
+ m_currentTestCase.verifyInitialDocumentState();
+
+ // redo the modification, ensure the listener got the proper notifications
+ assertEquals( "did not yet do a redo!", 0, m_undoListener.getRedoActionCount() );
+ i_undoManager.redo();
+ assertEquals( "did a redo, but got no notification of it!", 1, m_undoListener.getRedoActionCount() );
+ // ensure the document is in the proper state, again
+ m_currentTestCase.verifySingleModificationDocumentState();
+
+ // now do an Undo via the UI (aka the dispatch API), and see if this works, and notifies the listener as
+ // expected
+ m_currentTestCase.getDocument().getCurrentView().dispatch( ".uno:Undo" );
+ m_currentTestCase.verifyInitialDocumentState();
+ assertEquals( "UI-Undo does not notify the listener", 2, m_undoListener.getUndoActionCount() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testMultipleModifications( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ m_undoListener.reset();
+ assertEquals( "unexpected initial undo context depth", 0, m_undoListener.getCurrentUndoContextDepth() );
+ i_undoManager.enterUndoContext( "Batch Changes" );
+ assertEquals( "unexpected undo context depth after entering a context",
+ 1, m_undoListener.getCurrentUndoContextDepth() );
+ assertEquals( "entering an Undo context has not been notified properly",
+ "Batch Changes", m_undoListener.getCurrentUndoContextTitle() );
+
+ final int modifications = m_currentTestCase.doMultipleModifications();
+ assertEquals( "unexpected number of undo actions while doing batch changes to the document",
+ modifications, m_undoListener.getUndoActionsAdded() );
+ assertEquals( "seems the document operations touched the undo context depth",
+ 1, m_undoListener.getCurrentUndoContextDepth() );
+
+ i_undoManager.leaveUndoContext();
+ assertEquals( "unexpected undo context depth after leaving the last context",
+ 0, m_undoListener.getCurrentUndoContextDepth() );
+ assertEquals( "no Undo done, yet - still the listener has been notified of an Undo action",
+ 0, m_undoListener.getUndoActionCount() );
+
+ i_undoManager.undo();
+ assertEquals( "Just did an undo - the listener should have been notified", 1, m_undoListener.getUndoActionCount() );
+ m_currentTestCase.verifyInitialDocumentState();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testCustomUndoActions( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ i_undoManager.clear();
+ m_undoListener.reset();
+ assertFalse( "undo stack not empty after clearing the undo manager", i_undoManager.isUndoPossible() );
+ assertFalse( "redo stack not empty after clearing the undo manager", i_undoManager.isRedoPossible() );
+ assertArrayEquals( ">0 descriptions for an empty undo stack?",
+ new String[0], i_undoManager.getAllUndoActionTitles() );
+ assertArrayEquals( ">0 descriptions for an empty redo stack?",
+ new String[0], i_undoManager.getAllRedoActionTitles() );
+
+ // add two actions, one directly, one within a context
+ final CustomUndoAction action1 = new CustomUndoAction( "UndoAction1" );
+ i_undoManager.addUndoAction( action1 );
+ assertEquals( "Adding an undo action not observed by the listener", 1, m_undoListener.getUndoActionsAdded() );
+ assertEquals( "Adding an undo action did not notify the proper title",
+ action1.getTitle(), m_undoListener.getMostRecentlyAddedActionTitle() );
+ final String contextTitle = "Undo Context";
+ i_undoManager.enterUndoContext( contextTitle );
+ final CustomUndoAction action2 = new CustomUndoAction( "UndoAction2" );
+ i_undoManager.addUndoAction( action2 );
+ assertEquals( "Adding an undo action not observed by the listener",
+ 2, m_undoListener.getUndoActionsAdded() );
+ assertEquals( "Adding an undo action did not notify the proper title",
+ action2.getTitle(), m_undoListener.getMostRecentlyAddedActionTitle() );
+ i_undoManager.leaveUndoContext();
+
+ // see if the manager has proper descriptions
+ assertArrayEquals( "unexpected Redo descriptions after adding two actions",
+ new String[0], i_undoManager.getAllRedoActionTitles() );
+ assertArrayEquals( "unexpected Undo descriptions after adding two actions",
+ new String[]{contextTitle, action1.getTitle()}, i_undoManager.getAllUndoActionTitles() );
+
+ // undo one action
+ i_undoManager.undo();
+ assertEquals( "improper action title notified during programmatic Undo",
+ contextTitle, m_undoListener.getMostRecentlyUndoneTitle() );
+ assertTrue( "nested custom undo action has not been undone as expected", action2.undoCalled() );
+ assertFalse( "nested custom undo action has not been undone as expected", action1.undoCalled() );
+ assertArrayEquals( "unexpected Redo descriptions after undoing a nested custom action",
+ new String[]{contextTitle}, i_undoManager.getAllRedoActionTitles() );
+ assertArrayEquals( "unexpected Undo descriptions after undoing a nested custom action",
+ new String[]{action1.getTitle()}, i_undoManager.getAllUndoActionTitles() );
+
+ // undo the second action, via UI dispatches
+ m_currentTestCase.getDocument().getCurrentView().dispatch( ".uno:Undo" );
+ assertEquals( "improper action title notified during UI Undo", action1.getTitle(), m_undoListener.getMostRecentlyUndoneTitle() );
+ assertTrue( "nested custom undo action has not been undone as expected", action1.undoCalled() );
+ assertArrayEquals( "unexpected Redo descriptions after undoing the second custom action",
+ new String[]{action1.getTitle(), contextTitle}, i_undoManager.getAllRedoActionTitles() );
+ assertArrayEquals( "unexpected Undo descriptions after undoing the second custom action",
+ new String[0], i_undoManager.getAllUndoActionTitles() );
+
+ // check the actions are disposed when the stacks are cleared
+ i_undoManager.clear();
+ assertTrue( action1.disposed() && action2.disposed() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testLocking( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ i_undoManager.reset();
+ m_undoListener.reset();
+
+ // implicit Undo actions, triggered by changes to the document
+ assertFalse( "unexpected initial locking state", i_undoManager.isLocked() );
+ i_undoManager.lock();
+ assertTrue( "just locked the manager, why does it lie?", i_undoManager.isLocked() );
+ m_currentTestCase.doSingleModification();
+ assertEquals( "when the Undo manager is locked, no implicit additions should happen",
+ 0, m_undoListener.getUndoActionsAdded() );
+ i_undoManager.unlock();
+ assertEquals( "unlock is not expected to add collected actions - they should be discarded",
+ 0, m_undoListener.getUndoActionsAdded() );
+ assertFalse( "just unlocked the manager, why does it lie?", i_undoManager.isLocked() );
+
+ // explicit Undo actions
+ i_undoManager.lock();
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.unlock();
+ assertEquals( "explicit Undo actions are expected to be ignored when the manager is locked",
+ 0, m_undoListener.getUndoActionsAdded() );
+
+ // Undo contexts while being locked
+ i_undoManager.lock();
+ i_undoManager.enterUndoContext( "Dummy Context" );
+ i_undoManager.enterHiddenUndoContext();
+ assertEquals( "entering Undo contexts should be ignored when the manager is locked", 0, m_undoListener.getCurrentUndoContextDepth() );
+ i_undoManager.leaveUndoContext();
+ i_undoManager.leaveUndoContext();
+ i_undoManager.unlock();
+
+ // |unlock| error handling
+ assertFalse( "internal error: manager should not be locked at this point in time", i_undoManager.isLocked() );
+ boolean caughtExpected = false;
+ try { i_undoManager.unlock(); } catch ( final NotLockedException e ) { caughtExpected = true; }
+ assertTrue( "unlocking the manager when it is not locked should throw", caughtExpected );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testContextHandling( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ // .............................................................................................................
+ // part I: non-empty contexts
+ i_undoManager.reset();
+ m_undoListener.reset();
+
+ // put one action on the undo and one on the redo stack, as precondition for the following tests
+ final XUndoAction undoAction1 = new CustomUndoAction( "Undo Action 1" );
+ i_undoManager.addUndoAction( undoAction1 );
+ final XUndoAction undoAction2 = new CustomUndoAction( "Undo Action 2" );
+ i_undoManager.addUndoAction( undoAction2 );
+ i_undoManager.undo();
+ assertTrue( "precondition for context handling tests not met (1)", i_undoManager.isUndoPossible() );
+ assertTrue( "precondition for context handling tests not met (2)", i_undoManager.isRedoPossible() );
+ assertArrayEquals( new String[] { undoAction1.getTitle() }, i_undoManager.getAllUndoActionTitles() );
+ assertArrayEquals( new String[] { undoAction2.getTitle() }, i_undoManager.getAllRedoActionTitles() );
+
+ final String[] expectedRedoActionComments = new String[] { undoAction2.getTitle() };
+ assertArrayEquals( expectedRedoActionComments, i_undoManager.getAllRedoActionTitles() );
+
+ // enter a context
+ i_undoManager.enterUndoContext( "Undo Context" );
+ // this should not (yet) touch the redo stack
+ assertArrayEquals( expectedRedoActionComments, i_undoManager.getAllRedoActionTitles() );
+ assertEquals( "unexpected undo context depth after entering a context", 1, m_undoListener.getCurrentUndoContextDepth() );
+ // add a single action
+ XUndoAction undoAction3 = new CustomUndoAction( "Undo Action 3" );
+ i_undoManager.addUndoAction( undoAction3 );
+ // still, the redo stack should be untouched - added at a lower level does not affect it at all
+ assertArrayEquals( expectedRedoActionComments, i_undoManager.getAllRedoActionTitles() );
+
+ // while the context is open, its title should already contribute to the stack, ...
+ assertEquals( "Undo Context", i_undoManager.getCurrentUndoActionTitle() );
+ // ... getAllUndo/RedoActionTitles should operate on the top level, not on the level defined by the open
+ // context, ...
+ assertArrayEquals( new String[] { "Undo Context", undoAction1.getTitle() },
+ i_undoManager.getAllUndoActionTitles() );
+ // ... but Undo and Redo should be impossible as long as the context is open
+ assertFalse( i_undoManager.isUndoPossible() );
+ assertFalse( i_undoManager.isRedoPossible() );
+
+ // leave the context, check the listener has been notified properly, and the notified context depth is correct
+ i_undoManager.leaveUndoContext();
+ assertTrue( m_undoListener.wasContextLeft() );
+ assertFalse( m_undoListener.wasHiddenContextLeft() );
+ assertFalse( m_undoListener.hasContextBeenCancelled() );
+ assertEquals( "unexpected undo context depth leaving a non-empty context", 0, m_undoListener.getCurrentUndoContextDepth() );
+ // leaving a non-empty context should have cleare the redo stack
+ assertArrayEquals( new String[0], i_undoManager.getAllRedoActionTitles() );
+ assertTrue( m_undoListener.wasRedoStackCleared() );
+
+ // .............................................................................................................
+ // part II: empty contexts
+ i_undoManager.reset();
+ m_undoListener.reset();
+
+ // enter a context, leave it immediately without adding an action to it
+ i_undoManager.enterUndoContext( "Undo Context" );
+ i_undoManager.leaveUndoContext();
+ assertFalse( m_undoListener.wasContextLeft() );
+ assertFalse( m_undoListener.wasHiddenContextLeft() );
+ assertTrue( m_undoListener.hasContextBeenCancelled() );
+ assertFalse( "leaving an empty context should silently remove it, and not contribute to the stack",
+ i_undoManager.isUndoPossible() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testNestedContexts( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ i_undoManager.reset();
+ m_undoListener.reset();
+ i_undoManager.enterUndoContext( "context 1" );
+ i_undoManager.enterUndoContext( "context 1.1" );
+ final CustomUndoAction action1 = new CustomUndoAction( "action 1.1.1" );
+ i_undoManager.addUndoAction( action1 );
+ i_undoManager.enterUndoContext( "context 1.1.2" );
+ final CustomUndoAction action2 = new CustomUndoAction( "action 1.1.2.1" );
+ i_undoManager.addUndoAction( action2 );
+ i_undoManager.leaveUndoContext();
+ final CustomUndoAction action3 = new CustomUndoAction( "action 1.1.3" );
+ i_undoManager.addUndoAction( action3 );
+ i_undoManager.leaveUndoContext();
+ i_undoManager.leaveUndoContext();
+ final CustomUndoAction action4 = new CustomUndoAction( "action 1.2" );
+ i_undoManager.addUndoAction( action4 );
+
+ i_undoManager.undo();
+ assertEquals( "undoing a single action notifies a wrong title", action4.getTitle(), m_undoListener.getMostRecentlyUndoneTitle() );
+ assertTrue( "custom Undo not called", action4.undoCalled() );
+ assertFalse( "too many custom Undos called", action1.undoCalled() || action2.undoCalled() || action3.undoCalled() );
+ i_undoManager.undo();
+ assertTrue( "nested actions not properly undone", action1.undoCalled() && action2.undoCalled() && action3.undoCalled() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testErrorHandling( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ i_undoManager.reset();
+ m_undoListener.reset();
+
+ // try retrieving the comments for the current Undo/Redo - this should fail
+ boolean caughtExpected = false;
+ try { i_undoManager.getCurrentUndoActionTitle(); }
+ catch( final EmptyUndoStackException e ) { caughtExpected = true; }
+ assertTrue( "trying the title of the current Undo action is expected to fail for an empty stack", caughtExpected );
+
+ caughtExpected = false;
+ try { i_undoManager.getCurrentRedoActionTitle(); }
+ catch( final EmptyUndoStackException e ) { caughtExpected = true; }
+ assertTrue( "trying the title of the current Redo action is expected to fail for an empty stack", caughtExpected );
+
+ caughtExpected = false;
+ try { i_undoManager.undo(); } catch ( final EmptyUndoStackException e ) { caughtExpected = true; }
+ assertTrue( "undo should throw if no Undo action is on the stack", caughtExpected );
+
+ caughtExpected = false;
+ try { i_undoManager.redo(); } catch ( final EmptyUndoStackException e ) { caughtExpected = true; }
+ assertTrue( "redo should throw if no Redo action is on the stack", caughtExpected );
+
+ caughtExpected = false;
+ try { i_undoManager.leaveUndoContext(); } catch ( final InvalidStateException e ) { caughtExpected = true; }
+ assertTrue( "leaveUndoContext should throw if no context is currently open", caughtExpected );
+
+ caughtExpected = false;
+ try { i_undoManager.addUndoAction( null ); } catch ( com.sun.star.lang.IllegalArgumentException e ) { caughtExpected = true; }
+ assertTrue( "adding a NULL action should be rejected", caughtExpected );
+
+ i_undoManager.reset();
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.undo();
+ i_undoManager.enterUndoContext( "Undo Context" );
+ // those methods should fail when a context is open:
+ final String[] methodNames = new String[] { "undo", "redo", "clear", "clearRedo" };
+ for ( int i=0; i<methodNames.length; ++i )
+ {
+ caughtExpected = false;
+ try
+ {
+ Method method = i_undoManager.getClass().getMethod( methodNames[i], new Class[0] );
+ method.invoke( i_undoManager, new Object[0] );
+ }
+ catch ( IllegalAccessException ex ) { }
+ catch ( IllegalArgumentException ex ) { }
+ catch ( InvocationTargetException ex )
+ {
+ Throwable targetException = ex.getTargetException();
+ caughtExpected = ( targetException instanceof UndoContextNotClosedException );
+ }
+ catch ( NoSuchMethodException ex ) { }
+ catch ( SecurityException ex ) { }
+
+ assertTrue( methodNames[i] + " should be rejected when there is an open context", caughtExpected );
+ }
+ i_undoManager.leaveUndoContext();
+
+ // try Undo actions which fail in their Undo/Redo
+ for ( int i=0; i<4; ++i )
+ {
+ final boolean undo = ( i < 2 );
+ final boolean doByAPI = ( i % 2 ) == 0;
+
+ i_undoManager.reset();
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.addUndoAction( new FailingUndoAction( undo ? FAIL_UNDO : FAIL_REDO ) );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.undo();
+ if ( !undo )
+ i_undoManager.undo();
+ // assert preconditions for the below test
+ assertTrue( i_undoManager.isUndoPossible() );
+ assertTrue( i_undoManager.isRedoPossible() );
+
+ boolean caughtUndoFailed = false;
+ try
+ {
+ if ( undo )
+ if ( doByAPI )
+ i_undoManager.undo();
+ else
+ m_currentTestCase.getDocument().getCurrentView().dispatch( ".uno:Undo" );
+ else
+ if ( doByAPI )
+ i_undoManager.redo();
+ else
+ m_currentTestCase.getDocument().getCurrentView().dispatch( ".uno:Redo" );
+ }
+ catch ( UndoFailedException e )
+ {
+ caughtUndoFailed = true;
+ }
+ if ( doByAPI )
+ assertTrue( "Exceptions in XUndoAction.undo should be propagated at the API", caughtUndoFailed );
+ else
+ assertFalse( "Undo/Redo by UI should not let escape Exceptions", caughtUndoFailed );
+ if ( undo )
+ {
+ assertFalse( "a failing Undo should clear the Undo stack", i_undoManager.isUndoPossible() );
+ assertTrue( "a failing Undo should /not/ clear the Redo stack", i_undoManager.isRedoPossible() );
+ }
+ else
+ {
+ assertTrue( "a failing Redo should /not/ clear the Undo stack", i_undoManager.isUndoPossible() );
+ assertFalse( "a failing Redo should clear the Redo stack", i_undoManager.isRedoPossible() );
+ }
+ }
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testStackHandling( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ i_undoManager.reset();
+ m_undoListener.reset();
+
+ assertFalse( i_undoManager.isUndoPossible() );
+ assertFalse( i_undoManager.isRedoPossible() );
+
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ assertTrue( i_undoManager.isUndoPossible() );
+ assertFalse( i_undoManager.isRedoPossible() );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ assertTrue( i_undoManager.isUndoPossible() );
+ assertFalse( i_undoManager.isRedoPossible() );
+ i_undoManager.undo();
+ assertTrue( i_undoManager.isUndoPossible() );
+ assertTrue( i_undoManager.isRedoPossible() );
+ i_undoManager.undo();
+ assertFalse( i_undoManager.isUndoPossible() );
+ assertTrue( i_undoManager.isRedoPossible() );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ assertTrue( i_undoManager.isUndoPossible() );
+ assertFalse( "adding a new action should have cleared the Redo stack", i_undoManager.isRedoPossible() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testClearance( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ i_undoManager.reset();
+ m_undoListener.reset();
+
+ // add an action, clear the stack, verify the listener has been called
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ assertFalse( "clearance listener unexpectedly called", m_undoListener.wereStacksCleared() );
+ assertFalse( "redo-clearance listener unexpectedly called", m_undoListener.wasRedoStackCleared() );
+ i_undoManager.clear();
+ assertTrue( "clearance listener not called as expected", m_undoListener.wereStacksCleared() );
+ assertFalse( "redo-clearance listener unexpectedly called (2)", m_undoListener.wasRedoStackCleared() );
+
+ // ensure the listener is also called if the stack is actually empty at the moment of the call
+ m_undoListener.reset();
+ assertFalse( i_undoManager.isUndoPossible() );
+ i_undoManager.clear();
+ assertTrue( "clearance listener is also expected to be called if the stack was empty before", m_undoListener.wereStacksCleared() );
+
+ // ensure the proper listeners are called for clearRedo
+ m_undoListener.reset();
+ i_undoManager.clearRedo();
+ assertFalse( m_undoListener.wereStacksCleared() );
+ assertTrue( m_undoListener.wasRedoStackCleared() );
+
+ // ensure the redo listener is also called upon implicit redo stack clearance
+ m_undoListener.reset();
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.undo();
+ assertTrue( i_undoManager.isUndoPossible() );
+ assertTrue( i_undoManager.isRedoPossible() );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ assertFalse( i_undoManager.isRedoPossible() );
+ assertTrue( "implicit clearance of the Redo stack does not notify listeners", m_undoListener.wasRedoStackCleared() );
+
+ // test resetting the manager
+ m_undoListener.reset();
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.undo();
+ assertTrue( i_undoManager.isUndoPossible() );
+ assertTrue( i_undoManager.isRedoPossible() );
+ i_undoManager.reset();
+ assertFalse( i_undoManager.isUndoPossible() );
+ assertFalse( i_undoManager.isRedoPossible() );
+ assertTrue( "|reset| does not properly notify", m_undoListener.wasManagerReset() );
+
+ // resetting the manager, with open undo contexts
+ m_undoListener.reset();
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.enterUndoContext( "Undo Context" );
+ i_undoManager.addUndoAction( new CustomUndoAction() );
+ i_undoManager.enterHiddenUndoContext();
+ i_undoManager.reset();
+ assertTrue( "|reset| while contexts are open does not properly notify", m_undoListener.wasManagerReset() );
+ // verify the manager really has the proper context depth now
+ i_undoManager.enterUndoContext( "Undo Context" );
+ assertEquals( "seems that |reset| did not really close the open contexts", 1, m_undoListener.getCurrentUndoContextDepth() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private void impl_testHiddenContexts( final XUndoManager i_undoManager ) throws com.sun.star.uno.Exception
+ {
+ i_undoManager.reset();
+ m_undoListener.reset();
+ assertFalse( "precondition for testing hidden undo contexts not met", i_undoManager.isUndoPossible() );
+
+ // entering a hidden context should be rejected if the stack is empty
+ boolean caughtExpected = false;
+ try { i_undoManager.enterHiddenUndoContext(); }
+ catch ( final EmptyUndoStackException e ) { caughtExpected = true; }
+ assertTrue( "entering hidden contexts should be denied on an empty stack", caughtExpected );
+
+ // but it should be allowed if the context is not empty
+ final CustomUndoAction undoAction0 = new CustomUndoAction( "Step 0" );
+ i_undoManager.addUndoAction( undoAction0 );
+ final CustomUndoAction undoAction1 = new CustomUndoAction( "Step 1" );
+ i_undoManager.addUndoAction( undoAction1 );
+ i_undoManager.enterHiddenUndoContext();
+ final CustomUndoAction hiddenUndoAction = new CustomUndoAction( "hidden context action" );
+ i_undoManager.addUndoAction( hiddenUndoAction );
+ i_undoManager.leaveUndoContext();
+ assertFalse( "leaving a hidden should not call |leftUndocontext|", m_undoListener.wasContextLeft() );
+ assertTrue( "leaving a hidden does not call |leftHiddenUndocontext|", m_undoListener.wasHiddenContextLeft() );
+ assertFalse( "leaving a non-empty hidden context claims to have cancelled it", m_undoListener.hasContextBeenCancelled() );
+ assertEquals( "leaving a hidden context is not properly notified", 0, m_undoListener.getCurrentUndoContextDepth() );
+ assertArrayEquals( "unexpected Undo stack after leaving a hidden context",
+ new String[] { undoAction1.getTitle(), undoAction0.getTitle() },
+ i_undoManager.getAllUndoActionTitles() );
+
+ // and then calling |undo| once should not only undo everything in the hidden context, but also
+ // the previous action - but not more
+ i_undoManager.undo();
+ assertTrue( "Undo after leaving a hidden context does not actually undo the context actions",
+ hiddenUndoAction.undoCalled() );
+ assertTrue( "Undo after leaving a hidden context does not undo the predecessor action",
+ undoAction1.undoCalled() );
+ assertFalse( "Undo after leaving a hidden context undoes too much",
+ undoAction0.undoCalled() );
+
+ // leaving an empty hidden context should call the proper notification method
+ m_undoListener.reset();
+ i_undoManager.enterHiddenUndoContext();
+ i_undoManager.leaveUndoContext();
+ assertFalse( m_undoListener.wasContextLeft() );
+ assertFalse( m_undoListener.wasHiddenContextLeft() );
+ assertTrue( m_undoListener.hasContextBeenCancelled() );
+
+ // nesting hidden and normal contexts
+ m_undoListener.reset();
+ i_undoManager.reset();
+ final CustomUndoAction action0 = new CustomUndoAction( "action 0" );
+ i_undoManager.addUndoAction( action0 );
+ i_undoManager.enterUndoContext( "context 1" );
+ final CustomUndoAction action1 = new CustomUndoAction( "action 1" );
+ i_undoManager.addUndoAction( action1 );
+ i_undoManager.enterHiddenUndoContext();
+ final CustomUndoAction action2 = new CustomUndoAction( "action 2" );
+ i_undoManager.addUndoAction( action2 );
+ i_undoManager.enterUndoContext( "context 2" );
+ // is entering a hidden context rejected even at the nesting level > 0 (the above test was for nesting level == 0)?
+ caughtExpected = false;
+ try { i_undoManager.enterHiddenUndoContext(); }
+ catch( final EmptyUndoStackException e ) { caughtExpected = true; }
+ assertTrue( "at a nesting level > 0, denied hidden contexts does not work as expected", caughtExpected );
+ final CustomUndoAction action3 = new CustomUndoAction( "action 3" );
+ i_undoManager.addUndoAction( action3 );
+ i_undoManager.enterHiddenUndoContext();
+ assertEquals( "mixed hidden/normal context do are not properly notified", 4, m_undoListener.getCurrentUndoContextDepth() );
+ i_undoManager.leaveUndoContext();
+ assertTrue( "the left context was empty - why wasn't 'cancelled' notified?", m_undoListener.hasContextBeenCancelled() );
+ assertFalse( m_undoListener.wasContextLeft() );
+ assertFalse( m_undoListener.wasHiddenContextLeft() );
+ i_undoManager.leaveUndoContext();
+ i_undoManager.leaveUndoContext();
+ i_undoManager.leaveUndoContext();
+ i_undoManager.undo();
+ assertFalse( "one action too much has been undone", action0.undoCalled() );
+ assertTrue( action1.undoCalled() );
+ assertTrue( action2.undoCalled() );
+ assertTrue( action3.undoCalled() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private XComponentContext getContext()
+ {
+ return m_connection.getComponentContext();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private XMultiServiceFactory getORB()
+ {
+ final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, getContext().getServiceManager() );
+ return xMSF1;
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @BeforeClass
+ public static void setUpConnection() throws Exception
+ {
+ System.out.println( "--------------------------------------------------------------------------------" );
+ System.out.println( "starting class: " + UndoManager.class.getName() );
+ System.out.println( "connecting ..." );
+ m_connection.setUp();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @AfterClass
+ public static void tearDownConnection() throws InterruptedException, com.sun.star.uno.Exception
+ {
+ System.out.println();
+ System.out.println( "tearing down connection" );
+ m_connection.tearDown();
+ System.out.println( "finished class: " + UndoManager.class.getName() );
+ System.out.println( "--------------------------------------------------------------------------------" );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private static class CustomUndoAction implements XUndoAction, XComponent
+ {
+ CustomUndoAction()
+ {
+ m_title = "Custom Undo Action";
+ }
+
+ CustomUndoAction( final String i_title )
+ {
+ m_title = i_title;
+ }
+
+ public String getTitle()
+ {
+ return m_title;
+ }
+
+ public void undo() throws UndoFailedException
+ {
+ m_undoCalled = true;
+ }
+
+ public void redo() throws UndoFailedException
+ {
+ m_redoCalled = true;
+ }
+
+ public void dispose()
+ {
+ m_disposed = true;
+ }
+
+ public void addEventListener( XEventListener xl )
+ {
+ fail( "addEventListener is not expected to be called in the course of this test" );
+ }
+
+ public void removeEventListener( XEventListener xl )
+ {
+ fail( "removeEventListener is not expected to be called in the course of this test" );
+ }
+
+ boolean undoCalled() { return m_undoCalled; }
+ boolean redoCalled() { return m_redoCalled; }
+ boolean disposed() { return m_disposed; }
+
+ private final String m_title;
+ private boolean m_undoCalled = false;
+ private boolean m_redoCalled = false;
+ private boolean m_disposed = false;
+ }
+
+ private static short FAIL_UNDO = 1;
+ private static short FAIL_REDO = 2;
+
+ private static class FailingUndoAction implements XUndoAction
+ {
+ FailingUndoAction( final short i_failWhich )
+ {
+ m_failWhich = i_failWhich;
+ }
+
+ public String getTitle()
+ {
+ return "failing undo";
+ }
+
+ public void undo() throws UndoFailedException
+ {
+ if ( m_failWhich != FAIL_REDO )
+ impl_throw();
+ }
+
+ public void redo() throws UndoFailedException
+ {
+ if ( m_failWhich != FAIL_UNDO )
+ impl_throw();
+ }
+
+ private void impl_throw() throws UndoFailedException
+ {
+ throw new UndoFailedException();
+ }
+
+ private final short m_failWhich;
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private static class CountingUndoAction implements XUndoAction
+ {
+ CountingUndoAction( final int i_expectedOrder, final Object i_lock, final Integer[] i_actionsUndoneCounter )
+ {
+ m_expectedOrder = i_expectedOrder;
+ m_lock = i_lock;
+ m_actionsUndoneCounter = i_actionsUndoneCounter;
+ }
+
+ public String getTitle()
+ {
+ return "Counting Undo Action";
+ }
+
+ public void undo() throws UndoFailedException
+ {
+ synchronized( m_lock )
+ {
+ assertEquals( "Undo action called out of order", m_expectedOrder, m_actionsUndoneCounter[0].intValue() );
+ ++m_actionsUndoneCounter[0];
+ }
+ }
+
+ public void redo() throws UndoFailedException
+ {
+ fail( "CountingUndoAction.redo is not expected to be called in this test." );
+ }
+ private final int m_expectedOrder;
+ private final Object m_lock;
+ private Integer[] m_actionsUndoneCounter;
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private static String getCallbackUndoContextTitle()
+ {
+ return "Some Unfinished Undo Context";
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private static String getCallbackComponentServiceName()
+ {
+ return "org.openoffice.complex.sfx2.Callback";
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ /**
+ * a factory for a callback component which, at OOo runtime, is inserted into OOo's "component repository"
+ */
+ private class CallbackComponentFactory implements XSingleComponentFactory, XServiceInfo, XComponent
+ {
+ public Object createInstanceWithContext( XComponentContext i_context ) throws com.sun.star.uno.Exception
+ {
+ return new CallbackComponent();
+ }
+
+ public Object createInstanceWithArgumentsAndContext( Object[] i_arguments, XComponentContext i_context ) throws com.sun.star.uno.Exception
+ {
+ return createInstanceWithContext( i_context );
+ }
+
+ public String getImplementationName()
+ {
+ return "org.openoffice.complex.sfx2.CallbackComponent";
+ }
+
+ public boolean supportsService( String i_serviceName )
+ {
+ return i_serviceName.equals( getCallbackComponentServiceName() );
+ }
+
+ public String[] getSupportedServiceNames()
+ {
+ return new String[] { getCallbackComponentServiceName() };
+ }
+
+ public void dispose()
+ {
+ final EventObject event = new EventObject( this );
+
+ final ArrayList eventListenersCopy = (ArrayList)m_eventListeners.clone();
+ final Iterator iter = eventListenersCopy.iterator();
+ while ( iter.hasNext() )
+ {
+ ((XEventListener)iter.next()).disposing( event );
+ }
+ }
+
+ public void addEventListener( XEventListener i_listener )
+ {
+ if ( i_listener != null )
+ m_eventListeners.add( i_listener );
+ }
+
+ public void removeEventListener( XEventListener i_listener )
+ {
+ m_eventListeners.remove( i_listener );
+ }
+
+ private final ArrayList m_eventListeners = new ArrayList();
+ };
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private class CallbackComponent implements XJob, XTypeProvider
+ {
+ CallbackComponent()
+ {
+ }
+
+ public Object execute( NamedValue[] i_parameters ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.uno.Exception
+ {
+ // this method is called from within the Basic script which is to check whether the OOo framework
+ // properly cleans up unfinished Undo contexts. It is called immediately after the context has been
+ // entered, so verify the expected Undo manager state.
+ assertEquals( getCallbackUndoContextTitle(), m_undoListener.getCurrentUndoContextTitle() );
+ assertEquals( 1, m_undoListener.getCurrentUndoContextDepth() );
+
+ synchronized( m_callbackCondition )
+ {
+ m_callbackCalled = true;
+ m_callbackCondition.notifyAll();
+ }
+ return m_closeAfterCallback ? "close" : "";
+ }
+
+ public Type[] getTypes()
+ {
+ final Class interfaces[] = getClass().getInterfaces();
+ Type types[] = new Type[ interfaces.length ];
+ for ( int i = 0; i < interfaces.length; ++i )
+ types[i] = new Type(interfaces[i]);
+ return types;
+ }
+
+ public byte[] getImplementationId()
+ {
+ return getClass().toString().getBytes();
+ }
+ }
+
+ 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;
+ private boolean m_callbackCalled = false;
+ private boolean m_closeAfterCallback = false;
+ private final Object m_callbackCondition = new Object();
+}
diff --git a/sfx2/qa/complex/sfx2/makefile.mk b/sfx2/qa/complex/sfx2/makefile.mk
new file mode 100644
index 000000000000..20b170fba3b4
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/makefile.mk
@@ -0,0 +1,84 @@
+#*************************************************************************
+#
+# 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.
+#
+#*************************************************************************
+
+.IF "$(OOO_JUNIT_JAR)" == ""
+nothing .PHONY:
+ @echo -----------------------------------------------------
+ @echo - JUnit not available, not building anything
+ @echo -----------------------------------------------------
+.ELSE # IF "$(OOO_JUNIT_JAR)" != ""
+
+PRJ = ../../..
+PRJNAME = sfx2
+TARGET = qa_complex
+PACKAGE = complex/sfx2
+
+# --- Settings -----------------------------------------------------
+.INCLUDE: settings.mk
+
+#----- compile .java files -----------------------------------------
+
+JARFILES = OOoRunnerLight.jar ridl.jar test.jar test-tools.jar unoil.jar
+EXTRAJARFILES = $(OOO_JUNIT_JAR)
+JAVAFILES = $(shell @$(FIND) . -name "*.java") \
+
+#----- create a jar from compiled files ----------------------------
+
+JARTARGET = $(TARGET).jar
+
+#----- JUnit tests class -------------------------------------------
+
+JAVATESTFILES = \
+ DocumentInfo.java \
+ DocumentProperties.java \
+ StandaloneDocumentInfo.java \
+ DocumentMetadataAccess.java \
+ UndoManager.java \
+
+# disabled: #i115674#
+# GlobalEventBroadcaster.java \
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE: target.mk
+
+ALL : ALLTAR
+
+# --- subsequent tests ---------------------------------------------
+
+.IF "$(OOO_SUBSEQUENT_TESTS)" != ""
+
+.INCLUDE: installationtest.mk
+
+ALLTAR : javatest
+
+ # Sample how to debug
+ # JAVAIFLAGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9003,suspend=y
+
+.END # "$(OOO_SUBSEQUENT_TESTS)" == ""
+
+.END # ELSE "$(OOO_JUNIT_JAR)" != ""
diff --git a/sfx2/qa/complex/standalonedocumentinfo/StandaloneDocumentInfoTest.java b/sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest.java
index f5512bf9723b..d255f3d16822 100644
--- a/sfx2/qa/complex/standalonedocumentinfo/StandaloneDocumentInfoTest.java
+++ b/sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest.java
@@ -24,7 +24,7 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.standalonedocumentinfo;
+package complex.sfx2.standalonedocinfo;
public interface StandaloneDocumentInfoTest {
boolean test();
diff --git a/sfx2/qa/complex/standalonedocumentinfo/Test01.java b/sfx2/qa/complex/sfx2/standalonedocinfo/Test01.java
index 2f9a6266b4e2..bf54bb4ca90b 100644
--- a/sfx2/qa/complex/standalonedocumentinfo/Test01.java
+++ b/sfx2/qa/complex/sfx2/standalonedocinfo/Test01.java
@@ -24,8 +24,10 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.standalonedocumentinfo;
+package complex.sfx2.standalonedocinfo;
+import complex.sfx2.standalonedocinfo.TestHelper;
+import complex.sfx2.standalonedocinfo.StandaloneDocumentInfoTest;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.document.XStandaloneDocumentInfo;
import com.sun.star.io.XTempFile;
diff --git a/sfx2/qa/complex/standalonedocumentinfo/TestHelper.java b/sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper.java
index f6d63e1b7793..a650ce9bb2e4 100644
--- a/sfx2/qa/complex/standalonedocumentinfo/TestHelper.java
+++ b/sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper.java
@@ -24,7 +24,7 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.standalonedocumentinfo;
+package complex.sfx2.standalonedocinfo;
public class TestHelper {
diff --git a/sfx2/qa/complex/framework/testdocuments/CUSTOM.odt b/sfx2/qa/complex/sfx2/testdocuments/CUSTOM.odt
index 831a8f451dfd..831a8f451dfd 100644
--- a/sfx2/qa/complex/framework/testdocuments/CUSTOM.odt
+++ b/sfx2/qa/complex/sfx2/testdocuments/CUSTOM.odt
Binary files differ
diff --git a/sfx2/qa/complex/framework/testdocuments/TEST.odt b/sfx2/qa/complex/sfx2/testdocuments/TEST.odt
index 7c6f0b60f7b0..7c6f0b60f7b0 100644
--- a/sfx2/qa/complex/framework/testdocuments/TEST.odt
+++ b/sfx2/qa/complex/sfx2/testdocuments/TEST.odt
Binary files differ
diff --git a/sfx2/qa/complex/framework/testdocuments/TESTRDFA.odt b/sfx2/qa/complex/sfx2/testdocuments/TESTRDFA.odt
index d59739142df6..d59739142df6 100644
--- a/sfx2/qa/complex/framework/testdocuments/TESTRDFA.odt
+++ b/sfx2/qa/complex/sfx2/testdocuments/TESTRDFA.odt
Binary files differ
diff --git a/sfx2/qa/complex/framework/testdocuments/empty.rdf b/sfx2/qa/complex/sfx2/testdocuments/empty.rdf
index af62bab39dfa..af62bab39dfa 100644
--- a/sfx2/qa/complex/framework/testdocuments/empty.rdf
+++ b/sfx2/qa/complex/sfx2/testdocuments/empty.rdf
diff --git a/sfx2/qa/complex/framework/DialogThread.java b/sfx2/qa/complex/sfx2/tools/DialogThread.java
index 7151ccbb292d..e67e65f218db 100644
--- a/sfx2/qa/complex/framework/DialogThread.java
+++ b/sfx2/qa/complex/sfx2/tools/DialogThread.java
@@ -24,7 +24,7 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.framework.DocHelper;
+package complex.sfx2.tools;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XController;
@@ -37,9 +37,6 @@ import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.URL;
import com.sun.star.util.XURLTransformer;
-import java.lang.Thread;
-
-
/**
* This class opens a given dialog in a separate Thread by dispatching an url
*
@@ -55,21 +52,17 @@ public class DialogThread extends Thread {
this.m_url = url;
}
+ @Override
public void run() {
- XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
- m_xDoc);
+ XModel aModel = UnoRuntime.queryInterface( XModel.class, m_xDoc );
XController xController = aModel.getCurrentController();
//Opening Dialog
try {
- XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface(
- XDispatchProvider.class,
- xController.getFrame());
- XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface(
- XURLTransformer.class,
- m_xMSF.createInstance(
- "com.sun.star.util.URLTransformer"));
+ XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class, xController.getFrame() );
+ XURLTransformer xParser = UnoRuntime.queryInterface( XURLTransformer.class,
+ m_xMSF.createInstance( "com.sun.star.util.URLTransformer" ) );
// Because it's an in/out parameter
// we must use an array of URL objects.
diff --git a/sfx2/qa/complex/framework/TestDocument.java b/sfx2/qa/complex/sfx2/tools/TestDocument.java
index 8cc6ef7756b1..120dca978bba 100644
--- a/sfx2/qa/complex/framework/TestDocument.java
+++ b/sfx2/qa/complex/sfx2/tools/TestDocument.java
@@ -25,12 +25,12 @@
*
************************************************************************/
-package complex.framework;
+package complex.sfx2.tools;
import java.io.File;
import org.openoffice.test.OfficeFileUrl;
-final class TestDocument {
+public final class TestDocument {
public static String getUrl(String name) {
return OfficeFileUrl.getAbsolute(new File("testdocuments", name));
}
diff --git a/sfx2/qa/complex/framework/WriterHelper.java b/sfx2/qa/complex/sfx2/tools/WriterHelper.java
index d3f19703bb9d..4767028572bb 100644
--- a/sfx2/qa/complex/framework/WriterHelper.java
+++ b/sfx2/qa/complex/sfx2/tools/WriterHelper.java
@@ -24,7 +24,7 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-package complex.framework.DocHelper;
+package complex.sfx2.tools;
import com.sun.star.accessibility.AccessibleRole;
import com.sun.star.accessibility.XAccessible;
@@ -40,7 +40,6 @@ import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.XCloseable;
-import complex.framework.DocHelper.DialogThread;
import java.io.PrintWriter;
import util.AccessibilityTools;
@@ -104,13 +103,12 @@ public class WriterHelper {
if (createButton.length() > 1) {
XExtendedToolkit tk = getToolkit();
- AccessibilityTools at = new AccessibilityTools();
Object atw = tk.getActiveTopWindow();
XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, atw);
- XAccessible xRoot = at.getAccessibleObject(xWindow);
- XAccessibleContext buttonContext = at.getAccessibleObjectForRole(
+ XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
+ XAccessibleContext buttonContext = AccessibilityTools.getAccessibleObjectForRole(
xRoot,
AccessibleRole.PUSH_BUTTON,
createButton);
@@ -154,28 +152,26 @@ public class WriterHelper {
public XTextDocument DocByAutopilot(XMultiServiceFactory msf,
int[] indexes, boolean destroyLocal,
String bName) {
- XTextDocument xLocalDoc = WriterTools.createTextDoc(m_xMSF);
+ XTextDocument xTextDoc = WriterTools.createTextDoc(m_xMSF);
Object toolkit = null;
try {
toolkit = msf.createInstance("com.sun.star.awt.Toolkit");
} catch (com.sun.star.uno.Exception e) {
- e.printStackTrace();
+ e.printStackTrace( System.err );
}
XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, toolkit);
shortWait();
- AccessibilityTools at = new AccessibilityTools();
-
Object atw = tk.getActiveTopWindow();
XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, atw);
- XAccessible xRoot = at.getAccessibleObject(xWindow);
+ XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
- XAccessibleContext ARoot = at.getAccessibleObjectForRole(xRoot,
+ XAccessibleContext ARoot = AccessibilityTools.getAccessibleObjectForRole(xRoot,
AccessibleRole.MENU_BAR);
XAccessibleSelection sel = UnoRuntime.queryInterface(XAccessibleSelection.class, ARoot);
@@ -196,11 +192,11 @@ public class WriterHelper {
xWindow = UnoRuntime.queryInterface(XWindow.class, atw);
- xRoot = at.getAccessibleObject(xWindow);
+ xRoot = AccessibilityTools.getAccessibleObject(xWindow);
//at.printAccessibleTree(new PrintWriter(System.out),xRoot);
- XAccessibleAction action = UnoRuntime.queryInterface(XAccessibleAction.class, at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, bName));
+ XAccessibleAction action = UnoRuntime.queryInterface(XAccessibleAction.class, AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, bName));
try {
action.doAccessibleAction(0);
@@ -213,11 +209,11 @@ public class WriterHelper {
xWindow = UnoRuntime.queryInterface(XWindow.class, atw);
- xRoot = at.getAccessibleObject(xWindow);
+ xRoot = AccessibilityTools.getAccessibleObject(xWindow);
- at.printAccessibleTree(new PrintWriter(System.out),xRoot);
+ AccessibilityTools.printAccessibleTree(new PrintWriter(System.out),xRoot);
- action = UnoRuntime.queryInterface(XAccessibleAction.class, at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, "Yes"));
+ action = UnoRuntime.queryInterface(XAccessibleAction.class, AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, "Yes"));
try {
if (action != null) action.doAccessibleAction(0);
@@ -231,7 +227,7 @@ public class WriterHelper {
XTextDocument returnDoc = UnoRuntime.queryInterface(XTextDocument.class, xDesktop.getCurrentComponent());
if (destroyLocal) {
- closeDoc(xLocalDoc);
+ closeDoc(xTextDoc);
}
return returnDoc;
@@ -259,7 +255,7 @@ public class WriterHelper {
toolkit = m_xMSF.createInstance("com.sun.star.awt.Toolkit");
} catch (com.sun.star.uno.Exception e) {
System.out.println("Couldn't get toolkit");
- e.printStackTrace();
+ e.printStackTrace( System.err );
}
XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, toolkit);
@@ -277,7 +273,7 @@ public class WriterHelper {
desk = m_xMSF.createInstance("com.sun.star.frame.Desktop");
} catch (com.sun.star.uno.Exception e) {
System.out.println("Couldn't get desktop");
- e.printStackTrace();
+ e.printStackTrace( System.err );
}
XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, desk);
diff --git a/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java b/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java
new file mode 100755
index 000000000000..34825fdbada9
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/CalcDocumentTest.java
@@ -0,0 +1,96 @@
+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
+ * @author frank.schoenheit@oracle.com
+ */
+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 100755
index 000000000000..7c8421ec6e5b
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/ChartDocumentTest.java
@@ -0,0 +1,277 @@
+/*************************************************************************
+ * 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.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.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 );
+
+ // 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()
+ {
+ XPropertySet axisProperties = null;
+ try
+ {
+ 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 );
+ }
+ catch ( Exception ex )
+ {
+ fail( "internal error: could not retrieve primary Y axis properties" );
+ }
+ 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 100755
index 000000000000..d6de90884673
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/DocumentTest.java
@@ -0,0 +1,61 @@
+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.
+ *
+ * @author frank.schoenheit@oracle.com
+ */
+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}
+ * @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
+ * {@link 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 100755
index 000000000000..11adc80c2e85
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/DocumentTestBase.java
@@ -0,0 +1,29 @@
+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;
+
+/**
+ * @author frank.schoenheit@oracle.com
+ */
+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 100755
index 000000000000..d98e1372dea5
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/DrawDocumentTest.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 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 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";
+ }
+}
diff --git a/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java b/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java
new file mode 100755
index 000000000000..702fb85ebb11
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/undo/WriterDocumentTest.java
@@ -0,0 +1,104 @@
+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; //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.";
+}
diff --git a/sfx2/qa/complex/tests.sce b/sfx2/qa/complex/tests.sce
deleted file mode 100644
index c38852927ede..000000000000
--- a/sfx2/qa/complex/tests.sce
+++ /dev/null
@@ -1,3 +0,0 @@
--o complex.framework.DocumentMetaData
--o complex.framework.DocumentMetadataAccessTest
-#-o complex.framework.CheckGlobalEventBroadcaster_writer1