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.paragraph;
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 
34 import com.sun.star.style.NumberingType;
35 import com.sun.star.text.*;
36 import com.sun.star.awt.Size;
37 import com.sun.star.beans.*;
38 import com.sun.star.container.XIndexAccess;
39 import com.sun.star.container.XIndexReplace;
40 import com.sun.star.frame.XStorable;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.uno.UnoRuntime;
43 
44 public class ParagraphNumberingAndBullet_Graphic_WidthAndHeight {
45     private static final UnoApp app = new UnoApp();
46     XText xText = null;
47 
48     @Before
setUp()49     public void setUp() throws Exception {
50         app.start();
51 
52     }
53 
54     @After
tearDown()55     public void tearDown() throws Exception {
56         app.close();
57     }
58     /*
59      * test paragraph background color
60      * 1.new a text document
61      * 2.insert some text
62      * 3.set paragraph numbering bullet with graphic
63      * 4.save and close the document
64      * 5.reload the saved document and check the paragraph graphic bullet
65      */
66     @Test@Ignore("Bug #120833 - [testUNO patch]graphic bullet will change to character bullet when save to doc.")
testNumberingBullet_Graphic()67     public void testNumberingBullet_Graphic() throws Exception {
68 
69         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
70         xText = xTextDocument.getText();
71         xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
72                 "Hello,world!Hello,world!");
73         //create cursor to select paragraph and formating paragraph
74         XTextCursor xTextCursor = xText.createTextCursor();
75         //create paragraph property set
76         XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
77         //create document service factory
78         XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
79         //set numbering character
80         Size size=new Size();
81         size.Height=1000;
82         size.Width=1000;
83         XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
84         PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue(),new PropertyValue()};
85         propsRule[0].Name = "NumberingType";
86         propsRule[0].Value = NumberingType.BITMAP;
87         propsRule[1].Name = "GraphicURL";
88         propsRule[1].Value = FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif"));
89         propsRule[2].Name = "GraphicSize";
90         propsRule[2].Value = size;
91         XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
92         xReplaceRule.replaceByIndex(0, propsRule);
93         //set paragraph numbering and bullet character
94         xTextProps.setPropertyValue("NumberingRules", xNumRule);
95 
96         //save to odt
97         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
98         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
99         aStoreProperties_odt[0] = new PropertyValue();
100         aStoreProperties_odt[1] = new PropertyValue();
101         aStoreProperties_odt[0].Name = "Override";
102         aStoreProperties_odt[0].Value = true;
103         aStoreProperties_odt[1].Name = "FilterName";
104         aStoreProperties_odt[1].Value = "writer8";
105         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
106         //save to doc
107         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
108         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
109         aStoreProperties_doc[0] = new PropertyValue();
110         aStoreProperties_doc[1] = new PropertyValue();
111         aStoreProperties_doc[0].Name = "Override";
112         aStoreProperties_doc[0].Value = true;
113         aStoreProperties_doc[1].Name = "FilterName";
114         aStoreProperties_doc[1].Value = "MS Word 97";
115         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
116         app.closeDocument(xTextDocument);
117 
118         //reopen the document
119         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
120         XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
121         XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
122         XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
123         PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
124         //verify paragraph numbering and bullet alignment
125         assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
126         assertEquals("assert numbering and bullet",NumberingType.BITMAP,propsRule_assert_odt[11].Value);
127         assertEquals("assert numbering and bullet","GraphicURL",propsRule_assert_odt[12].Name);
128         assertEquals("assert numbering and bullet",FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif")),propsRule_assert_odt[12].Value);
129         assertEquals("assert numbering and bullet","GraphicSize",propsRule_assert_odt[14].Name);
130         Size size_assert_odt=(Size)propsRule_assert_odt[14].Value;
131         assertEquals("assert numbering and bullet",1000,size_assert_odt.Height);
132         assertEquals("assert numbering and bullet",1000,size_assert_odt.Width);
133 
134         //reopen the document
135         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
136         XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
137         XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
138         PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
139         //verify paragraph numbering and bullet alignment
140         assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
141         assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value);
142         assertEquals("assert numbering and bullet","GraphicURL",propsRule_assert_odt[12].Name);
143         assertEquals("assert numbering and bullet",FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif")),propsRule_assert_doc[12].Value);
144         assertEquals("assert numbering and bullet","GraphicSize",propsRule_assert_doc[14].Name);
145         Size size_assert_doc=(Size)propsRule_assert_odt[14].Value;
146         assertEquals("assert numbering and bullet",1000,size_assert_doc.Height);
147         assertEquals("assert numbering and bullet",1000,size_assert_doc.Width);
148     }
149 }
150