Back to index

lightning-sunbird  0.9+nobinonly
Functions
Sleep.cpp File Reference
#include <ThreadManagerTests.h>

Go to the source code of this file.

Functions

 TM_OJIAPITest (ThreadManager_Sleep_1)
 TM_OJIAPITest (ThreadManager_Sleep_2)

Function Documentation

TM_OJIAPITest ( ThreadManager_Sleep_1  )

Definition at line 41 of file Sleep.cpp.

                                     {
       GET_TM_FOR_TEST
       PRUint32 id = 0;
       class DummyThread : public BaseDummyThread {
       private:
              nsIThreadManager *tm;
       public:
              int awoken;
              DummyThread(nsIThreadManager *aTm) : tm(aTm), awoken(0) {}
              NS_METHOD Run() {
                     tm->Sleep(0);
                     awoken = 1;
                     return NS_OK;
              }
       };

       DummyThread *newThread = new DummyThread(threadMgr);
       nsresult rc  = threadMgr->CreateThread(&id, (nsIRunnable*)newThread);
       if (NS_SUCCEEDED(rc)) {
              rc = threadMgr->Sleep(500);        
              if (NS_SUCCEEDED(rc) && newThread->awoken) //if it waked up -> pass
                     return TestResult::PASS("Method should work OK.");
              return TestResult::FAIL("Sleep", rc);
       } 
       return TestResult::FAIL("Sleep", "Can't create new thread", rc);

}

Here is the call graph for this function:

TM_OJIAPITest ( ThreadManager_Sleep_2  )

Definition at line 71 of file Sleep.cpp.

                                     {
       GET_TM_FOR_TEST
       PRUint32 id = 0;
       class DummyThread : public BaseDummyThread {
       private:
              nsIThreadManager *tm;
       public:
              int isSleeping;
              DummyThread(nsIThreadManager *aTm) : tm(aTm), isSleeping(1) {} //UINT_MAX = 32-bit uint max value 
              NS_METHOD Run() {
                     tm->Sleep(UINT_MAX);
                     isSleeping = 0;
                     return NS_OK;
              }
       };

       DummyThread *newThread = new DummyThread(threadMgr);
       nsresult rc  = threadMgr->CreateThread(&id, (nsIRunnable*)newThread);
       if (NS_SUCCEEDED(rc)) {
              rc = threadMgr->Sleep(500);        
              if (NS_SUCCEEDED(rc) && newThread->isSleeping)
                     return TestResult::PASS("Method should work OK.");
              return TestResult::FAIL("Sleep", rc);
       } 
       return TestResult::FAIL("Sleep", "Can't create new thread", rc);

}

Here is the call graph for this function: