2 // System.IO.Path Test Cases
\r
4 // Author: Marcin Szczepanski (marcins@zipworld.com.au)
\r
6 // TODO: Add a more thorough workout for some
\r
7 // of the "trickier" functions.
\r
11 using NUnit.Framework;
\r
16 namespace MonoTests.System.IO
\r
19 public class PathTest : TestCase {
\r
25 public static ITest Suite {
\r
27 return new TestSuite(typeof(PathTest));
\r
31 public PathTest() : base ("MonoTests.System.IO.PathTest testcase") { }
\r
32 public PathTest( string name ): base(name) { }
\r
34 protected override void SetUp() {
\r
38 path1 = "c:\\foo\\test.txt";
\r
39 path2 = "c:\\winnt";
\r
44 path1 = "/foo/test.txt";
\r
50 path1 = "foo:test.txt";
\r
59 public void TestChangeExtension() {
\r
60 string testPath = Path.ChangeExtension( path1, "doc" );
\r
63 AssertEquals( "c:\\foo\\test.doc", testPath );
\r
65 AssertEquals( "/foo/test.doc", testPath );
\r
67 AssertEquals( "foo:test.doc", testPath );
\r
71 public void TestCombine() {
\r
72 string testPath = Path.Combine( path2, path3 );
\r
75 AssertEquals( "c:\\winnt\\system32", testPath );
\r
77 AssertEquals( "/etc/init.d", testPath );
\r
79 AssertEquals( "foo:bar", testPath );
\r
83 public void TestDirectoryName() {
\r
84 string testDirName = Path.GetDirectoryName( path1 );
\r
87 AssertEquals( "c:\\foo", testDirName );
\r
89 AssertEquals( "/etc", testDirName );
\r
91 AssertEquals( "foo", testDirName );
\r
95 public void TestGetExtension() {
\r
96 string testExtn = Path.GetExtension( path1 );
\r
98 AssertEquals( ".txt", testExtn );
\r
100 testExtn = Path.GetExtension( path2 );
\r
102 AssertEquals ( "", testExtn );
\r
105 public void TestGetFileName() {
\r
106 string testFileName = Path.GetFileName( path1 );
\r
108 AssertEquals( "test.txt", testFileName );
\r
111 public void TestGetFileNameWithoutExtension() {
\r
112 string testFileName = Path.GetFileNameWithoutExtension( path1 );
\r
114 AssertEquals( "test", testFileName );
\r
117 public void TestGetFullPath() {
\r
118 string testFullPath = Path.GetFullPath( "foo.txt" );
\r
119 // AssertEquals( "foo.txt", testFullPath );
\r
122 public void TestGetTempPath() {
\r
123 string getTempPath = Path.GetTempPath();
\r
124 AssertEquals( Environment.GetEnvironmentVariable( "TEMP" ) + '\\', getTempPath );
\r
128 // Not sure what's an appropriate test for this function? Maybe just
\r
129 // check if the temp file exists as advertised
\r
131 public void TestGetTempFileName() {
\r
132 string getTempFileName = Path.GetTempFileName();
\r
133 //Console.WriteLine( getTempFileName );
\r
136 public void TestHasExtension() {
\r
137 AssertEquals( true, Path.HasExtension( "foo.txt" ) );
\r
138 AssertEquals( false, Path.HasExtension( "foo" ) );
\r
139 AssertEquals( true, Path.HasExtension( path1 ) );
\r
140 AssertEquals( false, Path.HasExtension( path2 ) );
\r
143 public void TestRooted() {
\r
144 AssertEquals( true, Path.IsPathRooted( "c:\\winnt\\" ) );
\r
145 AssertEquals( false, Path.IsPathRooted( "system32\\drivers\\" ) );
\r