summaryrefslogtreecommitdiffstats
path: root/unotest/source/java/org/openoffice
diff options
context:
space:
mode:
Diffstat (limited to 'unotest/source/java/org/openoffice')
-rw-r--r--unotest/source/java/org/openoffice/test/Argument.java36
-rw-r--r--unotest/source/java/org/openoffice/test/FileHelper.java62
-rw-r--r--unotest/source/java/org/openoffice/test/OfficeConnection.java229
-rw-r--r--unotest/source/java/org/openoffice/test/OfficeFileUrl.java42
-rw-r--r--unotest/source/java/org/openoffice/test/TestArgument.java39
-rw-r--r--unotest/source/java/org/openoffice/test/UnoApiTest.java52
-rw-r--r--unotest/source/java/org/openoffice/test/makefile.mk57
-rw-r--r--unotest/source/java/org/openoffice/test/tools/DocumentType.java64
-rw-r--r--unotest/source/java/org/openoffice/test/tools/OfficeDocument.java328
-rw-r--r--unotest/source/java/org/openoffice/test/tools/OfficeDocumentView.java144
-rw-r--r--unotest/source/java/org/openoffice/test/tools/SpreadsheetDocument.java73
-rw-r--r--unotest/source/java/org/openoffice/test/tools/SpreadsheetView.java72
-rw-r--r--unotest/source/java/org/openoffice/test/tools/makefile.mk49
13 files changed, 1247 insertions, 0 deletions
diff --git a/unotest/source/java/org/openoffice/test/Argument.java b/unotest/source/java/org/openoffice/test/Argument.java
new file mode 100644
index 000000000000..0380375d8519
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/Argument.java
@@ -0,0 +1,36 @@
+/*************************************************************************
+*
+* 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 org.openoffice.test;
+
+public final class Argument {
+ public static String get(String name) {
+ return System.getProperty("org.openoffice.test.arg." + name);
+ }
+
+ private Argument() {}
+}
diff --git a/unotest/source/java/org/openoffice/test/FileHelper.java b/unotest/source/java/org/openoffice/test/FileHelper.java
new file mode 100644
index 000000000000..722b31124d43
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/FileHelper.java
@@ -0,0 +1,62 @@
+/*
+ * ************************************************************************
+ *
+ * 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 org.openoffice.test;
+
+/**
+ * Helper Functions for File handling
+ */
+public class FileHelper
+{
+ public FileHelper()
+ {
+ }
+ /**
+ * Concat a _sRelativePathToAdd to a _sPath and append a '/' to the _sPath only if need.
+ *
+ * @param _sPath
+ * @param _sRelativePathToAdd
+ * @return a right concated path
+ */
+ public static String appendPath(String _sPath, String _sRelativePathToAdd)
+ {
+ String sNewPath = _sPath;
+ String fs = System.getProperty("file.separator");
+ if (_sPath.startsWith("file:"))
+ {
+ fs = "/"; // we use a file URL so only '/' is allowed.
+ }
+ if (! (sNewPath.endsWith("/") || sNewPath.endsWith("\\") ) )
+ {
+ sNewPath += fs;
+ }
+ sNewPath += _sRelativePathToAdd;
+ return sNewPath;
+ }
+}
diff --git a/unotest/source/java/org/openoffice/test/OfficeConnection.java b/unotest/source/java/org/openoffice/test/OfficeConnection.java
new file mode 100644
index 000000000000..b05c34bc3996
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/OfficeConnection.java
@@ -0,0 +1,229 @@
+/*************************************************************************
+* 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 org.openoffice.test;
+
+import com.sun.star.bridge.UnoUrlResolver;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.comp.helper.Bootstrap;
+import com.sun.star.connection.NoConnectException;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.lang.DisposedException;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Map;
+import java.util.UUID;
+import static org.junit.Assert.*;
+
+/** Start up and shut down an OOo instance.
+
+ Details about the OOo instance are tunneled in via
+ org.openoffice.test.arg.... system properties.
+*/
+
+public final class OfficeConnection {
+ /** Start up an OOo instance.
+ */
+ public void setUp() throws Exception {
+ String sofficeArg = Argument.get("soffice");
+ if (sofficeArg.startsWith("path:")) {
+ description = "pipe,name=oootest" + UUID.randomUUID();
+ ProcessBuilder pb = new ProcessBuilder(
+ sofficeArg.substring("path:".length()), "--quickstart=no",
+ "--nofirststartwizard", "--norestore", "--nologo", "--headless",
+ "--accept=" + description + ";urp",
+ "-env:UserInstallation=" + Argument.get("user"),
+ "-env:UNO_JAVA_JFW_ENV_JREHOME=true");
+ String envArg = Argument.get("env");
+ if (envArg != null) {
+ Map<String, String> env = pb.environment();
+ int i = envArg.indexOf('=');
+ if (i == -1) {
+ env.remove(envArg);
+ } else {
+ env.put(envArg.substring(0, i), envArg.substring(i + 1));
+ }
+ }
+ process = pb.start();
+ outForward = new Forward(process.getInputStream(), System.out);
+ outForward.start();
+ errForward = new Forward(process.getErrorStream(), System.err);
+ errForward.start();
+ } else if (sofficeArg.startsWith("connect:")) {
+ description = sofficeArg.substring("connect:".length());
+ } else {
+ fail(
+ "\"soffice\" argument \"" + sofficeArg +
+ " starts with neither \"path:\" nor \"connect:\"");
+ }
+ XUnoUrlResolver resolver = UnoUrlResolver.create(
+ Bootstrap.createInitialComponentContext(null));
+ for (;;) {
+ try {
+ context = UnoRuntime.queryInterface(
+ XComponentContext.class,
+ resolver.resolve(
+ "uno:" + description +
+ ";urp;StarOffice.ComponentContext"));
+ break;
+ } catch (NoConnectException e) {}
+ if (process != null) {
+ assertNull(waitForProcess(process, 1000)); // 1 sec
+ }
+ }
+ try {
+ ProcessBuilder debugbp = new ProcessBuilder(
+ Argument.get("debugcommand").split(" "));
+ debugbp.start();
+ Thread.sleep(1000);
+ } catch(Exception e) {}
+ }
+
+ /** Shut down the OOo instance.
+ */
+ public void tearDown()
+ throws InterruptedException, com.sun.star.uno.Exception
+ {
+ boolean desktopTerminated = true;
+ if (process != null) {
+ if (context != null) {
+ XMultiComponentFactory factory = context.getServiceManager();
+ assertNotNull(factory);
+ XDesktop desktop = UnoRuntime.queryInterface(
+ XDesktop.class,
+ factory.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", context));
+ context = null;
+ try {
+ desktopTerminated = desktop.terminate();
+ } catch (DisposedException e) {}
+ // it appears that DisposedExceptions can already happen
+ // while receiving the response of the terminate call
+ desktop = null;
+ } else {
+ process.destroy();
+ }
+ }
+ int code = 0;
+ if (process != null) {
+ code = process.waitFor();
+ }
+ boolean outTerminated = outForward == null || outForward.terminated();
+ boolean errTerminated = errForward == null || errForward.terminated();
+ assertTrue(desktopTerminated);
+ assertEquals(0, code);
+ assertTrue(outTerminated);
+ assertTrue(errTerminated);
+ }
+
+ /** Obtain the component context of the running OOo instance.
+ */
+ public XComponentContext getComponentContext() {
+ return context;
+ }
+
+ //TODO: get rid of this hack for legacy qa/unoapi tests
+ public String getDescription() {
+ return description;
+ }
+
+ private static Integer waitForProcess(Process process, final long millis)
+ throws InterruptedException
+ {
+ final Thread t1 = Thread.currentThread();
+ Thread t2 = new Thread("waitForProcess") {
+ public void run() {
+ try {
+ Thread.currentThread().sleep(millis);
+ } catch (InterruptedException e) {}
+ t1.interrupt();
+ }
+ };
+ boolean old = Thread.interrupted();
+ // clear interrupted status, get old status
+ t2.start();
+ int n = 0;
+ boolean done = false;
+ try {
+ n = process.waitFor();
+ done = true;
+ } catch (InterruptedException e) {}
+ t2.interrupt();
+ try {
+ t2.join();
+ } catch (InterruptedException e) {
+ t2.join();
+ }
+ Thread.interrupted(); // clear interrupted status
+ if (old) {
+ t1.interrupt(); // reset old status
+ }
+ return done ? new Integer(n) : null;
+ }
+
+ private static final class Forward extends Thread {
+ public Forward(InputStream in, PrintStream out) {
+ super("process output forwarder");
+ this.in = in;
+ this.out = out;
+ }
+
+ public void run() {
+ for (;;) {
+ byte[] buf = new byte[1024];
+ int n;
+ try {
+ n = in.read(buf);
+ } catch (IOException e) {
+ throw new RuntimeException("wrapping", e);
+ }
+ if (n == -1) {
+ break;
+ }
+ out.write(buf, 0, n);
+ }
+ done = true;
+ }
+
+ public boolean terminated() throws InterruptedException {
+ join();
+ return done;
+ }
+
+ private final InputStream in;
+ private final PrintStream out;
+ private boolean done = false;
+ }
+
+ private String description;
+ private Process process = null;
+ private Forward outForward = null;
+ private Forward errForward = null;
+ private XComponentContext context = null;
+}
diff --git a/unotest/source/java/org/openoffice/test/OfficeFileUrl.java b/unotest/source/java/org/openoffice/test/OfficeFileUrl.java
new file mode 100644
index 000000000000..1ab62e283e6a
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/OfficeFileUrl.java
@@ -0,0 +1,42 @@
+/*************************************************************************
+*
+* 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 org.openoffice.test;
+
+import java.io.File;
+
+/** Obtain the office-internal absolute file URL of a given file.
+ */
+public final class OfficeFileUrl {
+ public static String getAbsolute(File file) {
+ return file.getAbsoluteFile().toURI().toString().replaceFirst(
+ "\\A[Ff][Ii][Ll][Ee]:/(?=[^/]|\\z)", "file:///");
+ // file:/path -> file:///path
+ }
+
+ private OfficeFileUrl() {}
+}
diff --git a/unotest/source/java/org/openoffice/test/TestArgument.java b/unotest/source/java/org/openoffice/test/TestArgument.java
new file mode 100644
index 000000000000..1303d09e1ba2
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/TestArgument.java
@@ -0,0 +1,39 @@
+/*************************************************************************
+*
+* 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 org.openoffice.test;
+
+/** Obtain the value of a test argument (tunneled in via an
+ "org.openoffice.test.arg.testarg.<name>" system property).
+ */
+public final class TestArgument {
+ public static String get(String name) {
+ return Argument.get("testarg." + name);
+ }
+
+ private TestArgument() {}
+}
diff --git a/unotest/source/java/org/openoffice/test/UnoApiTest.java b/unotest/source/java/org/openoffice/test/UnoApiTest.java
new file mode 100644
index 000000000000..fc5ba5a9c68f
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/UnoApiTest.java
@@ -0,0 +1,52 @@
+/*************************************************************************
+* 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 org.openoffice.test;
+
+import org.openoffice.Runner;
+import org.openoffice.test.OfficeConnection;
+import org.openoffice.test.Argument;
+import static org.junit.Assert.*;
+
+public final class UnoApiTest {
+ @org.junit.Before public void setUp() throws Exception {
+ connection.setUp();
+ }
+
+ @org.junit.After public void tearDown()
+ throws InterruptedException, com.sun.star.uno.Exception
+ {
+ connection.tearDown();
+ }
+
+ @org.junit.Test public void test() {
+ assertTrue(
+ Runner.run(
+ "-sce", Argument.get("sce"), "-xcl", Argument.get("xcl"), "-tdoc",
+ Argument.get("tdoc"), "-cs", connection.getDescription()));
+ }
+
+ private final OfficeConnection connection = new OfficeConnection();
+}
diff --git a/unotest/source/java/org/openoffice/test/makefile.mk b/unotest/source/java/org/openoffice/test/makefile.mk
new file mode 100644
index 000000000000..65b54d11da65
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/makefile.mk
@@ -0,0 +1,57 @@
+#*************************************************************************
+# 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.
+#***********************************************************************/
+
+PRJ = ../../../../..
+PRJNAME = test
+TARGET = test
+
+.IF "$(OOO_JUNIT_JAR)" != ""
+
+PACKAGE = org/openoffice/test
+JAVAFILES = \
+ Argument.java \
+ FileHelper.java \
+ OfficeConnection.java \
+ OfficeFileUrl.java \
+ TestArgument.java \
+ UnoApiTest.java \
+
+JARFILES = juh.jar ridl.jar unoil.jar OOoRunner.jar
+EXTRAJARFILES = $(OOO_JUNIT_JAR)
+
+JARTARGET = $(TARGET).jar
+JARCLASSDIRS = $(PACKAGE)
+JARCLASSEXCLUDES = $(PACKAGE)/tools/*
+JARCLASSPATH = $(JARFILES)
+ # expect $(OOO_JUNIT_JAR) to be on CLASSPATH wherever test.jar is used (also,
+ # on Windows, $(OOO_JUNIT_JAR) could be an absolute pathname with drive letter
+ # like X:/path and some JVMs would refuse to load test.jar if its MANIFEST.MF
+ # Class-Path contained such a pathname that looks like an unknown URL with
+ # scheme X)
+
+.END
+
+.INCLUDE: settings.mk
+.INCLUDE: target.mk
diff --git a/unotest/source/java/org/openoffice/test/tools/DocumentType.java b/unotest/source/java/org/openoffice/test/tools/DocumentType.java
new file mode 100644
index 000000000000..bf310c5ed0fa
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/tools/DocumentType.java
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * 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 org.openoffice.test.tools;
+
+/** a helper "enumeration class" for classifying a document type
+*/
+public class DocumentType extends com.sun.star.uno.Enum
+{
+ private DocumentType( int value )
+ {
+ super( value );
+ }
+
+ public static DocumentType getDefault()
+ {
+ return WRITER;
+ }
+
+ public static final DocumentType WRITER = new DocumentType(0);
+ public static final DocumentType CALC = new DocumentType(1);
+ public static final DocumentType DRAWING = new DocumentType(2);
+ public static final DocumentType XMLFORM = new DocumentType(3);
+ public static final DocumentType PRESENTATION = new DocumentType(4);
+ public static final DocumentType FORMULA = new DocumentType(5);
+ public static final DocumentType UNKNOWN = new DocumentType(-1);
+
+ public static DocumentType fromInt(int value)
+ {
+ switch(value)
+ {
+ case 0: return WRITER;
+ case 1: return CALC;
+ case 2: return DRAWING;
+ case 3: return XMLFORM;
+ case 4: return PRESENTATION;
+ case 5: return FORMULA;
+ default: return UNKNOWN;
+ }
+ }
+};
diff --git a/unotest/source/java/org/openoffice/test/tools/OfficeDocument.java b/unotest/source/java/org/openoffice/test/tools/OfficeDocument.java
new file mode 100644
index 000000000000..bfb76a347e1c
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/tools/OfficeDocument.java
@@ -0,0 +1,328 @@
+/*************************************************************************
+ *
+ * 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 org.openoffice.test.tools;
+
+import com.sun.star.beans.PropertyState;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.document.MacroExecMode;
+import com.sun.star.drawing.XDrawPage;
+import com.sun.star.drawing.XDrawPageSupplier;
+import com.sun.star.drawing.XDrawPages;
+import com.sun.star.drawing.XDrawPagesSupplier;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.util.CloseVetoException;
+import com.sun.star.util.XCloseable;
+import com.sun.star.util.XModifiable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**************************************************************************/
+
+/**************************************************************************/
+/** provides a small wrapper around a document
+*/
+public class OfficeDocument
+{
+ /* ================================================================== */
+ /* ------------------------------------------------------------------ */
+ public OfficeDocument( XMultiServiceFactory orb, XComponent document )
+ {
+ m_orb = orb;
+ m_documentComponent = document;
+ }
+
+ /* ------------------------------------------------------------------ */
+ protected static XComponent implLoadAsComponent( XMultiServiceFactory orb, String documentOrFactoryURL ) throws com.sun.star.uno.Exception
+ {
+ return implLoadAsComponent( orb, documentOrFactoryURL, new PropertyValue[0] );
+ }
+
+ /* ------------------------------------------------------------------ */
+ protected static XComponent implLoadAsComponent( XMultiServiceFactory orb, String documentOrFactoryURL, final PropertyValue[] i_args ) throws com.sun.star.uno.Exception
+ {
+ XComponentLoader aLoader = UnoRuntime.queryInterface( XComponentLoader.class,
+ orb.createInstance( "com.sun.star.frame.Desktop" ) );
+
+ XComponent document = UnoRuntime.queryInterface( XComponent.class,
+ aLoader.loadComponentFromURL( documentOrFactoryURL, "_blank", 0, i_args )
+ );
+ return document;
+ }
+
+ /* ------------------------------------------------------------------ */
+ private static OfficeDocument implLoadDocument( XMultiServiceFactory orb, String documentOrFactoryURL ) throws com.sun.star.uno.Exception
+ {
+ return implLoadDocument( orb, documentOrFactoryURL, new PropertyValue[0] );
+ }
+
+ /* ------------------------------------------------------------------ */
+ private static OfficeDocument implLoadDocument( XMultiServiceFactory orb, String documentOrFactoryURL, final PropertyValue[] i_args ) throws com.sun.star.uno.Exception
+ {
+ XComponent document = implLoadAsComponent( orb, documentOrFactoryURL, i_args );
+
+ XServiceInfo xSI = UnoRuntime.queryInterface( XServiceInfo.class, document );
+ if ( xSI.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
+ return new SpreadsheetDocument( orb, document );
+ return new OfficeDocument( orb, document );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public static OfficeDocument loadDocument( XMultiServiceFactory orb, String documentURL ) throws com.sun.star.uno.Exception
+ {
+ return implLoadDocument( orb, documentURL );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public static OfficeDocument blankTextDocument( XMultiServiceFactory orb ) throws com.sun.star.uno.Exception
+ {
+ return blankDocument( orb, DocumentType.WRITER );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public static OfficeDocument blankXMLForm( XMultiServiceFactory orb ) throws com.sun.star.uno.Exception
+ {
+ return blankDocument( orb, DocumentType.XMLFORM );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public static OfficeDocument blankDocument( XMultiServiceFactory orb, DocumentType eType ) throws com.sun.star.uno.Exception
+ {
+ final PropertyValue[] args = new PropertyValue[] {
+ new PropertyValue( "MacroExecutionMode", -1, MacroExecMode.ALWAYS_EXECUTE, PropertyState.DIRECT_VALUE )
+ };
+ return implLoadDocument( orb, getDocumentFactoryURL( eType ), args );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public boolean close()
+ {
+ try
+ {
+ XCloseable closeDoc = UnoRuntime.queryInterface( XCloseable.class, m_documentComponent );
+ closeDoc.close( true );
+ return true;
+ }
+ catch ( CloseVetoException e )
+ {
+ Logger.getLogger( OfficeDocument.class.getName() ).log( Level.SEVERE, "closing the document was vetoed", e );
+ }
+ return false;
+ }
+
+ /* ================================================================== */
+ /* ------------------------------------------------------------------ */
+ public XComponent getDocument( )
+ {
+ return m_documentComponent;
+ }
+
+ /* ------------------------------------------------------------------ */
+ public boolean isModified()
+ {
+ XModifiable modify = (XModifiable)query( XModifiable.class );
+ return modify.isModified();
+ }
+
+ /* ------------------------------------------------------------------ */
+ public Object query( Class aInterfaceClass )
+ {
+ return UnoRuntime.queryInterface( aInterfaceClass, m_documentComponent );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public XMultiServiceFactory getOrb( )
+ {
+ return m_orb;
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** retrieves the current view of the document
+ @return
+ the view component, queried for the interface described by aInterfaceClass
+ */
+ public OfficeDocumentView getCurrentView( )
+ {
+ // get the model interface for the document
+ XModel xDocModel = UnoRuntime.queryInterface( XModel.class, m_documentComponent );
+ // get the current controller for the document - as a controller is tied to a view,
+ // this gives us the currently active view for the document.
+ XController xController = xDocModel.getCurrentController();
+
+ if ( classify() == DocumentType.CALC )
+ return new SpreadsheetView( m_orb, this, xController );
+
+ return new OfficeDocumentView( m_orb, this, xController );
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** reloads the document
+ *
+ * The reload is done by dispatching the respective URL at a frame of the document.
+ * As a consequence, if you have references to a view of the document, or any interface
+ * of the document, they will become invalid.
+ * The Model instance itself, at which you called reload, will still be valid, it will
+ * automatically update its internal state after the reload.
+ *
+ * Another consequence is that if the document does not have a view at all, it cannot
+ * be reloaded.
+ */
+ public void reload() throws Exception
+ {
+ OfficeDocumentView view = getCurrentView();
+ XFrame frame = view.getController().getFrame();
+ XModel oldModel = frame.getController().getModel();
+
+ getCurrentView().dispatch( ".uno:Reload" );
+
+ m_documentComponent = UnoRuntime.queryInterface( XComponent.class, frame.getController().getModel() );
+
+ XModel newModel = getCurrentView().getController().getModel();
+ if ( UnoRuntime.areSame( oldModel, newModel ) )
+ throw new java.lang.IllegalStateException( "reload failed" );
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** returns a URL which can be used to create a document of a certain type
+ */
+ public static String getDocumentFactoryURL( DocumentType eType )
+ {
+ if ( eType == DocumentType.WRITER )
+ return "private:factory/swriter";
+ if ( eType == DocumentType.CALC )
+ return "private:factory/scalc";
+ if ( eType == DocumentType.DRAWING )
+ return "private:factory/sdraw";
+ if ( eType == DocumentType.XMLFORM )
+ return "private:factory/swriter?slot=21053";
+ if ( eType == DocumentType.PRESENTATION )
+ return "private:factory/simpress";
+ if ( eType == DocumentType.FORMULA )
+ return "private:factory/smath";
+ return "private:factory/swriter";
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** classifies a document
+ */
+ public DocumentType classify( )
+ {
+ XServiceInfo xSI = UnoRuntime.queryInterface( XServiceInfo.class, m_documentComponent );
+
+ if ( xSI.supportsService( "com.sun.star.text.TextDocument" ) )
+ return DocumentType.WRITER;
+ else if ( xSI.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
+ return DocumentType.CALC;
+ else if ( xSI.supportsService( "com.sun.star.drawing.DrawingDocument" ) )
+ return DocumentType.DRAWING;
+ else if ( xSI.supportsService( "com.sun.star.presentation.PresentationDocument" ) )
+ return DocumentType.PRESENTATION;
+ else if ( xSI.supportsService( "com.sun.star.formula.FormulaProperties" ) )
+ return DocumentType.FORMULA;
+
+ return DocumentType.UNKNOWN;
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** retrieves a com.sun.star.drawing.DrawPage of the document, denoted by index
+ * @param index
+ * the index of the draw page
+ * @throws
+ * com.sun.star.lang.IndexOutOfBoundsException
+ * com.sun.star.lang.WrappedTargetException
+ */
+ protected XDrawPage getDrawPage( int index ) throws com.sun.star.lang.IndexOutOfBoundsException, com.sun.star.lang.WrappedTargetException
+ {
+ XDrawPagesSupplier xSuppPages = UnoRuntime.queryInterface( XDrawPagesSupplier.class, getDocument() );
+ XDrawPages xPages = xSuppPages.getDrawPages();
+
+ return UnoRuntime.queryInterface( XDrawPage.class, xPages.getByIndex( index ) );
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** retrieves the <type scope="com.sun.star.drawing">DrawPage</type> of the document
+ */
+ protected XDrawPage getMainDrawPage( ) throws com.sun.star.uno.Exception
+ {
+ XDrawPage xReturn;
+
+ // in case of a Writer document, this is rather easy: simply ask the XDrawPageSupplier
+ XDrawPageSupplier xSuppPage = UnoRuntime.queryInterface( XDrawPageSupplier.class, getDocument() );
+ if ( null != xSuppPage )
+ xReturn = xSuppPage.getDrawPage();
+ else
+ { // the model itself is no draw page supplier - okay, it may be a Writer or Calc document
+ // (or any other multi-page document)
+ XDrawPagesSupplier xSuppPages = UnoRuntime.queryInterface( XDrawPagesSupplier.class, getDocument() );
+ XDrawPages xPages = xSuppPages.getDrawPages();
+
+ xReturn = UnoRuntime.queryInterface( XDrawPage.class, xPages.getByIndex( 0 ) );
+
+ // Note that this is no really error-proof code: If the document model does not support the
+ // XDrawPagesSupplier interface, or if the pages collection returned is empty, this will break.
+ }
+
+ return xReturn;
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** creates a component at the service factory provided by the document
+ */
+ public XInterface createInstance( String serviceSpecifier ) throws com.sun.star.uno.Exception
+ {
+ XMultiServiceFactory xORB = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_documentComponent );
+ return (XInterface)xORB.createInstance( serviceSpecifier );
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** creates a component at the service factory provided by the document, queried for a given interface type
+ */
+ public <T> T createInstance( String i_serviceSpecifier, Class<T> i_interfaceClass ) throws com.sun.star.uno.Exception
+ {
+ return UnoRuntime.queryInterface( i_interfaceClass, createInstance( i_serviceSpecifier ) );
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** creates a component at the service factory provided by the document
+ */
+ public XInterface createInstanceWithArguments( String serviceSpecifier, Object[] arguments ) throws com.sun.star.uno.Exception
+ {
+ XMultiServiceFactory xORB = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_documentComponent );
+ return (XInterface) xORB.createInstanceWithArguments( serviceSpecifier, arguments );
+ }
+
+ private XMultiServiceFactory m_orb;
+ private XComponent m_documentComponent;
+};
+
diff --git a/unotest/source/java/org/openoffice/test/tools/OfficeDocumentView.java b/unotest/source/java/org/openoffice/test/tools/OfficeDocumentView.java
new file mode 100644
index 000000000000..9d5db59ac009
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/tools/OfficeDocumentView.java
@@ -0,0 +1,144 @@
+/*************************************************************************
+ *
+ * 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 org.openoffice.test.tools;
+
+/**************************************************************************/
+
+import com.sun.star.beans.NamedValue;
+import com.sun.star.beans.PropertyState;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.URL;
+import com.sun.star.util.XURLTransformer;
+
+/**************************************************************************/
+/** provides a small wrapper around a document view
+*/
+public class OfficeDocumentView
+{
+ private XMultiServiceFactory m_orb;
+ private XController m_controller;
+ private OfficeDocument m_document;
+
+ /* ------------------------------------------------------------------ */
+ final public XController getController()
+ {
+ return m_controller;
+ }
+
+ /* ------------------------------------------------------------------ */
+ final protected OfficeDocument getDocument()
+ {
+ return m_document;
+ }
+
+ /* ------------------------------------------------------------------ */
+ public OfficeDocumentView( XMultiServiceFactory orb, OfficeDocument document, XController controller )
+ {
+ m_orb = orb;
+ m_document = document;
+ m_controller = controller;
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** retrieves a dispatcher for the given URL, obtained at the current view of the document
+ @param aURL
+ a one-element array. The first element must contain a valid
+ <member scope="com.sun.star.util">URL::Complete</member> value. Upon return, the URL is correctly
+ parsed.
+ @return
+ the dispatcher for the URL in question
+ */
+ public XDispatch getDispatcher( URL[] aURL ) throws com.sun.star.uno.Exception
+ {
+ XDispatch xReturn = null;
+
+ // go get the dispatch provider of it's frame
+ XDispatchProvider xProvider = UnoRuntime.queryInterface( XDispatchProvider.class, m_controller.getFrame() );
+ if ( null != xProvider )
+ {
+ // need an URLTransformer
+ XURLTransformer xTransformer = UnoRuntime.queryInterface( XURLTransformer.class,
+ m_orb.createInstance( "com.sun.star.util.URLTransformer" ) );
+ xTransformer.parseStrict( aURL );
+
+ xReturn = xProvider.queryDispatch( aURL[0], new String( ), 0 );
+ }
+ return xReturn;
+ }
+
+
+ /* ------------------------------------------------------------------ */
+ /** retrieves a dispatcher for the given URL, obtained at the current view of the document
+ */
+ public XDispatch getDispatcher( String url ) throws com.sun.star.uno.Exception
+ {
+ URL[] aURL = new URL[] { new URL() };
+ aURL[0].Complete = url;
+ return getDispatcher( aURL );
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** dispatches the given URL into the view, if there's a dispatcher for it
+
+ @return
+ <TRUE/> if the URL was successfully dispatched
+ */
+ public boolean dispatch( String i_url ) throws com.sun.star.uno.Exception
+ {
+ return dispatch( i_url, new PropertyValue[0] );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public boolean dispatch( final String i_url, final PropertyValue[] i_arguments ) throws com.sun.star.uno.Exception
+ {
+ URL[] completeURL = new URL[] { new URL() };
+ completeURL[0].Complete = i_url;
+ XDispatch dispatcher = getDispatcher( completeURL );
+ if ( dispatcher == null )
+ return false;
+
+ dispatcher.dispatch( completeURL[0], i_arguments );
+ return true;
+ }
+
+ /* ------------------------------------------------------------------ */
+ public boolean dispatch( final String i_url, final NamedValue[] i_arguments ) throws com.sun.star.uno.Exception
+ {
+ final PropertyValue[] dispatchArgs = new PropertyValue[ i_arguments.length ];
+ for ( int i=0; i<i_arguments.length; ++i )
+ {
+ dispatchArgs[i] = new PropertyValue( i_arguments[i].Name, -1, i_arguments[i].Value, PropertyState.DIRECT_VALUE );
+ }
+ return dispatch( i_url, dispatchArgs );
+ }
+};
+
diff --git a/unotest/source/java/org/openoffice/test/tools/SpreadsheetDocument.java b/unotest/source/java/org/openoffice/test/tools/SpreadsheetDocument.java
new file mode 100644
index 000000000000..83b4028eec32
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/tools/SpreadsheetDocument.java
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * 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 org.openoffice.test.tools;
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XComponent;
+import com.sun.star.table.XCellRange;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.uno.UnoRuntime;
+
+/**
+ * @author frank.schoenheit@oracle.com
+ */
+public class SpreadsheetDocument extends OfficeDocument
+{
+ /** Creates a new blank spreadsheet document */
+ /* ------------------------------------------------------------------ */
+ public SpreadsheetDocument( XMultiServiceFactory orb ) throws com.sun.star.uno.Exception
+ {
+ super( orb, implLoadAsComponent( orb, "private:factory/scalc" ) );
+ }
+
+ /* ------------------------------------------------------------------ */
+ public SpreadsheetDocument( XMultiServiceFactory orb, XComponent document ) throws com.sun.star.uno.Exception
+ {
+ super( orb, document );
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** returns the sheets collection
+ */
+ public XSpreadsheets getSheets() throws com.sun.star.uno.Exception
+ {
+ XSpreadsheetDocument spreadsheetDoc = UnoRuntime.queryInterface( XSpreadsheetDocument.class, getDocument() );
+ return spreadsheetDoc.getSheets();
+ }
+
+ /* ------------------------------------------------------------------ */
+ /** returns the sheet with the given index
+ */
+ public XCellRange getSheet( int index ) throws com.sun.star.uno.Exception
+ {
+ XIndexAccess sheets = UnoRuntime.queryInterface( XIndexAccess.class, getSheets() );
+ return UnoRuntime.queryInterface( XCellRange.class, sheets.getByIndex( index ) );
+ }
+}
diff --git a/unotest/source/java/org/openoffice/test/tools/SpreadsheetView.java b/unotest/source/java/org/openoffice/test/tools/SpreadsheetView.java
new file mode 100644
index 000000000000..34cb8b0813e4
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/tools/SpreadsheetView.java
@@ -0,0 +1,72 @@
+/*************************************************************************
+ *
+ * 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 org.openoffice.test.tools;
+
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.frame.XController;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheetView;
+import com.sun.star.uno.UnoRuntime;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author frank.schoenheit@oracle.com
+ */
+public class SpreadsheetView extends OfficeDocumentView
+{
+
+ /** Creates a new instance of SpreadsheetView */
+ public SpreadsheetView( XMultiServiceFactory orb, OfficeDocument document, XController controller )
+ {
+ super( orb, document, controller );
+ }
+
+ /** activates the sheet with the given index
+ */
+ void activateSheet( int sheetIndex )
+ {
+ try
+ {
+ // get the sheet to activate
+ XSpreadsheetDocument doc = UnoRuntime.queryInterface( XSpreadsheetDocument.class, getDocument().getDocument() );
+ XIndexAccess sheets = UnoRuntime.queryInterface( XIndexAccess.class, doc.getSheets() );
+
+ XSpreadsheet sheet = UnoRuntime.queryInterface( XSpreadsheet.class, sheets.getByIndex( sheetIndex ) );
+
+ // activate
+ XSpreadsheetView view = UnoRuntime.queryInterface( XSpreadsheetView.class, getController() );
+ view.setActiveSheet( sheet );
+ }
+ catch( com.sun.star.uno.Exception e )
+ {
+ Logger.getLogger( SpreadsheetView.class.getName() ).log( Level.SEVERE, "unable to activate the given sheet", e );
+ }
+ }
+}
diff --git a/unotest/source/java/org/openoffice/test/tools/makefile.mk b/unotest/source/java/org/openoffice/test/tools/makefile.mk
new file mode 100644
index 000000000000..1464bb958d49
--- /dev/null
+++ b/unotest/source/java/org/openoffice/test/tools/makefile.mk
@@ -0,0 +1,49 @@
+#*************************************************************************
+# 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.
+#***********************************************************************/
+
+PRJ = ../../../../../..
+PRJNAME = test
+TARGET = test-tools
+
+PACKAGE = org/openoffice/test/tools
+
+.INCLUDE: settings.mk
+
+JARFILES = juh.jar ridl.jar unoil.jar
+JAVAFILES = \
+ OfficeDocument.java \
+ OfficeDocumentView.java \
+ DocumentType.java \
+ SpreadsheetDocument.java \
+ SpreadsheetView.java \
+
+JARTARGET = $(TARGET).jar
+JARCLASSDIRS = $(PACKAGE)
+JARCLASSPATH = $(JARFILES)
+
+.INCLUDE: target.mk
+
+test:
+ echo $(JAVACLASSFILES)