tstPath.cpp revision 0b4c8f4579460fb6f03354d6c3b1f9f904ba3cf3
/* $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>
#if defined (RT_OS_WINDOWS)
# include <direct.h> // for getcwd
#else
# include <unistd.h> // for getcwd
#endif
#include <errno.h> // for getcwd
do { \
if (RT_FAILURE(rc)) \
{ \
cErrors++; \
} \
} while (0)
int main()
{
/*
* Init RT.
*/
int rc;
int cErrors = 0;
if (RT_FAILURE(rc))
return 1;
/*
* RTPathProgram, RTPathUserHome and RTProcGetExecutableName.
*/
char szPath[RTPATH_MAX];
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
else
{
RTPrintf("tstPath: FAILED - RTProcGetExecutableName\n");
cErrors++;
}
/*
* RTPathAbsEx
*/
RTPrintf("tstPath: TESTING RTPathAbsEx()\n");
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(aRTPathAbsExTests); ++ i)
{
{
RTPrintf("tstPath: RTPathAbsEx unexpected result code!\n"
" input base: '%s'\n"
" input path: '%s'\n"
" output: '%s'\n"
" rc: %Rrc\n"
" expected rc: %Rrc\n",
aRTPathAbsExTests[i].rc);
cErrors++;
continue;
}
char szTmp[RTPATH_MAX];
char *pszExpected = NULL;
{
{
{
cErrors++;
break;
}
pszExpected = szTmp;
{
}
#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
{
}
#endif
}
else
{
pszExpected = szTmp;
}
{
RTPrintf("tstPath: RTPathAbsEx failed!\n"
" input base: '%s'\n"
" input path: '%s'\n"
" output: '%s'\n"
" expected: '%s'\n",
cErrors++;
}
}
}
/*
* RTPathStripFilename
*/
RTPrintf("tstPath: RTPathStripFilename...\n");
static const char *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 = apszStripFilenameTests[i];
char szPath[RTPATH_MAX];
{
RTPrintf("tstPath: RTPathStripFilename failed!\n"
" input: '%s'\n"
" output: '%s'\n"
"expected: '%s'\n",
cErrors++;
}
}
/*
* Summary.
*/
if (!cErrors)
RTPrintf("tstPath: SUCCESS\n");
else
return !!cErrors;
}