make POSIX and Windows implementation of wxThread::Run() coherently assert when trying to Run() a thread twice; add a test for it.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65106 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2010-07-25 13:55:36 +00:00
parent 79b7701c0b
commit 89a76d5d2c
3 changed files with 21 additions and 7 deletions

View File

@@ -208,6 +208,7 @@ private:
CPPUNIT_TEST( TestDetached );
CPPUNIT_TEST( TestThreadSuspend );
CPPUNIT_TEST( TestThreadDelete );
CPPUNIT_TEST( TestThreadRun );
CPPUNIT_TEST( TestThreadConditions );
CPPUNIT_TEST( TestSemaphore );
CPPUNIT_TEST_SUITE_END();
@@ -218,6 +219,7 @@ private:
void TestThreadSuspend();
void TestThreadDelete();
void TestThreadRun();
void TestThreadConditions();
DECLARE_NO_COPY_CLASS(MiscThreadTestCase)
@@ -320,6 +322,7 @@ void MiscThreadTestCase::TestThreadSuspend()
void MiscThreadTestCase::TestThreadDelete()
{
// FIXME:
// As above, using Sleep() is only for testing here - we must use some
// synchronisation object instead to ensure that the thread is still
// running when we delete it - deleting a detached thread which already
@@ -345,7 +348,7 @@ void MiscThreadTestCase::TestThreadDelete()
MyJoinableThread thread3(20);
CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread3.Run() );
CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread3.Delete() );
// delete a joinable thread
// delete a joinable running thread
MyJoinableThread thread4(2);
CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread4.Run() );
@@ -354,6 +357,16 @@ void MiscThreadTestCase::TestThreadDelete()
// delete a joinable thread which already terminated
}
void MiscThreadTestCase::TestThreadRun()
{
MyJoinableThread thread1(2);
CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread1.Run() );
thread1.Wait(); // wait until the thread ends
// verify that running twice the same thread fails
WX_ASSERT_FAILS_WITH_ASSERT( thread1.Run() );
}
void MiscThreadTestCase::TestThreadConditions()
{
wxMutex mutex;