1 #include "TestCommon.h"
3 #include "nsIURLParser.h"
5 #include "nsIServiceManager.h"
7 #include "nsServiceManagerUtils.h"
10 print_field(const char *label
, char *str
, int32_t 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
, int32_t authLen
)
32 uint32_t usernamePos
, passwordPos
;
33 int32_t usernameLen
, passwordLen
;
35 int32_t 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
, int32_t filepathLen
)
53 PRINT_FIELD(filepath
);
55 uint32_t dirPos
, basePos
, extPos
;
56 int32_t 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
, int32_t pathLen
)
73 uint32_t filePos
, queryPos
, refPos
;
74 int32_t fileLen
, queryLen
, refLen
;
76 urlParser
->ParsePath(path
, pathLen
,
82 parse_file_path(urlParser
, path
+ filePos
, fileLen
);
83 PRINT_SUBFIELD(path
, query
);
84 PRINT_SUBFIELD(path
, ref
);
88 main(int argc
, char **argv
)
90 if (test_common_init(&argc
, &argv
) != 0)
94 printf("usage: TestURLParser [-std|-noauth|-auth] <url>\n");
97 nsCOMPtr
<nsIURLParser
> urlParser
;
98 if (strcmp(argv
[1], "-noauth") == 0) {
99 urlParser
= do_GetService(NS_NOAUTHURLPARSER_CONTRACTID
);
102 else if (strcmp(argv
[1], "-auth") == 0) {
103 urlParser
= do_GetService(NS_AUTHURLPARSER_CONTRACTID
);
107 urlParser
= do_GetService(NS_STDURLPARSER_CONTRACTID
);
108 if (strcmp(argv
[1], "-std") == 0)
111 printf("assuming -std\n");
114 printf("have urlParser @%p\n", static_cast<void*>(urlParser
.get()));
116 char *spec
= argv
[1];
117 uint32_t schemePos
, authPos
, pathPos
;
118 int32_t schemeLen
, authLen
, pathLen
;
120 urlParser
->ParseURL(spec
, -1,
121 &schemePos
, &schemeLen
,
126 PRINT_SUBFIELD(spec
, scheme
);
128 parse_authority(urlParser
, spec
+ authPos
, authLen
);
130 parse_path(urlParser
, spec
+ pathPos
, pathLen
);
133 printf("no urlParser\n");