xref: /trunk/test/testuno/source/fvt/uno/sw/puretext/CharacterRelief.java (revision a7b613a6af1cb6c17f72fb50272cb23f0021e01b)
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.Test;
8 import org.openoffice.test.common.FileUtil;
9 import org.openoffice.test.common.Testspace;
10 import org.openoffice.test.uno.UnoApp;
11 //import org.openoffice.test.vcl.Tester.*;
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 CharacterRelief {
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     public void testCharacterReliefSetting() throws Exception {
34         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
35         xText = xTextDocument.getText();
36         xText.setString("we are Chinese,they are American.We are all living in one earth!"
37                 + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
38                 + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
39                 + "and we all love our home very much!!!");
40         // create text cursor for selecting and formatting text
41         XTextCursor xTextCursor = xText.createTextCursor();
42         XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
43         xTextCursor.gotoStart(false);
44         xTextCursor.goRight((short) 102, true);
45         xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.EMBOSSED));
46         xTextCursor.gotoRange(xTextCursor, false);
47         xTextCursor.goRight((short) 102, true);
48         xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.ENGRAVED));
49         xTextCursor.gotoRange(xTextCursor, false);
50         xTextCursor.goRight((short) 102, true);
51         xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.NONE));
52         //save to odt
53         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
54         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
55         aStoreProperties_odt[0] = new PropertyValue();
56         aStoreProperties_odt[1] = new PropertyValue();
57         aStoreProperties_odt[0].Name = "Override";
58         aStoreProperties_odt[0].Value = true;
59         aStoreProperties_odt[1].Name = "FilterName";
60         aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
61         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
62         //save to doc
63         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
64         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
65         aStoreProperties_doc[0] = new PropertyValue();
66         aStoreProperties_doc[1] = new PropertyValue();
67         aStoreProperties_doc[0].Name = "Override";
68         aStoreProperties_doc[0].Value = true;
69         aStoreProperties_doc[1].Name = "FilterName";
70         aStoreProperties_doc[1].Value = "MS Word 97";
71         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
72         app.closeDocument(xTextDocument);
73 
74         //reopen the document and assert row height setting
75         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
76         XTextCursor xTextCursor_assert_odt=assertDocument_odt.getText().createTextCursor();
77         XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt);
78         //verify set property
79         xTextCursor_assert_odt.gotoStart(false);
80         xTextCursor_assert_odt.goRight((short) 102, true);
81         assertEquals("assert character relief",com.sun.star.text.FontRelief.EMBOSSED,xCursorProps_assert_odt.getPropertyValue("CharRelief"));
82         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
83         xTextCursor_assert_odt.goRight((short) 102, true);
84         assertEquals("assert character relief",com.sun.star.text.FontRelief.ENGRAVED,xCursorProps_assert_odt.getPropertyValue("CharRelief"));
85         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
86         xTextCursor_assert_odt.goRight((short) 102, true);
87         assertEquals("assert character relief",com.sun.star.text.FontRelief.NONE,xCursorProps_assert_odt.getPropertyValue("CharRelief"));
88 
89         //reopen the document and assert row height setting
90         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
91         XTextCursor xTextCursor_assert_doc=assertDocument_doc.getText().createTextCursor();
92         XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc);
93         //verify set property
94         xTextCursor_assert_doc.gotoStart(false);
95         xTextCursor_assert_doc.goRight((short) 102, true);
96         assertEquals("assert character relief",com.sun.star.text.FontRelief.EMBOSSED,xCursorProps_assert_doc.getPropertyValue("CharRelief"));
97         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
98         xTextCursor_assert_doc.goRight((short) 102, true);
99         assertEquals("assert character relief",com.sun.star.text.FontRelief.ENGRAVED,xCursorProps_assert_doc.getPropertyValue("CharRelief"));
100         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
101         xTextCursor_assert_doc.goRight((short) 102, true);
102         assertEquals("assert character relief",com.sun.star.text.FontRelief.NONE,xCursorProps_assert_doc.getPropertyValue("CharRelief"));
103     }
104 }
105