Assert.AreEqual ("one", testPath, "Combine #03");
string current = Directory.GetCurrentDirectory ();
+ bool currentIsDSC = current.Length == 1 && current [0] == DSC;
testPath = Path.Combine (current, "one");
- string expected = current + DSC + "one";
+ string expected = (currentIsDSC ? String.Empty : current) + DSC + "one";
Assert.AreEqual (expected, testPath, "Combine #04");
testPath = Path.Combine ("one", current);
expected = "one" + DSC + "two" + DSC;
Assert.AreEqual (expected, testPath, "Combine #07");
-#if NET_4_0
Assert.AreEqual ("a", Path.Combine (new [] { "a", "" }), "Combine #08");
-#endif
}
[Test]
public void GetFullPath ()
{
string current = Directory.GetCurrentDirectory ();
-
+ bool currentIsDSC = current.Length == 1 && current [0] == DSC;
string testFullPath = Path.GetFullPath ("foo.txt");
- string expected = current + DSC + "foo.txt";
+ string expected = (currentIsDSC ? String.Empty : current) + DSC + "foo.txt";
Assert.AreEqual (expected, testFullPath, "GetFullPath #01");
testFullPath = Path.GetFullPath ("a//./.././foo.txt");
Assert.AreEqual (expected, testFullPath, "GetFullPath #02");
+
+ if (!Windows){
+ Assert.AreEqual ("/bin/bash", Path.GetFullPath ("/../bin/bash"));
+ }
+
}
[Test]
public void GetFullPath_Unix ()
{
if (Windows)
- return;
+ Assert.Ignore ("Running on Windows.");
string root = "/";
string [,] test = new string [,] {
Assert.AreEqual (Environment.CurrentDirectory, Path.GetFullPath ("."), "#03");
Assert.AreEqual (Path.Combine (Environment.CurrentDirectory, "hey"),
Path.GetFullPath ("hey"), "#04");
+ Assert.AreEqual ("/", Path.GetFullPath ("/"), "#01");
+
+ string curdir = Directory.GetCurrentDirectory ();
+ try {
+ Directory.SetCurrentDirectory ("/");
+ Assert.AreEqual ("/test.txt", Path.GetFullPath ("test.txt"), "xambug #833");
+ }
+ finally {
+ Directory.SetCurrentDirectory (curdir);
+ }
}
[Test]
public void GetFullPath_Windows ()
{
if (!Windows)
- return;
+ Assert.Ignore ("Not running on Windows.");
string root = "C:\\";
string [,] test = new string [,] {
{"root//dir", "root\\dir"},
{"root/. /", "root\\"},
{"root/.. /", ""},
-#if !NET_2_0
- {"root/ . /", "root\\"},
- {"root/ .. /", ""},
-#endif
{"root/./", "root\\"},
{"root/.. /", ""},
{".//", ""}
{"root//dir", "root\\dir"},
{"root/. /", "root\\"},
{"root/.. /", ""},
-#if !NET_2_0
- {"root/ . /", "root\\"},
- {"root/ .. /", ""},
-#endif
{"root/./", "root\\"},
{"root/.. /", ""},
{".//", ""}
{"root//dir", "root\\dir"},
{"root/. /", "root\\"},
{"root/.. /", ""},
-#if !NET_2_0
- {"root/ . /", "root\\"},
- {"root/ .. /", ""},
-#endif
{"root/./", "root\\"},
{"root/.. /", ""},
{".//", ""}
i, root + test [i, 0], ex.GetType ()));
}
}
+
+ // These cases require that we don't pass a root to GetFullPath - it should return the proper drive root.
+ string root4 = Path.GetPathRoot(Directory.GetCurrentDirectory());
+ Assert.AreEqual(root4, Path.GetFullPath(@"\"));
+ Assert.AreEqual(root4, Path.GetFullPath("/"));
}
[Test]
{
if (Windows) {
Assert.AreEqual (@"Z:\", Path.GetFullPath ("Z:"), "GetFullPath w#01");
-#if !TARGET_JVM // Java full (canonical) path always starts with caps drive letter
Assert.AreEqual (@"c:\abc\def", Path.GetFullPath (@"c:\abc\def"), "GetFullPath w#02");
-#endif
Assert.IsTrue (Path.GetFullPath (@"\").EndsWith (@"\"), "GetFullPath w#03");
// "\\\\" is not allowed
Assert.IsTrue (Path.GetFullPath ("/").EndsWith (@"\"), "GetFullPath w#05");
}
[Test]
-#if ONLY_1_1
- [Category ("NotWorking")] // we also throw ArgumentException on 1.0 profile
-#endif
public void GetPathRoot_Path_InvalidPathChars ()
{
-#if NET_2_0
try {
Path.GetPathRoot ("hi\0world");
Assert.Fail ("#1");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
-#else
- Assert.AreEqual (String.Empty, Path.GetPathRoot ("hi\0world"));
-#endif
}
[Test]
// http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
int platform = (int) Environment.OSVersion.Platform;
if ((platform == 4) || (platform == 128) || (platform == 6))
- return;
+ Assert.Ignore ("Running on Unix.");
string curdir = Directory.GetCurrentDirectory ();
try {
-#if TARGET_JVM
- string system = "C:\\WINDOWS\\system32\\";
-#else
string system = Environment.SystemDirectory;
-#endif
Directory.SetCurrentDirectory (system);
string drive = system.Substring (0, 2);
Assert.AreEqual (system, Path.GetFullPath (drive), "current dir");
// http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
int platform = (int) Environment.OSVersion.Platform;
if ((platform == 4) || (platform == 128) || (platform == 6))
- return;
+ Assert.Ignore ("Running on Unix.");
string curdir = Directory.GetCurrentDirectory ();
try {
-#if TARGET_JVM
- string system = "C:\\WINDOWS\\system32\\";
-#else
string system = Environment.SystemDirectory;
-#endif
Directory.SetCurrentDirectory (system);
// e.g. C:dir (no backslash) will return CurrentDirectory + dir
string dir = system.Substring (0, 2) + "dir";
}
#endif
[Test]
-#if TARGET_JVM
- [Ignore("Java full (canonical) path always returns windows dir in caps")]
-#endif
public void WindowsDriveC14N_77058 ()
{
// check for Unix platforms - see FAQ for more details
// http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
int platform = (int) Environment.OSVersion.Platform;
if ((platform == 4) || (platform == 128) || (platform == 6))
- return;
+ Assert.Ignore ("Running on Unix.");
Assert.AreEqual (@"C:\Windows\dir", Path.GetFullPath (@"C:\Windows\System32\..\dir"), "1");
Assert.AreEqual (@"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\dir"), "2");
{
char[] invalid = Path.InvalidPathChars;
if (Windows) {
-#if NET_2_0
Assert.AreEqual (36, invalid.Length, "Length");
-#else
- Assert.AreEqual (15, invalid.Length, "Length");
-#endif
+
foreach (char c in invalid) {
int i = (int) c;
-#if NET_2_0
+
if (i < 32)
continue;
-#else
- if ((i == 0) || (i == 8) || ((i > 15) && (i < 19)) || ((i > 19) && (i < 26)))
- continue;
-#endif
+
// in both 1.1 SP1 and 2.0
if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
continue;
}
}
-#if NET_2_0
[Test]
public void GetInvalidFileNameChars_Values ()
{
}
}
}
-#endif
-#if NET_4_0
+
string Concat (string sep, params string [] parms)
{
return String.Join (sep, parms);
Assert.AreEqual ("", Path.Combine ("", "", "", "", ""), "#A4");
}
-#endif
}
}