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.Test;
29 import org.openoffice.test.common.FileUtil;
30 import org.openoffice.test.common.Testspace;
31 import org.openoffice.test.uno.UnoApp;
32 //import org.openoffice.test.vcl.Tester.*;
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 CharacterChangeCase {
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 	@Test
testCharacterLowerCaseSetting()53 	public void testCharacterLowerCaseSetting() throws Exception {
54 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
55 		xText = xTextDocument.getText();
56 		// simply set whole text as one string
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!!!");
59 		// create text cursor for selecting and formatting text
60 		XTextCursor xTextCursor = xText.createTextCursor();
61 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
62 		xTextCursor.gotoStart(false);
63 		xTextCursor.goRight((short) 102, true);
64 		xCursorProps.setPropertyValue("CharCaseMap",new Short(com.sun.star.style.CaseMap.LOWERCASE));
65 		//save to doc
66 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
67 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
68 		aStoreProperties_doc[0] = new PropertyValue();
69 		aStoreProperties_doc[1] = new PropertyValue();
70 		aStoreProperties_doc[0].Name = "Override";
71 		aStoreProperties_doc[0].Value = true;
72 		aStoreProperties_doc[1].Name = "FilterName";
73 		aStoreProperties_doc[1].Value = "MS Word 97";
74 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
75 		//save to odt
76 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
77 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
78 		aStoreProperties_odt[0] = new PropertyValue();
79 		aStoreProperties_odt[1] = new PropertyValue();
80 		aStoreProperties_odt[0].Name = "Override";
81 		aStoreProperties_odt[0].Value = true;
82 		aStoreProperties_odt[1].Name = "FilterName";
83 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
84 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
85 
86 		app.closeDocument(xTextDocument);
87 
88 		//reopen the document and assert case map
89 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
90 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
91 		//verify set property
92 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.LOWERCASE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap"));
93 
94 		//when save to doc,lower case setting by UNO API lost,change to default.
95 		//reopen the document and assert case map
96 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
97 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
98 		//verify set property
99 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap"));
100 	}
101 	@Test
testCharacterUpperCaseSetting()102 	public void testCharacterUpperCaseSetting() throws Exception {
103 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
104 		xText = xTextDocument.getText();
105 		// simply set whole text as one string
106 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
107 				+ "and we all love our home very much!!!");
108 		// create text cursor for selecting and formatting text
109 		XTextCursor xTextCursor = xText.createTextCursor();
110 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
111 		xTextCursor.gotoStart(false);
112 		xTextCursor.goRight((short) 102, true);
113 		xCursorProps.setPropertyValue("CharCaseMap",com.sun.star.style.CaseMap.UPPERCASE);
114 		//save to odt
115 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
116 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
117 		aStoreProperties_odt[0] = new PropertyValue();
118 		aStoreProperties_odt[1] = new PropertyValue();
119 		aStoreProperties_odt[0].Name = "Override";
120 		aStoreProperties_odt[0].Value = true;
121 		aStoreProperties_odt[1].Name = "FilterName";
122 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
123 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
124 		//save to doc
125 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
126 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
127 		aStoreProperties_doc[0] = new PropertyValue();
128 		aStoreProperties_doc[1] = new PropertyValue();
129 		aStoreProperties_doc[0].Name = "Override";
130 		aStoreProperties_doc[0].Value = true;
131 		aStoreProperties_doc[1].Name = "FilterName";
132 		aStoreProperties_doc[1].Value = "MS Word 97";
133 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
134 		app.closeDocument(xTextDocument);
135 
136 		//reopen the document and assert row height setting
137 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
138 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
139 		//verify set property
140 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.UPPERCASE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap"));
141 
142 		//reopen the document and assert row height setting
143 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
144 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
145 		//verify set property
146 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.UPPERCASE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap"));
147 	}
148 	@Test
testCharacterSmallCapsSetting()149 	public void testCharacterSmallCapsSetting() throws Exception {
150 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
151 		xText = xTextDocument.getText();
152 		// simply set whole text as one string
153 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
154 				+ "and we all love our home very much!!!");
155 		// create text cursor for selecting and formatting text
156 		XTextCursor xTextCursor = xText.createTextCursor();
157 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
158 		xTextCursor.gotoStart(false);
159 		xTextCursor.goRight((short) 102, true);
160 		xCursorProps.setPropertyValue("CharCaseMap",com.sun.star.style.CaseMap.SMALLCAPS);
161 		//save to odt
162 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
163 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
164 		aStoreProperties_odt[0] = new PropertyValue();
165 		aStoreProperties_odt[1] = new PropertyValue();
166 		aStoreProperties_odt[0].Name = "Override";
167 		aStoreProperties_odt[0].Value = true;
168 		aStoreProperties_odt[1].Name = "FilterName";
169 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
170 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
171 		//save to doc
172 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
173 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
174 		aStoreProperties_doc[0] = new PropertyValue();
175 		aStoreProperties_doc[1] = new PropertyValue();
176 		aStoreProperties_doc[0].Name = "Override";
177 		aStoreProperties_doc[0].Value = true;
178 		aStoreProperties_doc[1].Name = "FilterName";
179 		aStoreProperties_doc[1].Value = "MS Word 97";
180 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
181 		app.closeDocument(xTextDocument);
182 
183 		//reopen the document and assert row height setting
184 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
185 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
186 		//verify set property
187 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.SMALLCAPS,xCursorProps_assert_odt.getPropertyValue("CharCaseMap"));
188 
189 		//reopen the document and assert row height setting
190 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
191 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
192 		//verify set property
193 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.SMALLCAPS,xCursorProps_assert_doc.getPropertyValue("CharCaseMap"));
194 	}
195 	@Test
testCharacterCapitalEveryWordSetting()196 	public void testCharacterCapitalEveryWordSetting() throws Exception {
197 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
198 		xText = xTextDocument.getText();
199 		// simply set whole text as one string
200 		xText.setString("we are Chinese they are American  we are all living in one earth "
201 				+ "and we all love our home very much!!!");
202 		// create text cursor for selecting and formatting text
203 		XTextCursor xTextCursor = xText.createTextCursor();
204 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
205 		xTextCursor.gotoStart(false);
206 		xTextCursor.goRight((short) 110, true);
207 		xCursorProps.setPropertyValue("CharCaseMap",new Short(com.sun.star.style.CaseMap.TITLE));
208 		//save to odt
209 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
210 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
211 		aStoreProperties_odt[0] = new PropertyValue();
212 		aStoreProperties_odt[1] = new PropertyValue();
213 		aStoreProperties_odt[0].Name = "Override";
214 		aStoreProperties_odt[0].Value = true;
215 		aStoreProperties_odt[1].Name = "FilterName";
216 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
217 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
218 		//save to doc
219 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
220 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
221 		aStoreProperties_doc[0] = new PropertyValue();
222 		aStoreProperties_doc[1] = new PropertyValue();
223 		aStoreProperties_doc[0].Name = "Override";
224 		aStoreProperties_doc[0].Value = true;
225 		aStoreProperties_doc[1].Name = "FilterName";
226 		aStoreProperties_doc[1].Value = "MS Word 97";
227 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
228 		app.closeDocument(xTextDocument);
229 
230 		//reopen the document and assert row height setting
231 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
232 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
233 		//verify set property
234 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.TITLE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap"));
235 
236 		//reopen the document and assert row height setting
237 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
238 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
239 		//verify set property,when save to doc and reopen,the property value change to default,but display is normally
240 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap"));
241 	}
242 	@Test
testCharacterNoCaseSetting()243 	public void testCharacterNoCaseSetting() throws Exception {
244 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
245 		xText = xTextDocument.getText();
246 		// simply set whole text as one string
247 		xText.setString("we are Chinese they are American  we are all living in one earth "
248 				+ "and we all love our home very much!!!");
249 		// create text cursor for selecting and formatting text
250 		XTextCursor xTextCursor = xText.createTextCursor();
251 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
252 		xTextCursor.gotoStart(false);
253 		xTextCursor.goRight((short) 110, true);
254 		xCursorProps.setPropertyValue("CharCaseMap",new Short(com.sun.star.style.CaseMap.NONE));
255 		//save to odt
256 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
257 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
258 		aStoreProperties_odt[0] = new PropertyValue();
259 		aStoreProperties_odt[1] = new PropertyValue();
260 		aStoreProperties_odt[0].Name = "Override";
261 		aStoreProperties_odt[0].Value = true;
262 		aStoreProperties_odt[1].Name = "FilterName";
263 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
264 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
265 		//save to doc
266 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
267 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
268 		aStoreProperties_doc[0] = new PropertyValue();
269 		aStoreProperties_doc[1] = new PropertyValue();
270 		aStoreProperties_doc[0].Name = "Override";
271 		aStoreProperties_doc[0].Value = true;
272 		aStoreProperties_doc[1].Name = "FilterName";
273 		aStoreProperties_doc[1].Value = "MS Word 97";
274 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
275 		app.closeDocument(xTextDocument);
276 
277 		//reopen the document and assert row height setting
278 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
279 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
280 		//verify set property
281 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap"));
282 
283 		//reopen the document and assert row height setting
284 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
285 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
286 		//verify set property
287 		assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap"));
288 	}
289 }
290