Remove CppUnit boilerplate from wxFileName test
This is similar to the grand parent commit for the file functions. No real changes.
This commit is contained in:
@@ -114,84 +114,17 @@ static struct TestFileNameInfo
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// test class
|
// tests
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class FileNameTestCase : public CppUnit::TestCase
|
TEST_CASE("wxFileName::Construction", "[filename]")
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileNameTestCase() { }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CPPUNIT_TEST_SUITE( FileNameTestCase );
|
|
||||||
CPPUNIT_TEST( TestConstruction );
|
|
||||||
CPPUNIT_TEST( TestComparison );
|
|
||||||
CPPUNIT_TEST( TestSplit );
|
|
||||||
CPPUNIT_TEST( TestSetPath );
|
|
||||||
CPPUNIT_TEST( TestStrip );
|
|
||||||
CPPUNIT_TEST( TestNormalize );
|
|
||||||
CPPUNIT_TEST( TestRelative );
|
|
||||||
CPPUNIT_TEST( TestReplace );
|
|
||||||
CPPUNIT_TEST( TestGetHumanReadable );
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
CPPUNIT_TEST( TestShortLongPath );
|
|
||||||
#endif // __WINDOWS__
|
|
||||||
CPPUNIT_TEST( TestUNC );
|
|
||||||
CPPUNIT_TEST( TestVolumeUniqueName );
|
|
||||||
CPPUNIT_TEST( TestCreateTempFileName );
|
|
||||||
CPPUNIT_TEST( TestGetTimes );
|
|
||||||
CPPUNIT_TEST( TestSetTimes );
|
|
||||||
CPPUNIT_TEST( TestExists );
|
|
||||||
CPPUNIT_TEST( TestIsSame );
|
|
||||||
#if defined(__UNIX__)
|
|
||||||
CPPUNIT_TEST( TestSymlinks );
|
|
||||||
#endif // __UNIX__
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
CPPUNIT_TEST( TestShortcuts );
|
|
||||||
#endif // __WINDOWS__
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void TestConstruction();
|
|
||||||
void TestComparison();
|
|
||||||
void TestSplit();
|
|
||||||
void TestSetPath();
|
|
||||||
void TestStrip();
|
|
||||||
void TestRelative();
|
|
||||||
void TestNormalize();
|
|
||||||
void TestReplace();
|
|
||||||
void TestGetHumanReadable();
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
void TestShortLongPath();
|
|
||||||
#endif // __WINDOWS__
|
|
||||||
void TestUNC();
|
|
||||||
void TestVolumeUniqueName();
|
|
||||||
void TestCreateTempFileName();
|
|
||||||
void TestGetTimes();
|
|
||||||
void TestSetTimes();
|
|
||||||
void TestExists();
|
|
||||||
void TestIsSame();
|
|
||||||
#if defined(__UNIX__)
|
|
||||||
void TestSymlinks();
|
|
||||||
#endif // __UNIX__
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
void TestShortcuts();
|
|
||||||
#endif // __WINDOWS__
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(FileNameTestCase);
|
|
||||||
};
|
|
||||||
|
|
||||||
// register in the unnamed registry so that these tests are run by default
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( FileNameTestCase );
|
|
||||||
|
|
||||||
// also include in its own registry so that these tests can be run alone
|
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileNameTestCase, "FileNameTestCase" );
|
|
||||||
|
|
||||||
void FileNameTestCase::TestConstruction()
|
|
||||||
{
|
{
|
||||||
for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
|
for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
|
||||||
{
|
{
|
||||||
const TestFileNameInfo& fni = filenames[n];
|
const TestFileNameInfo& fni = filenames[n];
|
||||||
|
|
||||||
|
INFO("Test #" << n << ": \"" << fni.fullname << "\"");
|
||||||
|
|
||||||
wxFileName fn(fni.fullname, fni.format);
|
wxFileName fn(fni.fullname, fni.format);
|
||||||
|
|
||||||
// the original full name could contain consecutive [back]slashes,
|
// the original full name could contain consecutive [back]slashes,
|
||||||
@@ -223,17 +156,12 @@ void FileNameTestCase::TestConstruction()
|
|||||||
fullnameOrig.Replace("//", "/");
|
fullnameOrig.Replace("//", "/");
|
||||||
|
|
||||||
|
|
||||||
wxString fullname = fn.GetFullPath(fni.format);
|
CHECK( fn.GetFullPath(fni.format) == fullnameOrig );
|
||||||
CPPUNIT_ASSERT_EQUAL( fullnameOrig, fullname );
|
|
||||||
|
|
||||||
// notice that we use a dummy working directory to ensure that paths
|
// notice that we use a dummy working directory to ensure that paths
|
||||||
// with "../.." in them could be normalized, otherwise this would fail
|
// with "../.." in them could be normalized, otherwise this would fail
|
||||||
// if the test is run from root directory or its direct subdirectory
|
// if the test is run from root directory or its direct subdirectory
|
||||||
CPPUNIT_ASSERT_MESSAGE
|
CHECK( fn.Normalize(wxPATH_NORM_ALL, "/foo/bar/baz", fni.format) );
|
||||||
(
|
|
||||||
(const char *)wxString::Format("Normalize(%s) failed", fni.fullname).mb_str(),
|
|
||||||
fn.Normalize(wxPATH_NORM_ALL, "/foo/bar/baz", fni.format)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( *fni.volume && *fni.path )
|
if ( *fni.volume && *fni.path )
|
||||||
{
|
{
|
||||||
@@ -243,10 +171,10 @@ void FileNameTestCase::TestConstruction()
|
|||||||
pathWithVolume += wxFileName::GetVolumeSeparator(fni.format);
|
pathWithVolume += wxFileName::GetVolumeSeparator(fni.format);
|
||||||
pathWithVolume += fni.path;
|
pathWithVolume += fni.path;
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( wxFileName(pathWithVolume,
|
CHECK( wxFileName(pathWithVolume,
|
||||||
fni.name,
|
fni.name,
|
||||||
fni.ext,
|
fni.ext,
|
||||||
fni.format), fn );
|
fni.format) == fn );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,31 +182,31 @@ void FileNameTestCase::TestConstruction()
|
|||||||
|
|
||||||
// empty strings
|
// empty strings
|
||||||
fn.AssignDir(wxEmptyString);
|
fn.AssignDir(wxEmptyString);
|
||||||
CPPUNIT_ASSERT( !fn.IsOk() );
|
CHECK( !fn.IsOk() );
|
||||||
|
|
||||||
fn.Assign(wxEmptyString);
|
fn.Assign(wxEmptyString);
|
||||||
CPPUNIT_ASSERT( !fn.IsOk() );
|
CHECK( !fn.IsOk() );
|
||||||
|
|
||||||
fn.Assign(wxEmptyString, wxEmptyString);
|
fn.Assign(wxEmptyString, wxEmptyString);
|
||||||
CPPUNIT_ASSERT( !fn.IsOk() );
|
CHECK( !fn.IsOk() );
|
||||||
|
|
||||||
fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString);
|
fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString);
|
||||||
CPPUNIT_ASSERT( !fn.IsOk() );
|
CHECK( !fn.IsOk() );
|
||||||
|
|
||||||
fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString);
|
fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString);
|
||||||
CPPUNIT_ASSERT( !fn.IsOk() );
|
CHECK( !fn.IsOk() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestComparison()
|
TEST_CASE("wxFileName::Comparison", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn1(wxT("/tmp/file1"));
|
wxFileName fn1(wxT("/tmp/file1"));
|
||||||
wxFileName fn2(wxT("/tmp/dir2/../file2"));
|
wxFileName fn2(wxT("/tmp/dir2/../file2"));
|
||||||
fn1.Normalize();
|
fn1.Normalize();
|
||||||
fn2.Normalize();
|
fn2.Normalize();
|
||||||
CPPUNIT_ASSERT_EQUAL(fn1.GetPath(), fn2.GetPath());
|
CHECK(fn1.GetPath() == fn2.GetPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestSplit()
|
TEST_CASE("wxFileName::Split", "[filename]")
|
||||||
{
|
{
|
||||||
for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
|
for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
|
||||||
{
|
{
|
||||||
@@ -287,29 +215,29 @@ void FileNameTestCase::TestSplit()
|
|||||||
wxFileName::SplitPath(fni.fullname,
|
wxFileName::SplitPath(fni.fullname,
|
||||||
&volume, &path, &name, &ext, fni.format);
|
&volume, &path, &name, &ext, fni.format);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(fni.volume), volume );
|
CHECK( volume == fni.volume );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(fni.path), path );
|
CHECK( path == fni.path );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(fni.name), name );
|
CHECK( name == fni.name );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(fni.ext), ext );
|
CHECK( ext == fni.ext );
|
||||||
}
|
}
|
||||||
|
|
||||||
// special case of empty extension
|
// special case of empty extension
|
||||||
wxFileName fn("foo.");
|
wxFileName fn("foo.");
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString("foo."), fn.GetFullPath() );
|
CHECK( fn.GetFullPath() == "foo." );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestSetPath()
|
TEST_CASE("wxFileName::SetPath", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn("d:\\test\\foo.bar", wxPATH_DOS);
|
wxFileName fn("d:\\test\\foo.bar", wxPATH_DOS);
|
||||||
fn.SetPath("c:\\temp", wxPATH_DOS);
|
fn.SetPath("c:\\temp", wxPATH_DOS);
|
||||||
CPPUNIT_ASSERT( fn.SameAs(wxFileName("c:\\temp\\foo.bar", wxPATH_DOS)) );
|
CHECK( fn.SameAs(wxFileName("c:\\temp\\foo.bar", wxPATH_DOS)) );
|
||||||
|
|
||||||
fn = wxFileName("/usr/bin/ls", wxPATH_UNIX);
|
fn = wxFileName("/usr/bin/ls", wxPATH_UNIX);
|
||||||
fn.SetPath("/usr/local/bin", wxPATH_UNIX);
|
fn.SetPath("/usr/local/bin", wxPATH_UNIX);
|
||||||
CPPUNIT_ASSERT( fn.SameAs(wxFileName("/usr/local/bin/ls", wxPATH_UNIX)) );
|
CHECK( fn.SameAs(wxFileName("/usr/local/bin/ls", wxPATH_UNIX)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestNormalize()
|
TEST_CASE("wxFileName::Normalize", "[filename]")
|
||||||
{
|
{
|
||||||
// prepare some data to be used later
|
// prepare some data to be used later
|
||||||
wxString sep = wxFileName::GetPathSeparator();
|
wxString sep = wxFileName::GetPathSeparator();
|
||||||
@@ -434,32 +362,32 @@ void FileNameTestCase::TestNormalize()
|
|||||||
!shortNamesDisabled )
|
!shortNamesDisabled )
|
||||||
{
|
{
|
||||||
wxFileName fn("..\\MKINST~1");
|
wxFileName fn("..\\MKINST~1");
|
||||||
CPPUNIT_ASSERT( fn.Normalize(wxPATH_NORM_LONG, cwd) );
|
CHECK( fn.Normalize(wxPATH_NORM_LONG, cwd) );
|
||||||
CPPUNIT_ASSERT_EQUAL( "..\\mkinstalldirs", fn.GetFullPath() );
|
CHECK( fn.GetFullPath() == "..\\mkinstalldirs" );
|
||||||
}
|
}
|
||||||
//else: when in doubt, don't run the test
|
//else: when in doubt, don't run the test
|
||||||
#endif // __WINDOWS__
|
#endif // __WINDOWS__
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestRelative()
|
TEST_CASE("wxFileName::Relative", "[filename]")
|
||||||
{
|
{
|
||||||
const wxString pathSep = wxFileName::GetPathSeparator();
|
const wxString pathSep = wxFileName::GetPathSeparator();
|
||||||
|
|
||||||
wxFileName fn("a" + pathSep + "b.cpp");
|
wxFileName fn("a" + pathSep + "b.cpp");
|
||||||
fn.MakeRelativeTo("a");
|
fn.MakeRelativeTo("a");
|
||||||
CPPUNIT_ASSERT_EQUAL( "b.cpp", fn.GetFullPath() );
|
CHECK( fn.GetFullPath() == "b.cpp" );
|
||||||
|
|
||||||
fn.AssignDir("a" + pathSep + "b");
|
fn.AssignDir("a" + pathSep + "b");
|
||||||
fn.MakeRelativeTo("a");
|
fn.MakeRelativeTo("a");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( "b" + pathSep, fn.GetFullPath() );
|
CHECK( fn.GetFullPath() == "b" + pathSep );
|
||||||
|
|
||||||
fn.AssignDir("a");
|
fn.AssignDir("a");
|
||||||
fn.MakeRelativeTo("a");
|
fn.MakeRelativeTo("a");
|
||||||
CPPUNIT_ASSERT_EQUAL( "." + pathSep, fn.GetFullPath() );
|
CHECK( fn.GetFullPath() == "." + pathSep );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestReplace()
|
TEST_CASE("wxFileName::Replace", "[filename]")
|
||||||
{
|
{
|
||||||
static const struct FileNameTest
|
static const struct FileNameTest
|
||||||
{
|
{
|
||||||
@@ -528,11 +456,10 @@ void FileNameTestCase::TestReplace()
|
|||||||
fn.ReplaceHomeDir()
|
fn.ReplaceHomeDir()
|
||||||
);
|
);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString("~/test1/test2/test3/some file"),
|
CHECK( fn.GetFullPath(wxPATH_UNIX) == "~/test1/test2/test3/some file" );
|
||||||
fn.GetFullPath(wxPATH_UNIX) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestGetHumanReadable()
|
TEST_CASE("wxFileName::GetHumanReadable", "[filename]")
|
||||||
{
|
{
|
||||||
static const struct TestData
|
static const struct TestData
|
||||||
{
|
{
|
||||||
@@ -560,74 +487,69 @@ void FileNameTestCase::TestGetHumanReadable()
|
|||||||
|
|
||||||
// take care of using the decimal point for the current locale before
|
// take care of using the decimal point for the current locale before
|
||||||
// the actual comparison
|
// the actual comparison
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CHECK
|
||||||
(
|
(
|
||||||
td.result,
|
|
||||||
wxFileName::GetHumanReadableSize(td.size, "NA", td.prec, td.conv)
|
wxFileName::GetHumanReadableSize(td.size, "NA", td.prec, td.conv)
|
||||||
|
==
|
||||||
|
td.result
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// also test the default convention value
|
// also test the default convention value
|
||||||
CPPUNIT_ASSERT_EQUAL( "1.4 MB", wxFileName::GetHumanReadableSize(1512993, "") );
|
CHECK( wxFileName::GetHumanReadableSize(1512993, "") == "1.4 MB" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestStrip()
|
TEST_CASE("wxFileName::Strip", "[filename]")
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_EQUAL( "", wxFileName::StripExtension("") );
|
CHECK( wxFileName::StripExtension("") == "" );
|
||||||
CPPUNIT_ASSERT_EQUAL( ".", wxFileName::StripExtension(".") );
|
CHECK( wxFileName::StripExtension(".") == "." );
|
||||||
CPPUNIT_ASSERT_EQUAL( ".vimrc", wxFileName::StripExtension(".vimrc") );
|
CHECK( wxFileName::StripExtension(".vimrc") == ".vimrc" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "bad", wxFileName::StripExtension("bad") );
|
CHECK( wxFileName::StripExtension("bad") == "bad" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "good", wxFileName::StripExtension("good.wav") );
|
CHECK( wxFileName::StripExtension("good.wav") == "good" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "good.wav", wxFileName::StripExtension("good.wav.wav") );
|
CHECK( wxFileName::StripExtension("good.wav.wav") == "good.wav" );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
void FileNameTestCase::TestShortLongPath()
|
TEST_CASE("wxFileName::ShortLongPath", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe");
|
wxFileName fn("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe");
|
||||||
|
|
||||||
// incredibly enough, GetLongPath() used to return different results during
|
// incredibly enough, GetLongPath() used to return different results during
|
||||||
// the first and subsequent runs, test for this
|
// the first and subsequent runs, test for this
|
||||||
CPPUNIT_ASSERT_EQUAL( fn.GetLongPath(), fn.GetLongPath() );
|
CHECK( fn.GetLongPath() == fn.GetLongPath() );
|
||||||
CPPUNIT_ASSERT_EQUAL( fn.GetShortPath(), fn.GetShortPath() );
|
CHECK( fn.GetShortPath() == fn.GetShortPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __WINDOWS__
|
#endif // __WINDOWS__
|
||||||
|
|
||||||
void FileNameTestCase::TestUNC()
|
TEST_CASE("wxFileName::UNC", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn("//share/path/name.ext", wxPATH_DOS);
|
wxFileName fn("//share/path/name.ext", wxPATH_DOS);
|
||||||
CPPUNIT_ASSERT_EQUAL( "share", fn.GetVolume() );
|
CHECK( fn.GetVolume() == "share" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "\\path", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
|
CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\path" );
|
||||||
|
|
||||||
fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS);
|
fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS);
|
||||||
CPPUNIT_ASSERT_EQUAL( "share2", fn.GetVolume() );
|
CHECK( fn.GetVolume() == "share2" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "\\path2", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
|
CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\path2" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestVolumeUniqueName()
|
TEST_CASE("wxFileName::VolumeUniqueName", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
|
wxFileName fn("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
|
||||||
wxPATH_DOS);
|
wxPATH_DOS);
|
||||||
CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}",
|
CHECK( fn.GetVolume() == "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}" );
|
||||||
fn.GetVolume() );
|
CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "\\", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
|
CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
|
|
||||||
fn.GetFullPath(wxPATH_DOS) );
|
|
||||||
|
|
||||||
fn.Assign("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\"
|
fn.Assign("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\"
|
||||||
"Program Files\\setup.exe", wxPATH_DOS);
|
"Program Files\\setup.exe", wxPATH_DOS);
|
||||||
CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}",
|
CHECK( fn.GetVolume() == "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}" );
|
||||||
fn.GetVolume() );
|
CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\Program Files" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "\\Program Files",
|
CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\Program Files\\setup.exe" );
|
||||||
fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\"
|
|
||||||
"Program Files\\setup.exe",
|
|
||||||
fn.GetFullPath(wxPATH_DOS) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestCreateTempFileName()
|
TEST_CASE("wxFileName::CreateTempFileName", "[filename]")
|
||||||
{
|
{
|
||||||
static const struct TestData
|
static const struct TestData
|
||||||
{
|
{
|
||||||
@@ -655,106 +577,106 @@ void FileNameTestCase::TestCreateTempFileName()
|
|||||||
wxString prefix = testData[n].prefix;
|
wxString prefix = testData[n].prefix;
|
||||||
prefix.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir());
|
prefix.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir());
|
||||||
|
|
||||||
std::string errDesc = wxString::Format("failed on prefix '%s'", prefix).ToStdString();
|
INFO("Prefix: " << prefix);
|
||||||
|
|
||||||
wxString path = wxFileName::CreateTempFileName(prefix);
|
wxString path = wxFileName::CreateTempFileName(prefix);
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( errDesc, !testData[n].shouldSucceed, path.empty() );
|
CHECK( path.empty() == !testData[n].shouldSucceed );
|
||||||
|
|
||||||
if (testData[n].shouldSucceed)
|
if (testData[n].shouldSucceed)
|
||||||
{
|
{
|
||||||
errDesc += "; path is " + path.ToStdString();
|
INFO("Path: " << path);
|
||||||
|
|
||||||
// test the place where the temp file has been created
|
// test the place where the temp file has been created
|
||||||
wxString expected = testData[n].expectedFolder;
|
wxString expected = testData[n].expectedFolder;
|
||||||
expected.Replace("$SYSTEM_TEMP", wxStandardPaths::Get().GetTempDir());
|
expected.Replace("$SYSTEM_TEMP", wxStandardPaths::Get().GetTempDir());
|
||||||
expected.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir());
|
expected.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir());
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( errDesc, expected, wxFileName(path).GetPath() );
|
CHECK( wxFileName(path).GetPath() == expected );
|
||||||
|
|
||||||
// the temporary file is created with full permissions for the current process
|
// the temporary file is created with full permissions for the current process
|
||||||
// so we should always be able to remove it:
|
// so we should always be able to remove it:
|
||||||
CPPUNIT_ASSERT_MESSAGE( errDesc, wxRemoveFile(path) );
|
CHECK( wxRemoveFile(path) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestGetTimes()
|
TEST_CASE("wxFileName::GetTimes", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
||||||
CPPUNIT_ASSERT( fn.IsOk() );
|
REQUIRE( fn.IsOk() );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
||||||
|
|
||||||
wxDateTime dtAccess, dtMod, dtCreate;
|
wxDateTime dtAccess, dtMod, dtCreate;
|
||||||
CPPUNIT_ASSERT( fn.GetTimes(&dtAccess, &dtMod, &dtCreate) );
|
REQUIRE( fn.GetTimes(&dtAccess, &dtMod, &dtCreate) );
|
||||||
|
|
||||||
// make sure all retrieved dates are equal to the current date&time
|
// make sure all retrieved dates are equal to the current date&time
|
||||||
// with an accuracy up to 1 minute
|
// with an accuracy up to 1 minute
|
||||||
CPPUNIT_ASSERT(dtCreate.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
CHECK(dtCreate.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
||||||
CPPUNIT_ASSERT(dtMod.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
CHECK(dtMod.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
||||||
CPPUNIT_ASSERT(dtAccess.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
CHECK(dtAccess.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestSetTimes()
|
TEST_CASE("wxFileName::SetTimes", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
||||||
CPPUNIT_ASSERT( fn.IsOk() );
|
REQUIRE( fn.IsOk() );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
||||||
|
|
||||||
const wxDateTime dtAccess(1, wxDateTime::Jan, 2013);
|
const wxDateTime dtAccess(1, wxDateTime::Jan, 2013);
|
||||||
const wxDateTime dtModify(1, wxDateTime::Feb, 2013);
|
const wxDateTime dtModify(1, wxDateTime::Feb, 2013);
|
||||||
const wxDateTime dtCreate(1, wxDateTime::Mar, 2013);
|
const wxDateTime dtCreate(1, wxDateTime::Mar, 2013);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( fn.SetTimes(&dtAccess, &dtModify, &dtCreate) );
|
REQUIRE( fn.SetTimes(&dtAccess, &dtModify, &dtCreate) );
|
||||||
|
|
||||||
wxDateTime dtAccess2,
|
wxDateTime dtAccess2,
|
||||||
dtModify2,
|
dtModify2,
|
||||||
dtCreate2;
|
dtCreate2;
|
||||||
CPPUNIT_ASSERT( fn.GetTimes(&dtAccess2, &dtModify2, &dtCreate2) );
|
REQUIRE( fn.GetTimes(&dtAccess2, &dtModify2, &dtCreate2) );
|
||||||
CPPUNIT_ASSERT_EQUAL( dtAccess, dtAccess2 );
|
CHECK( dtAccess2 == dtAccess );
|
||||||
CPPUNIT_ASSERT_EQUAL( dtModify, dtModify2 );
|
CHECK( dtModify2 == dtModify );
|
||||||
|
|
||||||
// Under Unix the creation time can't be set.
|
// Under Unix the creation time can't be set.
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
CPPUNIT_ASSERT_EQUAL( dtCreate, dtCreate2 );
|
CHECK( dtCreate2 == dtCreate );
|
||||||
#endif // __WINDOWS__
|
#endif // __WINDOWS__
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestExists()
|
TEST_CASE("wxFileName::Exists", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
||||||
CPPUNIT_ASSERT( fn.IsOk() );
|
REQUIRE( fn.IsOk() );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( fn.FileExists() );
|
CHECK( fn.FileExists() );
|
||||||
CPPUNIT_ASSERT( !wxFileName::DirExists(fn.GetFullPath()) );
|
CHECK( !wxFileName::DirExists(fn.GetFullPath()) );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( fn.Exists(wxFILE_EXISTS_REGULAR) );
|
CHECK( fn.Exists(wxFILE_EXISTS_REGULAR) );
|
||||||
CPPUNIT_ASSERT( !fn.Exists(wxFILE_EXISTS_DIR) );
|
CHECK( !fn.Exists(wxFILE_EXISTS_DIR) );
|
||||||
CPPUNIT_ASSERT( fn.Exists() );
|
CHECK( fn.Exists() );
|
||||||
|
|
||||||
const wxString& tempdir = wxFileName::GetTempDir();
|
const wxString& tempdir = wxFileName::GetTempDir();
|
||||||
|
|
||||||
wxFileName fileInTempDir(tempdir, "bloordyblop");
|
wxFileName fileInTempDir(tempdir, "bloordyblop");
|
||||||
CPPUNIT_ASSERT( !fileInTempDir.Exists() );
|
CHECK( !fileInTempDir.Exists() );
|
||||||
CPPUNIT_ASSERT( fileInTempDir.DirExists() );
|
CHECK( fileInTempDir.DirExists() );
|
||||||
|
|
||||||
wxFileName dirTemp(wxFileName::DirName(tempdir));
|
wxFileName dirTemp(wxFileName::DirName(tempdir));
|
||||||
CPPUNIT_ASSERT( !dirTemp.FileExists() );
|
CHECK( !dirTemp.FileExists() );
|
||||||
CPPUNIT_ASSERT( dirTemp.DirExists() );
|
CHECK( dirTemp.DirExists() );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( dirTemp.Exists(wxFILE_EXISTS_DIR) );
|
CHECK( dirTemp.Exists(wxFILE_EXISTS_DIR) );
|
||||||
CPPUNIT_ASSERT( !dirTemp.Exists(wxFILE_EXISTS_REGULAR) );
|
CHECK( !dirTemp.Exists(wxFILE_EXISTS_REGULAR) );
|
||||||
CPPUNIT_ASSERT( dirTemp.Exists() );
|
CHECK( dirTemp.Exists() );
|
||||||
|
|
||||||
#ifdef __UNIX__
|
#ifdef __UNIX__
|
||||||
CPPUNIT_ASSERT( !wxFileName::FileExists("/dev/null") );
|
CHECK( !wxFileName::FileExists("/dev/null") );
|
||||||
CPPUNIT_ASSERT( !wxFileName::DirExists("/dev/null") );
|
CHECK( !wxFileName::DirExists("/dev/null") );
|
||||||
CPPUNIT_ASSERT( wxFileName::Exists("/dev/null") );
|
CHECK( wxFileName::Exists("/dev/null") );
|
||||||
CPPUNIT_ASSERT( wxFileName::Exists("/dev/null", wxFILE_EXISTS_DEVICE) );
|
CHECK( wxFileName::Exists("/dev/null", wxFILE_EXISTS_DEVICE) );
|
||||||
#ifdef __LINUX__
|
#ifdef __LINUX__
|
||||||
// These files are only guaranteed to exist under Linux.
|
// These files are only guaranteed to exist under Linux.
|
||||||
// No need for wxFILE_EXISTS_NO_FOLLOW here; wxFILE_EXISTS_SYMLINK implies it
|
// No need for wxFILE_EXISTS_NO_FOLLOW here; wxFILE_EXISTS_SYMLINK implies it
|
||||||
CPPUNIT_ASSERT( wxFileName::Exists("/proc/self", wxFILE_EXISTS_SYMLINK) );
|
CHECK( wxFileName::Exists("/proc/self", wxFILE_EXISTS_SYMLINK) );
|
||||||
CPPUNIT_ASSERT( wxFileName::Exists("/dev/log", wxFILE_EXISTS_SOCKET) );
|
CHECK( wxFileName::Exists("/dev/log", wxFILE_EXISTS_SOCKET) );
|
||||||
#endif // __LINUX__
|
#endif // __LINUX__
|
||||||
#ifndef __VMS
|
#ifndef __VMS
|
||||||
wxString fifo = dirTemp.GetPath() + "/fifo";
|
wxString fifo = dirTemp.GetPath() + "/fifo";
|
||||||
@@ -762,24 +684,24 @@ void FileNameTestCase::TestExists()
|
|||||||
{
|
{
|
||||||
wxON_BLOCK_EXIT1(wxRemoveFile, fifo);
|
wxON_BLOCK_EXIT1(wxRemoveFile, fifo);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( wxFileName::Exists(fifo, wxFILE_EXISTS_FIFO) );
|
CHECK( wxFileName::Exists(fifo, wxFILE_EXISTS_FIFO) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif // __UNIX__
|
#endif // __UNIX__
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestIsSame()
|
TEST_CASE("wxFileName::SameAs", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn1( wxFileName::CreateTempFileName( "filenametest1" ) );
|
wxFileName fn1( wxFileName::CreateTempFileName( "filenametest1" ) );
|
||||||
CPPUNIT_ASSERT( fn1.IsOk() );
|
REQUIRE( fn1.IsOk() );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, fn1.GetFullPath() );
|
wxON_BLOCK_EXIT1( wxRemoveFile, fn1.GetFullPath() );
|
||||||
|
|
||||||
wxFileName fn2( wxFileName::CreateTempFileName( "filenametest2" ) );
|
wxFileName fn2( wxFileName::CreateTempFileName( "filenametest2" ) );
|
||||||
CPPUNIT_ASSERT( fn2.IsOk() );
|
REQUIRE( fn2.IsOk() );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, fn2.GetFullPath() );
|
wxON_BLOCK_EXIT1( wxRemoveFile, fn2.GetFullPath() );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( fn1.SameAs( fn1 ) );
|
CHECK( fn1.SameAs( fn1 ) );
|
||||||
CPPUNIT_ASSERT( !fn1.SameAs( fn2 ) );
|
CHECK( !fn1.SameAs( fn2 ) );
|
||||||
|
|
||||||
#if defined(__UNIX__)
|
#if defined(__UNIX__)
|
||||||
// We need to create a temporary directory and a temporary link.
|
// We need to create a temporary directory and a temporary link.
|
||||||
@@ -789,7 +711,7 @@ void FileNameTestCase::TestIsSame()
|
|||||||
const wxString tempdir1 = wxString::From8BitData(tn);
|
const wxString tempdir1 = wxString::From8BitData(tn);
|
||||||
free(tn);
|
free(tn);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( wxFileName::Mkdir(tempdir1) );
|
REQUIRE( wxFileName::Mkdir(tempdir1) );
|
||||||
// Unfortunately the casts are needed to select the overload we need here.
|
// Unfortunately the casts are needed to select the overload we need here.
|
||||||
wxON_BLOCK_EXIT2( static_cast<bool (*)(const wxString&, int)>(wxFileName::Rmdir),
|
wxON_BLOCK_EXIT2( static_cast<bool (*)(const wxString&, int)>(wxFileName::Rmdir),
|
||||||
tempdir1, static_cast<int>(wxPATH_RMDIR_RECURSIVE) );
|
tempdir1, static_cast<int>(wxPATH_RMDIR_RECURSIVE) );
|
||||||
@@ -797,7 +719,7 @@ void FileNameTestCase::TestIsSame()
|
|||||||
tn = tempnam(NULL, "wxfn2");
|
tn = tempnam(NULL, "wxfn2");
|
||||||
const wxString tempdir2 = wxString::From8BitData(tn);
|
const wxString tempdir2 = wxString::From8BitData(tn);
|
||||||
free(tn);
|
free(tn);
|
||||||
CPPUNIT_ASSERT_EQUAL( 0, symlink(tempdir1.c_str(), tempdir2.c_str()) );
|
CHECK( symlink(tempdir1.c_str(), tempdir2.c_str()) == 0 );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, tempdir2 );
|
wxON_BLOCK_EXIT1( wxRemoveFile, tempdir2 );
|
||||||
|
|
||||||
|
|
||||||
@@ -805,21 +727,21 @@ void FileNameTestCase::TestIsSame()
|
|||||||
wxFileName fn4(tempdir2, "foo");
|
wxFileName fn4(tempdir2, "foo");
|
||||||
|
|
||||||
// These files have different paths, hence are different.
|
// These files have different paths, hence are different.
|
||||||
CPPUNIT_ASSERT( !fn3.SameAs(fn4) );
|
CHECK( !fn3.SameAs(fn4) );
|
||||||
|
|
||||||
// Create and close a file to trigger creating it.
|
// Create and close a file to trigger creating it.
|
||||||
wxFile(fn3.GetFullPath(), wxFile::write);
|
wxFile(fn3.GetFullPath(), wxFile::write);
|
||||||
|
|
||||||
// Now that both files do exist we should be able to detect that they are
|
// Now that both files do exist we should be able to detect that they are
|
||||||
// actually the same file.
|
// actually the same file.
|
||||||
CPPUNIT_ASSERT( fn3.SameAs(fn4) );
|
CHECK( fn3.SameAs(fn4) );
|
||||||
#endif // __UNIX__
|
#endif // __UNIX__
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__UNIX__)
|
#if defined(__UNIX__)
|
||||||
|
|
||||||
// Tests for functions that are changed by ShouldFollowLink()
|
// Tests for functions that are changed by ShouldFollowLink()
|
||||||
void FileNameTestCase::TestSymlinks()
|
TEST_CASE("wxFileName::Symlinks", "[filename]")
|
||||||
{
|
{
|
||||||
const wxString tmpdir(wxStandardPaths::Get().GetTempDir());
|
const wxString tmpdir(wxStandardPaths::Get().GetTempDir());
|
||||||
|
|
||||||
@@ -836,76 +758,49 @@ void FileNameTestCase::TestSymlinks()
|
|||||||
tempdir << wxFileName::GetPathSeparator();
|
tempdir << wxFileName::GetPathSeparator();
|
||||||
#endif
|
#endif
|
||||||
wxFileName tempdirfn(wxFileName::DirName(tempdir));
|
wxFileName tempdirfn(wxFileName::DirName(tempdir));
|
||||||
CPPUNIT_ASSERT(tempdirfn.DirExists());
|
CHECK(tempdirfn.DirExists());
|
||||||
|
|
||||||
// Create a regular file in that dir, to act as a symlink target
|
// Create a regular file in that dir, to act as a symlink target
|
||||||
wxFileName targetfn(wxFileName::CreateTempFileName(tempdir));
|
wxFileName targetfn(wxFileName::CreateTempFileName(tempdir));
|
||||||
CPPUNIT_ASSERT(targetfn.FileExists());
|
CHECK(targetfn.FileExists());
|
||||||
|
|
||||||
// Resolving a non-symlink will just return the same thing
|
// Resolving a non-symlink will just return the same thing
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Non-symlink didn't resolve to the same file");
|
||||||
(
|
CHECK( targetfn.ResolveLink() == targetfn );
|
||||||
"Non-symlink didn't resolve to the same file",
|
|
||||||
targetfn, targetfn.ResolveLink()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create a symlink to that file
|
// Create a symlink to that file
|
||||||
wxFileName linktofile(tempdir, "linktofile");
|
wxFileName linktofile(tempdir, "linktofile");
|
||||||
CPPUNIT_ASSERT_EQUAL(0, symlink(targetfn.GetFullPath().c_str(),
|
CHECK( symlink(targetfn.GetFullPath().c_str(), linktofile.GetFullPath().c_str()) == 0 );
|
||||||
linktofile.GetFullPath().c_str()));
|
|
||||||
|
|
||||||
// Test resolving the filename to the symlink
|
// Test resolving the filename to the symlink
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Failed to resolve symlink to file");
|
||||||
(
|
CHECK( linktofile.ResolveLink() == targetfn );
|
||||||
"Failed to resolve symlink to file",
|
|
||||||
targetfn, linktofile.ResolveLink()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create a relative symlink to that file
|
// Create a relative symlink to that file
|
||||||
wxFileName relativelinktofile(tempdir, "relativelinktofile");
|
wxFileName relativelinktofile(tempdir, "relativelinktofile");
|
||||||
wxString relativeFileName = "./" + targetfn.GetFullName();
|
wxString relativeFileName = "./" + targetfn.GetFullName();
|
||||||
CPPUNIT_ASSERT_EQUAL(0, symlink(relativeFileName.c_str(),
|
CHECK( symlink(relativeFileName.c_str(), relativelinktofile.GetFullPath().c_str()) == 0 );
|
||||||
relativelinktofile.GetFullPath().c_str()));
|
INFO("Failed to resolve relative symlink to absolute file path");
|
||||||
|
CHECK( relativelinktofile.ResolveLink() == targetfn );
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Failed to resolve relative symlink to absolute file path",
|
|
||||||
targetfn, relativelinktofile.ResolveLink()
|
|
||||||
);
|
|
||||||
|
|
||||||
// ... and another to the temporary directory
|
// ... and another to the temporary directory
|
||||||
const wxString linktodirName(tempdir + "/linktodir");
|
const wxString linktodirName(tempdir + "/linktodir");
|
||||||
wxFileName linktodirfn(linktodirName);
|
wxFileName linktodirfn(linktodirName);
|
||||||
wxFileName linktodir(wxFileName::DirName(linktodirName));
|
wxFileName linktodir(wxFileName::DirName(linktodirName));
|
||||||
CPPUNIT_ASSERT_EQUAL(0, symlink(tmpfn.GetFullPath().c_str(),
|
CHECK( symlink(tmpfn.GetFullPath().c_str(), linktodirName.c_str()) == 0 );
|
||||||
linktodirName.c_str()));
|
INFO("Failed to resolve symlink to directory");
|
||||||
|
CHECK( linktodirfn.ResolveLink() == tmpfn );
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Failed to resolve symlink to directory",
|
|
||||||
tmpfn, linktodirfn.ResolveLink()
|
|
||||||
);
|
|
||||||
|
|
||||||
// And symlinks to both of those symlinks
|
// And symlinks to both of those symlinks
|
||||||
wxFileName linktofilelnk(tempdir, "linktofilelnk");
|
wxFileName linktofilelnk(tempdir, "linktofilelnk");
|
||||||
CPPUNIT_ASSERT_EQUAL(0, symlink(linktofile.GetFullPath().c_str(),
|
CHECK( symlink(linktofile.GetFullPath().c_str(), linktofilelnk.GetFullPath().c_str()) == 0 );
|
||||||
linktofilelnk.GetFullPath().c_str()));
|
INFO("Failed to resolve symlink to file symlink");
|
||||||
|
CHECK( linktofilelnk.ResolveLink() == targetfn );
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Failed to resolve symlink to file symlink",
|
|
||||||
targetfn, linktofilelnk.ResolveLink()
|
|
||||||
);
|
|
||||||
|
|
||||||
wxFileName linktodirlnk(tempdir, "linktodirlnk");
|
wxFileName linktodirlnk(tempdir, "linktodirlnk");
|
||||||
CPPUNIT_ASSERT_EQUAL(0, symlink(linktodir.GetFullPath().c_str(),
|
CHECK( symlink(linktodir.GetFullPath().c_str(), linktodirlnk.GetFullPath().c_str()) == 0 );
|
||||||
linktodirlnk.GetFullPath().c_str()));
|
INFO("Failed to resolve symlink to directory symlink");
|
||||||
|
CHECK( linktodirlnk.ResolveLink() == tmpfn );
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Failed to resolve symlink to directory symlink",
|
|
||||||
tmpfn, linktodirlnk.ResolveLink()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Run the tests twice: once in the default symlink following mode and the
|
// Run the tests twice: once in the default symlink following mode and the
|
||||||
// second time without following symlinks.
|
// second time without following symlinks.
|
||||||
@@ -924,130 +819,77 @@ void FileNameTestCase::TestSymlinks()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test SameAs()
|
// Test SameAs()
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Comparison with file" + msg);
|
||||||
(
|
CHECK( linktofile.SameAs(targetfn) == deref );
|
||||||
"Comparison with file" + msg,
|
|
||||||
deref, linktofile.SameAs(targetfn)
|
|
||||||
);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Comparison with directory" + msg);
|
||||||
(
|
CHECK( linktodir.SameAs(tmpfn) == deref );
|
||||||
"Comparison with directory" + msg,
|
|
||||||
deref, linktodir.SameAs(tmpfn)
|
|
||||||
);
|
|
||||||
|
|
||||||
// A link-to-a-link should dereference through to the final target
|
// A link-to-a-link should dereference through to the final target
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Comparison with link to a file" + msg);
|
||||||
(
|
CHECK( linktofilelnk.SameAs(targetfn) == deref );
|
||||||
"Comparison with link to a file" + msg,
|
INFO("Comparison with link to a directory" + msg);
|
||||||
deref,
|
CHECK( linktodirlnk.SameAs(tmpfn) == deref );
|
||||||
linktofilelnk.SameAs(targetfn)
|
|
||||||
);
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Comparison with link to a directory" + msg,
|
|
||||||
deref,
|
|
||||||
linktodirlnk.SameAs(tmpfn)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Test GetTimes()
|
// Test GetTimes()
|
||||||
|
INFO("Getting times of a directory" + msg);
|
||||||
wxDateTime dtAccess, dtMod, dtCreate;
|
wxDateTime dtAccess, dtMod, dtCreate;
|
||||||
CPPUNIT_ASSERT_MESSAGE
|
CHECK( linktodir.GetTimes(&dtAccess, &dtMod, &dtCreate) );
|
||||||
(
|
|
||||||
"Getting times of a directory" + msg,
|
|
||||||
linktodir.GetTimes(&dtAccess, &dtMod, &dtCreate)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Test (File|Dir)Exists()
|
// Test (File|Dir)Exists()
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Testing file existence" + msg);
|
||||||
(
|
CHECK( linktofile.FileExists() == deref );
|
||||||
"Testing file existence" + msg,
|
INFO("Testing directory existence" + msg);
|
||||||
deref,
|
CHECK( linktodir.DirExists() == deref );
|
||||||
linktofile.FileExists()
|
|
||||||
);
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Testing directory existence" + msg,
|
|
||||||
deref,
|
|
||||||
linktodir.DirExists()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Test wxFileName::Exists
|
// Test wxFileName::Exists
|
||||||
// The wxFILE_EXISTS_NO_FOLLOW flag should override DontFollowLink()
|
// The wxFILE_EXISTS_NO_FOLLOW flag should override DontFollowLink()
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Testing file existence" + msg);
|
||||||
(
|
CHECK_FALSE( linktofile.Exists(wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW) );
|
||||||
"Testing file existence" + msg,
|
|
||||||
false,
|
INFO("Testing directory existence" + msg);
|
||||||
linktofile.Exists(wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW)
|
CHECK_FALSE( linktodir.Exists(wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW) );
|
||||||
);
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Testing directory existence" + msg,
|
|
||||||
false,
|
|
||||||
linktodir.Exists(wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW)
|
|
||||||
);
|
|
||||||
// and the static versions
|
// and the static versions
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Testing file existence" + msg);
|
||||||
(
|
CHECK_FALSE( wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW) );
|
||||||
"Testing file existence" + msg,
|
CHECK( wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR) );
|
||||||
false,
|
|
||||||
wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR | wxFILE_EXISTS_NO_FOLLOW)
|
INFO("Testing directory existence" + msg);
|
||||||
);
|
CHECK_FALSE( wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW) );
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
CHECK( wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR) );
|
||||||
(
|
|
||||||
"Testing file existence" + msg,
|
|
||||||
true,
|
|
||||||
wxFileName::Exists(linktofile.GetFullPath(), wxFILE_EXISTS_REGULAR)
|
|
||||||
);
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Testing directory existence" + msg,
|
|
||||||
false,
|
|
||||||
wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR | wxFILE_EXISTS_NO_FOLLOW)
|
|
||||||
);
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
|
||||||
(
|
|
||||||
"Testing directory existence" + msg,
|
|
||||||
true,
|
|
||||||
wxFileName::Exists(linktodir.GetFullPath(), wxFILE_EXISTS_DIR)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally test Exists() after removing the file.
|
// Finally test Exists() after removing the file.
|
||||||
CPPUNIT_ASSERT(wxRemoveFile(targetfn.GetFullPath()));
|
CHECK(wxRemoveFile(targetfn.GetFullPath()));
|
||||||
|
|
||||||
// Resolving a file that doesn't exist returns empty
|
// Resolving a file that doesn't exist returns empty
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Non-existent file didn't resolve correctly");
|
||||||
(
|
CHECK( targetfn.ResolveLink() == wxFileName() );
|
||||||
"Non-existent file didn't resolve correctly",
|
|
||||||
wxFileName(), targetfn.ResolveLink()
|
|
||||||
);
|
|
||||||
|
|
||||||
// This should succeed, as the symlink still exists and
|
// This should succeed, as the symlink still exists and
|
||||||
// the default wxFILE_EXISTS_ANY implies wxFILE_EXISTS_NO_FOLLOW
|
// the default wxFILE_EXISTS_ANY implies wxFILE_EXISTS_NO_FOLLOW
|
||||||
CPPUNIT_ASSERT(wxFileName(tempdir, "linktofile").Exists());
|
CHECK(wxFileName(tempdir, "linktofile").Exists());
|
||||||
// So should this one, as wxFILE_EXISTS_SYMLINK does too
|
// So should this one, as wxFILE_EXISTS_SYMLINK does too
|
||||||
CPPUNIT_ASSERT(wxFileName(tempdir, "linktofile").
|
CHECK(wxFileName(tempdir, "linktofile").Exists(wxFILE_EXISTS_SYMLINK));
|
||||||
Exists(wxFILE_EXISTS_SYMLINK));
|
|
||||||
// but not this one, as the now broken symlink is followed
|
// but not this one, as the now broken symlink is followed
|
||||||
CPPUNIT_ASSERT(!wxFileName(tempdir, "linktofile").
|
CHECK(!wxFileName(tempdir, "linktofile").Exists(wxFILE_EXISTS_REGULAR));
|
||||||
Exists(wxFILE_EXISTS_REGULAR));
|
CHECK(linktofile.Exists());
|
||||||
CPPUNIT_ASSERT(linktofile.Exists());
|
|
||||||
|
|
||||||
// This is also a convenient place to test Rmdir() as we have things to
|
// This is also a convenient place to test Rmdir() as we have things to
|
||||||
// remove.
|
// remove.
|
||||||
|
|
||||||
// First, check that removing a symlink to a directory fails.
|
// First, check that removing a symlink to a directory fails.
|
||||||
CPPUNIT_ASSERT( !wxFileName::Rmdir(linktodirName) );
|
CHECK( !wxFileName::Rmdir(linktodirName) );
|
||||||
|
|
||||||
// And recursively removing it only removes the symlink itself, not the
|
// And recursively removing it only removes the symlink itself, not the
|
||||||
// directory.
|
// directory.
|
||||||
CPPUNIT_ASSERT( wxFileName::Rmdir(linktodirName, wxPATH_RMDIR_RECURSIVE) );
|
CHECK( wxFileName::Rmdir(linktodirName, wxPATH_RMDIR_RECURSIVE) );
|
||||||
CPPUNIT_ASSERT( tmpfn.Exists() );
|
CHECK( tmpfn.Exists() );
|
||||||
|
|
||||||
// Finally removing the directory itself does remove everything.
|
// Finally removing the directory itself does remove everything.
|
||||||
CPPUNIT_ASSERT(tempdirfn.Rmdir(wxPATH_RMDIR_RECURSIVE));
|
CHECK(tempdirfn.Rmdir(wxPATH_RMDIR_RECURSIVE));
|
||||||
CPPUNIT_ASSERT( !tempdirfn.Exists() );
|
CHECK( !tempdirfn.Exists() );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __UNIX__
|
#endif // __UNIX__
|
||||||
@@ -1066,29 +908,29 @@ void CreateShortcut(const wxString& pathFile, const wxString& pathLink)
|
|||||||
wxCOMPtr<IShellLink> sl;
|
wxCOMPtr<IShellLink> sl;
|
||||||
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
||||||
IID_IShellLink, (void **)&sl);
|
IID_IShellLink, (void **)&sl);
|
||||||
CPPUNIT_ASSERT( SUCCEEDED(hr) );
|
REQUIRE( SUCCEEDED(hr) );
|
||||||
|
|
||||||
wxCOMPtr<IPersistFile> pf;
|
wxCOMPtr<IPersistFile> pf;
|
||||||
hr = sl->QueryInterface(IID_IPersistFile, (void **)&pf);
|
hr = sl->QueryInterface(IID_IPersistFile, (void **)&pf);
|
||||||
CPPUNIT_ASSERT( SUCCEEDED(hr) );
|
REQUIRE( SUCCEEDED(hr) );
|
||||||
|
|
||||||
hr = sl->SetPath(pathFile.t_str());
|
hr = sl->SetPath(pathFile.t_str());
|
||||||
CPPUNIT_ASSERT( SUCCEEDED(hr) );
|
CHECK( SUCCEEDED(hr) );
|
||||||
|
|
||||||
hr = pf->Save(pathLink.wc_str(), TRUE);
|
hr = pf->Save(pathLink.wc_str(), TRUE);
|
||||||
CPPUNIT_ASSERT( SUCCEEDED(hr) );
|
CHECK( SUCCEEDED(hr) );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
void FileNameTestCase::TestShortcuts()
|
TEST_CASE("wxFileName::Shortcuts", "[filename]")
|
||||||
{
|
{
|
||||||
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
||||||
CPPUNIT_ASSERT( fn.IsOk() );
|
REQUIRE( fn.IsOk() );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
wxON_BLOCK_EXIT1( wxRemoveFile, fn.GetFullPath() );
|
||||||
|
|
||||||
wxFileName fnLink(fn.GetPath(), "sc_" + fn.GetName(), "lnk");
|
wxFileName fnLink(fn.GetPath(), "sc_" + fn.GetName(), "lnk");
|
||||||
CPPUNIT_ASSERT( fnLink.IsOk() );
|
REQUIRE( fnLink.IsOk() );
|
||||||
wxON_BLOCK_EXIT1( wxRemoveFile, fnLink.GetFullPath() );
|
wxON_BLOCK_EXIT1( wxRemoveFile, fnLink.GetFullPath() );
|
||||||
|
|
||||||
CreateShortcut(fn.GetFullPath(), fnLink.GetFullPath());
|
CreateShortcut(fn.GetFullPath(), fnLink.GetFullPath());
|
||||||
@@ -1097,7 +939,7 @@ void FileNameTestCase::TestShortcuts()
|
|||||||
// name.
|
// name.
|
||||||
wxFileName fnLinkRel(fnLink);
|
wxFileName fnLinkRel(fnLink);
|
||||||
fnLink.MakeRelativeTo(".");
|
fnLink.MakeRelativeTo(".");
|
||||||
CPPUNIT_ASSERT_EQUAL(fnLink.GetFullName(), fnLinkRel.GetFullName());
|
CHECK( fnLinkRel.GetFullName() == fnLink.GetFullName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __WINDOWS__
|
#endif // __WINDOWS__
|
||||||
|
Reference in New Issue
Block a user