xref: /AOO41X/test/testuno/source/fvt/uno/sw/paragraph/ParagraphDropcap.java (revision dd517d763d1590106211e60c61ad7d6551aa7b11)
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.Test;
8 import org.openoffice.test.common.FileUtil;
9 import org.openoffice.test.common.Testspace;
10 import org.openoffice.test.uno.UnoApp;
11 
12 import com.sun.star.style.DropCapFormat;
13 import com.sun.star.text.*;
14 import com.sun.star.beans.*;
15 import com.sun.star.frame.XStorable;
16 import com.sun.star.uno.UnoRuntime;
17 
18 public class ParagraphDropcap {
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 paragraph background color
34      * 1.new a text document
35      * 2.insert some text
36      * 3.set paragraph drop
37      * 4.save and close the document
38      * 5.reload the saved document and check the paragraph drop cap
39      */
40     @Test
41     public void testParagraphDropcapSetting() throws Exception {
42 
43         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
44         xText = xTextDocument.getText();
45         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!" +
46                 "Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!");
47         // create text cursor for selecting and formatting text
48         XTextCursor xTextCursor = xText.createTextCursor();
49         XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
50         //set paragraph dropcaps
51         DropCapFormat dropcapFormat=new DropCapFormat();
52         dropcapFormat.Lines=3;
53         dropcapFormat.Distance=101;
54         dropcapFormat.Count=9;
55         xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat);
56         //xCursorProps.setPropertyValue("DropCapWholeWord",true);
57         //save to odt
58         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
59         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
60         aStoreProperties_odt[0] = new PropertyValue();
61         aStoreProperties_odt[1] = new PropertyValue();
62         aStoreProperties_odt[0].Name = "Override";
63         aStoreProperties_odt[0].Value = true;
64         aStoreProperties_odt[1].Name = "FilterName";
65         aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
66         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
67         //save to doc
68         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
69         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
70         aStoreProperties_doc[0] = new PropertyValue();
71         aStoreProperties_doc[1] = new PropertyValue();
72         aStoreProperties_doc[0].Name = "Override";
73         aStoreProperties_doc[0].Value = true;
74         aStoreProperties_doc[1].Name = "FilterName";
75         aStoreProperties_doc[1].Value = "MS Word 97";
76         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
77         app.closeDocument(xTextDocument);
78 
79         //reopen the document
80         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
81         XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
82         //verify paragraph dropcap
83         DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat"));
84         assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_odt.Count);
85         assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines);
86         assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance);
87 
88         //reopen the document
89         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
90         XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
91         //verify paragraph dropcap
92         DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat"));
93         assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_doc.Count);
94         assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines);
95         assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance);
96     }
97     @Test
98     public void testParagraphDropcapWholewordSetting() throws Exception {
99 
100         XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
101         xText = xTextDocument.getText();
102         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!" +
103                 "Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!");
104         // create text cursor for selecting and formatting text
105         XTextCursor xTextCursor = xText.createTextCursor();
106         XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
107         //set paragraph dropcaps
108         DropCapFormat dropcapFormat=new DropCapFormat();
109         dropcapFormat.Lines=3;
110         dropcapFormat.Distance=101;
111         xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat);
112         xCursorProps.setPropertyValue("DropCapWholeWord",true);
113         //save to odt
114         XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
115         PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
116         aStoreProperties_odt[0] = new PropertyValue();
117         aStoreProperties_odt[1] = new PropertyValue();
118         aStoreProperties_odt[0].Name = "Override";
119         aStoreProperties_odt[0].Value = true;
120         aStoreProperties_odt[1].Name = "FilterName";
121         aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
122         xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
123         //save to doc
124         XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
125         PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
126         aStoreProperties_doc[0] = new PropertyValue();
127         aStoreProperties_doc[1] = new PropertyValue();
128         aStoreProperties_doc[0].Name = "Override";
129         aStoreProperties_doc[0].Value = true;
130         aStoreProperties_doc[1].Name = "FilterName";
131         aStoreProperties_doc[1].Value = "MS Word 97";
132         xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
133         app.closeDocument(xTextDocument);
134 
135         //reopen the document
136         XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
137         XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
138         //verify paragraph dropcap
139         DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat"));
140         assertEquals("assert paragraph dropcaps",true,xCursorProps_Assert_odt.getPropertyValue("DropCapWholeWord"));
141         assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines);
142         assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance);
143 
144         //reopen the document
145         XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
146         XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
147         //verify paragraph dropcap
148         DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat"));
149         assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines);
150         assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance);
151         //when save to doc,the DropCapWholeWord option will disable,and enable dropcapFormat.count
152         assertEquals("assert paragraph dropcaps",false,xCursorProps_Assert_doc.getPropertyValue("DropCapWholeWord"));
153     }
154 }
155