Author: liuzhe
Date: Tue Aug 21 06:17:53 2012
New Revision: 1375390

URL: http://svn.apache.org/viewvc?rev=1375390&view=rev
Log:
fix two test class have errors when running

Added:
    incubator/ooo/trunk/main/test/testuno/source/testcase/mix/
    incubator/ooo/trunk/main/test/testuno/source/testcase/mix/MixedTest.java
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/crossreference/
    
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/crossreference/CheckCrossReferences.java
      - copied, changed from r1374892, 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/frame/
    
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/frame/CheckFrames.java
      - copied, changed from r1374892, 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java
      - copied, changed from r1375388, 
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUnoUtil.java
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java
Removed:
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/MixedTest.java
    
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUnoUtil.java
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/
Modified:
    incubator/ooo/trunk/main/test/testuno/.externalToolBuilders/Classpath 
Builder.launch
    
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
    
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java

Modified: incubator/ooo/trunk/main/test/testuno/.externalToolBuilders/Classpath 
Builder.launch
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/.externalToolBuilders/Classpath%20Builder.launch?rev=1375390&r1=1375389&r2=1375390&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/.externalToolBuilders/Classpath 
Builder.launch (original)
+++ incubator/ooo/trunk/main/test/testuno/.externalToolBuilders/Classpath 
Builder.launch Tue Aug 21 06:17:53 2012
@@ -4,6 +4,12 @@
 <booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
 <booleanAttribute key="org.eclipse.ant.uiSET_INPUTHANDLER" value="false"/>
 <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.ui.ATTR_CONSOLE_OUTPUT_ON" 
value="false"/>
 <booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" 
value="false"/>

Added: incubator/ooo/trunk/main/test/testuno/source/testcase/mix/MixedTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/mix/MixedTest.java?rev=1375390&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testcase/mix/MixedTest.java 
(added)
+++ incubator/ooo/trunk/main/test/testuno/source/testcase/mix/MixedTest.java 
Tue Aug 21 06:17:53 2012
@@ -0,0 +1,64 @@
+package testcase.mix;
+
+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.VclApp;
+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.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();
+       VclApp vclApp = new VclApp();
+       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"));
+       }
+}

Modified: 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java?rev=1375390&r1=1375389&r2=1375390&view=diff
==============================================================================
--- 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
 (original)
+++ 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
 Tue Aug 21 06:17:53 2012
@@ -25,7 +25,7 @@ import org.openoffice.test.common.FileUt
 import org.openoffice.test.common.Testspace;
 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.XPropertySet;
@@ -48,7 +48,7 @@ import com.sun.star.uno.UnoRuntime;
 public class CheckCharacterStyle {
 
        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 XText xShapeText = null;
        private String filePath = null;

Modified: 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java?rev=1375390&r1=1375389&r2=1375390&view=diff
==============================================================================
--- 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java
 (original)
+++ 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java
 Tue Aug 21 06:17:53 2012
@@ -22,7 +22,7 @@
 package testcase.uno.sw.bookmark;
 
 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.AfterClass;
@@ -106,7 +106,7 @@ public class CheckBookmarks {
                XTextCursor xTextCursor = xText.createTextCursor();
                xTextCursor.gotoEnd(false);
                xTextCursor.goLeft((short)10, true);
-               xTextCursor.setString("");
+               xTextCursor.setString("new");
                
                // Let's see the bookmarks
                XNameAccess xBookmarks = 
UnoRuntime.queryInterface(XBookmarksSupplier.class, document).getBookmarks();

Copied: 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/crossreference/CheckCrossReferences.java
 (from r1374892, 
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/crossreference/CheckCrossReferences.java?p2=incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/crossreference/CheckCrossReferences.java&p1=incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java&r1=1374892&r2=1375390&rev=1375390&view=diff
==============================================================================
--- 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckCrossReferences.java
 (original)
+++ 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/crossreference/CheckCrossReferences.java
 Tue Aug 21 06:17:53 2012
@@ -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.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;
@@ -44,63 +44,70 @@ import com.sun.star.text.XTextField;
 import com.sun.star.text.XTextFieldsSupplier;
 import com.sun.star.text.XTextRange;
 import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.XRefreshable;
 
 /**
  * 
- * @author od138299
  */
 public class CheckCrossReferences {
 
        private XEnumeration xParaEnum;
        private XEnumeration xPortionEnum;
        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 {
                if (xPortionEnum != null) {
                        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();
-                               if (sPortionType.equals("TextField")) {
-                                       XTextField xField = (XTextField) 
UnoRuntime.queryInterface(XTextField.class, 
xPortionProps.getPropertyValue("TextField"));
-                                       assertNotNull("Cannot retrieve next 
field.", xField);
-                                       return xField;
-                               }
+                               if (sPortionType.equals("TextField"))
+                                       return 
UnoRuntime.queryInterface(XTextField.class, 
xPortionProps.getPropertyValue("TextField"));
                        }
                }
 
                while (xParaEnum.hasMoreElements()) {
-                       XEnumerationAccess aPara = (XEnumerationAccess) 
UnoRuntime.queryInterface(XEnumerationAccess.class, xParaEnum.nextElement());
+                       XEnumerationAccess aPara = 
UnoRuntime.queryInterface(XEnumerationAccess.class, xParaEnum.nextElement());
                        xPortionEnum = aPara.createEnumeration();
                        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();
-                               if (sPortionType.equals("TextField")) {
-                                       XTextField xField = (XTextField) 
UnoRuntime.queryInterface(XTextField.class, 
xPortionProps.getPropertyValue("TextField"));
-                                       assertNotNull("Cannot retrieve next 
field.", xField);
-                                       return xField;
-                               }
+                               if (sPortionType.equals("TextField"))
+                                       return 
UnoRuntime.queryInterface(XTextField.class, 
xPortionProps.getPropertyValue("TextField"));
                        }
                }
 
-               fail("Cannot retrieve next field.");
-               return null; // unreachable
+               return null;
        }
 
        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);
        }
@@ -108,141 +115,104 @@ public class CheckCrossReferences {
        @Test
        public void checkCrossReferences() throws Exception {
                // setup paragraph enumeration
-               {
-                       XEnumerationAccess xParaEnumAccess = 
(XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, 
document.getText());
-                       xParaEnum = xParaEnumAccess.createEnumeration();
-               }
+               xParaEnum = UnoRuntime.queryInterface(XEnumerationAccess.class, 
document.getText()).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());
-               }
+               XTextFieldsSupplier xFieldSupp = 
UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
+               xFldsRefresh = UnoRuntime.queryInterface(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);
-               }
+               // 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 a certain cross-reference bookmark and a reference 
field to this bookmark
 
-                       // 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());
-                       }
+               // restart paragraph enumeration
+               xParaEnum = UnoRuntime.queryInterface(XEnumerationAccess.class, 
document.getText()).createEnumeration();
 
-                       // 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();
+               // 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;
                        }
-
-                       // 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);
-       }
+               assertNotNull("Cannot find paragraph to insert cross-reference 
bookmark.", xParaTextRange);
 
-       private XTextDocument document = null;
+               // insert bookmark
+               XMultiServiceFactory xFac = (XMultiServiceFactory) 
UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
+               final String cBookmarkName = "__RefNumPara__47114711";
+               XTextContent xBookmark = (XTextContent) 
UnoRuntime.queryInterface(XTextContent.class, 
xFac.createInstance("com.sun.star.text.Bookmark"));
+
+               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("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
-       public static void setUpConnection() throws Exception {
-               app.start();
-       }
+               // check inserted reference field
+               xField = 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));
 
-       @AfterClass
-       public static void tearDownConnection() throws InterruptedException, 
Exception {
-               app.close();
        }
 
-       private static final UnoApp app = new UnoApp();
 }

Copied: 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/frame/CheckFrames.java
 (from r1374892, 
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/frame/CheckFrames.java?p2=incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/frame/CheckFrames.java&p1=incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java&r1=1374892&r2=1375390&rev=1375390&view=diff
==============================================================================
--- 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/CheckFlies.java 
(original)
+++ 
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/frame/CheckFrames.java
 Tue Aug 21 06:17:53 2012
@@ -19,140 +19,70 @@
  * 
  *************************************************************/
 
-package testcase.uno.sw;
+package testcase.uno.sw.frame;
 
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.Collection;
+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.BeforeClass;
 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 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);
-       }
+public class CheckFrames {
 
-       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"));
+       private static final UnoApp app = new UnoApp();
 
-               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 XTextDocument document = null;
 
-       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) {
-               }
+       @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"));
 
-               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);
+               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 setUpDocument() throws Exception {
-               document = (XTextDocument) 
UnoRuntime.queryInterface(XTextDocument.class, 
app.loadDocument(Testspace.prepareData("testcase/uno/sw/CheckFlies.odt")));
-                 
+       public void setUp() throws Exception {
+               app.start();
        }
 
        @After
-       public void tearDownDocument() {
+       public void tearDown() {
                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();
 }

Copied: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java 
(from r1375388, 
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUnoUtil.java)
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java?p2=incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java&p1=incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUnoUtil.java&r1=1375388&r2=1375390&rev=1375390&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUnoUtil.java 
(original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java Tue 
Aug 21 06:17:53 2012
@@ -17,14 +17,14 @@ import com.sun.star.uno.UnoRuntime;
  * 
  *
  */
-public class SDUnoUtil {
+public class SDUtil {
 
        /**
         * @throws WrappedTargetException 
         * @throws  
         * @throws java.lang.Exception
         */
-       public SDUnoUtil(){
+       public SDUtil(){
                
        }
                

Added: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java?rev=1375390&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java (added)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java Tue 
Aug 21 06:17:53 2012
@@ -0,0 +1,60 @@
+package testlib.uno;
+
+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.XBookmarksSupplier;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.UnoRuntime;
+
+public class SWUtil {
+       
+       private static final UnoApp app = new UnoApp();
+       public static void saveAsDoc(XTextDocument document, String url) throws 
Exception {
+               saveAs(document, "MS Word 97", url);
+               
+       }
+
+       public static void saveAsODT(XTextDocument document, String url) throws 
Exception {
+               saveAs(document, "writer8", url);
+       }
+       
+       public static void saveAs(XTextDocument document, String filterValue, 
String url) throws Exception {
+               XStorable store = UnoRuntime.queryInterface(XStorable.class, 
document);
+               
+               PropertyValue[] propsValue = new PropertyValue[1];
+               propsValue[0] = new PropertyValue();
+               propsValue[0].Name = "FilterName";
+               propsValue[0].Value = filterValue;
+               store.storeAsURL(url, propsValue);
+               
+       }
+       
+       public static XTextDocument newDocument() throws Exception {
+               return (XTextDocument) 
UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
+               
+       }
+       
+       /**
+        * Insert a bookmark into text document
+        * @param document text document
+        * @param textCursor which part will be bookmarked
+        * @param bookmarkName bookmark name
+        * @throws Exception
+        */
+       public static void insertBookmark(XTextDocument document, XTextCursor 
textCursor, String bookmarkName) throws Exception {
+               XMultiServiceFactory xDocFactory = (XMultiServiceFactory) 
UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
+               Object xBookmark = 
xDocFactory.createInstance("com.sun.star.text.Bookmark");
+               XTextContent xBookmarkAsTextContent = (XTextContent) 
UnoRuntime.queryInterface(XTextContent.class, xBookmark);
+               XNamed xBookmarkAsNamed = (XNamed) 
UnoRuntime.queryInterface(XNamed.class, xBookmark);
+               xBookmarkAsNamed.setName(bookmarkName);
+               document.getText().insertTextContent(textCursor, 
xBookmarkAsTextContent, true);
+       }
+
+}


Reply via email to