xref: /AOO41X/test/testuno/source/fvt/uno/sw/puretext/CharacterStrikeThrough.java (revision 44cf02803b51681da4056cdf9500cc33ee29bd2f)
107d7dbdcSHerbert Dürr /**************************************************************
207d7dbdcSHerbert Dürr  *
307d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
407d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
507d7dbdcSHerbert Dürr  * distributed with this work for additional information
607d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
707d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
807d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
907d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
1007d7dbdcSHerbert Dürr  *
1107d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
1207d7dbdcSHerbert Dürr  *
1307d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
1407d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
1507d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1607d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
1707d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
1807d7dbdcSHerbert Dürr  * under the License.
1907d7dbdcSHerbert Dürr  *
2007d7dbdcSHerbert Dürr  *************************************************************/
2107d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.puretext;
23eba4d44aSLiu Zhe 
24eba4d44aSLiu Zhe import static org.junit.Assert.*;
25eba4d44aSLiu Zhe 
26eba4d44aSLiu Zhe import org.junit.After;
27eba4d44aSLiu Zhe import org.junit.Before;
28eba4d44aSLiu Zhe import org.junit.Test;
29eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil;
30eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
31eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
32eba4d44aSLiu Zhe import com.sun.star.text.*;
33eba4d44aSLiu Zhe import com.sun.star.beans.*;
34eba4d44aSLiu Zhe import com.sun.star.frame.XStorable;
35eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
36eba4d44aSLiu Zhe 
37eba4d44aSLiu Zhe 
38eba4d44aSLiu Zhe public class CharacterStrikeThrough {
39eba4d44aSLiu Zhe 	private static final UnoApp app = new UnoApp();
40eba4d44aSLiu Zhe 	XText xText = null;
41eba4d44aSLiu Zhe 
42eba4d44aSLiu Zhe 	@Before
setUp()43eba4d44aSLiu Zhe 	public void setUp() throws Exception {
44eba4d44aSLiu Zhe 		app.start();
45eba4d44aSLiu Zhe 
46eba4d44aSLiu Zhe 	}
47eba4d44aSLiu Zhe 
48eba4d44aSLiu Zhe 	@After
tearDown()49eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
50eba4d44aSLiu Zhe 		app.close();
51eba4d44aSLiu Zhe 	}
52eba4d44aSLiu Zhe 
53*44cf0280SCarl Marcum 	@Test
testCharacterStrikeThroughSetting()54eba4d44aSLiu Zhe 	public void testCharacterStrikeThroughSetting() throws Exception {
55eba4d44aSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
56eba4d44aSLiu Zhe 		xText = xTextDocument.getText();
57eba4d44aSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
58eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
59eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
60eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
61eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
62eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
63eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
64eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!");
65eba4d44aSLiu Zhe 		// create text cursor for selecting and formatting text
66eba4d44aSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
67eba4d44aSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
68eba4d44aSLiu Zhe 		xTextCursor.gotoStart(false);
69eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 100, true);
70eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.BOLD));
71eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
72eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 100, true);
73eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DONTKNOW));
74eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
75eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 100, true);
76eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DOUBLE));
77eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
78eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 100, true);
79eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.NONE));
80eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
81eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 100, true);
82eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SINGLE));
83eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
84eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 100, true);
85eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SLASH));
86eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
87eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 100, true);
88eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.X));
89eba4d44aSLiu Zhe 		//save to odt
90eba4d44aSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
91eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
92eba4d44aSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
93eba4d44aSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
94eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
95eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Value = true;
96eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
97eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
98eba4d44aSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
99eba4d44aSLiu Zhe 		//save to doc
100eba4d44aSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
101eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
102eba4d44aSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
103eba4d44aSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
104eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
105eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Value = true;
106eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
107eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
108eba4d44aSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
109eba4d44aSLiu Zhe 		app.closeDocument(xTextDocument);
110eba4d44aSLiu Zhe 
111eba4d44aSLiu Zhe 		//reopen the document and assert row height setting
112eba4d44aSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
113eba4d44aSLiu Zhe 		XTextCursor xTextCursor_assert_odt=assertDocument_odt.getText().createTextCursor();
114eba4d44aSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt);
115eba4d44aSLiu Zhe 		//verify set property
116eba4d44aSLiu Zhe 		xTextCursor_assert_odt.gotoStart(false);
117eba4d44aSLiu Zhe 		xTextCursor_assert_odt.goRight((short) 100, true);
118eba4d44aSLiu Zhe 		assertEquals("assert strikethrough is bold",com.sun.star.awt.FontStrikeout.BOLD,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
119eba4d44aSLiu Zhe 		xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
120eba4d44aSLiu Zhe 		xTextCursor_assert_odt.goRight((short) 100, true);
121eba4d44aSLiu Zhe         assertEquals("assert strikethrough is don'tknow",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
122eba4d44aSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
123eba4d44aSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
124eba4d44aSLiu Zhe         assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
125eba4d44aSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
126eba4d44aSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
127eba4d44aSLiu Zhe         assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
128eba4d44aSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
129eba4d44aSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
130eba4d44aSLiu Zhe         assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
131eba4d44aSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
132eba4d44aSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
133eba4d44aSLiu Zhe         assertEquals("assert strikethrough is with /",com.sun.star.awt.FontStrikeout.SLASH,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
134eba4d44aSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
135eba4d44aSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
136eba4d44aSLiu Zhe         assertEquals("assert strikethrough is with X",com.sun.star.awt.FontStrikeout.X,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
137eba4d44aSLiu Zhe 
138eba4d44aSLiu Zhe 		//reopen the document and assert row height setting
139eba4d44aSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
140eba4d44aSLiu Zhe 		XTextCursor xTextCursor_assert_doc=assertDocument_doc.getText().createTextCursor();
141eba4d44aSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc);
142eba4d44aSLiu Zhe 		//verify set property
143*44cf0280SCarl Marcum                 // Bug #120656 - [testUNO patch]bold,/,X strike through change to single when save to doc
144eba4d44aSLiu Zhe 		xTextCursor_assert_doc.gotoStart(false);
145eba4d44aSLiu Zhe 		xTextCursor_assert_doc.goRight((short) 100, true);
146*44cf0280SCarl Marcum 		assertEquals("for .doc assert strikethrough is SINGLE instead of bold",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
147*44cf0280SCarl Marcum 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
148eba4d44aSLiu Zhe 		xTextCursor_assert_doc.goRight((short) 100, true);
149*44cf0280SCarl Marcum         assertEquals("for .doc assert strikethrough is SINGLE instead of don'tknow",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
150*44cf0280SCarl Marcum         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
151eba4d44aSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
152eba4d44aSLiu Zhe         assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
153*44cf0280SCarl Marcum         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
154eba4d44aSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
155eba4d44aSLiu Zhe         assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
156*44cf0280SCarl Marcum         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
157eba4d44aSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
158eba4d44aSLiu Zhe         assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
159*44cf0280SCarl Marcum         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
160eba4d44aSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
161*44cf0280SCarl Marcum         assertEquals("for .doc assert strikethrough is SINGLE instead of /",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
162*44cf0280SCarl Marcum         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
163eba4d44aSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
164*44cf0280SCarl Marcum         assertEquals("for .doc assert strikethrough is SINGLE instead of X",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
165eba4d44aSLiu Zhe 	}
166eba4d44aSLiu Zhe }
167