PathTest.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. //
  2. // System.IO.Path Test Cases
  3. //
  4. // Authors:
  5. // Marcin Szczepanski ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. // Ben Maurer ([email protected])
  8. // Gilles Freart ([email protected])
  9. // Atsushi Enomoto ([email protected])
  10. //
  11. // (c) Marcin Szczepanski
  12. // (c) 2002 Ximian, Inc. (http://www.ximian.com)
  13. // (c) 2003 Ben Maurer
  14. // (c) 2003 Gilles Freart
  15. //
  16. using NUnit.Framework;
  17. using System.IO;
  18. using System;
  19. using System.Text;
  20. namespace MonoTests.System.IO
  21. {
  22. enum OsType {
  23. Windows,
  24. Unix,
  25. Mac
  26. }
  27. [TestFixture]
  28. public class PathTest : Assertion
  29. {
  30. static string path1;
  31. static string path2;
  32. static string path3;
  33. static OsType OS;
  34. static char DSC = Path.DirectorySeparatorChar;
  35. [SetUp]
  36. public void SetUp ()
  37. {
  38. if ('/' == DSC) {
  39. OS = OsType.Unix;
  40. path1 = "/foo/test.txt";
  41. path2 = "/etc";
  42. path3 = "init.d";
  43. } else if ('\\' == DSC) {
  44. OS = OsType.Windows;
  45. path1 = "c:\\foo\\test.txt";
  46. path2 = Environment.GetEnvironmentVariable ("SYSTEMROOT");
  47. path3 = "system32";
  48. } else {
  49. OS = OsType.Mac;
  50. //FIXME: For Mac. figure this out when we need it
  51. path1 = "foo:test.txt";
  52. path2 = "foo";
  53. path3 = "bar";
  54. }
  55. }
  56. bool Windows
  57. {
  58. get {
  59. return OS == OsType.Windows;
  60. }
  61. }
  62. bool Unix
  63. {
  64. get {
  65. return OS == OsType.Unix;
  66. }
  67. }
  68. bool Mac
  69. {
  70. get {
  71. return OS == OsType.Mac;
  72. }
  73. }
  74. public void TestChangeExtension ()
  75. {
  76. string [] files = new string [3];
  77. files [(int) OsType.Unix] = "/foo/test.doc";
  78. files [(int) OsType.Windows] = "c:\\foo\\test.doc";
  79. files [(int) OsType.Mac] = "foo:test.doc";
  80. string testPath = Path.ChangeExtension (path1, "doc");
  81. AssertEquals ("ChangeExtension #01", files [(int) OS], testPath);
  82. testPath = Path.ChangeExtension ("", ".extension");
  83. AssertEquals ("ChangeExtension #02", String.Empty, testPath);
  84. testPath = Path.ChangeExtension (null, ".extension");
  85. AssertEquals ("ChangeExtension #03", null, testPath);
  86. testPath = Path.ChangeExtension ("path", null);
  87. AssertEquals ("ChangeExtension #04", "path", testPath);
  88. testPath = Path.ChangeExtension ("path.ext", "doc");
  89. AssertEquals ("ChangeExtension #05", "path.doc", testPath);
  90. testPath = Path.ChangeExtension ("path.ext1.ext2", "doc");
  91. AssertEquals ("ChangeExtension #06", "path.ext1.doc", testPath);
  92. testPath = Path.ChangeExtension ("hogehoge.xml", ".xsl");
  93. AssertEquals ("ChangeExtension #07", "hogehoge.xsl", testPath);
  94. testPath = Path.ChangeExtension ("hogehoge", ".xsl");
  95. AssertEquals ("ChangeExtension #08", "hogehoge.xsl", testPath);
  96. testPath = Path.ChangeExtension ("hogehoge.xml", "xsl");
  97. AssertEquals ("ChangeExtension #09", "hogehoge.xsl", testPath);
  98. testPath = Path.ChangeExtension ("hogehoge", "xsl");
  99. AssertEquals ("ChangeExtension #10", "hogehoge.xsl", testPath);
  100. testPath = Path.ChangeExtension ("hogehoge.xml", String.Empty);
  101. AssertEquals ("ChangeExtension #11", "hogehoge.", testPath);
  102. testPath = Path.ChangeExtension ("hogehoge", String.Empty);
  103. AssertEquals ("ChangeExtension #12", "hogehoge.", testPath);
  104. testPath = Path.ChangeExtension ("hogehoge.", null);
  105. AssertEquals ("ChangeExtension #13", "hogehoge", testPath);
  106. testPath = Path.ChangeExtension ("hogehoge", null);
  107. AssertEquals ("ChangeExtension #14", "hogehoge", testPath);
  108. testPath = Path.ChangeExtension (String.Empty, null);
  109. AssertEquals ("ChangeExtension #15", String.Empty, testPath);
  110. testPath = Path.ChangeExtension (String.Empty, "bashrc");
  111. AssertEquals ("ChangeExtension #16", String.Empty, testPath);
  112. testPath = Path.ChangeExtension (String.Empty, ".bashrc");
  113. AssertEquals ("ChangeExtension #17", String.Empty, testPath);
  114. testPath = Path.ChangeExtension (null, null);
  115. AssertNull ("ChangeExtension #18", testPath);
  116. if (Windows) {
  117. try {
  118. testPath = Path.ChangeExtension ("<", ".extension");
  119. Fail ("ChangeException Fail #01");
  120. } catch (Exception e) {
  121. AssertEquals ("ChangeExtension Exc. #01", typeof (ArgumentException), e.GetType ());
  122. }
  123. }
  124. }
  125. public void TestCombine ()
  126. {
  127. string [] files = new string [3];
  128. files [(int) OsType.Unix] = "/etc/init.d";
  129. files [(int) OsType.Windows] = Environment.GetEnvironmentVariable ("SYSTEMROOT") + @"\system32";
  130. files [(int) OsType.Mac] = "foo:bar";
  131. string testPath = Path.Combine (path2, path3);
  132. AssertEquals ("Combine #01", files [(int) OS], testPath);
  133. testPath = Path.Combine ("one", "");
  134. AssertEquals ("Combine #02", "one", testPath);
  135. testPath = Path.Combine ("", "one");
  136. AssertEquals ("Combine #03", "one", testPath);
  137. string current = Directory.GetCurrentDirectory ();
  138. testPath = Path.Combine (current, "one");
  139. string expected = current + DSC + "one";
  140. AssertEquals ("Combine #04", expected, testPath);
  141. testPath = Path.Combine ("one", current);
  142. // LAMESPEC noted in Path.cs
  143. AssertEquals ("Combine #05", current, testPath);
  144. testPath = Path.Combine (current, expected);
  145. AssertEquals ("Combine #06", expected, testPath);
  146. testPath = DSC + "one";
  147. testPath = Path.Combine (testPath, "two" + DSC);
  148. expected = DSC + "one" + DSC + "two" + DSC;
  149. AssertEquals ("Combine #06", expected, testPath);
  150. testPath = "one" + DSC;
  151. testPath = Path.Combine (testPath, DSC + "two");
  152. expected = DSC + "two";
  153. AssertEquals ("Combine #06", expected, testPath);
  154. testPath = "one" + DSC;
  155. testPath = Path.Combine (testPath, "two" + DSC);
  156. expected = "one" + DSC + "two" + DSC;
  157. AssertEquals ("Combine #07", expected, testPath);
  158. //TODO: Tests for UNC names
  159. try {
  160. testPath = Path.Combine ("one", null);
  161. Fail ("Combine Fail #01");
  162. } catch (Exception e) {
  163. AssertEquals ("Combine Exc. #01", typeof (ArgumentNullException), e.GetType ());
  164. }
  165. try {
  166. testPath = Path.Combine (null, "one");
  167. Fail ("Combine Fail #02");
  168. } catch (Exception e) {
  169. AssertEquals ("Combine Exc. #02", typeof (ArgumentNullException), e.GetType ());
  170. }
  171. if (Windows) {
  172. try {
  173. testPath = Path.Combine ("a>", "one");
  174. Fail ("Combine Fail #03");
  175. } catch (Exception e) {
  176. AssertEquals ("Combine Exc. #03", typeof (ArgumentException), e.GetType ());
  177. }
  178. try {
  179. testPath = Path.Combine ("one", "aaa<");
  180. Fail ("Combine Fail #04");
  181. } catch (Exception e) {
  182. AssertEquals ("Combine Exc. #04", typeof (ArgumentException), e.GetType ());
  183. }
  184. }
  185. }
  186. [Test]
  187. [ExpectedException (typeof(ArgumentException))]
  188. public void EmptyDirectoryName ()
  189. {
  190. string testDirName = Path.GetDirectoryName ("");
  191. }
  192. public void TestDirectoryName ()
  193. {
  194. string [] files = new string [3];
  195. files [(int) OsType.Unix] = "/foo";
  196. files [(int) OsType.Windows] = "c:\\foo";
  197. files [(int) OsType.Mac] = "foo";
  198. AssertEquals ("GetDirectoryName #01", null, Path.GetDirectoryName (null));
  199. string testDirName = Path.GetDirectoryName (path1);
  200. AssertEquals ("GetDirectoryName #02", files [(int) OS], testDirName);
  201. testDirName = Path.GetDirectoryName (files [(int) OS] + DSC);
  202. AssertEquals ("GetDirectoryName #03", files [(int) OS], testDirName);
  203. if (Windows) {
  204. try {
  205. testDirName = Path.GetDirectoryName ("aaa>");
  206. Fail ("GetDirectoryName Fail #02");
  207. } catch (Exception e) {
  208. AssertEquals ("GetDirectoryName Exc. #02", typeof (ArgumentException), e.GetType ());
  209. }
  210. }
  211. try {
  212. testDirName = Path.GetDirectoryName (" ");
  213. Fail ("GetDirectoryName Fail #03");
  214. } catch (Exception e) {
  215. AssertEquals ("GetDirectoryName Exc. #03", typeof (ArgumentException), e.GetType ());
  216. }
  217. }
  218. public void TestGetExtension ()
  219. {
  220. string testExtn = Path.GetExtension (path1);
  221. AssertEquals ("GetExtension #01", ".txt", testExtn);
  222. testExtn = Path.GetExtension (path2);
  223. AssertEquals ("GetExtension #02", String.Empty, testExtn);
  224. testExtn = Path.GetExtension (String.Empty);
  225. AssertEquals ("GetExtension #03", String.Empty, testExtn);
  226. testExtn = Path.GetExtension (null);
  227. AssertEquals ("GetExtension #04", null, testExtn);
  228. testExtn = Path.GetExtension (" ");
  229. AssertEquals ("GetExtension #05", String.Empty, testExtn);
  230. testExtn = Path.GetExtension (path1 + ".doc");
  231. AssertEquals ("GetExtension #06", ".doc", testExtn);
  232. testExtn = Path.GetExtension (path1 + ".doc" + DSC + "a.txt");
  233. AssertEquals ("GetExtension #07", ".txt", testExtn);
  234. testExtn = Path.GetExtension (".");
  235. AssertEquals ("GetExtension #08", String.Empty, testExtn);
  236. testExtn = Path.GetExtension ("end.");
  237. AssertEquals ("GetExtension #09", String.Empty, testExtn);
  238. testExtn = Path.GetExtension (".start");
  239. AssertEquals ("GetExtension #10", ".start", testExtn);
  240. testExtn = Path.GetExtension (".a");
  241. AssertEquals ("GetExtension #11", ".a", testExtn);
  242. testExtn = Path.GetExtension ("a.");
  243. AssertEquals ("GetExtension #12", String.Empty, testExtn);
  244. testExtn = Path.GetExtension ("a");
  245. AssertEquals ("GetExtension #13", String.Empty, testExtn);
  246. testExtn = Path.GetExtension ("makefile");
  247. AssertEquals ("GetExtension #14", String.Empty, testExtn);
  248. if (Windows) {
  249. try {
  250. testExtn = Path.GetExtension ("hi<there.txt");
  251. Fail ("GetExtension Fail #01");
  252. } catch (Exception e) {
  253. AssertEquals ("GetExtension Exc. #01", typeof (ArgumentException), e.GetType ());
  254. }
  255. }
  256. }
  257. public void TestGetFileName ()
  258. {
  259. string testFileName = Path.GetFileName (path1);
  260. AssertEquals ("GetFileName #01", "test.txt", testFileName);
  261. testFileName = Path.GetFileName (null);
  262. AssertEquals ("GetFileName #02", null, testFileName);
  263. testFileName = Path.GetFileName (String.Empty);
  264. AssertEquals ("GetFileName #03", String.Empty, testFileName);
  265. testFileName = Path.GetFileName (" ");
  266. AssertEquals ("GetFileName #04", " ", testFileName);
  267. if (Windows) {
  268. try {
  269. testFileName = Path.GetFileName ("hi<");
  270. Fail ("GetFileName Fail #01");
  271. } catch (Exception e) {
  272. AssertEquals ("GetFileName Exc. #01", typeof (ArgumentException), e.GetType ());
  273. }
  274. }
  275. }
  276. public void TestGetFileNameWithoutExtension ()
  277. {
  278. string testFileName = Path.GetFileNameWithoutExtension (path1);
  279. AssertEquals ("GetFileNameWithoutExtension #01", "test", testFileName);
  280. testFileName = Path.GetFileNameWithoutExtension (null);
  281. AssertEquals ("GetFileNameWithoutExtension #02", null, testFileName);
  282. testFileName = Path.GetFileNameWithoutExtension (String.Empty);
  283. AssertEquals ("GetFileNameWithoutExtension #03", String.Empty, testFileName);
  284. }
  285. [Ignore("This does not work under windows. See ERROR comments below.")]
  286. public void TestGetFullPath ()
  287. {
  288. string current = Directory.GetCurrentDirectory ();
  289. string testFullPath = Path.GetFullPath ("foo.txt");
  290. string expected = current + DSC + "foo.txt";
  291. AssertEquals ("GetFullPath #01", expected, testFullPath);
  292. testFullPath = Path.GetFullPath ("a//./.././foo.txt");
  293. AssertEquals ("GetFullPath #02", expected, testFullPath);
  294. string root = Windows ? "C:\\" : "/";
  295. string [,] test = new string [,] {
  296. {"root////././././././../root/././../root", "root"},
  297. {"root/", "root/"},
  298. {"root/./", "root/"},
  299. {"root/./", "root/"},
  300. {"root/../", ""},
  301. {"root/../", ""},
  302. {"root/../..", ""},
  303. {"root/.hiddenfile", "root/.hiddenfile"},
  304. {"root/. /", "root/. /"},
  305. {"root/.. /", "root/.. /"},
  306. {"root/..weirdname", "root/..weirdname"},
  307. {"root/..", ""},
  308. {"root/../a/b/../../..", ""},
  309. {"root/./..", ""},
  310. {"..", ""},
  311. {".", ""},
  312. {"root//dir", "root/dir"},
  313. {"root/. /", "root/. /"},
  314. {"root/.. /", "root/.. /"},
  315. {"root/ . /", "root/ . /"},
  316. {"root/ .. /", "root/ .. /"},
  317. {"root/./", "root/"},
  318. //ERROR! Paths are trimmed
  319. {"root/.. /", "root/.. /"},
  320. {".//", ""}
  321. };
  322. //ERROR! GetUpperBound (1) returns 1. GetUpperBound (0) == 23
  323. //... so only the first test was being done.
  324. for (int i = 0; i < test.GetUpperBound (1); i++) {
  325. AssertEquals (String.Format ("GetFullPath #{0}", i), root + test [i, 1], Path.GetFullPath (root + test [i, 0]));
  326. }
  327. if (Windows) {
  328. string uncroot = @"\\server\share\";
  329. string [,] testunc = new string [,] {
  330. {"root////././././././../root/././../root", "root"},
  331. {"root/", "root/"},
  332. {"root/./", "root/"},
  333. {"root/./", "root/"},
  334. {"root/../", ""},
  335. {"root/../", ""},
  336. {"root/../..", ""},
  337. {"root/.hiddenfile", "root/.hiddenfile"},
  338. {"root/. /", "root/. /"},
  339. {"root/.. /", "root/.. /"},
  340. {"root/..weirdname", "root/..weirdname"},
  341. {"root/..", ""},
  342. {"root/../a/b/../../..", ""},
  343. {"root/./..", ""},
  344. {"..", ""},
  345. {".", ""},
  346. {"root//dir", "root/dir"},
  347. {"root/. /", "root/. /"},
  348. {"root/.. /", "root/.. /"},
  349. {"root/ . /", "root/ . /"},
  350. {"root/ .. /", "root/ .. /"},
  351. {"root/./", "root/"},
  352. {"root/.. /", "root/.. /"},
  353. {".//", ""}
  354. };
  355. for (int i = 0; i < test.GetUpperBound (1); i++) {
  356. AssertEquals (String.Format ("GetFullPath UNC #{0}", i), uncroot + test [i, 1], Path.GetFullPath (uncroot + test [i, 0]));
  357. }
  358. }
  359. try {
  360. testFullPath = Path.GetFullPath (null);
  361. Fail ("GetFullPath Fail #01");
  362. } catch (Exception e) {
  363. AssertEquals ("GetFullPath Exc. #01", typeof (ArgumentNullException), e.GetType ());
  364. }
  365. try {
  366. testFullPath = Path.GetFullPath (String.Empty);
  367. Fail ("GetFullPath Fail #02");
  368. } catch (Exception e) {
  369. AssertEquals ("GetFullPath Exc. #02", typeof (ArgumentException), e.GetType ());
  370. }
  371. }
  372. public void TestGetFullPath2 ()
  373. {
  374. if (Windows) {
  375. AssertEquals ("GetFullPath w#01", @"Z:\", Path.GetFullPath ("Z:"));
  376. AssertEquals ("GetFullPath w#02", @"c:\abc\def", Path.GetFullPath (@"c:\abc\def"));
  377. Assert ("GetFullPath w#03", Path.GetFullPath (@"\").EndsWith (@"\"));
  378. // "\\\\" is not allowed
  379. Assert ("GetFullPath w#05", Path.GetFullPath ("/").EndsWith (@"\"));
  380. // "//" is not allowed
  381. Assert ("GetFullPath w#07", Path.GetFullPath ("readme.txt").EndsWith (@"\readme.txt"));
  382. Assert ("GetFullPath w#08", Path.GetFullPath ("c").EndsWith (@"\c"));
  383. Assert ("GetFullPath w#09", Path.GetFullPath (@"abc\def").EndsWith (@"abc\def"));
  384. Assert ("GetFullPath w#10", Path.GetFullPath (@"\abc\def").EndsWith (@"\abc\def"));
  385. AssertEquals ("GetFullPath w#11", @"\\abc\def", Path.GetFullPath (@"\\abc\def"));
  386. AssertEquals ("GetFullPath w#12", Directory.GetCurrentDirectory () + @"\abc\def", Path.GetFullPath (@"abc//def"));
  387. AssertEquals ("GetFullPath w#13", Directory.GetCurrentDirectory ().Substring (0,2) + @"\abc\def", Path.GetFullPath ("/abc/def"));
  388. AssertEquals ("GetFullPath w#14", @"\\abc\def", Path.GetFullPath ("//abc/def"));
  389. }
  390. }
  391. public void TestGetPathRoot ()
  392. {
  393. string current;
  394. string expected;
  395. if (!Windows){
  396. current = Directory.GetCurrentDirectory ();
  397. expected = current [0].ToString ();
  398. } else {
  399. current = @"J:\Some\Strange Directory\Name";
  400. expected = "J:\\";
  401. }
  402. string pathRoot = Path.GetPathRoot (current);
  403. AssertEquals ("GetPathRoot #01", expected, pathRoot);
  404. pathRoot = Path.GetPathRoot ("hola");
  405. AssertEquals ("GetPathRoot #02", String.Empty, pathRoot);
  406. pathRoot = Path.GetPathRoot (null);
  407. AssertEquals ("GetPathRoot #03", null, pathRoot);
  408. if (Windows) {
  409. AssertEquals ("GetPathRoot w#01", "z:", Path.GetPathRoot ("z:"));
  410. AssertEquals ("GetPathRoot w#02", "c:\\", Path.GetPathRoot ("c:\\abc\\def"));
  411. AssertEquals ("GetPathRoot w#03", "\\", Path.GetPathRoot ("\\"));
  412. AssertEquals ("GetPathRoot w#04", "\\\\", Path.GetPathRoot ("\\\\"));
  413. AssertEquals ("GetPathRoot w#05", "\\", Path.GetPathRoot ("/"));
  414. AssertEquals ("GetPathRoot w#06", "\\\\", Path.GetPathRoot ("//"));
  415. AssertEquals ("GetPathRoot w#07", String.Empty, Path.GetPathRoot ("readme.txt"));
  416. AssertEquals ("GetPathRoot w#08", String.Empty, Path.GetPathRoot ("c"));
  417. AssertEquals ("GetPathRoot w#09", String.Empty, Path.GetPathRoot ("abc\\def"));
  418. AssertEquals ("GetPathRoot w#10", "\\", Path.GetPathRoot ("\\abc\\def"));
  419. AssertEquals ("GetPathRoot w#11", "\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def"));
  420. AssertEquals ("GetPathRoot w#12", String.Empty, Path.GetPathRoot ("abc//def"));
  421. AssertEquals ("GetPathRoot w#13", "\\", Path.GetPathRoot ("/abc/def"));
  422. AssertEquals ("GetPathRoot w#14", "\\\\abc\\def", Path.GetPathRoot ("//abc/def"));
  423. } else {
  424. // TODO: Same tests for Unix.
  425. }
  426. }
  427. public void TestGetTempPath ()
  428. {
  429. string getTempPath = Path.GetTempPath ();
  430. Assert ("GetTempPath #01", getTempPath != String.Empty);
  431. Assert ("GetTempPath #02", Path.IsPathRooted (getTempPath));
  432. AssertEquals ("GetTempPath #03", Path.DirectorySeparatorChar, getTempPath [getTempPath.Length - 1]);
  433. }
  434. public void TestGetTempFileName ()
  435. {
  436. string getTempFileName = null;
  437. try {
  438. getTempFileName = Path.GetTempFileName ();
  439. Assert ("GetTempFileName #01", getTempFileName != String.Empty);
  440. Assert ("GetTempFileName #02", File.Exists (getTempFileName));
  441. } finally {
  442. if (getTempFileName != null && getTempFileName != String.Empty){
  443. File.Delete (getTempFileName);
  444. }
  445. }
  446. }
  447. public void TestHasExtension ()
  448. {
  449. AssertEquals ("HasExtension #01", true, Path.HasExtension ("foo.txt"));
  450. AssertEquals ("HasExtension #02", false, Path.HasExtension ("foo"));
  451. AssertEquals ("HasExtension #03", true, Path.HasExtension (path1));
  452. AssertEquals ("HasExtension #04", false, Path.HasExtension (path2));
  453. AssertEquals ("HasExtension #05", false, Path.HasExtension (null));
  454. AssertEquals ("HasExtension #06", false, Path.HasExtension (String.Empty));
  455. AssertEquals ("HasExtension #07", false, Path.HasExtension (" "));
  456. AssertEquals ("HasExtension #08", false, Path.HasExtension ("."));
  457. AssertEquals ("HasExtension #09", false, Path.HasExtension ("end."));
  458. AssertEquals ("HasExtension #10", true, Path.HasExtension (".start"));
  459. AssertEquals ("HasExtension #11", true, Path.HasExtension (".a"));
  460. AssertEquals ("HasExtension #12", false, Path.HasExtension ("a."));
  461. AssertEquals ("HasExtension #13", false, Path.HasExtension ("Makefile"));
  462. }
  463. public void TestRooted ()
  464. {
  465. Assert ("IsPathRooted #01", Path.IsPathRooted (path2));
  466. Assert ("IsPathRooted #02", !Path.IsPathRooted (path3));
  467. Assert ("IsPathRooted #03", !Path.IsPathRooted (null));
  468. Assert ("IsPathRooted #04", !Path.IsPathRooted (String.Empty));
  469. Assert ("IsPathRooted #05", !Path.IsPathRooted (" "));
  470. Assert ("IsPathRooted #06", Path.IsPathRooted ("/"));
  471. Assert ("IsPathRooted #07", Path.IsPathRooted ("\\"));
  472. Assert ("IsPathRooted #08", Path.IsPathRooted ("//"));
  473. Assert ("IsPathRooted #09", Path.IsPathRooted ("\\\\"));
  474. Assert ("IsPathRooted #10", !Path.IsPathRooted (":"));
  475. if (Windows)
  476. Assert ("IsPathRooted #11", Path.IsPathRooted ("z:"));
  477. else
  478. Assert ("IsPathRooted #11", !Path.IsPathRooted ("z:"));
  479. if (Windows) {
  480. Assert ("IsPathRooted #12", Path.IsPathRooted ("z:\\"));
  481. Assert ("IsPathRooted #13", Path.IsPathRooted ("z:\\topdir"));
  482. // This looks MS BUG. It is treated as absolute path
  483. Assert ("IsPathRooted #14", Path.IsPathRooted ("z:curdir"));
  484. Assert ("IsPathRooted #15", Path.IsPathRooted ("\\abc\\def"));
  485. }
  486. }
  487. public void TestCanonicalizeDots ()
  488. {
  489. string current = Path.GetFullPath (".");
  490. Assert ("TestCanonicalizeDotst #01", !current.EndsWith ("."));
  491. string parent = Path.GetFullPath ("..");
  492. Assert ("TestCanonicalizeDotst #02", !current.EndsWith (".."));
  493. }
  494. public void TestDirectoryNameBugs ()
  495. {
  496. if (Windows) {
  497. AssertEquals ("Win #01", "C:\\foo", Path.GetDirectoryName ("C:\\foo\\foo.txt"));
  498. } else {
  499. AssertEquals ("No win #01", "/etc", Path.GetDirectoryName ("/etc/hostname"));
  500. }
  501. }
  502. public void TestGetFullPathUnix ()
  503. {
  504. if (Windows)
  505. return;
  506. AssertEquals ("#01", "/", Path.GetFullPath ("/"));
  507. AssertEquals ("#02", "/hey", Path.GetFullPath ("/hey"));
  508. AssertEquals ("#03", Environment.CurrentDirectory, Path.GetFullPath ("."));
  509. AssertEquals ("#04", Path.Combine (Environment.CurrentDirectory, "hey"),
  510. Path.GetFullPath ("hey"));
  511. }
  512. }
  513. }