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

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Cohn <macohn@microsoft.com>2015-07-08 04:31:10 +0300
committerstephentoub <stoub@microsoft.com>2015-08-11 01:29:24 +0300
commit381785c196c573fe4ee7b36eaf4c53f4f5526ca0 (patch)
tree192dca265c9cde48137c8ca1fa098aa7fc3137d1 /src/System.IO/tests/StringReader
parentb0d0470b9a6387a08bf05d22c6d1e713865ce0b6 (diff)
Port additional System.IO tests from ToF
Port additional System.IO tests from ToF for System.IO.BinaryWriter System.IO.MemoryStream System.IO.Stream System.IO.StreamReader System.IO.StreamWriter System.IO.StringReader System.IO.StringWriter
Diffstat (limited to 'src/System.IO/tests/StringReader')
-rw-r--r--src/System.IO/tests/StringReader/StringReaderCtorTests.cs156
1 files changed, 156 insertions, 0 deletions
diff --git a/src/System.IO/tests/StringReader/StringReaderCtorTests.cs b/src/System.IO/tests/StringReader/StringReaderCtorTests.cs
new file mode 100644
index 0000000000..39d3f24bee
--- /dev/null
+++ b/src/System.IO/tests/StringReader/StringReaderCtorTests.cs
@@ -0,0 +1,156 @@
+using System;
+using System.IO;
+using Xunit;
+
+namespace StringReaderTests
+{
+ public class ReaderTests
+ {
+ [Fact]
+ public static void StringReaderWithNullString()
+ {
+ // [] Null Argument should store null string
+ //-----------------------------------------------------------
+
+ Assert.Throws<ArgumentNullException>(() =>
+ {
+ StringReader sr = new StringReader(null);
+ String strTemp = sr.ReadToEnd();
+ sr.ReadLine();
+ sr.Peek();
+ sr.Read();
+ sr.Dispose();
+ });
+
+ }
+
+ [Fact]
+ public static void StringReaderWithEmptyString()
+ {
+
+ // [] Check vanilla construction
+ //-----------------------------------------------------------
+ StringReader sr = new StringReader(String.Empty);
+ Assert.Equal(String.Empty, sr.ReadToEnd());
+ }
+
+ [Fact]
+ public static void StringReaderWithGenericString()
+ {
+ // [] Another vanilla construction
+ //-----------------------------------------------------------
+
+ StringReader sr = new StringReader("Hello\0World");
+ Assert.Equal("Hello\0World", sr.ReadToEnd());
+ }
+
+ [Fact]
+ public static void ReadEmtpyString() {
+ StringReader sr = new StringReader(String.Empty);
+ Assert.Equal(-1, sr.Read());
+
+ }
+
+ [Fact]
+ public static void ReadString() {
+ String str1 = "Hello\0\t\v \\ World";
+ StringReader sr = new StringReader(str1);
+ for (int i = 0; i < str1.Length; i++)
+ {
+ Assert.Equal((int)str1[i], sr.Read());
+ }
+
+ }
+
+ [Fact]
+ public static void ReadPsudoRandomString()
+ {
+ String str1 = String.Empty;
+ Random r = new Random(-55);
+ for (int i = 0; i < 5000; i++)
+ str1 += (Char)r.Next(0, 255);
+
+ StringReader sr = new StringReader(str1);
+ for (int i = 0; i < str1.Length; i++)
+ {
+ Assert.Equal((int)str1[i], sr.Read());
+ }
+ }
+
+
+
+
+
+ [Fact]
+ public static void PeedEmtpyString()
+ {
+ StringReader sr = new StringReader(String.Empty);
+ Assert.Equal(-1, sr.Peek());
+
+ }
+
+ [Fact]
+ public static void PeekString()
+ {
+ String str1 = "Hello\0\t\v \\ World";
+ StringReader sr = new StringReader(str1);
+ for (int i = 0; i < str1.Length; i++)
+ {
+ int test = sr.Peek();
+ sr.Read();
+ Assert.Equal((int)str1[i], test);
+ }
+
+ }
+
+ [Fact]
+ public static void PeekPsudoRandomString()
+ {
+ String str1 = String.Empty;
+ Random r = new Random(-55);
+ for (int i = 0; i < 5000; i++)
+ str1 += (Char)r.Next(0, 255);
+
+ StringReader sr = new StringReader(str1);
+ for (int i = 0; i < str1.Length; i++)
+ {
+ int test = sr.Peek();
+ sr.Read();
+ Assert.Equal((int)str1[i], test);
+ }
+ }
+
+ [Fact]
+ public static void ReadToEndEmptyString()
+ {
+ ///////////////////////// START TESTS ////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+
+ StringReader sr;
+
+ sr = new StringReader(String.Empty);
+ Assert.Equal(String.Empty, sr.ReadToEnd());
+
+ }
+
+ [Fact]
+ public static void ReadToEndString() {
+ String str1 = "Hello\0\t\v \\ World";
+ StringReader sr = new StringReader(str1);
+ Assert.Equal(str1, sr.ReadToEnd());
+ }
+
+ [Fact]
+ public static void ReadToEndPsuedoRandom() {
+ // [] Try with large random strings
+ //-----------------------------------------------------------
+ String str1 = String.Empty;
+ Random r = new Random(-55);
+ for (int i = 0; i < 10000; i++)
+ str1 += (Char)r.Next(0, 255);
+
+ StringReader sr = new StringReader(str1);
+ Assert.Equal(str1, sr.ReadToEnd());
+ }
+ }
+}