xref: /trunk/test/testuno/source/fvt/uno/sw/puretext/CharacterHyperlink.java (revision 45e2f390c041b30a26ca2aee1e99e305783ca105)
1 package fvt.uno.sw.puretext;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Ignore;
8 import org.junit.Test;
9 import org.openoffice.test.common.FileUtil;
10 import org.openoffice.test.common.Testspace;
11 import org.openoffice.test.uno.UnoApp;
12 import com.sun.star.text.*;
13 import com.sun.star.beans.*;
14 import com.sun.star.frame.XStorable;
15 import com.sun.star.uno.UnoRuntime;
16 
17 public class CharacterHyperlink {
18     private static final UnoApp app = new UnoApp();
19     XText xText = null;
20 
21     @Before
22     public void setUp() throws Exception {
23         app.start();
24 
25     }
26 
27     @After
28     public void tearDown() throws Exception {
29         //app.close();
30     }
31 
32     @Test
33     @Ignore("Bug #120676 - hyperlink name and target lost when saving to doc")
34     public void testCharacterBackHyperlinkSetting() throws Exception {
35         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
36         xText = xTextDocument.getText();
37         xText.setString("we are Chinese,they are American.We are all living in one earth!"
38                 + "and we all love our home very much!!!");
39         // create text cursor for selecting and formatting text
40         XTextCursor xTextCursor = xText.createTextCursor();
41         XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
42         xTextCursor.gotoStart(false);
43         xTextCursor.goRight((short) 102, true);
44         xCursorProps.setPropertyValue("HyperLinkURL", FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")));
45         xCursorProps.setPropertyValue("HyperLinkTarget","picture");
46         xCursorProps.setPropertyValue("HyperLinkName","testCharacterHyperlink");
47 
48         //save to odt
49         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
50         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
51         aStoreProperties_odt[0] = new PropertyValue();
52         aStoreProperties_odt[1] = new PropertyValue();
53         aStoreProperties_odt[0].Name = "Override";
54         aStoreProperties_odt[0].Value = true;
55         aStoreProperties_odt[1].Name = "FilterName";
56         aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
57         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
58         //save to doc
59         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
60         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
61         aStoreProperties_doc[0] = new PropertyValue();
62         aStoreProperties_doc[1] = new PropertyValue();
63         aStoreProperties_doc[0].Name = "Override";
64         aStoreProperties_doc[0].Value = true;
65         aStoreProperties_doc[1].Name = "FilterName";
66         aStoreProperties_doc[1].Value = "MS Word 97";
67         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
68         app.closeDocument(xTextDocument);
69 
70         //reopen the document and assert row height setting
71         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
72         XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
73         //verify set property
74         assertEquals("assert character hyperlink URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xCursorProps_assert_odt.getPropertyValue("HyperLinkURL"));
75         assertEquals("assert character hyperlink target name","picture",xCursorProps_assert_odt.getPropertyValue("HyperLinkTarget"));
76         assertEquals("assert character hyperlink name","testCharacterHyperlink",xCursorProps_assert_odt.getPropertyValue("HyperLinkName"));
77 
78         //reopen the document and assert row height setting
79         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
80         XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
81         //verify set property
82         assertEquals("assert character hyperlink URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xCursorProps_assert_doc.getPropertyValue("HyperLinkURL"));
83         assertEquals("assert character hyperlink target name","picture",xCursorProps_assert_doc.getPropertyValue("HyperLinkTarget"));
84         assertEquals("assert character hyperlink name","testCharacterHyperlink",xCursorProps_assert_doc.getPropertyValue("HyperLinkName"));
85     }
86 }
87