1*07d7dbdcSHerbert Dürr /**************************************************************
2*07d7dbdcSHerbert Dürr  *
3*07d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
4*07d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
5*07d7dbdcSHerbert Dürr  * distributed with this work for additional information
6*07d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
7*07d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
8*07d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
9*07d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
10*07d7dbdcSHerbert Dürr  *
11*07d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
12*07d7dbdcSHerbert Dürr  *
13*07d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
14*07d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
15*07d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*07d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
17*07d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
18*07d7dbdcSHerbert Dürr  * under the License.
19*07d7dbdcSHerbert Dürr  *
20*07d7dbdcSHerbert Dürr  *************************************************************/
21*07d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.puretext;
23352c0eacSLiu Zhe 
24352c0eacSLiu Zhe import static org.junit.Assert.*;
25352c0eacSLiu Zhe 
26352c0eacSLiu Zhe import org.junit.After;
27352c0eacSLiu Zhe import org.junit.Before;
28352c0eacSLiu Zhe import org.junit.Test;
29352c0eacSLiu Zhe import org.openoffice.test.common.FileUtil;
30352c0eacSLiu Zhe import org.openoffice.test.common.Testspace;
31352c0eacSLiu Zhe import org.openoffice.test.uno.UnoApp;
32352c0eacSLiu Zhe import com.sun.star.text.*;
33352c0eacSLiu Zhe import com.sun.star.beans.*;
34352c0eacSLiu Zhe import com.sun.star.frame.XStorable;
35352c0eacSLiu Zhe import com.sun.star.uno.UnoRuntime;
36352c0eacSLiu Zhe 
37352c0eacSLiu Zhe public class CharacterSpacing {
38352c0eacSLiu Zhe 	private static final UnoApp app = new UnoApp();
39352c0eacSLiu Zhe 	XText xText = null;
40352c0eacSLiu Zhe 
41352c0eacSLiu Zhe 	@Before
setUp()42352c0eacSLiu Zhe 	public void setUp() throws Exception {
43352c0eacSLiu Zhe 		app.start();
44352c0eacSLiu Zhe 
45352c0eacSLiu Zhe 	}
46352c0eacSLiu Zhe 
47352c0eacSLiu Zhe 	@After
tearDown()48352c0eacSLiu Zhe 	public void tearDown() throws Exception {
49352c0eacSLiu Zhe 		app.close();
50352c0eacSLiu Zhe 	}
51352c0eacSLiu Zhe 
52352c0eacSLiu Zhe 	@Test
testCharacterSpacing_Default()53352c0eacSLiu Zhe 	public void testCharacterSpacing_Default() throws Exception {
54352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
55352c0eacSLiu Zhe 		xText = xTextDocument.getText();
56352c0eacSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
57352c0eacSLiu Zhe 				+ "and we all love our home very much!!!");
58352c0eacSLiu Zhe 		// create text cursor for selecting and formatting text
59352c0eacSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
60352c0eacSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
61352c0eacSLiu Zhe 		xTextCursor.gotoStart(false);
62352c0eacSLiu Zhe 		xTextCursor.goRight((short) 102, true);
63352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharAutoKerning", true);
64352c0eacSLiu Zhe 		//save to odt
65352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
66352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
67352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
68352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
69352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
70352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
71352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
72352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
73352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
74352c0eacSLiu Zhe 		//save to doc
75352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
76352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
77352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
78352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
79352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
80352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
81352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
82352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
83352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
84352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
85352c0eacSLiu Zhe 
86352c0eacSLiu Zhe 		//reopen the document and assert row height setting
87352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
88352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
89352c0eacSLiu Zhe 		//verify set property
90352c0eacSLiu Zhe 		assertEquals("assert character color",true,xCursorProps_assert_odt.getPropertyValue("CharAutoKerning"));
91352c0eacSLiu Zhe 
92352c0eacSLiu Zhe 		//reopen the document and assert row height setting
93352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
94352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
95352c0eacSLiu Zhe 		//verify set property
96352c0eacSLiu Zhe 		assertEquals("assert character color",true,xCursorProps_assert_doc.getPropertyValue("CharAutoKerning"));
97352c0eacSLiu Zhe 	}
98352c0eacSLiu Zhe 	@Test
testCharacterSpacing_Expand()99352c0eacSLiu Zhe 	public void testCharacterSpacing_Expand() throws Exception {
100352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
101352c0eacSLiu Zhe 		xText = xTextDocument.getText();
102352c0eacSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
103352c0eacSLiu Zhe 				+ "and we all love our home very much!!!");
104352c0eacSLiu Zhe 		// create text cursor for selecting and formatting text
105352c0eacSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
106352c0eacSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
107352c0eacSLiu Zhe 		xTextCursor.gotoStart(false);
108352c0eacSLiu Zhe 		xTextCursor.goRight((short) 102, true);
109352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharKerning", (short)101);
110352c0eacSLiu Zhe 		//save to odt
111352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
112352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
113352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
114352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
115352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
116352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
117352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
118352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
119352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
120352c0eacSLiu Zhe 		//save to doc
121352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
122352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
123352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
124352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
125352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
126352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
127352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
128352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
129352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
130352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
131352c0eacSLiu Zhe 
132352c0eacSLiu Zhe 		//reopen the document and assert row height setting
133352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
134352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
135352c0eacSLiu Zhe 		//verify set property
136352c0eacSLiu Zhe 		assertEquals("assert character color",(short)101,xCursorProps_assert_odt.getPropertyValue("CharKerning"));
137352c0eacSLiu Zhe 
138352c0eacSLiu Zhe 		//reopen the document and assert row height setting
139352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
140352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
141352c0eacSLiu Zhe 		//verify set property
142352c0eacSLiu Zhe 		assertEquals("assert character color",(short)101,xCursorProps_assert_doc.getPropertyValue("CharKerning"));
143352c0eacSLiu Zhe 	}
144352c0eacSLiu Zhe 	@Test
testCharacterSpacing_Condens()145352c0eacSLiu Zhe 	public void testCharacterSpacing_Condens() throws Exception {
146352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
147352c0eacSLiu Zhe 		xText = xTextDocument.getText();
148352c0eacSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
149352c0eacSLiu Zhe 				+ "and we all love our home very much!!!");
150352c0eacSLiu Zhe 		// create text cursor for selecting and formatting text
151352c0eacSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
152352c0eacSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
153352c0eacSLiu Zhe 		xTextCursor.gotoStart(false);
154352c0eacSLiu Zhe 		xTextCursor.goRight((short) 102, true);
155352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharKerning", (short)-101);
156352c0eacSLiu Zhe 		//save to odt
157352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
158352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
159352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
160352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
161352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
162352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
163352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
164352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
165352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
166352c0eacSLiu Zhe 		//save to doc
167352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
168352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
169352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
170352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
171352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
172352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
173352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
174352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
175352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
176352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
177352c0eacSLiu Zhe 
178352c0eacSLiu Zhe 		//reopen the document and assert row height setting
179352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
180352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
181352c0eacSLiu Zhe 		//verify set property
182352c0eacSLiu Zhe 		assertEquals("assert character color",(short)-101,xCursorProps_assert_odt.getPropertyValue("CharKerning"));
183352c0eacSLiu Zhe 
184352c0eacSLiu Zhe 		//reopen the document and assert row height setting
185352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
186352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
187352c0eacSLiu Zhe 		//verify set property
188352c0eacSLiu Zhe 		assertEquals("assert character color",(short)-101,xCursorProps_assert_doc.getPropertyValue("CharKerning"));
189352c0eacSLiu Zhe }
190352c0eacSLiu Zhe }
191