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 CharacterSpacing {
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
testCharacterSpacing_Default()53 	public void testCharacterSpacing_Default() throws Exception {
54 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
55 		xText = xTextDocument.getText();
56 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
57 				+ "and we all love our home very much!!!");
58 		// create text cursor for selecting and formatting text
59 		XTextCursor xTextCursor = xText.createTextCursor();
60 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
61 		xTextCursor.gotoStart(false);
62 		xTextCursor.goRight((short) 102, true);
63 		xCursorProps.setPropertyValue("CharAutoKerning", true);
64 		//save to odt
65 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
66 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
67 		aStoreProperties_odt[0] = new PropertyValue();
68 		aStoreProperties_odt[1] = new PropertyValue();
69 		aStoreProperties_odt[0].Name = "Override";
70 		aStoreProperties_odt[0].Value = true;
71 		aStoreProperties_odt[1].Name = "FilterName";
72 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
73 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
74 		//save to doc
75 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
76 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
77 		aStoreProperties_doc[0] = new PropertyValue();
78 		aStoreProperties_doc[1] = new PropertyValue();
79 		aStoreProperties_doc[0].Name = "Override";
80 		aStoreProperties_doc[0].Value = true;
81 		aStoreProperties_doc[1].Name = "FilterName";
82 		aStoreProperties_doc[1].Value = "MS Word 97";
83 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
84 		app.closeDocument(xTextDocument);
85 
86 		//reopen the document and assert row height setting
87 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
88 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
89 		//verify set property
90 		assertEquals("assert character color",true,xCursorProps_assert_odt.getPropertyValue("CharAutoKerning"));
91 
92 		//reopen the document and assert row height setting
93 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
94 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
95 		//verify set property
96 		assertEquals("assert character color",true,xCursorProps_assert_doc.getPropertyValue("CharAutoKerning"));
97 	}
98 	@Test
testCharacterSpacing_Expand()99 	public void testCharacterSpacing_Expand() throws Exception {
100 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
101 		xText = xTextDocument.getText();
102 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
103 				+ "and we all love our home very much!!!");
104 		// create text cursor for selecting and formatting text
105 		XTextCursor xTextCursor = xText.createTextCursor();
106 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
107 		xTextCursor.gotoStart(false);
108 		xTextCursor.goRight((short) 102, true);
109 		xCursorProps.setPropertyValue("CharKerning", (short)101);
110 		//save to odt
111 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
112 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
113 		aStoreProperties_odt[0] = new PropertyValue();
114 		aStoreProperties_odt[1] = new PropertyValue();
115 		aStoreProperties_odt[0].Name = "Override";
116 		aStoreProperties_odt[0].Value = true;
117 		aStoreProperties_odt[1].Name = "FilterName";
118 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
119 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
120 		//save to doc
121 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
122 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
123 		aStoreProperties_doc[0] = new PropertyValue();
124 		aStoreProperties_doc[1] = new PropertyValue();
125 		aStoreProperties_doc[0].Name = "Override";
126 		aStoreProperties_doc[0].Value = true;
127 		aStoreProperties_doc[1].Name = "FilterName";
128 		aStoreProperties_doc[1].Value = "MS Word 97";
129 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
130 		app.closeDocument(xTextDocument);
131 
132 		//reopen the document and assert row height setting
133 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
134 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
135 		//verify set property
136 		assertEquals("assert character color",(short)101,xCursorProps_assert_odt.getPropertyValue("CharKerning"));
137 
138 		//reopen the document and assert row height setting
139 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
140 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
141 		//verify set property
142 		assertEquals("assert character color",(short)101,xCursorProps_assert_doc.getPropertyValue("CharKerning"));
143 	}
144 	@Test
testCharacterSpacing_Condens()145 	public void testCharacterSpacing_Condens() throws Exception {
146 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
147 		xText = xTextDocument.getText();
148 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
149 				+ "and we all love our home very much!!!");
150 		// create text cursor for selecting and formatting text
151 		XTextCursor xTextCursor = xText.createTextCursor();
152 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
153 		xTextCursor.gotoStart(false);
154 		xTextCursor.goRight((short) 102, true);
155 		xCursorProps.setPropertyValue("CharKerning", (short)-101);
156 		//save to odt
157 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
158 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
159 		aStoreProperties_odt[0] = new PropertyValue();
160 		aStoreProperties_odt[1] = new PropertyValue();
161 		aStoreProperties_odt[0].Name = "Override";
162 		aStoreProperties_odt[0].Value = true;
163 		aStoreProperties_odt[1].Name = "FilterName";
164 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
165 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
166 		//save to doc
167 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
168 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
169 		aStoreProperties_doc[0] = new PropertyValue();
170 		aStoreProperties_doc[1] = new PropertyValue();
171 		aStoreProperties_doc[0].Name = "Override";
172 		aStoreProperties_doc[0].Value = true;
173 		aStoreProperties_doc[1].Name = "FilterName";
174 		aStoreProperties_doc[1].Value = "MS Word 97";
175 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
176 		app.closeDocument(xTextDocument);
177 
178 		//reopen the document and assert row height setting
179 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
180 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
181 		//verify set property
182 		assertEquals("assert character color",(short)-101,xCursorProps_assert_odt.getPropertyValue("CharKerning"));
183 
184 		//reopen the document and assert row height setting
185 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
186 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
187 		//verify set property
188 		assertEquals("assert character color",(short)-101,xCursorProps_assert_doc.getPropertyValue("CharKerning"));
189 }
190 }
191