xref: /trunk/test/testuno/source/fvt/uno/sw/paragraph/ParagraphNumberingAndBullet_CharacterBullet.java (revision a7b613a6af1cb6c17f72fb50272cb23f0021e01b)
1 package fvt.uno.sw.paragraph;
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 
13 import com.sun.star.style.NumberingType;
14 import com.sun.star.text.*;
15 import com.sun.star.beans.*;
16 import com.sun.star.container.XIndexAccess;
17 import com.sun.star.container.XIndexReplace;
18 import com.sun.star.frame.XStorable;
19 import com.sun.star.lang.XMultiServiceFactory;
20 import com.sun.star.uno.UnoRuntime;
21 
22 public class ParagraphNumberingAndBullet_CharacterBullet {
23     private static final UnoApp app = new UnoApp();
24     XText xText = null;
25 
26     @Before
27     public void setUp() throws Exception {
28         app.start();
29 
30     }
31 
32     @After
33     public void tearDown() throws Exception {
34         //app.close();
35     }
36     /*
37      * test paragraph background color
38      * 1.new a text document
39      * 2.insert some text
40      * 3.set paragraph bullet
41      * 4.save and close the document
42      * 5.reload the saved document and check the paragraph bullet
43      */
44     @Test @Ignore("Bug #120963 - [testUNO patch]the bullet character font style change to other font style character when save to doc.")
45     public void testNumberingAndBullet_CharacterBullet1() throws Exception {
46 
47         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
48         xText = xTextDocument.getText();
49         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!" +
50                 "Hello,world!Hello,world!");
51         //create cursor to select paragraph and formating paragraph
52         XTextCursor xTextCursor = xText.createTextCursor();
53         //create paragraph property set
54         XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
55         //create document service factory
56         XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
57         //set numbering character
58         XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
59         PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()};
60         propsRule[0].Name = "NumberingType";
61         propsRule[0].Value = NumberingType.CHAR_SPECIAL;
62         propsRule[1].Name = "BulletId";
63         propsRule[1].Value = (short)8226;
64         XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
65         xReplaceRule.replaceByIndex(0, propsRule);
66         //set paragraph numbering and bullet character
67         xTextProps.setPropertyValue("NumberingRules", xNumRule);
68         //save to odt
69         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
70         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
71         aStoreProperties_odt[0] = new PropertyValue();
72         aStoreProperties_odt[1] = new PropertyValue();
73         aStoreProperties_odt[0].Name = "Override";
74         aStoreProperties_odt[0].Value = true;
75         aStoreProperties_odt[1].Name = "FilterName";
76         aStoreProperties_odt[1].Value = "writer8";
77         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
78         //save to doc
79         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
80         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
81         aStoreProperties_doc[0] = new PropertyValue();
82         aStoreProperties_doc[1] = new PropertyValue();
83         aStoreProperties_doc[0].Name = "Override";
84         aStoreProperties_doc[0].Value = true;
85         aStoreProperties_doc[1].Name = "FilterName";
86         aStoreProperties_doc[1].Value = "MS Word 97";
87         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
88         app.closeDocument(xTextDocument);
89 
90         //reopen the document
91         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
92         XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
93         XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
94         XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
95         PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
96         //verify paragraph numbering and bullet alignment
97         assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
98         assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_odt[11].Value);
99         assertEquals("assert numbering and bullet","BulletId",propsRule_assert_odt[12].Name);
100         assertEquals("assert numbering and bullet",(short)8226,propsRule_assert_odt[12].Value);
101 
102         //reopen the document
103         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
104         XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
105         XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
106         PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
107         //verify paragraph numbering and bullet alignment
108         assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
109         assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value);
110         assertEquals("assert numbering and bullet","BulletId",propsRule_assert_doc[12].Name);
111         assertEquals("assert numbering and bullet",(short)8226,propsRule_assert_doc[12].Value);
112     }
113     @Test @Ignore("Bug #120963 - [testUNO patch]the bullet character font style change to other font style character when save to doc.")
114     public void testNumberingAndBullet_CharacterBullet2() throws Exception {
115 
116         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
117         xText = xTextDocument.getText();
118         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!" +
119                 "Hello,world!Hello,world!");
120         //create cursor to select paragraph and formating paragraph
121         XTextCursor xTextCursor = xText.createTextCursor();
122         //create paragraph property set
123         XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
124         //create document service factory
125         XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
126         //set numbering character
127         XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
128         PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()};
129         propsRule[0].Name = "NumberingType";
130         propsRule[0].Value = NumberingType.CHAR_SPECIAL;
131         propsRule[1].Name = "BulletId";
132         propsRule[1].Value = (short)9679;
133         XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
134         xReplaceRule.replaceByIndex(0, propsRule);
135         //set paragraph numbering and bullet character
136         xTextProps.setPropertyValue("NumberingRules", xNumRule);
137         //save to odt
138         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
139         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
140         aStoreProperties_odt[0] = new PropertyValue();
141         aStoreProperties_odt[1] = new PropertyValue();
142         aStoreProperties_odt[0].Name = "Override";
143         aStoreProperties_odt[0].Value = true;
144         aStoreProperties_odt[1].Name = "FilterName";
145         aStoreProperties_odt[1].Value = "writer8";
146         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
147         //save to doc
148         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
149         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
150         aStoreProperties_doc[0] = new PropertyValue();
151         aStoreProperties_doc[1] = new PropertyValue();
152         aStoreProperties_doc[0].Name = "Override";
153         aStoreProperties_doc[0].Value = true;
154         aStoreProperties_doc[1].Name = "FilterName";
155         aStoreProperties_doc[1].Value = "MS Word 97";
156         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
157         app.closeDocument(xTextDocument);
158 
159         //reopen the document
160         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
161         XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
162         XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
163         XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
164         PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
165         //verify paragraph numbering and bullet alignment
166         assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
167         assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_odt[11].Value);
168         assertEquals("assert numbering and bullet","BulletId",propsRule_assert_odt[12].Name);
169         assertEquals("assert numbering and bullet",(short)9679,propsRule_assert_odt[12].Value);
170 
171         //reopen the document
172         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
173         XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
174         XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
175         PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
176         //verify paragraph numbering and bullet alignment
177         assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
178         assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value);
179         assertEquals("assert numbering and bullet","BulletId",propsRule_assert_doc[12].Name);
180         assertEquals("assert numbering and bullet",(short)9679,propsRule_assert_doc[12].Value);
181     }
182 }
183