Kaydet (Commit) 87e2b468 authored tarafından Liu Zhe's avatar Liu Zhe

fix two test class have errors when running

üst c312cc6e
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> <booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<booleanAttribute key="org.eclipse.ant.uiSET_INPUTHANDLER" value="false"/> <booleanAttribute key="org.eclipse.ant.uiSET_INPUTHANDLER" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${workspace}"/> <stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${workspace}"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/testuno"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.debug.core.capture_output" value="false"/> <booleanAttribute key="org.eclipse.debug.core.capture_output" value="false"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON" value="false"/> <booleanAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON" value="false"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> <booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
......
package testcase.uno; package testcase.mix;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.openoffice.test.uno.UnoApp; import org.openoffice.test.uno.UnoApp;
import org.openoffice.test.vcl.widgets.VclApp;
import org.openoffice.test.vcl.widgets.VclListBox; import org.openoffice.test.vcl.widgets.VclListBox;
import org.openoffice.test.vcl.widgets.VclTabPage; import org.openoffice.test.vcl.widgets.VclTabPage;
import org.openoffice.test.vcl.widgets.VclWindow; import org.openoffice.test.vcl.widgets.VclWindow;
import com.sun.star.beans.XPropertySet; 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.XText;
import com.sun.star.text.XTextCursor; import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument; import com.sun.star.text.XTextDocument;
...@@ -24,6 +23,7 @@ import com.sun.star.uno.UnoRuntime; ...@@ -24,6 +23,7 @@ import com.sun.star.uno.UnoRuntime;
*/ */
public class MixedTest { public class MixedTest {
UnoApp unoApp = new UnoApp(); UnoApp unoApp = new UnoApp();
VclApp vclApp = new VclApp();
VclWindow writer = new VclWindow("SW_HID_EDIT_WIN"); VclWindow writer = new VclWindow("SW_HID_EDIT_WIN");
VclTabPage effectsPage = new VclTabPage("CUI_HID_SVXPAGE_CHAR_EFFECTS"); VclTabPage effectsPage = new VclTabPage("CUI_HID_SVXPAGE_CHAR_EFFECTS");
VclListBox colorList = new VclListBox("cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR"); VclListBox colorList = new VclListBox("cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR");
......
...@@ -25,7 +25,7 @@ import org.openoffice.test.common.FileUtil; ...@@ -25,7 +25,7 @@ import org.openoffice.test.common.FileUtil;
import org.openoffice.test.common.Testspace; import org.openoffice.test.common.Testspace;
import org.openoffice.test.uno.UnoApp; import org.openoffice.test.uno.UnoApp;
import testlib.uno.SDUnoUtil; import testlib.uno.SDUtil;
import com.sun.star.beans.PropertyValue; import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet; import com.sun.star.beans.XPropertySet;
...@@ -48,7 +48,7 @@ import com.sun.star.uno.UnoRuntime; ...@@ -48,7 +48,7 @@ import com.sun.star.uno.UnoRuntime;
public class CheckCharacterStyle { public class CheckCharacterStyle {
private static final UnoApp app = new UnoApp(); private static final UnoApp app = new UnoApp();
private static final SDUnoUtil SDUtil = new SDUnoUtil(); private static final SDUtil SDUtil = new SDUtil();
private XComponent m_xSDComponent = null; private XComponent m_xSDComponent = null;
private XText xShapeText = null; private XText xShapeText = null;
private String filePath = null; private String filePath = null;
......
/**************************************************************
*
* 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();
}
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
package testcase.uno.sw.bookmark; package testcase.uno.sw.bookmark;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static testlib.uno.sw.SWUtil.insertBookmark; import static testlib.uno.SWUtil.insertBookmark;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
...@@ -106,7 +106,7 @@ public class CheckBookmarks { ...@@ -106,7 +106,7 @@ public class CheckBookmarks {
XTextCursor xTextCursor = xText.createTextCursor(); XTextCursor xTextCursor = xText.createTextCursor();
xTextCursor.gotoEnd(false); xTextCursor.gotoEnd(false);
xTextCursor.goLeft((short)10, true); xTextCursor.goLeft((short)10, true);
xTextCursor.setString(""); xTextCursor.setString("new");
// Let's see the bookmarks // Let's see the bookmarks
XNameAccess xBookmarks = UnoRuntime.queryInterface(XBookmarksSupplier.class, document).getBookmarks(); XNameAccess xBookmarks = UnoRuntime.queryInterface(XBookmarksSupplier.class, document).getBookmarks();
......
...@@ -19,14 +19,14 @@ ...@@ -19,14 +19,14 @@
* *
*************************************************************/ *************************************************************/
package testcase.uno.sw; package testcase.uno.sw.crossreference;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.openoffice.test.common.Testspace; import org.openoffice.test.common.Testspace;
import org.openoffice.test.uno.UnoApp; import org.openoffice.test.uno.UnoApp;
...@@ -44,63 +44,70 @@ import com.sun.star.text.XTextField; ...@@ -44,63 +44,70 @@ import com.sun.star.text.XTextField;
import com.sun.star.text.XTextFieldsSupplier; import com.sun.star.text.XTextFieldsSupplier;
import com.sun.star.text.XTextRange; import com.sun.star.text.XTextRange;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.XRefreshable;
/** /**
* *
* @author od138299
*/ */
public class CheckCrossReferences { public class CheckCrossReferences {
private XEnumeration xParaEnum; private XEnumeration xParaEnum;
private XEnumeration xPortionEnum; private XEnumeration xPortionEnum;
private com.sun.star.util.XRefreshable xFldsRefresh; private com.sun.star.util.XRefreshable xFldsRefresh;
private final static UnoApp app = new UnoApp();
private XTextDocument document = null;
@Before
public void setUpDocument() throws Exception {
app.start();
document = UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.prepareData("testcase/uno/sw/CheckCrossReferences.odt")));
}
@After
public void tearDownDocument() {
app.closeDocument(document);
}
@AfterClass
public static void tearDownConnection() throws InterruptedException, Exception {
app.close();
}
public XTextField getNextField() throws Exception { public XTextField getNextField() throws Exception {
if (xPortionEnum != null) { if (xPortionEnum != null) {
while (xPortionEnum.hasMoreElements()) { while (xPortionEnum.hasMoreElements()) {
XPropertySet xPortionProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPortionEnum.nextElement()); XPropertySet xPortionProps = UnoRuntime.queryInterface(XPropertySet.class, xPortionEnum.nextElement());
final String sPortionType = xPortionProps.getPropertyValue("TextPortionType").toString(); final String sPortionType = xPortionProps.getPropertyValue("TextPortionType").toString();
if (sPortionType.equals("TextField")) { if (sPortionType.equals("TextField"))
XTextField xField = (XTextField) UnoRuntime.queryInterface(XTextField.class, xPortionProps.getPropertyValue("TextField")); return UnoRuntime.queryInterface(XTextField.class, xPortionProps.getPropertyValue("TextField"));
assertNotNull("Cannot retrieve next field.", xField);
return xField;
}
} }
} }
while (xParaEnum.hasMoreElements()) { while (xParaEnum.hasMoreElements()) {
XEnumerationAccess aPara = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xParaEnum.nextElement()); XEnumerationAccess aPara = UnoRuntime.queryInterface(XEnumerationAccess.class, xParaEnum.nextElement());
xPortionEnum = aPara.createEnumeration(); xPortionEnum = aPara.createEnumeration();
while (xPortionEnum.hasMoreElements()) { while (xPortionEnum.hasMoreElements()) {
XPropertySet xPortionProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPortionEnum.nextElement()); XPropertySet xPortionProps = UnoRuntime.queryInterface(XPropertySet.class, xPortionEnum.nextElement());
final String sPortionType = xPortionProps.getPropertyValue("TextPortionType").toString(); final String sPortionType = xPortionProps.getPropertyValue("TextPortionType").toString();
if (sPortionType.equals("TextField")) { if (sPortionType.equals("TextField"))
XTextField xField = (XTextField) UnoRuntime.queryInterface(XTextField.class, xPortionProps.getPropertyValue("TextField")); return UnoRuntime.queryInterface(XTextField.class, xPortionProps.getPropertyValue("TextField"));
assertNotNull("Cannot retrieve next field.", xField);
return xField;
}
} }
} }
fail("Cannot retrieve next field."); return null;
return null; // unreachable
} }
public XPropertySet getFieldProps(XTextField xField) { public XPropertySet getFieldProps(XTextField xField) {
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xField); XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xField);
assertNotNull("Cannot retrieve field properties.", xProps);
return xProps; return xProps;
} }
public void checkField(XTextField xField, XPropertySet xProps, short nFormat, String aExpectedFldResult) throws Exception { public void checkField(XTextField xField, XPropertySet xProps, short nFormat, String aExpectedFldResult) throws Exception {
// set requested format // set requested format
xProps.setPropertyValue("ReferenceFieldPart", new Short(nFormat)); xProps.setPropertyValue("ReferenceFieldPart", new Short(nFormat));
// refresh fields in order to get new format applied // refresh fields in order to get new format applied
xFldsRefresh.refresh(); xFldsRefresh.refresh();
String aFldResult = xField.getPresentation(false); String aFldResult = xField.getPresentation(false);
assertEquals("set reference field format doesn't result in correct field result", aExpectedFldResult, aFldResult); assertEquals("set reference field format doesn't result in correct field result", aExpectedFldResult, aFldResult);
} }
...@@ -108,141 +115,104 @@ public class CheckCrossReferences { ...@@ -108,141 +115,104 @@ public class CheckCrossReferences {
@Test @Test
public void checkCrossReferences() throws Exception { public void checkCrossReferences() throws Exception {
// setup paragraph enumeration // setup paragraph enumeration
{ xParaEnum = UnoRuntime.queryInterface(XEnumerationAccess.class, document.getText()).createEnumeration();
XEnumerationAccess xParaEnumAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, document.getText());
xParaEnum = xParaEnumAccess.createEnumeration();
}
// get field refresher // get field refresher
{ XTextFieldsSupplier xFieldSupp = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
XTextFieldsSupplier xFieldSupp = (XTextFieldsSupplier) UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); xFldsRefresh = UnoRuntime.queryInterface(XRefreshable.class, xFieldSupp.getTextFields());
xFldsRefresh = (com.sun.star.util.XRefreshable) UnoRuntime.queryInterface(com.sun.star.util.XRefreshable.class, xFieldSupp.getTextFields());
} // strings for checking
final String FldResult1 = "*i*";
// check first reference field final String FldResult2 = "+b+*i*";
{ final String FldResult3 = "-1-+b+*i*";
// strings for checking final String FldResult4 = "1.";
final String FldResult1 = "*i*"; final String FldResult5 = " 1.";
final String FldResult2 = "+b+*i*"; final String FldResult6 = "A. 1.";
final String FldResult3 = "-1-+b+*i*";
final String FldResult4 = "1."; // variables for current field
final String FldResult5 = " 1."; XTextField xField = null;
final String FldResult6 = "A. 1."; XPropertySet xProps = null;
// variables for current field xField = getNextField();
XTextField xField = null; xProps = getFieldProps(xField);
XPropertySet xProps = null; checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult2);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1);
xField = getNextField(); checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3);
xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult2); xField = getNextField();
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1); xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3); checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult1);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1);
xField = getNextField(); checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3);
xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult1); xField = getNextField();
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1); xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3); checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult3);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1);
xField = getNextField(); checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3);
xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult3); xField = getNextField();
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1); xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3); checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult5);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4);
xField = getNextField(); checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6);
xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult5); xField = getNextField();
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4); xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6); checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult4);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4);
xField = getNextField(); checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6);
xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult4); xField = getNextField();
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4); xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6); checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult6);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4);
xField = getNextField(); checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6);
xProps = getFieldProps(xField);
checkField(xField, xProps, ReferenceFieldPart.NUMBER, FldResult6); // insert a certain cross-reference bookmark and a reference field to this bookmark
checkField(xField, xProps, ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4);
checkField(xField, xProps, ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6); // restart paragraph enumeration
} xParaEnum = UnoRuntime.queryInterface(XEnumerationAccess.class, document.getText()).createEnumeration();
// insert a certain cross-reference bookmark and a reference field to // iterate on the paragraphs to find certain paragraph to insert the bookmark
// this bookmark XTextRange xParaTextRange = null;
{ while (xParaEnum.hasMoreElements()) {
// restart paragraph enumeration xParaTextRange = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, xParaEnum.nextElement());
XEnumerationAccess xParaEnumAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, document.getText()); if (xParaTextRange.getString().equals("J")) {
xParaEnum = xParaEnumAccess.createEnumeration(); break;
} else {
// iterate on the paragraphs to find certain paragraph to insert the xParaTextRange = null;
// 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));
} }
} assertNotNull("Cannot find paragraph to insert cross-reference bookmark.", xParaTextRange);
@Before // insert bookmark
public void setUpDocument() throws Exception { XMultiServiceFactory xFac = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
document = UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.prepareData("testcase/uno/sw/CheckCrossReferences.odt"))); final String cBookmarkName = "__RefNumPara__47114711";
} XTextContent xBookmark = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xFac.createInstance("com.sun.star.text.Bookmark"));
@After XNamed xName = (XNamed) UnoRuntime.queryInterface(XNamed.class, xBookmark);
public void tearDownDocument() { xName.setName(cBookmarkName);
app.closeDocument(document); xBookmark.attach(xParaTextRange.getStart());
}
// insert reference field, which references the inserted bookmark
private XTextDocument document = null; XTextContent xNewField = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xFac.createInstance("com.sun.star.text.textfield.GetReference"));
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();
@BeforeClass // check inserted reference field
public static void setUpConnection() throws Exception { xField = UnoRuntime.queryInterface(XTextField.class, xNewField);
app.start(); 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));
@AfterClass
public static void tearDownConnection() throws InterruptedException, Exception {
app.close();
} }
private static final UnoApp app = new UnoApp();
} }
/**************************************************************
*
* 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.frame;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.openoffice.test.common.Testspace;
import org.openoffice.test.uno.UnoApp;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNameAccess;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextFrame;
import com.sun.star.text.XTextFramesSupplier;
import com.sun.star.uno.UnoRuntime;
public class CheckFrames {
private static final UnoApp app = new UnoApp();
private XTextDocument document = null;
@Test(expected = NoSuchElementException.class)
public void testLoadTextFrame() throws Exception {
document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.prepareData("testcase/uno/sw/CheckFlies.odt")));
XTextFramesSupplier xTFS = UnoRuntime.queryInterface(XTextFramesSupplier.class, document);
String[] expectedNames = { "Frame1", "Frame2" };
String[] expectedContents = { "PageBoundFrame", "ParaBoundFrame" };
XNameAccess xTextFrames = xTFS.getTextFrames();
assertArrayEquals("Text frame names", expectedNames, xTextFrames.getElementNames());
assertTrue("Has text frame named Frame1", xTextFrames.hasByName(expectedNames[0]));
assertFalse("Has nonexisting text frame.", xTextFrames.hasByName("Nonexisting text frame"));
XIndexAccess xTextFramesIdx = UnoRuntime.queryInterface(XIndexAccess.class, xTextFrames);
assertEquals("Text frame count", expectedNames.length, xTextFramesIdx.getCount());
String[] contents = new String[expectedNames.length];
for (int i = 0; i < xTextFramesIdx.getCount(); i++) {
Object obj = xTextFramesIdx.getByIndex(i);
XTextFrame frame = UnoRuntime.queryInterface(XTextFrame.class, obj);
contents[i] = frame.getText().getString();
}
assertArrayEquals("Text frame contents", expectedContents, contents);
xTextFrames.getByName("Nonexisting Textframe");
}
@Before
public void setUp() throws Exception {
app.start();
}
@After
public void tearDown() {
app.closeDocument(document);
}
@AfterClass
public static void tearDownConnection() throws InterruptedException, Exception {
app.close();
}
}
...@@ -17,14 +17,14 @@ import com.sun.star.uno.UnoRuntime; ...@@ -17,14 +17,14 @@ import com.sun.star.uno.UnoRuntime;
* *
* *
*/ */
public class SDUnoUtil { public class SDUtil {
/** /**
* @throws WrappedTargetException * @throws WrappedTargetException
* @throws * @throws
* @throws java.lang.Exception * @throws java.lang.Exception
*/ */
public SDUnoUtil(){ public SDUtil(){
} }
......
package testlib.uno.sw; package testlib.uno;
import org.openoffice.test.uno.UnoApp; import org.openoffice.test.uno.UnoApp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment