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