Line 0
Link Here
|
|
|
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 |
* |
23 |
*/ |
24 |
package testcase.uno.sd.file; |
25 |
import static org.junit.Assert.*; |
26 |
|
27 |
import org.junit.After; |
28 |
import org.junit.AfterClass; |
29 |
import org.junit.Before; |
30 |
import org.junit.BeforeClass; |
31 |
import org.junit.Test; |
32 |
import org.openoffice.test.uno.UnoApp; |
33 |
import org.openoffice.test.common.FileUtil; |
34 |
import org.openoffice.test.common.Testspace; |
35 |
|
36 |
import com.sun.star.beans.IllegalTypeException; |
37 |
import com.sun.star.beans.Property; |
38 |
import com.sun.star.beans.PropertyAttribute; |
39 |
import com.sun.star.beans.PropertyExistException; |
40 |
import com.sun.star.beans.PropertyValue; |
41 |
import com.sun.star.beans.UnknownPropertyException; |
42 |
import com.sun.star.beans.XPropertyContainer; |
43 |
import com.sun.star.beans.XPropertySet; |
44 |
import com.sun.star.beans.XPropertySetInfo; |
45 |
import com.sun.star.container.XNameAccess; |
46 |
import com.sun.star.document.XDocumentProperties; |
47 |
import com.sun.star.document.XDocumentPropertiesSupplier; |
48 |
import java.util.Calendar; |
49 |
import com.sun.star.util.DateTime; |
50 |
import com.sun.star.util.Date; |
51 |
import com.sun.star.util.Duration; |
52 |
import com.sun.star.lang.IllegalArgumentException; |
53 |
import com.sun.star.lang.WrappedTargetException; |
54 |
import com.sun.star.lang.XComponent; |
55 |
import com.sun.star.lang.XMultiServiceFactory; |
56 |
import com.sun.star.uno.UnoRuntime; |
57 |
|
58 |
/** |
59 |
* @author LouQL |
60 |
* |
61 |
*/ |
62 |
public class CheckFileProperties { |
63 |
|
64 |
private static final UnoApp app = new UnoApp(); |
65 |
|
66 |
private XComponent m_xSDComponent = null; |
67 |
private static String m_filePath = null; |
68 |
|
69 |
@Before |
70 |
public void setUpDocument() throws Exception { |
71 |
if (FileUtil.fileExists(m_filePath)) {//load |
72 |
m_xSDComponent = app.loadDocument(m_filePath); |
73 |
} else {//new |
74 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface( |
75 |
XComponent.class, app.newDocument("simpress")); |
76 |
} |
77 |
} |
78 |
|
79 |
private String getUserName() throws com.sun.star.uno.Exception |
80 |
{ |
81 |
Object configurationProvider = app.getServiceFactory(). |
82 |
createInstance("com.sun.star.configuration.ConfigurationProvider"); |
83 |
|
84 |
XMultiServiceFactory msFac = (XMultiServiceFactory)UnoRuntime.queryInterface( |
85 |
XMultiServiceFactory.class, configurationProvider); |
86 |
|
87 |
PropertyValue[] propValue = new PropertyValue[1]; |
88 |
propValue[0] = new PropertyValue(); |
89 |
propValue[0].Name = "nodepath"; |
90 |
propValue[0].Value = "/org.openoffice.UserProfile/Data"; |
91 |
|
92 |
Object configurationAccess = msFac.createInstanceWithArguments( |
93 |
"com.sun.star.configuration.ConfigurationAccess", propValue); |
94 |
XNameAccess nameAcc = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, configurationAccess); |
95 |
String givenname = (String)nameAcc.getByName("givenname"); |
96 |
String sn = (String)nameAcc.getByName("sn"); |
97 |
String name = null; |
98 |
if(givenname.length() == 0) name = sn; |
99 |
else name = givenname+" "+sn; |
100 |
|
101 |
return name; |
102 |
} |
103 |
|
104 |
private XDocumentProperties getDocumentProperties(){ |
105 |
XDocumentPropertiesSupplier xDocumentProSupplier = (XDocumentPropertiesSupplier)UnoRuntime.queryInterface( |
106 |
XDocumentPropertiesSupplier.class, this.m_xSDComponent); |
107 |
return xDocumentProSupplier.getDocumentProperties(); |
108 |
} |
109 |
|
110 |
@After |
111 |
public void tearDownDocument() { |
112 |
app.closeDocument(m_xSDComponent); |
113 |
|
114 |
} |
115 |
|
116 |
@BeforeClass |
117 |
public static void setUpConnection() throws Exception { |
118 |
app.start(); |
119 |
m_filePath = Testspace.getPath("temp/CheckFileProperties.odp"); |
120 |
FileUtil.deleteFile(m_filePath); |
121 |
} |
122 |
|
123 |
@AfterClass |
124 |
public static void tearDownConnection() throws InterruptedException, |
125 |
Exception { |
126 |
app.close(); |
127 |
//remove the temp file |
128 |
FileUtil.deleteFile(Testspace.getPath("temp")); |
129 |
} |
130 |
|
131 |
/* |
132 |
* UI entry: File->Properties->General->Created*/ |
133 |
@Test |
134 |
public void testGeneralAuthor() throws Exception { |
135 |
// String author = getUserName(); |
136 |
// if(author.length() == 0) |
137 |
// { |
138 |
String author = getUserName(); |
139 |
XDocumentProperties xDocPro = getDocumentProperties(); |
140 |
xDocPro.setAuthor(author); |
141 |
// } |
142 |
app.saveDocument(m_xSDComponent, m_filePath); |
143 |
app.closeDocument(m_xSDComponent); |
144 |
m_xSDComponent = app.loadDocument(m_filePath); |
145 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
146 |
assertEquals("Author should be "+ author, author, xDocPro2.getAuthor()); |
147 |
} |
148 |
|
149 |
private boolean DateTimeEquals(DateTime datetime1, DateTime datetime2){ |
150 |
|
151 |
if(datetime1.Seconds == datetime2.Seconds && |
152 |
datetime1.Minutes == datetime2.Minutes && |
153 |
datetime1.Hours == datetime2.Hours && |
154 |
datetime1.Day == datetime2.Day && |
155 |
datetime1.Month == datetime2.Month && |
156 |
datetime1.Year == datetime2.Year) |
157 |
return true; |
158 |
else |
159 |
return false; |
160 |
} |
161 |
|
162 |
private boolean DateEquals(Date date1, Date date2){ |
163 |
|
164 |
if(date1.Day == date2.Day && |
165 |
date1.Month == date2.Month && |
166 |
date1.Year == date2.Year) |
167 |
return true; |
168 |
else |
169 |
return false; |
170 |
} |
171 |
|
172 |
private boolean DurationEquals(Duration d1, Duration d2){ |
173 |
|
174 |
if(d1.Seconds == d2.Seconds && |
175 |
d1.Minutes == d2.Minutes && |
176 |
d1.Hours == d2.Hours && |
177 |
d1.Days == d2.Days && |
178 |
d1.Months == d2.Months && |
179 |
d1.Years == d2.Years) |
180 |
return true; |
181 |
else |
182 |
return false; |
183 |
} |
184 |
|
185 |
private DateTime getCurrentDateTime(){ |
186 |
Calendar ca = Calendar.getInstance(); |
187 |
DateTime currentDateTime = new DateTime(); |
188 |
currentDateTime.Year = (short)ca.get(Calendar.YEAR); |
189 |
currentDateTime.Month = (short)ca.get(Calendar.MONTH); |
190 |
currentDateTime.Day = (short)ca.get(Calendar.DATE); |
191 |
currentDateTime.Minutes = (short)ca.get(Calendar.MINUTE); |
192 |
currentDateTime.Hours = (short)ca.get(Calendar.HOUR); |
193 |
currentDateTime.Seconds = (short)ca.get(Calendar.SECOND); |
194 |
|
195 |
return currentDateTime; |
196 |
} |
197 |
|
198 |
private Date getCurrentDate(){ |
199 |
Calendar ca = Calendar.getInstance(); |
200 |
Date currentDate = new Date(); |
201 |
currentDate.Year = (short)ca.get(Calendar.YEAR); |
202 |
currentDate.Month = (short)ca.get(Calendar.MONTH); |
203 |
currentDate.Day = (short)ca.get(Calendar.DATE); |
204 |
|
205 |
return currentDate; |
206 |
} |
207 |
|
208 |
/* |
209 |
* UI entry: File->Properties->General->Created*/ |
210 |
@Test |
211 |
public void testGeneralCreationDate() throws Exception { |
212 |
DateTime creationDate = getCurrentDateTime(); |
213 |
|
214 |
XDocumentProperties xDocPro = getDocumentProperties(); |
215 |
|
216 |
xDocPro.setCreationDate(creationDate); |
217 |
|
218 |
app.saveDocument(m_xSDComponent, m_filePath); |
219 |
app.closeDocument(m_xSDComponent); |
220 |
m_xSDComponent = app.loadDocument(m_filePath); |
221 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
222 |
DateTime result = xDocPro2.getCreationDate(); |
223 |
assertTrue("CreationDate should be the same as set", this.DateTimeEquals(creationDate, result)); |
224 |
} |
225 |
|
226 |
/* |
227 |
* UI entry: File->Properties->General->Modified*/ |
228 |
@Test |
229 |
//ModifiedBy will be set each time the file loaded. The value is the one set in Tools->options->User data->Last name |
230 |
public void testGeneralModifiedBy() throws Exception { |
231 |
String modifiedBy = this.getUserName(); |
232 |
if(modifiedBy.length() ==0) |
233 |
{ |
234 |
modifiedBy = "ModifyUser"; |
235 |
XDocumentProperties xDocPro = getDocumentProperties(); |
236 |
xDocPro.setModifiedBy(modifiedBy); |
237 |
} |
238 |
|
239 |
app.saveDocument(m_xSDComponent, m_filePath); |
240 |
app.closeDocument(m_xSDComponent); |
241 |
m_xSDComponent = app.loadDocument(m_filePath); |
242 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
243 |
assertEquals("The file is modified by "+ modifiedBy, modifiedBy, xDocPro2.getModifiedBy()); |
244 |
} |
245 |
|
246 |
/* |
247 |
* UI entry: File->Properties->General->Modified*/ |
248 |
@Test |
249 |
public void testGeneralModificationDate() throws Exception { |
250 |
//modification date will be set each time the file saved, so I don't save after set. |
251 |
DateTime modificationDate = getCurrentDateTime(); |
252 |
|
253 |
XDocumentProperties xDocPro = getDocumentProperties(); |
254 |
|
255 |
xDocPro.setModificationDate(modificationDate); |
256 |
|
257 |
DateTime result = xDocPro.getModificationDate(); |
258 |
assertTrue("ModificationDate should be the same as set", this.DateTimeEquals(modificationDate, result)); |
259 |
} |
260 |
|
261 |
/* |
262 |
* UI entry: File->Properties->General->Last printed*/ |
263 |
@Test |
264 |
public void testGeneralPrintBy() throws Exception { |
265 |
String printBy = "PrintBy"; |
266 |
XDocumentProperties xDocPro = getDocumentProperties(); |
267 |
|
268 |
xDocPro.setPrintedBy(printBy); |
269 |
|
270 |
app.saveDocument(m_xSDComponent, m_filePath); |
271 |
app.closeDocument(m_xSDComponent); |
272 |
m_xSDComponent = app.loadDocument(m_filePath); |
273 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
274 |
assertEquals("This document is printed by "+ printBy, printBy, xDocPro2.getPrintedBy()); |
275 |
} |
276 |
|
277 |
/* |
278 |
* UI entry: File->Properties->General->Last printed*/ |
279 |
@Test |
280 |
public void testGeneralPrintDate() throws Exception { |
281 |
DateTime printDate = getCurrentDateTime(); |
282 |
|
283 |
XDocumentProperties xDocPro = getDocumentProperties(); |
284 |
|
285 |
xDocPro.setPrintDate(printDate); |
286 |
|
287 |
app.saveDocument(m_xSDComponent, m_filePath); |
288 |
app.closeDocument(m_xSDComponent); |
289 |
m_xSDComponent = app.loadDocument(m_filePath); |
290 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
291 |
DateTime result = xDocPro2.getPrintDate(); |
292 |
assertTrue("PrintDate should be the same as set", this.DateTimeEquals(printDate, result)); |
293 |
} |
294 |
|
295 |
/* |
296 |
* UI entry: File->Properties->General->Total editing time*/ |
297 |
@Test |
298 |
public void testGeneralEditingDuration() throws Exception { |
299 |
int editingDuration = 60; |
300 |
|
301 |
XDocumentProperties xDocPro = getDocumentProperties(); |
302 |
|
303 |
xDocPro.setEditingDuration(editingDuration); |
304 |
|
305 |
app.saveDocument(m_xSDComponent, m_filePath); |
306 |
app.closeDocument(m_xSDComponent); |
307 |
m_xSDComponent = app.loadDocument(m_filePath); |
308 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
309 |
assertEquals("Totally editing time should be "+ editingDuration, editingDuration, xDocPro2.getEditingDuration()); |
310 |
} |
311 |
|
312 |
/* |
313 |
* UI entry: File->Properties->General->Revision number*/ |
314 |
@Test |
315 |
public void testGeneralRevisionNumber() throws Exception { |
316 |
short revisionNumber = 10; |
317 |
|
318 |
XDocumentProperties xDocPro = getDocumentProperties(); |
319 |
|
320 |
xDocPro.setEditingCycles(revisionNumber); |
321 |
|
322 |
app.saveDocument(m_xSDComponent, m_filePath); |
323 |
app.closeDocument(m_xSDComponent); |
324 |
m_xSDComponent = app.loadDocument(m_filePath); |
325 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
326 |
assertEquals("Revision number should be "+ revisionNumber, revisionNumber, xDocPro2.getEditingCycles()); |
327 |
} |
328 |
|
329 |
/* |
330 |
* UI entry: File->Properties->General->template*/ |
331 |
@Test |
332 |
public void testGeneralTemplateName() throws Exception { |
333 |
String templateName = "I'm a template"; |
334 |
|
335 |
XDocumentProperties xDocPro = getDocumentProperties(); |
336 |
|
337 |
xDocPro.setTemplateName(templateName); |
338 |
|
339 |
app.saveDocument(m_xSDComponent, m_filePath); |
340 |
app.closeDocument(m_xSDComponent); |
341 |
m_xSDComponent = app.loadDocument(m_filePath); |
342 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
343 |
assertEquals("Template name should be "+ templateName, templateName, xDocPro2.getTemplateName()); |
344 |
} |
345 |
|
346 |
/* |
347 |
* UI entry: File->Properties->General->Reset*/ |
348 |
@Test |
349 |
public void testGeneralReset() throws Exception { |
350 |
String author = "ResetAuthor"; |
351 |
XDocumentProperties xDocPro = getDocumentProperties(); |
352 |
xDocPro.resetUserData(author); |
353 |
|
354 |
assertEquals("Author should be "+ author, author, xDocPro.getAuthor()); |
355 |
assertEquals("Modified should be empty", "", xDocPro.getModifiedBy()); |
356 |
assertTrue("ModificationDate should be empty", |
357 |
DateTimeEquals(new DateTime(), xDocPro.getModificationDate())); |
358 |
assertEquals("PrintBy should be empty", "", xDocPro.getPrintedBy()); |
359 |
assertTrue("PrintDate should be empty", |
360 |
DateTimeEquals(new DateTime(), xDocPro.getPrintDate())); |
361 |
assertEquals("Totally editing time should be empty", 0, xDocPro.getEditingDuration()); |
362 |
assertEquals("Revision number should be empty", 1, xDocPro.getEditingCycles()); |
363 |
} |
364 |
|
365 |
// UI entry: File->Properties->General->Apply user data |
366 |
|
367 |
// UI entry: File->Properties->General->digital signature |
368 |
|
369 |
//Description begin |
370 |
/* |
371 |
* UI entry: File->Properties->Description->Title*/ |
372 |
@Test |
373 |
public void testDescriptionTitle() throws Exception{ |
374 |
String title = "titleForTest"; |
375 |
XDocumentProperties xDocPro = getDocumentProperties(); |
376 |
xDocPro.setTitle(title); |
377 |
|
378 |
app.saveDocument(m_xSDComponent, m_filePath); |
379 |
app.closeDocument(m_xSDComponent); |
380 |
m_xSDComponent = app.loadDocument(m_filePath); |
381 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
382 |
assertEquals("Title should be "+ title, title, xDocPro2.getTitle()); |
383 |
} |
384 |
|
385 |
/* |
386 |
* UI entry: File->Properties->Description->Subject*/ |
387 |
@Test |
388 |
public void testDescriptionSubject() throws Exception{ |
389 |
String subject = "subjectForTest"; |
390 |
XDocumentProperties xDocPro = getDocumentProperties(); |
391 |
xDocPro.setSubject(subject); |
392 |
|
393 |
app.saveDocument(m_xSDComponent, m_filePath); |
394 |
app.closeDocument(m_xSDComponent); |
395 |
m_xSDComponent = app.loadDocument(m_filePath); |
396 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
397 |
assertEquals("Subject should be "+ subject, subject, xDocPro2.getSubject()); |
398 |
} |
399 |
|
400 |
/* |
401 |
* UI entry: File->Properties->Description->Keywords*/ |
402 |
@Test |
403 |
public void testDescriptionKeywords() throws Exception{ |
404 |
String[] keywords = {"keyword1", "keyword2"}; |
405 |
XDocumentProperties xDocPro = getDocumentProperties(); |
406 |
xDocPro.setKeywords(keywords); |
407 |
|
408 |
app.saveDocument(m_xSDComponent, m_filePath); |
409 |
app.closeDocument(m_xSDComponent); |
410 |
|
411 |
m_xSDComponent = app.loadDocument(m_filePath); |
412 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
413 |
String[] keywordsResult = xDocPro2.getKeywords(); |
414 |
assertEquals("There should be 2 Keywords", 2, keywordsResult.length); |
415 |
for(int i=0;i<keywordsResult.length;i++) |
416 |
{ |
417 |
String num = Integer.toString(i+1); |
418 |
assertEquals("The keywords should be keyword"+num, "keyword"+num, keywordsResult[i]); |
419 |
} |
420 |
} |
421 |
|
422 |
/* |
423 |
* UI entry: File->Properties->Description->Comments*/ |
424 |
@Test |
425 |
public void testDescriptionComments() throws Exception{ |
426 |
String comments = "This is the comment."; |
427 |
XDocumentProperties xDocPro = getDocumentProperties(); |
428 |
xDocPro.setDescription(comments); |
429 |
|
430 |
app.saveDocument(m_xSDComponent, m_filePath); |
431 |
app.closeDocument(m_xSDComponent); |
432 |
|
433 |
m_xSDComponent = app.loadDocument(m_filePath); |
434 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
435 |
|
436 |
assertEquals("Comments should be "+comments, comments, xDocPro2.getDescription()); |
437 |
} |
438 |
//Description end |
439 |
|
440 |
//custom properties begin |
441 |
//UI entry: File->Properties->Custom properties |
442 |
private void addCustomPro(String propertyName, Object value) throws PropertyExistException, IllegalTypeException, IllegalArgumentException{ |
443 |
XDocumentProperties xDocPro = getDocumentProperties(); |
444 |
XPropertyContainer proContainer = xDocPro.getUserDefinedProperties(); |
445 |
proContainer.addProperty(propertyName, PropertyAttribute.REMOVEABLE, value); |
446 |
} |
447 |
|
448 |
private Object getCustomPro(String propertyName) throws UnknownPropertyException, WrappedTargetException{ |
449 |
XDocumentProperties xDocPro = getDocumentProperties(); |
450 |
XPropertyContainer proContainer = xDocPro.getUserDefinedProperties(); |
451 |
XPropertySet xProSet = (XPropertySet)UnoRuntime.queryInterface( |
452 |
XPropertySet.class, proContainer); |
453 |
|
454 |
return xProSet.getPropertyValue(propertyName); |
455 |
} |
456 |
|
457 |
@Test |
458 |
public void testCustomAddPro_Text() throws Exception{ |
459 |
String addedProName = "TextPro"; |
460 |
String addedProDefaultValue = "testUser"; |
461 |
|
462 |
addCustomPro(addedProName, addedProDefaultValue); |
463 |
|
464 |
app.saveDocument(m_xSDComponent, m_filePath); |
465 |
app.closeDocument(m_xSDComponent); |
466 |
|
467 |
m_xSDComponent = app.loadDocument(m_filePath); |
468 |
|
469 |
String result = (String)getCustomPro(addedProName); |
470 |
|
471 |
assertTrue("added Text property \""+addedProName+"\" should exist", result != null); |
472 |
assertEquals("value of added property should be "+addedProDefaultValue, |
473 |
addedProDefaultValue, result); |
474 |
} |
475 |
|
476 |
@Test |
477 |
public void testCustomAddPro_DateTime() throws Exception{ |
478 |
String addedProName = "DateTimePro"; |
479 |
DateTime addedProDefaultValue = getCurrentDateTime(); |
480 |
|
481 |
addCustomPro(addedProName, addedProDefaultValue); |
482 |
|
483 |
app.saveDocument(m_xSDComponent, m_filePath); |
484 |
app.closeDocument(m_xSDComponent); |
485 |
|
486 |
m_xSDComponent = app.loadDocument(m_filePath); |
487 |
|
488 |
DateTime result = (DateTime)getCustomPro(addedProName); |
489 |
assertTrue("added DateTime property \""+addedProName+"\" should exist", result != null); |
490 |
assertTrue("value of added property should be the same as set", |
491 |
this.DateTimeEquals(result, addedProDefaultValue)); |
492 |
} |
493 |
|
494 |
@Test |
495 |
public void testCustomAddPro_Date() throws Exception{ |
496 |
String addedProName = "DatePro"; |
497 |
Date addedProDefaultValue = getCurrentDate(); |
498 |
|
499 |
addCustomPro(addedProName, addedProDefaultValue); |
500 |
|
501 |
app.saveDocument(m_xSDComponent, m_filePath); |
502 |
app.closeDocument(m_xSDComponent); |
503 |
|
504 |
m_xSDComponent = app.loadDocument(m_filePath); |
505 |
|
506 |
Date result = (Date)getCustomPro(addedProName); |
507 |
assertTrue("added Date property \""+addedProName+"\" should exist", result != null); |
508 |
assertTrue("value of added property should be the same as set", |
509 |
this.DateEquals(result, addedProDefaultValue)); |
510 |
} |
511 |
|
512 |
@Test |
513 |
public void testCustomAddPro_Duration() throws Exception{ |
514 |
String addedProName = "DurationPro"; |
515 |
Duration addedProDefaultValue = new Duration(); |
516 |
addedProDefaultValue.Days = 1; |
517 |
|
518 |
addCustomPro(addedProName, addedProDefaultValue); |
519 |
|
520 |
app.saveDocument(m_xSDComponent, m_filePath); |
521 |
app.closeDocument(m_xSDComponent); |
522 |
|
523 |
m_xSDComponent = app.loadDocument(m_filePath); |
524 |
|
525 |
Duration result = (Duration)getCustomPro(addedProName); |
526 |
assertTrue("added Date property \""+addedProName+"\" should exist", result != null); |
527 |
assertTrue("value of added property should the same as set", DurationEquals(addedProDefaultValue, result)); |
528 |
} |
529 |
|
530 |
@Test |
531 |
public void testCustomAddPro_Number() throws Exception{ |
532 |
String addedProName = "NumberPro"; |
533 |
Double addedProDefaultValue = (double)10; |
534 |
|
535 |
addCustomPro(addedProName, addedProDefaultValue); |
536 |
|
537 |
app.saveDocument(m_xSDComponent, m_filePath); |
538 |
app.closeDocument(m_xSDComponent); |
539 |
|
540 |
m_xSDComponent = app.loadDocument(m_filePath); |
541 |
|
542 |
Object oResult = getCustomPro(addedProName); |
543 |
|
544 |
Double result = (Double)oResult; |
545 |
assertTrue("added Number property \""+addedProName+"\" should exist", oResult != null); |
546 |
assertEquals("value of added property should be "+Double.toString(addedProDefaultValue), |
547 |
addedProDefaultValue, result); |
548 |
} |
549 |
|
550 |
@Test |
551 |
public void testCustomAddPro_Boolean() throws Exception{ |
552 |
String addedProName = "BooleanPro"; |
553 |
Boolean addedProDefaultValue = true; |
554 |
|
555 |
addCustomPro(addedProName, addedProDefaultValue); |
556 |
|
557 |
app.saveDocument(m_xSDComponent, m_filePath); |
558 |
app.closeDocument(m_xSDComponent); |
559 |
|
560 |
m_xSDComponent = app.loadDocument(m_filePath); |
561 |
|
562 |
Object oResult = getCustomPro(addedProName); |
563 |
|
564 |
boolean result = (Boolean)oResult; |
565 |
assertTrue("added Number property \""+addedProName+"\" should exist", oResult != null); |
566 |
assertEquals("value of added property should be "+Boolean.toString(addedProDefaultValue), |
567 |
addedProDefaultValue, result); |
568 |
} |
569 |
|
570 |
@Test |
571 |
public void testCustomRemovePro() throws Exception{ |
572 |
XDocumentProperties xDocPro = getDocumentProperties(); |
573 |
XPropertyContainer proContainer = xDocPro.getUserDefinedProperties(); |
574 |
XPropertySet xProSet = (XPropertySet)UnoRuntime.queryInterface( |
575 |
XPropertySet.class, proContainer); |
576 |
XPropertySetInfo xproSetInfo = xProSet.getPropertySetInfo(); |
577 |
Property[] pros = xproSetInfo.getProperties(); |
578 |
|
579 |
if(pros.length == 0) //if there is no custom property, add one |
580 |
{ |
581 |
addCustomPro("testPro", "value"); |
582 |
} |
583 |
|
584 |
for(int i=0; i< pros.length;i++) |
585 |
{ |
586 |
proContainer.removeProperty(pros[i].Name); |
587 |
} |
588 |
|
589 |
app.saveDocument(m_xSDComponent, m_filePath); |
590 |
app.closeDocument(m_xSDComponent); |
591 |
|
592 |
m_xSDComponent = app.loadDocument(m_filePath); |
593 |
|
594 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
595 |
XPropertyContainer proContainer2 = xDocPro2.getUserDefinedProperties(); |
596 |
XPropertySet xProSet2 = (XPropertySet)UnoRuntime.queryInterface( |
597 |
XPropertySet.class, proContainer2); |
598 |
XPropertySetInfo xproSetInfo2 = xProSet2.getPropertySetInfo(); |
599 |
Property[] pros2 = xproSetInfo2.getProperties(); |
600 |
|
601 |
assertEquals("number of custom property should be zero ", |
602 |
0, pros2.length); |
603 |
} |
604 |
//custom properties end |
605 |
|
606 |
//Internet begin |
607 |
private void setAutoLoad(String URL, int secs) throws IllegalArgumentException |
608 |
{ |
609 |
XDocumentProperties xDocPro = getDocumentProperties(); |
610 |
xDocPro.setAutoloadURL(URL); |
611 |
xDocPro.setAutoloadSecs(secs); |
612 |
xDocPro.setDefaultTarget("_blank"); |
613 |
} |
614 |
|
615 |
@Test |
616 |
public void testNoRefresh() throws Exception{ |
617 |
String autoLoadURL = ""; |
618 |
int autoLoadSecs = 0; |
619 |
setAutoLoad(autoLoadURL, autoLoadSecs); |
620 |
|
621 |
app.saveDocument(m_xSDComponent, m_filePath); |
622 |
app.closeDocument(m_xSDComponent); |
623 |
|
624 |
m_xSDComponent = app.loadDocument(m_filePath); |
625 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
626 |
|
627 |
assertEquals("AutoLoadURL should be empty", autoLoadURL, xDocPro2.getAutoloadURL()); |
628 |
assertEquals("AutoLoadSecs should be 0", autoLoadSecs, xDocPro2.getAutoloadSecs()); |
629 |
} |
630 |
|
631 |
@Test |
632 |
public void testRefreshEvery60Secs() throws Exception{ |
633 |
String autoLoadURL = ""; |
634 |
int autoLoadSecs = 60; |
635 |
setAutoLoad(autoLoadURL, autoLoadSecs); |
636 |
|
637 |
app.saveDocument(m_xSDComponent, m_filePath); |
638 |
app.closeDocument(m_xSDComponent); |
639 |
|
640 |
m_xSDComponent = app.loadDocument(m_filePath); |
641 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
642 |
|
643 |
assertEquals("AutoLoadURL should be empty", autoLoadURL, xDocPro2.getAutoloadURL()); |
644 |
assertEquals("AutoLoadSecs should be "+Integer.toString(autoLoadSecs), autoLoadSecs, xDocPro2.getAutoloadSecs()); |
645 |
} |
646 |
|
647 |
@Test |
648 |
public void testRedirect() throws Exception{ |
649 |
String autoLoadURL = "http://www.openoffice.com/"; |
650 |
int autoLoadSecs = 5; |
651 |
setAutoLoad(autoLoadURL, autoLoadSecs); |
652 |
|
653 |
app.saveDocument(m_xSDComponent, m_filePath); |
654 |
app.closeDocument(m_xSDComponent); |
655 |
|
656 |
m_xSDComponent = app.loadDocument(m_filePath); |
657 |
XDocumentProperties xDocPro2 = getDocumentProperties(); |
658 |
|
659 |
assertEquals("AutoLoadURL should be empty", autoLoadURL, xDocPro2.getAutoloadURL()); |
660 |
assertEquals("AutoLoadSecs should be "+Integer.toString(autoLoadSecs), autoLoadSecs, xDocPro2.getAutoloadSecs()); |
661 |
} |
662 |
//Internet end |
663 |
} |