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