Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions
CnsIObserServ Class Reference

#include <nsIObserServ.h>

Inheritance diagram for CnsIObserServ:
Inheritance graph
[legend]
Collaboration diagram for CnsIObserServ:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CnsIObserServ ()
virtual ~CnsIObserServ ()
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER void 
RunAllTests ()
void AddObserversTest (int)
void RemoveObserversTest (int)
void NotifyObserversTest (int)
void EnumerateObserversTest (int)
void OnStartTests (UINT nMenuID)
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Detailed Description

Definition at line 51 of file nsIObserServ.h.


Constructor & Destructor Documentation

Definition at line 51 of file nsIObserServ.cpp.

{
       mRefCnt = 1 ;
}

Definition at line 58 of file nsIObserServ.cpp.

{

}

Member Function Documentation

Definition at line 124 of file nsIObserServ.cpp.

{
       int i;

       nsCOMPtr<nsIObserverService>observerService(do_GetService("@mozilla.org/observer-service;1",&rv));
       RvTestResult(rv, "nsIObserverService object test", displayType);
       RvTestResultDlg(rv, "nsIObserverService object test", true);

       QAOutput("\n nsIObserverService::AddObserversTest().");
       if (!observerService) 
       {
              QAOutput("Can't get nsIObserverService object. Tests fail.");
              return;
       }

       for (i=0; i<10; i++)
       {
              rv = observerService->AddObserver(this, ObserverTable[i].theTopic, 
                                                                     ObserverTable[i].theOwnsWeak);
              FormatAndPrintOutput("The observer to be added = ", ObserverTable[i].theTopic, 1);  
              RvTestResult(rv, "AddObservers() test", displayType);
              RvTestResultDlg(rv, "AddObservers() test");
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 195 of file nsIObserServ.cpp.

{
       PRInt32 i=0;
       nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1",&rv));
       nsCOMPtr<nsISimpleEnumerator> simpleEnum;

       QAOutput("\n nsIObserverService::EnumerateObserversTest().");
       if (!observerService) 
       {
              QAOutput("Can't get nsIObserverService object. Tests fail.");
              return;
       }

       for (i=0; i<10; i++)
       {
              // need to handle Simple Enumerator

              rv = observerService->EnumerateObservers(ObserverTable[i].theTopic, 
                                                                                     getter_AddRefs(simpleEnum));

              RvTestResult(rv, "EnumerateObserversTest() test", displayType);
              RvTestResultDlg(rv, "EnumerateObserversTest() test");
              if (!simpleEnum)
              {
                     QAOutput("Didn't get SimpleEnumerator object. Tests fail.");
                     return;
              }

              nsCOMPtr<nsIObserver> observer;
              PRBool theLoop = PR_TRUE;
              PRBool bLoop = PR_TRUE;

              while( NS_SUCCEEDED(simpleEnum->HasMoreElements(&theLoop)) && bLoop) 
              {
                     simpleEnum->GetNext(getter_AddRefs(observer));

                     if (!observer)
                     {
                            QAOutput("Didn't get the observer object. Tests fail.");
                            return;
                     }
                     rv = observer->Observe(observer, ObserverTable[i].theTopic, 0);
                     RvTestResult(rv, "nsIObserver() test", 1);       
                     RvTestResultDlg(rv, "nsIObserver() test");
                     
                     // compare 'this' with observer object
                     if( this == NS_REINTERPRET_CAST(CnsIObserServ*,NS_REINTERPRET_CAST(void*, observer.get())))
                     {
                            QAOutput("observers match. Test passes.");
                            bLoop = PR_FALSE;
                     }
                     else
                            QAOutput("observers don't match. Test fails.");
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 172 of file nsIObserServ.cpp.

{
       PRInt32 i;
       nsCOMPtr<nsIObserverService>observerService(do_GetService("@mozilla.org/observer-service;1",&rv));

       QAOutput("\n nsIObserverService::NotifyObserversTest().");

       if (!observerService) 
       {
              QAOutput("Can't get nsIObserverService object. Tests fail.");
              return;
       }

       for (i=0; i<10; i++)
       {
              FormatAndPrintOutput("The notified observer = ", ObserverTable[i].theTopic, 1);
              rv = observerService->NotifyObservers(nsnull, ObserverTable[i].theTopic, 0);
              RvTestResult(rv, "NotifyObservers() test", displayType);
              RvTestResultDlg(rv, "NotifyObservers() test");
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Definition at line 77 of file nsIObserServ.cpp.

{
       // Calls  all or indivdual test cases on the basis of the 
       // option selected from menu.

       switch(nMenuID)
       {

       case ID_INTERFACES_NSIOBSERVERSERVICE_RUNALLTESTS :
              RunAllTests();
              break;

       case ID_INTERFACES_NSIOBSERVERSERVICE_ADDOBSERVERS :
              AddObserversTest(2);
              break;

       case ID_INTERFACES_NSIOBSERVERSERVICE_ENUMERATEOBSERVERS :
              QAOutput("Adding observers first", 2);
              AddObserversTest(1);        
              EnumerateObserversTest(1);
              break;

       case ID_INTERFACES_NSIOBSERVERSERVICE_NOTIFYOBSERVERS :
              NotifyObserversTest(1);
              break;

       case ID_INTERFACES_NSIOBSERVERSERVICE_REMOVEOBSERVERS :
              QAOutput("Adding observers first.", 2);
              AddObserversTest(1);
              RemoveObserversTest(1);
              break;

       default :
              AfxMessageBox("Menu handler not added for this menu item");
              break;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 149 of file nsIObserServ.cpp.

{
       int i;

       nsCOMPtr<nsIObserverService>observerService(do_GetService("@mozilla.org/observer-service;1",&rv));

       QAOutput("\n nsIObserverService::RemoveObserversTest().");
       if (!observerService) 
       {
              QAOutput("Can't get nsIObserverService object. Tests fail.");
              return;
       }

       for (i=0; i<10; i++)
       {
              rv = observerService->RemoveObserver(this, ObserverTable[i].theTopic);
              FormatAndPrintOutput("The observer to be removed = ", ObserverTable[i].theTopic, 1);       
              RvTestResult(rv, "RemoveObservers() test", displayType);
              RvTestResultDlg(rv, "RemoveObservers() test");
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 116 of file nsIObserServ.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: