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