From 43fbebfbe5d14054c72486aed92f9702367406f8 Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Fri, 4 Sep 2015 16:32:10 +0000 Subject: #i125003# migrate main/sal/qa/osl/process from cppunit to Google Test. --- sal/qa/osl/process/makefile.mk | 53 +- sal/qa/osl/process/osl_Thread.cxx | 2317 ++++++++++++++++-------------------- sal/qa/osl/process/osl_process.cxx | 611 ++++------ 3 files changed, 1328 insertions(+), 1653 deletions(-) (limited to 'sal/qa') diff --git a/sal/qa/osl/process/makefile.mk b/sal/qa/osl/process/makefile.mk index 72e0e00ccdbe..c45f0144879c 100644 --- a/sal/qa/osl/process/makefile.mk +++ b/sal/qa/osl/process/makefile.mk @@ -31,6 +31,13 @@ ENABLE_EXCEPTIONS=TRUE .INCLUDE : settings.mk +.IF "$(ENABLE_UNIT_TESTS)" != "YES" +all: + @echo unit tests are disabled. Nothing to do. + +.ELSE + + CFLAGS+= $(LFS_CFLAGS) CXXFLAGS+= $(LFS_CFLAGS) @@ -41,33 +48,23 @@ CXXFLAGS+= $(LFS_CFLAGS) CFLAGS+=/Ob1 .ENDIF -SHL1OBJS= \ +APP1OBJS= \ $(SLO)$/osl_Thread.obj -SHL1TARGET= osl_Thread -SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL1IMPLIB= i$(SHL1TARGET) - -# SHL1DEF= $(MISC)$/$(SHL1TARGET).def - -DEF1NAME =$(SHL1TARGET) - -# DEF1EXPORTFILE= export.exp -SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +APP1TARGET= osl_Thread +APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP1RPATH = NONE +APP1TEST = enabled # END ------------------------------------------------------------------ #.IF "$(GUI)" == "WNT" -SHL2OBJS=$(SLO)$/osl_process.obj -SHL2TARGET=osl_process -SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL2IMPLIB=i$(SHL2TARGET) -SHL2DEF=$(MISC)$/$(SHL2TARGET).def -DEF2NAME=$(SHL2TARGET) -DEF2EXPORTFILE=export.exp +APP2OBJS=$(SLO)$/osl_process.obj +APP2TARGET=osl_process +APP2STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP2RPATH = NONE +APP2TEST = enabled # END ------------------------------------------------------------------ @@ -85,20 +82,8 @@ APP3STDLIBS=$(SALLIB) #.ENDIF # "$(GUI)" == "WNT" -#------------------------------- All object files ------------------------------- -# do this here, so we get right dependencies - -.IF "$(GUI)" == "OS2" - -SLOFILES=$(SHL2OBJS) - -.ELSE - -SLOFILES=$(SHL1OBJS) $(SHL2OBJS) - -.ENDIF - # --- Targets ------------------------------------------------------ .INCLUDE : target.mk -.INCLUDE : _cppunit.mk + +.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES" diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx index 36bf0cceb2f0..01cbe00ed6a3 100644 --- a/sal/qa/osl/process/osl_Thread.cxx +++ b/sal/qa/osl/process/osl_Thread.cxx @@ -45,7 +45,7 @@ #endif #include -#include +#include "gtest/gtest.h" using namespace osl; using namespace rtl; @@ -92,7 +92,7 @@ void StopWatch::start() m_bIsValid = false; m_bIsRunning = true; osl_getSystemTime( &t1 ); - t_print("# %d %d nsecs\n", t1.Seconds, t1.Nanosec); + printf("# %d %d nsecs\n", t1.Seconds, t1.Nanosec); // gettimeofday(&t1, 0); } @@ -103,7 +103,7 @@ void StopWatch::stop() // gettimeofday(&t2, 0); // Timer ausfragen osl_getSystemTime( &t2 ); - t_print("# %d %d nsecs\n", t2.Seconds, t2.Nanosec); + printf("# %d %d nsecs\n", t2.Seconds, t2.Nanosec); if (m_bIsRunning) { // check ob gestartet. @@ -123,7 +123,7 @@ void StopWatch::stop() m_nNanoSec = 1000000000 + static_cast(t2.Nanosec) - static_cast(t1.Nanosec); m_nSeconds -= 1; } - t_print("# %d %d nsecs\n", m_nSeconds, m_nNanoSec ); + printf("# %d %d nsecs\n", m_nSeconds, m_nNanoSec ); //if (m_nNanoSec < 0) //{ //m_nNanoSec += 1000000000; @@ -193,7 +193,7 @@ namespace ThreadHelper { // if (nVerbose == VERBOSE) // { - // t_print("wait %d tenth seconds. ", _nTenthSec ); + // printf("wait %d tenth seconds. ", _nTenthSec ); // fflush(stdout); // } #ifdef WNT //Windows @@ -207,7 +207,7 @@ namespace ThreadHelper #endif // if (nVerbose == VERBOSE) // { - // t_print("done\n"); + // printf("done\n"); // } } @@ -216,27 +216,27 @@ namespace ThreadHelper // LLA: output the priority if (_aPriority == osl_Thread_PriorityHighest) { - t_print("Prio is High\n"); + printf("Prio is High\n"); } else if (_aPriority == osl_Thread_PriorityAboveNormal) { - t_print("Prio is above normal\n"); + printf("Prio is above normal\n"); } else if (_aPriority == osl_Thread_PriorityNormal) { - t_print("Prio is normal\n"); + printf("Prio is normal\n"); } else if (_aPriority == osl_Thread_PriorityBelowNormal) { - t_print("Prio is below normal\n"); + printf("Prio is below normal\n"); } else if (_aPriority == osl_Thread_PriorityLowest) { - t_print("Prio is lowest\n"); + printf("Prio is lowest\n"); } else { - t_print("Prio is unknown\n"); + printf("Prio is unknown\n"); } } } @@ -277,7 +277,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -293,7 +293,7 @@ public: OCountThread() { m_nWaitSec = 0; - t_print("new OCountThread thread %d!\n", getIdentifier()); + printf("new OCountThread thread %d!\n", getIdentifier()); } sal_Int32 getValue() { return m_aFlag.getValue(); } @@ -339,7 +339,7 @@ protected: } void SAL_CALL onTerminated() { - t_print("normally terminate this thread %d!\n", getIdentifier()); + printf("normally terminate this thread %d!\n", getIdentifier()); } public: @@ -347,7 +347,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -399,7 +399,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -434,18 +434,18 @@ protected: } void SAL_CALL onTerminated() { - t_print("normally terminate this thread %d!\n", getIdentifier()); + printf("normally terminate this thread %d!\n", getIdentifier()); } public: ONoScheduleThread() { - t_print("new thread id %d!\n", getIdentifier()); + printf("new thread id %d!\n", getIdentifier()); } ~ONoScheduleThread() { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -478,7 +478,7 @@ protected: } void SAL_CALL onTerminated() { - // t_print("normally terminate this thread %d!\n", getIdentifier()); + // printf("normally terminate this thread %d!\n", getIdentifier()); } public: @@ -486,7 +486,7 @@ public: { if (isRunning()) { - // t_print("error: not terminated.\n"); + // printf("error: not terminated.\n"); } } @@ -504,7 +504,7 @@ namespace osl_Thread // while on Windows, after createSuspended, the thread can not terminate, wait endlessly, // so here call resume at first, then call terminate. #ifdef WNT - t_print("resumeAndWaitThread\n"); + printf("resumeAndWaitThread\n"); _pThread->resume(); ThreadHelper::thread_sleep_tenth_sec(1); #else @@ -525,145 +525,123 @@ namespace osl_Thread _pThread->resume(); ThreadHelper::thread_sleep_tenth_sec(1); #endif - t_print("#wait for join.\n"); + printf("#wait for join.\n"); _pThread->join(); } /** Test of the osl::Thread::create method */ - class create : public CppUnit::TestFixture + class create : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class create - /** Simple create a thread. - Create a simple thread, it just does add 1 to value(which initialized 0), - if the thread run, the value should be 1. - */ - void create_001() - { - myThread* newthread = new myThread(); - sal_Bool bRes = newthread->create(); - CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!\n", bRes == sal_True ); - - ThreadHelper::thread_sleep_tenth_sec(1); // wait short - sal_Bool isRunning = newthread->isRunning(); // check if thread is running - /// wait for the new thread to assure it has run - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nValue = newthread->getValue(); - /// to assure the new thread has terminated - termAndJoinThread(newthread); - delete newthread; - - t_print(" nValue = %d\n", nValue); - t_print("isRunning = %d\n", isRunning); - - CPPUNIT_ASSERT_MESSAGE( - "Creates a new thread", - nValue >= 1 && isRunning == sal_True - ); + /** Simple create a thread. - } + Create a simple thread, it just does add 1 to value(which initialized 0), + if the thread run, the value should be 1. + */ + TEST_F(create, create_001) + { + myThread* newthread = new myThread(); + sal_Bool bRes = newthread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can not creates a new thread!\n"; - /** only one running thread per instance, return false if create secondly - */ - void create_002() - { - myThread* newthread = new myThread(); - sal_Bool res1 = newthread->create(); - sal_Bool res2 = newthread->create(); - t_print("In non pro, an assertion should occurred. This behaviour is right.\n"); - termAndJoinThread(newthread); - delete newthread; - - CPPUNIT_ASSERT_MESSAGE( - "Creates a new thread: can not create two threads per instance", - res1 && !res2 - ); + ThreadHelper::thread_sleep_tenth_sec(1); // wait short + sal_Bool isRunning = newthread->isRunning(); // check if thread is running + /// wait for the new thread to assure it has run + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nValue = newthread->getValue(); + /// to assure the new thread has terminated + termAndJoinThread(newthread); + delete newthread; - } + printf(" nValue = %d\n", nValue); + printf("isRunning = %d\n", isRunning); - CPPUNIT_TEST_SUITE(create); - CPPUNIT_TEST(create_001); - CPPUNIT_TEST(create_002); - CPPUNIT_TEST_SUITE_END(); - }; // class create + ASSERT_TRUE(nValue >= 1 && isRunning == sal_True) << "Creates a new thread"; + } + + /** only one running thread per instance, return false if create secondly + */ + TEST_F(create, create_002) + { + myThread* newthread = new myThread(); + sal_Bool res1 = newthread->create(); + sal_Bool res2 = newthread->create(); + printf("In non pro, an assertion should occured. This behaviour is right.\n"); + termAndJoinThread(newthread); + delete newthread; + + ASSERT_TRUE(res1 && !res2) << "Creates a new thread: can not create two threads per instance"; + + } /** Test of the osl::Thread::createSuspended method */ - class createSuspended : public CppUnit::TestFixture + class createSuspended : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class createSuspended - /** Create a suspended thread, use the same class as create_001 + /** Create a suspended thread, use the same class as create_001 - after create, wait enough time, check the value, if it's still the initial value, pass - */ - void createSuspended_001() - { - myThread* newthread = new myThread(); - sal_Bool bRes = newthread->createSuspended(); - CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!", bRes == sal_True ); - - ThreadHelper::thread_sleep_tenth_sec(1); - sal_Bool isRunning = newthread->isRunning(); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nValue = newthread->getValue(); + after create, wait enough time, check the value, if it's still the initial value, pass + */ + TEST_F(createSuspended, createSuspended_001) + { + myThread* newthread = new myThread(); + sal_Bool bRes = newthread->createSuspended(); + ASSERT_TRUE(bRes == sal_True) << "Can not creates a new thread!"; - resumeAndWaitThread(newthread); + ThreadHelper::thread_sleep_tenth_sec(1); + sal_Bool isRunning = newthread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nValue = newthread->getValue(); - termAndJoinThread(newthread); - delete newthread; + resumeAndWaitThread(newthread); - CPPUNIT_ASSERT_MESSAGE( - "Creates a new suspended thread", - nValue == 0 && isRunning - ); - } + termAndJoinThread(newthread); + delete newthread; - void createSuspended_002() - { - myThread* newthread = new myThread(); - sal_Bool res1 = newthread->createSuspended(); - sal_Bool res2 = newthread->createSuspended(); + ASSERT_TRUE(nValue == 0 && isRunning) << "Creates a new suspended thread"; + } + // LLA: Deadlocked!!! + TEST_F(createSuspended, createSuspended_002) + { + myThread* newthread = new myThread(); + sal_Bool res1 = newthread->createSuspended(); + sal_Bool res2 = newthread->createSuspended(); - resumeAndWaitThread(newthread); + resumeAndWaitThread(newthread); - termAndJoinThread(newthread); + termAndJoinThread(newthread); - delete newthread; + delete newthread; - CPPUNIT_ASSERT_MESSAGE( - "Creates a new thread: can not create two threads per instance", - res1 && !res2 - ); - } + ASSERT_TRUE(res1 && !res2) << "Creates a new thread: can not create two threads per instance"; + } - CPPUNIT_TEST_SUITE(createSuspended); - CPPUNIT_TEST(createSuspended_001); - // LLA: Deadlocked!!! - CPPUNIT_TEST(createSuspended_002); - CPPUNIT_TEST_SUITE_END(); - }; // class createSuspended /** when the count value equal to or more than 3, suspend the thread. */ @@ -683,436 +661,384 @@ namespace osl_Thread /** Test of the osl::Thread::suspend method */ - class suspend : public CppUnit::TestFixture + class suspend : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class suspend - /** Use a thread which has a flag added 1 every second + /** Use a thread which has a flag added 1 every second - ALGORITHM: - create the thread, after running special time, record value of flag, then suspend it, - wait a long time, check the flag, if it remains unchanged during suspending - */ - void suspend_001() - { - OCountThread* aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - // the thread run for some seconds, but not terminate - suspendCountThread( aCountThread ); + ALGORITHM: + create the thread, after running special time, record value of flag, then suspend it, + wait a long time, check the flag, if it remains unchanged during suspending + */ + TEST_F(suspend, suspend_001) + { + OCountThread* aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + // the thread run for some seconds, but not terminate + suspendCountThread( aCountThread ); - // the value just after calling suspend - sal_Int32 nValue = aCountThread->getValue(); // (2) + // the value just after calling suspend + sal_Int32 nValue = aCountThread->getValue(); // (2) - ThreadHelper::thread_sleep_tenth_sec(3); + ThreadHelper::thread_sleep_tenth_sec(3); - // the value after waiting 3 seconds - sal_Int32 nLaterValue = aCountThread->getValue(); // (3) + // the value after waiting 3 seconds + sal_Int32 nLaterValue = aCountThread->getValue(); // (3) - resumeAndWaitThread(aCountThread); - termAndJoinThread(aCountThread); - delete aCountThread; + resumeAndWaitThread(aCountThread); + termAndJoinThread(aCountThread); + delete aCountThread; - CPPUNIT_ASSERT_MESSAGE( - "Suspend the thread", - bRes == sal_True && nValue == nLaterValue - ); + ASSERT_TRUE(bRes == sal_True && nValue == nLaterValue) << "Suspend the thread"; - } - /** suspend a thread in it's worker-function, the ALGORITHM is same as suspend_001 - reason of deadlocked I think: no schedule can schedule other threads to go on excuting - */ - void suspend_002() + } + /** suspend a thread in it's worker-function, the ALGORITHM is same as suspend_001 + reason of deadlocked I think: no schedule can schedule other threads to go on excuting + */ + TEST_F(suspend, suspend_002) + { +#if 0 + OSuspendThread* aThread = new OSuspendThread(); + sal_Bool bRes = aThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + // first the thread run for some seconds, but not terminate + sal_Int32 nValue = 0; + //while (1) + //{ + ThreadHelper::thread_sleep_tenth_sec(3); + nValue = aThread->getValue(); // (1) + printf(" getValue is %d !", nValue ); + if (nValue >= 2) { - OSuspendThread* aThread = new OSuspendThread(); - sal_Bool bRes = aThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - // first the thread run for some seconds, but not terminate - sal_Int32 nValue = 0; - //while (1) - //{ - ThreadHelper::thread_sleep_tenth_sec(3); - nValue = aThread->getValue(); // (1) - t_print(" getValue is %d !", nValue ); - if (nValue >= 2) - { - aThread->setSuspend(); - //break; - } - //} - t_print(" after while!"); - // the value just after calling suspend - nValue = aThread->getValue(); // (2) - - ThreadHelper::thread_sleep_tenth_sec(3); - t_print(" after sleep!"); - // the value after waiting 3 seconds - sal_Int32 nLaterValue = aThread->getValue(); // (3) - - //resumeAndWaitThread(aThread); - aThread->resume(); - termAndJoinThread(aThread); - delete aThread; - - CPPUNIT_ASSERT_MESSAGE( - "Suspend the thread", - bRes == sal_True && nValue == nLaterValue - ); + aThread->setSuspend(); + //break; } + //} + printf(" after while!"); + // the value just after calling suspend + nValue = aThread->getValue(); // (2) + + ThreadHelper::thread_sleep_tenth_sec(3); + printf(" after sleep!"); + // the value after waiting 3 seconds + sal_Int32 nLaterValue = aThread->getValue(); // (3) + + //resumeAndWaitThread(aThread); + aThread->resume(); + termAndJoinThread(aThread); + delete aThread; + + ASSERT_TRUE(bRes == sal_True && nValue == nLaterValue) << "Suspend the thread"; +#endif + } - CPPUNIT_TEST_SUITE(suspend); - CPPUNIT_TEST(suspend_001); - // LLA: Deadlocked!!! - // CPPUNIT_TEST(createSuspended_002); - CPPUNIT_TEST_SUITE_END(); - }; // class suspend /** Test of the osl::Thread::resume method */ - class resume : public CppUnit::TestFixture + class resume : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class resume - /** check if the thread run samely as usual after suspend and resume - - ALGORITHM: - compare the values before and after suspend, they should be same, - then compare values before and after resume, the difference should be same as the sleep seconds number - */ - void resume_001() - { - OCountThread* pCountThread = new OCountThread(); - sal_Bool bRes = pCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + /** check if the thread run samely as usual after suspend and resume - suspendCountThread(pCountThread); + ALGORITHM: + compare the values before and after suspend, they should be same, + then compare values before and after resume, the difference should be same as the sleep seconds number + */ + TEST_F(resume, resume_001) + { + OCountThread* pCountThread = new OCountThread(); + sal_Bool bRes = pCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - sal_Int32 nSuspendValue = pCountThread->getValue(); // (2) - // suspend for 3 seconds - ThreadHelper::thread_sleep_tenth_sec(3); - pCountThread->resume(); + suspendCountThread(pCountThread); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nResumeValue = pCountThread->getValue(); + sal_Int32 nSuspendValue = pCountThread->getValue(); // (2) + // suspend for 3 seconds + ThreadHelper::thread_sleep_tenth_sec(3); + pCountThread->resume(); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nLaterValue = pCountThread->getValue(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nResumeValue = pCountThread->getValue(); - termAndJoinThread(pCountThread); - delete pCountThread; + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nLaterValue = pCountThread->getValue(); - t_print("SuspendValue: %d\n", nSuspendValue); - t_print("ResumeValue: %d\n", nResumeValue); - t_print("LaterValue: %d\n", nLaterValue); + termAndJoinThread(pCountThread); + delete pCountThread; - /* LLA: this assumption is no longer relevant: nResumeValue == nSuspendValue && */ - CPPUNIT_ASSERT_MESSAGE( - "Suspend then resume the thread", - nLaterValue >= 9 && - nResumeValue > nSuspendValue && - nLaterValue > nResumeValue - ); + printf("SuspendValue: %d\n", nSuspendValue); + printf("ResumeValue: %d\n", nResumeValue); + printf("LaterValue: %d\n", nLaterValue); - } + /* LLA: this assumption is no longer relevant: nResumeValue == nSuspendValue && */ + ASSERT_TRUE(nLaterValue >= 9 && + nResumeValue > nSuspendValue && + nLaterValue > nResumeValue) << "Suspend then resume the thread"; - /** Create a suspended thread then resume, check if the thread has run - */ - void resume_002() - { - myThread* newthread = new myThread(); - sal_Bool bRes = newthread->createSuspended(); - CPPUNIT_ASSERT_MESSAGE ( "Can't create thread!", bRes == sal_True ); + } - newthread->resume(); - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Int32 nValue = newthread->getValue(); + /** Create a suspended thread then resume, check if the thread has run + */ + TEST_F(resume, resume_002) + { + myThread* newthread = new myThread(); + sal_Bool bRes = newthread->createSuspended(); + ASSERT_TRUE(bRes == sal_True) << "Can't create thread!"; - termAndJoinThread(newthread); - delete newthread; + newthread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nValue = newthread->getValue(); - t_print(" nValue = %d\n", nValue); + termAndJoinThread(newthread); + delete newthread; - CPPUNIT_ASSERT_MESSAGE( - "Creates a suspended thread, then resume", - nValue >= 1 - ); - } + printf(" nValue = %d\n", nValue); - CPPUNIT_TEST_SUITE(resume); - CPPUNIT_TEST(resume_001); - CPPUNIT_TEST(resume_002); - CPPUNIT_TEST_SUITE_END(); - }; // class resume + ASSERT_TRUE(nValue >= 1) << "Creates a suspended thread, then resume"; + } /** Test of the osl::Thread::terminate method */ - class terminate : public CppUnit::TestFixture + class terminate : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class terminate - /** Check after call terminate if the running thread running go on executing + /** Check after call terminate if the running thread running go on executing - ALGORITHM: - before and after call terminate, the values should be the same - */ - void terminate_001() - { - OCountThread* aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Int32 nValue = aCountThread->getValue(); - aCountThread->terminate(); - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Int32 nLaterValue = aCountThread->getValue(); - - // isRunning should be false after terminate - sal_Bool isRunning = aCountThread->isRunning(); - aCountThread->join(); - delete aCountThread; - - t_print(" nValue = %d\n", nValue); - t_print("nLaterValue = %d\n", nLaterValue); - - CPPUNIT_ASSERT_MESSAGE( - "Terminate the thread", - isRunning == sal_False && nLaterValue >= nValue - ); - } - /** Check if a suspended thread will terminate after call terminate, different on w32 and on UNX - */ - void terminate_002() - { - OCountThread* aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + ALGORITHM: + before and after call terminate, the values should be the same + */ + TEST_F(terminate, terminate_001) + { + OCountThread* aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - ThreadHelper::thread_sleep_tenth_sec(1); - suspendCountThread(aCountThread); - sal_Int32 nValue = aCountThread->getValue(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nValue = aCountThread->getValue(); + aCountThread->terminate(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nLaterValue = aCountThread->getValue(); + + // isRunning should be false after terminate + sal_Bool isRunning = aCountThread->isRunning(); + aCountThread->join(); + delete aCountThread; - // seems a suspended thread can not be terminated on W32, while on Solaris can - resumeAndWaitThread(aCountThread); + printf(" nValue = %d\n", nValue); + printf("nLaterValue = %d\n", nLaterValue); - ThreadHelper::thread_sleep_tenth_sec(2); + ASSERT_TRUE(isRunning == sal_False && nLaterValue >= nValue) << "Terminate the thread"; + } + /** Check if a suspended thread will terminate after call terminate, different on w32 and on UNX + */ + TEST_F(terminate, terminate_002) + { + OCountThread* aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - termAndJoinThread(aCountThread); - sal_Int32 nLaterValue = aCountThread->getValue(); - delete aCountThread; + ThreadHelper::thread_sleep_tenth_sec(1); + suspendCountThread(aCountThread); + sal_Int32 nValue = aCountThread->getValue(); - t_print(" nValue = %d\n", nValue); - t_print("nLaterValue = %d\n", nLaterValue); + // seems a suspended thread can not be terminated on W32, while on Solaris can + resumeAndWaitThread(aCountThread); - CPPUNIT_ASSERT_MESSAGE( - "Suspend then resume the thread", - nLaterValue > nValue ); - } + ThreadHelper::thread_sleep_tenth_sec(2); + + termAndJoinThread(aCountThread); + sal_Int32 nLaterValue = aCountThread->getValue(); + delete aCountThread; + + printf(" nValue = %d\n", nValue); + printf("nLaterValue = %d\n", nLaterValue); + + ASSERT_TRUE(nLaterValue > nValue) << "Suspend then resume the thread"; + } - CPPUNIT_TEST_SUITE(terminate); - CPPUNIT_TEST(terminate_001); - CPPUNIT_TEST(terminate_002); - CPPUNIT_TEST_SUITE_END(); - }; // class terminate /** Test of the osl::Thread::join method */ - class join : public CppUnit::TestFixture + class join : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class join - /** Check after call terminate if the thread running function will not go on executing + /** Check after call terminate if the thread running function will not go on executing - the next statement after join will not exec before the thread terminate - ALGORITHM: - recode system time at the beginning of the thread run, call join, then record system time again, - the difference of the two time should be equal or more than 20 seconds, the CountThead normally terminate - */ - void join_001() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - StopWatch aStopWatch; - aStopWatch.start(); - // TimeValue aTimeVal_befor; - // osl_getSystemTime( &aTimeVal_befor ); - //t_print("#join:the system time is %d,%d\n", pTimeVal_befor->Seconds,pTimeVal_befor->Nanosec); - - aCountThread->join(); - - //the below line will be executed after aCountThread terminate - // TimeValue aTimeVal_after; - // osl_getSystemTime( &aTimeVal_after ); - aStopWatch.stop(); - // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; - double nSec = aStopWatch.getSeconds(); - t_print("join_001 nSec=%f\n", nSec); - delete aCountThread; - - CPPUNIT_ASSERT_MESSAGE( - "Join the thread: after the thread terminate", - nSec >= 2 - ); + the next statement after join will not exec before the thread terminate + ALGORITHM: + recode system time at the beginning of the thread run, call join, then record system time again, + the difference of the two time should be equal or more than 20 seconds, the CountThead normally terminate + */ + TEST_F(join, join_001) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - } - /** after terminated by another thread, join exited immediately + StopWatch aStopWatch; + aStopWatch.start(); + // TimeValue aTimeVal_befor; + // osl_getSystemTime( &aTimeVal_befor ); + //printf("#join:the system time is %d,%d\n", pTimeVal_befor->Seconds,pTimeVal_befor->Nanosec); - ALGORITHM: - terminate the thread when value>=3, call join, check the beginning time and time after join, - the difference should be 3 seconds, join costs little time - */ - void join_002() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - //record the time when the running begin - // TimeValue aTimeVal_befor; - // osl_getSystemTime( &aTimeVal_befor ); - StopWatch aStopWatch; - aStopWatch.start(); - - ThreadHelper::thread_sleep_tenth_sec(10); - termAndJoinThread(aCountThread); - - //the below line will be executed after aCountThread terminate - // TimeValue aTimeVal_after; - // osl_getSystemTime( &aTimeVal_after ); - // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; - aStopWatch.stop(); - double nSec = aStopWatch.getSeconds(); - t_print("join_002 nSec=%f\n", nSec); - - delete aCountThread; - CPPUNIT_ASSERT_MESSAGE( - "Join the thread: after thread terminate by another thread", - nSec >= 1 - ); - } + aCountThread->join(); - CPPUNIT_TEST_SUITE(join); - CPPUNIT_TEST(join_001); - CPPUNIT_TEST(join_002); - CPPUNIT_TEST_SUITE_END(); - }; // class join + //the below line will be executed after aCountThread terminate + // TimeValue aTimeVal_after; + // osl_getSystemTime( &aTimeVal_after ); + aStopWatch.stop(); + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + double nSec = aStopWatch.getSeconds(); + printf("join_001 nSec=%f\n", nSec); + delete aCountThread; + + ASSERT_TRUE(nSec >= 2) << "Join the thread: after the thread terminate"; + + } + /** after terminated by another thread, join exited immediately + + ALGORITHM: + terminate the thread when value>=3, call join, check the beginning time and time after join, + the difference should be 3 seconds, join costs little time + */ + TEST_F(join, join_002) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + + //record the time when the running begin + // TimeValue aTimeVal_befor; + // osl_getSystemTime( &aTimeVal_befor ); + StopWatch aStopWatch; + aStopWatch.start(); + + ThreadHelper::thread_sleep_tenth_sec(10); + termAndJoinThread(aCountThread); + + //the below line will be executed after aCountThread terminate + // TimeValue aTimeVal_after; + // osl_getSystemTime( &aTimeVal_after ); + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + aStopWatch.stop(); + double nSec = aStopWatch.getSeconds(); + printf("join_002 nSec=%f\n", nSec); + + delete aCountThread; + ASSERT_TRUE(nSec >= 1) << "Join the thread: after thread terminate by another thread"; + } /** Test of the osl::Thread::isRunning method */ - class isRunning : public CppUnit::TestFixture + class isRunning : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class isRunning - /** - */ - void isRunning_001() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - sal_Bool bRun = aCountThread->isRunning(); - - ThreadHelper::thread_sleep_tenth_sec(2); - termAndJoinThread(aCountThread); - sal_Bool bTer = aCountThread->isRunning(); - delete aCountThread; + /** + */ + TEST_F(isRunning, isRunning_001) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - CPPUNIT_ASSERT_MESSAGE( - "Test isRunning", - bRun == sal_True && bTer == sal_False - ); - } - /** check the value of isRunning when suspending and after resume - */ - void isRunning_002() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - // sal_Bool bRunning = aCountThread->isRunning(); - // sal_Int32 nValue = 0; - suspendCountThread(aCountThread); - - sal_Bool bRunning_sup = aCountThread->isRunning(); - ThreadHelper::thread_sleep_tenth_sec(2); - aCountThread->resume(); - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Bool bRunning_res = aCountThread->isRunning(); - termAndJoinThread(aCountThread); - sal_Bool bRunning_ter = aCountThread->isRunning(); - delete aCountThread; - - CPPUNIT_ASSERT_MESSAGE( - "Test isRunning", - bRes == sal_True && - bRunning_sup == sal_True && - bRunning_res == sal_True && - bRunning_ter == sal_False - ); + sal_Bool bRun = aCountThread->isRunning(); - } + ThreadHelper::thread_sleep_tenth_sec(2); + termAndJoinThread(aCountThread); + sal_Bool bTer = aCountThread->isRunning(); + delete aCountThread; - CPPUNIT_TEST_SUITE(isRunning); - CPPUNIT_TEST(isRunning_001); - CPPUNIT_TEST(isRunning_002); - CPPUNIT_TEST_SUITE_END(); - }; // class isRunning + ASSERT_TRUE(bRun == sal_True && bTer == sal_False) << "Test isRunning"; + } + /** check the value of isRunning when suspending and after resume + */ + TEST_F(isRunning, isRunning_002) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + + // sal_Bool bRunning = aCountThread->isRunning(); + // sal_Int32 nValue = 0; + suspendCountThread(aCountThread); + + sal_Bool bRunning_sup = aCountThread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(2); + aCountThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Bool bRunning_res = aCountThread->isRunning(); + termAndJoinThread(aCountThread); + sal_Bool bRunning_ter = aCountThread->isRunning(); + delete aCountThread; + + ASSERT_TRUE(bRes == sal_True && + bRunning_sup == sal_True && + bRunning_res == sal_True && + bRunning_ter == sal_False) << "Test isRunning"; + } /// check osl::Thread::setPriority - class setPriority : public CppUnit::TestFixture + class setPriority : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } @@ -1179,10 +1105,10 @@ namespace osl_Thread nValueNormal2 = p2Thread->getValue(); rtl::OString sPrio = getPrioName(_aPriority); - t_print("After 10 tenth seconds\n"); + printf("After 10 tenth seconds\n"); - t_print("nValue in %s Prio Thread is %d\n",sPrio.getStr(), nValueNormal); - t_print("nValue in %s Prio Thread is %d\n", sPrio.getStr(), nValueNormal2); + printf("nValue in %s Prio Thread is %d\n",sPrio.getStr(), nValueNormal); + printf("nValue in %s Prio Thread is %d\n", sPrio.getStr(), nValueNormal2); // ThreadHelper::thread_sleep_tenth_sec(1); pThread->join(); @@ -1193,618 +1119,556 @@ namespace osl_Thread sal_Int32 nDelta = abs(nValueNormal - nValueNormal2); double nQuotient = std::max(nValueNormal, nValueNormal2); - CPPUNIT_ASSERT_MESSAGE( - "Quotient is zero, which means, there exist no right values.", - nQuotient != 0 - ); + ASSERT_TRUE(nQuotient != 0) << "Quotient is zero, which means, there exist no right values."; double nDeltaPercent = nDelta / nQuotient * 100; - t_print("Delta value %d, percent %f\n",nDelta, nDeltaPercent); + printf("Delta value %d, percent %f\n",nDelta, nDeltaPercent); // LLA: it's not a bug if the current OS is not able to handle thread scheduling right and good. // like Windows XP - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "Run 2 normal threads, the count diff more than 5 percent.", - // LLA: nDeltaPercent <= 5 - // LLA: ); - } - - void setPriority_001_1() - { - check2Threads(osl_Thread_PriorityHighest); - } - void setPriority_001_2() - { - check2Threads(osl_Thread_PriorityAboveNormal); + // LLA: ASSERT_TRUE(// LLA: nDeltaPercent <= 5 + // LLA:) << // LLA: "Run 2 normal threads, the count diff more than 5 percent."; } - void setPriority_001_3() - { - check2Threads(osl_Thread_PriorityNormal); - } - void setPriority_001_4() - { - check2Threads(osl_Thread_PriorityBelowNormal); - } - void setPriority_001_5() - { - check2Threads(osl_Thread_PriorityLowest); - } - - void setPriority_002() - { - // initial 5 threads with different priorities - - OAddThread aHighestThread; - OAddThread aAboveNormalThread; - OAddThread aNormalThread; - //OAddThread *aBelowNormalThread = new OAddThread(); - //OAddThread *aLowestThread = new OAddThread(); - - //Create them and start running at the same time - aHighestThread.createSuspended(); - aHighestThread.setPriority(osl_Thread_PriorityHighest); - - aAboveNormalThread.createSuspended(); - aAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal); - - aNormalThread.createSuspended(); - aNormalThread.setPriority(osl_Thread_PriorityNormal); - /*aBelowNormalThread->create(); - aBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - aLowestThread->create(); - aLowestThread->setPriority(osl_Thread_PriorityLowest); - */ - - aHighestThread.resume(); - aAboveNormalThread.resume(); - aNormalThread.resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - aHighestThread.suspend(); - aAboveNormalThread.suspend(); - aNormalThread.suspend(); - - termAndJoinThread(&aNormalThread); - termAndJoinThread(&aAboveNormalThread); - termAndJoinThread(&aHighestThread); - //aBelowNormalThread->terminate(); - //aLowestThread->terminate(); - - sal_Int32 nValueHighest = 0; - nValueHighest = aHighestThread.getValue(); + }; // class setPriority - sal_Int32 nValueAboveNormal = 0; - nValueAboveNormal = aAboveNormalThread.getValue(); + TEST_F(setPriority, setPriority_001_1) + { + check2Threads(osl_Thread_PriorityHighest); + } + TEST_F(setPriority, setPriority_001_2) + { + check2Threads(osl_Thread_PriorityAboveNormal); + } + TEST_F(setPriority, setPriority_001_3) + { + check2Threads(osl_Thread_PriorityNormal); + } + TEST_F(setPriority, setPriority_001_4) + { + check2Threads(osl_Thread_PriorityBelowNormal); + } + TEST_F(setPriority, setPriority_001_5) + { + check2Threads(osl_Thread_PriorityLowest); + } - sal_Int32 nValueNormal = 0; - nValueNormal = aNormalThread.getValue(); - - // sal_Int32 nValueBelowNormal = 0; - //nValueBelowNormal = aBelowNormalThread->getValue(); - // sal_Int32 nValueLowest = 0; - //nValueLowest = aLowestThread->getValue(); - t_print("After 10 tenth seconds\n"); - t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - - // LLA: this is not a save test, so we only check if all values not zero - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "SetPriority", - // LLA: nValueHighest >= nValueAboveNormal && - // LLA: nValueAboveNormal >= nValueNormal && - // LLA: nValueNormal > 0 - // LLA: ); +#ifndef SOLARIS + TEST_F(setPriority, setPriority_002) + { + // initial 5 threads with different priorities + + OAddThread aHighestThread; + OAddThread aAboveNormalThread; + OAddThread aNormalThread; + //OAddThread *aBelowNormalThread = new OAddThread(); + //OAddThread *aLowestThread = new OAddThread(); + + //Create them and start running at the same time + aHighestThread.createSuspended(); + aHighestThread.setPriority(osl_Thread_PriorityHighest); + + aAboveNormalThread.createSuspended(); + aAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal); + + aNormalThread.createSuspended(); + aNormalThread.setPriority(osl_Thread_PriorityNormal); + /*aBelowNormalThread->create(); + aBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + aLowestThread->create(); + aLowestThread->setPriority(osl_Thread_PriorityLowest); + */ + + aHighestThread.resume(); + aAboveNormalThread.resume(); + aNormalThread.resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + aHighestThread.suspend(); + aAboveNormalThread.suspend(); + aNormalThread.suspend(); + + termAndJoinThread(&aNormalThread); + termAndJoinThread(&aAboveNormalThread); + termAndJoinThread(&aHighestThread); + //aBelowNormalThread->terminate(); + //aLowestThread->terminate(); + + sal_Int32 nValueHighest = 0; + nValueHighest = aHighestThread.getValue(); + + sal_Int32 nValueAboveNormal = 0; + nValueAboveNormal = aAboveNormalThread.getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = aNormalThread.getValue(); + + // sal_Int32 nValueBelowNormal = 0; + //nValueBelowNormal = aBelowNormalThread->getValue(); + // sal_Int32 nValueLowest = 0; + //nValueLowest = aLowestThread->getValue(); + printf("After 10 tenth seconds\n"); + printf("nValue in Highest Prio Thread is %d\n",nValueHighest); + printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + printf("nValue in Normal Prio Thread is %d\n",nValueNormal); + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: ASSERT_TRUE(// LLA: nValueHighest >= nValueAboveNormal && + // LLA: nValueAboveNormal >= nValueNormal && + // LLA: nValueNormal > 0 + // LLA:) << // LLA: "SetPriority"; // LLA: windows let starve threads with lower priority #ifndef WNT - CPPUNIT_ASSERT_MESSAGE( - "SetPriority", - nValueHighest > 0 && - nValueAboveNormal > 0 && - nValueNormal > 0 - ); + ASSERT_TRUE(nValueHighest > 0 && + nValueAboveNormal > 0 && + nValueNormal > 0) << "SetPriority"; #endif - } - - void setPriority_003() - { - // initial 5 threads with different priorities - OAddThread *pHighestThread = new OAddThread(); - OAddThread *pAboveNormalThread = new OAddThread(); - OAddThread *pNormalThread = new OAddThread(); - OAddThread *pBelowNormalThread = new OAddThread(); - OAddThread *pLowestThread = new OAddThread(); - - //Create them and start running at the same time - pHighestThread->createSuspended(); - pHighestThread->setPriority(osl_Thread_PriorityHighest); - - pAboveNormalThread->createSuspended(); - pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); - - pNormalThread->createSuspended(); - pNormalThread->setPriority(osl_Thread_PriorityNormal); - - pBelowNormalThread->createSuspended(); - pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - - pLowestThread->createSuspended(); - pLowestThread->setPriority(osl_Thread_PriorityLowest); - - pHighestThread->resume(); - pAboveNormalThread->resume(); - pNormalThread->resume(); - pBelowNormalThread->resume(); - pLowestThread->resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - pHighestThread->suspend(); - pAboveNormalThread->suspend(); - pNormalThread->suspend(); - pBelowNormalThread->suspend(); - pLowestThread->suspend(); - - termAndJoinThread(pHighestThread); - termAndJoinThread(pAboveNormalThread); - termAndJoinThread(pNormalThread); - termAndJoinThread(pBelowNormalThread); - termAndJoinThread(pLowestThread); - - sal_Int32 nValueHighest = 0; - nValueHighest = pHighestThread->getValue(); - - sal_Int32 nValueAboveNormal = 0; - nValueAboveNormal = pAboveNormalThread->getValue(); + } - sal_Int32 nValueNormal = 0; - nValueNormal = pNormalThread->getValue(); - - sal_Int32 nValueBelowNormal = 0; - nValueBelowNormal = pBelowNormalThread->getValue(); - - sal_Int32 nValueLowest = 0; - nValueLowest = pLowestThread->getValue(); - - t_print("After 10 tenth seconds\n"); - t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); - t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); - - delete pHighestThread; - delete pAboveNormalThread; - delete pNormalThread; - delete pBelowNormalThread; - delete pLowestThread; - - // LLA: this is not a save test, so we only check if all values not zero - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "SetPriority", - // LLA: nValueHighest > nValueAboveNormal && - // LLA: nValueAboveNormal > nValueNormal && - // LLA: nValueNormal > nValueBelowNormal && - // LLA: nValueBelowNormal > nValueLowest && - // LLA: nValueLowest > 0 - // LLA: ); + TEST_F(setPriority, setPriority_003) + { + // initial 5 threads with different priorities + OAddThread *pHighestThread = new OAddThread(); + OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //Create them and start running at the same time + pHighestThread->createSuspended(); + pHighestThread->setPriority(osl_Thread_PriorityHighest); + + pAboveNormalThread->createSuspended(); + pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread->createSuspended(); + pNormalThread->setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread->createSuspended(); + pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread->createSuspended(); + pLowestThread->setPriority(osl_Thread_PriorityLowest); + + pHighestThread->resume(); + pAboveNormalThread->resume(); + pNormalThread->resume(); + pBelowNormalThread->resume(); + pLowestThread->resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + pHighestThread->suspend(); + pAboveNormalThread->suspend(); + pNormalThread->suspend(); + pBelowNormalThread->suspend(); + pLowestThread->suspend(); + + termAndJoinThread(pHighestThread); + termAndJoinThread(pAboveNormalThread); + termAndJoinThread(pNormalThread); + termAndJoinThread(pBelowNormalThread); + termAndJoinThread(pLowestThread); + + sal_Int32 nValueHighest = 0; + nValueHighest = pHighestThread->getValue(); + + sal_Int32 nValueAboveNormal = 0; + nValueAboveNormal = pAboveNormalThread->getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + printf("After 10 tenth seconds\n"); + printf("nValue in Highest Prio Thread is %d\n",nValueHighest); + printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + printf("nValue in Normal Prio Thread is %d\n",nValueNormal); + printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + printf("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + delete pHighestThread; + delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: ASSERT_TRUE(// LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA:) << // LLA: "SetPriority"; // LLA: windows let starve threads with lower priority #ifndef WNT - CPPUNIT_ASSERT_MESSAGE( - "SetPriority", - nValueHighest > 0 && - nValueAboveNormal > 0 && - nValueNormal > 0 && - nValueBelowNormal > 0 && - nValueLowest > 0 - ); + ASSERT_TRUE(nValueHighest > 0 && + nValueAboveNormal > 0 && + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0) << "SetPriority"; #endif - } - - void setPriority_004() - { - // initial 5 threads with different priorities - // OAddThread *pHighestThread = new OAddThread(); - OAddThread *pAboveNormalThread = new OAddThread(); - OAddThread *pNormalThread = new OAddThread(); - OAddThread *pBelowNormalThread = new OAddThread(); - OAddThread *pLowestThread = new OAddThread(); - - //Create them and start running at the same time - // pHighestThread->createSuspended(); - // pHighestThread->setPriority(osl_Thread_PriorityHighest); - - pAboveNormalThread->createSuspended(); - pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); - - pNormalThread->createSuspended(); - pNormalThread->setPriority(osl_Thread_PriorityNormal); - - pBelowNormalThread->createSuspended(); - pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - - pLowestThread->createSuspended(); - pLowestThread->setPriority(osl_Thread_PriorityLowest); - - // pHighestThread->resume(); - pAboveNormalThread->resume(); - pNormalThread->resume(); - pBelowNormalThread->resume(); - pLowestThread->resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - // pHighestThread->suspend(); - pAboveNormalThread->suspend(); - pNormalThread->suspend(); - pBelowNormalThread->suspend(); - pLowestThread->suspend(); - - // termAndJoinThread(pHighestThread); - termAndJoinThread(pAboveNormalThread); - termAndJoinThread(pNormalThread); - termAndJoinThread(pBelowNormalThread); - termAndJoinThread(pLowestThread); - - // sal_Int32 nValueHighest = 0; - // nValueHighest = pHighestThread->getValue(); - - sal_Int32 nValueAboveNormal = 0; - nValueAboveNormal = pAboveNormalThread->getValue(); + } - sal_Int32 nValueNormal = 0; - nValueNormal = pNormalThread->getValue(); - - sal_Int32 nValueBelowNormal = 0; - nValueBelowNormal = pBelowNormalThread->getValue(); - - sal_Int32 nValueLowest = 0; - nValueLowest = pLowestThread->getValue(); - - t_print("After 5 tenth seconds\n"); - // t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); - t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); - - // delete pHighestThread; - delete pAboveNormalThread; - delete pNormalThread; - delete pBelowNormalThread; - delete pLowestThread; - - // LLA: this is not a save test, so we only check if all values not zero - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "SetPriority", - // LLA: nValueHighest > nValueAboveNormal && - // LLA: nValueAboveNormal > nValueNormal && - // LLA: nValueNormal > nValueBelowNormal && - // LLA: nValueBelowNormal > nValueLowest && - // LLA: nValueLowest > 0 - // LLA: ); + TEST_F(setPriority, setPriority_004) + { + // initial 5 threads with different priorities + // OAddThread *pHighestThread = new OAddThread(); + OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //Create them and start running at the same time + // pHighestThread->createSuspended(); + // pHighestThread->setPriority(osl_Thread_PriorityHighest); + + pAboveNormalThread->createSuspended(); + pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread->createSuspended(); + pNormalThread->setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread->createSuspended(); + pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread->createSuspended(); + pLowestThread->setPriority(osl_Thread_PriorityLowest); + + // pHighestThread->resume(); + pAboveNormalThread->resume(); + pNormalThread->resume(); + pBelowNormalThread->resume(); + pLowestThread->resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + // pHighestThread->suspend(); + pAboveNormalThread->suspend(); + pNormalThread->suspend(); + pBelowNormalThread->suspend(); + pLowestThread->suspend(); + + // termAndJoinThread(pHighestThread); + termAndJoinThread(pAboveNormalThread); + termAndJoinThread(pNormalThread); + termAndJoinThread(pBelowNormalThread); + termAndJoinThread(pLowestThread); + + // sal_Int32 nValueHighest = 0; + // nValueHighest = pHighestThread->getValue(); + + sal_Int32 nValueAboveNormal = 0; + nValueAboveNormal = pAboveNormalThread->getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + printf("After 5 tenth seconds\n"); + // printf("nValue in Highest Prio Thread is %d\n",nValueHighest); + printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + printf("nValue in Normal Prio Thread is %d\n",nValueNormal); + printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + printf("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + // delete pHighestThread; + delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: ASSERT_TRUE(// LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA:) << // LLA: "SetPriority"; // LLA: windows let starve threads with lower priority #ifndef WNT - CPPUNIT_ASSERT_MESSAGE( - "SetPriority", - /* nValueHighest > 0 && */ - nValueAboveNormal > 0 && - nValueNormal > 0 && - nValueBelowNormal > 0 && - nValueLowest > 0 - ); + ASSERT_TRUE(/* nValueHighest > 0 && */ + nValueAboveNormal > 0 && + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0) << "SetPriority"; #endif - } - void setPriority_005() - { - // initial 5 threads with different priorities - // OAddThread *pHighestThread = new OAddThread(); - // OAddThread *pAboveNormalThread = new OAddThread(); - OAddThread *pNormalThread = new OAddThread(); - OAddThread *pBelowNormalThread = new OAddThread(); - OAddThread *pLowestThread = new OAddThread(); - - //Create them and start running at the same time - // pHighestThread->createSuspended(); - // pHighestThread->setPriority(osl_Thread_PriorityHighest); - - // pAboveNormalThread->createSuspended(); - // pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); - - pNormalThread->createSuspended(); - pNormalThread->setPriority(osl_Thread_PriorityNormal); - - pBelowNormalThread->createSuspended(); - pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - - pLowestThread->createSuspended(); - pLowestThread->setPriority(osl_Thread_PriorityLowest); - - // pHighestThread->resume(); - // pAboveNormalThread->resume(); - pNormalThread->resume(); - pBelowNormalThread->resume(); - pLowestThread->resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - // pHighestThread->suspend(); - // pAboveNormalThread->suspend(); - pNormalThread->suspend(); - pBelowNormalThread->suspend(); - pLowestThread->suspend(); - - // termAndJoinThread(pHighestThread); - // termAndJoinThread(pAboveNormalThread); - termAndJoinThread(pNormalThread); - termAndJoinThread(pBelowNormalThread); - termAndJoinThread(pLowestThread); - - // sal_Int32 nValueHighest = 0; - // nValueHighest = pHighestThread->getValue(); - - // sal_Int32 nValueAboveNormal = 0; - // nValueAboveNormal = pAboveNormalThread->getValue(); - - sal_Int32 nValueNormal = 0; - nValueNormal = pNormalThread->getValue(); - - sal_Int32 nValueBelowNormal = 0; - nValueBelowNormal = pBelowNormalThread->getValue(); - - sal_Int32 nValueLowest = 0; - nValueLowest = pLowestThread->getValue(); - - t_print("After 5 tenth seconds\n"); - // t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - // t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); - t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); - - // delete pHighestThread; - // delete pAboveNormalThread; - delete pNormalThread; - delete pBelowNormalThread; - delete pLowestThread; - - // LLA: this is not a save test, so we only check if all values not zero - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "SetPriority", - // LLA: nValueHighest > nValueAboveNormal && - // LLA: nValueAboveNormal > nValueNormal && - // LLA: nValueNormal > nValueBelowNormal && - // LLA: nValueBelowNormal > nValueLowest && - // LLA: nValueLowest > 0 - // LLA: ); + } + TEST_F(setPriority, setPriority_005) + { + // initial 5 threads with different priorities + // OAddThread *pHighestThread = new OAddThread(); + // OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //Create them and start running at the same time + // pHighestThread->createSuspended(); + // pHighestThread->setPriority(osl_Thread_PriorityHighest); + + // pAboveNormalThread->createSuspended(); + // pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread->createSuspended(); + pNormalThread->setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread->createSuspended(); + pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread->createSuspended(); + pLowestThread->setPriority(osl_Thread_PriorityLowest); + + // pHighestThread->resume(); + // pAboveNormalThread->resume(); + pNormalThread->resume(); + pBelowNormalThread->resume(); + pLowestThread->resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + // pHighestThread->suspend(); + // pAboveNormalThread->suspend(); + pNormalThread->suspend(); + pBelowNormalThread->suspend(); + pLowestThread->suspend(); + + // termAndJoinThread(pHighestThread); + // termAndJoinThread(pAboveNormalThread); + termAndJoinThread(pNormalThread); + termAndJoinThread(pBelowNormalThread); + termAndJoinThread(pLowestThread); + + // sal_Int32 nValueHighest = 0; + // nValueHighest = pHighestThread->getValue(); + + // sal_Int32 nValueAboveNormal = 0; + // nValueAboveNormal = pAboveNormalThread->getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + printf("After 5 tenth seconds\n"); + // printf("nValue in Highest Prio Thread is %d\n",nValueHighest); + // printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + printf("nValue in Normal Prio Thread is %d\n",nValueNormal); + printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + printf("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + // delete pHighestThread; + // delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: ASSERT_TRUE(// LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA:) << // LLA: "SetPriority"; // LLA: windows let starve threads with lower priority #ifndef WNT - CPPUNIT_ASSERT_MESSAGE( - "SetPriority", - /* nValueHighest > 0 && */ - /* nValueAboveNormal > 0 && */ - nValueNormal > 0 && - nValueBelowNormal > 0 && - nValueLowest > 0 - ); + ASSERT_TRUE(/* nValueHighest > 0 && */ + /* nValueAboveNormal > 0 && */ + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0) << "SetPriority"; #endif - } - + } +#endif // SOLARIS - CPPUNIT_TEST_SUITE(setPriority); -#ifndef SOLARIS - CPPUNIT_TEST(setPriority_002); - CPPUNIT_TEST(setPriority_003); - CPPUNIT_TEST(setPriority_004); - CPPUNIT_TEST(setPriority_005); -#endif - CPPUNIT_TEST(setPriority_001_1); - CPPUNIT_TEST(setPriority_001_2); - CPPUNIT_TEST(setPriority_001_3); - CPPUNIT_TEST(setPriority_001_4); - CPPUNIT_TEST(setPriority_001_5); - CPPUNIT_TEST_SUITE_END(); - }; // class setPriority /** Test of the osl::Thread::getPriority method */ - class getPriority : public CppUnit::TestFixture + class getPriority : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class getPriority - // insert your test code here. - void getPriority_001() - { - OAddThread *pHighestThread = new OAddThread(); + TEST_F(getPriority, getPriority_001) + { + OAddThread *pHighestThread = new OAddThread(); - //Create them and start running at the same time - pHighestThread->create(); - pHighestThread->setPriority(osl_Thread_PriorityHighest); + //Create them and start running at the same time + pHighestThread->create(); + pHighestThread->setPriority(osl_Thread_PriorityHighest); - oslThreadPriority aPriority = pHighestThread->getPriority(); - termAndJoinThread(pHighestThread); - delete pHighestThread; + oslThreadPriority aPriority = pHighestThread->getPriority(); + termAndJoinThread(pHighestThread); + delete pHighestThread; - ThreadHelper::outputPriority(aPriority); + ThreadHelper::outputPriority(aPriority); // LLA: Priority settings may not work within some OS versions. #if ( defined WNT ) || ( defined SOLARIS ) - CPPUNIT_ASSERT_MESSAGE( - "getPriority", - aPriority == osl_Thread_PriorityHighest - ); + ASSERT_TRUE(aPriority == osl_Thread_PriorityHighest) << "getPriority"; #else // LLA: Linux // NO_PTHREAD_PRIORITY ??? - CPPUNIT_ASSERT_MESSAGE( - "getPriority", - aPriority == osl_Thread_PriorityNormal - ); + ASSERT_TRUE(aPriority == osl_Thread_PriorityNormal) << "getPriority"; #endif - } - - void getPriority_002() - { + } - } + TEST_F(getPriority, getPriority_002) + { - CPPUNIT_TEST_SUITE(getPriority); - CPPUNIT_TEST(getPriority_001); - CPPUNIT_TEST(getPriority_002); - CPPUNIT_TEST_SUITE_END(); - }; // class getPriority + } - class getIdentifier : public CppUnit::TestFixture + class getIdentifier : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class getIdentifier - // insert your test code here. - void getIdentifier_001() - { - - } + // insert your test code here. + TEST_F(getIdentifier, getIdentifier_001) + { - void getIdentifier_002() - { + } - } + TEST_F(getIdentifier, getIdentifier_002) + { - CPPUNIT_TEST_SUITE(getIdentifier); - CPPUNIT_TEST(getIdentifier_001); - CPPUNIT_TEST(getIdentifier_002); - CPPUNIT_TEST_SUITE_END(); - }; // class getIdentifier + } /** Test of the osl::Thread::getCurrentIdentifier method */ - class getCurrentIdentifier : public CppUnit::TestFixture + class getCurrentIdentifier : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class getCurrentIdentifier - // insert your test code here. - void getCurrentIdentifier_001() - { - oslThreadIdentifier oId; - OCountThread* pCountThread = new OCountThread; - //OCountThread* pCountThread2 = new OCountThread; - pCountThread->create(); - //pCountThread2->create(); - pCountThread->setWait(3); - oId = Thread::getCurrentIdentifier(); - oslThreadIdentifier oIdChild = pCountThread->getIdentifier(); - //t_print("CurrentId is %ld, Child1 id is %ld, Child2 id is %ld\n",oId, oIdChild,pCountThread2->m_id ); - termAndJoinThread(pCountThread); - delete pCountThread; - //termAndJoinThread(pCountThread2); - //delete pCountThread2; - - CPPUNIT_ASSERT_MESSAGE( - "Get the identifier for the current active thread.", - oId != oIdChild - ); + // insert your test code here. + TEST_F(getCurrentIdentifier, getCurrentIdentifier_001) + { + oslThreadIdentifier oId; + OCountThread* pCountThread = new OCountThread; + //OCountThread* pCountThread2 = new OCountThread; + pCountThread->create(); + //pCountThread2->create(); + pCountThread->setWait(3); + oId = Thread::getCurrentIdentifier(); + oslThreadIdentifier oIdChild = pCountThread->getIdentifier(); + //printf("CurrentId is %ld, Child1 id is %ld, Child2 id is %ld\n",oId, oIdChild,pCountThread2->m_id ); + termAndJoinThread(pCountThread); + delete pCountThread; + //termAndJoinThread(pCountThread2); + //delete pCountThread2; + + ASSERT_TRUE(oId != oIdChild) << "Get the identifier for the current active thread."; - } + } - void getCurrentIdentifier_002() - { - } + TEST_F(getCurrentIdentifier, getCurrentIdentifier_002) + { + } - CPPUNIT_TEST_SUITE(getCurrentIdentifier); - CPPUNIT_TEST(getCurrentIdentifier_001); - //CPPUNIT_TEST(getCurrentIdentifier_002); - CPPUNIT_TEST_SUITE_END(); - }; // class getCurrentIdentifier /** Test of the osl::Thread::wait method */ - class wait : public CppUnit::TestFixture + class wait : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class wait - /** call wait in the run method - ALGORITHM: - tested thread wait nWaitSec seconds, main thread sleep (2) seconds, - then terminate the tested thread, due to the fact that the thread do a sleep(1) + wait(5) - it's finish after 6 seconds. - */ - void wait_001() - { - OCountThread *aCountThread = new OCountThread(); - sal_Int32 nWaitSec = 5; - aCountThread->setWait(nWaitSec); - // thread runs at least 5 seconds. - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - //record the time when the running begin - StopWatch aStopWatch; - aStopWatch.start(); - - // wait a little bit, to let the thread the time, to start - ThreadHelper::thread_sleep_tenth_sec( 4 ); - - // if wait works, - // this function returns, after 4 sec. later - termAndJoinThread(aCountThread); - - // value should be one. - sal_Int32 nValue = aCountThread->getValue(); - - aStopWatch.stop(); - - // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; - double nTenthSec = aStopWatch.getTenthSec(); - double nSec = aStopWatch.getSeconds(); - delete aCountThread; - t_print("nTenthSec = %f \n", nTenthSec); - t_print("nSec = %f \n", nSec); - t_print("nValue = %d \n", nValue); - - CPPUNIT_ASSERT_MESSAGE( - "Wait: Blocks the calling thread for the given number of time.", - nTenthSec >= 5 && nValue == 1 - ); + /** call wait in the run method - } + ALGORITHM: + tested thread wait nWaitSec seconds, main thread sleep (2) seconds, + then terminate the tested thread, due to the fact that the thread do a sleep(1) + wait(5) + it's finish after 6 seconds. + */ + TEST_F(wait, wait_001) + { + OCountThread *aCountThread = new OCountThread(); + sal_Int32 nWaitSec = 5; + aCountThread->setWait(nWaitSec); + // thread runs at least 5 seconds. + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + + //record the time when the running begin + StopWatch aStopWatch; + aStopWatch.start(); + + // wait a little bit, to let the thread the time, to start + ThreadHelper::thread_sleep_tenth_sec( 4 ); + + // if wait works, + // this function returns, after 4 sec. later + termAndJoinThread(aCountThread); + + // value should be one. + sal_Int32 nValue = aCountThread->getValue(); + + aStopWatch.stop(); + + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + double nTenthSec = aStopWatch.getTenthSec(); + double nSec = aStopWatch.getSeconds(); + delete aCountThread; + printf("nTenthSec = %f \n", nTenthSec); + printf("nSec = %f \n", nSec); + printf("nValue = %d \n", nValue); + + ASSERT_TRUE(nTenthSec >= 5 && nValue == 1) << "Wait: Blocks the calling thread for the given number of time."; + + } // LLA: wait_001 does the same. // LLA: /** wait then terminate the thread // LLA: @@ -1812,7 +1676,7 @@ namespace osl_Thread // LLA: wait nWaitSec seconds, and terminate when the wait does not finish // LLA: Windows & UNX: thread terminates immediatlly // LLA: */ -// LLA: void wait_002() +// LLA: TEST_F(wait, wait_002) // LLA: { // LLA: OCountThread aThread; // LLA: @@ -1820,7 +1684,7 @@ namespace osl_Thread // LLA: aThread.setWait(nWaitSec); // LLA: // LLA: sal_Bool bRes = aThread.create(); -// LLA: CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); +// LLA: ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; // LLA: // LLA: StopWatch aStopWatch; // LLA: // TimeValue aTimeVal_befor; @@ -1835,184 +1699,135 @@ namespace osl_Thread // LLA: aStopWatch.stop(); // LLA: // sal_Int32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; // LLA: double nSec = aStopWatch.getSeconds(); -// LLA: t_print("sec=%f\n", nSec); -// LLA: t_print("nValue = %d\n", nValue); +// LLA: printf("sec=%f\n", nSec); +// LLA: printf("nValue = %d\n", nValue); // LLA: -// LLA: CPPUNIT_ASSERT_MESSAGE( -// LLA: "Wait: Blocks the calling thread for the given number of time.", -// LLA: nSec < 1 && nValue == 0 -// LLA: ); +// LLA: ASSERT_TRUE(// LLA: nSec < 1 && nValue == 0 +// LLA:) << // LLA: "Wait: Blocks the calling thread for the given number of time."; // LLA: } - - CPPUNIT_TEST_SUITE(wait); - CPPUNIT_TEST(wait_001); - // LLA: CPPUNIT_TEST(wait_002); - CPPUNIT_TEST_SUITE_END(); - }; // class wait - /** osl::Thread::yield method: can not design good test scenario to test up to now */ - class yield : public CppUnit::TestFixture + class yield : public ::testing::Test { public: - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } - - // insert your test code here. - void yield_001() - { - } - - - CPPUNIT_TEST_SUITE(yield); - CPPUNIT_TEST(yield_001); - CPPUNIT_TEST_SUITE_END(); }; // class yield + // insert your test code here. + TEST_F(yield, yield_001) + { + } + /** Test of the osl::Thread::schedule method */ - class schedule : public CppUnit::TestFixture + class schedule : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class schedule - /** The requested thread will get terminate the next time schedule() is called. - - Note: on UNX, if call suspend thread is not the to be suspended thread, the to be - suspended thread will get suspended the next time schedule() is called, - while on w32, it's nothing with schedule. + /** The requested thread will get terminate the next time schedule() is called. - check if suspend and terminate work well via schedule - */ - void schedule_001() - { - OAddThread* aThread = new OAddThread(); - sal_Bool bRes = aThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + Note: on UNX, if call suspend thread is not the to be suspended thread, the to be + suspended thread will get suspended the next time schedule() is called, + while on w32, it's nothing with schedule. - ThreadHelper::thread_sleep_tenth_sec(2); - aThread->suspend(); - ThreadHelper::thread_sleep_tenth_sec(1); - sal_Int32 nValue = aThread->getValue(); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nLaterValue = aThread->getValue(); - // resumeAndWaitThread(aThread); - t_print(" value = %d\n", nValue); - t_print("later value = %d\n", nLaterValue); - // if value and latervalue not equal, than the thread would not suspended + check if suspend and terminate work well via schedule + */ + TEST_F(schedule, schedule_001) + { + OAddThread* aThread = new OAddThread(); + sal_Bool bRes = aThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + + ThreadHelper::thread_sleep_tenth_sec(2); + aThread->suspend(); + ThreadHelper::thread_sleep_tenth_sec(1); + sal_Int32 nValue = aThread->getValue(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nLaterValue = aThread->getValue(); + // resumeAndWaitThread(aThread); + printf(" value = %d\n", nValue); + printf("later value = %d\n", nLaterValue); + // if value and latervalue not equal, than the thread would not suspended - CPPUNIT_ASSERT_MESSAGE( - "Schedule: suspend works.", - nLaterValue == nValue - ); + ASSERT_TRUE(nLaterValue == nValue) << "Schedule: suspend works."; - aThread->resume(); - ThreadHelper::thread_sleep_tenth_sec(2); + aThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); - aThread->terminate(); - sal_Int32 nValue_term = aThread->getValue(); + aThread->terminate(); + sal_Int32 nValue_term = aThread->getValue(); - aThread->join(); - sal_Int32 nValue_join = aThread->getValue(); + aThread->join(); + sal_Int32 nValue_join = aThread->getValue(); - t_print("value after term = %d\n", nValue_term); - t_print("value after join = %d\n", nValue_join); + printf("value after term = %d\n", nValue_term); + printf("value after join = %d\n", nValue_join); - // nValue_term and nValue_join should be the same - // but should be differ from nValue + // nValue_term and nValue_join should be the same + // but should be differ from nValue - delete aThread; - //check if thread really terminate after call terminate, if join immediatlly return - CPPUNIT_ASSERT_MESSAGE( - "Schedule: Returns False if the thread should terminate.", - nValue_join - nValue_term <= 1 && nValue_join - nValue_term >= 0 - ); + delete aThread; + //check if thread really terminate after call terminate, if join immediatlly return + ASSERT_TRUE(nValue_join - nValue_term <= 1 && nValue_join - nValue_term >= 0) << "Schedule: Returns False if the thread should terminate."; - } + } - /** design a thread that has not call schedule in the workfunction--run method - */ - void schedule_002() - { - ONoScheduleThread aThread; // this thread runs 10 sec. (no schedule() used) - sal_Bool bRes = aThread.create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + /** design a thread that has not call schedule in the workfunction--run method + */ + TEST_F(schedule, schedule_002) + { + ONoScheduleThread aThread; // this thread runs 10 sec. (no schedule() used) + sal_Bool bRes = aThread.create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - ThreadHelper::thread_sleep_tenth_sec(2); - aThread.suspend(); - sal_Int32 nValue = aThread.getValue(); + ThreadHelper::thread_sleep_tenth_sec(2); + aThread.suspend(); + sal_Int32 nValue = aThread.getValue(); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nLaterValue = aThread.getValue(); - ThreadHelper::thread_sleep_tenth_sec(5); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nLaterValue = aThread.getValue(); + ThreadHelper::thread_sleep_tenth_sec(5); - resumeAndWaitThread(&aThread); + resumeAndWaitThread(&aThread); - t_print(" value = %d\n", nValue); - t_print("later value = %d\n", nLaterValue); + printf(" value = %d\n", nValue); + printf("later value = %d\n", nLaterValue); - //On windows, suspend works, so the values are same + //On windows, suspend works, so the values are same #ifdef WNT - CPPUNIT_ASSERT_MESSAGE( - "Schedule: don't schedule in thread run method, suspend works.", - nLaterValue == nValue - ); + ASSERT_TRUE(nLaterValue == nValue) << "Schedule: don't schedule in thread run method, suspend works."; #endif - //On UNX, suspend does not work, so the difference of the values equals to sleep seconds number + //On UNX, suspend does not work, so the difference of the values equals to sleep seconds number #ifdef UNX - aThread.resume(); - CPPUNIT_ASSERT_MESSAGE( - "Schedule: don't schedule in thread run method, suspend does not work too.", - nLaterValue > nValue - ); + aThread.resume(); + ASSERT_TRUE(nLaterValue > nValue) << "Schedule: don't schedule in thread run method, suspend does not work too."; #endif - // terminate will not work if no schedule in thread's work function - termAndJoinThread(&aThread); - sal_Int32 nValue_term = aThread.getValue(); - - t_print(" value term = %d\n", nValue_term); + // terminate will not work if no schedule in thread's work function + termAndJoinThread(&aThread); + sal_Int32 nValue_term = aThread.getValue(); - CPPUNIT_ASSERT_MESSAGE( - "Schedule: don't schedule in thread run method, terminate failed.", - nValue_term == 10 - ); - } + printf(" value term = %d\n", nValue_term); - CPPUNIT_TEST_SUITE(schedule); - CPPUNIT_TEST(schedule_001); - CPPUNIT_TEST(schedule_002); - CPPUNIT_TEST_SUITE_END(); - }; // class schedule + ASSERT_TRUE(nValue_term == 10) << "Schedule: don't schedule in thread run method, terminate failed."; + } -// ----------------------------------------------------------------------------- - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::create, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::createSuspended, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::suspend, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::resume, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::terminate, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::join, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::isRunning, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::setPriority, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::getPriority, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::getIdentifier, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::getCurrentIdentifier, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::wait, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::yield, "osl_Thread"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::schedule, "osl_Thread"); } // namespace osl_Thread @@ -2020,7 +1835,7 @@ namespace osl_Thread // destroy function when the binding thread terminate void SAL_CALL destroyCallback(void * data) { - t_print("destroying local data %s\n", (char *) data); + printf("destroying local data %s\n", (char *) data); delete[] (char *) data; } @@ -2059,7 +1874,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } }; @@ -2077,7 +1892,7 @@ private: *pId = getIdentifier(); idData.setData(pId); oslThreadIdentifier* pIdData = (oslThreadIdentifier*)idData.getData(); - //t_print("Thread %d has Data %d\n", getIdentifier(), *pIdData); + //printf("Thread %d has Data %d\n", getIdentifier(), *pIdData); m_Id = *pIdData; delete pId; } @@ -2087,7 +1902,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } }; @@ -2095,246 +1910,214 @@ public: namespace osl_ThreadData { - class ctors : public CppUnit::TestFixture + class ctors : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class ctors - // insert your test code here. - void ctor_001() - { - - } - CPPUNIT_TEST_SUITE(ctors); - CPPUNIT_TEST(ctor_001); - CPPUNIT_TEST_SUITE_END(); - }; // class ctors + // insert your test code here. + TEST_F(ctors, ctor_001) + { + } - class setData : public CppUnit::TestFixture + class setData : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class setData - /** the same instance of the class can have different values in different threads - */ - void setData_001() - { - idThread aThread1; - aThread1.create(); - idThread aThread2; - aThread2.create(); + /** the same instance of the class can have different values in different threads + */ + TEST_F(setData, setData_001) + { + idThread aThread1; + aThread1.create(); + idThread aThread2; + aThread2.create(); - aThread1.join(); - aThread2.join(); + aThread1.join(); + aThread2.join(); - oslThreadIdentifier aThreadId1 = aThread1.getIdentifier(); - oslThreadIdentifier aThreadId2 = aThread2.getIdentifier(); + oslThreadIdentifier aThreadId1 = aThread1.getIdentifier(); + oslThreadIdentifier aThreadId2 = aThread2.getIdentifier(); - CPPUNIT_ASSERT_MESSAGE( - "ThreadData setData: ", - aThread1.m_Id == aThreadId1 && aThread2.m_Id == aThreadId2 - ); + ASSERT_TRUE(aThread1.m_Id == aThreadId1 && aThread2.m_Id == aThreadId2) << "ThreadData setData: "; - } + } - void setData_002() - { - // at first, set the data a value - char* pc = new char[2]; - char m_nData = 'm'; + TEST_F(setData, setData_002) + { + // at first, set the data a value + char* pc = new char[2]; + char m_nData = 'm'; // LLA: this is a copy functions only and really only for \0 terminated strings // m_nData is not a string, it's a character // strcpy(pc, &m_nData); - memcpy(pc, &m_nData, 1); - pc[1] = '\0'; + memcpy(pc, &m_nData, 1); + pc[1] = '\0'; - myThreadData.setData(pc); + myThreadData.setData(pc); - myKeyThread aThread1('a'); - aThread1.create(); - myKeyThread aThread2('b'); - aThread2.create(); - // aThread1 and aThread2 should have not terminated yet, check current data, not 'a' 'b' - char* pChar = (char*)myThreadData.getData(); - char aChar = *pChar; + myKeyThread aThread1('a'); + aThread1.create(); + myKeyThread aThread2('b'); + aThread2.create(); + // aThread1 and aThread2 should have not terminated yet, check current data, not 'a' 'b' + char* pChar = (char*)myThreadData.getData(); + char aChar = *pChar; - aThread1.join(); - aThread2.join(); + aThread1.join(); + aThread2.join(); - // the saved thread data of aThread1 & aThread2, different - char cData1 = aThread1.m_Char_Test; - char cData2 = aThread2.m_Char_Test; + // the saved thread data of aThread1 & aThread2, different + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; - CPPUNIT_ASSERT_MESSAGE( - "ThreadData setData: ", - cData1 == 'a' && cData2 == 'b' && aChar == 'm' - ); + ASSERT_TRUE(cData1 == 'a' && cData2 == 'b' && aChar == 'm') << "ThreadData setData: "; - } - /** setData the second time, and then getData - */ - void setData_003() - { - // at first, set the data a value - char* pc = new char[2]; - char m_nData = 'm'; + } + /** setData the second time, and then getData + */ + TEST_F(setData, setData_003) + { + // at first, set the data a value + char* pc = new char[2]; + char m_nData = 'm'; // strcpy(pc, &m_nData); - memcpy(pc, &m_nData, 1); - pc[1] = '\0'; - myThreadData.setData(pc); - - myKeyThread aThread1('a'); - aThread1.create(); - myKeyThread aThread2('b'); - aThread2.create(); - // aThread1 and aThread2 should have not terminated yet - // setData the second time - char* pc2 = new char[2]; - m_nData = 'o'; -// strcpy(pc2, &m_nData); - memcpy(pc2, &m_nData, 1); - pc2[1] = '\0'; + memcpy(pc, &m_nData, 1); + pc[1] = '\0'; + myThreadData.setData(pc); - myThreadData.setData(pc2); - char* pChar = (char*)myThreadData.getData(); - char aChar = *pChar; + myKeyThread aThread1('a'); + aThread1.create(); + myKeyThread aThread2('b'); + aThread2.create(); + // aThread1 and aThread2 should have not terminated yet + // setData the second time + char* pc2 = new char[2]; + m_nData = 'o'; +// strcpy(pc2, &m_nData); + memcpy(pc2, &m_nData, 1); + pc2[1] = '\0'; - aThread1.join(); - aThread2.join(); + myThreadData.setData(pc2); + char* pChar = (char*)myThreadData.getData(); + char aChar = *pChar; - // the saved thread data of aThread1 & aThread2, different - char cData1 = aThread1.m_Char_Test; - char cData2 = aThread2.m_Char_Test; + aThread1.join(); + aThread2.join(); - CPPUNIT_ASSERT_MESSAGE( - "ThreadData setData: ", - cData1 == 'a' && cData2 == 'b' && aChar == 'o' - ); + // the saved thread data of aThread1 & aThread2, different + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; - } + ASSERT_TRUE(cData1 == 'a' && cData2 == 'b' && aChar == 'o') << "ThreadData setData: "; - CPPUNIT_TEST_SUITE(setData); - CPPUNIT_TEST(setData_001); - CPPUNIT_TEST(setData_002); - CPPUNIT_TEST(setData_003); - CPPUNIT_TEST_SUITE_END(); - }; // class setData + } //sal_Bool buildTwoThreads(char) - class getData : public CppUnit::TestFixture + class getData : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class getData - // After setData in child threads, get Data in the main thread, should be independent - void getData_001() - { - char* pc = new char[2]; - char m_nData[] = "i"; - strcpy(pc, m_nData); - t_print("pc %s\n", pc); - myThreadData.setData(pc); + // After setData in child threads, get Data in the main thread, should be independent + TEST_F(getData, getData_001) + { + char* pc = new char[2]; + char m_nData[] = "i"; + strcpy(pc, m_nData); + printf("pc %s\n", pc); + myThreadData.setData(pc); - myKeyThread aThread1('c'); - aThread1.create(); - myKeyThread aThread2('d'); - aThread2.create(); + myKeyThread aThread1('c'); + aThread1.create(); + myKeyThread aThread2('d'); + aThread2.create(); - aThread1.join(); - aThread2.join(); + aThread1.join(); + aThread2.join(); - char cData1 = aThread1.m_Char_Test; - char cData2 = aThread2.m_Char_Test; + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; - char* pChar = (char*)myThreadData.getData(); - char aChar = *pChar; + char* pChar = (char*)myThreadData.getData(); + char aChar = *pChar; - CPPUNIT_ASSERT_MESSAGE( - "ThreadData setData: ", - cData1 == 'c' && cData2 == 'd' && aChar == 'i' - ); + ASSERT_TRUE(cData1 == 'c' && cData2 == 'd' && aChar == 'i') << "ThreadData setData: "; - } + } - // setData then change the value in the address data pointer points, - // and then getData, should get the new value - void getData_002() - { - char* pc = new char[2]; - char m_nData = 'i'; + // setData then change the value in the address data pointer points, + // and then getData, should get the new value + TEST_F(getData, getData_002) + { + char* pc = new char[2]; + char m_nData = 'i'; // strcpy(pc, &m_nData); - memcpy(pc, &m_nData, 1); - pc[1] = '\0'; + memcpy(pc, &m_nData, 1); + pc[1] = '\0'; // strncpy(pc, &m_nData, sizeof(char); - t_print("pc %s\n", pc); - myThreadData.setData(pc); + printf("pc %s\n", pc); + myThreadData.setData(pc); - myKeyThread aThread1('a'); - aThread1.create(); - myKeyThread aThread2('b'); - aThread2.create(); + myKeyThread aThread1('a'); + aThread1.create(); + myKeyThread aThread2('b'); + aThread2.create(); - // change the value which pc points - char m_nData2 = 'j'; - // strcpy(pc, &m_nData2); - memcpy(pc, &m_nData2, 1); - pc[1] = '\0'; + // change the value which pc points + char m_nData2 = 'j'; + // strcpy(pc, &m_nData2); + memcpy(pc, &m_nData2, 1); + pc[1] = '\0'; - //t_print("pc %s\n", pc); - void* pChar = myThreadData.getData(); - char aChar = *(char*)pChar; + //printf("pc %s\n", pc); + void* pChar = myThreadData.getData(); + char aChar = *(char*)pChar; - aThread1.join(); - aThread2.join(); + aThread1.join(); + aThread2.join(); - char cData1 = aThread1.m_Char_Test; - char cData2 = aThread2.m_Char_Test; + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; - CPPUNIT_ASSERT_MESSAGE( - "ThreadData setData: ", - cData1 == 'a' && cData2 == 'b' && aChar == 'j' - ); + ASSERT_TRUE(cData1 == 'a' && cData2 == 'b' && aChar == 'j') << "ThreadData setData: "; - } + } - CPPUNIT_TEST_SUITE(getData); - CPPUNIT_TEST(getData_001); - CPPUNIT_TEST(getData_002); - CPPUNIT_TEST_SUITE_END(); - }; // class getData -// ----------------------------------------------------------------------------- - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ThreadData::ctors, "osl_ThreadData"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ThreadData::setData, "osl_ThreadData"); - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ThreadData::getData, "osl_ThreadData"); } // namespace osl_ThreadData -// this macro creates an empty function, which will called by the RegisterAllFunctions() -// to let the user the possibility to also register some functions by hand. -NOADDITIONAL; - +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/sal/qa/osl/process/osl_process.cxx b/sal/qa/osl/process/osl_process.cxx index be19ef03a4f2..0c1ee9f10383 100644 --- a/sal/qa/osl/process/osl_process.cxx +++ b/sal/qa/osl/process/osl_process.cxx @@ -24,7 +24,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" -#include +#include "gtest/gtest.h" #include #include #include @@ -75,9 +75,9 @@ inline void printUString( const ::rtl::OUString & str ) { rtl::OString aString; - t_print("#printUString_u# " ); + printf("#printUString_u# " ); aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); - t_print("%s\n", aString.getStr( ) ); + printf("%s\n", aString.getStr( ) ); } /** get binary Path. @@ -95,8 +95,9 @@ inline ::rtl::OUString getExecutablePath( void ) //rtl::OUString CWD = getExecutablePath(); //######################################## -class Test_osl_joinProcess : public CppUnit::TestFixture +class Test_osl_joinProcess : public ::testing::Test { +protected: const OUString join_param_; const OUString wait_time_; OUString suCWD; @@ -119,178 +120,136 @@ public: suExecutableFileURL += rtl::OUString::createFromAscii("/"); suExecutableFileURL += EXECUTABLE_NAME; } +}; - /*------------------------------------- - Start a process and join with this - process specify a timeout so that - osl_joinProcessWithTimeout returns - osl_Process_E_TimedOut - -------------------------------------*/ +/*------------------------------------- + Start a process and join with this + process specify a timeout so that + osl_joinProcessWithTimeout returns + osl_Process_E_TimedOut + -------------------------------------*/ - void osl_joinProcessWithTimeout_timeout_failure() - { - oslProcess process; - oslProcessError osl_error = osl_executeProcess( - suExecutableFileURL.pData, - parameters_, - parameters_count_, - osl_Process_NORMAL, - osl_getCurrentSecurity(), - suCWD.pData, - NULL, - 0, - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - TimeValue timeout; - timeout.Seconds = 1; - timeout.Nanosec = 0; - - osl_error = osl_joinProcessWithTimeout(process, &timeout); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcessWithTimeout returned without timeout failure", - osl_Process_E_TimedOut == osl_error - ); - - osl_error = osl_terminateProcess(process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_terminateProcess failed", - osl_error == osl_Process_E_None - ); - - osl_freeProcessHandle(process); - } +TEST_F(Test_osl_joinProcess, osl_joinProcessWithTimeout_timeout_failure) +{ + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); - /*------------------------------------- - Start a process and join with this - process specify a timeout so that - osl_joinProcessWithTimeout returns - osl_Process_E_None - -------------------------------------*/ + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; - void osl_joinProcessWithTimeout_without_timeout_failure() - { - oslProcess process; - oslProcessError osl_error = osl_executeProcess( - suExecutableFileURL.pData, - parameters_, - parameters_count_, - osl_Process_NORMAL, - osl_getCurrentSecurity(), - suCWD.pData, - NULL, - 0, - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - TimeValue timeout; - timeout.Seconds = 10; - timeout.Nanosec = 0; - - osl_error = osl_joinProcessWithTimeout(process, &timeout); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcessWithTimeout returned with failure", - osl_Process_E_None == osl_error - ); - - osl_freeProcessHandle(process); - } + TimeValue timeout; + timeout.Seconds = 1; + timeout.Nanosec = 0; - /*------------------------------------- - Start a process and join with this - process specify an infinite timeout - -------------------------------------*/ + osl_error = osl_joinProcessWithTimeout(process, &timeout); - void osl_joinProcessWithTimeout_infinite() - { - oslProcess process; - oslProcessError osl_error = osl_executeProcess( - suExecutableFileURL.pData, - parameters_, - parameters_count_, - osl_Process_NORMAL, - osl_getCurrentSecurity(), - suCWD.pData, - NULL, - 0, - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - osl_error = osl_joinProcessWithTimeout(process, NULL); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcessWithTimeout returned with failure", - osl_Process_E_None == osl_error - ); - - osl_freeProcessHandle(process); - } + ASSERT_TRUE(osl_Process_E_TimedOut == osl_error) << "osl_joinProcessWithTimeout returned without timeout failure"; - /*------------------------------------- - Start a process and join with this - process using osl_joinProcess - -------------------------------------*/ + osl_error = osl_terminateProcess(process); - void osl_joinProcess() - { - oslProcess process; - oslProcessError osl_error = osl_executeProcess( - suExecutableFileURL.pData, - parameters_, - parameters_count_, - osl_Process_NORMAL, - osl_getCurrentSecurity(), - suCWD.pData, - NULL, - 0, - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - osl_error = ::osl_joinProcess(process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcess returned with failure", - osl_Process_E_None == osl_error - ); - - osl_freeProcessHandle(process); - } + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_terminateProcess failed"; + + osl_freeProcessHandle(process); +} + +/*------------------------------------- + Start a process and join with this + process specify a timeout so that + osl_joinProcessWithTimeout returns + osl_Process_E_None + -------------------------------------*/ + +TEST_F(Test_osl_joinProcess, osl_joinProcessWithTimeout_without_timeout_failure) +{ + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); + + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; + + TimeValue timeout; + timeout.Seconds = 10; + timeout.Nanosec = 0; + + osl_error = osl_joinProcessWithTimeout(process, &timeout); + + ASSERT_TRUE(osl_Process_E_None == osl_error) << "osl_joinProcessWithTimeout returned with failure"; + + osl_freeProcessHandle(process); +} + + /*------------------------------------- + Start a process and join with this + process specify an infinite timeout + -------------------------------------*/ + +TEST_F(Test_osl_joinProcess, osl_joinProcessWithTimeout_infinite) +{ + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); + + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; + + osl_error = osl_joinProcessWithTimeout(process, NULL); + + ASSERT_TRUE(osl_Process_E_None == osl_error) << "osl_joinProcessWithTimeout returned with failure"; + + osl_freeProcessHandle(process); +} + + /*------------------------------------- + Start a process and join with this + process using osl_joinProcess + -------------------------------------*/ + +TEST_F(Test_osl_joinProcess, osl_joinProcess) +{ + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); + + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; + + osl_error = ::osl_joinProcess(process); + + ASSERT_TRUE(osl_Process_E_None == osl_error) << "osl_joinProcess returned with failure"; + + osl_freeProcessHandle(process); +} - CPPUNIT_TEST_SUITE(Test_osl_joinProcess); - CPPUNIT_TEST(osl_joinProcessWithTimeout_timeout_failure); - CPPUNIT_TEST(osl_joinProcessWithTimeout_without_timeout_failure); - CPPUNIT_TEST(osl_joinProcessWithTimeout_infinite); - CPPUNIT_TEST(osl_joinProcess); - CPPUNIT_TEST_SUITE_END(); -}; //######################################################### @@ -363,8 +322,9 @@ private: #endif //######################################################### -class Test_osl_executeProcess : public CppUnit::TestFixture +class Test_osl_executeProcess : public ::testing::Test { +protected: const OUString env_param_; OUString temp_file_path_; @@ -389,7 +349,7 @@ public: } //------------------------------------------------ - virtual void setUp() + virtual void SetUp() { temp_file_path_ = create_temp_file(); parameters_[1] = temp_file_path_.pData; @@ -400,11 +360,11 @@ public: { OUString temp_file_url; FileBase::RC rc = FileBase::createTempFile(0, 0, &temp_file_url); - CPPUNIT_ASSERT_MESSAGE("createTempFile failed", FileBase::E_None == rc); + EXPECT_TRUE(FileBase::E_None == rc) << "createTempFile failed"; OUString temp_file_path; rc = FileBase::getSystemPathFromFileURL(temp_file_url, temp_file_path); - CPPUNIT_ASSERT_MESSAGE("getSystemPathFromFileURL failed", FileBase::E_None == rc); + EXPECT_TRUE(FileBase::E_None == rc) << "getSystemPathFromFileURL failed"; return temp_file_path; } @@ -416,11 +376,7 @@ public: parameters_[1]), osl_getThreadTextEncoding()); std::ifstream file(temp_file_name.getStr()); - CPPUNIT_ASSERT_MESSAGE - ( - "I/O error, cannot open child environment file", - file.is_open() - ); + ASSERT_TRUE(file.is_open()) << "I/O error, cannot open child environment file"; std::string line; while (std::getline(file, line)) @@ -491,188 +447,139 @@ public: return (common_env_size_equals && common_env_content_equals && different_env_size_equals && different_env_content_equals); } +}; - //------------------------------------------------ - // test that parent and child process have the - // same environment when osl_executeProcess will - // be called with out setting new environment - // variables - void osl_execProc_parent_equals_child_environment() - { - oslProcess process; - oslProcessError osl_error = osl_executeProcess( - suExecutableFileURL.pData, - parameters_, - parameters_count_, - osl_Process_NORMAL, - NULL, - suCWD.pData, - NULL, - 0, - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - osl_error = ::osl_joinProcess(process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcess returned with failure", - osl_Process_E_None == osl_error - ); - - osl_freeProcessHandle(process); - - CPPUNIT_ASSERT_MESSAGE - ( - "Parent an child environment not equal", - compare_environments() - ); - } +//------------------------------------------------ +// test that parent and child process have the +// same environment when osl_executeProcess will +// be called with out setting new environment +// variables +TEST_F(Test_osl_executeProcess, osl_execProc_parent_equals_child_environment) +{ + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + NULL, + suCWD.pData, + NULL, + 0, + &process); - //------------------------------------------------ - #define ENV1 "PAT=a:\\" - #define ENV2 "PATHb=b:\\" - #define ENV3 "Patha=c:\\" - #define ENV4 "Patha=d:\\" + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; - void osl_execProc_merged_child_environment() - { - rtl_uString* child_env[4]; - OUString env1 = OUString::createFromAscii(ENV1); - OUString env2 = OUString::createFromAscii(ENV2); - OUString env3 = OUString::createFromAscii(ENV3); - OUString env4 = OUString::createFromAscii(ENV4); - - child_env[0] = env1.pData; - child_env[1] = env2.pData; - child_env[2] = env3.pData; - child_env[3] = env4.pData; - - oslProcess process; - oslProcessError osl_error = osl_executeProcess( - suExecutableFileURL.pData, - parameters_, - parameters_count_, - osl_Process_NORMAL, - NULL, - suCWD.pData, - child_env, - sizeof(child_env)/sizeof(child_env[0]), - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - osl_error = ::osl_joinProcess(process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcess returned with failure", - osl_Process_E_None == osl_error - ); - - osl_freeProcessHandle(process); - - string_container_t different_child_env_vars; - different_child_env_vars.push_back(ENV1); - different_child_env_vars.push_back(ENV2); - different_child_env_vars.push_back(ENV4); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_execProc_merged_child_environment", - compare_merged_environments(different_child_env_vars) - ); - } + osl_error = ::osl_joinProcess(process); - void osl_execProc_test_batch() - { - oslProcess process; - rtl::OUString suBatch = suCWD + rtl::OUString::createFromAscii("/") + rtl::OUString::createFromAscii("batch.bat"); - oslProcessError osl_error = osl_executeProcess( - suBatch.pData, - NULL, - 0, - osl_Process_NORMAL, - NULL, - suCWD.pData, - NULL, - 0, - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - osl_error = ::osl_joinProcess(process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcess returned with failure", - osl_Process_E_None == osl_error - ); - - osl_freeProcessHandle(process); - } + ASSERT_TRUE(osl_Process_E_None == osl_error) << "osl_joinProcess returned with failure"; - void osl_execProc_exe_name_in_argument_list() - { - rtl_uString* params[3]; - - params[0] = suExecutableFileURL.pData; - params[1] = env_param_.pData; - params[2] = temp_file_path_.pData; - oslProcess process; - oslProcessError osl_error = osl_executeProcess( - NULL, - params, - 3, - osl_Process_NORMAL, - NULL, - suCWD.pData, - NULL, - 0, - &process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_createProcess failed", - osl_error == osl_Process_E_None - ); - - osl_error = ::osl_joinProcess(process); - - CPPUNIT_ASSERT_MESSAGE - ( - "osl_joinProcess returned with failure", - osl_Process_E_None == osl_error - ); - - osl_freeProcessHandle(process); - } + osl_freeProcessHandle(process); - CPPUNIT_TEST_SUITE(Test_osl_executeProcess); - CPPUNIT_TEST(osl_execProc_parent_equals_child_environment); - CPPUNIT_TEST(osl_execProc_merged_child_environment); - CPPUNIT_TEST(osl_execProc_test_batch); - CPPUNIT_TEST(osl_execProc_exe_name_in_argument_list); - CPPUNIT_TEST_SUITE_END(); -}; + ASSERT_TRUE(compare_environments()) << "Parent an child environment not equal"; +} -//##################################### -// register test suites -//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_joinProcess, "Test_osl_joinProcess"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_executeProcess, "Test_osl_executeProcess"); +//------------------------------------------------ +#define ENV1 "PAT=a:\\" +#define ENV2 "PATHb=b:\\" +#define ENV3 "Patha=c:\\" +#define ENV4 "Patha=d:\\" -NOADDITIONAL; +TEST_F(Test_osl_executeProcess, osl_execProc_merged_child_environment) +{ + rtl_uString* child_env[4]; + OUString env1 = OUString::createFromAscii(ENV1); + OUString env2 = OUString::createFromAscii(ENV2); + OUString env3 = OUString::createFromAscii(ENV3); + OUString env4 = OUString::createFromAscii(ENV4); + + child_env[0] = env1.pData; + child_env[1] = env2.pData; + child_env[2] = env3.pData; + child_env[3] = env4.pData; + + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + NULL, + suCWD.pData, + child_env, + sizeof(child_env)/sizeof(child_env[0]), + &process); + + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; + + osl_error = ::osl_joinProcess(process); + + ASSERT_TRUE(osl_Process_E_None == osl_error) << "osl_joinProcess returned with failure"; + + osl_freeProcessHandle(process); + + string_container_t different_child_env_vars; + different_child_env_vars.push_back(ENV1); + different_child_env_vars.push_back(ENV2); + different_child_env_vars.push_back(ENV4); + + ASSERT_TRUE(compare_merged_environments(different_child_env_vars)) << "osl_execProc_merged_child_environment"; +} +TEST_F(Test_osl_executeProcess, osl_execProc_test_batch) +{ + oslProcess process; + rtl::OUString suBatch = suCWD + rtl::OUString::createFromAscii("/") + rtl::OUString::createFromAscii("batch.bat"); + oslProcessError osl_error = osl_executeProcess( + suBatch.pData, + NULL, + 0, + osl_Process_NORMAL, + NULL, + suCWD.pData, + NULL, + 0, + &process); + + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; + + osl_error = ::osl_joinProcess(process); + + ASSERT_TRUE(osl_Process_E_None == osl_error) << "osl_joinProcess returned with failure"; + + osl_freeProcessHandle(process); +} + +TEST_F(Test_osl_executeProcess, osl_execProc_exe_name_in_argument_list) +{ + rtl_uString* params[3]; + + params[0] = suExecutableFileURL.pData; + params[1] = env_param_.pData; + params[2] = temp_file_path_.pData; + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + NULL, + params, + 3, + osl_Process_NORMAL, + NULL, + suCWD.pData, + NULL, + 0, + &process); + + ASSERT_TRUE(osl_error == osl_Process_E_None) << "osl_createProcess failed"; + + osl_error = ::osl_joinProcess(process); + + ASSERT_TRUE(osl_Process_E_None == osl_error) << "osl_joinProcess returned with failure"; + + osl_freeProcessHandle(process); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} -- cgit