Author: liuzhe
Date: Sun Jul 22 23:47:48 2012
New Revision: 1364464
URL: http://svn.apache.org/viewvc?rev=1364464&view=rev
Log:
#120320# - [Advanced] Create new UNO API test project
Added:
incubator/ooo/trunk/main/test/testuno/
incubator/ooo/trunk/main/test/testuno/.classpath
incubator/ooo/trunk/main/test/testuno/.project
incubator/ooo/trunk/main/test/testuno/source/
incubator/ooo/trunk/main/test/testuno/source/org/
incubator/ooo/trunk/main/test/testuno/source/org/openoffice/
incubator/ooo/trunk/main/test/testuno/source/org/openoffice/test/
incubator/ooo/trunk/main/test/testuno/source/org/openoffice/test/uno/
incubator/ooo/trunk/main/test/testuno/source/org/openoffice/test/uno/UnoApp.java
incubator/ooo/trunk/main/test/testuno/source/testcase/
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/MixedTest.java
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckBookmarks.java
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.odt
(with props)
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.odt
(with props)
Added: incubator/ooo/trunk/main/test/testuno/.classpath
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/.classpath?rev=1364464&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/.classpath (added)
+++ incubator/ooo/trunk/main/test/testuno/.classpath Sun Jul 22 23:47:48 2012
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="source"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib"
path="/opt/openoffice.org/basis3.4/program/classes/unoil.jar"/>
+ <classpathentry kind="lib"
path="/opt/openoffice.org/ure/share/java/ridl.jar"/>
+ <classpathentry kind="lib"
path="/opt/openoffice.org/ure/share/java/jurt.jar"/>
+ <classpathentry kind="lib"
path="/opt/openoffice.org/ure/share/java/juh.jar"/>
+ <classpathentry combineaccessrules="false" kind="src"
path="/testcommon"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: incubator/ooo/trunk/main/test/testuno/.project
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/.project?rev=1364464&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/.project (added)
+++ incubator/ooo/trunk/main/test/testuno/.project Sun Jul 22 23:47:48 2012
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>testuno</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added:
incubator/ooo/trunk/main/test/testuno/source/org/openoffice/test/uno/UnoApp.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/org/openoffice/test/uno/UnoApp.java?rev=1364464&view=auto
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/org/openoffice/test/uno/UnoApp.java
(added)
+++
incubator/ooo/trunk/main/test/testuno/source/org/openoffice/test/uno/UnoApp.java
Sun Jul 22 23:47:48 2012
@@ -0,0 +1,164 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+package org.openoffice.test.uno;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.openoffice.test.OpenOffice;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.SystemUtil;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.bridge.UnoUrlResolver;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.comp.helper.Bootstrap;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.util.XCloseable;
+import com.sun.star.util.XModifiable;
+
+public class UnoApp {
+
+ private OpenOffice openOffice = null;
+
+ private String unoUrl = null;
+
+ private XComponentContext componentContext = null;
+
+ private XMultiComponentFactory componentFactory = null;
+
+ private XMultiServiceFactory serviceFactory = null;
+
+ private XDesktop desktop = null;
+
+ public UnoApp() {
+ this.openOffice = OpenOffice.getDefault();
+ }
+
+ /**
+ * Start OpenOffice and connect to it
+ */
+ public void start() {
+ if (openOffice != null) {
+ openOffice.start();
+ unoUrl = openOffice.getUnoUrl();
+ }
+
+ for (int i = 0; i < 3; i++) {
+ try {
+ XUnoUrlResolver resolver =
UnoUrlResolver.create(Bootstrap.createInitialComponentContext(null));
+ componentContext =
UnoRuntime.queryInterface(XComponentContext.class, resolver.resolve("uno:" +
unoUrl + ";StarOffice.ComponentContext"));
+ componentFactory =
componentContext.getServiceManager();
+ serviceFactory =
UnoRuntime.queryInterface(XMultiServiceFactory.class, componentFactory);
+ desktop =
UnoRuntime.queryInterface(XDesktop.class,
serviceFactory.createInstance("com.sun.star.comp.framework.Desktop"));
+ return;
+ } catch (Exception e) {
+ // e.printStackTrace(); // for debugging
+ }
+
+ SystemUtil.sleep(2);
+ }
+
+ throw new RuntimeException("OpenOffice can be connected!");
+ }
+
+ private Timer timer = new Timer(true);
+
+ private TimerTask timerTask = null;
+
+ /**
+ * Shut down the connection and close OpenOffice
+ */
+ public void close() {
+ try {
+ timerTask = new TimerTask() {
+ public void run() {
+ if (openOffice != null)
+ openOffice.kill();
+ }
+ };
+ timer.schedule(timerTask, 1000 * 2);
+ desktop.terminate();
+ } catch (Exception e) {
+ // e.printStackTrace(); // for debugging
+ } finally {
+ if (openOffice != null)
+ openOffice.kill();
+
+ timerTask.cancel();
+ timerTask = null;
+ componentContext = null;
+ componentFactory = null;
+ serviceFactory = null;
+ desktop = null;
+ }
+ }
+
+ /**
+ * Get the XComponentContext of the connected OpenOffice instance
+ *
+ * @return
+ */
+ public XComponentContext getComponentContext() {
+ return componentContext;
+ }
+
+ public XMultiComponentFactory getComponentFactory() {
+ return componentFactory;
+ }
+
+ public XMultiServiceFactory getServiceFactory() {
+ return serviceFactory;
+ }
+
+ public XDesktop getDesktop() {
+ return desktop;
+ }
+
+ public XComponent loadDocument(String file) throws Exception {
+ XComponentLoader componentLoader = (XComponentLoader)
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
+ return
componentLoader.loadComponentFromURL(FileUtil.getUrl(file), "_blank", 0, new
PropertyValue[0]);
+ }
+
+ public XComponent newDocument(String type) throws Exception {
+ XComponentLoader componentLoader = (XComponentLoader)
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
+ return componentLoader.loadComponentFromURL("private:factory/"
+ type, "_blank", 0, new PropertyValue[0]);
+ }
+
+ public void closeDocument(XComponent doc) {
+ try {
+ XModifiable modified = (XModifiable)
UnoRuntime.queryInterface(XModifiable.class, doc);
+ XCloseable closer = (XCloseable)
UnoRuntime.queryInterface(XCloseable.class, doc);
+ if (modified != null)
+ modified.setModified(false);
+ closer.close(true);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+}
Added: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/MixedTest.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/MixedTest.java?rev=1364464&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testcase/uno/MixedTest.java
(added)
+++ incubator/ooo/trunk/main/test/testuno/source/testcase/uno/MixedTest.java
Sun Jul 22 23:47:48 2012
@@ -0,0 +1,64 @@
+package testcase.uno;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openoffice.test.uno.UnoApp;
+import org.openoffice.test.vcl.widgets.VclListBox;
+import org.openoffice.test.vcl.widgets.VclTabPage;
+import org.openoffice.test.vcl.widgets.VclWindow;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.lang.XComponent;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.UnoRuntime;
+
+/**
+ * Demo for testing with both UNO and VCLAuto
+ * @author test
+ *
+ */
+public class MixedTest {
+ UnoApp unoApp = new UnoApp();
+ VclWindow writer = new VclWindow("SW_HID_EDIT_WIN");
+ VclTabPage effectsPage = new VclTabPage("CUI_HID_SVXPAGE_CHAR_EFFECTS");
+ VclListBox colorList = new
VclListBox("cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR");
+ XTextDocument textDocument = null;
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ unoApp.start();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ unoApp.closeDocument(textDocument);
+ unoApp.close();
+ }
+
+ @Test
+ public void testUseBothUNOAndGuiAPI() throws Exception {
+ //Use UNO API to create a new document
+ textDocument = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter"));
+ XText xText = textDocument.getText();
+ xText.setString("UNO: Hello World!");
+ //Input something by typing keyboard
+ writer.typeKeys("GUI: Hello world!");
+ //Set text color to green via GUI
+ writer.drag(10, 10, 300, 400);
+ writer.menuItem("Format->Character...").select();
+ effectsPage.select();
+ colorList.select("Light green");
+ effectsPage.ok();
+ //Verify the result via UNO API
+ XTextCursor xTextCursor = xText.createTextCursor();
+ XPropertySet xps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
+ Assert.assertEquals("Text Color", 0x0000FF00,
xps.getPropertyValue("CharColor"));
+ }
+}
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckBookmarks.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckBookmarks.java?rev=1364464&view=auto
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckBookmarks.java
(added)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckBookmarks.java
Sun Jul 22 23:47:48 2012
@@ -0,0 +1,214 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+package testcase.uno.sw;
+
+import static org.junit.Assert.*;
+
+import java.math.BigInteger;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNamed;
+import com.sun.star.frame.XStorable;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.text.ControlCharacter;
+import com.sun.star.text.XBookmarksSupplier;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextRange;
+import com.sun.star.uno.UnoRuntime;
+
+class BookmarkHashes {
+ public BigInteger m_nSetupHash;
+ public BigInteger m_nInsertRandomHash;
+ public BigInteger m_nDeleteRandomHash;
+ public BigInteger m_nLinebreakHash;
+ public BigInteger m_nOdfReloadHash;
+ public BigInteger m_nMsWordReloadHash;
+
+ public void assertExpectation(BookmarkHashes aExpectation) {
+ assertEquals(aExpectation.m_nSetupHash, m_nSetupHash);
+ assertEquals(aExpectation.m_nInsertRandomHash,
m_nInsertRandomHash);
+ assertEquals(aExpectation.m_nDeleteRandomHash,
m_nDeleteRandomHash);
+ assertEquals(aExpectation.m_nLinebreakHash, m_nLinebreakHash);
+ assertEquals(aExpectation.m_nOdfReloadHash, m_nOdfReloadHash);
+ assertEquals(aExpectation.m_nMsWordReloadHash,
m_nMsWordReloadHash);
+ }
+
+ static public java.math.BigInteger getBookmarksHash(XTextDocument xDoc)
throws Exception {
+ StringBuffer buffer = new StringBuffer("");
+ XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
UnoRuntime.queryInterface(XBookmarksSupplier.class, xDoc);
+ XNameAccess xBookmarks = xBookmarksSupplier.getBookmarks();
+ for (String sBookmarkname : xBookmarks.getElementNames()) {
+ Object xBookmark = xBookmarks.getByName(sBookmarkname);
+ XTextContent xBookmarkAsContent = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, xBookmark);
+ buffer.append(sBookmarkname);
+ buffer.append(":");
+
buffer.append(xBookmarkAsContent.getAnchor().getString());
+ buffer.append(";");
+ }
+ java.security.MessageDigest sha1 =
java.security.MessageDigest.getInstance("SHA-1");
+ sha1.reset();
+ sha1.update(buffer.toString().getBytes());
+ return new java.math.BigInteger(sha1.digest());
+ }
+}
+
+public class CheckBookmarks {
+ private XTextDocument m_xDoc = null;
+ private XTextDocument m_xOdfReloadedDoc = null;
+ private XTextDocument m_xMsWordReloadedDoc = null;
+ private final BookmarkHashes actualHashes = new BookmarkHashes();
+
+ private BookmarkHashes getDEV300m41Expectations() {
+ BookmarkHashes result = new BookmarkHashes();
+ result.m_nSetupHash = new
BigInteger("-4b0706744e8452fe1ae9d5e1c28cf70fb6194795", 16);
+ result.m_nInsertRandomHash = new
BigInteger("25aa0fad3f4881832dcdfe658ec2efa8a1a02bc5", 16);
+ result.m_nDeleteRandomHash = new
BigInteger("-3ec87e810b46d734677c351ad893bbbf9ea10f55", 16);
+ result.m_nLinebreakHash = new
BigInteger("3ae08c284ea0d6e738cb43c0a8105e718a633550", 16);
+ result.m_nOdfReloadHash = new
BigInteger("3ae08c284ea0d6e738cb43c0a8105e718a633550", 16);
+ result.m_nMsWordReloadHash = new
BigInteger("3ae08c284ea0d6e738cb43c0a8105e718a633550", 16);
+ return result;
+ }
+
+ @Test
+ public void checkBookmarks() throws Exception {
+ actualHashes.assertExpectation(getDEV300m41Expectations());
+ }
+
+ @Before
+ public void setUpDocuments() throws Exception {
+ m_xDoc = UnoRuntime.queryInterface(XTextDocument.class,
app.newDocument("swriter"));
+ setupBookmarks();
+ actualHashes.m_nSetupHash =
BookmarkHashes.getBookmarksHash(m_xDoc);
+ insertRandomParts(200177);
+ actualHashes.m_nInsertRandomHash =
BookmarkHashes.getBookmarksHash(m_xDoc);
+ deleteRandomParts(4711);
+ actualHashes.m_nDeleteRandomHash =
BookmarkHashes.getBookmarksHash(m_xDoc);
+ insertLinebreaks(007);
+ actualHashes.m_nLinebreakHash =
BookmarkHashes.getBookmarksHash(m_xDoc);
+ m_xOdfReloadedDoc = reloadFrom("StarOffice XML (Writer)",
"odf");
+ actualHashes.m_nOdfReloadHash =
BookmarkHashes.getBookmarksHash(m_xOdfReloadedDoc);
+ m_xMsWordReloadedDoc = reloadFrom("MS Word 97", "doc");
+ actualHashes.m_nMsWordReloadHash =
BookmarkHashes.getBookmarksHash(m_xMsWordReloadedDoc);
+ }
+
+ @After
+ public void tearDownDocuments() {
+ app.closeDocument(m_xDoc);
+ app.closeDocument(m_xOdfReloadedDoc);
+ app.closeDocument(m_xMsWordReloadedDoc);
+ }
+
+ @BeforeClass
+ public static void setUpConnection() throws Exception {
+ app.start();
+ }
+
+ @AfterClass
+ public static void tearDownConnection() throws Exception {
+ app.close();
+ }
+
+ private static final UnoApp app = new UnoApp();
+
+ private void setupBookmarks() throws Exception {
+ XText xText = m_xDoc.getText();
+ for (int nPara = 0; nPara < 10; ++nPara) {
+ for (int nBookmark = 0; nBookmark < 100; ++nBookmark) {
+ insertBookmark(xText.createTextCursor(), "P" +
nPara + "word" + nBookmark, "P" + nPara + "word" + nBookmark);
+ XTextCursor xWordCrsr =
xText.createTextCursor();
+ xWordCrsr.setString(" ");
+ }
+ XTextCursor xParaCrsr = xText.createTextCursor();
+ XTextRange xParaCrsrAsRange = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, xParaCrsr);
+ xText.insertControlCharacter(xParaCrsrAsRange,
ControlCharacter.PARAGRAPH_BREAK, false);
+ }
+ }
+
+ private void insertRandomParts(long seed) throws Exception {
+ java.util.Random rnd = new java.util.Random(seed);
+ XTextCursor xCrsr = m_xDoc.getText().createTextCursor();
+ for (int i = 0; i < 600; i++) {
+ xCrsr.goRight((short) rnd.nextInt(100), false);
+ xCrsr.setString(Long.toString(rnd.nextLong()));
+ }
+ }
+
+ private void deleteRandomParts(long seed) throws Exception {
+ java.util.Random rnd = new java.util.Random(seed);
+ XTextCursor xCrsr = m_xDoc.getText().createTextCursor();
+ for (int i = 0; i < 600; i++) {
+ xCrsr.goRight((short) rnd.nextInt(100), false);
+ xCrsr.goRight((short) rnd.nextInt(20), true);
+ xCrsr.setString("");
+ }
+ }
+
+ private void insertLinebreaks(long seed) throws Exception {
+ XText xText = m_xDoc.getText();
+ java.util.Random rnd = new java.util.Random(seed);
+ XTextCursor xCrsr = m_xDoc.getText().createTextCursor();
+ for (int i = 0; i < 30; i++) {
+ xCrsr.goRight((short) rnd.nextInt(300), false);
+ XTextRange xCrsrAsRange = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, xCrsr);
+ xText.insertControlCharacter(xCrsrAsRange,
ControlCharacter.PARAGRAPH_BREAK, false);
+ }
+ }
+
+ private void insertBookmark(XTextCursor crsr, String name, String
content) throws Exception {
+ XMultiServiceFactory xDocFactory = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xDoc);
+
+ Object xBookmark =
xDocFactory.createInstance("com.sun.star.text.Bookmark");
+ XTextContent xBookmarkAsTextContent = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, xBookmark);
+ crsr.setString(content);
+ XNamed xBookmarkAsNamed = (XNamed)
UnoRuntime.queryInterface(XNamed.class, xBookmark);
+ xBookmarkAsNamed.setName(name);
+ m_xDoc.getText().insertTextContent(crsr,
xBookmarkAsTextContent, true);
+ }
+
+ private XTextDocument reloadFrom(String sFilter, String sExtension)
throws Exception {
+ String filePath = Testspace.getPath("output/Bookmarktest." +
sExtension);
+ PropertyValue[] aStoreProperties = new PropertyValue[2];
+ aStoreProperties[0] = new PropertyValue();
+ aStoreProperties[1] = new PropertyValue();
+ aStoreProperties[0].Name = "Override";
+ aStoreProperties[0].Value = true;
+ aStoreProperties[1].Name = "FilterName";
+ aStoreProperties[1].Value = sFilter;
+ XStorable xStorable = (XStorable)
UnoRuntime.queryInterface(XStorable.class, m_xDoc);
+ xStorable.storeToURL(FileUtil.getUrl(filePath),
aStoreProperties);
+
+ return UnoRuntime.queryInterface(XTextDocument.class,
app.loadDocument(filePath));
+ }
+}
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java?rev=1364464&view=auto
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java
(added)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java
Sun Jul 22 23:47:48 2012
@@ -0,0 +1,248 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+package testcase.uno.sw;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XEnumerationAccess;
+import com.sun.star.container.XNamed;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.text.ReferenceFieldPart;
+import com.sun.star.text.ReferenceFieldSource;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextField;
+import com.sun.star.text.XTextFieldsSupplier;
+import com.sun.star.text.XTextRange;
+import com.sun.star.uno.UnoRuntime;
+
+/**
+ *
+ * @author od138299
+ */
+public class CheckCrossReferences {
+
+ private XEnumeration xParaEnum;
+ private XEnumeration xPortionEnum;
+ private com.sun.star.util.XRefreshable xFldsRefresh;
+
+ public XTextField getNextField() throws Exception {
+ if (xPortionEnum != null) {
+ while (xPortionEnum.hasMoreElements()) {
+ XPropertySet xPortionProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xPortionEnum.nextElement());
+ final String sPortionType =
xPortionProps.getPropertyValue("TextPortionType").toString();
+ if (sPortionType.equals("TextField")) {
+ XTextField xField = (XTextField)
UnoRuntime.queryInterface(XTextField.class,
xPortionProps.getPropertyValue("TextField"));
+ assertNotNull("Cannot retrieve next
field.", xField);
+ return xField;
+ }
+ }
+ }
+
+ while (xParaEnum.hasMoreElements()) {
+ XEnumerationAccess aPara = (XEnumerationAccess)
UnoRuntime.queryInterface(XEnumerationAccess.class, xParaEnum.nextElement());
+ xPortionEnum = aPara.createEnumeration();
+ while (xPortionEnum.hasMoreElements()) {
+ XPropertySet xPortionProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xPortionEnum.nextElement());
+ final String sPortionType =
xPortionProps.getPropertyValue("TextPortionType").toString();
+ if (sPortionType.equals("TextField")) {
+ XTextField xField = (XTextField)
UnoRuntime.queryInterface(XTextField.class,
xPortionProps.getPropertyValue("TextField"));
+ assertNotNull("Cannot retrieve next
field.", xField);
+ return xField;
+ }
+ }
+ }
+
+ fail("Cannot retrieve next field.");
+ return null; // unreachable
+ }
+
+ public XPropertySet getFieldProps(XTextField xField) {
+ XPropertySet xProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xField);
+
+ assertNotNull("Cannot retrieve field properties.", xProps);
+
+ return xProps;
+ }
+
+ public void checkField(XTextField xField, XPropertySet xProps, short
nFormat, String aExpectedFldResult) throws Exception {
+ // set requested format
+ xProps.setPropertyValue("ReferenceFieldPart", new
Short(nFormat));
+
+ // refresh fields in order to get new format applied
+ xFldsRefresh.refresh();
+
+ String aFldResult = xField.getPresentation(false);
+ assertEquals("set reference field format doesn't result in
correct field result", aExpectedFldResult, aFldResult);
+ }
+
+ @Test
+ public void checkCrossReferences() throws Exception {
+ // setup paragraph enumeration
+ {
+ XEnumerationAccess xParaEnumAccess =
(XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class,
document.getText());
+ xParaEnum = xParaEnumAccess.createEnumeration();
+ }
+
+ // get field refresher
+ {
+ XTextFieldsSupplier xFieldSupp = (XTextFieldsSupplier)
UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
+ xFldsRefresh = (com.sun.star.util.XRefreshable)
UnoRuntime.queryInterface(com.sun.star.util.XRefreshable.class,
xFieldSupp.getTextFields());
+ }
+
+ // check first reference field
+ {
+ // strings for checking
+ final String FldResult1 = "*i*";
+ final String FldResult2 = "+b+*i*";
+ final String FldResult3 = "-1-+b+*i*";
+ final String FldResult4 = "1.";
+ final String FldResult5 = " 1.";
+ final String FldResult6 = "A. 1.";
+
+ // variables for current field
+ XTextField xField = null;
+ XPropertySet xProps = null;
+
+ xField = getNextField();
+ xProps = getFieldProps(xField);
+ checkField(xField, xProps, ReferenceFieldPart.NUMBER,
FldResult2);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3);
+
+ xField = getNextField();
+ xProps = getFieldProps(xField);
+ checkField(xField, xProps, ReferenceFieldPart.NUMBER,
FldResult1);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3);
+
+ xField = getNextField();
+ xProps = getFieldProps(xField);
+ checkField(xField, xProps, ReferenceFieldPart.NUMBER,
FldResult3);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3);
+
+ xField = getNextField();
+ xProps = getFieldProps(xField);
+ checkField(xField, xProps, ReferenceFieldPart.NUMBER,
FldResult5);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6);
+
+ xField = getNextField();
+ xProps = getFieldProps(xField);
+ checkField(xField, xProps, ReferenceFieldPart.NUMBER,
FldResult4);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6);
+
+ xField = getNextField();
+ xProps = getFieldProps(xField);
+ checkField(xField, xProps, ReferenceFieldPart.NUMBER,
FldResult6);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4);
+ checkField(xField, xProps,
ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6);
+ }
+
+ // insert a certain cross-reference bookmark and a reference
field to
+ // this bookmark
+ {
+ // restart paragraph enumeration
+ XEnumerationAccess xParaEnumAccess =
(XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class,
document.getText());
+ xParaEnum = xParaEnumAccess.createEnumeration();
+
+ // iterate on the paragraphs to find certain paragraph
to insert the
+ // bookmark
+ XTextRange xParaTextRange = null;
+ while (xParaEnum.hasMoreElements()) {
+ xParaTextRange = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, xParaEnum.nextElement());
+ if (xParaTextRange.getString().equals("J")) {
+ break;
+ } else {
+ xParaTextRange = null;
+ }
+ }
+ assertNotNull("Cannot find paragraph to insert
cross-reference bookmark.", xParaTextRange);
+
+ // insert bookmark
+ XMultiServiceFactory xFac = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
+ final String cBookmarkName = "__RefNumPara__47114711";
+ XTextContent xBookmark = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, xFac.createInstance("Bookmark"));
+ if (xBookmark != null) {
+ XNamed xName = (XNamed)
UnoRuntime.queryInterface(XNamed.class, xBookmark);
+ xName.setName(cBookmarkName);
+ xBookmark.attach(xParaTextRange.getStart());
+ }
+
+ // insert reference field, which references the
inserted bookmark
+ XTextContent xNewField = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class,
xFac.createInstance("TextField.GetReference"));
+ if (xNewField != null) {
+ XPropertySet xFieldProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xNewField);
+
xFieldProps.setPropertyValue("ReferenceFieldPart", new
Short(ReferenceFieldPart.TEXT));
+
xFieldProps.setPropertyValue("ReferenceFieldSource", new
Short(ReferenceFieldSource.BOOKMARK));
+ xFieldProps.setPropertyValue("SourceName",
cBookmarkName);
+ XTextRange xFieldTextRange = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, xParaEnum.nextElement());
+ xNewField.attach(xFieldTextRange.getEnd());
+ xFldsRefresh.refresh();
+ }
+
+ // check inserted reference field
+ XTextField xField = (XTextField)
UnoRuntime.queryInterface(XTextField.class, xNewField);
+ assertEquals("inserted reference field doesn't has
correct field result", "J", xField.getPresentation(false));
+
+ xParaTextRange.getStart().setString("Hallo new
bookmark: ");
+ xFldsRefresh.refresh();
+ assertEquals("inserted reference field doesn't has
correct field result", "Hallo new bookmark: J", xField.getPresentation(false));
+ }
+ }
+
+ @Before
+ public void setUpDocument() throws Exception {
+ document = UnoRuntime.queryInterface(XTextDocument.class,
app.loadDocument(Testspace.prepareData("testcase/uno/sw/CheckCrossReferences.odt")));
+ }
+
+ @After
+ public void tearDownDocument() {
+ app.closeDocument(document);
+ }
+
+ private XTextDocument document = null;
+
+ @BeforeClass
+ public static void setUpConnection() throws Exception {
+ app.start();
+ }
+
+ @AfterClass
+ public static void tearDownConnection() throws InterruptedException,
Exception {
+ app.close();
+ }
+
+ private static final UnoApp app = new UnoApp();
+}
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.odt
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.odt?rev=1364464&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.odt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java?rev=1364464&view=auto
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java
(added)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java
Sun Jul 22 23:47:48 2012
@@ -0,0 +1,158 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+package testcase.uno.sw;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.UnoRuntime;
+
+public class CheckFlies {
+ @Test
+ public void checkFlies() throws Exception {
+ com.sun.star.text.XTextFramesSupplier xTFS =
(com.sun.star.text.XTextFramesSupplier) UnoRuntime.queryInterface(
+ com.sun.star.text.XTextFramesSupplier.class,
document);
+ checkTextFrames(xTFS);
+ com.sun.star.text.XTextGraphicObjectsSupplier xTGOS =
(com.sun.star.text.XTextGraphicObjectsSupplier) UnoRuntime.queryInterface(
+
com.sun.star.text.XTextGraphicObjectsSupplier.class, document);
+ checkGraphicFrames(xTGOS);
+ com.sun.star.text.XTextEmbeddedObjectsSupplier xTEOS =
(com.sun.star.text.XTextEmbeddedObjectsSupplier) UnoRuntime.queryInterface(
+
com.sun.star.text.XTextEmbeddedObjectsSupplier.class, document);
+ checkEmbeddedFrames(xTEOS);
+ }
+
+ private void
checkEmbeddedFrames(com.sun.star.text.XTextEmbeddedObjectsSupplier xTGOS)
throws Exception {
+ Collection<String> vExpectedEmbeddedFrames = new
ArrayList<String>();
+ vExpectedEmbeddedFrames.add("Object1");
+ int nEmbeddedFrames = vExpectedEmbeddedFrames.size();
+ com.sun.star.container.XNameAccess xEmbeddedFrames =
xTGOS.getEmbeddedObjects();
+ for (String sFrameName : xEmbeddedFrames.getElementNames()) {
+ assertTrue("Unexpected frame name",
vExpectedEmbeddedFrames.remove(sFrameName));
+ xEmbeddedFrames.getByName(sFrameName);
+ assertTrue("Could not find embedded frame by name.",
xEmbeddedFrames.hasByName(sFrameName));
+ }
+ assertTrue("Missing expected embedded frames.",
vExpectedEmbeddedFrames.isEmpty());
+ try {
+ xEmbeddedFrames.getByName("Nonexisting embedded frame");
+ fail("Got nonexisting embedded frame");
+ } catch (com.sun.star.container.NoSuchElementException e) {
+ }
+ assertFalse("Has nonexisting embedded frame",
xEmbeddedFrames.hasByName("Nonexisting embedded frame"));
+
+ com.sun.star.container.XIndexAccess xEmbeddedFramesIdx =
(com.sun.star.container.XIndexAccess) UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class,
xEmbeddedFrames);
+ assertEquals("Unexpected number of embedded frames reported.",
nEmbeddedFrames, xEmbeddedFramesIdx.getCount());
+ for (int nCurrentFrameIdx = 0; nCurrentFrameIdx <
xEmbeddedFramesIdx.getCount(); nCurrentFrameIdx++) {
+ xEmbeddedFramesIdx.getByIndex(nCurrentFrameIdx);
+ }
+ }
+
+ private void
checkGraphicFrames(com.sun.star.text.XTextGraphicObjectsSupplier xTGOS) throws
Exception {
+ Collection<String> vExpectedGraphicFrames = new
ArrayList<String>();
+ vExpectedGraphicFrames.add("graphics1");
+ int nGraphicFrames = vExpectedGraphicFrames.size();
+ com.sun.star.container.XNameAccess xGraphicFrames =
xTGOS.getGraphicObjects();
+ for (String sFrameName : xGraphicFrames.getElementNames()) {
+ assertTrue("Unexpected frame name",
vExpectedGraphicFrames.remove(sFrameName));
+ xGraphicFrames.getByName(sFrameName);
+ assertTrue("Could not find graphics frame by name.",
xGraphicFrames.hasByName(sFrameName));
+ }
+ assertTrue("Missing expected graphics frames.",
vExpectedGraphicFrames.isEmpty());
+ try {
+ xGraphicFrames.getByName("Nonexisting graphics frame");
+ fail("Got nonexisting graphics frame");
+ } catch (com.sun.star.container.NoSuchElementException e) {
+ }
+ assertFalse("Has nonexisting graphics frame",
xGraphicFrames.hasByName("Nonexisting graphics frame"));
+
+ com.sun.star.container.XIndexAccess xGraphicFramesIdx =
(com.sun.star.container.XIndexAccess) UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class,
xGraphicFrames);
+ assertEquals("Unexpected number of graphics frames reported.",
nGraphicFrames, xGraphicFramesIdx.getCount());
+ for (int nCurrentFrameIdx = 0; nCurrentFrameIdx <
xGraphicFramesIdx.getCount(); nCurrentFrameIdx++) {
+ xGraphicFramesIdx.getByIndex(nCurrentFrameIdx);
+ }
+ }
+
+ private void checkTextFrames(com.sun.star.text.XTextFramesSupplier
xTFS) throws Exception {
+ Collection<String> vExpectedTextFrames = new
ArrayList<String>();
+ vExpectedTextFrames.add("Frame1");
+ vExpectedTextFrames.add("Frame2");
+
+ int nTextFrames = vExpectedTextFrames.size();
+ com.sun.star.container.XNameAccess xTextFrames =
xTFS.getTextFrames();
+ for (String sFrameName : xTextFrames.getElementNames()) {
+ assertTrue("Unexpected frame name",
vExpectedTextFrames.remove(sFrameName));
+ xTextFrames.getByName(sFrameName);
+ assertTrue("Could not find text frame by name.",
xTextFrames.hasByName(sFrameName));
+ }
+ assertTrue("Missing expected text frames.",
vExpectedTextFrames.isEmpty());
+ try {
+ xTextFrames.getByName("Nonexisting Textframe");
+ fail("Got nonexisting text frame.");
+ } catch (com.sun.star.container.NoSuchElementException e) {
+ }
+ assertFalse("Has nonexisting text frame.",
xTextFrames.hasByName("Nonexisting text frame"));
+
+ com.sun.star.container.XIndexAccess xTextFramesIdx =
(com.sun.star.container.XIndexAccess) UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class,
xTextFrames);
+ assertEquals("Unexpected number of text frames reported.",
nTextFrames, xTextFramesIdx.getCount());
+ for (int nCurrentFrameIdx = 0; nCurrentFrameIdx <
xTextFramesIdx.getCount(); nCurrentFrameIdx++) {
+ xTextFramesIdx.getByIndex(nCurrentFrameIdx);
+ }
+ }
+
+ @Before
+ public void setUpDocument() throws Exception {
+ document = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class,
app.loadDocument(Testspace.prepareData("testcase/uno/sw/CheckFlies.odt")));
+
+ }
+
+ @After
+ public void tearDownDocument() {
+ app.closeDocument(document);
+ }
+
+ private XTextDocument document = null;
+
+ @BeforeClass
+ public static void setUpConnection() throws Exception {
+ app.start();
+ }
+
+ @AfterClass
+ public static void tearDownConnection() throws InterruptedException,
Exception {
+ app.close();
+ }
+
+ private static final UnoApp app = new UnoApp();
+}
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.odt
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.odt?rev=1364464&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.odt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream