tstPath.cpp revision 25dd91c6de6e7cdd9d22f1d6e617d90919cd0cfb
/* $Id$ */
/** @file
* IPRT Testcase - Test various path functions.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
int main()
{
char szPath[RTPATH_MAX];
/*
* Init RT+Test.
*/
if (RT_FAILURE(rc))
return 1;
if (RT_FAILURE(rc))
return 1;
/*
* RTPathExecDir, RTPathUserHome and RTProcGetExecutableName.
*/
if (RT_SUCCESS(rc))
else
RTTestIFailed("RTProcGetExecutableName -> NULL");
if (RT_SUCCESS(rc))
/*
* RTPathAbsEx
*/
static const struct
{
const char *pcszInputBase;
const char *pcszInputPath;
int rc;
const char *pcszOutput;
}
{
#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
#else
{ NULL, "relative/../dir\\.\\.\\.\\file.txt", VINF_SUCCESS, "%p/dir\\.\\.\\.\\file.txt" }, /* linux-specific */
#endif
#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
{ "C:\\VirtualBox/Machines", "..\\VirtualBox.xml", VINF_SUCCESS, "C:\\VirtualBox\\VirtualBox.xml" },
{ "\\\\server\\share_as_base", "relative\\data", VINF_SUCCESS, "\\\\server\\share_as_base\\relative\\data" },
#else
#endif
};
for (unsigned i = 0; i < RT_ELEMENTS(s_aRTPathAbsExTests); ++ i)
{
{
RTTestIFailed("unexpected result code!\n"
" input base: '%s'\n"
" input path: '%s'\n"
" output: '%s'\n"
" rc: %Rrc\n"
" expected rc: %Rrc",
s_aRTPathAbsExTests[i].rc);
continue;
}
char szTmp[RTPATH_MAX];
char *pszExpected = NULL;
{
{
if (RT_FAILURE(rc))
break;
pszExpected = szTmp;
{
}
#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
{
}
#endif
}
else
{
pszExpected = szTmp;
}
{
RTTestIFailed("Unexpected result\n"
" input base: '%s'\n"
" input path: '%s'\n"
" output: '%s'\n"
" expected: '%s'",
}
}
}
/*
* RTPathStripFilename
*/
static const char *s_apszStripFilenameTests[] =
{
"/usr", "/",
"usr", ".",
#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
"c:/windows", "c:/",
"c:/", "c:/",
"D:", "D:",
"C:\\OS2\\DLLS", "C:\\OS2",
#endif
};
{
const char *pszInput = s_apszStripFilenameTests[i];
{
RTTestIFailed("Unexpected result\n"
" input: '%s'\n"
" output: '%s'\n"
"expected: '%s'",
}
}
/*
* RTPathAppend.
*/
static const char *s_apszAppendTests[] =
{
/* base append result */
"/", "", "/",
"", "/", "/",
"/", "/", "/",
"/x", "", "/x",
"/x", "/", "/x/",
"/", "x", "/x",
#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
"/", "\\", "/",
"\\", "/", "\\",
"\\\\srv\\shr", "/\\dir//", "\\\\srv\\shr\\dir//",
"C:", "autoexec.bat", "C:autoexec.bat",
"C:", "/autoexec.bat", "C:/autoexec.bat",
"C:", "\\autoexec.bat", "C:\\autoexec.bat",
"C:\\", "/autoexec.bat", "C:\\autoexec.bat",
"C:\\\\", "autoexec.bat", "C:\\autoexec.bat",
#endif
};
{
const char *pszInput = s_apszAppendTests[i];
if (RT_FAILURE(rc))
continue;
{
RTTestIFailed("Unexpected result\n"
" input: '%s'\n"
" append: '%s'\n"
" output: '%s'\n"
"expected: '%s'",
}
else
{
{
}
}
}
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}