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