2002/03/07 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / corlib / Test / System.IO / PathTest.cs
1 //\r
2 // System.IO.Path Test Cases\r
3 //\r
4 // Author: Marcin Szczepanski (marcins@zipworld.com.au)\r
5 //\r
6 // TODO: Add a more thorough workout for some\r
7 // of the "trickier" functions.\r
8 \r
9 #define WINDOWS\r
10 \r
11 using NUnit.Framework;\r
12 using System.IO;\r
13 using System;\r
14 using System.Text;\r
15 \r
16 namespace MonoTests.System.IO\r
17 {\r
18 \r
19 public class PathTest : TestCase {\r
20 \r
21         string path1;\r
22         string path2;\r
23         string path3;\r
24      \r
25         public static ITest Suite {\r
26                 get {\r
27                         return new TestSuite(typeof(PathTest));\r
28                 }\r
29         }\r
30 \r
31         public PathTest() : base ("MonoTests.System.IO.PathTest testcase") { }\r
32         public PathTest( string name ): base(name) { }\r
33 \r
34         protected override void SetUp() {\r
35                 \r
36                 #if WINDOWS\r
37                 \r
38                 path1 = "c:\\foo\\test.txt";\r
39                 path2 = "c:\\winnt";\r
40                 path3 = "system32";\r
41 \r
42                 #elif UNIX\r
43                 \r
44                 path1 = "/foo/test.txt";\r
45                 path2 = "/etc";\r
46                 path3 = "init.d"\r
47                 \r
48                 #elif MAC\r
49                 \r
50                 path1 = "foo:test.txt";\r
51                 path2 = "foo";\r
52                 path3 = "bar";\r
53 \r
54                 #endif\r
55 \r
56         }\r
57 \r
58 \r
59         public void TestChangeExtension() {\r
60                 string testPath = Path.ChangeExtension( path1, "doc" );\r
61 \r
62                 #if WINDOWS\r
63                 AssertEquals( "c:\\foo\\test.doc", testPath );\r
64                 #elif UNIX\r
65                 AssertEquals( "/foo/test.doc", testPath );\r
66                 #elif MAC\r
67                 AssertEquals( "foo:test.doc", testPath );\r
68                 #endif\r
69         }\r
70 \r
71         public void TestCombine() {\r
72                 string testPath = Path.Combine( path2, path3 );\r
73 \r
74                 #if WINDOWS\r
75                 AssertEquals( "c:\\winnt\\system32", testPath );\r
76                 #elif UNIX\r
77                 AssertEquals( "/etc/init.d", testPath );\r
78                 #elif MAC\r
79                 AssertEquals( "foo:bar", testPath );\r
80                 #endif\r
81         }\r
82 \r
83         public void TestDirectoryName() {\r
84                 string testDirName = Path.GetDirectoryName( path1 );\r
85 \r
86                 #if WINDOWS\r
87                 AssertEquals( "c:\\foo", testDirName );\r
88                 #elif UNIX\r
89                 AssertEquals( "/etc", testDirName );\r
90                 #elif MAC\r
91                 AssertEquals( "foo", testDirName );\r
92                 #endif\r
93         }\r
94 \r
95         public void TestGetExtension() {\r
96                 string testExtn = Path.GetExtension( path1 );\r
97 \r
98                 AssertEquals( ".txt", testExtn );\r
99 \r
100                 testExtn = Path.GetExtension( path2 );\r
101 \r
102                 AssertEquals ( "", testExtn );\r
103         }\r
104 \r
105         public void TestGetFileName() {\r
106                 string testFileName = Path.GetFileName( path1 );\r
107 \r
108                 AssertEquals( "test.txt", testFileName );\r
109         }\r
110 \r
111         public void TestGetFileNameWithoutExtension() {\r
112                 string testFileName = Path.GetFileNameWithoutExtension( path1 );\r
113 \r
114                 AssertEquals( "test", testFileName );\r
115         }\r
116 \r
117         public void TestGetFullPath() {\r
118                 string testFullPath = Path.GetFullPath( "foo.txt" );\r
119          //       AssertEquals( "foo.txt", testFullPath );\r
120         }\r
121         \r
122         public void TestGetTempPath() {\r
123                 string getTempPath = Path.GetTempPath();\r
124                 AssertEquals( Environment.GetEnvironmentVariable( "TEMP" ) + '\\',  getTempPath );\r
125         }\r
126 \r
127         /*\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
130         //\r
131         public void TestGetTempFileName() {\r
132                 string getTempFileName = Path.GetTempFileName();\r
133                 //Console.WriteLine( getTempFileName );\r
134         }*/\r
135 \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
141         }\r
142 \r
143         public void TestRooted() {\r
144                 AssertEquals( true, Path.IsPathRooted( "c:\\winnt\\" ) );\r
145                 AssertEquals( false, Path.IsPathRooted( "system32\\drivers\\" ) );\r
146         }\r
147 }\r
148 \r
149 }\r