Lines 32-37
Link Here
|
32 |
import org.openoffice.test.common.FileUtil; |
32 |
import org.openoffice.test.common.FileUtil; |
33 |
import org.openoffice.test.uno.UnoApp; |
33 |
import org.openoffice.test.uno.UnoApp; |
34 |
|
34 |
|
|
|
35 |
import testlib.uno.SWUtil; |
36 |
|
35 |
import com.sun.star.text.XTextDocument; |
37 |
import com.sun.star.text.XTextDocument; |
36 |
import com.sun.star.text.XTextCursor; |
38 |
import com.sun.star.text.XTextCursor; |
37 |
import com.sun.star.text.XText; |
39 |
import com.sun.star.text.XText; |
Lines 39-48
Link Here
|
39 |
import com.sun.star.beans.PropertyValue; |
41 |
import com.sun.star.beans.PropertyValue; |
40 |
import com.sun.star.frame.*; |
42 |
import com.sun.star.frame.*; |
41 |
import com.sun.star.uno.UnoRuntime; |
43 |
import com.sun.star.uno.UnoRuntime; |
42 |
import com.sun.star.util.XCloseable; |
|
|
43 |
import com.sun.star.lang.XComponent; |
44 |
import com.sun.star.lang.XComponent; |
44 |
import com.sun.star.container.XEnumerationAccess; |
|
|
45 |
import com.sun.star.container.XEnumeration; |
46 |
|
45 |
|
47 |
|
46 |
|
48 |
public class DocumentTest { |
47 |
public class DocumentTest { |
Lines 51-60
Link Here
|
51 |
File temp = null; |
50 |
File temp = null; |
52 |
String workingFilePath = ""; |
51 |
String workingFilePath = ""; |
53 |
String workingTemplatePath = ""; |
52 |
String workingTemplatePath = ""; |
54 |
|
53 |
|
55 |
/** |
|
|
56 |
* @throws java.lang.Exception |
57 |
*/ |
58 |
@Before |
54 |
@Before |
59 |
public void setUp() throws Exception { |
55 |
public void setUp() throws Exception { |
60 |
unoApp.start(); |
56 |
unoApp.start(); |
Lines 72-142
Link Here
|
72 |
public void tearDown() throws Exception { |
68 |
public void tearDown() throws Exception { |
73 |
unoApp.close(); |
69 |
unoApp.close(); |
74 |
} |
70 |
} |
75 |
|
|
|
76 |
private XComponent newDocumentFromTemplate(String templatePath) throws Exception |
77 |
{ |
78 |
XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, unoApp.getDesktop()); |
79 |
PropertyValue[] pros = new PropertyValue[1]; |
80 |
pros[0] = new PropertyValue(); |
81 |
pros[0].Name = "AsTemplate"; |
82 |
pros[0].Value = new Boolean(true); |
83 |
|
84 |
XComponent component = componentLoader.loadComponentFromURL(FileUtil.getUrl(workingTemplatePath), "_blank", 0,pros); |
85 |
return component; |
86 |
} |
87 |
|
88 |
|
89 |
/** |
71 |
/** |
90 |
* test close document |
72 |
* test new document and close document |
91 |
* @throws Exception |
73 |
* @throws Exception |
92 |
*/ |
74 |
*/ |
93 |
@Test |
75 |
@Test |
94 |
public void testCloseDocument() throws Exception |
76 |
public void testNewAndCloseDocument() throws Exception |
95 |
{ |
77 |
{ |
96 |
XComponent component = unoApp.newDocument("swriter"); |
78 |
XComponent component = unoApp.newDocument("swriter"); |
97 |
unoApp.closeDocument(component); |
|
|
98 |
XModel xModel = unoApp.getDesktop().getCurrentFrame().getController().getModel(); |
99 |
Assert.assertTrue("Document has been closed.",xModel==null); |
100 |
} |
101 |
|
102 |
/** |
103 |
* test new document |
104 |
* @throws Exception |
105 |
*/ |
106 |
@Test |
107 |
public void testNewDocument() throws Exception |
108 |
{ |
109 |
XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, unoApp.getDesktop()); |
110 |
XComponent component = componentLoader.loadComponentFromURL("private:factory/" + "swriter", "_blank", 0, new PropertyValue[0]); |
111 |
textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component); |
79 |
textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component); |
112 |
XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument); |
80 |
XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument); |
113 |
String title = xTitle.getTitle(); |
81 |
String title = xTitle.getTitle(); |
114 |
Assert.assertEquals("New Document title start with \"Untitled\"",true, title.startsWith("Untitled")); |
82 |
Assert.assertEquals("New Document title start with \"Untitled\"",true, title.startsWith("Untitled")); |
115 |
unoApp.closeDocument(textDocument); |
83 |
unoApp.closeDocument(component); |
116 |
} |
84 |
XModel xModel = unoApp.getDesktop().getCurrentFrame().getController().getModel(); |
117 |
|
85 |
Assert.assertTrue("Document has been closed.",xModel==null); |
|
|
86 |
} |
118 |
/** |
87 |
/** |
119 |
* test new document from template |
88 |
* test new document from template |
120 |
* @throws Exception |
89 |
* @throws Exception |
121 |
*/ |
90 |
*/ |
122 |
@Test |
91 |
@Test |
123 |
public void testNewDocumentFromTemplate() throws Exception |
92 |
public void testNewDocumentFromTemplate() throws Exception |
124 |
{ |
93 |
{ |
125 |
XComponent component = this.newDocumentFromTemplate(workingTemplatePath); |
94 |
XComponent component = SWUtil.newDocumentFromTemplate(workingTemplatePath,unoApp); |
126 |
textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component); |
95 |
textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component); |
|
|
96 |
XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument); |
127 |
XText xText = textDocument.getText(); |
97 |
XText xText = textDocument.getText(); |
128 |
XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument); |
|
|
129 |
xText = textDocument.getText(); |
130 |
XTextCursor xTextCursor = xText.createTextCursor(); |
98 |
XTextCursor xTextCursor = xText.createTextCursor(); |
131 |
xTextCursor.gotoEnd(true); |
99 |
xTextCursor.gotoEnd(true); |
132 |
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); |
100 |
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); |
133 |
String paraStyle = (String)xPropertySet.getPropertyValue("ParaStyleName"); |
101 |
String paraStyle = (String)xPropertySet.getPropertyValue("ParaStyleName"); |
134 |
|
102 |
Assert.assertEquals("new document from template, heading style in template is remained. ", "Heading 1", paraStyle); |
135 |
Assert.assertEquals("new document from template, heading style in template is remained. ", "Heading 1", paraStyle); |
|
|
136 |
|
137 |
Assert.assertEquals("new document from template, title start with \"Untitled\".", true, xTitle.getTitle().startsWith("Untitled")); |
103 |
Assert.assertEquals("new document from template, title start with \"Untitled\".", true, xTitle.getTitle().startsWith("Untitled")); |
138 |
|
|
|
139 |
unoApp.closeDocument(textDocument); |
140 |
} |
104 |
} |
141 |
|
105 |
|
142 |
/** |
106 |
/** |
Lines 151-173
Link Here
|
151 |
XText xText = textDocument.getText(); |
115 |
XText xText = textDocument.getText(); |
152 |
XTextCursor xTextCursor = xText.createTextCursor(); |
116 |
XTextCursor xTextCursor = xText.createTextCursor(); |
153 |
xTextCursor.gotoEnd(true); |
117 |
xTextCursor.gotoEnd(true); |
154 |
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); |
118 |
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); |
155 |
|
119 |
xPropertySet.setPropertyValue("ParaStyleName", "Heading 1"); |
156 |
xPropertySet.setPropertyValue("ParaStyleName", "Heading 1"); |
120 |
SWUtil.save(textDocument); |
157 |
|
121 |
unoApp.closeDocument(textDocument); |
158 |
XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, component); |
|
|
159 |
xStorable.store(); |
160 |
unoApp.closeDocument(textDocument); |
161 |
|
162 |
component = unoApp.loadDocument(workingFilePath); |
122 |
component = unoApp.loadDocument(workingFilePath); |
163 |
textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component); |
123 |
textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component); |
164 |
xText = textDocument.getText(); |
124 |
xText = textDocument.getText(); |
165 |
xTextCursor = xText.createTextCursor(); |
125 |
xTextCursor = xText.createTextCursor(); |
166 |
xTextCursor.gotoEnd(true); |
126 |
xTextCursor.gotoEnd(true); |
167 |
xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); |
127 |
xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); |
168 |
|
|
|
169 |
Assert.assertEquals("Modify plain text to heading 1 style. ", "Heading 1", (String)xPropertySet.getPropertyValue("ParaStyleName")); |
128 |
Assert.assertEquals("Modify plain text to heading 1 style. ", "Heading 1", (String)xPropertySet.getPropertyValue("ParaStyleName")); |
170 |
unoApp.closeDocument(textDocument); |
|
|
171 |
} |
129 |
} |
172 |
|
130 |
|
173 |
/** |
131 |
/** |
Lines 186-206
Link Here
|
186 |
|
144 |
|
187 |
xPropertySet.setPropertyValue("ParaStyleName", "Heading 1"); |
145 |
xPropertySet.setPropertyValue("ParaStyleName", "Heading 1"); |
188 |
xText.insertString(xTextCursor, "test Save odt as doc.", false); |
146 |
xText.insertString(xTextCursor, "test Save odt as doc.", false); |
189 |
|
147 |
SWUtil.saveAsDoc(textDocument, FileUtil.getUrl(saveAsFile)); |
190 |
XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, component); |
|
|
191 |
PropertyValue[] storeProps = new PropertyValue[2]; |
192 |
|
193 |
storeProps[0] = new PropertyValue(); |
194 |
storeProps[0].Name = "Overwrite"; |
195 |
storeProps[0].Value = new Boolean(true); |
196 |
|
197 |
storeProps[1] = new PropertyValue(); |
198 |
storeProps[1].Name = "FilterName"; |
199 |
storeProps[1].Value = "MS Word 97"; |
200 |
|
201 |
xStorable.storeAsURL(FileUtil.getUrl(saveAsFile), storeProps); |
202 |
Assert.assertTrue("Save odt document as doc the file exist: " + saveAsFile.getAbsolutePath(), saveAsFile.exists()); |
148 |
Assert.assertTrue("Save odt document as doc the file exist: " + saveAsFile.getAbsolutePath(), saveAsFile.exists()); |
203 |
unoApp.closeDocument(textDocument); |
|
|
204 |
} |
149 |
} |
205 |
|
150 |
|
206 |
/** |
151 |
/** |
Lines 232-239
Link Here
|
232 |
xStorable.storeToURL(FileUtil.getUrl(saveAsFile), storeProps); |
177 |
xStorable.storeToURL(FileUtil.getUrl(saveAsFile), storeProps); |
233 |
|
178 |
|
234 |
Assert.assertTrue("Export document as PDF.", saveAsFile.exists()); |
179 |
Assert.assertTrue("Export document as PDF.", saveAsFile.exists()); |
235 |
|
|
|
236 |
unoApp.closeDocument(textDocument); |
237 |
} |
180 |
} |
238 |
|
181 |
|
239 |
/** |
182 |
/** |
Lines 270-288
Link Here
|
270 |
storeProps[2].Value=new Boolean(true); |
213 |
storeProps[2].Value=new Boolean(true); |
271 |
|
214 |
|
272 |
xStorable.storeToURL(FileUtil.getUrl(saveAsFile), storeProps); |
215 |
xStorable.storeToURL(FileUtil.getUrl(saveAsFile), storeProps); |
273 |
unoApp.closeDocument(textDocument); |
216 |
unoApp.closeDocument(textDocument); |
274 |
|
217 |
Assert.assertTrue("Export document as ott.", saveAsFile.exists()); |
275 |
component = this.newDocumentFromTemplate(saveAsFile.getAbsolutePath()); |
|
|
276 |
textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component); |
277 |
XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument); |
278 |
xText = textDocument.getText(); |
279 |
xTextCursor = xText.createTextCursor(); |
280 |
xTextCursor.gotoEnd(true); |
281 |
xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); |
282 |
String paraStyle = (String)xPropertySet.getPropertyValue("ParaStyleName"); |
283 |
Assert.assertEquals("Save document as template, heading style is remained. ", "Heading 1", paraStyle); |
284 |
Assert.assertEquals("Save document as template, title start with \"Untitled\".", true, xTitle.getTitle().startsWith("Untitled")); |
285 |
unoApp.closeDocument(textDocument); |
286 |
} |
218 |
} |
287 |
|
219 |
|
288 |
} |
220 |
} |