1*eba4d44aSLiu Zhe package fvt.uno.sw.puretext;
2352c0eacSLiu Zhe 
3352c0eacSLiu Zhe import static org.junit.Assert.*;
4352c0eacSLiu Zhe 
5352c0eacSLiu Zhe import org.junit.After;
6352c0eacSLiu Zhe import org.junit.Before;
7352c0eacSLiu Zhe import org.junit.Test;
8352c0eacSLiu Zhe import org.openoffice.test.common.FileUtil;
9352c0eacSLiu Zhe import org.openoffice.test.common.Testspace;
10352c0eacSLiu Zhe import org.openoffice.test.uno.UnoApp;
11352c0eacSLiu Zhe import com.sun.star.text.*;
12352c0eacSLiu Zhe import com.sun.star.beans.*;
13352c0eacSLiu Zhe import com.sun.star.frame.XStorable;
14352c0eacSLiu Zhe import com.sun.star.uno.UnoRuntime;
15352c0eacSLiu Zhe 
16352c0eacSLiu Zhe public class CharacterLocale {
17352c0eacSLiu Zhe 	private static final UnoApp app = new UnoApp();
18352c0eacSLiu Zhe 	XText xText = null;
19352c0eacSLiu Zhe 
20352c0eacSLiu Zhe 	@Before
21352c0eacSLiu Zhe 	public void setUp() throws Exception {
22352c0eacSLiu Zhe 		app.start();
23352c0eacSLiu Zhe 
24352c0eacSLiu Zhe 	}
25352c0eacSLiu Zhe 
26352c0eacSLiu Zhe 	@After
27352c0eacSLiu Zhe 	public void tearDown() throws Exception {
28352c0eacSLiu Zhe 		app.close();
29352c0eacSLiu Zhe 	}
30352c0eacSLiu Zhe 
31352c0eacSLiu Zhe 	@Test
32352c0eacSLiu Zhe 	public void testCharacterLocaleSetting() throws Exception {
33352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
34352c0eacSLiu Zhe 		//save to odt
35352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
36352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
37352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
38352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
39352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
40352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
41352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
42352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
43352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
44352c0eacSLiu Zhe 		//save to doc
45352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
46352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
47352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
48352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
49352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
50352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
51352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
52352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
53352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
54352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
55352c0eacSLiu Zhe 
56352c0eacSLiu Zhe 		//reopen the document and assert row height setting
57352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
58352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
59352c0eacSLiu Zhe 		//verify set property
60352c0eacSLiu Zhe 		Object charLocale_obj_odt=xCursorProps_assert_odt.getPropertyValue("CharLocale");
61352c0eacSLiu Zhe 		com.sun.star.lang.Locale charLocale_odt=(com.sun.star.lang.Locale)UnoRuntime.queryInterface(com.sun.star.lang.Locale.class,charLocale_obj_odt);
62352c0eacSLiu Zhe 
63352c0eacSLiu Zhe 		assertEquals("assert character language","en",charLocale_odt.Language);
64352c0eacSLiu Zhe 		assertEquals("assert character language","US",charLocale_odt.Country);
65352c0eacSLiu Zhe 
66352c0eacSLiu Zhe 		//reopen the document and assert row height setting
67352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
68352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
69352c0eacSLiu Zhe 		//verify set property
70352c0eacSLiu Zhe 		Object charLocale_obj_doc=xCursorProps_assert_doc.getPropertyValue("CharLocale");
71352c0eacSLiu Zhe 		com.sun.star.lang.Locale charLocale_doc=(com.sun.star.lang.Locale)UnoRuntime.queryInterface(com.sun.star.lang.Locale.class,charLocale_obj_doc);
72352c0eacSLiu Zhe 
73352c0eacSLiu Zhe 		assertEquals("assert character language","en",charLocale_doc.Language);
74352c0eacSLiu Zhe 		assertEquals("assert character language","US",charLocale_doc.Country);
75352c0eacSLiu Zhe 	}
76352c0eacSLiu Zhe }
77