xref: /trunk/test/testuno/source/fvt/uno/sw/puretext/CharacterEmphasis.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.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 org.openoffice.test.vcl.Tester.*;
13 import com.sun.star.text.*;
14 import com.sun.star.beans.*;
15 import com.sun.star.frame.XStorable;
16 import com.sun.star.uno.UnoRuntime;
17 
18 public class CharacterEmphasis {
19     private static final UnoApp app = new UnoApp();
20     XText xText = null;
21 
22     @Before
23     public void setUp() throws Exception {
24         app.start();
25 
26     }
27 
28     @After
29     public void tearDown() throws Exception {
30         app.close();
31     }
32     @Test@Ignore("Bug #120657 - [testUNO patch]charmode change to disable from enable when save to doc.")
33     public void testCharacterEmphasisSetting() 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. " +
38                 "We are all living in one earth!We are Chinese,they are American. " +
39                 "We are all living in one earth!We are Chinese,they are American. " +
40                 "We are all living in one earth!We are Chinese,they are American. " +
41                 "We are all living in one earth!We are Chinese,they are American. " +
42                 "We are all living in one earth!We are Chinese,they are American." +
43                 " We are all living in one earth!We are Chinese,they are American. " +
44                 "We are all living in one earth!We are Chinese,they are American. " +
45                 "We are all living in one earth!We are Chinese,they are American. " +
46                 "We are all living in one earth!We are Chinese,they are American. " +
47                 "We are all living in one earth!We are Chinese,they are American. " +
48                 "We are all living in one earth!We are Chinese,they are American. " +
49                 "We are all living in one earth!We are Chinese,they are American. " +
50                 "We are all living in one earth!We are Chinese,they are American. " +
51                 "We are all living in one earth!We are Chinese,they are American. " +
52                 "We are all living in one earth!We are Chinese,they are American. " +
53                 "We are all living in one earth!We are Chinese,they are American. " +
54                 "We are all living in one earth!We are Chinese,they are American. " +
55                 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
56                 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
57                 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
58                 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
59                 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
60                 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
61                 "We are all living in one earth!");
62         // create text cursor for selecting and formatting text
63         XTextCursor xTextCursor = xText.createTextCursor();
64         XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
65         xTextCursor.gotoStart(false);
66         xTextCursor.goRight((short) 100, true);
67         xCursorProps.setPropertyValue("CharWordMode", true);
68         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.ACCENT_ABOVE));
69         xTextCursor.gotoRange(xTextCursor, false);
70         xTextCursor.goRight((short) 100, true);
71         xCursorProps.setPropertyValue("CharWordMode", false);
72         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.ACCENT_BELOW));
73         xTextCursor.gotoRange(xTextCursor, false);
74         xTextCursor.goRight((short) 100, true);
75         xCursorProps.setPropertyValue("CharWordMode", false);
76         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.CIRCLE_ABOVE));
77         xTextCursor.gotoRange(xTextCursor, false);
78         xTextCursor.goRight((short) 100, true);
79         xCursorProps.setPropertyValue("CharWordMode", true);
80         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.CIRCLE_BELOW));
81         xTextCursor.gotoRange(xTextCursor, false);
82         xTextCursor.goRight((short) 100, true);
83         xCursorProps.setPropertyValue("CharWordMode", true);
84         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DISK_ABOVE));
85         xTextCursor.gotoRange(xTextCursor, false);
86         xTextCursor.goRight((short) 100, true);
87         xCursorProps.setPropertyValue("CharWordMode", false);
88         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DISK_BELOW));
89         xTextCursor.gotoRange(xTextCursor, false);
90         xTextCursor.goRight((short) 100, true);
91         xCursorProps.setPropertyValue("CharWordMode", false);
92         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DOT_ABOVE));
93         xTextCursor.gotoRange(xTextCursor, false);
94         xTextCursor.goRight((short) 100, true);
95         xCursorProps.setPropertyValue("CharWordMode", false);
96         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DOT_BELOW));
97         xTextCursor.gotoRange(xTextCursor, false);
98         xTextCursor.goRight((short) 100, true);
99         xCursorProps.setPropertyValue("CharWordMode", false);
100         xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.NONE));
101         //save to odt
102         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
103         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
104         aStoreProperties_odt[0] = new PropertyValue();
105         aStoreProperties_odt[1] = new PropertyValue();
106         aStoreProperties_odt[0].Name = "Override";
107         aStoreProperties_odt[0].Value = true;
108         aStoreProperties_odt[1].Name = "FilterName";
109         aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
110         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
111         //save to doc
112         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
113         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
114         aStoreProperties_doc[0] = new PropertyValue();
115         aStoreProperties_doc[1] = new PropertyValue();
116         aStoreProperties_doc[0].Name = "Override";
117         aStoreProperties_doc[0].Value = true;
118         aStoreProperties_doc[1].Name = "FilterName";
119         aStoreProperties_doc[1].Value = "MS Word 97";
120         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
121         app.closeDocument(xTextDocument);
122 
123         //reopen the document and assert character emphasis
124         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
125         XTextCursor xTextCursor_assert_odt = assertDocument_odt.getText().createTextCursor();
126         XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt);
127 
128         xTextCursor_assert_odt.gotoStart(false);
129         xTextCursor_assert_odt.goRight((short) 100, true);
130         assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
131         assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
132         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
133         xTextCursor_assert_odt.goRight((short) 100, true);
134         assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
135         assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
136         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
137         xTextCursor_assert_odt.goRight((short) 100, true);
138         assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
139         assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
140         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
141         xTextCursor_assert_odt.goRight((short) 100, true);
142         assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
143         assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
144         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
145         xTextCursor_assert_odt.goRight((short) 100, true);
146         assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
147         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
148         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
149         xTextCursor_assert_odt.goRight((short) 100, true);
150         assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
151         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
152         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
153         xTextCursor_assert_odt.goRight((short) 100, true);
154         assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
155         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
156         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
157         xTextCursor_assert_odt.goRight((short) 100, true);
158         assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
159         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
160         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
161         xTextCursor_assert_odt.goRight((short) 100, true);
162         assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode"));
163         assertEquals("assert overline",com.sun.star.text.FontEmphasis.NONE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis"));
164 
165         //reopen the document and assert character emphasis
166         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
167         XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor();
168         XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc);
169 
170         xTextCursor_assert_doc.gotoStart(false);
171         xTextCursor_assert_doc.goRight((short) 100, true);
172         assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
173         assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
174         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
175         xTextCursor_assert_doc.goRight((short) 100, true);
176         assertEquals("assert individual word setting",false,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
177         assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
178         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
179         xTextCursor_assert_doc.goRight((short) 100, true);
180         assertEquals("assert individual word setting",false,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
181         assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
182         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
183         xTextCursor_assert_doc.goRight((short) 100, true);
184         assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
185         assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
186         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
187         xTextCursor_assert_doc.goRight((short) 100, true);
188         assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
189         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
190         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
191         xTextCursor_assert_doc.goRight((short) 100, true);
192         assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
193         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
194         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
195         xTextCursor_assert_doc.goRight((short) 100, true);
196         assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
197         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
198         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
199         xTextCursor_assert_doc.goRight((short) 100, true);
200         assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
201         assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
202         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
203         xTextCursor_assert_doc.goRight((short) 100, true);
204         assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode"));
205         assertEquals("assert overline",com.sun.star.text.FontEmphasis.NONE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis"));
206         }
207 }
208