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