1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: osl_Mutex.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
37 #include <osl_Mutex_Const.h>
42 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
46 /** print a UNI_CODE String.
48 inline void printUString( const ::rtl::OUString
& str
)
52 t_print("#printUString_u# " );
53 aString
= ::rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
54 t_print("%s\n", aString
.getStr( ) );
57 /** print Boolean value.
59 inline void printBool( sal_Bool bOk
)
61 t_print("#printBool# " );
62 ( sal_True
== bOk
) ? t_print("YES!\n" ): t_print("NO!\n" );
65 /** pause nSec seconds helper function.
67 namespace ThreadHelper
69 void thread_sleep( sal_Int32 _nSec
)
71 /// print statement in thread process must use fflush() to force display.
72 // t_print("# wait %d seconds. ", _nSec );
76 Sleep( _nSec
* 1000 );
78 #if ( defined UNX ) || ( defined OS2 ) //Unix
81 // t_print("# done\n" );
83 void thread_sleep_tenth_sec(sal_Int32 _nTenthSec
)
86 Sleep(_nTenthSec
* 100 );
88 #if ( defined UNX ) || ( defined OS2 ) //Unix
90 nTV
.Seconds
= static_cast<sal_uInt32
>( _nTenthSec
/10 );
91 nTV
.Nanosec
= ( (_nTenthSec
%10 ) * 100000000 );
98 //------------------------------------------------------------------------
99 // Beginning of the test cases for osl_Mutex class
100 //------------------------------------------------------------------------
103 /** mutually exclusive data
111 /** IncreaseThread provide data.
113 class IncreaseThread
: public Thread
116 IncreaseThread( struct resource
*pData
): pResource( pData
) { }
120 CPPUNIT_ASSERT_MESSAGE( "#IncreaseThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
123 struct resource
*pResource
;
127 pResource
->lock
.acquire( );
128 for( sal_Int8 i
= 0; i
< 3; i
++ )
131 yield( ); //yield() give CPU time to other thread, other thread if not block, they will change the data;
133 if ( pResource
->data2
== 0 )
134 pResource
->data2
= ( pResource
->data1
> 0 ? pResource
->data1
: 0 - pResource
->data1
);
135 pResource
->lock
.release();
139 /** DecreaseThread consume data.
141 class DecreaseThread
: public Thread
144 DecreaseThread( struct resource
*pData
): pResource( pData
) { }
148 CPPUNIT_ASSERT_MESSAGE( "#DecreaseThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
151 struct resource
*pResource
;
155 pResource
->lock
.acquire( );
156 for( sal_Int8 i
= 0; i
< 3; i
++ )
159 yield( ); //yield() give CPU time to other thread, other thread if not block, they will change the data;
161 if ( pResource
->data2
== 0 )
162 pResource
->data2
= ( pResource
->data1
> 0 ? pResource
->data1
: 0 - pResource
->data1
);
163 pResource
->lock
.release();
168 /** chain structure used in Threads as critical resource
171 sal_Int32 buffer
[ BUFFER_SIZE
];
176 /** PutThread write to the chain structure in a mutex manner.
178 class PutThread
: public Thread
181 //get the struct pointer to write data to buffer
182 PutThread( struct chain
* pData
): pChain( pData
) { }
186 CPPUNIT_ASSERT_MESSAGE( "#PutThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
189 struct chain
* pChain
;
193 //block here if the mutex has been acquired
194 pChain
->lock
.acquire( );
196 //current position in buffer to write
197 sal_Int8 nPos
= pChain
->pos
;
198 oslThreadIdentifier oId
= getIdentifier( );
201 for ( i
= 0; i
< 5; i
++ )
203 pChain
->buffer
[ nPos
+ i
] = oId
;
206 //revise the position
207 pChain
->pos
= nPos
+ i
;
209 //finish writing, release the mutex
210 pChain
->lock
.release();
214 /** thread for testing Mutex acquire.
216 class HoldThread
: public Thread
219 //get the Mutex pointer to operate
220 HoldThread( Mutex
* pMutex
): pMyMutex( pMutex
) { }
224 CPPUNIT_ASSERT_MESSAGE( "#HoldThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
231 // block here if the mutex has been acquired
232 pMyMutex
->acquire( );
233 t_print("# Mutex acquired. \n" );
234 pMyMutex
->release( );
238 class WaitThread
: public Thread
241 //get the Mutex pointer to operate
242 WaitThread( Mutex
* pMutex
): pMyMutex( pMutex
) { }
246 CPPUNIT_ASSERT_MESSAGE( "#WaitThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
253 // block here if the mutex has been acquired
254 pMyMutex
->acquire( );
255 ThreadHelper::thread_sleep_tenth_sec( 2 );
256 pMyMutex
->release( );
260 /** thread for testing getGlobalMutex.
262 class GlobalMutexThread
: public Thread
265 //get the Mutex pointer to operate
266 GlobalMutexThread( ){ }
268 ~GlobalMutexThread( )
270 CPPUNIT_ASSERT_MESSAGE( "#GlobalMutexThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
275 // block here if the mutex has been acquired
277 pGlobalMutex
= pGlobalMutex
->getGlobalMutex( );
278 pGlobalMutex
->acquire( );
279 t_print("# Global Mutex acquired. \n" );
280 pGlobalMutex
->release( );
285 //--------------------------------------------------------------
289 /** Test of the osl::Mutex::constructor
291 class ctor
: public CppUnit::TestFixture
294 // initialise your test code values here.
296 struct resource m_Res
;
300 for ( sal_Int8 i
=0; i
< BUFFER_SIZE
; i
++ )
301 m_Data
.buffer
[i
] = 0;
312 /** Create two threads to write data to the same buffer, use Mutex to assure
313 during one thread write data five times, the other thread should not begin writing.
314 the two threads wrote two different datas: their thread ID, so we can check the datas
315 in buffer to know the order of the two threads writing
319 PutThread
myThread1( &m_Data
);
320 PutThread
myThread2( &m_Data
);
325 //wait until the two threads terminate
329 sal_Bool bRes
= sal_False
;
331 // every 5 datas should the same
332 // LLA: this is not a good check, it's too fix
333 if (m_Data
.buffer
[0] == m_Data
.buffer
[1] &&
334 m_Data
.buffer
[1] == m_Data
.buffer
[2] &&
335 m_Data
.buffer
[2] == m_Data
.buffer
[3] &&
336 m_Data
.buffer
[3] == m_Data
.buffer
[4] &&
337 m_Data
.buffer
[5] == m_Data
.buffer
[6] &&
338 m_Data
.buffer
[6] == m_Data
.buffer
[7] &&
339 m_Data
.buffer
[7] == m_Data
.buffer
[8] &&
340 m_Data
.buffer
[8] == m_Data
.buffer
[9])
343 /*for (sal_Int8 i=0; i<BUFFER_SIZE; i++)
344 t_print("#data in buffer is %d\n", m_Data.buffer[i]);
347 CPPUNIT_ASSERT_MESSAGE("Mutex ctor", bRes
== sal_True
);
351 /** Create two threads to write data to operate on the same number , use Mutex to assure,
352 one thread increase data 3 times, the other thread decrease 3 times, store the operate
353 result when the first thread complete, if it is interrupt by the other thread, the stored
354 number will not be 3.
358 IncreaseThread
myThread1( &m_Res
);
359 DecreaseThread
myThread2( &m_Res
);
364 //wait until the two threads terminate
368 sal_Bool bRes
= sal_False
;
370 // every 5 datas should the same
371 if ( ( m_Res
.data1
== 0 ) && ( m_Res
.data2
== 3 ) )
374 CPPUNIT_ASSERT_MESSAGE( "test Mutex ctor function: increase and decrease a number 3 times without interrupt.", bRes
== sal_True
);
377 CPPUNIT_TEST_SUITE( ctor
);
378 CPPUNIT_TEST( ctor_001
);
379 CPPUNIT_TEST( ctor_002
);
380 CPPUNIT_TEST_SUITE_END( );
384 /** Test of the osl::Mutex::acquire method
386 class acquire
: public CppUnit::TestFixture
389 // acquire mutex in main thread, and then call acquire again in myThread,
390 // the child thread should block, wait 2 secs, it still block.
391 // Then release mutex in main thread, the child thread could return from acquire,
392 // and go to exec next statement, so could terminate quickly.
397 sal_Bool bRes
= aMutex
.acquire( );
398 // pass the pointer of mutex to child thread
399 HoldThread
myThread( &aMutex
);
402 ThreadHelper::thread_sleep_tenth_sec( 2 );
403 // if acquire in myThread does not work, 2 secs is long enough,
404 // myThread should terminate now, and bRes1 should be sal_False
405 sal_Bool bRes1
= myThread
.isRunning( );
408 ThreadHelper::thread_sleep_tenth_sec( 1 );
409 // after release mutex, myThread stops blocking and will terminate immediately
410 sal_Bool bRes2
= myThread
.isRunning( );
413 CPPUNIT_ASSERT_MESSAGE( "Mutex acquire",
414 bRes
== sal_True
&& bRes1
== sal_True
&& bRes2
== sal_False
);
417 //in the same thread, acquire twice should success
422 sal_Bool bRes
= aMutex
.acquire();
423 sal_Bool bRes1
= aMutex
.acquire();
425 sal_Bool bRes2
= aMutex
.tryToAcquire();
429 CPPUNIT_ASSERT_MESSAGE("Mutex acquire",
430 bRes
== sal_True
&& bRes1
== sal_True
&& bRes2
== sal_True
);
434 CPPUNIT_TEST_SUITE( acquire
);
435 CPPUNIT_TEST( acquire_001
);
436 CPPUNIT_TEST( acquire_002
);
437 CPPUNIT_TEST_SUITE_END( );
441 /** Test of the osl::Mutex::tryToAcquire method
443 class tryToAcquire
: public CppUnit::TestFixture
446 // First let child thread acquire the mutex, and wait 2 secs, during the 2 secs,
447 // in main thread, tryToAcquire mutex should return False
448 // then after the child thread terminated, tryToAcquire should return True
449 void tryToAcquire_001()
452 WaitThread
myThread(&aMutex
);
455 // ensure the child thread acquire the mutex
456 ThreadHelper::thread_sleep_tenth_sec(1);
458 sal_Bool bRes1
= aMutex
.tryToAcquire();
460 if (bRes1
== sal_True
)
462 // wait the child thread terminate
465 sal_Bool bRes2
= aMutex
.tryToAcquire();
467 if (bRes2
== sal_True
)
470 CPPUNIT_ASSERT_MESSAGE("Try to acquire Mutex",
471 bRes1
== sal_False
&& bRes2
== sal_True
);
474 CPPUNIT_TEST_SUITE(tryToAcquire
);
475 CPPUNIT_TEST(tryToAcquire_001
);
476 CPPUNIT_TEST_SUITE_END();
477 }; // class tryToAcquire
479 /** Test of the osl::Mutex::release method
481 class release
: public CppUnit::TestFixture
484 /** acquire/release are not used in pairs: after child thread acquired mutex,
485 the main thread release it, then any thread could acquire it.
490 WaitThread
myThread( &aMutex
);
493 // ensure the child thread acquire the mutex
494 ThreadHelper::thread_sleep_tenth_sec( 1 );
496 sal_Bool bRunning
= myThread
.isRunning( );
497 sal_Bool bRes1
= aMutex
.tryToAcquire( );
498 // wait the child thread terminate
501 sal_Bool bRes2
= aMutex
.tryToAcquire( );
503 if ( bRes2
== sal_True
)
506 CPPUNIT_ASSERT_MESSAGE( "release Mutex: try to aquire before and after the mutex has been released",
507 bRes1
== sal_False
&& bRes2
== sal_True
&& bRunning
== sal_True
);
511 // how about release twice?
514 // LLA: is this a real test?
517 sal_Bool bRes1
= aMutex
.release( );
518 sal_Bool bRes2
= aMutex
.release( );
520 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)",
521 bRes1
== sal_False
&& bRes2
== sal_False
);
525 CPPUNIT_TEST_SUITE( release
);
526 CPPUNIT_TEST( release_001
);
527 CPPUNIT_TEST( release_002
);
528 CPPUNIT_TEST_SUITE_END( );
533 /** Test of the osl::Mutex::getGlobalMutex method
535 class getGlobalMutex
: public CppUnit::TestFixture
538 // initialise your test code values here.
539 void getGlobalMutex_001()
542 pGlobalMutex
= pGlobalMutex
->getGlobalMutex();
543 pGlobalMutex
->acquire();
545 GlobalMutexThread myThread
;
548 ThreadHelper::thread_sleep_tenth_sec(1);
549 sal_Bool bRes1
= myThread
.isRunning();
551 pGlobalMutex
->release();
552 ThreadHelper::thread_sleep_tenth_sec(1);
553 // after release mutex, myThread stops blocking and will terminate immediately
554 sal_Bool bRes2
= myThread
.isRunning();
556 CPPUNIT_ASSERT_MESSAGE("Global Mutex works",
557 bRes1
== sal_True
&& bRes2
== sal_False
);
560 void getGlobalMutex_002( )
565 pGlobalMutex
= pGlobalMutex
->getGlobalMutex( );
566 pGlobalMutex
->acquire( );
568 Mutex
*pGlobalMutex1
;
569 pGlobalMutex1
= pGlobalMutex1
->getGlobalMutex( );
570 bRes
= pGlobalMutex1
->release( );
573 CPPUNIT_ASSERT_MESSAGE( "Global Mutex works: if the code between {} get the different mutex as the former one, it will return false when release.",
577 CPPUNIT_TEST_SUITE(getGlobalMutex
);
578 CPPUNIT_TEST(getGlobalMutex_001
);
579 CPPUNIT_TEST(getGlobalMutex_002
);
580 CPPUNIT_TEST_SUITE_END();
581 }; // class getGlobalMutex
583 // -----------------------------------------------------------------------------
584 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::ctor
, "osl_Mutex");
585 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::acquire
, "osl_Mutex");
586 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::tryToAcquire
, "osl_Mutex");
587 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::release
, "osl_Mutex");
588 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::getGlobalMutex
, "osl_Mutex");
589 } // namespace osl_Mutex
592 //------------------------------------------------------------------------
593 // Beginning of the test cases for osl_Guard class
594 //------------------------------------------------------------------------
596 class GuardThread
: public Thread
599 //get the Mutex pointer to operate
600 GuardThread( Mutex
* pMutex
): pMyMutex( pMutex
) { }
604 CPPUNIT_ASSERT_MESSAGE( "#GuardThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
611 // block here if the mutex has been acquired
612 MutexGuard
aGuard( pMyMutex
);
613 ThreadHelper::thread_sleep_tenth_sec( 2 );
620 class ctor
: public CppUnit::TestFixture
623 // insert your test code here.
627 GuardThread
myThread(&aMutex
);
630 ThreadHelper::thread_sleep_tenth_sec(1);
631 sal_Bool bRes
= aMutex
.tryToAcquire();
632 // after 1 second, the mutex has been guarded, and the child thread should be running
633 sal_Bool bRes1
= myThread
.isRunning();
636 sal_Bool bRes2
= aMutex
.tryToAcquire();
638 CPPUNIT_ASSERT_MESSAGE("GuardThread constructor",
639 bRes
== sal_False
&& bRes1
== sal_True
&& bRes2
== sal_True
);
646 /// use reference constructor here
647 MutexGuard
myGuard( aMutex
);
649 /// the GuardThread will block here when it is initialised.
650 GuardThread
myThread( &aMutex
);
653 /// is it still blocking?
654 ThreadHelper::thread_sleep_tenth_sec( 2 );
655 sal_Bool bRes
= myThread
.isRunning( );
661 CPPUNIT_ASSERT_MESSAGE("GuardThread constructor: reference initialization, aquire the mutex before running the thread, then check if it is blocking.",
665 CPPUNIT_TEST_SUITE(ctor
);
666 CPPUNIT_TEST(ctor_001
);
667 CPPUNIT_TEST(ctor_002
);
668 CPPUNIT_TEST_SUITE_END();
671 // -----------------------------------------------------------------------------
672 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Guard::ctor
, "osl_Guard");
673 } // namespace osl_Guard
676 //------------------------------------------------------------------------
677 // Beginning of the test cases for osl_ClearableGuard class
678 //------------------------------------------------------------------------
680 /** Thread for test ClearableGuard
682 class ClearGuardThread
: public Thread
685 //get the Mutex pointer to operate
686 ClearGuardThread( Mutex
* pMutex
): pMyMutex( pMutex
) {}
690 CPPUNIT_ASSERT_MESSAGE( "#ClearGuardThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
698 // t_print("# ClearGuardThread" );
699 ClearableMutexGuard
aGuard( pMyMutex
);
700 ThreadHelper::thread_sleep( 5 );
704 ThreadHelper::thread_sleep( 2 );
708 // -----------------------------------------------------------------------------
709 namespace osl_ClearableGuard
712 class ctor
: public CppUnit::TestFixture
719 /// now, the aMutex has been guarded.
720 ClearableMutexGuard
myMutexGuard( &aMutex
);
722 /// it will return sal_False if the aMutex has not been Guarded.
723 sal_Bool bRes
= aMutex
.release( );
725 CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the aquire operation when initilized.",
733 /// now, the aMutex has been guarded, this time, we use reference constructor.
734 ClearableMutexGuard
myMutexGuard( aMutex
);
736 /// it will return sal_False if the aMutex has not been Guarded.
737 sal_Bool bRes
= aMutex
.release( );
739 CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the aquire operation when initilized, we use reference constructor this time.",
743 CPPUNIT_TEST_SUITE(ctor
);
744 CPPUNIT_TEST(ctor_001
);
745 CPPUNIT_TEST(ctor_002
);
746 CPPUNIT_TEST_SUITE_END();
749 class clear
: public CppUnit::TestFixture
755 ClearGuardThread
myThread(&aMutex
);
758 TimeValue aTimeVal_befor
;
759 osl_getSystemTime( &aTimeVal_befor
);
760 // wait 1 second to assure the child thread has begun
761 ThreadHelper::thread_sleep(1);
765 if (aMutex
.tryToAcquire() == sal_True
)
769 ThreadHelper::thread_sleep(1);
771 TimeValue aTimeVal_after
;
772 osl_getSystemTime( &aTimeVal_after
);
773 sal_Int32 nSec
= aTimeVal_after
.Seconds
- aTimeVal_befor
.Seconds
;
774 t_print("nSec is %d\n", nSec
);
778 CPPUNIT_ASSERT_MESSAGE("ClearableGuard method: clear",
779 nSec
< 7 && nSec
> 1);
786 /// now, the aMutex has been guarded.
787 ClearableMutexGuard
myMutexGuard( &aMutex
);
789 /// launch the HoldThread, it will be blocked here.
790 HoldThread
myThread( &aMutex
);
794 ThreadHelper::thread_sleep_tenth_sec( 4 );
795 sal_Bool bRes
= myThread
.isRunning( );
797 /// use clear to release.
798 myMutexGuard
.clear( );
800 sal_Bool bRes1
= myThread
.isRunning( );
802 CPPUNIT_ASSERT_MESSAGE( "ClearableGuard method: clear, control the HoldThread's running status!",
803 ( sal_True
== bRes
) && ( sal_False
== bRes1
) );
806 CPPUNIT_TEST_SUITE( clear
);
807 CPPUNIT_TEST( clear_001
);
808 CPPUNIT_TEST( clear_002
);
809 CPPUNIT_TEST_SUITE_END( );
812 // -----------------------------------------------------------------------------
813 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_ClearableGuard::ctor
, "osl_ClearableGuard" );
814 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_ClearableGuard::clear
, "osl_ClearableGuard" );
815 } // namespace osl_ClearableGuard
818 //------------------------------------------------------------------------
819 // Beginning of the test cases for osl_ResettableGuard class
820 //------------------------------------------------------------------------
822 /** Thread for test ResettableGuard
824 class ResetGuardThread
: public Thread
827 //get the Mutex pointer to operate
828 ResetGuardThread( Mutex
* pMutex
): pMyMutex( pMutex
) {}
832 CPPUNIT_ASSERT_MESSAGE( "#ResetGuardThread does not shutdown properly.\n", sal_False
== this -> isRunning( ) );
840 t_print("# ResettableGuard" );
841 ResettableMutexGuard
aGuard( pMyMutex
);
844 ThreadHelper::thread_sleep_tenth_sec( 2 );
848 // -----------------------------------------------------------------------------
849 namespace osl_ResettableGuard
851 class ctor
: public CppUnit::TestFixture
858 /// now, the aMutex has been guarded.
859 ResettableMutexGuard
myMutexGuard( &aMutex
);
861 /// it will return sal_False if the aMutex has not been Guarded.
862 sal_Bool bRes
= aMutex
.release( );
864 CPPUNIT_ASSERT_MESSAGE("ResettableMutexGuard constructor, test the aquire operation when initilized.",
872 /// now, the aMutex has been guarded, this time, we use reference constructor.
873 ResettableMutexGuard
myMutexGuard( aMutex
);
875 /// it will return sal_False if the aMutex has not been Guarded.
876 sal_Bool bRes
= aMutex
.release( );
878 CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard constructor, test the aquire operation when initilized, we use reference constructor this time.",
883 CPPUNIT_TEST_SUITE(ctor
);
884 CPPUNIT_TEST(ctor_001
);
885 CPPUNIT_TEST(ctor_002
);
886 CPPUNIT_TEST_SUITE_END();
889 class reset
: public CppUnit::TestFixture
895 ResetGuardThread
myThread( &aMutex
);
897 ResettableMutexGuard
myMutexGuard( aMutex
);
899 /// is it running? and clear done?
900 myMutexGuard
.clear( );
901 ThreadHelper::thread_sleep_tenth_sec( 1 );
902 sal_Bool bRes
= myThread
.isRunning( );
904 /// if reset is not success, the release will return sal_False
905 myMutexGuard
.reset( );
906 sal_Bool bRes1
= aMutex
.release( );
909 CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset",
910 ( sal_True
== bRes
) && ( sal_True
== bRes1
) );
916 ResettableMutexGuard
myMutexGuard( &aMutex
);
918 /// shouldn't release after clear;
919 myMutexGuard
.clear( );
920 sal_Bool bRes
= aMutex
.release( );
922 /// can release after reset.
923 myMutexGuard
.reset( );
924 sal_Bool bRes1
= aMutex
.release( );
926 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",
927 ( sal_False
== bRes
) && ( sal_True
== bRes1
) );
930 CPPUNIT_TEST_SUITE(reset
);
931 CPPUNIT_TEST(reset_001
);
933 CPPUNIT_TEST(reset_002
);
935 CPPUNIT_TEST_SUITE_END();
938 // -----------------------------------------------------------------------------
939 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ResettableGuard::ctor
, "osl_ResettableGuard");
940 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ResettableGuard::reset
, "osl_ResettableGuard");
941 } // namespace osl_ResettableGuard
943 // this macro creates an empty function, which will called by the RegisterAllFunctions()
944 // to let the user the possibility to also register some functions by hand.
947 // The following sets variables for GNU EMACS