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