Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
TestServMgr.cpp File Reference
#include "MyService.h"
#include "nsXPCOM.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include <stdio.h>

Go to the source code of this file.

Functions

static NS_DEFINE_CID (kIMyServiceCID, NS_IMYSERVICE_CID)
nsresult BeginTest (int testNumber)
nsresult EndTest (int testNumber)
nsresult SimpleTest (int testNumber)
nsresult AsyncShutdown (int testNumber)
nsresult AsyncNoShutdownTest (int testNumber)
int main (void)
 main()

Variables

IMyServicemyServ = NULL

Function Documentation

nsresult AsyncNoShutdownTest ( int  testNumber)

Definition at line 113 of file TestServMgr.cpp.

{
    // This test gets a service, and also gets an async request for shutdown,
    // but the service doesn't get shut down because some other client (who's
    // not participating in the async shutdown game as he should) is 
    // continuing to hang onto the service. This causes myServ variable to 
    // get set to NULL, but the service doesn't get unloaded right away as
    // it should.

    nsresult err;

    err = BeginTest(testNumber);
    if (err != NS_OK) return err;

    // Create some other user of kIMyServiceCID, preventing it from
    // really going away:
    IMyService* otherClient;
    err = CallGetService(kIMyServiceCID, &otherClient);
    if (err != NS_OK) return err;

    err = AsyncShutdown(testNumber);
    if (err != NS_OK) return err;
    err = EndTest(testNumber);

    // Finally, release the other client.
    NS_RELEASE(otherClient);

    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult AsyncShutdown ( int  testNumber)

Definition at line 91 of file TestServMgr.cpp.

{
    nsresult err = NS_OK;

    // If the AsyncShutdown was truly asynchronous and happened on another
    // thread, we'd have to protect all accesses to myServ throughout this
    // code with a monitor.

    // XXX-darin: say what?!?

    /*
    err = nsServiceManager::UnregisterService(kIMyServiceCID);
    if (err == NS_ERROR_SERVICE_NOT_AVAILABLE) {
        printf("async shutdown -- service not found\n");
        return NS_OK;
    }
    */

    return err;
}

Here is the caller graph for this function:

nsresult BeginTest ( int  testNumber)

Definition at line 52 of file TestServMgr.cpp.

{
    nsresult err;
    NS_ASSERTION(myServ == NULL, "myServ not reset");
    err = CallGetService(kIMyServiceCID, &myServ);
    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult EndTest ( int  testNumber)

Definition at line 61 of file TestServMgr.cpp.

{
    nsresult err = NS_OK;

    if (myServ) {
        err = myServ->Doit();
        if (err != NS_OK) return err;

        NS_RELEASE(myServ);
    }
    
    printf("test %d succeeded\n", testNumber);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( void  )

main()

Definition at line 145 of file TestServMgr.cpp.

{
    nsresult err;
    int testNumber = 0;

    err = NS_InitXPCOM2(nsnull, nsnull, nsnull);
    if (NS_FAILED(err)) {
        printf("NS_InitXPCOM2 failed\n");
        return -1;
    }

    err = SimpleTest(++testNumber);
    if (err != NS_OK)
        goto error;

    err = AsyncNoShutdownTest(++testNumber);
    if (err != NS_OK)
        goto error;

    AsyncShutdown(++testNumber);

    printf("there was great success\n");
    return 0;

  error:
    printf("test %d failed\n", testNumber);
    return -1;
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kIMyServiceCID  ,
NS_IMYSERVICE_CID   
) [static]
nsresult SimpleTest ( int  testNumber)

Definition at line 77 of file TestServMgr.cpp.

{
    // This test just gets a service, uses it and releases it.

    nsresult err;
    err = BeginTest(testNumber);
    if (err != NS_OK) return err;
    err = EndTest(testNumber);
    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 49 of file TestServMgr.cpp.