2012-05-02 16:46:10 +04:00
|
|
|
/*============================================================================
|
|
|
|
KWSys - Kitware System Library
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "kwsysPrivate.h"
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# pragma warning (disable:4786)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include KWSYS_HEADER(SystemTools.hxx)
|
|
|
|
|
|
|
|
// Work-around CMake dependency scanning limitation. This must
|
|
|
|
// duplicate the above list of headers.
|
|
|
|
#if 0
|
|
|
|
# include "SystemTools.hxx.in"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Include with <> instead of "" to avoid getting any in-source copy
|
|
|
|
// left on disk.
|
|
|
|
#include <testSystemTools.h>
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
#include <iostream>
|
2015-09-28 16:29:33 +03:00
|
|
|
#include <sstream>
|
2012-05-02 16:46:10 +04:00
|
|
|
#include <string.h> /* strcmp */
|
2015-08-25 01:44:47 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
# include <io.h> /* _umask (MSVC) / umask (Borland) */
|
|
|
|
# ifdef _MSC_VER
|
|
|
|
# define umask _umask // Note this is still umask on Borland
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#include <sys/stat.h> /* umask (POSIX), _S_I* constants (Windows) */
|
|
|
|
// Visual C++ does not define mode_t (note that Borland does, however).
|
|
|
|
#if defined( _MSC_VER )
|
|
|
|
typedef unsigned short mode_t;
|
|
|
|
#endif
|
2012-05-02 16:46:10 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2013-01-31 17:21:49 +04:00
|
|
|
static const char* toUnixPaths[][2] =
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
|
|
|
{ "/usr/local/bin/passwd", "/usr/local/bin/passwd" },
|
|
|
|
{ "/usr/lo cal/bin/pa sswd", "/usr/lo cal/bin/pa sswd" },
|
|
|
|
{ "/usr/lo\\ cal/bin/pa\\ sswd", "/usr/lo\\ cal/bin/pa\\ sswd" },
|
|
|
|
{ "c:/usr/local/bin/passwd", "c:/usr/local/bin/passwd" },
|
|
|
|
{ "c:/usr/lo cal/bin/pa sswd", "c:/usr/lo cal/bin/pa sswd" },
|
|
|
|
{ "c:/usr/lo\\ cal/bin/pa\\ sswd", "c:/usr/lo\\ cal/bin/pa\\ sswd" },
|
|
|
|
{ "\\usr\\local\\bin\\passwd", "/usr/local/bin/passwd" },
|
|
|
|
{ "\\usr\\lo cal\\bin\\pa sswd", "/usr/lo cal/bin/pa sswd" },
|
|
|
|
{ "\\usr\\lo\\ cal\\bin\\pa\\ sswd", "/usr/lo\\ cal/bin/pa\\ sswd" },
|
|
|
|
{ "c:\\usr\\local\\bin\\passwd", "c:/usr/local/bin/passwd" },
|
|
|
|
{ "c:\\usr\\lo cal\\bin\\pa sswd", "c:/usr/lo cal/bin/pa sswd" },
|
|
|
|
{ "c:\\usr\\lo\\ cal\\bin\\pa\\ sswd", "c:/usr/lo\\ cal/bin/pa\\ sswd" },
|
|
|
|
{ "\\\\usr\\local\\bin\\passwd", "//usr/local/bin/passwd" },
|
|
|
|
{ "\\\\usr\\lo cal\\bin\\pa sswd", "//usr/lo cal/bin/pa sswd" },
|
|
|
|
{ "\\\\usr\\lo\\ cal\\bin\\pa\\ sswd", "//usr/lo\\ cal/bin/pa\\ sswd" },
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
static bool CheckConvertToUnixSlashes(std::string input,
|
|
|
|
std::string output)
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string result = input;
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::ConvertToUnixSlashes(result);
|
|
|
|
if ( result != output )
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-05-08 00:31:11 +04:00
|
|
|
<< "Problem with ConvertToUnixSlashes - input: " << input
|
|
|
|
<< " output: " << result << " expected: " << output
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2013-01-31 17:21:49 +04:00
|
|
|
static const char* checkEscapeChars[][4] =
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
|
|
|
{ "1 foo 2 bar 2", "12", "\\", "\\1 foo \\2 bar \\2"},
|
|
|
|
{ " {} ", "{}", "#", " #{#} "},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
static bool CheckEscapeChars(std::string input,
|
2013-01-31 17:21:49 +04:00
|
|
|
const char *chars_to_escape,
|
|
|
|
char escape_char,
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string output)
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string result = kwsys::SystemTools::EscapeChars(
|
2012-05-02 16:46:10 +04:00
|
|
|
input.c_str(), chars_to_escape, escape_char);
|
|
|
|
if (result != output)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-05-08 00:31:11 +04:00
|
|
|
<< "Problem with CheckEscapeChars - input: " << input
|
|
|
|
<< " output: " << result << " expected: " << output
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2013-01-31 17:21:49 +04:00
|
|
|
static bool CheckFileOperations()
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
|
|
|
bool res = true;
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testNonExistingFile(TEST_SYSTEMTOOLS_SOURCE_DIR
|
2015-08-03 20:14:14 +03:00
|
|
|
"/testSystemToolsNonExistingFile");
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testDotFile(TEST_SYSTEMTOOLS_SOURCE_DIR
|
2015-08-03 20:14:14 +03:00
|
|
|
"/.");
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testBinFile(TEST_SYSTEMTOOLS_SOURCE_DIR
|
2014-07-02 18:57:17 +04:00
|
|
|
"/testSystemTools.bin");
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testTxtFile(TEST_SYSTEMTOOLS_SOURCE_DIR
|
2014-07-02 18:57:17 +04:00
|
|
|
"/testSystemTools.cxx");
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testNewDir(TEST_SYSTEMTOOLS_BINARY_DIR
|
2014-07-02 18:57:17 +04:00
|
|
|
"/testSystemToolsNewDir");
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testNewFile(testNewDir + "/testNewFile.txt");
|
2014-07-02 18:57:17 +04:00
|
|
|
|
2015-08-03 20:14:14 +03:00
|
|
|
if (kwsys::SystemTools::DetectFileType(testNonExistingFile.c_str()) !=
|
|
|
|
kwsys::SystemTools::FileTypeUnknown)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-03 20:14:14 +03:00
|
|
|
<< "Problem with DetectFileType - failed to detect type of: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNonExistingFile << std::endl;
|
2015-08-03 20:14:14 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::DetectFileType(testDotFile.c_str()) !=
|
|
|
|
kwsys::SystemTools::FileTypeUnknown)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-03 20:14:14 +03:00
|
|
|
<< "Problem with DetectFileType - failed to detect type of: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testDotFile << std::endl;
|
2015-08-03 20:14:14 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2014-07-02 18:57:17 +04:00
|
|
|
if (kwsys::SystemTools::DetectFileType(testBinFile.c_str()) !=
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::FileTypeBinary)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with DetectFileType - failed to detect type of: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testBinFile << std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2014-07-02 18:57:17 +04:00
|
|
|
if (kwsys::SystemTools::DetectFileType(testTxtFile.c_str()) !=
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::FileTypeText)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with DetectFileType - failed to detect type of: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testTxtFile << std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
res = false;
|
|
|
|
}
|
2014-07-02 18:57:17 +04:00
|
|
|
|
2014-10-31 20:09:11 +03:00
|
|
|
if (kwsys::SystemTools::FileLength(testBinFile) != 766)
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with FileLength - incorrect length for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testBinFile << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2014-08-04 16:59:12 +04:00
|
|
|
if (!kwsys::SystemTools::MakeDirectory(testNewDir))
|
2014-07-02 18:57:17 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with MakeDirectory for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewDir << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::Touch(testNewFile.c_str(), true))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with Touch for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2015-08-25 01:44:47 +03:00
|
|
|
// Reset umask
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
// NOTE: Windows doesn't support toggling _S_IREAD.
|
|
|
|
mode_t fullMask = _S_IWRITE;
|
|
|
|
#else
|
|
|
|
// On a normal POSIX platform, we can toggle all permissions.
|
|
|
|
mode_t fullMask = S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
#endif
|
|
|
|
mode_t orig_umask = umask(fullMask);
|
|
|
|
|
|
|
|
// Test file permissions without umask
|
|
|
|
mode_t origPerm, thisPerm;
|
|
|
|
if (!kwsys::SystemTools::GetPermissions(testNewFile, origPerm))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with GetPermissions (1) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::SetPermissions(testNewFile, 0))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with SetPermissions (1) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with GetPermissions (2) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((thisPerm & fullMask) != 0)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "SetPermissions failed to set permissions (1) for: "
|
|
|
|
<< testNewFile << ": actual = " << thisPerm << "; expected = "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< 0 << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// While we're at it, check proper TestFileAccess functionality.
|
|
|
|
if (kwsys::SystemTools::TestFileAccess(testNewFile,
|
|
|
|
kwsys::TEST_FILE_WRITE))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "TestFileAccess incorrectly indicated that this is a writable file:"
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::TestFileAccess(testNewFile,
|
|
|
|
kwsys::TEST_FILE_OK))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "TestFileAccess incorrectly indicated that this file does not exist:"
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test restoring/setting full permissions.
|
|
|
|
if (!kwsys::SystemTools::SetPermissions(testNewFile, fullMask))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with SetPermissions (2) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with GetPermissions (3) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((thisPerm & fullMask) != fullMask)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "SetPermissions failed to set permissions (2) for: "
|
|
|
|
<< testNewFile << ": actual = " << thisPerm << "; expected = "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< fullMask << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test setting file permissions while honoring umask
|
|
|
|
if (!kwsys::SystemTools::SetPermissions(testNewFile, fullMask, true))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with SetPermissions (3) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with GetPermissions (4) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((thisPerm & fullMask) != 0)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "SetPermissions failed to honor umask for: "
|
|
|
|
<< testNewFile << ": actual = " << thisPerm << "; expected = "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< 0 << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore umask
|
|
|
|
umask(orig_umask);
|
|
|
|
|
|
|
|
// Restore file permissions
|
|
|
|
if (!kwsys::SystemTools::SetPermissions(testNewFile, origPerm))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2015-08-25 01:44:47 +03:00
|
|
|
<< "Problem with SetPermissions (4) for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the test file
|
2014-08-04 16:59:12 +04:00
|
|
|
if (!kwsys::SystemTools::RemoveFile(testNewFile))
|
2014-07-02 18:57:17 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with RemoveFile: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewFile << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string const testFileMissing(testNewDir + "/testMissingFile.txt");
|
2015-05-27 20:15:22 +03:00
|
|
|
if (!kwsys::SystemTools::RemoveFile(testFileMissing))
|
|
|
|
{
|
|
|
|
std::string const& msg = kwsys::SystemTools::GetLastSystemError();
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr <<
|
2015-05-27 20:15:22 +03:00
|
|
|
"RemoveFile(\"" << testFileMissing << "\") failed: " << msg << "\n";
|
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string const testFileMissingDir(testNewDir + "/missing/file.txt");
|
2015-05-27 20:15:22 +03:00
|
|
|
if (!kwsys::SystemTools::RemoveFile(testFileMissingDir))
|
|
|
|
{
|
|
|
|
std::string const& msg = kwsys::SystemTools::GetLastSystemError();
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr <<
|
2015-05-27 20:15:22 +03:00
|
|
|
"RemoveFile(\"" << testFileMissingDir << "\") failed: " << msg << "\n";
|
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2014-07-02 18:57:17 +04:00
|
|
|
kwsys::SystemTools::Touch(testNewFile.c_str(), true);
|
2014-08-04 16:59:12 +04:00
|
|
|
if (!kwsys::SystemTools::RemoveADirectory(testNewDir))
|
2014-07-02 18:57:17 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with RemoveADirectory for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewDir << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS
|
|
|
|
// Perform the same file and directory creation and deletion tests but
|
|
|
|
// with paths > 256 characters in length.
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testNewLongDir(
|
2014-07-02 18:57:17 +04:00
|
|
|
TEST_SYSTEMTOOLS_BINARY_DIR "/"
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"01234567890123");
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string testNewLongFile(testNewLongDir + "/"
|
2014-07-02 18:57:17 +04:00
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789"
|
|
|
|
"0123456789.txt");
|
|
|
|
|
2014-08-04 16:59:12 +04:00
|
|
|
if (!kwsys::SystemTools::MakeDirectory(testNewLongDir))
|
2014-07-02 18:57:17 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with MakeDirectory for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewLongDir << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::Touch(testNewLongFile.c_str(), true))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with Touch for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewLongFile << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
2014-08-04 16:59:12 +04:00
|
|
|
if (!kwsys::SystemTools::RemoveFile(testNewLongFile))
|
2014-07-02 18:57:17 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with RemoveFile: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewLongFile << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
kwsys::SystemTools::Touch(testNewLongFile.c_str(), true);
|
2014-08-04 16:59:12 +04:00
|
|
|
if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir))
|
2014-07-02 18:57:17 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with RemoveADirectory for: "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< testNewLongDir << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
2014-07-02 18:57:17 +04:00
|
|
|
#endif
|
2012-05-02 16:46:10 +04:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2013-01-31 17:21:49 +04:00
|
|
|
static bool CheckStringOperations()
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
|
|
|
bool res = true;
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string test = "mary had a little lamb.";
|
2012-05-02 16:46:10 +04:00
|
|
|
if (kwsys::SystemTools::CapitalizedWords(test) != "Mary Had A Little Lamb.")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with CapitalizedWords "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< '"' << test << '"' << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
test = "Mary Had A Little Lamb.";
|
2015-08-25 01:44:47 +03:00
|
|
|
if (kwsys::SystemTools::UnCapitalizedWords(test) !=
|
2012-05-02 16:46:10 +04:00
|
|
|
"mary had a little lamb.")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with UnCapitalizedWords "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< '"' << test << '"' << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
test = "MaryHadTheLittleLamb.";
|
2015-08-25 01:44:47 +03:00
|
|
|
if (kwsys::SystemTools::AddSpaceBetweenCapitalizedWords(test) !=
|
2012-05-02 16:46:10 +04:00
|
|
|
"Mary Had The Little Lamb.")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with AddSpaceBetweenCapitalizedWords "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< '"' << test << '"' << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 01:44:47 +03:00
|
|
|
char * cres =
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::AppendStrings("Mary Had A"," Little Lamb.");
|
|
|
|
if (strcmp(cres,"Mary Had A Little Lamb."))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with AppendStrings "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A\" \" Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
delete [] cres;
|
|
|
|
|
2015-08-25 01:44:47 +03:00
|
|
|
cres =
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::AppendStrings("Mary Had"," A ","Little Lamb.");
|
|
|
|
if (strcmp(cres,"Mary Had A Little Lamb."))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with AppendStrings "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had\" \" A \" \"Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
delete [] cres;
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::CountChar("Mary Had A Little Lamb.",'a') != 3)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with CountChar "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 01:44:47 +03:00
|
|
|
cres =
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.","aeiou");
|
|
|
|
if (strcmp(cres,"Mry Hd A Lttl Lmb."))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with RemoveChars "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
delete [] cres;
|
|
|
|
|
2015-08-25 01:44:47 +03:00
|
|
|
cres =
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb.");
|
|
|
|
if (strcmp(cres,"A"))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with RemoveCharsButUpperHex "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
delete [] cres;
|
|
|
|
|
|
|
|
char *cres2 = new char [strlen("Mary Had A Little Lamb.")+1];
|
|
|
|
strcpy(cres2,"Mary Had A Little Lamb.");
|
|
|
|
kwsys::SystemTools::ReplaceChars(cres2,"aeiou",'X');
|
|
|
|
if (strcmp(cres2,"MXry HXd A LXttlX LXmb."))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with ReplaceChars "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
delete [] cres2;
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
|
|
|
|
"Mary "))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with StringStartsWith "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!kwsys::SystemTools::StringEndsWith("Mary Had A Little Lamb.",
|
|
|
|
" Lamb."))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with StringEndsWith "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb.");
|
|
|
|
if (strcmp(cres,"Mary Had A Little Lamb."))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with DuplicateString "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
delete [] cres;
|
|
|
|
|
|
|
|
test = "Mary Had A Little Lamb.";
|
2015-08-25 01:44:47 +03:00
|
|
|
if (kwsys::SystemTools::CropString(test,13) !=
|
2012-05-02 16:46:10 +04:00
|
|
|
"Mary ...Lamb.")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with CropString "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
std::vector<std::string> lines;
|
2012-05-02 16:46:10 +04:00
|
|
|
kwsys::SystemTools::Split("Mary Had A Little Lamb.",lines,' ');
|
|
|
|
if (lines[0] != "Mary" || lines[1] != "Had" ||
|
|
|
|
lines[2] != "A" || lines[3] != "Little" || lines[4] != "Lamb.")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with Split "
|
2015-08-28 21:50:49 +03:00
|
|
|
<< "\"Mary Had A Little Lamb.\"" << std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath
|
|
|
|
("L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
|
|
|
|
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 18:57:17 +04:00
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath
|
|
|
|
("L:/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
|
|
|
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath
|
|
|
|
("\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
|
|
|
|
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath
|
|
|
|
("//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
|
|
|
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("//") !=
|
|
|
|
L"//")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"//\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\") !=
|
|
|
|
L"\\\\.\\")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"\\\\.\\\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X") !=
|
|
|
|
L"\\\\.\\X")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"\\\\.\\X\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:") !=
|
|
|
|
L"\\\\?\\X:")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"\\\\.\\X:\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:\\") !=
|
|
|
|
L"\\\\?\\X:\\")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"\\\\.\\X:\\\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("NUL") !=
|
|
|
|
L"\\\\.\\NUL")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "Problem with ConvertToWindowsExtendedPath "
|
|
|
|
<< "\"NUL\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2014-07-02 18:57:17 +04:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-05-02 16:46:10 +04:00
|
|
|
if (kwsys::SystemTools::ConvertToWindowsOutputPath
|
2015-08-25 01:44:47 +03:00
|
|
|
("L://Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
2012-05-02 16:46:10 +04:00
|
|
|
"\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with ConvertToWindowsOutputPath "
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "\"L://Local Mojo/Hex Power Pack/Iffy Voodoo\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
2015-08-25 01:44:47 +03:00
|
|
|
|
2012-05-02 16:46:10 +04:00
|
|
|
if (kwsys::SystemTools::ConvertToWindowsOutputPath
|
2015-08-25 01:44:47 +03:00
|
|
|
("//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
2012-05-02 16:46:10 +04:00
|
|
|
"\"\\\\grayson\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with ConvertToWindowsOutputPath "
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "\"//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (kwsys::SystemTools::ConvertToUnixOutputPath
|
2015-08-25 01:44:47 +03:00
|
|
|
("//Local Mojo/Hex Power Pack/Iffy Voodoo") !=
|
2012-05-02 16:46:10 +04:00
|
|
|
"//Local\\ Mojo/Hex\\ Power\\ Pack/Iffy\\ Voodoo")
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr
|
2012-05-02 16:46:10 +04:00
|
|
|
<< "Problem with ConvertToUnixOutputPath "
|
2014-07-02 18:57:17 +04:00
|
|
|
<< "\"//Local Mojo/Hex Power Pack/Iffy Voodoo\""
|
2015-08-28 21:50:49 +03:00
|
|
|
<< std::endl;
|
2015-08-25 01:44:47 +03:00
|
|
|
res = false;
|
2012-05-02 16:46:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2015-08-28 21:50:49 +03:00
|
|
|
static bool CheckPutEnv(const std::string& env, const char* name, const char* value)
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
|
|
|
if(!kwsys::SystemTools::PutEnv(env))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr << "PutEnv(\"" << env
|
|
|
|
<< "\") failed!" << std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const char* v = kwsys::SystemTools::GetEnv(name);
|
|
|
|
v = v? v : "(null)";
|
|
|
|
if(strcmp(v, value) != 0)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr << "GetEnv(\"" << name << "\") returned \""
|
|
|
|
<< v << "\", not \"" << value << "\"!" << std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-31 17:21:49 +04:00
|
|
|
static bool CheckUnPutEnv(const char* env, const char* name)
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
|
|
|
if(!kwsys::SystemTools::UnPutEnv(env))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr << "UnPutEnv(\"" << env << "\") failed!"
|
|
|
|
<< std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(const char* v = kwsys::SystemTools::GetEnv(name))
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr << "GetEnv(\"" << name << "\") returned \""
|
|
|
|
<< v << "\", not (null)!" << std::endl;
|
2012-05-02 16:46:10 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-31 17:21:49 +04:00
|
|
|
static bool CheckEnvironmentOperations()
|
2012-05-02 16:46:10 +04:00
|
|
|
{
|
|
|
|
bool res = true;
|
|
|
|
res &= CheckPutEnv("A=B", "A", "B");
|
|
|
|
res &= CheckPutEnv("B=C", "B", "C");
|
|
|
|
res &= CheckPutEnv("C=D", "C", "D");
|
|
|
|
res &= CheckPutEnv("D=E", "D", "E");
|
|
|
|
res &= CheckUnPutEnv("A", "A");
|
|
|
|
res &= CheckUnPutEnv("B=", "B");
|
|
|
|
res &= CheckUnPutEnv("C=D", "C");
|
|
|
|
/* Leave "D=E" in environment so a memory checker can test for leaks. */
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-09-09 07:24:08 +04:00
|
|
|
|
|
|
|
static bool CheckRelativePath(
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string& local,
|
|
|
|
const std::string& remote,
|
|
|
|
const std::string& expected)
|
2014-09-09 07:24:08 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string result = kwsys::SystemTools::RelativePath(local, remote);
|
2014-09-09 07:24:08 +04:00
|
|
|
if(expected != result)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr << "RelativePath(" << local << ", " << remote
|
|
|
|
<< ") yielded " << result << " instead of " << expected << std::endl;
|
2014-09-09 07:24:08 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CheckRelativePaths()
|
|
|
|
{
|
|
|
|
bool res = true;
|
|
|
|
res &= CheckRelativePath("/usr/share", "/bin/bash", "../../bin/bash");
|
|
|
|
res &= CheckRelativePath("/usr/./share/", "/bin/bash", "../../bin/bash");
|
|
|
|
res &= CheckRelativePath("/usr//share/", "/bin/bash", "../../bin/bash");
|
|
|
|
res &= CheckRelativePath("/usr/share/../bin/", "/bin/bash", "../../bin/bash");
|
|
|
|
res &= CheckRelativePath("/usr/share", "/usr/share//bin", "bin");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CheckCollapsePath(
|
2015-08-28 21:50:49 +03:00
|
|
|
const std::string& path,
|
|
|
|
const std::string& expected)
|
2014-09-09 07:24:08 +04:00
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string result = kwsys::SystemTools::CollapseFullPath(path);
|
2014-09-09 07:24:08 +04:00
|
|
|
if(expected != result)
|
|
|
|
{
|
2015-08-28 21:50:49 +03:00
|
|
|
std::cerr << "CollapseFullPath(" << path
|
|
|
|
<< ") yielded " << result << " instead of " << expected << std::endl;
|
2014-09-09 07:24:08 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CheckCollapsePath()
|
|
|
|
{
|
|
|
|
bool res = true;
|
|
|
|
res &= CheckCollapsePath("/usr/share/*", "/usr/share/*");
|
|
|
|
res &= CheckCollapsePath("C:/Windows/*", "C:/Windows/*");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-09-28 16:29:33 +03:00
|
|
|
static std::string StringVectorToString(const std::vector<std::string>& vec)
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "vector(";
|
|
|
|
for (std::vector<std::string>::const_iterator i = vec.begin();
|
|
|
|
i != vec.end(); ++i)
|
|
|
|
{
|
|
|
|
if (i != vec.begin())
|
|
|
|
{
|
|
|
|
ss << ", ";
|
|
|
|
}
|
|
|
|
ss << *i;
|
|
|
|
}
|
|
|
|
ss << ")";
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CheckGetPath()
|
|
|
|
{
|
|
|
|
const char* envName = "S";
|
|
|
|
#ifdef _WIN32
|
|
|
|
const char* envValue = "C:\\Somewhere\\something;D:\\Temp";
|
|
|
|
#else
|
|
|
|
const char* envValue = "/Somewhere/something:/tmp";
|
|
|
|
#endif
|
|
|
|
const char* registryPath = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MyApp; MyKey]";
|
|
|
|
|
|
|
|
std::vector<std::string> originalPathes;
|
|
|
|
originalPathes.push_back(registryPath);
|
|
|
|
|
|
|
|
std::vector<std::string> expectedPathes;
|
|
|
|
expectedPathes.push_back(registryPath);
|
|
|
|
#ifdef _WIN32
|
|
|
|
expectedPathes.push_back("C:/Somewhere/something");
|
|
|
|
expectedPathes.push_back("D:/Temp");
|
|
|
|
#else
|
|
|
|
expectedPathes.push_back("/Somewhere/something");
|
|
|
|
expectedPathes.push_back("/tmp");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool res = true;
|
|
|
|
res &= CheckPutEnv(std::string(envName) + "=" + envValue, envName, envValue);
|
|
|
|
|
|
|
|
std::vector<std::string> pathes = originalPathes;
|
|
|
|
kwsys::SystemTools::GetPath(pathes, envName);
|
|
|
|
|
|
|
|
if (pathes != expectedPathes)
|
|
|
|
{
|
|
|
|
std::cerr <<
|
|
|
|
"GetPath(" << StringVectorToString(originalPathes) <<
|
|
|
|
", " << envName << ") yielded " << StringVectorToString(pathes) <<
|
|
|
|
" instead of " << StringVectorToString(expectedPathes) <<
|
|
|
|
std::endl;
|
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
res &= CheckUnPutEnv(envName, envName);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-05-02 16:46:10 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
int testSystemTools(int, char*[])
|
|
|
|
{
|
|
|
|
bool res = true;
|
|
|
|
|
|
|
|
int cc;
|
|
|
|
for ( cc = 0; toUnixPaths[cc][0]; cc ++ )
|
|
|
|
{
|
|
|
|
res &= CheckConvertToUnixSlashes(toUnixPaths[cc][0], toUnixPaths[cc][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special check for ~
|
2015-08-28 21:50:49 +03:00
|
|
|
std::string output;
|
2012-05-02 16:46:10 +04:00
|
|
|
if(kwsys::SystemTools::GetEnv("HOME", output))
|
|
|
|
{
|
|
|
|
output += "/foo bar/lala";
|
|
|
|
res &= CheckConvertToUnixSlashes("~/foo bar/lala", output);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cc = 0; checkEscapeChars[cc][0]; cc ++ )
|
|
|
|
{
|
2015-08-25 01:44:47 +03:00
|
|
|
res &= CheckEscapeChars(checkEscapeChars[cc][0], checkEscapeChars[cc][1],
|
2012-05-02 16:46:10 +04:00
|
|
|
*checkEscapeChars[cc][2], checkEscapeChars[cc][3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
res &= CheckFileOperations();
|
|
|
|
|
|
|
|
res &= CheckStringOperations();
|
|
|
|
|
|
|
|
res &= CheckEnvironmentOperations();
|
|
|
|
|
2014-09-09 07:24:08 +04:00
|
|
|
res &= CheckRelativePaths();
|
|
|
|
|
|
|
|
res &= CheckCollapsePath();
|
|
|
|
|
2015-09-28 16:29:33 +03:00
|
|
|
res &= CheckGetPath();
|
|
|
|
|
2012-05-02 16:46:10 +04:00
|
|
|
return res ? 0 : 1;
|
|
|
|
}
|