+void FileNameTestCase::TestNormalize()
+{
+ // prepare some data to be used later
+ wxString sep = wxFileName::GetPathSeparator();
+ wxString cwd = wxGetCwd();
+ wxString home = wxGetUserHome();
+
+ cwd.Replace(sep, wxT("/"));
+ if (cwd.Last() != wxT('/'))
+ cwd += wxT('/');
+ home.Replace(sep, wxT("/"));
+ if (home.Last() != wxT('/'))
+ home += wxT('/');
+
+ // since we will always be testing paths using the wxPATH_UNIX
+ // format, we need to remove the volume, if present
+ if (home.Contains(wxT(':')))
+ home = home.AfterFirst(wxT(':'));
+ if (cwd.Contains(wxT(':')))
+ cwd = cwd.AfterFirst(wxT(':'));
+
+ static const struct FileNameTest
+ {
+ wxString original;
+ int flags;
+ wxString expected;
+ wxPathFormat fmt;
+ } tests[] =
+ {
+ // test wxPATH_NORM_ENV_VARS
+#ifdef __WXMSW__
+ { "%ABCDEF%/g/h/i", wxPATH_NORM_ENV_VARS, "abcdef/g/h/i", wxPATH_UNIX },
+#else
+ { "$(ABCDEF)/g/h/i", wxPATH_NORM_ENV_VARS, "abcdef/g/h/i", wxPATH_UNIX },
+#endif
+
+ // test wxPATH_NORM_DOTS
+ { "a/.././b/c/../../", wxPATH_NORM_DOTS, "", wxPATH_UNIX },
+
+ // test wxPATH_NORM_TILDE
+ // NB: do the tilde expansion also under Windows to test if it works there too
+ { "/a/b/~", wxPATH_NORM_TILDE, "/a/b/~", wxPATH_UNIX },
+ { "/~/a/b", wxPATH_NORM_TILDE, home + "a/b", wxPATH_UNIX },
+ { "~/a/b", wxPATH_NORM_TILDE, home + "a/b", wxPATH_UNIX },
+
+ // test wxPATH_NORM_CASE
+ { "Foo", wxPATH_NORM_CASE, "Foo", wxPATH_UNIX },
+ { "Foo", wxPATH_NORM_CASE, "foo", wxPATH_DOS },
+ { "C:\\Program Files\\wx", wxPATH_NORM_CASE,
+ "c:\\program files\\wx", wxPATH_DOS },
+ { "C:/Program Files/wx", wxPATH_NORM_ALL | wxPATH_NORM_CASE,
+ "c:\\program files\\wx", wxPATH_DOS },
+ { "C:\\Users\\zeitlin", wxPATH_NORM_ALL | wxPATH_NORM_CASE,
+ "c:\\users\\zeitlin", wxPATH_DOS },
+
+ // test wxPATH_NORM_ABSOLUTE
+ { "a/b/", wxPATH_NORM_ABSOLUTE, cwd + "a/b/", wxPATH_UNIX },
+ { "a/b/c.ext", wxPATH_NORM_ABSOLUTE, cwd + "a/b/c.ext", wxPATH_UNIX },
+ { "/a", wxPATH_NORM_ABSOLUTE, "/a", wxPATH_UNIX },
+
+ // test giving no flags at all to Normalize()
+ { "a/b/", 0, "a/b/", wxPATH_UNIX },
+ { "a/b/c.ext", 0, "a/b/c.ext", wxPATH_UNIX },
+ { "/a", 0, "/a", wxPATH_UNIX }
+ };
+
+ // set the env var ABCDEF
+ wxSetEnv(_T("ABCDEF"), _T("abcdef"));
+
+ for ( size_t i = 0; i < WXSIZEOF(tests); i++ )
+ {
+ const FileNameTest& fnt = tests[i];
+ wxFileName fn(fnt.original, fnt.fmt);
+
+ // be sure this normalization does not fail
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ (const char *)wxString::Format(_T("Normalize(%s) failed"), fnt.original).mb_str(),
+ fn.Normalize(fnt.flags, cwd, fnt.fmt)
+ );
+
+ // compare result with expected string
+ CPPUNIT_ASSERT_EQUAL( fnt.expected, fn.GetFullPath(fnt.fmt) );
+ }
+}
+
+wxString wxTestStripExtension(wxString szFile)
+{
+ wxStripExtension(szFile);
+ return szFile;
+}
+
+void FileNameTestCase::TestStrip()
+{
+ //test a crash
+ CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T("")) );
+
+ //others
+ CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".")) );
+ CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".wav")) );
+ CPPUNIT_ASSERT_EQUAL( wxString(_T("good")), wxTestStripExtension(_T("good.wav")) );
+ CPPUNIT_ASSERT_EQUAL( wxString(_T("good.wav")), wxTestStripExtension(_T("good.wav.wav")) );
+}
+
+#ifdef __WINDOWS__
+
+void FileNameTestCase::TestShortLongPath()
+{
+ wxFileName fn(_T("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"));
+
+ // incredibly enough, GetLongPath() used to return different results during
+ // the first and subsequent runs, test for this
+ CPPUNIT_ASSERT_EQUAL( fn.GetLongPath(), fn.GetLongPath() );
+ CPPUNIT_ASSERT_EQUAL( fn.GetShortPath(), fn.GetShortPath() );
+}
+
+#endif // __WINDOWS__