xref: /AOO41X/test/testuno/source/fvt/uno/sw/puretext/CharacterLocale.java (revision 07d7dbdcb8e526dfaf85923a181c45494526d79d)
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 com.sun.star.text.*;
33 import com.sun.star.beans.*;
34 import com.sun.star.frame.XStorable;
35 import com.sun.star.uno.UnoRuntime;
36 
37 public class CharacterLocale {
38     private static final UnoApp app = new UnoApp();
39     XText xText = null;
40 
41     @Before
setUp()42     public void setUp() throws Exception {
43         app.start();
44 
45     }
46 
47     @After
tearDown()48     public void tearDown() throws Exception {
49         app.close();
50     }
51 
52     @Test
testCharacterLocaleSetting()53     public void testCharacterLocaleSetting() throws Exception {
54         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
55         //save to odt
56         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
57         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
58         aStoreProperties_odt[0] = new PropertyValue();
59         aStoreProperties_odt[1] = new PropertyValue();
60         aStoreProperties_odt[0].Name = "Override";
61         aStoreProperties_odt[0].Value = true;
62         aStoreProperties_odt[1].Name = "FilterName";
63         aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
64         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
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         app.closeDocument(xTextDocument);
76 
77         //reopen the document and assert row height setting
78         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
79         XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
80         //verify set property
81         Object charLocale_obj_odt=xCursorProps_assert_odt.getPropertyValue("CharLocale");
82         com.sun.star.lang.Locale charLocale_odt=(com.sun.star.lang.Locale)UnoRuntime.queryInterface(com.sun.star.lang.Locale.class,charLocale_obj_odt);
83 
84         assertEquals("assert character language","en",charLocale_odt.Language);
85         assertEquals("assert character language","US",charLocale_odt.Country);
86 
87         //reopen the document and assert row height setting
88         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
89         XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
90         //verify set property
91         Object charLocale_obj_doc=xCursorProps_assert_doc.getPropertyValue("CharLocale");
92         com.sun.star.lang.Locale charLocale_doc=(com.sun.star.lang.Locale)UnoRuntime.queryInterface(com.sun.star.lang.Locale.class,charLocale_obj_doc);
93 
94         assertEquals("assert character language","en",charLocale_doc.Language);
95         assertEquals("assert character language","US",charLocale_doc.Country);
96     }
97 }
98