#define TEST_DYNLIB
#define TEST_ENVIRON
#define TEST_FILE
- #define TEST_FILENAME
- #define TEST_FILETIME
#else // #if TEST_ALL
#define TEST_DATETIME
#define TEST_VOLUME
{
wxPuts(wxT("*** wxFile read test ***"));
- wxFile file(wxT("testdata.fc"));
+ wxFile file(wxT("makefile.vc"));
if ( file.IsOpened() )
{
wxPrintf(wxT("File length: %lu\n"), file.Length());
{
wxPuts(wxT("*** wxTextFile read test ***"));
- wxTextFile file(wxT("testdata.fc"));
+ wxTextFile file(wxT("makefile.vc"));
if ( file.Open() )
{
wxPrintf(wxT("Number of lines: %u\n"), file.GetLineCount());
{
wxPuts(wxT("*** Testing wxCopyFile ***"));
- static const wxChar *filename1 = wxT("testdata.fc");
+ static const wxChar *filename1 = wxT("makefile.vc");
static const wxChar *filename2 = wxT("test2");
if ( !wxCopyFile(filename1, filename2) )
{
#endif // TEST_FILE
-// ----------------------------------------------------------------------------
-// wxFileName
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_FILENAME
-
-#include "wx/filename.h"
-
-#if 0
-static void DumpFileName(const wxChar *desc, const wxFileName& fn)
-{
- wxPuts(desc);
-
- wxString full = fn.GetFullPath();
-
- wxString vol, path, name, ext;
- wxFileName::SplitPath(full, &vol, &path, &name, &ext);
-
- wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
- full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
-
- wxFileName::SplitPath(full, &path, &name, &ext);
- wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
- path.c_str(), name.c_str(), ext.c_str());
-
- wxPrintf(wxT("path is also:\t'%s'\n"), fn.GetPath().c_str());
- wxPrintf(wxT("with volume: \t'%s'\n"),
- fn.GetPath(wxPATH_GET_VOLUME).c_str());
- wxPrintf(wxT("with separator:\t'%s'\n"),
- fn.GetPath(wxPATH_GET_SEPARATOR).c_str());
- wxPrintf(wxT("with both: \t'%s'\n"),
- fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str());
-
- wxPuts(wxT("The directories in the path are:"));
- wxArrayString dirs = fn.GetDirs();
- size_t count = dirs.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- wxPrintf(wxT("\t%u: %s\n"), n, dirs[n].c_str());
- }
-}
-#endif
-
-static void TestFileNameTemp()
-{
- wxPuts(wxT("*** testing wxFileName temp file creation ***"));
-
- static const wxChar *tmpprefixes[] =
- {
- wxT(""),
- wxT("foo"),
- wxT(".."),
- wxT("../bar"),
-#ifdef __UNIX__
- wxT("/tmp/foo"),
- wxT("/tmp/foo/bar"), // this one must be an error
-#endif // __UNIX__
- };
-
- for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
- {
- wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
- if ( path.empty() )
- {
- // "error" is not in upper case because it may be ok
- wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes[n]);
- }
- else
- {
- wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
- tmpprefixes[n], path.c_str());
-
- if ( !wxRemoveFile(path) )
- {
- wxLogWarning(wxT("Failed to remove temp file '%s'"),
- path.c_str());
- }
- }
- }
-}
-
-static void TestFileNameDirManip()
-{
- // TODO: test AppendDir(), RemoveDir(), ...
-}
-
-static void TestFileNameComparison()
-{
- // TODO!
-}
-
-static void TestFileNameOperations()
-{
- // TODO!
-}
-
-static void TestFileNameCwd()
-{
- // TODO!
-}
-
-#endif // TEST_FILENAME
-
-// ----------------------------------------------------------------------------
-// wxFileName time functions
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_FILETIME
-
-#include "wx/filename.h"
-#include "wx/datetime.h"
-
-static void TestFileGetTimes()
-{
- wxFileName fn(wxT("testdata.fc"));
-
- wxDateTime dtAccess, dtMod, dtCreate;
- if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) )
- {
- wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
- }
- else
- {
- static const wxChar *fmt = wxT("%Y-%b-%d %H:%M:%S");
-
- wxPrintf(wxT("File times for '%s':\n"), fn.GetFullPath().c_str());
- wxPrintf(wxT("Creation: \t%s\n"), dtCreate.Format(fmt).c_str());
- wxPrintf(wxT("Last read: \t%s\n"), dtAccess.Format(fmt).c_str());
- wxPrintf(wxT("Last write: \t%s\n"), dtMod.Format(fmt).c_str());
- }
-}
-
-#if 0
-static void TestFileSetTimes()
-{
- wxFileName fn(wxT("testdata.fc"));
-
- if ( !fn.Touch() )
- {
- wxPrintf(wxT("ERROR: Touch() failed.\n"));
- }
-}
-#endif
-
-#endif // TEST_FILETIME
-
// ----------------------------------------------------------------------------
// MIME types
// ----------------------------------------------------------------------------
TestTempFile();
#endif // TEST_FILE
-#ifdef TEST_FILENAME
- TestFileNameTemp();
- TestFileNameCwd();
- TestFileNameDirManip();
- TestFileNameComparison();
- TestFileNameOperations();
-#endif // TEST_FILENAME
-
-#ifdef TEST_FILETIME
- TestFileGetTimes();
- #if 0
- TestFileSetTimes();
- #endif
-#endif // TEST_FILETIME
-
#ifdef TEST_FTP
wxLog::AddTraceMask(FTP_TRACE_MASK);
#include "wx/filename.h"
#include "wx/filefn.h"
+#include "wx/stdpaths.h"
#ifdef __WXMSW__
#include "wx/msw/registry.h"
#endif // __WINDOWS__
CPPUNIT_TEST( TestUNC );
CPPUNIT_TEST( TestVolumeUniqueName );
+ CPPUNIT_TEST( TestCreateTempFileName );
+ CPPUNIT_TEST( TestGetTimes );
CPPUNIT_TEST_SUITE_END();
void TestConstruction();
#endif // __WINDOWS__
void TestUNC();
void TestVolumeUniqueName();
+ void TestCreateTempFileName();
+ void TestGetTimes();
DECLARE_NO_COPY_CLASS(FileNameTestCase)
};
{
const TestData& td = testData[n];
+ // take care of using the decimal point for the current locale before
+ // the actual comparison
+ wxString result_localized = wxString(td.result);
+ result_localized.Replace(".", wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER));
+
CPPUNIT_ASSERT_EQUAL
(
- td.result,
+ result_localized,
wxFileName::GetHumanReadableSize(td.size, "NA", td.prec, td.conv)
);
}
// also test the default convention value
- CPPUNIT_ASSERT_EQUAL( "1.4 MB", wxFileName::GetHumanReadableSize(1512993, "") );
+ wxString result_localized = wxString("1.4 MB");
+ result_localized.Replace(".", wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER));
+ CPPUNIT_ASSERT_EQUAL( result_localized, wxFileName::GetHumanReadableSize(1512993, "") );
}
void FileNameTestCase::TestStrip()
"Program Files\\setup.exe",
fn.GetFullPath(wxPATH_DOS) );
}
+
+void FileNameTestCase::TestCreateTempFileName()
+{
+ static const struct TestData
+ {
+ const char *prefix;
+ const char *expectedFolder;
+ bool shouldFail;
+ } testData[] =
+ {
+ { "", "$SYSTEM_TEMP", false },
+ { "foo", "$SYSTEM_TEMP", false },
+ { "..", "$SYSTEM_TEMP", false },
+ { "../bar", "..", false },
+ { "c:\\a\\place\\which\\does\\not\\exist", "", true },
+#ifdef __UNIX__
+ { "/tmp/foo", "/tmp", false },
+ { "/tmp/foo/bar", "", true },
+#endif // __UNIX__
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(testData); n++ )
+ {
+ wxString path = wxFileName::CreateTempFileName(testData[n].prefix);
+ CPPUNIT_ASSERT_EQUAL( path.empty(), testData[n].shouldFail );
+
+ if (!testData[n].shouldFail)
+ {
+ // test the place where the temp file has been created
+ wxString expected = testData[n].expectedFolder;
+ expected.Replace("$SYSTEM_TEMP", wxStandardPaths::Get().GetTempDir());
+ CPPUNIT_ASSERT_EQUAL(expected, wxFileName(path).GetPath());
+
+ // the temporary file is created with full permissions for the current process
+ // so we should always be able to remove it:
+ CPPUNIT_ASSERT( wxRemoveFile(path) );
+ }
+ }
+}
+
+void FileNameTestCase::TestGetTimes()
+{
+ wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
+ CPPUNIT_ASSERT( fn.IsOk() );
+
+ wxDateTime dtAccess, dtMod, dtCreate;
+ CPPUNIT_ASSERT( fn.GetTimes(&dtAccess, &dtMod, &dtCreate) );
+
+ // make sure all retrieved dates are equal to the current date&time
+ // with an accuracy up to 1 minute
+ CPPUNIT_ASSERT(dtCreate.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
+ CPPUNIT_ASSERT(dtMod.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
+ CPPUNIT_ASSERT(dtAccess.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
+}