mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Bug 1288301 - Convert TestStandardURL to gtest r=mcmanus
MozReview-Commit-ID: FscilBXGhI2 --HG-- rename : netwerk/test/TestStandardURL.cpp => netwerk/test/gtest/TestStandardURL.cpp
This commit is contained in:
parent
1e8ad08b0b
commit
59fdb38682
@ -1,127 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "TestCommon.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIURL.h"
|
||||
#include "prinrval.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
static nsIURL *test_url = 0;
|
||||
static nsCString test_param;
|
||||
|
||||
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()
|
||||
{
|
||||
nsAutoCString spec;
|
||||
test_url->GetSpec(spec);
|
||||
}
|
||||
|
||||
static void resolve_test()
|
||||
{
|
||||
nsAutoCString spec;
|
||||
test_url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), spec);
|
||||
}
|
||||
|
||||
static void set_scheme_test()
|
||||
{
|
||||
test_url->SetScheme(NS_LITERAL_CSTRING("foo"));
|
||||
}
|
||||
|
||||
static void get_scheme_test()
|
||||
{
|
||||
nsAutoCString scheme;
|
||||
test_url->GetScheme(scheme);
|
||||
}
|
||||
|
||||
static void host_test()
|
||||
{
|
||||
nsAutoCString host;
|
||||
test_url->GetHost(host);
|
||||
test_url->SetHost(NS_LITERAL_CSTRING("www.yahoo.com"));
|
||||
test_url->SetHost(host);
|
||||
}
|
||||
|
||||
static void set_path_test()
|
||||
{
|
||||
test_url->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you"));
|
||||
}
|
||||
|
||||
static void get_path_test()
|
||||
{
|
||||
nsAutoCString path;
|
||||
test_url->GetPath(path);
|
||||
}
|
||||
|
||||
static void query_test()
|
||||
{
|
||||
nsAutoCString query;
|
||||
test_url->GetQuery(query);
|
||||
test_url->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45"));
|
||||
test_url->SetQuery(query);
|
||||
}
|
||||
|
||||
static void ref_test()
|
||||
{
|
||||
nsAutoCString ref;
|
||||
test_url->GetRef(ref);
|
||||
test_url->SetRef(NS_LITERAL_CSTRING("#some-book-mark"));
|
||||
test_url->SetRef(ref);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
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;
|
||||
}
|
69
netwerk/test/gtest/TestStandardURL.cpp
Normal file
69
netwerk/test/gtest/TestStandardURL.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/MozGTestBench.h" // For MOZ_GTEST_BENCH
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsString.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
TEST(TestStandardURL, Simple) {
|
||||
nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
|
||||
ASSERT_TRUE(url);
|
||||
ASSERT_EQ(url->SetSpec(NS_LITERAL_CSTRING("http://example.com")), NS_OK);
|
||||
|
||||
nsAutoCString out;
|
||||
|
||||
ASSERT_EQ(url->GetSpec(out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("http://example.com/"));
|
||||
|
||||
ASSERT_EQ(url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("http://example.com/foo.html?q=45"));
|
||||
|
||||
ASSERT_EQ(url->SetScheme(NS_LITERAL_CSTRING("foo")), NS_OK);
|
||||
|
||||
ASSERT_EQ(url->GetScheme(out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("foo"));
|
||||
|
||||
ASSERT_EQ(url->GetHost(out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("example.com"));
|
||||
ASSERT_EQ(url->SetHost(NS_LITERAL_CSTRING("www.yahoo.com")), NS_OK);
|
||||
ASSERT_EQ(url->GetHost(out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("www.yahoo.com"));
|
||||
|
||||
ASSERT_EQ(url->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you")), NS_OK);
|
||||
ASSERT_EQ(url->GetPath(out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you"));
|
||||
|
||||
ASSERT_EQ(url->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45")), NS_OK);
|
||||
ASSERT_EQ(url->GetQuery(out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45"));
|
||||
|
||||
ASSERT_EQ(url->SetRef(NS_LITERAL_CSTRING("#some-book-mark")), NS_OK);
|
||||
ASSERT_EQ(url->GetRef(out), NS_OK);
|
||||
ASSERT_TRUE(out == NS_LITERAL_CSTRING("some-book-mark"));
|
||||
}
|
||||
|
||||
#define COUNT 10000
|
||||
|
||||
MOZ_GTEST_BENCH(TestStandardURL, Perf, [] {
|
||||
nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
|
||||
ASSERT_TRUE(url);
|
||||
nsAutoCString out;
|
||||
|
||||
for (int i = COUNT; i; --i) {
|
||||
url->SetSpec(NS_LITERAL_CSTRING("http://example.com"));
|
||||
url->GetSpec(out);
|
||||
url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), out);
|
||||
url->SetScheme(NS_LITERAL_CSTRING("foo"));
|
||||
url->GetScheme(out);
|
||||
url->SetHost(NS_LITERAL_CSTRING("www.yahoo.com"));
|
||||
url->GetHost(out);
|
||||
url->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you"));
|
||||
url->GetPath(out);
|
||||
url->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45"));
|
||||
url->GetQuery(out);
|
||||
url->SetRef(NS_LITERAL_CSTRING("#some-book-mark"));
|
||||
url->GetRef(out);
|
||||
}
|
||||
});
|
13
netwerk/test/gtest/moz.build
Normal file
13
netwerk/test/gtest/moz.build
Normal file
@ -0,0 +1,13 @@
|
||||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'TestStandardURL.cpp',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul-gtest'
|
@ -4,7 +4,7 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
TEST_DIRS += ['httpserver']
|
||||
TEST_DIRS += ['httpserver', 'gtest']
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += ['browser/browser.ini']
|
||||
MOCHITEST_MANIFESTS += ['mochitests/mochitest.ini']
|
||||
@ -24,7 +24,6 @@ GeckoSimplePrograms([
|
||||
'TestOpen',
|
||||
'TestProtocols',
|
||||
'TestServ',
|
||||
'TestStandardURL',
|
||||
'TestStreamLoader',
|
||||
'TestUpload',
|
||||
'TestURLParser',
|
||||
|
Loading…
Reference in New Issue
Block a user