1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "HistoryOptTest.hxx" 29 #include <unotools/historyoptions_const.hxx> 30 31 #include <com/sun/star/uno/Sequence.hxx> 32 #include <com/sun/star/beans/PropertyValue.hpp> 33 #include <com/sun/star/beans/XPropertySet.hpp> 34 #include <com/sun/star/container/XNameAccess.hpp> 35 #include <com/sun/star/container/XNameContainer.hpp> 36 37 #include <comphelper/configurationhelper.hxx> 38 #include <comphelper/sequenceashashmap.hxx> 39 #include <unotools/processfactory.hxx> 40 41 namespace css = ::com::sun::star; 42 43 //============================================================================= 44 static const ::rtl::OUString MESSAGE_CLEAR_FAILED = ::rtl::OUString::createFromAscii("Clearing the list failed."); 45 static const ::rtl::OUString MESSAGE_SETSIZE_FAILED = ::rtl::OUString::createFromAscii("Setting a new size for a list failed."); 46 static const ::rtl::OUString MESSAGE_MISS_HISTORY = ::rtl::OUString::createFromAscii("Could not get config access to history list inside config."); 47 static const ::rtl::OUString MESSAGE_MISS_ITEMLIST = ::rtl::OUString::createFromAscii("Could not get config access to item list inside config."); 48 static const ::rtl::OUString MESSAGE_MISS_ORDERLIST = ::rtl::OUString::createFromAscii("Could not get config access to order list inside config."); 49 static const ::rtl::OUString MESSAGE_MISS_ITEM = ::rtl::OUString::createFromAscii("Could not locate item."); 50 static const ::rtl::OUString MESSAGE_UNEXPECTED_ITEM = ::rtl::OUString::createFromAscii("Found an unexpected item."); 51 static const ::rtl::OUString MESSAGE_WRONG_ORDER = ::rtl::OUString::createFromAscii("Wrong order in history list."); 52 53 //============================================================================= 54 HistoryOptTest::HistoryOptTest() 55 : m_aConfigItem ( ) 56 , m_eList (ePICKLIST) 57 , m_xHistoriesXCU( ) 58 , m_xCommonXCU ( ) 59 { 60 } 61 62 //============================================================================= 63 HistoryOptTest::~HistoryOptTest() 64 { 65 m_xHistoriesXCU.clear(); 66 m_xCommonXCU.clear(); 67 } 68 69 //============================================================================= 70 void HistoryOptTest::checkPicklist() 71 { 72 impl_testHistory(ePICKLIST, 4); 73 } 74 75 //============================================================================= 76 void HistoryOptTest::checkURLHistory() 77 { 78 impl_testHistory(eHISTORY, 10); 79 } 80 81 //============================================================================= 82 void HistoryOptTest::checkHelpBookmarks() 83 { 84 impl_testHistory(eHELPBOOKMARKS, 100); 85 } 86 87 //============================================================================= 88 void HistoryOptTest::impl_testHistory(EHistoryType eHistory , 89 ::sal_Int32 nMaxItems) 90 { 91 try 92 { 93 m_eList = eHistory; 94 ::sal_Int32 c = nMaxItems; 95 ::sal_Int32 i = 0; 96 97 impl_clearList( ); 98 impl_setSize (c); 99 100 // a) fill list completely and check if all items could be realy created. 101 // But dont check its order here! Because every new item will change that order. 102 for (i=0; i<c; ++i) 103 { 104 impl_appendItem(i); 105 if ( ! impl_existsItem(i)) 106 throw css::uno::Exception(MESSAGE_MISS_ITEM, 0); 107 } 108 109 // b) Check order of all items in list now. 110 // It must be reverse to the item number ... 111 // item max = index 0 112 // item max-1 = index 1 113 // ... 114 for (i=0; i<c; ++i) 115 { 116 ::sal_Int32 nExpectedIndex = (c-1)-i; 117 if ( ! impl_existsItemAtIndex(i, nExpectedIndex)) 118 throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); 119 } 120 121 // c) increase prio of "first" item so it will switch 122 // to "second" and "second" will switch to "first" :-) 123 // Check also if all other items was not touched. 124 ::sal_Int32 nFirstItem = (c-1); 125 ::sal_Int32 nSecondItem = (c-2); 126 impl_appendItem(nSecondItem); 127 128 if ( 129 ( ! impl_existsItemAtIndex(nSecondItem, 0)) || 130 ( ! impl_existsItemAtIndex(nFirstItem , 1)) 131 ) 132 throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); 133 134 for (i=0; i<nSecondItem; ++i) 135 { 136 ::sal_Int32 nExpectedIndex = (c-1)-i; 137 if ( ! impl_existsItemAtIndex(i, nExpectedIndex)) 138 throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); 139 } 140 141 // d) Check if appending new items will destroy the oldest one. 142 ::sal_Int32 nNewestItem = c; 143 ::sal_Int32 nOldestItem = 0; 144 145 impl_appendItem(nNewestItem); 146 147 if ( ! impl_existsItemAtIndex(nNewestItem, 0)) 148 throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); 149 150 if (impl_existsItem(nOldestItem)) 151 throw css::uno::Exception(MESSAGE_UNEXPECTED_ITEM, 0); 152 153 // e) Check if decreasing list size will remove oldest items. 154 // Note: impl_setSize() will make sure that 3 items exists only. 155 // Otherwhise it throws an exception. If we further check 156 // positions of three items no further items must be checked. 157 // They cant exists :-) 158 ::sal_Int32 nNewSize = 3; 159 impl_setSize(nNewSize); 160 if ( 161 ( ! impl_existsItemAtIndex(nNewestItem, 0)) || 162 ( ! impl_existsItemAtIndex(nSecondItem, 1)) || 163 ( ! impl_existsItemAtIndex(nFirstItem , 2)) 164 ) 165 throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); 166 167 // finaly we should try to clean up all used structures so the same office can be used 168 // without problems :-) 169 impl_clearList(); 170 } 171 catch (const css::uno::Exception& ex) 172 { 173 impl_clearList(); 174 throw ex; 175 } 176 177 } 178 179 //============================================================================= 180 void HistoryOptTest::impl_clearList() 181 { 182 m_aConfigItem.Clear(m_eList); 183 ::sal_Int32 nCount = m_aConfigItem.GetList(m_eList).getLength(); 184 185 if (nCount != 0) 186 throw css::uno::Exception(MESSAGE_CLEAR_FAILED, 0); 187 188 css::uno::Reference< css::container::XNameAccess > xList; 189 xList = impl_getItemList(); 190 nCount = xList->getElementNames().getLength(); 191 192 if (nCount != 0) 193 throw css::uno::Exception(MESSAGE_CLEAR_FAILED, 0); 194 195 xList = impl_getOrderList(); 196 nCount = xList->getElementNames().getLength(); 197 198 if (nCount != 0) 199 throw css::uno::Exception(MESSAGE_CLEAR_FAILED, 0); 200 } 201 202 //============================================================================= 203 void HistoryOptTest::impl_setSize(::sal_Int32 nSize) 204 { 205 m_aConfigItem.SetSize (m_eList, nSize); 206 207 // a) size info returned by GetSize() means "MaxSize" 208 // so it must match exactly ! 209 ::sal_Int32 nCheck = m_aConfigItem.GetSize(m_eList); 210 if (nCheck != nSize) 211 throw css::uno::Exception(MESSAGE_SETSIZE_FAILED, 0); 212 213 // b) current size of used XCU lists reflects the current state of 214 // history list and not max size. So it can be less then size ! 215 css::uno::Reference< css::container::XNameAccess > xList; 216 xList = impl_getItemList(); 217 nCheck = xList->getElementNames().getLength(); 218 if (nCheck > nSize) 219 throw css::uno::Exception(MESSAGE_SETSIZE_FAILED, 0); 220 221 xList = impl_getOrderList(); 222 nCheck = xList->getElementNames().getLength(); 223 if (nCheck > nSize) 224 throw css::uno::Exception(MESSAGE_SETSIZE_FAILED, 0); 225 } 226 227 //============================================================================= 228 void HistoryOptTest::impl_appendItem(::sal_Int32 nItem) 229 { 230 const ::rtl::OUString sURL = impl_createItemURL (nItem); 231 const ::rtl::OUString sTitle = impl_createItemTitle (nItem); 232 const ::rtl::OUString sPassword = impl_createItemPassword(nItem); 233 234 m_aConfigItem.AppendItem(m_eList, sURL, ::rtl::OUString(), sTitle, sPassword); 235 } 236 237 //============================================================================= 238 ::rtl::OUString HistoryOptTest::impl_createItemURL(::sal_Int32 nItem) 239 { 240 ::rtl::OUStringBuffer sURL(256); 241 sURL.appendAscii("file:///ooo_api_test/non_existing_test_url_"); 242 sURL.append ((::sal_Int32)nItem ); 243 sURL.appendAscii(".odt" ); 244 245 return sURL.makeStringAndClear(); 246 } 247 248 //============================================================================= 249 ::rtl::OUString HistoryOptTest::impl_createItemTitle(::sal_Int32 nItem) 250 { 251 ::rtl::OUStringBuffer sTitle(256); 252 sTitle.appendAscii("Non Existing Test Item Nr "); 253 sTitle.append ((::sal_Int32)nItem ); 254 255 return sTitle.makeStringAndClear(); 256 } 257 258 //============================================================================= 259 ::rtl::OUString HistoryOptTest::impl_createItemPassword(::sal_Int32 nItem) 260 { 261 ::rtl::OUStringBuffer sPassword(256); 262 sPassword.appendAscii("Password_" ); 263 sPassword.append ((::sal_Int32)nItem); 264 265 return sPassword.makeStringAndClear(); 266 } 267 268 //============================================================================= 269 ::sal_Bool HistoryOptTest::impl_existsItem(::sal_Int32 nItem) 270 { 271 const ::rtl::OUString sURL = impl_createItemURL(nItem); 272 const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > lItems = m_aConfigItem.GetList(m_eList); 273 const ::sal_Int32 c = lItems.getLength (); 274 ::sal_Int32 i = 0; 275 ::sal_Bool bFound = sal_False; 276 277 for (i=0; i<c; ++i) 278 { 279 const ::comphelper::SequenceAsHashMap aItem(lItems[i]); 280 const ::rtl::OUString& sCheck = aItem.getUnpackedValueOrDefault(s_sURL, ::rtl::OUString()); 281 282 bFound = sCheck.equals(sURL); 283 if (bFound) 284 break; 285 } 286 287 if ( ! bFound) 288 return sal_False; 289 bFound = sal_False; 290 291 try 292 { 293 css::uno::Reference< css::container::XNameAccess > xItemList = impl_getItemList(); 294 css::uno::Reference< css::container::XNameAccess > xItem ; 295 xItemList->getByName(sURL) >>= xItem; 296 297 bFound = xItem.is(); 298 } 299 catch(const css::container::NoSuchElementException&) 300 {} 301 302 return bFound; 303 } 304 305 //============================================================================= 306 ::sal_Bool HistoryOptTest::impl_existsItemAtIndex(::sal_Int32 nItem , 307 ::sal_Int32 nIndex) 308 { 309 const ::rtl::OUString sURL = impl_createItemURL(nItem); 310 const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > lItems = m_aConfigItem.GetList(m_eList); 311 const ::sal_Int32 c = lItems.getLength (); 312 ::sal_Bool bFound = sal_False; 313 314 if (nIndex >= c) 315 return sal_False; 316 317 const ::comphelper::SequenceAsHashMap aItem(lItems[nIndex]); 318 ::rtl::OUString sCheck = aItem.getUnpackedValueOrDefault(s_sURL, ::rtl::OUString()); 319 320 bFound = sCheck.equals(sURL); 321 if ( ! bFound) 322 return sal_False; 323 bFound = sal_False; 324 325 try 326 { 327 css::uno::Reference< css::container::XNameAccess > xItemList = impl_getItemList(); 328 css::uno::Reference< css::container::XNameAccess > xItem ; 329 xItemList->getByName(sURL) >>= xItem; 330 331 bFound = xItem.is(); 332 } 333 catch(const css::container::NoSuchElementException&) 334 {} 335 336 if ( ! bFound) 337 return sal_False; 338 bFound = sal_False; 339 340 try 341 { 342 const ::rtl::OUString sOrder = ::rtl::OUString::valueOf(nIndex); 343 css::uno::Reference< css::container::XNameAccess > xOrderList = impl_getOrderList(); 344 css::uno::Reference< css::container::XNameAccess > xOrder ; 345 xOrderList->getByName(sOrder) >>= xOrder; 346 347 if (xOrder.is()) 348 { 349 xOrder->getByName(s_sHistoryItemRef) >>= sCheck; 350 bFound = sCheck.equals(sURL); 351 } 352 } 353 catch(const css::container::NoSuchElementException&) 354 {} 355 356 return bFound; 357 } 358 359 //============================================================================= 360 css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getItemList() 361 { 362 css::uno::Reference< css::container::XNameAccess > xHistory = impl_getNewHistory(); 363 css::uno::Reference< css::container::XNameAccess > xList ; 364 xHistory->getByName (s_sItemList) >>= xList; 365 366 if ( ! xList.is()) 367 throw css::uno::Exception(MESSAGE_MISS_ITEMLIST, 0); 368 369 return xList; 370 } 371 372 //============================================================================= 373 css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getOrderList() 374 { 375 css::uno::Reference< css::container::XNameAccess > xHistory = impl_getNewHistory(); 376 css::uno::Reference< css::container::XNameAccess > xList ; 377 xHistory->getByName (s_sOrderList) >>= xList; 378 379 if ( ! xList.is()) 380 throw css::uno::Exception(MESSAGE_MISS_ORDERLIST, 0); 381 382 return xList; 383 } 384 385 //============================================================================= 386 css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getNewHistory() 387 { 388 if ( ! m_xHistoriesXCU.is()) 389 { 390 m_xHistoriesXCU = css::uno::Reference< css::container::XNameAccess >( 391 ::comphelper::ConfigurationHelper::openConfig( 392 ::utl::getProcessServiceFactory(), 393 s_sHistories, 394 ::comphelper::ConfigurationHelper::E_STANDARD), 395 css::uno::UNO_QUERY_THROW); 396 } 397 398 css::uno::Reference< css::container::XNameAccess > xHistory; 399 400 switch (m_eList) 401 { 402 case ePICKLIST : 403 m_xHistoriesXCU->getByName(s_sPickList) >>= xHistory; 404 break; 405 406 case eHISTORY : 407 m_xHistoriesXCU->getByName(s_sURLHistory) >>= xHistory; 408 break; 409 410 case eHELPBOOKMARKS : 411 m_xHistoriesXCU->getByName(s_sHelpBookmarks) >>= xHistory; 412 break; 413 } 414 415 if ( ! xHistory.is()) 416 throw css::uno::Exception(MESSAGE_MISS_HISTORY, 0); 417 418 return xHistory; 419 } 420 421 //============================================================================= 422 css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getOldHistory() 423 { 424 if ( ! m_xCommonXCU.is()) 425 { 426 m_xCommonXCU = css::uno::Reference< css::container::XNameAccess >( 427 ::comphelper::ConfigurationHelper::openConfig( 428 ::utl::getProcessServiceFactory(), 429 s_sCommonHistory, 430 ::comphelper::ConfigurationHelper::E_STANDARD), 431 css::uno::UNO_QUERY_THROW); 432 } 433 434 css::uno::Reference< css::container::XNameAccess > xHistory; 435 436 switch (m_eList) 437 { 438 case ePICKLIST : 439 m_xCommonXCU->getByName(s_sPickList) >>= xHistory; 440 break; 441 442 case eHISTORY : 443 m_xCommonXCU->getByName(s_sURLHistory) >>= xHistory; 444 break; 445 446 case eHELPBOOKMARKS : 447 m_xCommonXCU->getByName(s_sHelpBookmarks) >>= xHistory; 448 break; 449 } 450 451 if ( ! xHistory.is()) 452 throw css::uno::Exception(MESSAGE_MISS_HISTORY, 0); 453 454 return xHistory; 455 } 456 457 /* 458 //============================================================================= 459 // clear the list in XML directly when using the new Histories.xcs 460 void HistoryOptTest::impl_clearList(const ::rtl::OUString& sList) 461 { 462 css::uno::Reference< css::container::XNameAccess > xListAccess; 463 css::uno::Reference< css::container::XNameContainer > xItemOrder; 464 css::uno::Reference< css::beans::XPropertySet > xFirstItem; 465 css::uno::Sequence< ::rtl::OUString > sFileList; 466 467 if (sList.equalsAscii("PickList")) 468 m_xCfg->getByName(s_sPickList) >>= xListAccess; 469 470 else if (sList.equalsAscii("URLHistory")) 471 m_xCfg->getByName(s_sURLHistory) >>= xListAccess; 472 473 else if (sList.equalsAscii("HelpBookmarks")) 474 m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess; 475 476 if (xListAccess.is()) 477 { 478 xListAccess->getByName(s_sItemList) >>= xItemOrder ; 479 sFileList = xItemOrder->getElementNames(); 480 for(sal_Int32 i=0; i<sFileList.getLength(); ++i) 481 xItemOrder->removeByName(sFileList[i]); 482 483 xListAccess->getByName(s_sOrderList) >>= xItemOrder ; 484 sFileList = xItemOrder->getElementNames(); 485 for(sal_Int32 j=0; j<sFileList.getLength(); ++j) 486 xItemOrder->removeByName(sFileList[j]); 487 488 xFirstItem = css::uno::Reference< css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY); 489 xFirstItem->setPropertyValue( s_sFirstItem, css::uno::makeAny((sal_Int32)0) ); 490 491 ::comphelper::ConfigurationHelper::flush(m_xCfg); 492 } 493 } 494 495 //============================================================================= 496 // use configuration API (not ConfigItem!) to verify the results within XML ! 497 sal_Bool HistoryOptTest::impl_isListEmpty(const ::rtl::OUString& sList) 498 { 499 css::uno::Reference< css::container::XNameAccess > xListAccess; 500 css::uno::Reference< css::container::XNameAccess > xItemList; 501 css::uno::Reference< css::container::XNameAccess > xOrderList; 502 sal_Bool bRet = sal_True; 503 504 if (sList.equalsAscii("PickList")) 505 m_xCfg->getByName(s_sPickList) >>= xListAccess; 506 507 else if (sList.equalsAscii("URLHistory")) 508 m_xCfg->getByName(s_sURLHistory) >>= xListAccess; 509 510 else if (sList.equalsAscii("HelpBookmarks")) 511 m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess; 512 513 if (xListAccess.is()) 514 { 515 xListAccess->getByName(s_sItemList) >>= xItemList; 516 xListAccess->getByName(s_sOrderList) >>= xOrderList; 517 518 css::uno::Sequence< ::rtl::OUString > sItemList = xItemList->getElementNames(); 519 css::uno::Sequence< ::rtl::OUString > sOrderList = xOrderList->getElementNames(); 520 if (sItemList.getLength()!=0 || sOrderList.getLength()!=0) 521 bRet = sal_False; 522 } 523 524 return bRet; 525 } 526 527 //============================================================================= 528 // append a item: use configuration API (not ConfigItem!) to verify the results within XML ! 529 void HistoryOptTest::impl_appendItem(const ::rtl::OUString& sList) 530 {//to do... 531 } 532 533 //============================================================================= 534 // test SvtHistoryOptions::GetSize() 535 void HistoryOptTest::impl_checkGetSize(const ::rtl::OUString& sList) 536 { 537 css::uno::Reference< css::beans::XPropertySet > xSet(m_xCommonXCU, css::uno::UNO_QUERY); 538 539 sal_uInt32 nSize = 0; 540 sal_uInt32 nSize_ = 0; 541 542 if (sList.equalsAscii("PickList")) 543 { 544 nSize = aHistoryOpt.GetSize(ePICKLIST); 545 546 xSet->setPropertyValue(s_sPickListSize, css::uno::makeAny(nSize+1)); 547 ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); 548 549 nSize_ = aHistoryOpt.GetSize(ePICKLIST); 550 if (nSize_ == nSize) 551 throw css::uno::RuntimeException( 552 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetSize(ePICKLIST) error!")), 0); 553 } 554 555 else if (sList.equalsAscii("URLHistory")) 556 { 557 nSize = aHistoryOpt.GetSize(eHISTORY); 558 559 xSet->setPropertyValue(s_sURLHistorySize, css::uno::makeAny(nSize+1)); 560 ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); 561 562 nSize_ = aHistoryOpt.GetSize(eHISTORY); 563 564 if (nSize_ == nSize) 565 throw css::uno::RuntimeException( 566 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetSize(eHISTORY) error!")), 0); 567 } 568 569 else if (sList.equalsAscii("HelpBookmarks")) 570 { 571 nSize = aHistoryOpt.GetSize(eHELPBOOKMARKS); 572 573 xSet->setPropertyValue(s_sHelpBookmarksSize, css::uno::makeAny(nSize+1)); 574 ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); 575 576 nSize_ = aHistoryOpt.GetSize(eHELPBOOKMARKS); 577 578 if (nSize_ == nSize) 579 throw css::uno::RuntimeException( 580 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetSize(eHELPBOOKMARKS) error!")), 0); 581 } 582 } 583 584 //============================================================================= 585 // test SvtHistoryOptions::SetSize() 586 void HistoryOptTest::impl_checkSetSize(const ::rtl::OUString& sList) 587 { 588 css::uno::Reference< css::beans::XPropertySet > xSet(m_xCommonXCU, css::uno::UNO_QUERY); 589 590 sal_uInt32 nSize = 0; 591 sal_uInt32 nSize_ = 0; 592 593 if (sList.equalsAscii("PickList")) 594 { 595 xSet->getPropertyValue(s_sPickListSize) >>= nSize; 596 aHistoryOpt.SetSize(ePICKLIST, (nSize+1)); 597 xSet->getPropertyValue(s_sPickListSize) >>= nSize_; 598 599 if (nSize_ == nSize) //old config item will throw error 600 throw css::uno::RuntimeException( 601 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetSize(ePICKLIST) error!")), 0); 602 } 603 604 else if (sList.equalsAscii("URLHistory")) 605 { 606 xSet->getPropertyValue(s_sURLHistorySize) >>= nSize; 607 aHistoryOpt.SetSize(eHISTORY, (nSize+1)); 608 xSet->getPropertyValue(s_sURLHistorySize) >>= nSize_; 609 610 if (nSize_ == nSize) //old config item will throw error 611 throw css::uno::RuntimeException( 612 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetSize(eHISTORY) error!")), 0); 613 } 614 615 else if (sList.equalsAscii("HelpBookmarks")) 616 { 617 xSet->getPropertyValue(s_sHelpBookmarksSize) >>= nSize; 618 aHistoryOpt.SetSize(eHELPBOOKMARKS, (nSize+1)); 619 xSet->getPropertyValue(s_sHelpBookmarksSize) >>= nSize_; 620 621 if (nSize_ == nSize) //old config item will throw error 622 throw css::uno::RuntimeException( 623 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetSize(eHELPBOOKMARKS) error!")), 0); 624 } 625 } 626 627 //============================================================================= 628 // test SvtHistoryOptions::Clear() 629 void HistoryOptTest::impl_checkClear(const ::rtl::OUString& sList) 630 { 631 if (sList.equalsAscii("PickList")) 632 { 633 aHistoryOpt.Clear(ePICKLIST); 634 if ( !impl_isListEmpty(s_sPickList) ) 635 throw css::uno::RuntimeException( 636 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Clear(ePICKLIST) error!")), 0); 637 } 638 639 else if (sList.equalsAscii("URLHistory")) 640 { 641 aHistoryOpt.Clear(eHISTORY); 642 if ( !impl_isListEmpty(s_sURLHistory) ) 643 throw css::uno::RuntimeException( 644 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Clear(eHISTORY) error!")), 0); 645 } 646 647 else if (sList.equalsAscii("HelpBookmarks")) 648 { 649 aHistoryOpt.Clear(eHELPBOOKMARKS); 650 if ( !impl_isListEmpty(s_sHelpBookmarks) ) 651 throw css::uno::RuntimeException( 652 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Clear(eHELPBOOKMARKS) error!")), 0); 653 } 654 } 655 656 //============================================================================= 657 // test SvtHistoryOptions::GetList() 658 void HistoryOptTest::impl_checkGetList(const ::rtl::OUString& sList) 659 { 660 if (sList.equalsAscii("PickList")) 661 { 662 impl_clearList(s_sPickList); 663 aHistoryOpt.AppendItem( ePICKLIST , 664 ::rtl::OUString::createFromAscii("file:///c/test1"), 665 ::rtl::OUString::createFromAscii(""), 666 ::rtl::OUString::createFromAscii(""), 667 ::rtl::OUString::createFromAscii("") ); 668 css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aHistoryList = aHistoryOpt.GetList( ePICKLIST ); 669 670 if ( aHistoryList.getLength()==0 ) 671 throw css::uno::RuntimeException( 672 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetList(ePICKLIST) error!")), 0); 673 } 674 675 else if (sList.equalsAscii("URLHistory")) 676 { 677 impl_clearList(s_sURLHistory); 678 aHistoryOpt.AppendItem( eHISTORY , 679 ::rtl::OUString::createFromAscii("file:///c/test1"), 680 ::rtl::OUString::createFromAscii(""), 681 ::rtl::OUString::createFromAscii(""), 682 ::rtl::OUString::createFromAscii("") ); 683 css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aHistoryList = aHistoryOpt.GetList( eHISTORY ); 684 685 if ( aHistoryList.getLength()==0 ) 686 throw css::uno::RuntimeException( 687 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetList(eHISTORY) error!")), 0); 688 } 689 690 else if (sList.equalsAscii("HelpBookmarks")) 691 { 692 impl_clearList(s_sHelpBookmarks); 693 aHistoryOpt.AppendItem( eHELPBOOKMARKS , 694 ::rtl::OUString::createFromAscii("file:///c/test1"), 695 ::rtl::OUString::createFromAscii(""), 696 ::rtl::OUString::createFromAscii(""), 697 ::rtl::OUString::createFromAscii("") ); 698 css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aHistoryList = aHistoryOpt.GetList( eHELPBOOKMARKS ); 699 700 if ( aHistoryList.getLength()==0 ) 701 throw css::uno::RuntimeException( 702 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetList(eHELPBOOKMARKS) error!")), 0); 703 } 704 } 705 706 void HistoryOptTest::impl_checkAppendItem(const ::rtl::OUString& sList) 707 { 708 if (sList.equalsAscii("PickList")) 709 { 710 impl_clearList(s_sPickList); 711 sal_Int32 nListSize = aHistoryOpt.GetSize(ePICKLIST); 712 713 for (sal_Int32 i=0; i<nListSize; ++i) 714 aHistoryOpt.AppendItem( ePICKLIST , 715 ::rtl::OUString::valueOf(i), 716 ::rtl::OUString::createFromAscii(""), 717 ::rtl::OUString::createFromAscii(""), 718 ::rtl::OUString::createFromAscii("") ); 719 720 aHistoryOpt.AppendItem( ePICKLIST , 721 ::rtl::OUString::valueOf(nListSize), 722 ::rtl::OUString::createFromAscii(""), 723 ::rtl::OUString::createFromAscii(""), 724 ::rtl::OUString::createFromAscii("") ); 725 } 726 727 else if (sList.equalsAscii("URLHistory")) 728 { 729 impl_clearList(s_sURLHistory); 730 sal_Int32 nListSize = aHistoryOpt.GetSize(eHISTORY); 731 732 for (sal_Int32 i=0; i<nListSize; ++i) 733 aHistoryOpt.AppendItem( eHISTORY , 734 ::rtl::OUString::valueOf(i), 735 ::rtl::OUString::createFromAscii(""), 736 ::rtl::OUString::createFromAscii(""), 737 ::rtl::OUString::createFromAscii("") ); 738 739 aHistoryOpt.AppendItem( eHISTORY , 740 ::rtl::OUString::valueOf(nListSize), 741 ::rtl::OUString::createFromAscii(""), 742 ::rtl::OUString::createFromAscii(""), 743 ::rtl::OUString::createFromAscii("") ); 744 } 745 746 else if (sList.equalsAscii("HelpBookmarks")) 747 { 748 //impl_clearList(s_sHelpBookmarks); 749 //sal_Int32 nListSize = aHistoryOpt.GetSize(eHELPBOOKMARKS); 750 751 //for (sal_Int32 i=0; i<nListSize; ++i) 752 // aHistoryOpt.AppendItem( eHELPBOOKMARKS , 753 // ::rtl::OUString::valueOf(i), 754 // ::rtl::OUString::createFromAscii(""), 755 // ::rtl::OUString::createFromAscii(""), 756 // ::rtl::OUString::createFromAscii("") ); 757 758 //aHistoryOpt.AppendItem( eHELPBOOKMARKS , 759 // ::rtl::OUString::valueOf(nListSize), 760 // ::rtl::OUString::createFromAscii(""), 761 // ::rtl::OUString::createFromAscii(""), 762 // ::rtl::OUString::createFromAscii("") ); 763 } 764 } 765 766 //============================================================================= 767 void HistoryOptTest::impl_checkPicklist() 768 { 769 impl_checkGetSize(s_sPickList); 770 impl_checkSetSize(s_sPickList); 771 772 impl_checkClear(s_sPickList); 773 impl_checkGetList(s_sPickList); 774 impl_checkAppendItem(s_sPickList); 775 } 776 777 //============================================================================= 778 void HistoryOptTest::impl_checkURLHistory() 779 { 780 impl_checkGetSize(s_sURLHistory); 781 impl_checkSetSize(s_sURLHistory); 782 783 impl_checkClear(s_sURLHistory); 784 impl_checkGetList(s_sURLHistory); 785 impl_checkAppendItem(s_sURLHistory); 786 } 787 788 //============================================================================= 789 void HistoryOptTest::impl_checkHelpBookmarks() 790 { 791 impl_checkGetSize(s_sHelpBookmarks); 792 impl_checkSetSize(s_sHelpBookmarks); 793 794 impl_checkClear(s_sHelpBookmarks); 795 impl_checkGetList(s_sHelpBookmarks); 796 impl_checkAppendItem(s_sHelpBookmarks); 797 } 798 */ 799