Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
TestURLParser.cpp File Reference
#include "TestCommon.h"
#include <stdio.h>
#include "nsIURLParser.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsNetCID.h"

Go to the source code of this file.


#define PRINT_FIELD(x)   print_field(# x, x, x ## Len)
#define PRINT_SUBFIELD(base, x)


static void print_field (const char *label, char *str, PRInt32 len)
static void parse_authority (nsIURLParser *urlParser, char *auth, PRInt32 authLen)
static void parse_file_path (nsIURLParser *urlParser, char *filepath, PRInt32 filepathLen)
static void parse_path (nsIURLParser *urlParser, char *path, PRInt32 pathLen)
int main (int argc, char **argv)
 The Xalan testcases app.

Define Documentation

#define PRINT_FIELD (   x)    print_field(# x, x, x ## Len)

Definition at line 17 of file TestURLParser.cpp.

#define PRINT_SUBFIELD (   base,
        if (x ## Len != -1) \
            print_field(# x, base + x ## Pos, x ## Len); \

Definition at line 20 of file TestURLParser.cpp.

Function Documentation

int main ( int  argc,
char **  argv 

The Xalan testcases app.

Definition at line 89 of file TestURLParser.cpp.

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

    if (argc < 2) {
        printf("usage: TestURLParser [-std|-noauth|-auth] <url>\n");
        return -1;
    nsCOMPtr<nsIURLParser> urlParser;
    if (strcmp(argv[1], "-noauth") == 0) {
        urlParser = do_GetService(NS_NOAUTHURLPARSER_CONTRACTID);
        argv[1] = argv[2];
    else if (strcmp(argv[1], "-auth") == 0) {
        urlParser = do_GetService(NS_AUTHURLPARSER_CONTRACTID);
        argv[1] = argv[2];
    else {
        urlParser = do_GetService(NS_STDURLPARSER_CONTRACTID);
        if (strcmp(argv[1], "-std") == 0)
            argv[1] = argv[2];
            printf("assuming -std\n");
    if (urlParser) {
        printf("have urlParser @%p\n", urlParser.get());

        char *spec = argv[1];
        PRUint32 schemePos, authPos, pathPos;
        PRInt32 schemeLen, authLen, pathLen;

        urlParser->ParseURL(spec, -1,
                            &schemePos, &schemeLen,
                            &authPos, &authLen,
                            &pathPos, &pathLen);

        if (schemeLen != -1)
            PRINT_SUBFIELD(spec, scheme);
        if (authLen != -1)
            parse_authority(urlParser, spec + authPos, authLen);
        if (pathLen != -1)
            parse_path(urlParser, spec + pathPos, pathLen);
        printf("no urlParser\n");
    return 0;

Here is the call graph for this function:

static void parse_authority ( nsIURLParser urlParser,
char *  auth,
PRInt32  authLen 
) [static]

Definition at line 27 of file TestURLParser.cpp.


    PRUint32 usernamePos, passwordPos;
    PRInt32 usernameLen, passwordLen;
    PRUint32 hostnamePos;
    PRInt32 hostnameLen, port;

    urlParser->ParseAuthority(auth, authLen,
                              &usernamePos, &usernameLen,
                              &passwordPos, &passwordLen,
                              &hostnamePos, &hostnameLen,

    PRINT_SUBFIELD(auth, username);
    PRINT_SUBFIELD(auth, password);
    PRINT_SUBFIELD(auth, hostname);
    if (port != -1)
        printf("[port=%d]\n", port);

Here is the caller graph for this function:

static void parse_file_path ( nsIURLParser urlParser,
char *  filepath,
PRInt32  filepathLen 
) [static]

Definition at line 50 of file TestURLParser.cpp.


    PRUint32 dirPos, basePos, extPos;
    PRInt32 dirLen, baseLen, extLen;

    urlParser->ParseFilePath(filepath, filepathLen,
                             &dirPos, &dirLen,
                             &basePos, &baseLen,
                             &extPos, &extLen);

    PRINT_SUBFIELD(filepath, dir);
    PRINT_SUBFIELD(filepath, base);
    PRINT_SUBFIELD(filepath, ext);

Here is the caller graph for this function:

static void parse_path ( nsIURLParser urlParser,
char *  path,
PRInt32  pathLen 
) [static]

Definition at line 68 of file TestURLParser.cpp.


    PRUint32 filePos, paramPos, queryPos, refPos;
    PRInt32 fileLen, paramLen, queryLen, refLen;

    urlParser->ParsePath(path, pathLen,
                         &filePos, &fileLen,
                         &paramPos, &paramLen,
                         &queryPos, &queryLen,
                         &refPos, &refLen);

    if (fileLen != -1)
        parse_file_path(urlParser, path + filePos, fileLen);
    PRINT_SUBFIELD(path, param);
    PRINT_SUBFIELD(path, query);
    PRINT_SUBFIELD(path, ref);

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_field ( const char *  label,
char *  str,
PRInt32  len 
) [static]

Definition at line 9 of file TestURLParser.cpp.

    char c = str[len];
    str[len] = '\0';
    printf("[%s=%s]\n", label, str);
    str[len] = c;