Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PathTest.cs « System.IO « Test « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2fd2c6da186d55884cd0a13b86340aea25f35880 (plain)
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
//
// System.IO.Path Test Cases
//
// Author: Marcin Szczepanski (marcins@zipworld.com.au)
//
// TODO: Add a more thorough workout for some
// of the "trickier" functions.

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 ('/' == Path.VolumeSeparatorChar){
			path1 = "/foo/test.txt";
			path2 = "/etc";
			path3 = "init.d";
		} else {
			path1 = "c:\\foo\\test.txt";
			path2 = "c:\\winnt";
			path3 = "system32";
		}

		// For Mac.  Figure this out when we need it
		//path1 = "foo:test.txt";
		//path2 = "foo";
		//path3 = "bar";
        }


        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();
                Assert ("Temp Path should not be empty",  getTempPath != String.Empty);
        }

        public void TestGetTempFileName() {
		string getTempFileName = "";
		try {
			getTempFileName = Path.GetTempFileName();
			Assert ("Temp file name should not be empty", getTempFileName != String.Empty);
			Assert ("File should exist", File.Exists(getTempFileName));
		} finally {
			if (getTempFileName != null && getTempFileName != String.Empty){
				File.Delete(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() {
                Assert ("Path should be rooted", Path.IsPathRooted(path2));
                Assert ("Path should NOT be rooted", !Path.IsPathRooted(path3));
        }
}

}