cout << "Adding Observer-A as observer of topic-A..." << endl;
printf("Adding Observer-A as observer of topic-A...\n");
int main(int argc, char *argv[]){    nsCString topicA; topicA.Assign( "topic-A" );    nsCString topicB; topicB.Assign( "topic-B" );    nsresult rv;    nsresult res = nsComponentManager::CreateInstance("@mozilla.org/observer-service;1",                                                NULL,                                                 NS_GET_IID(nsIObserverService),                                                (void **) &anObserverService);	    if (res == NS_OK) {        nsIObserver *aObserver = new TestObserver(NS_LITERAL_STRING("Observer-A"));        aObserver->AddRef();        nsIObserver *bObserver = new TestObserver(NS_LITERAL_STRING("Observer-B"));        bObserver->AddRef();                    cout << "Adding Observer-A as observer of topic-A..." << endl;        rv = anObserverService->AddObserver(aObserver, topicA.get(), PR_FALSE);        testResult(rv);         cout << "Adding Observer-B as observer of topic-A..." << endl;        rv = anObserverService->AddObserver(bObserver, topicA.get(), PR_FALSE);        testResult(rv);         cout << "Adding Observer-B as observer of topic-B..." << endl;        rv = anObserverService->AddObserver(bObserver, topicB.get(), PR_FALSE);        testResult(rv);        cout << "Testing Notify(observer-A, topic-A)..." << endl;        rv = anObserverService->NotifyObservers( aObserver,                                   topicA.get(),                                   NS_LITERAL_STRING("Testing Notify(observer-A, topic-A)").get() );        testResult(rv);        cout << "Testing Notify(observer-B, topic-B)..." << endl;        rv = anObserverService->NotifyObservers( bObserver,                                   topicB.get(),                                   NS_LITERAL_STRING("Testing Notify(observer-B, topic-B)").get() );        testResult(rv);         cout << "Testing EnumerateObserverList (for topic-A)..." << endl;        nsCOMPtr<nsISimpleEnumerator> e;        rv = anObserverService->EnumerateObservers(topicA.get(), getter_AddRefs(e));        testResult(rv);        cout << "Enumerating observers of topic-A..." << endl;        if ( e ) {          nsCOMPtr<nsIObserver> observer;          PRBool loop = PR_TRUE;          while( NS_SUCCEEDED(e->HasMoreElements(&loop)) && loop)           {              e->GetNext(getter_AddRefs(observer));              cout << "Calling observe on enumerated observer "                   << NS_REINTERPRET_CAST(TestObserver*, NS_REINTERPRET_CAST(void*, observer.get()))->mName << "..." << endl;              rv = observer->Observe( observer,                                       topicA.get(),                                       NS_LITERAL_STRING("during enumeration").get() );              testResult(rv);          }        }        cout << "...done enumerating observers of topic-A" << endl;        cout << "Removing Observer-A..." << endl;        rv = anObserverService->RemoveObserver(aObserver, topicA.get());        testResult(rv);        cout << "Removing Observer-B (topic-A)..." << endl;        rv = anObserverService->RemoveObserver(bObserver, topicB.get());        testResult(rv);        cout << "Removing Observer-B (topic-B)..." << endl;        rv = anObserverService->RemoveObserver(bObserver, topicA.get());        testResult(rv);           }    return NS_OK;}