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