Back to index

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

Go to the source code of this file.

Functions

 TM_OJIAPITest (ThreadManager_Notify_1)
 TM_OJIAPITest (ThreadManager_Notify_2)
 TM_OJIAPITest (ThreadManager_Notify_3)
 TM_OJIAPITest (ThreadManager_Notify_4)

Function Documentation

TM_OJIAPITest ( ThreadManager_Notify_1  )

Definition at line 40 of file Notify.cpp.

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

}

Here is the call graph for this function:

TM_OJIAPITest ( ThreadManager_Notify_2  )

Definition at line 50 of file Notify.cpp.

                                      {
       GET_TM_FOR_TEST
       nsresult rc = threadMgr->Notify(threadMgr);
       if (NS_SUCCEEDED(rc))
              return TestResult::PASS("Method should fail because it can call Notify only being monitor's owner.");
       return TestResult::FAIL("Notify", rc);

}

Here is the call graph for this function:

TM_OJIAPITest ( ThreadManager_Notify_3  )

Definition at line 60 of file Notify.cpp.

                                      {
       GET_TM_FOR_TEST
       class DummyThread : public BaseDummyThread {
       public:
              int notified;
              DummyThread(nsIThreadManager *threadMgr, nsresult def_rc) : notified(0) {
                     tm = threadMgr;
                     rc = def_rc; 
              }
              NS_METHOD Run() { 
                     nsresult lrc = tm->EnterMonitor(tm);
                     if (NS_SUCCEEDED(lrc))  {
                            //printf("Thread %p is waiting for notify ...\n", this);
                            lrc = tm->Wait(tm);
                            //if first thread notified it - nsresult rc =ing OK
                            if (NS_SUCCEEDED(lrc) && notified)
                                   this->rc = NS_OK;
                            tm->ExitMonitor(tm);
                     } else {
                            fprintf(stderr, "ERROR: new thread %p can't create monitor for adress %p\n", this, tm);
                     }
                     while(1);
                     return NS_OK;
              }
       };
       PRUint32 id = 0;
       DummyThread *newThread1 = new DummyThread(threadMgr, NS_ERROR_FAILURE);

       nsresult rc  = threadMgr->CreateThread(&id, (nsIRunnable*)newThread1);
       if (NS_SUCCEEDED(rc)) {
              //give time to new thread to enter monitor and say wait
              threadMgr->Sleep((PRUint32)500);
              rc = threadMgr->EnterMonitor(threadMgr);
              if (NS_SUCCEEDED(rc)) {
                     newThread1->notified = 1;
                     threadMgr->Notify(threadMgr);
                     if (NS_SUCCEEDED(rc)) {
                            rc = threadMgr->ExitMonitor(threadMgr);
                            if (NS_SUCCEEDED(rc)) {
                                   //time to check notified flag and set rc to NS_OK
                                   threadMgr->Sleep((PRUint32)500);
                                   if (NS_SUCCEEDED(newThread1->rc))
                                          return TestResult::PASS("Method should work OK.");
                                   return TestResult::FAIL("Notify", rc);           
                            } else {
                                   return TestResult::FAIL("Notify", "Can't exit monitor", rc);
                            }
                     } else {
                            //can't call Notify method
                            return TestResult::FAIL("Notify", rc);
                     }
              } else {
                     return TestResult::FAIL("Notify", "Can't enter monitor", rc);
              }
       }
       //can't create new threds
       return TestResult::FAIL("Notify", "Can't create new threads", rc);
}

Here is the call graph for this function:

TM_OJIAPITest ( ThreadManager_Notify_4  )

Definition at line 121 of file Notify.cpp.

                                      {
       GET_TM_FOR_TEST
       nsresult rc = threadMgr->EnterMonitor(threadMgr);
       
       if (NS_SUCCEEDED(rc)) {
              nsresult rc = threadMgr->Notify(threadMgr);
              if (NS_SUCCEEDED(rc))
                     return TestResult::PASS("Method should work even if there are no other threads waiting on monitor.");
              return TestResult::FAIL("Notify", rc);
       }
       return TestResult::FAIL("Notify", "Can't enter monitor", rc);
}

Here is the call graph for this function: