* StreamWriterTest.cs: Only check paramname for buffersize exception on
[mono.git] / mcs / class / corlib / Test / System.IO / StringReaderTest.cs
index dc4e85ea563564f5e94066d6703dbfcedec698e6..3ab127651af01d4e989bc2a440f6ec822c51dd25 100644 (file)
@@ -14,17 +14,19 @@ using System;
 
 namespace MonoTests.System.IO {
 
-public class StringReaderTest : TestCase {
-
-       public static ITest Suite {
-               get {
-                       return new TestSuite(typeof(StringReaderTest));
-               }
+[TestFixture]
+public class StringReaderTest : Assertion {
+       public  void TestReadLine() {
+               string testme = "a\nb\nc\n";
+               StringReader sr = new StringReader (testme);
+               string inputLine;
+               int lines = 0;
+               while ((inputLine = sr.ReadLine ()) != null)
+                       lines++;
+               
+               AssertEquals ("Incorrect number of lines", 3, lines);
        }
 
-       public StringReaderTest() : base ("MonoTests.System.IO.StringReaderTest testcase") { }
-       public StringReaderTest( string name ): base(name) { }
-
        public void TestPeekRead() {
                StringReader reader = new StringReader( "Test String" );
 
@@ -96,6 +98,10 @@ public class StringReaderTest : TestCase {
                AssertEquals( 3, charsRead );
                AssertEquals(  "Foo\0\0\0", new String( test ) );
 
+               /* Check that a new invocation on the empty reader will return 0 */
+               charsRead = reader.Read (test, 0, 6);
+               AssertEquals (0, charsRead);
+               
        }
 
         public void TestReadEOL() {
@@ -117,6 +123,84 @@ public class StringReaderTest : TestCase {
 
                 AssertEquals( "Line4", test );
         }
+
+        public void TestClose() {
+               
+               StringReader reader = new StringReader("reader");
+               reader.Close ();
+               
+               try {
+                       reader.Read ();
+                       Fail();
+               } catch (Exception e) {
+                       AssertEquals ("Close 1", typeof (ObjectDisposedException), e.GetType ());
+               }
+               
+               try {
+                       reader.Peek ();
+                       Fail ();
+               } catch (Exception e) {
+                       AssertEquals ("Close 2", typeof (ObjectDisposedException), e.GetType ());                                    
+               }               
+        }
+        
+        public void TestExceptions() {
+               
+               StringReader reader;
+               
+               try {
+                       reader = new StringReader(null);
+                       Fail ();
+               } catch (Exception e) {
+                       AssertEquals ("Exception 1", typeof (ArgumentNullException), e.GetType ());
+               }
+               
+               reader = new StringReader ("this is a test\nAnd nothing else");
+               
+               try {
+                       reader.Read (null, 0, 12);
+                       Fail ();
+               } catch (Exception e) {
+                       AssertEquals ("Exception 2", typeof (ArgumentNullException), e.GetType ());
+               }                       
+        }
+
+       [Test]
+       public void MoreEOL ()
+       {
+                TextReader tr = new StringReader ("There she was just a walking\n" +
+                                                 "Down the street singin'\r" +
+                                                 "Do wah diddy diddy dum diddy do");
+
+               int i = 0;
+               while (tr.ReadLine () != null)
+                       i++;
+
+               AssertEquals ("#01", 3, i);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void Read_IndexOverflow () 
+       {
+               StringReader sr = new StringReader ("Mono");
+               sr.Read (new char [4], Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void Read_CountOverflow () 
+       {
+               StringReader sr = new StringReader ("Mono");
+               sr.Read (new char [4], 1, Int32.MaxValue);
+       }
+
+       [Test]
+       public void Read_DoesntStopAtLineEndings ()
+       {
+               StringReader reader = new StringReader ("Line1\rLine2\r\nLine3\nLine4");
+               AssertEquals (24, reader.Read (new char[24], 0, 24));
+       }       
 }
 
 }