File: FileStreamSafeHandleTest.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (184 lines) | stat: -rw-r--r-- 3,678 bytes parent folder | download | duplicates (6)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// FileStreamSafeHandleTests.cs - Test Cases for System.IO.FileStream class
//
// Authors:
// 	Marcos Henrich (marcos.henrich@xamarin.com)
//
// Copyright 2015 Xamarin Inc (http://www.xamarin.com).
// 

using System;
using System.IO;
using System.Security.AccessControl;
using System.Threading;
using NUnit.Framework;

namespace MonoTests.System.IO
{
	[TestFixture]
	public class FileStreamWithClosedSafeHandleTests
	{
#if !MOBILE
		private FileStream GetFileStreamWithClosedHandle ()
		{
			var fs1 = new FileStream ("test2", FileMode.OpenOrCreate);
			var fs2 = new FileStream (fs1.SafeFileHandle, FileAccess.Read);
			fs1.Close ();

			return fs2;
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void GetLength ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			var l = fs.Length;
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void GetPosition ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			var p = fs.Position;
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void SetPosition ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.Position = 3;
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void GetAccessControl ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.GetAccessControl ();
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void SetAccessControl ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.SetAccessControl (new FileSecurity ());
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void Flush ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.Flush (false);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void SetLength ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.SetLength (20);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void Read ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.Read (new byte [2], 0, 1);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void Seek ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.Seek (0, SeekOrigin.Begin);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void Write ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.Write (new byte [2], 0, 1);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void ReadByte ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.ReadByte ();
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void WriteByte ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.WriteByte (0);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void Lock ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.Lock (0, 1);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void UnLock ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.Unlock (0, 1);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void ReadAsync ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.ReadAsync (new byte [2], 0, 1);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void WriteAsync ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.WriteAsync (new byte [2], 0, 1);
		}

		[Test]
		[ExpectedException (typeof (ObjectDisposedException))]
		public void FlushAsync ()
		{
			var fs = GetFileStreamWithClosedHandle ();

			fs.FlushAsync (new CancellationToken ());
		}
#endif
	}
}