xref: /AOO41X/test/testuno/source/fvt/uno/sw/puretext/CharacterHyperlink.java (revision 07d7dbdcb8e526dfaf85923a181c45494526d79d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package fvt.uno.sw.puretext;
23 
24 import static org.junit.Assert.*;
25 
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.openoffice.test.common.FileUtil;
31 import org.openoffice.test.common.Testspace;
32 import org.openoffice.test.uno.UnoApp;
33 import com.sun.star.text.*;
34 import com.sun.star.beans.*;
35 import com.sun.star.frame.XStorable;
36 import com.sun.star.uno.UnoRuntime;
37 
38 public class CharacterHyperlink {
39     private static final UnoApp app = new UnoApp();
40     XText xText = null;
41 
42     @Before
setUp()43     public void setUp() throws Exception {
44         app.start();
45 
46     }
47 
48     @After
tearDown()49     public void tearDown() throws Exception {
50         //app.close();
51     }
52 
53     @Test
54     @Ignore("Bug #120676 - hyperlink name and target lost when saving to doc")
testCharacterBackHyperlinkSetting()55     public void testCharacterBackHyperlinkSetting() throws Exception {
56         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
57         xText = xTextDocument.getText();
58         xText.setString("we are Chinese,they are American.We are all living in one earth!"
59                 + "and we all love our home very much!!!");
60         // create text cursor for selecting and formatting text
61         XTextCursor xTextCursor = xText.createTextCursor();
62         XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
63         xTextCursor.gotoStart(false);
64         xTextCursor.goRight((short) 102, true);
65         xCursorProps.setPropertyValue("HyperLinkURL", FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")));
66         xCursorProps.setPropertyValue("HyperLinkTarget","picture");
67         xCursorProps.setPropertyValue("HyperLinkName","testCharacterHyperlink");
68 
69         //save to odt
70         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
71         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
72         aStoreProperties_odt[0] = new PropertyValue();
73         aStoreProperties_odt[1] = new PropertyValue();
74         aStoreProperties_odt[0].Name = "Override";
75         aStoreProperties_odt[0].Value = true;
76         aStoreProperties_odt[1].Name = "FilterName";
77         aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
78         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
79         //save to doc
80         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
81         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
82         aStoreProperties_doc[0] = new PropertyValue();
83         aStoreProperties_doc[1] = new PropertyValue();
84         aStoreProperties_doc[0].Name = "Override";
85         aStoreProperties_doc[0].Value = true;
86         aStoreProperties_doc[1].Name = "FilterName";
87         aStoreProperties_doc[1].Value = "MS Word 97";
88         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
89         app.closeDocument(xTextDocument);
90 
91         //reopen the document and assert row height setting
92         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
93         XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
94         //verify set property
95         assertEquals("assert character hyperlink URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xCursorProps_assert_odt.getPropertyValue("HyperLinkURL"));
96         assertEquals("assert character hyperlink target name","picture",xCursorProps_assert_odt.getPropertyValue("HyperLinkTarget"));
97         assertEquals("assert character hyperlink name","testCharacterHyperlink",xCursorProps_assert_odt.getPropertyValue("HyperLinkName"));
98 
99         //reopen the document and assert row height setting
100         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
101         XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
102         //verify set property
103         assertEquals("assert character hyperlink URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xCursorProps_assert_doc.getPropertyValue("HyperLinkURL"));
104         assertEquals("assert character hyperlink target name","picture",xCursorProps_assert_doc.getPropertyValue("HyperLinkTarget"));
105         assertEquals("assert character hyperlink name","testCharacterHyperlink",xCursorProps_assert_doc.getPropertyValue("HyperLinkName"));
106     }
107 }
108