1*eba4d44aSLiu Zhe package fvt.uno.sw.puretext;
2352c0eacSLiu Zhe 
3352c0eacSLiu Zhe import static org.junit.Assert.*;
4352c0eacSLiu Zhe 
5352c0eacSLiu Zhe import org.junit.After;
6352c0eacSLiu Zhe import org.junit.Before;
7352c0eacSLiu Zhe import org.junit.Ignore;
8352c0eacSLiu Zhe import org.junit.Test;
9352c0eacSLiu Zhe import org.openoffice.test.common.FileUtil;
10352c0eacSLiu Zhe import org.openoffice.test.common.Testspace;
11352c0eacSLiu Zhe import org.openoffice.test.uno.UnoApp;
12352c0eacSLiu Zhe import com.sun.star.text.*;
13352c0eacSLiu Zhe import com.sun.star.beans.*;
14352c0eacSLiu Zhe import com.sun.star.frame.XStorable;
15352c0eacSLiu Zhe import com.sun.star.uno.UnoRuntime;
16352c0eacSLiu Zhe 
17352c0eacSLiu Zhe 
18352c0eacSLiu Zhe public class CharacterStrikeThrough {
19352c0eacSLiu Zhe 	private static final UnoApp app = new UnoApp();
20352c0eacSLiu Zhe 	XText xText = null;
21352c0eacSLiu Zhe 
22352c0eacSLiu Zhe 	@Before
23352c0eacSLiu Zhe 	public void setUp() throws Exception {
24352c0eacSLiu Zhe 		app.start();
25352c0eacSLiu Zhe 
26352c0eacSLiu Zhe 	}
27352c0eacSLiu Zhe 
28352c0eacSLiu Zhe 	@After
29352c0eacSLiu Zhe 	public void tearDown() throws Exception {
30352c0eacSLiu Zhe 		app.close();
31352c0eacSLiu Zhe 	}
32352c0eacSLiu Zhe 
33932de486SLiu Zhe 	@Test@Ignore("Bug #120656 - [testUNO patch]bold,/,X strike through change to single when save to doc")
34352c0eacSLiu Zhe 	public void testCharacterStrikeThroughSetting() throws Exception {
35352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
36352c0eacSLiu Zhe 		xText = xTextDocument.getText();
37352c0eacSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
38352c0eacSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
39352c0eacSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
40352c0eacSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
41352c0eacSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
42352c0eacSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
43352c0eacSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
44352c0eacSLiu Zhe 				+ "and we all love our home very much!!!");
45352c0eacSLiu Zhe 		// create text cursor for selecting and formatting text
46352c0eacSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
47352c0eacSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
48352c0eacSLiu Zhe 		xTextCursor.gotoStart(false);
49352c0eacSLiu Zhe 		xTextCursor.goRight((short) 100, true);
50352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.BOLD));
51352c0eacSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
52352c0eacSLiu Zhe 		xTextCursor.goRight((short) 100, true);
53352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DONTKNOW));
54352c0eacSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
55352c0eacSLiu Zhe 		xTextCursor.goRight((short) 100, true);
56352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DOUBLE));
57352c0eacSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
58352c0eacSLiu Zhe 		xTextCursor.goRight((short) 100, true);
59352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.NONE));
60352c0eacSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
61352c0eacSLiu Zhe 		xTextCursor.goRight((short) 100, true);
62352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SINGLE));
63352c0eacSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
64352c0eacSLiu Zhe 		xTextCursor.goRight((short) 100, true);
65352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SLASH));
66352c0eacSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
67352c0eacSLiu Zhe 		xTextCursor.goRight((short) 100, true);
68352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.X));
69352c0eacSLiu Zhe 		//save to odt
70352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
71352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
72352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
73352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
74352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
75352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
76352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
77352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
78352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
79352c0eacSLiu Zhe 		//save to doc
80352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
81352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
82352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
83352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
84352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
85352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
86352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
87352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
88352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
89352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
90352c0eacSLiu Zhe 
91352c0eacSLiu Zhe 		//reopen the document and assert row height setting
92352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
93352c0eacSLiu Zhe 		XTextCursor xTextCursor_assert_odt=assertDocument_odt.getText().createTextCursor();
94352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt);
95352c0eacSLiu Zhe 		//verify set property
96352c0eacSLiu Zhe 		xTextCursor_assert_odt.gotoStart(false);
97352c0eacSLiu Zhe 		xTextCursor_assert_odt.goRight((short) 100, true);
98352c0eacSLiu Zhe 		assertEquals("assert strikethrough is bold",com.sun.star.awt.FontStrikeout.BOLD,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
99352c0eacSLiu Zhe 		xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
100352c0eacSLiu Zhe 		xTextCursor_assert_odt.goRight((short) 100, true);
101352c0eacSLiu Zhe         assertEquals("assert strikethrough is don'tknow",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
102352c0eacSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
103352c0eacSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
104352c0eacSLiu Zhe         assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
105352c0eacSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
106352c0eacSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
107352c0eacSLiu Zhe         assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
108352c0eacSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
109352c0eacSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
110352c0eacSLiu Zhe         assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
111352c0eacSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
112352c0eacSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
113352c0eacSLiu Zhe         assertEquals("assert strikethrough is with /",com.sun.star.awt.FontStrikeout.SLASH,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
114352c0eacSLiu Zhe         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
115352c0eacSLiu Zhe         xTextCursor_assert_odt.goRight((short) 100, true);
116352c0eacSLiu Zhe         assertEquals("assert strikethrough is with X",com.sun.star.awt.FontStrikeout.X,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
117352c0eacSLiu Zhe 
118352c0eacSLiu Zhe 		//reopen the document and assert row height setting
119352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
120352c0eacSLiu Zhe 		XTextCursor xTextCursor_assert_doc=assertDocument_doc.getText().createTextCursor();
121352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc);
122352c0eacSLiu Zhe 		//verify set property
123352c0eacSLiu Zhe 		xTextCursor_assert_doc.gotoStart(false);
124352c0eacSLiu Zhe 		xTextCursor_assert_doc.goRight((short) 100, true);
125352c0eacSLiu Zhe 		assertEquals("assert strikethrough is bold",com.sun.star.awt.FontStrikeout.BOLD,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
126352c0eacSLiu Zhe 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
127352c0eacSLiu Zhe 		xTextCursor_assert_doc.goRight((short) 100, true);
128352c0eacSLiu Zhe         assertEquals("assert strikethrough is don'tknow",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
129352c0eacSLiu Zhe         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
130352c0eacSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
131352c0eacSLiu Zhe         assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
132352c0eacSLiu Zhe         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
133352c0eacSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
134352c0eacSLiu Zhe         assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
135352c0eacSLiu Zhe         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
136352c0eacSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
137352c0eacSLiu Zhe         assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
138352c0eacSLiu Zhe         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
139352c0eacSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
140352c0eacSLiu Zhe         assertEquals("assert strikethrough is with /",com.sun.star.awt.FontStrikeout.SLASH,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
141352c0eacSLiu Zhe         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
142352c0eacSLiu Zhe         xTextCursor_assert_doc.goRight((short) 100, true);
143352c0eacSLiu Zhe         assertEquals("assert strikethrough is with X",com.sun.star.awt.FontStrikeout.X,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
144352c0eacSLiu Zhe 	}
145352c0eacSLiu Zhe }
146