1 #include "TestCommon.h"
3 #include "nsIURLParser.h"
5 #include "nsIServiceManager.h"
7 #include "nsServiceManagerUtils.h"
10 print_field(const char *label
, char *str
, PRInt32 len
)
14 printf("[%s=%s]\n", label
, str
);
18 #define PRINT_FIELD(x) \
19 print_field(# x, x, x ## Len)
21 #define PRINT_SUBFIELD(base, x) \
24 print_field(# x, base + x ## Pos, x ## Len); \
28 parse_authority(nsIURLParser
*urlParser
, char *auth
, PRInt32 authLen
)
32 PRUint32 usernamePos
, passwordPos
;
33 PRInt32 usernameLen
, passwordLen
;
35 PRInt32 hostnameLen
, port
;
37 urlParser
->ParseAuthority(auth
, authLen
,
38 &usernamePos
, &usernameLen
,
39 &passwordPos
, &passwordLen
,
40 &hostnamePos
, &hostnameLen
,
43 PRINT_SUBFIELD(auth
, username
);
44 PRINT_SUBFIELD(auth
, password
);
45 PRINT_SUBFIELD(auth
, hostname
);
47 printf("[port=%d]\n", port
);
51 parse_file_path(nsIURLParser
*urlParser
, char *filepath
, PRInt32 filepathLen
)
53 PRINT_FIELD(filepath
);
55 PRUint32 dirPos
, basePos
, extPos
;
56 PRInt32 dirLen
, baseLen
, extLen
;
58 urlParser
->ParseFilePath(filepath
, filepathLen
,
63 PRINT_SUBFIELD(filepath
, dir
);
64 PRINT_SUBFIELD(filepath
, base
);
65 PRINT_SUBFIELD(filepath
, ext
);
69 parse_path(nsIURLParser
*urlParser
, char *path
, PRInt32 pathLen
)
73 PRUint32 filePos
, paramPos
, queryPos
, refPos
;
74 PRInt32 fileLen
, paramLen
, queryLen
, refLen
;
76 urlParser
->ParsePath(path
, pathLen
,
83 parse_file_path(urlParser
, path
+ filePos
, fileLen
);
84 PRINT_SUBFIELD(path
, param
);
85 PRINT_SUBFIELD(path
, query
);
86 PRINT_SUBFIELD(path
, ref
);
90 main(int argc
, char **argv
)
92 if (test_common_init(&argc
, &argv
) != 0)
96 printf("usage: TestURLParser [-std|-noauth|-auth] <url>\n");
99 nsCOMPtr
<nsIURLParser
> urlParser
;
100 if (strcmp(argv
[1], "-noauth") == 0) {
101 urlParser
= do_GetService(NS_NOAUTHURLPARSER_CONTRACTID
);
104 else if (strcmp(argv
[1], "-auth") == 0) {
105 urlParser
= do_GetService(NS_AUTHURLPARSER_CONTRACTID
);
109 urlParser
= do_GetService(NS_STDURLPARSER_CONTRACTID
);
110 if (strcmp(argv
[1], "-std") == 0)
113 printf("assuming -std\n");
116 printf("have urlParser @%p\n", urlParser
.get());
118 char *spec
= argv
[1];
119 PRUint32 schemePos
, authPos
, pathPos
;
120 PRInt32 schemeLen
, authLen
, pathLen
;
122 urlParser
->ParseURL(spec
, -1,
123 &schemePos
, &schemeLen
,
128 PRINT_SUBFIELD(spec
, scheme
);
130 parse_authority(urlParser
, spec
+ authPos
, authLen
);
132 parse_path(urlParser
, spec
+ pathPos
, pathLen
);
135 printf("no urlParser\n");