2005-11-08 22:23:00 +03:00
|
|
|
#include <stdio.h>
|
2001-11-16 05:09:13 +03:00
|
|
|
#include <stdlib.h>
|
2005-11-08 22:23:00 +03:00
|
|
|
|
|
|
|
#include "TestCommon.h"
|
2001-11-16 05:09:13 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "prinrval.h"
|
2005-11-08 22:23:00 +03:00
|
|
|
#include "nsStringAPI.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
static nsIURL *test_url = 0;
|
2002-03-06 10:48:55 +03:00
|
|
|
static nsCString test_param;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
static void run_test(const char *testname, int count, void (* testfunc)())
|
|
|
|
{
|
|
|
|
PRIntervalTime start, end;
|
|
|
|
start = PR_IntervalNow();
|
|
|
|
for (; count; --count)
|
|
|
|
testfunc();
|
|
|
|
end = PR_IntervalNow();
|
|
|
|
printf("completed %s test in %u milliseconds\n", testname,
|
|
|
|
PR_IntervalToMilliseconds(end - start));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_spec_test()
|
|
|
|
{
|
|
|
|
test_url->SetSpec(test_param);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_spec_test()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->GetSpec(spec);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void resolve_test()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), spec);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_scheme_test()
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->SetScheme(NS_LITERAL_CSTRING("foo"));
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_scheme_test()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->GetScheme(scheme);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void host_test()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString host;
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->GetHost(host);
|
|
|
|
test_url->SetHost(NS_LITERAL_CSTRING("www.yahoo.com"));
|
2001-11-16 05:09:13 +03:00
|
|
|
test_url->SetHost(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_path_test()
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you"));
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_path_test()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->GetPath(path);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void query_test()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString query;
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->GetQuery(query);
|
|
|
|
test_url->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45"));
|
2001-11-16 05:09:13 +03:00
|
|
|
test_url->SetQuery(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ref_test()
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString ref;
|
2002-03-06 10:48:55 +03:00
|
|
|
test_url->GetRef(ref);
|
|
|
|
test_url->SetRef(NS_LITERAL_CSTRING("#some-book-mark"));
|
2001-11-16 05:09:13 +03:00
|
|
|
test_url->SetRef(ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2004-10-22 00:57:17 +04:00
|
|
|
if (test_common_init(&argc, &argv) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: TestURL url [count]\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 1000;
|
|
|
|
if (argc == 3)
|
|
|
|
count = atoi(argv[2]);
|
|
|
|
else
|
|
|
|
printf("using a default count of %d\n", count);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
|
|
|
|
if (!url) {
|
|
|
|
printf("failed to instantiate component: %s\n", NS_STANDARDURL_CONTRACTID);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_url = url;
|
|
|
|
test_param = argv[1];
|
|
|
|
|
|
|
|
run_test("SetSpec", count, set_spec_test);
|
|
|
|
run_test("GetSpec", count, get_spec_test);
|
|
|
|
run_test("Resolve", count, resolve_test);
|
|
|
|
run_test("SetScheme", count, set_scheme_test);
|
|
|
|
run_test("GetScheme", count, get_scheme_test);
|
|
|
|
run_test("[GS]etHost", count, host_test);
|
|
|
|
run_test("SetPath", count, set_path_test);
|
|
|
|
run_test("GetPath", count, get_path_test);
|
|
|
|
run_test("[GS]etQuery", count, query_test);
|
|
|
|
run_test("[GS]etRef", count, ref_test);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|