tstRTUri.cpp revision 2eca2a2fb6e205bccf07ee440e48881cffb8959a
/* $Id$ */
/** @file
* IPRT Testcase - URI parsing and creation.
*/
/*
* Copyright (C) 2011 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 *gs_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 *gs_apcszSchemeResult[] =
{
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"urn",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
"foo"
};
static const char *gs_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 *gs_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 *gs_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 *gs_apcszFragmentResult[] =
{
"nose <>#%\"{}|^[]`",
NULL,
NULL,
NULL,
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
NULL,
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
NULL,
"nose <>#%\"{}|^[]`",
"nose <>#%\"{}|^[]`",
NULL,
NULL,
};
static const char *gs_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)
{
RTTestISubF("Uri creating %2u: Scheme: '%s', Authority: '%s', Path: '%s', Query: '%s', Fragment: '%s'", iCount, pszScheme, pszAuthority, pszPath, pszQuery, pszFragment);
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 */
/* Authority */
/* Path */
/* Query */
/* Fragment */
/* Creation */
tstCreate(i+1, gs_apcszCreateURIs[i][0], gs_apcszCreateURIs[i][1], gs_apcszCreateURIs[i][2], gs_apcszCreateURIs[i][3], gs_apcszCreateURIs[i][4], gs_apcszTestURIs[i]);
/* File Uri path */
tstFilePath(i+1, gs_apCreateFileURIs[i].pcszUri, gs_apCreateFileURIs[i].pcszPath, gs_apCreateFileURIs[i].uFormat);
/* File Uri creation */
for (size_t i = 0; i < 3; ++i)
return RTTestSummaryAndDestroy(hTest);
}