Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
TestDNS.cpp File Reference
#include "TestCommon.h"
#include <stdio.h>
#include <stdlib.h>
#include "nsIServiceManager.h"
#include "nsPIDNSService.h"
#include "nsIDNSListener.h"
#include "nsIDNSRecord.h"
#include "nsICancelable.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsNetCID.h"
#include "prinrval.h"
#include "prthread.h"
#include "prnetdb.h"
#include "nsCRT.h"

Go to the source code of this file.

Classes

class  myDNSListener

Functions

int main (int argc, char **argv)
 The Xalan testcases app.

Function Documentation

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 93 of file TestDNS.cpp.

{
    if (test_common_init(&argc, &argv) != 0)
        return -1;

    int sleepLen = 10; // default: 10 seconds

    if (argc == 1) {
        printf("usage: TestDNS [-N] hostname1 [hostname2 ...]\n");
        return -1;
    }

    nsCOMPtr<nsPIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
    if (!dns)
        return -1;

    if (argv[1][0] == '-') {
        sleepLen = atoi(argv[1]+1);
        argv++;
        argc--;
    }

    for (int j=0; j<2; ++j) {
        for (int i=1; i<argc; ++i) {
            // assume non-ASCII input is given in the native charset 
            nsCAutoString hostBuf;
            if (nsCRT::IsAscii(argv[i]))
                hostBuf.Assign(argv[i]);
            else
                hostBuf = NS_ConvertUCS2toUTF8(NS_ConvertASCIItoUCS2(argv[i]));

            nsCOMPtr<nsIDNSListener> listener = new myDNSListener(argv[i], i);

            nsCOMPtr<nsICancelable> req;
            nsresult rv = dns->AsyncResolve(hostBuf,
                                            nsIDNSService::RESOLVE_CANONICAL_NAME,
                                            listener, nsnull, getter_AddRefs(req));
            if (NS_FAILED(rv))
                printf("### AsyncResolve failed [rv=%x]\n", rv);
        }

        printf("main thread sleeping for %d seconds...\n", sleepLen);
        PR_Sleep(PR_SecondsToInterval(sleepLen));
    }

    printf("shutting down main thread...\n");
    dns->Shutdown();
    return 0;
}

Here is the call graph for this function: