4 #include "TestCommon.h"
6 #include "nsIServiceManager.h"
10 #include "nsStringAPI.h"
11 #include "nsComponentManagerUtils.h"
13 static nsIURL
*test_url
= 0;
14 static nsCString test_param
;
16 static void run_test(const char *testname
, int count
, void (* testfunc
)())
18 PRIntervalTime start
, end
;
19 start
= PR_IntervalNow();
20 for (; count
; --count
)
22 end
= PR_IntervalNow();
23 printf("completed %s test in %u milliseconds\n", testname
,
24 PR_IntervalToMilliseconds(end
- start
));
27 static void set_spec_test()
29 test_url
->SetSpec(test_param
);
32 static void get_spec_test()
35 test_url
->GetSpec(spec
);
38 static void resolve_test()
41 test_url
->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), spec
);
44 static void set_scheme_test()
46 test_url
->SetScheme(NS_LITERAL_CSTRING("foo"));
49 static void get_scheme_test()
52 test_url
->GetScheme(scheme
);
55 static void host_test()
58 test_url
->GetHost(host
);
59 test_url
->SetHost(NS_LITERAL_CSTRING("www.yahoo.com"));
60 test_url
->SetHost(host
);
63 static void set_path_test()
65 test_url
->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you"));
68 static void get_path_test()
71 test_url
->GetPath(path
);
74 static void query_test()
77 test_url
->GetQuery(query
);
78 test_url
->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45"));
79 test_url
->SetQuery(query
);
82 static void ref_test()
85 test_url
->GetRef(ref
);
86 test_url
->SetRef(NS_LITERAL_CSTRING("#some-book-mark"));
87 test_url
->SetRef(ref
);
90 int main(int argc
, char **argv
)
92 if (test_common_init(&argc
, &argv
) != 0)
96 printf("usage: TestURL url [count]\n");
102 count
= atoi(argv
[2]);
104 printf("using a default count of %d\n", count
);
106 nsCOMPtr
<nsIURL
> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID
) );
108 printf("failed to instantiate component: %s\n", NS_STANDARDURL_CONTRACTID
);
113 test_param
= argv
[1];
115 run_test("SetSpec", count
, set_spec_test
);
116 run_test("GetSpec", count
, get_spec_test
);
117 run_test("Resolve", count
, resolve_test
);
118 run_test("SetScheme", count
, set_scheme_test
);
119 run_test("GetScheme", count
, get_scheme_test
);
120 run_test("[GS]etHost", count
, host_test
);
121 run_test("SetPath", count
, set_path_test
);
122 run_test("GetPath", count
, get_path_test
);
123 run_test("[GS]etQuery", count
, query_test
);
124 run_test("[GS]etRef", count
, ref_test
);