1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/TestStandardURL.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 + 1.7 +#include "TestCommon.h" 1.8 +#include "nsCOMPtr.h" 1.9 +#include "nsIServiceManager.h" 1.10 +#include "nsNetCID.h" 1.11 +#include "nsIURL.h" 1.12 +#include "prinrval.h" 1.13 +#include "nsStringAPI.h" 1.14 +#include "nsComponentManagerUtils.h" 1.15 + 1.16 +static nsIURL *test_url = 0; 1.17 +static nsCString test_param; 1.18 + 1.19 +static void run_test(const char *testname, int count, void (* testfunc)()) 1.20 +{ 1.21 + PRIntervalTime start, end; 1.22 + start = PR_IntervalNow(); 1.23 + for (; count; --count) 1.24 + testfunc(); 1.25 + end = PR_IntervalNow(); 1.26 + printf("completed %s test in %u milliseconds\n", testname, 1.27 + PR_IntervalToMilliseconds(end - start)); 1.28 +} 1.29 + 1.30 +static void set_spec_test() 1.31 +{ 1.32 + test_url->SetSpec(test_param); 1.33 +} 1.34 + 1.35 +static void get_spec_test() 1.36 +{ 1.37 + nsAutoCString spec; 1.38 + test_url->GetSpec(spec); 1.39 +} 1.40 + 1.41 +static void resolve_test() 1.42 +{ 1.43 + nsAutoCString spec; 1.44 + test_url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), spec); 1.45 +} 1.46 + 1.47 +static void set_scheme_test() 1.48 +{ 1.49 + test_url->SetScheme(NS_LITERAL_CSTRING("foo")); 1.50 +} 1.51 + 1.52 +static void get_scheme_test() 1.53 +{ 1.54 + nsAutoCString scheme; 1.55 + test_url->GetScheme(scheme); 1.56 +} 1.57 + 1.58 +static void host_test() 1.59 +{ 1.60 + nsAutoCString host; 1.61 + test_url->GetHost(host); 1.62 + test_url->SetHost(NS_LITERAL_CSTRING("www.yahoo.com")); 1.63 + test_url->SetHost(host); 1.64 +} 1.65 + 1.66 +static void set_path_test() 1.67 +{ 1.68 + test_url->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you")); 1.69 +} 1.70 + 1.71 +static void get_path_test() 1.72 +{ 1.73 + nsAutoCString path; 1.74 + test_url->GetPath(path); 1.75 +} 1.76 + 1.77 +static void query_test() 1.78 +{ 1.79 + nsAutoCString query; 1.80 + test_url->GetQuery(query); 1.81 + test_url->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45")); 1.82 + test_url->SetQuery(query); 1.83 +} 1.84 + 1.85 +static void ref_test() 1.86 +{ 1.87 + nsAutoCString ref; 1.88 + test_url->GetRef(ref); 1.89 + test_url->SetRef(NS_LITERAL_CSTRING("#some-book-mark")); 1.90 + test_url->SetRef(ref); 1.91 +} 1.92 + 1.93 +int main(int argc, char **argv) 1.94 +{ 1.95 + if (test_common_init(&argc, &argv) != 0) 1.96 + return -1; 1.97 + 1.98 + if (argc < 2) { 1.99 + printf("usage: TestURL url [count]\n"); 1.100 + return -1; 1.101 + } 1.102 + 1.103 + int count = 1000; 1.104 + if (argc == 3) 1.105 + count = atoi(argv[2]); 1.106 + else 1.107 + printf("using a default count of %d\n", count); 1.108 + 1.109 + nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) ); 1.110 + if (!url) { 1.111 + printf("failed to instantiate component: %s\n", NS_STANDARDURL_CONTRACTID); 1.112 + return -1; 1.113 + } 1.114 + 1.115 + test_url = url; 1.116 + test_param = argv[1]; 1.117 + 1.118 + run_test("SetSpec", count, set_spec_test); 1.119 + run_test("GetSpec", count, get_spec_test); 1.120 + run_test("Resolve", count, resolve_test); 1.121 + run_test("SetScheme", count, set_scheme_test); 1.122 + run_test("GetScheme", count, get_scheme_test); 1.123 + run_test("[GS]etHost", count, host_test); 1.124 + run_test("SetPath", count, set_path_test); 1.125 + run_test("GetPath", count, get_path_test); 1.126 + run_test("[GS]etQuery", count, query_test); 1.127 + run_test("[GS]etRef", count, ref_test); 1.128 + 1.129 + return 0; 1.130 +}