2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
1999-06-14 08:45:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
A test file to check default URL parsing.
|
1999-11-03 09:33:03 +00:00
|
|
|
-Gagan Saksena 03/25/99
|
1999-06-14 08:45:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-10-21 20:57:17 +00:00
|
|
|
#include "TestCommon.h"
|
1999-06-14 08:45:27 +00:00
|
|
|
#include "plstr.h"
|
1999-06-15 00:34:37 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIIOService.h"
|
1999-06-14 08:45:27 +00:00
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2005-11-08 19:23:00 +00:00
|
|
|
#include "nsStringAPI.h"
|
2001-04-10 06:01:08 +00:00
|
|
|
#include "nsNetCID.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2005-11-08 19:23:00 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
#include "prprf.h"
|
1999-06-14 08:45:27 +00:00
|
|
|
|
|
|
|
// Define CIDs...
|
1999-06-15 00:34:37 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1999-11-03 09:33:03 +00:00
|
|
|
static NS_DEFINE_CID(kStdURLCID, NS_STANDARDURL_CID);
|
1999-06-14 08:45:27 +00:00
|
|
|
|
2000-04-15 01:47:17 +00:00
|
|
|
char* gFileIO = 0;
|
|
|
|
|
2001-11-16 02:09:13 +00:00
|
|
|
enum {
|
|
|
|
URL_FACTORY_DEFAULT,
|
|
|
|
URL_FACTORY_STDURL
|
|
|
|
};
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult writeoutto(const char* i_pURL, char** o_Result, int32_t urlFactory = URL_FACTORY_DEFAULT)
|
1999-06-14 08:45:27 +00:00
|
|
|
{
|
2000-04-15 01:47:17 +00:00
|
|
|
if (!o_Result || !i_pURL)
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-04-15 01:47:17 +00:00
|
|
|
*o_Result = 0;
|
|
|
|
nsCOMPtr<nsIURI> pURL;
|
|
|
|
nsresult result = NS_OK;
|
1999-06-15 00:34:37 +00:00
|
|
|
|
2001-11-16 02:09:13 +00:00
|
|
|
switch (urlFactory) {
|
|
|
|
case URL_FACTORY_STDURL: {
|
|
|
|
nsIURI* url;
|
2004-11-01 18:50:36 +00:00
|
|
|
result = CallCreateInstance(kStdURLCID, &url);
|
2001-11-16 02:09:13 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
{
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("CreateInstance failed\n");
|
2001-11-16 02:09:13 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
pURL = url;
|
2002-03-06 07:48:55 +00:00
|
|
|
pURL->SetSpec(nsDependentCString(i_pURL));
|
2001-11-16 02:09:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case URL_FACTORY_DEFAULT: {
|
|
|
|
nsCOMPtr<nsIIOService> pService =
|
|
|
|
do_GetService(kIOServiceCID, &result);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
{
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("Service failed!\n");
|
2001-11-16 02:09:13 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
result = pService->NewURI(nsDependentCString(i_pURL), nullptr, nullptr, getter_AddRefs(pURL));
|
1999-11-03 09:33:03 +00:00
|
|
|
}
|
2000-04-15 01:47:17 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:01:12 +00:00
|
|
|
nsCString output;
|
2000-04-15 01:47:17 +00:00
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURL> tURL = do_QueryInterface(pURL);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString temp;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port;
|
2002-03-06 07:48:55 +00:00
|
|
|
nsresult rv;
|
2000-04-15 01:47:17 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
#define RESULT() NS_SUCCEEDED(rv) ? temp.get() : ""
|
|
|
|
|
|
|
|
rv = tURL->GetScheme(temp);
|
|
|
|
output += RESULT();
|
2000-04-15 01:47:17 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetUsername(temp);
|
|
|
|
output += RESULT();
|
2001-09-12 08:01:12 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetPassword(temp);
|
|
|
|
output += RESULT();
|
2000-04-15 01:47:17 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetHost(temp);
|
|
|
|
output += RESULT();
|
2000-04-15 01:47:17 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetPort(&port);
|
2005-11-08 19:23:00 +00:00
|
|
|
char portbuffer[40];
|
|
|
|
PR_snprintf(portbuffer, sizeof(portbuffer), "%d", port);
|
|
|
|
output.Append(portbuffer);
|
2000-04-15 01:47:17 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetDirectory(temp);
|
|
|
|
output += RESULT();
|
2001-09-12 08:01:12 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetFileBaseName(temp);
|
|
|
|
output += RESULT();
|
2001-09-12 08:01:12 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetFileExtension(temp);
|
|
|
|
output += RESULT();
|
2001-09-12 08:01:12 +00:00
|
|
|
output += ',';
|
2011-08-22 14:51:52 +00:00
|
|
|
// removed with https://bugzilla.mozilla.org/show_bug.cgi?id=665706
|
|
|
|
// rv = tURL->GetParam(temp);
|
|
|
|
// output += RESULT();
|
2001-09-12 08:01:12 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetQuery(temp);
|
|
|
|
output += RESULT();
|
2000-04-15 01:47:17 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetRef(temp);
|
|
|
|
output += RESULT();
|
2001-09-12 08:01:12 +00:00
|
|
|
output += ',';
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = tURL->GetSpec(temp);
|
|
|
|
output += RESULT();
|
2001-09-29 08:28:41 +00:00
|
|
|
*o_Result = ToNewCString(output);
|
2001-09-12 08:01:12 +00:00
|
|
|
} else {
|
|
|
|
output = "Can not create URL";
|
2001-09-29 08:28:41 +00:00
|
|
|
*o_Result = ToNewCString(output);
|
2000-04-15 01:47:17 +00:00
|
|
|
}
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_OK;
|
2000-04-15 01:47:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult writeout(const char* i_pURL, int32_t urlFactory = URL_FACTORY_DEFAULT)
|
2000-04-15 01:47:17 +00:00
|
|
|
{
|
2001-09-12 08:01:12 +00:00
|
|
|
if (!i_pURL) return NS_ERROR_FAILURE;
|
2011-03-24 03:30:31 +00:00
|
|
|
nsCString temp;
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult rv = writeoutto(i_pURL, getter_Copies(temp), urlFactory);
|
2011-03-24 03:30:31 +00:00
|
|
|
printf("%s\n%s\n", i_pURL, temp.get());
|
2000-04-15 01:47:17 +00:00
|
|
|
return rv;
|
1999-06-14 08:45:27 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:01:12 +00:00
|
|
|
/* construct a url and print out its elements separated by commas and
|
|
|
|
the whole spec */
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult testURL(const char* i_pURL, int32_t urlFactory = URL_FACTORY_DEFAULT)
|
1999-06-14 08:45:27 +00:00
|
|
|
{
|
1999-07-22 21:14:51 +00:00
|
|
|
|
1999-11-03 09:33:03 +00:00
|
|
|
if (i_pURL)
|
2001-11-16 02:09:13 +00:00
|
|
|
return writeout(i_pURL, urlFactory);
|
1999-06-15 00:34:37 +00:00
|
|
|
|
2000-04-15 01:47:17 +00:00
|
|
|
if (!gFileIO)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-06-15 00:34:37 +00:00
|
|
|
|
2004-02-07 02:41:10 +00:00
|
|
|
FILE *testfile = fopen(gFileIO, "rt");
|
2000-04-15 01:47:17 +00:00
|
|
|
if (!testfile)
|
1999-11-03 09:33:03 +00:00
|
|
|
{
|
2004-02-07 02:41:10 +00:00
|
|
|
fprintf(stderr, "Cannot open testfile: %s\n", gFileIO);
|
2000-04-15 01:47:17 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-11-03 09:33:03 +00:00
|
|
|
|
2000-04-15 01:47:17 +00:00
|
|
|
char temp[512];
|
|
|
|
int count=0;
|
|
|
|
int failed=0;
|
2011-03-24 03:30:31 +00:00
|
|
|
nsCString prevResult;
|
|
|
|
nsCString tempurl;
|
1999-11-03 09:33:03 +00:00
|
|
|
|
2004-02-07 02:41:10 +00:00
|
|
|
while (fgets(temp,512,testfile))
|
1999-11-03 09:33:03 +00:00
|
|
|
{
|
2002-11-17 05:16:49 +00:00
|
|
|
if (*temp == '#' || !*temp)
|
2000-04-15 01:47:17 +00:00
|
|
|
continue;
|
|
|
|
|
2001-09-12 08:01:12 +00:00
|
|
|
if (0 == count%3)
|
2000-04-15 01:47:17 +00:00
|
|
|
{
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("Testing: %s\n", temp);
|
2011-03-24 03:30:31 +00:00
|
|
|
writeoutto(temp, getter_Copies(prevResult), urlFactory);
|
2000-04-15 01:47:17 +00:00
|
|
|
}
|
2001-09-12 08:01:12 +00:00
|
|
|
else if (1 == count%3) {
|
2011-03-24 03:30:31 +00:00
|
|
|
tempurl.Assign(temp);
|
2001-09-12 08:01:12 +00:00
|
|
|
} else {
|
2011-03-24 03:30:31 +00:00
|
|
|
if (prevResult.IsEmpty())
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("no results to compare to!\n");
|
2000-04-15 01:47:17 +00:00
|
|
|
else
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t res;
|
2011-03-24 03:30:31 +00:00
|
|
|
printf("Result: %s\n", prevResult.get());
|
2001-11-16 02:09:13 +00:00
|
|
|
if (urlFactory != URL_FACTORY_DEFAULT) {
|
2011-03-24 03:30:31 +00:00
|
|
|
printf("Expected: %s\n", tempurl.get());
|
|
|
|
res = PL_strcmp(tempurl.get(), prevResult.get());
|
2001-09-12 08:01:12 +00:00
|
|
|
} else {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("Expected: %s\n", temp);
|
2011-03-24 03:30:31 +00:00
|
|
|
res = PL_strcmp(temp, prevResult.get());
|
2001-09-12 08:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (res == 0)
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("\tPASSED\n\n");
|
2000-04-15 01:47:17 +00:00
|
|
|
else
|
|
|
|
{
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("\tFAILED\n\n");
|
2000-04-15 01:47:17 +00:00
|
|
|
failed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count++;
|
2001-09-12 08:01:12 +00:00
|
|
|
}
|
|
|
|
if (failed>0) {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("%d tests FAILED out of %d\n", failed, count/3);
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("All %d tests PASSED.\n", count/3);
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-15 00:34:37 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:01:12 +00:00
|
|
|
nsresult makeAbsTest(const char* i_BaseURI, const char* relativePortion,
|
|
|
|
const char* expectedResult)
|
1999-07-22 21:14:51 +00:00
|
|
|
{
|
|
|
|
if (!i_BaseURI)
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-07-04 14:29:25 +00:00
|
|
|
|
1999-11-18 06:19:01 +00:00
|
|
|
// build up the base URL
|
2004-11-01 18:50:36 +00:00
|
|
|
nsresult status;
|
|
|
|
nsCOMPtr<nsIURI> baseURL = do_CreateInstance(kStdURLCID, &status);
|
1999-11-03 09:33:03 +00:00
|
|
|
if (NS_FAILED(status))
|
|
|
|
{
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("CreateInstance failed\n");
|
1999-11-03 09:33:03 +00:00
|
|
|
return status;
|
|
|
|
}
|
2002-03-06 07:48:55 +00:00
|
|
|
status = baseURL->SetSpec(nsDependentCString(i_BaseURI));
|
1999-07-22 21:14:51 +00:00
|
|
|
if (NS_FAILED(status)) return status;
|
|
|
|
|
1999-11-18 06:19:01 +00:00
|
|
|
|
|
|
|
// get the new spec
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString newURL;
|
2002-03-06 07:48:55 +00:00
|
|
|
status = baseURL->Resolve(nsDependentCString(relativePortion), newURL);
|
1999-11-18 06:19:01 +00:00
|
|
|
if (NS_FAILED(status)) return status;
|
1999-07-22 21:14:51 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString temp;
|
2002-03-06 07:48:55 +00:00
|
|
|
baseURL->GetSpec(temp);
|
1999-07-22 21:14:51 +00:00
|
|
|
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("Analyzing %s\n", temp.get());
|
|
|
|
printf("With %s\n", relativePortion);
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("Got %s\n", newURL.get());
|
2001-09-12 08:01:12 +00:00
|
|
|
if (expectedResult) {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("Expect %s\n", expectedResult);
|
2002-03-06 07:48:55 +00:00
|
|
|
int res = PL_strcmp(newURL.get(), expectedResult);
|
2001-09-12 08:01:12 +00:00
|
|
|
if (res == 0) {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("\tPASSED\n\n");
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
} else {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("\tFAILED\n\n");
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-07-22 21:14:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult doMakeAbsTest(const char* i_URL = 0, const char* i_relativePortion=0)
|
1999-07-22 21:14:51 +00:00
|
|
|
{
|
|
|
|
if (i_URL && i_relativePortion)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return makeAbsTest(i_URL, i_relativePortion, nullptr);
|
1999-07-22 21:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run standard tests. These tests are based on the ones described in
|
2001-09-12 08:01:12 +00:00
|
|
|
// rfc2396 with the exception of the handling of ?y which is wrong as
|
|
|
|
// notified by on of the RFC authors.
|
|
|
|
|
|
|
|
/* Section C.1. Normal Examples
|
1999-07-22 21:14:51 +00:00
|
|
|
|
|
|
|
g:h = <URL:g:h>
|
|
|
|
g = <URL:http://a/b/c/g>
|
|
|
|
./g = <URL:http://a/b/c/g>
|
|
|
|
g/ = <URL:http://a/b/c/g/>
|
|
|
|
/g = <URL:http://a/g>
|
|
|
|
//g = <URL:http://g>
|
|
|
|
?y = <URL:http://a/b/c/d;p?y>
|
|
|
|
g?y = <URL:http://a/b/c/g?y>
|
|
|
|
g?y/./x = <URL:http://a/b/c/g?y/./x>
|
|
|
|
#s = <URL:http://a/b/c/d;p?q#s>
|
|
|
|
g#s = <URL:http://a/b/c/g#s>
|
|
|
|
g#s/./x = <URL:http://a/b/c/g#s/./x>
|
|
|
|
g?y#s = <URL:http://a/b/c/g?y#s>
|
2001-09-12 08:01:12 +00:00
|
|
|
;x = <URL:http://a/b/c/;x>
|
1999-07-22 21:14:51 +00:00
|
|
|
g;x = <URL:http://a/b/c/g;x>
|
|
|
|
g;x?y#s = <URL:http://a/b/c/g;x?y#s>
|
|
|
|
. = <URL:http://a/b/c/>
|
|
|
|
./ = <URL:http://a/b/c/>
|
|
|
|
.. = <URL:http://a/b/>
|
|
|
|
../ = <URL:http://a/b/>
|
|
|
|
../g = <URL:http://a/b/g>
|
|
|
|
../.. = <URL:http://a/>
|
|
|
|
../../ = <URL:http://a/>
|
|
|
|
../../g = <URL:http://a/g>
|
|
|
|
*/
|
|
|
|
|
1999-09-21 22:27:27 +00:00
|
|
|
struct test {
|
2001-09-12 08:01:12 +00:00
|
|
|
const char* baseURL;
|
1999-09-21 22:27:27 +00:00
|
|
|
const char* relativeURL;
|
|
|
|
const char* expectedResult;
|
1999-07-22 21:14:51 +00:00
|
|
|
};
|
|
|
|
|
1999-09-21 22:27:27 +00:00
|
|
|
test tests[] = {
|
2001-09-12 08:01:12 +00:00
|
|
|
// Tests from rfc2396, section C.1 with the exception of the
|
|
|
|
// handling of ?y
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g:h", "g:h" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g", "http://a/b/c/g" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "./g", "http://a/b/c/g" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/", "http://a/b/c/g/" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "/g", "http://a/g" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "//g", "http://g" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/./x" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/./x" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", ";x", "http://a/b/c/;x" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", ".", "http://a/b/c/" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "./", "http://a/b/c/" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "..", "http://a/b/" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "../", "http://a/b/" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "../g", "http://a/b/g" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "../..", "http://a/" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "../../", "http://a/" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "../../g", "http://a/g" },
|
1999-09-21 22:27:27 +00:00
|
|
|
|
|
|
|
// Our additional tests...
|
2001-09-12 08:01:12 +00:00
|
|
|
{ "http://a/b/c/d;p?q#f", "#my::anchor", "http://a/b/c/d;p?q#my::anchor" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "get?baseRef=viewcert.jpg", "http://a/b/c/get?baseRef=viewcert.jpg" },
|
1999-09-21 22:27:27 +00:00
|
|
|
|
|
|
|
// Make sure relative query's work right even if the query
|
|
|
|
// string contains absolute urls or other junk.
|
2001-09-12 08:01:12 +00:00
|
|
|
{ "http://a/b/c/d;p?q#f", "?http://foo", "http://a/b/c/d;p?http://foo" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g?http://foo", "http://a/b/c/g?http://foo" },
|
|
|
|
{"http://a/b/c/d;p?q#f", "g/h?http://foo", "http://a/b/c/g/h?http://foo" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/h/../H?http://foo","http://a/b/c/g/H?http://foo" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/h/../H?http://foo?baz", "http://a/b/c/g/H?http://foo?baz" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/h/../H?http://foo;baz", "http://a/b/c/g/H?http://foo;baz" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/h/../H?http://foo#bar", "http://a/b/c/g/H?http://foo#bar" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/h/../H;baz?http://foo", "http://a/b/c/g/H;baz?http://foo" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/h/../H;baz?http://foo#bar", "http://a/b/c/g/H;baz?http://foo#bar" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "g/h/../H;baz?C:\\temp", "http://a/b/c/g/H;baz?C:\\temp" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q" },
|
|
|
|
{ "http://a/b/c/d;p?q#f", "#", "http://a/b/c/d;p?q#" },
|
|
|
|
{ "http://a/b/c;p/d;p?q#f", "../g;p" , "http://a/b/g;p" },
|
|
|
|
|
1999-07-22 21:14:51 +00:00
|
|
|
};
|
|
|
|
|
1999-09-21 22:27:27 +00:00
|
|
|
const int numTests = sizeof(tests) / sizeof(tests[0]);
|
2001-09-12 08:01:12 +00:00
|
|
|
int failed = 0;
|
|
|
|
nsresult rv;
|
1999-09-21 22:27:27 +00:00
|
|
|
for (int i = 0 ; i<numTests ; ++i)
|
1999-07-22 21:14:51 +00:00
|
|
|
{
|
2001-09-12 08:01:12 +00:00
|
|
|
rv = makeAbsTest(tests[i].baseURL, tests[i].relativeURL,
|
|
|
|
tests[i].expectedResult);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
failed++;
|
|
|
|
}
|
|
|
|
if (failed>0) {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("%d tests FAILED out of %d\n", failed, numTests);
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("All %d tests PASSED.\n", numTests);
|
2001-09-12 08:01:12 +00:00
|
|
|
return NS_OK;
|
1999-07-22 21:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void printusage(void)
|
|
|
|
{
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("urltest [-std] [-file <filename>] <URL> "
|
|
|
|
" [-abs <relative>]\n\n"
|
|
|
|
"\t-std : Generate results using nsStdURL.\n"
|
|
|
|
"\t-file : Read URLs from file.\n"
|
|
|
|
"\t-abs : Make an absolute URL from the base (<URL>) and the\n"
|
|
|
|
"\t\trelative path specified. If -abs is given without\n"
|
|
|
|
"\t\ta base URI standard RFC 2396 relative URL tests\n"
|
|
|
|
"\t\tare performed. Implies -std.\n"
|
|
|
|
"\t<URL> : The string representing the URL.\n");
|
1999-07-22 21:14:51 +00:00
|
|
|
}
|
|
|
|
|
1999-06-15 00:34:37 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2004-10-21 20:57:17 +00:00
|
|
|
if (test_common_init(&argc, &argv) != 0)
|
|
|
|
return -1;
|
|
|
|
|
1999-06-15 00:34:37 +00:00
|
|
|
if (argc < 2) {
|
1999-07-22 21:14:51 +00:00
|
|
|
printusage();
|
2012-08-07 17:17:27 +00:00
|
|
|
return 0;
|
1999-06-14 08:45:27 +00:00
|
|
|
}
|
2002-07-04 14:29:25 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
2002-07-04 14:29:25 +00:00
|
|
|
|
|
|
|
// end of all messages from register components...
|
2004-02-07 02:41:10 +00:00
|
|
|
printf("------------------\n\n");
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t urlFactory = URL_FACTORY_DEFAULT;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool bMakeAbs= false;
|
2002-07-04 14:29:25 +00:00
|
|
|
char* relativePath = 0;
|
|
|
|
char* url = 0;
|
|
|
|
for (int i=1; i<argc; i++) {
|
|
|
|
if (PL_strcasecmp(argv[i], "-std") == 0)
|
|
|
|
{
|
|
|
|
urlFactory = URL_FACTORY_STDURL;
|
|
|
|
if (i+1 >= argc)
|
|
|
|
{
|
|
|
|
printusage();
|
2012-08-07 17:17:27 +00:00
|
|
|
return 0;
|
2002-07-04 14:29:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (PL_strcasecmp(argv[i], "-abs") == 0)
|
2001-09-12 08:01:12 +00:00
|
|
|
{
|
2002-07-04 14:29:25 +00:00
|
|
|
if (!gFileIO)
|
|
|
|
{
|
|
|
|
relativePath = argv[i+1];
|
|
|
|
i++;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
bMakeAbs = true;
|
2001-09-12 08:01:12 +00:00
|
|
|
}
|
2002-07-04 14:29:25 +00:00
|
|
|
else if (PL_strcasecmp(argv[i], "-file") == 0)
|
2000-04-15 01:47:17 +00:00
|
|
|
{
|
2002-07-04 14:29:25 +00:00
|
|
|
if (i+1 >= argc)
|
|
|
|
{
|
|
|
|
printusage();
|
2012-08-07 17:17:27 +00:00
|
|
|
return 0;
|
2002-07-04 14:29:25 +00:00
|
|
|
}
|
|
|
|
gFileIO = argv[i+1];
|
2000-04-15 01:47:17 +00:00
|
|
|
i++;
|
|
|
|
}
|
2002-07-04 14:29:25 +00:00
|
|
|
else
|
1999-07-22 21:14:51 +00:00
|
|
|
{
|
2002-07-04 14:29:25 +00:00
|
|
|
url = argv[i];
|
1999-07-22 21:14:51 +00:00
|
|
|
}
|
2002-07-04 14:29:25 +00:00
|
|
|
}
|
|
|
|
PRTime startTime = PR_Now();
|
|
|
|
if (bMakeAbs)
|
|
|
|
{
|
2012-08-07 17:17:27 +00:00
|
|
|
if (url && relativePath) {
|
|
|
|
doMakeAbsTest(url, relativePath);
|
|
|
|
} else {
|
|
|
|
doMakeAbsTest();
|
|
|
|
}
|
1999-07-22 21:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-07 17:17:27 +00:00
|
|
|
if (gFileIO) {
|
|
|
|
testURL(0, urlFactory);
|
|
|
|
} else {
|
|
|
|
testURL(url, urlFactory);
|
|
|
|
}
|
1999-07-22 21:14:51 +00:00
|
|
|
}
|
2002-07-04 14:29:25 +00:00
|
|
|
if (gFileIO)
|
|
|
|
{
|
|
|
|
PRTime endTime = PR_Now();
|
2012-08-22 15:56:38 +00:00
|
|
|
printf("Elapsed time: %d micros.\n", (int32_t)
|
2002-07-04 14:29:25 +00:00
|
|
|
(endTime - startTime));
|
|
|
|
}
|
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
2012-08-07 17:17:27 +00:00
|
|
|
return NS_FAILED(NS_ShutdownXPCOM(nullptr)) ? 1 : 0;
|
1999-06-14 08:45:27 +00:00
|
|
|
}
|