+
+void FileNameTestCase::TestUNC()
+{
+ wxFileName fn("//share/path/name.ext", wxPATH_DOS);
+ CPPUNIT_ASSERT_EQUAL( "share", fn.GetVolume() );
+ CPPUNIT_ASSERT_EQUAL( "\\path", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
+
+ fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS);
+ CPPUNIT_ASSERT_EQUAL( "share2", fn.GetVolume() );
+ CPPUNIT_ASSERT_EQUAL( "\\path2", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
+}
+
+void FileNameTestCase::TestVolumeUniqueName()
+{
+ wxFileName fn("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
+ wxPATH_DOS);
+ CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}",
+ fn.GetVolume() );
+ CPPUNIT_ASSERT_EQUAL( "\\", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
+ CPPUNIT_ASSERT_EQUAL( "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
+ fn.GetFullPath(wxPATH_DOS) );
+
+ fn.Assign("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\"
+ "Program Files\\setup.exe", wxPATH_DOS);
+ CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}",
+ fn.GetVolume() );
+ CPPUNIT_ASSERT_EQUAL( "\\Program Files",
+ 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()
+{
+ static const struct TestData
+ {
+ const char *prefix;
+ const char *expectedFolder;
+ bool shouldSucceed;
+ } testData[] =
+ {
+ { "", "$SYSTEM_TEMP", true },
+ { "foo", "$SYSTEM_TEMP", true },
+ { "..", "$SYSTEM_TEMP", true },
+ { "../bar", "..", true },
+#ifdef __WXMSW__
+ { "$USER_DOCS_DIR\\", "$USER_DOCS_DIR", true },
+ { "c:\\a\\directory\\which\\does\\not\\exist", "", false },
+#elif defined( __UNIX__ )
+ { "$USER_DOCS_DIR/", "$USER_DOCS_DIR", true },
+ { "/tmp/foo", "/tmp", true },
+ { "/tmp/a/directory/which/does/not/exist", "", false },
+#endif // __UNIX__
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(testData); n++ )
+ {
+ wxString prefix = testData[n].prefix;
+ prefix.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir());
+
+ std::string errDesc = wxString::Format("failed on prefix '%s'", prefix).ToStdString();
+
+ wxString path = wxFileName::CreateTempFileName(prefix);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( errDesc, !testData[n].shouldSucceed, path.empty() );
+
+ if (testData[n].shouldSucceed)
+ {
+ errDesc += "; path is " + path.ToStdString();
+
+ // test the place where the temp file has been created
+ wxString expected = testData[n].expectedFolder;
+ expected.Replace("$SYSTEM_TEMP", wxStandardPaths::Get().GetTempDir());
+ expected.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( errDesc, 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_MESSAGE( errDesc, 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)));
+}