tstRTUri.cpp revision e384ca7cf2c9e630ac01d430f02cab748307da21
/* $Id$ */
/** @file
* IPRT Testcase - URI parsing and creation.
*/
/*
* Copyright (C) 2011-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Test data *
*******************************************************************************/
static const char *g_apcszTestURIs[] =
{
"foo://tt:tt@example.com:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"foo://tt:tt@example.com:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret",
"foo://tt:tt@example.com:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
"foo:tt@example.com",
"foo:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"foo:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"urn:example:animal:ferret:nose",
"foo:?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"foo:#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"foo://tt:tt@example.com:8042/?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"foo://tt:tt@example.com:8042/",
"foo://tt:tt@example.com:8042?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"foo://tt:tt@example.com:8042#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
"foo://tt:tt@example.com:8042",
"foo:///",
"foo://"
};
static const char *g_apcszSchemeResult[] =
{
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"urn",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo"
};
static const char *g_apcszAuthorityResult[] =
{
"tt:tt@example.com:8042",
"tt:tt@example.com:8042",
"tt:tt@example.com:8042",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
"tt:tt@example.com:8042",
"tt:tt@example.com:8042",
"tt:tt@example.com:8042",
"tt:tt@example.com:8042",
"tt:tt@example.com:8042",
NULL,
};
static const char *g_apcszPathResult[] =
{
"/over/ <>#%\"{}|^[]`/there",
"/over/ <>#%\"{}|^[]`/there",
"/over/ <>#%\"{}|^[]`/there",
"tt@example.com",
"/over/ <>#%\"{}|^[]`/there",
"/over/ <>#%\"{}|^[]`/there",
"example:animal:ferret:nose",
NULL,
NULL,
"/",
"/",
NULL,
NULL,
NULL,
"/",
};
static const char *g_apcszQueryResult[] =
{
"name= <>#%\"{}|^[]`ferret",
"name= <>#%\"{}|^[]`ferret",
NULL,
NULL,
"name= <>#%\"{}|^[]`ferret",
NULL,
NULL,
"name= <>#%\"{}|^[]`ferret",
NULL,
"name= <>#%\"{}|^[]`ferret",
NULL,
"name= <>#%\"{}|^[]`ferret",
NULL,
NULL,
NULL,
};
static const char *g_apcszFragmentResult[] =
{
"nose <>#%\"{}|^[]`",
NULL,
NULL,
NULL,
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
NULL,
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
NULL,
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
NULL,
NULL,
};
static const char *g_apcszCreateURIs[][5] =
{
{ "foo", "tt:tt@example.com:8042", "/over/ <>#%\"{}|^[]`/there", "name= <>#%\"{}|^[]`ferret", "nose <>#%\"{}|^[]`" },
{ "foo", "tt:tt@example.com:8042", "/over/ <>#%\"{}|^[]`/there", "name= <>#%\"{}|^[]`ferret", NULL },
{ "foo", "tt:tt@example.com:8042", "/", "name= <>#%\"{}|^[]`ferret", "nose <>#%\"{}|^[]`" },
};
struct URIFILETEST
{
const char *pcszPath;
const char *pcszUri;
}
{
{ "C:\\over\\ <>#%\"{}|^[]`\\there", "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere", URI_FILE_FORMAT_WIN },
{ "/over/ <>#%\"{}|^[]`/there", "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there", URI_FILE_FORMAT_UNIX },
{ "/C:/over/ <>#%\"{}|^[]`/there", "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere", URI_FILE_FORMAT_UNIX },
{ "over\\ <>#%\"{}|^[]`\\there", "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there", URI_FILE_FORMAT_WIN }
};
/**
* Basic API checks.
*/
{
if (pszTest)
{
}
else
if (pszResult)
}
{
if (pszTest)
{
}
else
if (pszResult)
}
{
if (pszTest)
{
}
else
if (pszResult)
}
{
if (pszTest)
{
}
else
if (pszResult)
}
{
if (pszTest)
{
}
else
if (pszResult)
}
static void tstCreate(size_t iCount, const char *pszScheme, const char *pszAuthority, const char *pszPath, const char *pszQuery, const char *pszFragment, const char *pszTest)
{
if (pszTest)
{
}
else
if (pszResult)
return;
}
{
if (pszTest)
{
}
else
if (pszResult)
return;
}
{
if (pszTest)
{
}
else
if (pszResult)
return;
}
int main()
{
if (rc)
return rc;
/* Scheme */
RTTestISubF("RTUriScheme");
/* Authority */
RTTestISubF("RTUriAuthority");
/* Path */
RTTestISubF("RTUriPath");
/* Query */
RTTestISubF("RTUriQuery");
/* Fragment */
RTTestISubF("RTUriFragment");
/* Creation */
RTTestISubF("RTUriCreate");
/* File Uri path */
RTTestISubF("RTUriFilePath");
tstFilePath(i+1, g_apCreateFileURIs[i].pcszUri, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].uFormat);
/* File Uri creation */
RTTestISubF("RTUriFileCreate");
for (size_t i = 0; i < 3; ++i)
return RTTestSummaryAndDestroy(hTest);
}