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 com.sun.star.text.*;
12 import com.sun.star.beans.*;
13 import com.sun.star.frame.XStorable;
14 import com.sun.star.uno.UnoRuntime;
15 
16 public class CharacterLocale {
17 	private static final UnoApp app = new UnoApp();
18 	XText xText = null;
19 
20 	@Before
21 	public void setUp() throws Exception {
22 		app.start();
23 
24 	}
25 
26 	@After
27 	public void tearDown() throws Exception {
28 		app.close();
29 	}
30 
31 	@Test
32 	public void testCharacterLocaleSetting() throws Exception {
33 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
34 		//save to odt
35 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
36 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
37 		aStoreProperties_odt[0] = new PropertyValue();
38 		aStoreProperties_odt[1] = new PropertyValue();
39 		aStoreProperties_odt[0].Name = "Override";
40 		aStoreProperties_odt[0].Value = true;
41 		aStoreProperties_odt[1].Name = "FilterName";
42 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
43 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
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 		app.closeDocument(xTextDocument);
55 
56 		//reopen the document and assert row height setting
57 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
58 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
59 		//verify set property
60 		Object charLocale_obj_odt=xCursorProps_assert_odt.getPropertyValue("CharLocale");
61 		com.sun.star.lang.Locale charLocale_odt=(com.sun.star.lang.Locale)UnoRuntime.queryInterface(com.sun.star.lang.Locale.class,charLocale_obj_odt);
62 
63 		assertEquals("assert character language","en",charLocale_odt.Language);
64 		assertEquals("assert character language","US",charLocale_odt.Country);
65 
66 		//reopen the document and assert row height setting
67 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
68 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
69 		//verify set property
70 		Object charLocale_obj_doc=xCursorProps_assert_doc.getPropertyValue("CharLocale");
71 		com.sun.star.lang.Locale charLocale_doc=(com.sun.star.lang.Locale)UnoRuntime.queryInterface(com.sun.star.lang.Locale.class,charLocale_obj_doc);
72 
73 		assertEquals("assert character language","en",charLocale_doc.Language);
74 		assertEquals("assert character language","US",charLocale_doc.Country);
75 	}
76 }
77