Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
TestOpen.cpp File Reference
#include "TestCommon.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIURI.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
#include "nsIInputStream.h"
#include "nsNetUtil.h"
#include <stdio.h>

Go to the source code of this file.

Defines

#define RETURN_IF_FAILED(rv, what)

Functions

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

Define Documentation

#define RETURN_IF_FAILED (   rv,
  what 
)
Value:
PR_BEGIN_MACRO \
    if (NS_FAILED(rv)) { \
        printf(what ": failed - %08x\n", rv); \
        return -1; \
    } \
    PR_END_MACRO

Definition at line 54 of file TestOpen.cpp.


Function Documentation

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 63 of file TestOpen.cpp.

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

    nsresult rv;
    char buf[256];

    if (argc != 3) {
        printf("Usage: TestOpen url filename\nLoads a URL using ::Open, writing it to a file\n");
        return -1;
    }

    nsCOMPtr<nsIURI> uri;
    nsCOMPtr<nsIInputStream> stream;

    rv = NS_NewURI(getter_AddRefs(uri), argv[1]);
    RETURN_IF_FAILED(rv, "NS_NewURI");

    rv = NS_OpenURI(getter_AddRefs(stream), uri);
    RETURN_IF_FAILED(rv, "NS_OpenURI");

    FILE* outfile = fopen(argv[2], "wb");
    if (!outfile) {
      printf("error opening %s\n", argv[2]);
      return 1;
    }

    PRUint32 read;
    while (NS_SUCCEEDED(stream->Read(buf, sizeof(buf), &read)) && read) {
      fwrite(buf, 1, read, outfile);
    }
    printf("Done\n");

    fclose(outfile);

    NS_ShutdownXPCOM(nsnull);
    return 0;
}

Here is the call graph for this function: