1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
31 //------------------------------------------------------------------------
33 //------------------------------------------------------------------------
34 #include "cppunit/TestAssert.h"
35 #include "cppunit/TestFixture.h"
36 #include "cppunit/extensions/HelperMacros.h"
37 #include "cppunit/plugin/TestPlugIn.h"
38 #include <osl_Mutex_Const.h>
43 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
47 /** print a UNI_CODE String.
49 inline void printUString( const ::rtl::OUString
& str
)
53 printf("#printUString_u# " );
54 aString
= ::rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
55 printf("%s\n", aString
.getStr( ) );
58 /** print Boolean value.
60 inline void printBool( sal_Bool bOk
)
62 printf("#printBool# " );
63 ( sal_True
== bOk
) ? printf("YES!\n" ): printf("NO!\n" );
66 /** pause nSec seconds helper function.
68 namespace ThreadHelper
70 void thread_sleep( sal_Int32 _nSec
)
72 /// print statement in thread process must use fflush() to force display.
73 // t_print("# wait %d seconds. ", _nSec );
77 Sleep( _nSec
* 1000 );
79 #if ( defined UNX ) || ( defined OS2 ) //Unix
82 // printf("# done\n" );
84 void thread_sleep_tenth_sec(sal_Int32 _nTenthSec
)
87 Sleep(_nTenthSec
* 100 );
89 #if ( defined UNX ) || ( defined OS2 ) //Unix
91 nTV
.Seconds
= static_cast<sal_uInt32
>( _nTenthSec
/10 );
92 nTV
.Nanosec
= ( (_nTenthSec
%10 ) * 100000000 );
99 //------------------------------------------------------------------------
100 // Beginning of the test cases for osl_Mutex class
101 //------------------------------------------------------------------------
104 /** mutually exclusive data
112 /** IncreaseThread provide data.
114 class IncreaseThread
: public Thread
117 IncreaseThread( struct resource
*pData
): pResource( pData
) { }
121 CPPUNIT_ASSERT_MESSAGE( "#IncreaseThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
124 struct resource
*pResource
;
128 pResource
->lock
.acquire( );
129 for( sal_Int8 i
= 0; i
< 3; i
++ )
132 yield( ); //yield() give CPU time to other thread, other thread if not block, they will change the data;
134 if ( pResource
->data2
== 0 )
135 pResource
->data2
= ( pResource
->data1
> 0 ? pResource
->data1
: 0 - pResource
->data1
);
136 pResource
->lock
.release();
140 /** DecreaseThread consume data.
142 class DecreaseThread
: public Thread
145 DecreaseThread( struct resource
*pData
): pResource( pData
) { }
149 CPPUNIT_ASSERT_MESSAGE( "#DecreaseThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
152 struct resource
*pResource
;
156 pResource
->lock
.acquire( );
157 for( sal_Int8 i
= 0; i
< 3; i
++ )
160 yield( ); //yield() give CPU time to other thread, other thread if not block, they will change the data;
162 if ( pResource
->data2
== 0 )
163 pResource
->data2
= ( pResource
->data1
> 0 ? pResource
->data1
: 0 - pResource
->data1
);
164 pResource
->lock
.release();
169 /** chain structure used in Threads as critical resource
172 sal_Int32 buffer
[ BUFFER_SIZE
];
177 /** PutThread write to the chain structure in a mutex manner.
179 class PutThread
: public Thread
182 //get the struct pointer to write data to buffer
183 PutThread( struct chain
* pData
): pChain( pData
) { }
187 CPPUNIT_ASSERT_MESSAGE( "#PutThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
190 struct chain
* pChain
;
194 //block here if the mutex has been acquired
195 pChain
->lock
.acquire( );
197 //current position in buffer to write
198 sal_Int8 nPos
= pChain
->pos
;
199 oslThreadIdentifier oId
= getIdentifier( );
202 for ( i
= 0; i
< 5; i
++ )
204 pChain
->buffer
[ nPos
+ i
] = oId
;
207 //revise the position
208 pChain
->pos
= nPos
+ i
;
210 //finish writing, release the mutex
211 pChain
->lock
.release();
215 /** thread for testing Mutex acquire.
217 class HoldThread
: public Thread
220 //get the Mutex pointer to operate
221 HoldThread( Mutex
* pMutex
): pMyMutex( pMutex
) { }
225 CPPUNIT_ASSERT_MESSAGE( "#HoldThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
232 // block here if the mutex has been acquired
233 pMyMutex
->acquire( );
234 printf("# Mutex acquired. \n" );
235 pMyMutex
->release( );
239 class WaitThread
: public Thread
242 //get the Mutex pointer to operate
243 WaitThread( Mutex
* pMutex
): pMyMutex( pMutex
) { }
247 CPPUNIT_ASSERT_MESSAGE( "#WaitThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
254 // block here if the mutex has been acquired
255 pMyMutex
->acquire( );
256 ThreadHelper::thread_sleep_tenth_sec( 2 );
257 pMyMutex
->release( );
261 /** thread for testing getGlobalMutex.
263 class GlobalMutexThread
: public Thread
266 //get the Mutex pointer to operate
267 GlobalMutexThread( ){ }
269 ~GlobalMutexThread( )
271 CPPUNIT_ASSERT_MESSAGE( "#GlobalMutexThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
276 // block here if the mutex has been acquired
278 pGlobalMutex
= pGlobalMutex
->getGlobalMutex( );
279 pGlobalMutex
->acquire( );
280 printf("# Global Mutex acquired. \n" );
281 pGlobalMutex
->release( );
286 //--------------------------------------------------------------
290 /** Test of the osl::Mutex::constructor
292 class ctor
: public CppUnit::TestFixture
295 // initialise your test code values here.
297 struct resource m_Res
;
301 for ( sal_Int8 i
=0; i
< BUFFER_SIZE
; i
++ )
302 m_Data
.buffer
[i
] = 0;
313 /** Create two threads to write data to the same buffer, use Mutex to assure
314 during one thread write data five times, the other thread should not begin writing.
315 the two threads wrote two different datas: their thread ID, so we can check the datas
316 in buffer to know the order of the two threads writing
320 PutThread
myThread1( &m_Data
);
321 PutThread
myThread2( &m_Data
);
326 //wait until the two threads terminate
330 sal_Bool bRes
= sal_False
;
332 // every 5 datas should the same
333 // LLA: this is not a good check, it's too fix
334 if (m_Data
.buffer
[0] == m_Data
.buffer
[1] &&
335 m_Data
.buffer
[1] == m_Data
.buffer
[2] &&
336 m_Data
.buffer
[2] == m_Data
.buffer
[3] &&
337 m_Data
.buffer
[3] == m_Data
.buffer
[4] &&
338 m_Data
.buffer
[5] == m_Data
.buffer
[6] &&
339 m_Data
.buffer
[6] == m_Data
.buffer
[7] &&
340 m_Data
.buffer
[7] == m_Data
.buffer
[8] &&
341 m_Data
.buffer
[8] == m_Data
.buffer
[9])
344 /*for (sal_Int8 i=0; i<BUFFER_SIZE; i++)
345 printf("#data in buffer is %d\n", m_Data.buffer[i]);
348 CPPUNIT_ASSERT_MESSAGE("Mutex ctor", bRes
== sal_True
);
352 /** Create two threads to write data to operate on the same number , use Mutex to assure,
353 one thread increase data 3 times, the other thread decrease 3 times, store the operate
354 result when the first thread complete, if it is interrupt by the other thread, the stored
355 number will not be 3.
359 IncreaseThread
myThread1( &m_Res
);
360 DecreaseThread
myThread2( &m_Res
);
365 //wait until the two threads terminate
369 sal_Bool bRes
= sal_False
;
371 // every 5 datas should the same
372 if ( ( m_Res
.data1
== 0 ) && ( m_Res
.data2
== 3 ) )
375 CPPUNIT_ASSERT_MESSAGE( "test Mutex ctor function: increase and decrease a number 3 times without interrupt.", bRes
== sal_True
);
378 CPPUNIT_TEST_SUITE( ctor
);
379 CPPUNIT_TEST( ctor_001
);
380 CPPUNIT_TEST( ctor_002
);
381 CPPUNIT_TEST_SUITE_END( );
385 /** Test of the osl::Mutex::acquire method
387 class acquire
: public CppUnit::TestFixture
390 // acquire mutex in main thread, and then call acquire again in myThread,
391 // the child thread should block, wait 2 secs, it still block.
392 // Then release mutex in main thread, the child thread could return from acquire,
393 // and go to exec next statement, so could terminate quickly.
398 sal_Bool bRes
= aMutex
.acquire( );
399 // pass the pointer of mutex to child thread
400 HoldThread
myThread( &aMutex
);
403 ThreadHelper::thread_sleep_tenth_sec( 2 );
404 // if acquire in myThread does not work, 2 secs is long enough,
405 // myThread should terminate now, and bRes1 should be sal_False
406 sal_Bool bRes1
= myThread
.isRunning( );
409 ThreadHelper::thread_sleep_tenth_sec( 1 );
410 // after release mutex, myThread stops blocking and will terminate immediately
411 sal_Bool bRes2
= myThread
.isRunning( );
414 CPPUNIT_ASSERT_MESSAGE( "Mutex acquire",
415 bRes
== sal_True
&& bRes1
== sal_True
&& bRes2
== sal_False
);
418 //in the same thread, acquire twice should success
423 sal_Bool bRes
= aMutex
.acquire();
424 sal_Bool bRes1
= aMutex
.acquire();
426 sal_Bool bRes2
= aMutex
.tryToAcquire();
430 CPPUNIT_ASSERT_MESSAGE("Mutex acquire",
431 bRes
== sal_True
&& bRes1
== sal_True
&& bRes2
== sal_True
);
435 CPPUNIT_TEST_SUITE( acquire
);
436 CPPUNIT_TEST( acquire_001
);
437 CPPUNIT_TEST( acquire_002
);
438 CPPUNIT_TEST_SUITE_END( );
442 /** Test of the osl::Mutex::tryToAcquire method
444 class tryToAcquire
: public CppUnit::TestFixture
447 // First let child thread acquire the mutex, and wait 2 secs, during the 2 secs,
448 // in main thread, tryToAcquire mutex should return False
449 // then after the child thread terminated, tryToAcquire should return True
450 void tryToAcquire_001()
453 WaitThread
myThread(&aMutex
);
456 // ensure the child thread acquire the mutex
457 ThreadHelper::thread_sleep_tenth_sec(1);
459 sal_Bool bRes1
= aMutex
.tryToAcquire();
461 if (bRes1
== sal_True
)
463 // wait the child thread terminate
466 sal_Bool bRes2
= aMutex
.tryToAcquire();
468 if (bRes2
== sal_True
)
471 CPPUNIT_ASSERT_MESSAGE("Try to acquire Mutex",
472 bRes1
== sal_False
&& bRes2
== sal_True
);
475 CPPUNIT_TEST_SUITE(tryToAcquire
);
476 CPPUNIT_TEST(tryToAcquire_001
);
477 CPPUNIT_TEST_SUITE_END();
478 }; // class tryToAcquire
480 /** Test of the osl::Mutex::release method
482 class release
: public CppUnit::TestFixture
485 /** acquire/release are not used in pairs: after child thread acquired mutex,
486 the main thread release it, then any thread could acquire it.
491 WaitThread
myThread( &aMutex
);
494 // ensure the child thread acquire the mutex
495 ThreadHelper::thread_sleep_tenth_sec( 1 );
497 sal_Bool bRunning
= myThread
.isRunning( );
498 sal_Bool bRes1
= aMutex
.tryToAcquire( );
499 // wait the child thread terminate
502 sal_Bool bRes2
= aMutex
.tryToAcquire( );
504 if ( bRes2
== sal_True
)
507 CPPUNIT_ASSERT_MESSAGE( "release Mutex: try to aquire before and after the mutex has been released",
508 bRes1
== sal_False
&& bRes2
== sal_True
&& bRunning
== sal_True
);
512 // how about release twice?
515 // LLA: is this a real test?
518 sal_Bool bRes1
= aMutex
.release( );
519 sal_Bool bRes2
= aMutex
.release( );
521 CPPUNIT_ASSERT_MESSAGE( "release Mutex: mutex should not be released without aquire, should not release twice. although the behaviour is still under discussion, this test is passed on (LINUX), not passed on (SOLARIS)&(WINDOWS)",
522 bRes1
== sal_False
&& bRes2
== sal_False
);
526 CPPUNIT_TEST_SUITE( release
);
527 CPPUNIT_TEST( release_001
);
528 CPPUNIT_TEST( release_002
);
529 CPPUNIT_TEST_SUITE_END( );
534 /** Test of the osl::Mutex::getGlobalMutex method
536 class getGlobalMutex
: public CppUnit::TestFixture
539 // initialise your test code values here.
540 void getGlobalMutex_001()
543 pGlobalMutex
= pGlobalMutex
->getGlobalMutex();
544 pGlobalMutex
->acquire();
546 GlobalMutexThread myThread
;
549 ThreadHelper::thread_sleep_tenth_sec(1);
550 sal_Bool bRes1
= myThread
.isRunning();
552 pGlobalMutex
->release();
553 ThreadHelper::thread_sleep_tenth_sec(1);
554 // after release mutex, myThread stops blocking and will terminate immediately
555 sal_Bool bRes2
= myThread
.isRunning();
557 CPPUNIT_ASSERT_MESSAGE("Global Mutex works",
558 bRes1
== sal_True
&& bRes2
== sal_False
);
561 void getGlobalMutex_002( )
566 pGlobalMutex
= pGlobalMutex
->getGlobalMutex( );
567 pGlobalMutex
->acquire( );
569 Mutex
*pGlobalMutex1
;
570 pGlobalMutex1
= pGlobalMutex1
->getGlobalMutex( );
571 bRes
= pGlobalMutex1
->release( );
574 CPPUNIT_ASSERT_MESSAGE( "Global Mutex works: if the code between {} get the different mutex as the former one, it will return false when release.",
578 CPPUNIT_TEST_SUITE(getGlobalMutex
);
579 CPPUNIT_TEST(getGlobalMutex_001
);
580 CPPUNIT_TEST(getGlobalMutex_002
);
581 CPPUNIT_TEST_SUITE_END();
582 }; // class getGlobalMutex
584 // -----------------------------------------------------------------------------
585 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::ctor
, "osl_Mutex");
586 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::acquire
, "osl_Mutex");
587 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::tryToAcquire
, "osl_Mutex");
588 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::release
, "osl_Mutex");
589 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::getGlobalMutex
, "osl_Mutex");
590 } // namespace osl_Mutex
593 //------------------------------------------------------------------------
594 // Beginning of the test cases for osl_Guard class
595 //------------------------------------------------------------------------
597 class GuardThread
: public Thread
600 //get the Mutex pointer to operate
601 GuardThread( Mutex
* pMutex
): pMyMutex( pMutex
) { }
605 CPPUNIT_ASSERT_MESSAGE( "#GuardThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
612 // block here if the mutex has been acquired
613 MutexGuard
aGuard( pMyMutex
);
614 ThreadHelper::thread_sleep_tenth_sec( 2 );
621 class ctor
: public CppUnit::TestFixture
624 // insert your test code here.
628 GuardThread
myThread(&aMutex
);
631 ThreadHelper::thread_sleep_tenth_sec(1);
632 sal_Bool bRes
= aMutex
.tryToAcquire();
633 // after 1 second, the mutex has been guarded, and the child thread should be running
634 sal_Bool bRes1
= myThread
.isRunning();
637 sal_Bool bRes2
= aMutex
.tryToAcquire();
639 CPPUNIT_ASSERT_MESSAGE("GuardThread constructor",
640 bRes
== sal_False
&& bRes1
== sal_True
&& bRes2
== sal_True
);
647 /// use reference constructor here
648 MutexGuard
myGuard( aMutex
);
650 /// the GuardThread will block here when it is initialised.
651 GuardThread
myThread( &aMutex
);
654 /// is it still blocking?
655 ThreadHelper::thread_sleep_tenth_sec( 2 );
656 sal_Bool bRes
= myThread
.isRunning( );
662 CPPUNIT_ASSERT_MESSAGE("GuardThread constructor: reference initialization, aquire the mutex before running the thread, then check if it is blocking.",
666 CPPUNIT_TEST_SUITE(ctor
);
667 CPPUNIT_TEST(ctor_001
);
668 CPPUNIT_TEST(ctor_002
);
669 CPPUNIT_TEST_SUITE_END();
672 // -----------------------------------------------------------------------------
673 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Guard::ctor
, "osl_Guard");
674 } // namespace osl_Guard
677 //------------------------------------------------------------------------
678 // Beginning of the test cases for osl_ClearableGuard class
679 //------------------------------------------------------------------------
681 /** Thread for test ClearableGuard
683 class ClearGuardThread
: public Thread
686 //get the Mutex pointer to operate
687 ClearGuardThread( Mutex
* pMutex
): pMyMutex( pMutex
) {}
691 CPPUNIT_ASSERT_MESSAGE( "#ClearGuardThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
699 // printf("# ClearGuardThread" );
700 ClearableMutexGuard
aGuard( pMyMutex
);
701 ThreadHelper::thread_sleep( 5 );
705 ThreadHelper::thread_sleep( 2 );
709 // -----------------------------------------------------------------------------
710 namespace osl_ClearableGuard
713 class ctor
: public CppUnit::TestFixture
720 /// now, the aMutex has been guarded.
721 ClearableMutexGuard
myMutexGuard( &aMutex
);
723 /// it will return sal_False if the aMutex has not been Guarded.
724 sal_Bool bRes
= aMutex
.release( );
726 CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the aquire operation when initilized.",
734 /// now, the aMutex has been guarded, this time, we use reference constructor.
735 ClearableMutexGuard
myMutexGuard( aMutex
);
737 /// it will return sal_False if the aMutex has not been Guarded.
738 sal_Bool bRes
= aMutex
.release( );
740 CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the aquire operation when initilized, we use reference constructor this time.",
744 CPPUNIT_TEST_SUITE(ctor
);
745 CPPUNIT_TEST(ctor_001
);
746 CPPUNIT_TEST(ctor_002
);
747 CPPUNIT_TEST_SUITE_END();
750 class clear
: public CppUnit::TestFixture
756 ClearGuardThread
myThread(&aMutex
);
759 TimeValue aTimeVal_befor
;
760 osl_getSystemTime( &aTimeVal_befor
);
761 // wait 1 second to assure the child thread has begun
762 ThreadHelper::thread_sleep(1);
766 if (aMutex
.tryToAcquire() == sal_True
)
770 ThreadHelper::thread_sleep(1);
772 TimeValue aTimeVal_after
;
773 osl_getSystemTime( &aTimeVal_after
);
774 sal_Int32 nSec
= aTimeVal_after
.Seconds
- aTimeVal_befor
.Seconds
;
775 printf("nSec is %"SAL_PRIdINT32
"\n", nSec
);
779 CPPUNIT_ASSERT_MESSAGE("ClearableGuard method: clear",
780 nSec
< 7 && nSec
> 1);
787 /// now, the aMutex has been guarded.
788 ClearableMutexGuard
myMutexGuard( &aMutex
);
790 /// launch the HoldThread, it will be blocked here.
791 HoldThread
myThread( &aMutex
);
795 ThreadHelper::thread_sleep_tenth_sec( 4 );
796 sal_Bool bRes
= myThread
.isRunning( );
798 /// use clear to release.
799 myMutexGuard
.clear( );
801 sal_Bool bRes1
= myThread
.isRunning( );
803 CPPUNIT_ASSERT_MESSAGE( "ClearableGuard method: clear, control the HoldThread's running status!",
804 ( sal_True
== bRes
) && ( sal_False
== bRes1
) );
807 CPPUNIT_TEST_SUITE( clear
);
808 CPPUNIT_TEST( clear_001
);
809 CPPUNIT_TEST( clear_002
);
810 CPPUNIT_TEST_SUITE_END( );
813 // -----------------------------------------------------------------------------
814 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_ClearableGuard::ctor
, "osl_ClearableGuard" );
815 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_ClearableGuard::clear
, "osl_ClearableGuard" );
816 } // namespace osl_ClearableGuard
819 //------------------------------------------------------------------------
820 // Beginning of the test cases for osl_ResettableGuard class
821 //------------------------------------------------------------------------
823 /** Thread for test ResettableGuard
825 class ResetGuardThread
: public Thread
828 //get the Mutex pointer to operate
829 ResetGuardThread( Mutex
* pMutex
): pMyMutex( pMutex
) {}
833 CPPUNIT_ASSERT_MESSAGE( "#ResetGuardThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
841 printf("# ResettableGuard\n" );
842 ResettableMutexGuard
aGuard( pMyMutex
);
845 ThreadHelper::thread_sleep_tenth_sec( 2 );
849 // -----------------------------------------------------------------------------
850 namespace osl_ResettableGuard
852 class ctor
: public CppUnit::TestFixture
859 /// now, the aMutex has been guarded.
860 ResettableMutexGuard
myMutexGuard( &aMutex
);
862 /// it will return sal_False if the aMutex has not been Guarded.
863 sal_Bool bRes
= aMutex
.release( );
865 CPPUNIT_ASSERT_MESSAGE("ResettableMutexGuard constructor, test the aquire operation when initilized.",
873 /// now, the aMutex has been guarded, this time, we use reference constructor.
874 ResettableMutexGuard
myMutexGuard( aMutex
);
876 /// it will return sal_False if the aMutex has not been Guarded.
877 sal_Bool bRes
= aMutex
.release( );
879 CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard constructor, test the aquire operation when initilized, we use reference constructor this time.",
884 CPPUNIT_TEST_SUITE(ctor
);
885 CPPUNIT_TEST(ctor_001
);
886 CPPUNIT_TEST(ctor_002
);
887 CPPUNIT_TEST_SUITE_END();
890 class reset
: public CppUnit::TestFixture
896 ResetGuardThread
myThread( &aMutex
);
897 ResettableMutexGuard
myMutexGuard( aMutex
);
900 /// is it running? and clear done?
901 sal_Bool bRes
= myThread
.isRunning( );
902 myMutexGuard
.clear( );
903 ThreadHelper::thread_sleep_tenth_sec( 1 );
905 /// if reset is not success, the release will return sal_False
906 myMutexGuard
.reset( );
907 sal_Bool bRes1
= aMutex
.release( );
910 CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset",
911 ( sal_True
== bRes
) && ( sal_True
== bRes1
) );
917 ResettableMutexGuard
myMutexGuard( &aMutex
);
919 /// shouldn't release after clear;
920 myMutexGuard
.clear( );
921 sal_Bool bRes
= aMutex
.release( );
923 /// can release after reset.
924 myMutexGuard
.reset( );
925 sal_Bool bRes1
= aMutex
.release( );
927 CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset, release after clear and reset, on Solaris, the mutex can be release without aquire, so it can not passed on (SOLARIS), but not the reason for reset_002",
928 ( sal_False
== bRes
) && ( sal_True
== bRes1
) );
931 CPPUNIT_TEST_SUITE(reset
);
932 CPPUNIT_TEST(reset_001
);
934 CPPUNIT_TEST(reset_002
);
936 CPPUNIT_TEST_SUITE_END();
939 // -----------------------------------------------------------------------------
940 CPPUNIT_TEST_SUITE_REGISTRATION(osl_ResettableGuard::ctor
);
941 CPPUNIT_TEST_SUITE_REGISTRATION(osl_ResettableGuard::reset
);
942 } // namespace osl_ResettableGuard
944 CPPUNIT_PLUGIN_IMPLEMENT();
946 // The following sets variables for GNU EMACS