2005-04-09 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / corlib / Test / System.IO / StreamReaderTest.cs
1 // StreamReaderTest.cs - NUnit Test Cases for the SystemIO.StreamReader class\r
2 //\r
3 // David Brandt (bucky@keystreams.com)\r
4 //\r
5 // (C) Ximian, Inc.  http://www.ximian.com\r
6 // Copyright (C) 2004 Novell (http://www.novell.com)\r
7 // \r
8 \r
9 using NUnit.Framework;\r
10 using System;\r
11 using System.IO;\r
12 using System.Text;\r
13 \r
14 namespace MonoTests.System.IO\r
15 {\r
16 \r
17 [TestFixture]\r
18 public class StreamReaderTest : Assertion\r
19 {\r
20         static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");\r
21         private string _codeFileName = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";\r
22 \r
23         [SetUp]\r
24         public void SetUp ()\r
25         {       \r
26                 if (!Directory.Exists (TempFolder))                             \r
27                         Directory.CreateDirectory (TempFolder);\r
28                 \r
29                 if (!File.Exists (_codeFileName))\r
30                         File.Create (_codeFileName).Close ();\r
31         }\r
32 \r
33         [TearDown]\r
34         public void TearDown ()\r
35         {\r
36                 if (Directory.Exists (TempFolder))\r
37                         Directory.Delete (TempFolder, true);\r
38         }\r
39 \r
40 \r
41         [Test]\r
42         public void TestCtor1() {\r
43                 {\r
44                         bool errorThrown = false;\r
45                         try {\r
46                                 StreamReader r = new StreamReader((Stream)null);\r
47                         } catch (ArgumentNullException) {\r
48                                 errorThrown = true;\r
49                         }\r
50                         Assert("null string error not thrown", errorThrown);\r
51                 }\r
52                 {\r
53                         bool errorThrown = false;\r
54                         FileStream f = new FileStream(_codeFileName, FileMode.Open, FileAccess.Write);\r
55                         try {\r
56                                 StreamReader r = new StreamReader(f);\r
57                                 r.Close();\r
58                         } catch (ArgumentException) {\r
59                                 errorThrown = true;\r
60                         }\r
61                         f.Close();\r
62                         Assert("no read error not thrown", errorThrown);\r
63                 }\r
64                 {\r
65                         // this is probably incestuous, but, oh well.\r
66                         FileStream f = new FileStream(_codeFileName, \r
67                                                       FileMode.Open, \r
68                                                       FileAccess.Read);\r
69                         StreamReader r = new StreamReader(f);\r
70                         AssertNotNull("no stream reader", r);\r
71                         r.Close();\r
72                         f.Close();\r
73                 }\r
74         }\r
75 \r
76         [Test]\r
77         public void TestCtor2() {\r
78                 {\r
79                         bool errorThrown = false;\r
80                         try {\r
81                                 StreamReader r = new StreamReader("");\r
82                         } catch (ArgumentException) {\r
83                                 errorThrown = true;\r
84                         } catch (Exception e) {\r
85                                 Fail ("Incorrect exception thrown at 1: " + e.ToString());\r
86                         }\r
87                         Assert("empty string error not thrown", errorThrown);\r
88                 }\r
89                 {\r
90                         bool errorThrown = false;\r
91                         try {\r
92                                 StreamReader r = new StreamReader((string)null);\r
93                         } catch (ArgumentNullException) {\r
94                                 errorThrown = true;\r
95                         } catch (Exception e) {\r
96                                 Fail ("Incorrect exception thrown at 2: " + e.ToString());\r
97                         }\r
98                         Assert("null string error not thrown", errorThrown);\r
99                 }\r
100                 {\r
101                         bool errorThrown = false;\r
102                         try {\r
103                                 StreamReader r = new StreamReader("nonexistentfile");\r
104                         } catch (FileNotFoundException) {\r
105                                 errorThrown = true;\r
106                         } catch (Exception e) {\r
107                                 Fail ("Incorrect exception thrown at 3: " + e.ToString());\r
108                         }\r
109                         Assert("fileNotFound error not thrown", errorThrown);\r
110                 }\r
111                 {\r
112                         bool errorThrown = false;\r
113                         try {\r
114                                 StreamReader r = new StreamReader("nonexistentdir/file");\r
115                         } catch (DirectoryNotFoundException) {\r
116                                 errorThrown = true;\r
117                         } catch (Exception e) {\r
118                                 Fail ("Incorrect exception thrown at 4: " + e.ToString());\r
119                         }\r
120                         Assert("dirNotFound error not thrown", errorThrown);\r
121                 }\r
122                 {\r
123                         bool errorThrown = false;\r
124                         try {\r
125                                 StreamReader r = new StreamReader("!$what? what? Huh? !$*#" + Path.InvalidPathChars[0]);\r
126                         } catch (IOException) {\r
127                                 errorThrown = true;\r
128                         } catch (ArgumentException) {\r
129                                 // FIXME - the spec says 'IOExc', but the\r
130                                 //   compiler says 'ArgExc'...\r
131                                 errorThrown = true;\r
132                         } catch (Exception e) {\r
133                                 Fail ("Incorrect exception thrown at 5: " + e.ToString());\r
134                         }\r
135                         Assert("invalid filename error not thrown", errorThrown);\r
136                 }\r
137                 {\r
138                         // this is probably incestuous, but, oh well.\r
139                         StreamReader r = new StreamReader(_codeFileName);\r
140                         AssertNotNull("no stream reader", r);\r
141                         r.Close();\r
142                 }\r
143         }\r
144 \r
145         [Test]\r
146         public void TestCtor3() {\r
147                 {\r
148                         bool errorThrown = false;\r
149                         try {\r
150                                 StreamReader r = new StreamReader((Stream)null, false);\r
151                         } catch (ArgumentNullException) {\r
152                                 errorThrown = true;\r
153                         } catch (Exception e) {\r
154                                 Fail ("Incorrect exception thrown at 1: " + e.ToString());\r
155                         }\r
156                         Assert("null stream error not thrown", errorThrown);\r
157                 }\r
158                 {\r
159                         bool errorThrown = false;\r
160                         FileStream f = new FileStream(_codeFileName, FileMode.Open, FileAccess.Write);\r
161                         try {\r
162                                 StreamReader r = new StreamReader(f, false);\r
163                                 r.Close();\r
164                         } catch (ArgumentException) {\r
165                                 errorThrown = true;\r
166                         } catch (Exception e) {\r
167                                 Fail ("Incorrect exception thrown at 2: " + e.ToString());\r
168                         }\r
169                         f.Close();\r
170                         Assert("no read error not thrown", errorThrown);\r
171                 }\r
172                 {\r
173                         // this is probably incestuous, but, oh well.\r
174                         FileStream f = new FileStream(_codeFileName, \r
175                                                       FileMode.Open, \r
176                                                       FileAccess.Read);\r
177                         StreamReader r = new StreamReader(f, false);\r
178                         AssertNotNull("no stream reader", r);\r
179                         r.Close();\r
180                         f.Close();\r
181                 }\r
182                 {\r
183                         bool errorThrown = false;\r
184                         try {\r
185                                 StreamReader r = new StreamReader((Stream)null, true);\r
186                         } catch (ArgumentNullException) {\r
187                                 errorThrown = true;\r
188                         } catch (Exception e) {\r
189                                 Fail ("Incorrect exception thrown at 3: " + e.ToString());\r
190                         }\r
191                         Assert("null string error not thrown", errorThrown);\r
192                 }\r
193                 {\r
194                         bool errorThrown = false;\r
195                         FileStream f = new FileStream(_codeFileName, FileMode.Open, FileAccess.Write);\r
196                         try {\r
197                                 StreamReader r = new StreamReader(f, true);\r
198                                 r.Close();\r
199                         } catch (ArgumentException) {\r
200                                 errorThrown = true;\r
201                         } catch (Exception e) {\r
202                                 Fail ("Incorrect exception thrown at 4: " + e.ToString());\r
203                         }\r
204                         f.Close();\r
205                         Assert("no read error not thrown", errorThrown);\r
206                 }\r
207                 {\r
208                         // this is probably incestuous, but, oh well.\r
209                         FileStream f = new FileStream(_codeFileName, \r
210                                                       FileMode.Open, \r
211                                                       FileAccess.Read);\r
212                         StreamReader r = new StreamReader(f, true);\r
213                         AssertNotNull("no stream reader", r);\r
214                         r.Close();\r
215                         f.Close();\r
216                 }\r
217         }\r
218 \r
219         [Test]\r
220         public void TestCtor4() {\r
221                 {\r
222                         bool errorThrown = false;\r
223                         try {\r
224                                 StreamReader r = new StreamReader("", false);\r
225                         } catch (ArgumentException) {\r
226                                 errorThrown = true;\r
227                         } catch (Exception e) {\r
228                                 Fail ("Incorrect exception thrown at 1: " + e.ToString());\r
229                         }\r
230                         Assert("empty string error not thrown", errorThrown);\r
231                 }\r
232                 {\r
233                         bool errorThrown = false;\r
234                         try {\r
235                                 StreamReader r = new StreamReader((string)null, false);\r
236                         } catch (ArgumentNullException) {\r
237                                 errorThrown = true;\r
238                         } catch (Exception e) {\r
239                                 Fail ("Incorrect exception thrown at 2: " + e.ToString());\r
240                         }\r
241                         Assert("null string error not thrown", errorThrown);\r
242                 }\r
243                 {\r
244                         bool errorThrown = false;\r
245                         try {\r
246                                 StreamReader r = new StreamReader(TempFolder + "/nonexistentfile", false);\r
247                         } catch (FileNotFoundException) {\r
248                                 errorThrown = true;\r
249                         } catch (Exception e) {\r
250                                 Fail ("Incorrect exception thrown at 3: " + e.ToString());\r
251                         }\r
252                         Assert("fileNotFound error not thrown", errorThrown);\r
253                 }\r
254                 {\r
255                         bool errorThrown = false;\r
256                         try {\r
257                                 StreamReader r = new StreamReader(TempFolder + "/nonexistentdir/file", false);\r
258                         } catch (DirectoryNotFoundException) {\r
259                                 errorThrown = true;\r
260                         } catch (Exception e) {\r
261                                 Fail ("Incorrect exception thrown at 4: " + e.ToString());\r
262                         }\r
263                         Assert("dirNotFound error not thrown", errorThrown);\r
264                 }\r
265                 {\r
266                         bool errorThrown = false;\r
267                         try {\r
268                                 StreamReader r = new StreamReader("!$what? what? Huh? !$*#" + Path.InvalidPathChars[0], false);\r
269                         } catch (IOException) {\r
270                                 errorThrown = true;\r
271                         } catch (ArgumentException) {\r
272                                 // FIXME - the spec says 'IOExc', but the\r
273                                 //   compiler says 'ArgExc'...\r
274                                 errorThrown = true;\r
275                         } catch (Exception e) {\r
276                                 Fail ("Incorrect exception thrown at 5: " + e.ToString());\r
277                         }\r
278                         Assert("invalid filename error not thrown", errorThrown);\r
279                 }\r
280                 {\r
281                         // this is probably incestuous, but, oh well.\r
282                         StreamReader r = new StreamReader(_codeFileName, false);\r
283                         AssertNotNull("no stream reader", r);\r
284                         r.Close();\r
285                 }\r
286                 {\r
287                         bool errorThrown = false;\r
288                         try {\r
289                                 StreamReader r = new StreamReader("", true);\r
290                         } catch (ArgumentException) {\r
291                                 errorThrown = true;\r
292                         } catch (Exception e) {\r
293                                 Fail ("Incorrect exception thrown at 6: " + e.ToString());\r
294                         }\r
295                         Assert("empty string error not thrown", errorThrown);\r
296                 }\r
297                 {\r
298                         bool errorThrown = false;\r
299                         try {\r
300                                 StreamReader r = new StreamReader((string)null, true);\r
301                         } catch (ArgumentNullException) {\r
302                                 errorThrown = true;\r
303                         } catch (Exception e) {\r
304                                 Fail ("Incorrect exception thrown at 7: " + e.ToString());\r
305                         }\r
306                         Assert("null string error not thrown", errorThrown);\r
307                 }\r
308                 {\r
309                         bool errorThrown = false;\r
310                         try {\r
311                                 StreamReader r = new StreamReader(TempFolder + "/nonexistentfile", true);\r
312                         } catch (FileNotFoundException) {\r
313                                 errorThrown = true;\r
314                         } catch (Exception e) {\r
315                                 Fail ("Incorrect exception thrown at 8: " + e.ToString());\r
316                         }\r
317                         Assert("fileNotFound error not thrown", errorThrown);\r
318                 }\r
319                 {\r
320                         bool errorThrown = false;\r
321                         try {\r
322                                 StreamReader r = new StreamReader(TempFolder + "/nonexistentdir/file", true);\r
323                         } catch (DirectoryNotFoundException) {\r
324                                 errorThrown = true;\r
325                         } catch (Exception e) {\r
326                                 Fail ("Incorrect exception thrown at 9: " + e.ToString());\r
327                         }\r
328                         Assert("dirNotFound error not thrown", errorThrown);\r
329                 }\r
330                 {\r
331                         bool errorThrown = false;\r
332                         try {\r
333                                 StreamReader r = new StreamReader("!$what? what? Huh? !$*#" + Path.InvalidPathChars[0], true);\r
334                         } catch (IOException) {\r
335                                 errorThrown = true;\r
336                         } catch (ArgumentException) {\r
337                                 // FIXME - the spec says 'IOExc', but the\r
338                                 //   compiler says 'ArgExc'...\r
339                                 errorThrown = true;\r
340                         } catch (Exception e) {\r
341                                 Fail ("Incorrect exception thrown at 10: " + e.ToString());\r
342                         }\r
343                         Assert("invalid filename error not thrown", errorThrown);\r
344                 }\r
345                 {\r
346                         // this is probably incestuous, but, oh well.\r
347                         StreamReader r = new StreamReader(_codeFileName, true);\r
348                         AssertNotNull("no stream reader", r);\r
349                         r.Close();\r
350                 }\r
351         }\r
352 \r
353         // TODO - Ctor with Encoding\r
354         \r
355         [Test]\r
356         public void TestBaseStream() {\r
357                 string progress = "beginning";\r
358                 try {\r
359                         Byte[] b = {};\r
360                         MemoryStream m = new MemoryStream(b);\r
361                         StreamReader r = new StreamReader(m);\r
362                         AssertEquals("wrong base stream ", m, r.BaseStream);\r
363                         progress = "Closing StreamReader";\r
364                         r.Close();\r
365                         progress = "Closing MemoryStream";\r
366                         m.Close();\r
367                 } catch (Exception e) {\r
368                         Fail ("At '" + progress + "' an unexpected exception was thrown: " + e.ToString());\r
369                 }\r
370         }\r
371 \r
372         public void TestCurrentEncoding() {\r
373                 try {\r
374                         Byte[] b = {};\r
375                         MemoryStream m = new MemoryStream(b);\r
376                         StreamReader r = new StreamReader(m);\r
377                         AssertEquals("wrong encoding", \r
378                                      Encoding.UTF8.GetType (), r.CurrentEncoding.GetType ());\r
379                 } catch (Exception e) {\r
380                         Fail ("Unexpected exception thrown: " + e.ToString());\r
381                 }\r
382         }\r
383 \r
384         // TODO - Close - annoying spec - won't commit to any exceptions. How to test?\r
385         // TODO - DiscardBufferedData - I have no clue how to test this function.\r
386 \r
387         [Test]\r
388         public void TestPeek() {\r
389                 // FIXME - how to get an IO Exception?\r
390                 {\r
391                         bool errorThrown = false;\r
392                         try {\r
393                                 Byte[] b = {};\r
394                                 MemoryStream m = new MemoryStream(b);\r
395                                 StreamReader r = new StreamReader(m);\r
396                                 m.Close();\r
397                                 int nothing = r.Peek();\r
398                         } catch (ObjectDisposedException) {\r
399                                 errorThrown = true;\r
400                         }\r
401                         Assert("nothing-to-peek-at error not thrown", errorThrown);\r
402                 }\r
403                 {\r
404                         Byte[] b = {1, 2, 3, 4, 5, 6};\r
405                         MemoryStream m = new MemoryStream(b);\r
406                         \r
407                         StreamReader r = new StreamReader(m);\r
408                         for (int i = 1; i <= 6; i++) {\r
409                                 AssertEquals("peek incorrect", i, r.Peek());\r
410                                 r.Read();\r
411                         }\r
412                         AssertEquals("should be none left", -1, r.Peek());\r
413                 }\r
414         }\r
415 \r
416         [Test]\r
417         public void TestRead() {\r
418                 // FIXME - how to get an IO Exception?\r
419                 {\r
420                         bool errorThrown = false;\r
421                         try {\r
422                                 Byte[] b = {};\r
423                                 MemoryStream m = new MemoryStream(b);\r
424                                 StreamReader r = new StreamReader(m);\r
425                                 m.Close();\r
426                                 int nothing = r.Read();\r
427                         } catch (ObjectDisposedException) {\r
428                                 errorThrown = true;\r
429                         } catch (Exception e) {\r
430                                 Fail ("Incorrect exception thrown at 1: " + e.ToString());\r
431                         }\r
432                         Assert("nothing-to-read error not thrown", errorThrown);\r
433                 }\r
434                 {\r
435                         Byte[] b = {1, 2, 3, 4, 5, 6};\r
436                         MemoryStream m = new MemoryStream(b);\r
437                         \r
438                         StreamReader r = new StreamReader(m);\r
439                         for (int i = 1; i <= 6; i++) {\r
440                                 AssertEquals("read incorrect", i, r.Read());\r
441                         }\r
442                         AssertEquals("Should be none left", -1, r.Read());\r
443                 }\r
444 \r
445                 {\r
446                         bool errorThrown = false;\r
447                         try {\r
448                                 Byte[] b = {};\r
449                                 StreamReader r = new StreamReader(new MemoryStream(b));\r
450                                 r.Read(null, 0, 0);\r
451                         } catch (ArgumentNullException) {\r
452                                 errorThrown = true;\r
453                         } catch (ArgumentException) {\r
454                                 errorThrown = true;\r
455                         } catch (Exception e) {\r
456                                 Fail ("Incorrect exception thrown at 2: " + e.ToString());\r
457                         }\r
458                         Assert("null buffer error not thrown", errorThrown);\r
459                 }\r
460                 {\r
461                         bool errorThrown = false;\r
462                         try {\r
463                                 Byte[] b = {};\r
464                                 StreamReader r = new StreamReader(new MemoryStream(b));\r
465                                 Char[] c = new Char[1];\r
466                                 r.Read(c, 0, 2);\r
467                         } catch (ArgumentException) {\r
468                                 errorThrown = true;\r
469                         } catch (Exception e) {\r
470                                 Fail ("Incorrect exception thrown at 3: " + e.ToString());\r
471                         }\r
472                         Assert("too-long range error not thrown", errorThrown);\r
473                 }\r
474                 {\r
475                         bool errorThrown = false;\r
476                         try {\r
477                                 Byte[] b = {};\r
478                                 StreamReader r = new StreamReader(new MemoryStream(b));\r
479                                 Char[] c = new Char[1];\r
480                                 r.Read(c, -1, 2);\r
481                         } catch (ArgumentOutOfRangeException) {\r
482                                 errorThrown = true;\r
483                         } catch (Exception e) {\r
484                                 Fail ("Incorrect exception thrown at 4: " + e.ToString());\r
485                         }\r
486                         Assert("out of range error not thrown", errorThrown);\r
487                 }\r
488                 {\r
489                         bool errorThrown = false;\r
490                         try {\r
491                                 Byte[] b = {};\r
492                                 StreamReader r = new StreamReader(new MemoryStream(b));\r
493                                 Char[] c = new Char[1];\r
494                                 r.Read(c, 0, -1);\r
495                         } catch (ArgumentOutOfRangeException) {\r
496                                 errorThrown = true;\r
497                         } catch (Exception e) {\r
498                                 Fail ("Incorrect exception thrown at 5: " + e.ToString());\r
499                         }\r
500                         Assert("out of range error not thrown", errorThrown);\r
501                 }\r
502                 {\r
503                         int ii = 1;\r
504                         try {\r
505                                 Byte[] b = {(byte)'a', (byte)'b', (byte)'c', \r
506                                             (byte)'d', (byte)'e', (byte)'f', \r
507                                             (byte)'g'};\r
508                                 MemoryStream m = new MemoryStream(b);\r
509                                 ii++;\r
510                                 StreamReader r = new StreamReader(m);\r
511                                 ii++;\r
512 \r
513                                 char[] buffer = new Char[7];\r
514                                 ii++;\r
515                                 char[] target = {'g','d','e','f','b','c','a'};\r
516                                 ii++;\r
517                                 r.Read(buffer, 6, 1);\r
518                                 ii++;\r
519                                 r.Read(buffer, 4, 2);\r
520                                 ii++;\r
521                                 r.Read(buffer, 1, 3);\r
522                                 ii++;\r
523                                 r.Read(buffer, 0, 1);\r
524                                 ii++;\r
525                                 for (int i = 0; i < target.Length; i++) {\r
526                                         AssertEquals("read no work", \r
527                                                      target[i], buffer[i]);\r
528                                 i++;\r
529                                 }\r
530                                                     \r
531                         } catch (Exception e) {\r
532                                 Fail ("Caught when ii=" + ii + ". e:" + e.ToString());\r
533                         }\r
534                 }\r
535         }\r
536 \r
537         [Test]\r
538         public void TestReadLine() {\r
539                 // TODO Out Of Memory Exc? IO Exc?\r
540                 Byte[] b = new Byte[8];\r
541                 b[0] = (byte)'a';\r
542                 b[1] = (byte)'\n';\r
543                 b[2] = (byte)'b';\r
544                 b[3] = (byte)'\n';\r
545                 b[4] = (byte)'c';\r
546                 b[5] = (byte)'\n';\r
547                 b[6] = (byte)'d';\r
548                 b[7] = (byte)'\n';\r
549                 MemoryStream m = new MemoryStream(b);\r
550                 StreamReader r = new StreamReader(m);\r
551                 AssertEquals("line doesn't match", "a", r.ReadLine());\r
552                 AssertEquals("line doesn't match", "b", r.ReadLine());\r
553                 AssertEquals("line doesn't match", "c", r.ReadLine());\r
554                 AssertEquals("line doesn't match", "d", r.ReadLine());\r
555                 AssertEquals("line doesn't match", null, r.ReadLine());\r
556         }\r
557 \r
558         public void TestReadToEnd() {\r
559                 // TODO Out Of Memory Exc? IO Exc?\r
560                 Byte[] b = new Byte[8];\r
561                 b[0] = (byte)'a';\r
562                 b[1] = (byte)'\n';\r
563                 b[2] = (byte)'b';\r
564                 b[3] = (byte)'\n';\r
565                 b[4] = (byte)'c';\r
566                 b[5] = (byte)'\n';\r
567                 b[6] = (byte)'d';\r
568                 b[7] = (byte)'\n';\r
569                 MemoryStream m = new MemoryStream(b);\r
570                 StreamReader r = new StreamReader(m);\r
571                 AssertEquals("line doesn't match", "a\nb\nc\nd\n", r.ReadToEnd());\r
572                 AssertEquals("line doesn't match", "", r.ReadToEnd());\r
573         }\r
574 \r
575         [Test]\r
576         public void TestBaseStreamClosed ()\r
577         {\r
578                 byte [] b = {};\r
579                 MemoryStream m = new MemoryStream (b);\r
580                 StreamReader r = new StreamReader (m);\r
581                 m.Close ();\r
582                 bool thrown = false;\r
583                 try {\r
584                         r.Peek ();\r
585                 } catch (ObjectDisposedException) {\r
586                         thrown = true;\r
587                 }\r
588 \r
589                 AssertEquals ("#01", true, thrown);\r
590         }\r
591 \r
592         [Test]\r
593         [ExpectedException (typeof (ArgumentNullException))]\r
594         public void Contructor_Stream_NullEncoding () \r
595         {\r
596                 StreamReader r = new StreamReader (new MemoryStream (), null);\r
597         }\r
598 \r
599         [Test]\r
600         [ExpectedException (typeof (ArgumentNullException))]\r
601         public void Contructor_Path_NullEncoding () \r
602         {\r
603                 StreamReader r = new StreamReader (_codeFileName, null);\r
604         }\r
605 \r
606         [Test]\r
607         [ExpectedException (typeof (ArgumentNullException))]\r
608         public void Read_Null () \r
609         {\r
610                 StreamReader r = new StreamReader (new MemoryStream ());\r
611                 r.Read (null, 0, 0);\r
612         }\r
613 \r
614         [Test]\r
615         [ExpectedException (typeof (ArgumentException))]\r
616         public void Read_IndexOverflow () \r
617         {\r
618                 char[] array = new char [16];\r
619                 StreamReader r = new StreamReader (new MemoryStream (16));\r
620                 r.Read (array, 1, Int32.MaxValue);\r
621         }       \r
622 \r
623         [Test]\r
624         [ExpectedException (typeof (ArgumentException))]\r
625         public void Read_CountOverflow () \r
626         {\r
627                 char[] array = new char [16];\r
628                 StreamReader r = new StreamReader (new MemoryStream (16));\r
629                 r.Read (array, Int32.MaxValue, 1);\r
630         }       \r
631 }\r
632 }\r