+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 struct FileNameTest
+ {
+ const wxChar *original;
+ int flags;
+ wxString expected;
+ } tests[] =
+ {
+ // test wxPATH_NORM_ENV_VARS
+#ifdef __WXMSW__
+ { wxT("%ABCDEF%/g/h/i"), wxPATH_NORM_ENV_VARS, wxT("abcdef/g/h/i") },
+#else
+ { wxT("$(ABCDEF)/g/h/i"), wxPATH_NORM_ENV_VARS, wxT("abcdef/g/h/i") },
+#endif
+
+ // test wxPATH_NORM_DOTS
+ { wxT("a/.././b/c/../../"), wxPATH_NORM_DOTS, wxT("") },
+
+ // test wxPATH_NORM_TILDE
+ // NB: do the tilde expansion also under Windows to test if it works there too
+ { wxT("/a/b/~"), wxPATH_NORM_TILDE, wxT("/a/b/~") },
+ { wxT("/~/a/b"), wxPATH_NORM_TILDE, home + wxT("a/b") },
+ { wxT("~/a/b"), wxPATH_NORM_TILDE, home + wxT("a/b") },
+
+ // test wxPATH_NORM_ABSOLUTE
+ { wxT("a/b/"), wxPATH_NORM_ABSOLUTE, cwd + wxT("a/b/") },
+ { wxT("a/b/c.ext"), wxPATH_NORM_ABSOLUTE, cwd + wxT("a/b/c.ext") },
+ { wxT("/a"), wxPATH_NORM_ABSOLUTE, wxT("/a") },
+
+ // test giving no flags at all to Normalize()
+ { wxT("a/b/"), 0, wxT("a/b/") },
+ { wxT("a/b/c.ext"), 0, wxT("a/b/c.ext") },
+ { wxT("/a"), 0, wxT("/a") }
+ };
+
+ // set the env var ABCDEF
+ wxSetEnv(_T("ABCDEF"), _T("abcdef"));
+
+ for ( size_t i = 0; i < WXSIZEOF(tests); i++ )
+ {
+ wxFileName fn(tests[i].original, wxPATH_UNIX);
+
+ // be sure this normalization does not fail
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ (const char *)wxString::Format(_T("Normalize(%s) failed"), tests[i].original).mb_str(),
+ fn.Normalize(tests[i].flags, cwd, wxPATH_UNIX)
+ );
+
+ // compare result with expected string
+ CPPUNIT_ASSERT_EQUAL( tests[i].expected, fn.GetFullPath(wxPATH_UNIX) );
+ }
+}
+