1 package fvt.uno.sw.puretext;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Ignore;
8 import org.junit.Test;
9 import org.openoffice.test.common.FileUtil;
10 import org.openoffice.test.common.Testspace;
11 import org.openoffice.test.uno.UnoApp;
12 import com.sun.star.text.*;
13 import com.sun.star.beans.*;
14 import com.sun.star.frame.XStorable;
15 import com.sun.star.uno.UnoRuntime;
16 
17 
18 public class CharacterStrikeThrough {
19 	private static final UnoApp app = new UnoApp();
20 	XText xText = null;
21 
22 	@Before
23 	public void setUp() throws Exception {
24 		app.start();
25 
26 	}
27 
28 	@After
29 	public void tearDown() throws Exception {
30 		app.close();
31 	}
32 
33 	@Test@Ignore("Bug #120656 - [testUNO patch]bold,/,X strike through change to single when save to doc")
34 	public void testCharacterStrikeThroughSetting() throws Exception {
35 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
36 		xText = xTextDocument.getText();
37 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
38 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
39 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
40 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
41 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
42 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
43 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
44 				+ "and we all love our home very much!!!");
45 		// create text cursor for selecting and formatting text
46 		XTextCursor xTextCursor = xText.createTextCursor();
47 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
48 		xTextCursor.gotoStart(false);
49 		xTextCursor.goRight((short) 100, true);
50 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.BOLD));
51 		xTextCursor.gotoRange(xTextCursor, false);
52 		xTextCursor.goRight((short) 100, true);
53 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DONTKNOW));
54 		xTextCursor.gotoRange(xTextCursor, false);
55 		xTextCursor.goRight((short) 100, true);
56 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DOUBLE));
57 		xTextCursor.gotoRange(xTextCursor, false);
58 		xTextCursor.goRight((short) 100, true);
59 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.NONE));
60 		xTextCursor.gotoRange(xTextCursor, false);
61 		xTextCursor.goRight((short) 100, true);
62 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SINGLE));
63 		xTextCursor.gotoRange(xTextCursor, false);
64 		xTextCursor.goRight((short) 100, true);
65 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SLASH));
66 		xTextCursor.gotoRange(xTextCursor, false);
67 		xTextCursor.goRight((short) 100, true);
68 		xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.X));
69 		//save to odt
70 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
71 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
72 		aStoreProperties_odt[0] = new PropertyValue();
73 		aStoreProperties_odt[1] = new PropertyValue();
74 		aStoreProperties_odt[0].Name = "Override";
75 		aStoreProperties_odt[0].Value = true;
76 		aStoreProperties_odt[1].Name = "FilterName";
77 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
78 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
79 		//save to doc
80 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
81 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
82 		aStoreProperties_doc[0] = new PropertyValue();
83 		aStoreProperties_doc[1] = new PropertyValue();
84 		aStoreProperties_doc[0].Name = "Override";
85 		aStoreProperties_doc[0].Value = true;
86 		aStoreProperties_doc[1].Name = "FilterName";
87 		aStoreProperties_doc[1].Value = "MS Word 97";
88 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
89 		app.closeDocument(xTextDocument);
90 
91 		//reopen the document and assert row height setting
92 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
93 		XTextCursor xTextCursor_assert_odt=assertDocument_odt.getText().createTextCursor();
94 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt);
95 		//verify set property
96 		xTextCursor_assert_odt.gotoStart(false);
97 		xTextCursor_assert_odt.goRight((short) 100, true);
98 		assertEquals("assert strikethrough is bold",com.sun.star.awt.FontStrikeout.BOLD,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
99 		xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
100 		xTextCursor_assert_odt.goRight((short) 100, true);
101         assertEquals("assert strikethrough is don'tknow",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
102         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
103         xTextCursor_assert_odt.goRight((short) 100, true);
104         assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
105         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
106         xTextCursor_assert_odt.goRight((short) 100, true);
107         assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
108         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
109         xTextCursor_assert_odt.goRight((short) 100, true);
110         assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
111         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
112         xTextCursor_assert_odt.goRight((short) 100, true);
113         assertEquals("assert strikethrough is with /",com.sun.star.awt.FontStrikeout.SLASH,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
114         xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
115         xTextCursor_assert_odt.goRight((short) 100, true);
116         assertEquals("assert strikethrough is with X",com.sun.star.awt.FontStrikeout.X,xCursorProps_assert_odt.getPropertyValue("CharStrikeout"));
117 
118 		//reopen the document and assert row height setting
119 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
120 		XTextCursor xTextCursor_assert_doc=assertDocument_doc.getText().createTextCursor();
121 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc);
122 		//verify set property
123 		xTextCursor_assert_doc.gotoStart(false);
124 		xTextCursor_assert_doc.goRight((short) 100, true);
125 		assertEquals("assert strikethrough is bold",com.sun.star.awt.FontStrikeout.BOLD,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
126 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
127 		xTextCursor_assert_doc.goRight((short) 100, true);
128         assertEquals("assert strikethrough is don'tknow",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
129         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
130         xTextCursor_assert_doc.goRight((short) 100, true);
131         assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
132         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
133         xTextCursor_assert_doc.goRight((short) 100, true);
134         assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
135         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
136         xTextCursor_assert_doc.goRight((short) 100, true);
137         assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
138         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
139         xTextCursor_assert_doc.goRight((short) 100, true);
140         assertEquals("assert strikethrough is with /",com.sun.star.awt.FontStrikeout.SLASH,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
141         xTextCursor_assert_doc.gotoRange(xTextCursor_assert_odt, false);
142         xTextCursor_assert_doc.goRight((short) 100, true);
143         assertEquals("assert strikethrough is with X",com.sun.star.awt.FontStrikeout.X,xCursorProps_assert_doc.getPropertyValue("CharStrikeout"));
144 	}
145 }
146