On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / netwerk / test / TestStandardURL.cpp
blob1633b25e9c66b8ac58d008f0d07c58d2bb19072b
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "TestCommon.h"
5 #include "nsCOMPtr.h"
6 #include "nsIServiceManager.h"
7 #include "nsNetCID.h"
8 #include "nsIURL.h"
9 #include "prinrval.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)
21 testfunc();
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()
34 nsCAutoString spec;
35 test_url->GetSpec(spec);
38 static void resolve_test()
40 nsCAutoString spec;
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()
51 nsCAutoString scheme;
52 test_url->GetScheme(scheme);
55 static void host_test()
57 nsCAutoString host;
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()
70 nsCAutoString path;
71 test_url->GetPath(path);
74 static void query_test()
76 nsCAutoString query;
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()
84 nsCAutoString ref;
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)
93 return -1;
95 if (argc < 2) {
96 printf("usage: TestURL url [count]\n");
97 return -1;
100 int count = 1000;
101 if (argc == 3)
102 count = atoi(argv[2]);
103 else
104 printf("using a default count of %d\n", count);
106 nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
107 if (!url) {
108 printf("failed to instantiate component: %s\n", NS_STANDARDURL_CONTRACTID);
109 return -1;
112 test_url = url;
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);
126 return 0;