Back to index

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

Go to the source code of this file.

Functions

 TM_OJIAPITest (ThreadManager_ExitMonitor_1)
 TM_OJIAPITest (ThreadManager_ExitMonitor_2)
 TM_OJIAPITest (ThreadManager_ExitMonitor_3)
 TM_OJIAPITest (ThreadManager_ExitMonitor_4)

Function Documentation

TM_OJIAPITest ( ThreadManager_ExitMonitor_1  )

Definition at line 39 of file ExitMonitor.cpp.

                                           {
       GET_TM_FOR_TEST
       nsresult rc = threadMgr->ExitMonitor(NULL);
       if (NS_FAILED(rc))
              return TestResult::PASS("Method should fail because adress is invalid (NULL).");
       return TestResult::FAIL("ExitMonitor", rc);
}

Here is the call graph for this function:

TM_OJIAPITest ( ThreadManager_ExitMonitor_2  )

Definition at line 47 of file ExitMonitor.cpp.

                                           {
       GET_TM_FOR_TEST
       nsresult rc = threadMgr->ExitMonitor(threadMgr);
       if (NS_SUCCEEDED(rc))
              return TestResult::PASS("Thread can exit monitor even if it doesn't own it.");
       return TestResult::FAIL("ExitMonitor", rc);

}

Here is the call graph for this function:

TM_OJIAPITest ( ThreadManager_ExitMonitor_3  )

Definition at line 56 of file ExitMonitor.cpp.

                                           {
       GET_TM_FOR_TEST
       nsresult rc = threadMgr->EnterMonitor(threadMgr);
       if (NS_SUCCEEDED(rc)) {
              rc = threadMgr->ExitMonitor(threadMgr);
              if (NS_SUCCEEDED(rc))
                     return TestResult::PASS("Method should work OK.");
              return TestResult::FAIL("ExitMonitor", rc);
       }
       return TestResult::FAIL("ExitMonitor", "Can't enter monitor", rc);

}

Here is the call graph for this function:

TM_OJIAPITest ( ThreadManager_ExitMonitor_4  )

Definition at line 69 of file ExitMonitor.cpp.

                                           {
       GET_TM_FOR_TEST
       class DummyThread : public BaseDummyThread {
       public:
              DummyThread(nsIThreadManager *threadMgr, nsresult def_rc) {
                     tm = threadMgr;
                     rc = def_rc;
              } 
              NS_METHOD Run() { 
                     //printf("New thread enters monitor with adress %p ... ", tm); 
                     tm->EnterMonitor(tm); 
                     rc = NS_OK;
                     //printf("OK - new thread should be able to enter monitor !\n"); 
                     while(1); 
                     return NS_OK;
              }
       };
       PRUint32 id = 0;
       DummyThread *newThread = new DummyThread(threadMgr, NS_ERROR_FAILURE);

       //printf("Our thread enters monitor with adress %p (%d) ...\n", threadMgr, id);
       nsresult rc = threadMgr->EnterMonitor(threadMgr);
       if (NS_SUCCEEDED(rc)) {
              rc = threadMgr->CreateThread(&id, (nsIRunnable*)newThread);
              if (NS_SUCCEEDED(rc))  {
                     //let's give new thread a second to call EnterMonitor method
                     threadMgr->Sleep(500);
                     rc = threadMgr->ExitMonitor(threadMgr);
                     if (NS_SUCCEEDED(rc)) {
                            threadMgr->Sleep(500);
                            rc = newThread->rc;
                            if (NS_SUCCEEDED(rc))
                                   return TestResult::PASS("Another thread CAN enter monitor if the current thread unlock it.");
                            return TestResult::FAIL("ExitMonitor", rc);
                     }
                     //printf("First thread can't exit monitor ...\n");
                     return TestResult::FAIL("ExitMonitor", "First thread can't exit monitor", rc);
              }
              //printf("Can't create new thred !\n");          
              return TestResult::FAIL("ExitMonitor", "Can't create new thread", rc);

       }
       //printf("First thread can't enter monitor ...\n");
       return TestResult::FAIL("ExitMonitor", "First thread can't enter monitor", rc);
}

Here is the call graph for this function: