diff options
author | stephentoub <stoub@microsoft.com> | 2015-08-09 19:06:31 +0300 |
---|---|---|
committer | stephentoub <stoub@microsoft.com> | 2015-08-11 01:29:24 +0300 |
commit | bac232c457ff0053909bc2c3a45f6711f9df5121 (patch) | |
tree | 0fdb7c4d178b676dd5707380409e9ca6f914de0e | |
parent | 381785c196c573fe4ee7b36eaf4c53f4f5526ca0 (diff) |
Address PR feedback
- Fixed test failures on Linux
- Fixes test failures when run with different cultures
- Fixed ordering of arguments to Assert.Equal
- Changed several Assert.Equal to be Assert.Same
- Added some missing Assert.True calls
- Changed several [Facts] to be [Theory]s
- Removed some stale comments
- Added copyright header to all new .cs files
- A few other miscellaneous things...
22 files changed, 587 insertions, 626 deletions
diff --git a/src/System.IO/tests/BinaryWriter/BinaryWriterTests.cs b/src/System.IO/tests/BinaryWriter/BinaryWriterTests.cs index 2bc27b55dc..eb711eafd9 100644 --- a/src/System.IO/tests/BinaryWriter/BinaryWriterTests.cs +++ b/src/System.IO/tests/BinaryWriter/BinaryWriterTests.cs @@ -1,13 +1,16 @@ -using Xunit; +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; +using System.Collections.Generic; using System.IO; using System.Text; +using Xunit; namespace Tests { public class BinaryWriterTests { - [Fact] public static void BinaryWriter_CtorAndWriteTests1() { @@ -28,41 +31,25 @@ namespace Tests public static void BinaryWriter_CtorAndWriteTests1_Negative() { // [] Should throw ArgumentNullException for null argument - Assert.Throws<ArgumentNullException>(() => { BinaryWriter writer = new BinaryWriter(null); }); + Assert.Throws<ArgumentNullException>(() => new BinaryWriter(null)); // [] Can't construct a BinaryWriter on a readonly stream using (MemoryStream memStream = new MemoryStream(new byte[10], false)) { - Assert.Throws<ArgumentException>(() => { BinaryWriter writer = new BinaryWriter(memStream); }); + Assert.Throws<ArgumentException>(() => new BinaryWriter(memStream)); } // [] Can't construct a BinaryWriter with a closed stream { MemoryStream memStream = new MemoryStream(); memStream.Dispose(); - Assert.Throws<ArgumentException>(() => { BinaryWriter dw2 = new BinaryWriter(memStream); }); + Assert.Throws<ArgumentException>(() => new BinaryWriter(memStream)); } } - [Fact] - public static void BinaryWriter_EncodingCtorAndWriteTests_UTF8() - { - BinaryWriter_EncodingCtorAndWriteTests(Encoding.UTF8, "This is UTF8\u00FF"); - } - - [Fact] - public static void BinaryWriter_EncodingCtorAndWriteTests_BigEndianUnicode() - { - BinaryWriter_EncodingCtorAndWriteTests(Encoding.BigEndianUnicode, "This is BigEndianUnicode\u00FF"); - } - - [Fact] - public static void BinaryWriter_EncodingCtorAndWriteTests_Unicode() - { - BinaryWriter_EncodingCtorAndWriteTests(Encoding.Unicode, "This is Unicode\u00FF"); - } - - private static void BinaryWriter_EncodingCtorAndWriteTests(Encoding encoding, string testString) + [Theory] + [MemberData("EncodingAndEncodingStrings")] + public static void BinaryWriter_EncodingCtorAndWriteTests(Encoding encoding, string testString) { using (MemoryStream memStream = new MemoryStream()) using (BinaryWriter writer = new BinaryWriter(memStream, encoding)) @@ -76,16 +63,24 @@ namespace Tests } } + public static IEnumerable<object[]> EncodingAndEncodingStrings + { + get + { + yield return new object[] { Encoding.UTF8, "This is UTF8\u00FF" }; + yield return new object[] { Encoding.BigEndianUnicode, "This is BigEndianUnicode\u00FF" }; + yield return new object[] { Encoding.Unicode, "This is Unicode\u00FF" }; + } + } + [Fact] public static void BinaryWriter_EncodingCtorAndWriteTests_Negative() { // [] Check for ArgumentNullException on null stream - Assert.Throws<ArgumentNullException>( - () => { new BinaryReader((Stream)null, Encoding.UTF8); }); + Assert.Throws<ArgumentNullException>(() => new BinaryReader((Stream)null, Encoding.UTF8)); // [] Check for ArgumentNullException on null encoding - Assert.Throws<ArgumentNullException>( - () => { new BinaryReader(new MemoryStream(), null); }); + Assert.Throws<ArgumentNullException>(() => new BinaryReader(new MemoryStream(), null)); } [Fact] @@ -106,7 +101,7 @@ namespace Tests { lReturn = dw2.Seek(iArrLargeValues[iLoop], SeekOrigin.Begin); - Assert.Equal(lReturn, iArrLargeValues[iLoop]); + Assert.Equal(iArrLargeValues[iLoop], lReturn); } dw2.Dispose(); mstr.Dispose(); @@ -117,7 +112,7 @@ namespace Tests dw2.Write("0123456789".ToCharArray()); lReturn = dw2.Seek(0, SeekOrigin.Begin); - Assert.Equal(lReturn, 0); + Assert.Equal(0, lReturn); dw2.Write("lki".ToCharArray()); dw2.Flush(); @@ -126,7 +121,7 @@ namespace Tests for (int i = 0; i < bArr.Length; i++) sb.Append((Char)bArr[i]); - Assert.Equal(sb.ToString(), "lki3456789"); + Assert.Equal("lki3456789", sb.ToString()); dw2.Dispose(); mstr.Dispose(); @@ -137,7 +132,7 @@ namespace Tests dw2.Write("0123456789".ToCharArray()); lReturn = dw2.Seek(3, SeekOrigin.Begin); - Assert.Equal(lReturn, 3); + Assert.Equal(3, lReturn); dw2.Write("lk".ToCharArray()); dw2.Flush(); @@ -146,7 +141,7 @@ namespace Tests for (int i = 0; i < bArr.Length; i++) sb.Append((Char)bArr[i]); - Assert.Equal(sb.ToString(), "012lk56789"); + Assert.Equal("012lk56789", sb.ToString()); dw2.Dispose(); mstr.Dispose(); @@ -157,7 +152,7 @@ namespace Tests dw2.Write("0123456789".ToCharArray()); lReturn = dw2.Seek(-3, SeekOrigin.End); - Assert.Equal(lReturn, 7); + Assert.Equal(7, lReturn); dw2.Write("ll".ToCharArray()); dw2.Flush(); @@ -166,7 +161,7 @@ namespace Tests for (int i = 0; i < bArr.Length; i++) sb.Append((Char)bArr[i]); - Assert.Equal(sb.ToString(), "0123456ll9"); + Assert.Equal("0123456ll9", sb.ToString()); dw2.Dispose(); mstr.Dispose(); @@ -178,7 +173,7 @@ namespace Tests mstr.Position = 2; lReturn = dw2.Seek(2, SeekOrigin.Current); - Assert.Equal(lReturn, 4); + Assert.Equal(4, lReturn); dw2.Write("ll".ToCharArray()); dw2.Flush(); @@ -187,7 +182,7 @@ namespace Tests for (int i = 0; i < bArr.Length; i++) sb.Append((Char)bArr[i]); - Assert.Equal(sb.ToString(), "0123ll6789"); + Assert.Equal("0123ll6789", sb.ToString()); dw2.Dispose(); mstr.Dispose(); @@ -198,7 +193,7 @@ namespace Tests dw2.Write("0123456789".ToCharArray()); lReturn = dw2.Seek(4, SeekOrigin.End); //This wont throw any exception now. - Assert.Equal(mstr.Position, 14); + Assert.Equal(14, mstr.Position); dw2.Dispose(); @@ -210,7 +205,7 @@ namespace Tests dw2.Write("0123456789".ToCharArray()); lReturn = dw2.Seek(11, SeekOrigin.Begin); //This wont throw any exception now. - Assert.Equal(mstr.Position, 11); + Assert.Equal(11, mstr.Position); dw2.Dispose(); mstr.Dispose(); @@ -221,7 +216,7 @@ namespace Tests dw2.Write("0123456789".ToCharArray()); lReturn = dw2.Seek(10, SeekOrigin.Begin); - Assert.Equal(lReturn, 10); + Assert.Equal(10, lReturn); dw2.Write("ll".ToCharArray()); bArr = mstr.ToArray(); @@ -229,30 +224,25 @@ namespace Tests for (int i = 0; i < bArr.Length; i++) sb.Append((Char)bArr[i]); - Assert.Equal(sb.ToString(), "0123456789ll"); + Assert.Equal("0123456789ll", sb.ToString()); dw2.Dispose(); mstr.Dispose(); } - [Fact] - public static void BinaryWriter_SeekTests_NegativeOffset() + [Theory] + [InlineData(-1)] + [InlineData(-2)] + [InlineData(-10000)] + [InlineData(Int32.MinValue)] + public static void BinaryWriter_SeekTests_NegativeOffset(int invalidValue) { - int[] invalidValues = new Int32[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue, Int16.MinValue }; - - // [] ArgumentOutOfRangeException if offset is negative + // [] IOException if offset is negative using (MemoryStream memStream = new MemoryStream()) using (BinaryWriter writer = new BinaryWriter(memStream)) { writer.Write("Hello, this is my string".ToCharArray()); - - foreach (int invalidValue in invalidValues) - { - Assert.Throws<IOException>(() => - { - writer.Seek(invalidValue, SeekOrigin.Begin); - }); - } + Assert.Throws<IOException>(() => writer.Seek(invalidValue, SeekOrigin.Begin)); } } @@ -279,7 +269,7 @@ namespace Tests using (MemoryStream ms2 = new MemoryStream()) using (BinaryWriter sr2 = new BinaryWriter(ms2)) { - Assert.Equal(ms2, sr2.BaseStream); + Assert.Same(ms2, sr2.BaseStream); } } @@ -290,11 +280,12 @@ namespace Tests using (MemoryStream memstr2 = new MemoryStream()) using (BinaryWriter bw2 = new BinaryWriter(memstr2)) { - bw2.Write("HelloWorld"); - //TODO:: Ckeck with dev why it's 11 bytes. - Assert.Equal(11, memstr2.Length); + string str = "HelloWorld"; + int expectedLength = str.Length + 1; // 1 for 7-bit encoded length + bw2.Write(str); + Assert.Equal(expectedLength, memstr2.Length); bw2.Flush(); - Assert.Equal(11, memstr2.Length); + Assert.Equal(expectedLength, memstr2.Length); } // [] Flushing closed writer should not throw an exception. diff --git a/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteByteCharTests.cs b/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteByteCharTests.cs index 4e464040e7..92c0a00f18 100644 --- a/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteByteCharTests.cs +++ b/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteByteCharTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using Xunit; using System; using System.IO; @@ -7,7 +10,6 @@ namespace BinaryWriterTests { public class BinaryWriter_WriteByteCharTests { - /// <summary> /// Cases Tested: /// 1) Tests that BinaryWriter properly writes chars into a stream. @@ -24,31 +26,24 @@ namespace BinaryWriterTests Char[] chArr = new Char[0]; int ii = 0; - // [] Write a series of characters to a Memorystream and read them back + // [] Write a series of characters to a MemoryStream and read them back chArr = new Char[] { 'A', 'c', '\0', '\u2701', '$', '.', '1', 'l', '\u00FF', '\n', '\t', '\v' }; for (ii = 0; ii < chArr.Length; ii++) dw2.Write(chArr[ii]); dw2.Flush(); mstr.Position = 0; - try - { - for (ii = 0; ; ii++) - { - Assert.Equal(dr2.ReadChar(), chArr[ii]); - } - } - catch (EndOfStreamException) + for (ii = 0; ii < chArr.Length; ii++) { + char c = dr2.ReadChar(); + Assert.Equal(chArr[ii], c); } - - Assert.Equal(ii, chArr.Length); + Assert.Throws<EndOfStreamException>(() => dr2.ReadChar()); dw2.Dispose(); dr2.Dispose(); mstr.Dispose(); - //VSWhidbey #273805 //If someone writes out characters using BinaryWriter's Write(char[]) method, they must use something like BinaryReader's ReadChars(int) method to read it back in. //They cannot use BinaryReader's ReadChar(). Similarly, data written using Write(char) can't be read back using ReadChars(int). @@ -73,7 +68,6 @@ namespace BinaryWriterTests [Fact] public static void BinaryWriter_WriteCharTest_Negative() { - //VSWhidbey #273805 //If someone writes out characters using BinaryWriter's Write(char[]) method, they must use something like BinaryReader's ReadChars(int) method to read it back in. //They cannot use BinaryReader's ReadChar(). Similarly, data written using Write(char) can't be read back using ReadChars(int). @@ -86,14 +80,14 @@ namespace BinaryWriterTests for (int i = 0; i < randomNumbers.Length; i++) { ch = (Char)randomNumbers[i]; - Assert.Throws<ArgumentException>(delegate { writer.Write(ch); }); + Assert.Throws<ArgumentException>(() => writer.Write(ch)); } // between 56320 <= x < 57343 randomNumbers = new int[] { 56320, 57342, 56431, 57001, 56453, 57245, 57111 }; for (int i = 0; i < randomNumbers.Length; i++) { ch = (Char)randomNumbers[i]; - Assert.Throws<ArgumentException>(delegate { writer.Write(ch); }); + Assert.Throws<ArgumentException>(() => writer.Write(ch)); } writer.Dispose(); @@ -107,8 +101,8 @@ namespace BinaryWriterTests [Fact] public static void BinaryWriter_WriteCharTest2() { - //VSWhidbey #275448 - BinaryReader/BinaryWriter don't do well when mixing char or char[] data and binary data. - //The bug was Wont Fix for compatibility reasons + // BinaryReader/BinaryWriter don't do well when mixing char or char[] data and binary data. + // This behavior remains for compat. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Stream stream = new MemoryStream(); @@ -127,7 +121,7 @@ namespace BinaryWriterTests stream.Seek(0, SeekOrigin.Begin); BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding(codepageName)); char japanese = reader.ReadChar(); - Assert.True((int)japanese == 0x30ca); + Assert.Equal(0x30ca, (int)japanese); byte[] readBytes = reader.ReadBytes(5); for (int i = 0; i < 5; i++) { @@ -162,7 +156,7 @@ namespace BinaryWriterTests for (ii = 0; ii < bytArr.Length; ii++) { - Assert.Equal(dr2.ReadByte(), bytArr[ii]); + Assert.Equal(bytArr[ii], dr2.ReadByte()); } // [] Check End Of Stream @@ -197,7 +191,7 @@ namespace BinaryWriterTests for (ii = 0; ii < sbArr.Length; ii++) { - Assert.Equal(dr2.ReadSByte(), sbArr[ii]); + Assert.Equal(sbArr[ii], dr2.ReadSByte()); } dr2.Dispose(); @@ -255,7 +249,7 @@ namespace BinaryWriterTests for (ii = 0; ii < bytArr.Length; ii++) { - Assert.Equal(dr2.ReadByte(), bytArr[ii]); + Assert.Equal(bytArr[ii], dr2.ReadByte()); } // [] Check End Of Stream @@ -348,11 +342,11 @@ namespace BinaryWriterTests bReadArr = new Byte[bArr.Length]; ReturnValue = dr2.Read(bReadArr, 0, bArr.Length); - Assert.Equal(ReturnValue, bArr.Length); + Assert.Equal(bArr.Length, ReturnValue); for (ii = 0; ii < bArr.Length; ii++) { - Assert.Equal(bReadArr[ii], bArr[ii]); + Assert.Equal(bArr[ii], bReadArr[ii]); } dw2.Dispose(); @@ -393,7 +387,7 @@ namespace BinaryWriterTests for (ii = 0; ii < chArr.Length; ii++) { - Assert.Equal(dr2.ReadChar(), chArr[ii]); + Assert.Equal(chArr[ii], dr2.ReadChar()); } // [] Check End Of Stream @@ -455,26 +449,23 @@ namespace BinaryWriterTests /// <summary> /// Cases Tested: - ///VSWhidbey #273805 - ///If someone writes out characters using BinaryWriter's Write(char[]) method, they must use something like BinaryReader's ReadChars(int) method to read it back in. - ///They cannot use BinaryReader's ReadChar(). Similarly, data written using Write(char) can't be read back using ReadChars(int). - /// - ///A high-surrogate is a Unicode code point in the range U+D800 through U+DBFF and a low-surrogate is a Unicode code point in the range U+DC00 through U+DFFF - /// - ///UPDATE: 9/21/2006: We dont throw on the second read but then throws continuously - note the loop count difference in the 2 loops - ///See VSWhdibey 598304 - ///From [KimHamil] - ///BinaryReader was reverting to its original location instead of advancing. This was changed to skip past the char in the surrogate range. - ///The affected method is InternalReadOneChar (IROC). Note that the work here is slightly complicated by the way surrogates are handled by - ///the decoding classes. When IROC calls decoder.GetChars(), if the bytes passed in are surrogates, UnicodeEncoding doesn't report it. - ///charsRead would end up being one value, and since BinaryReader doesn't have the logic telling it exactly how many bytes total to expect, - ///it calls GetChars in a second loop. In that loop, UnicodeEncoding matches up a surrogate pair. If it realizes it's too big for the encoding, - ///then it throws an ArgumentException (chars overflow). This meant that BinaryReader.IROC is advancing past two chars in the surrogate - ///range, which is why the position actually needs to be moved back (but not past the first surrogate char). - - ///Note that UnicodeEncoding doesn't always throw when it encounters two successive chars in the surrogate range. The exception - ///encountered here happens if it finds a valid pair but then determines it's too long. If the pair isn't valid (a low then a high), - ///then it returns 0xfffd, which is why BinaryReader.ReadChar needs to do an explicit check. (It always throws when it encounters a surrogate) + /// If someone writes out characters using BinaryWriter's Write(char[]) method, they must use something like BinaryReader's ReadChars(int) method to read it back in. + /// They cannot use BinaryReader's ReadChar(). Similarly, data written using Write(char) can't be read back using ReadChars(int). + /// A high-surrogate is a Unicode code point in the range U+D800 through U+DBFF and a low-surrogate is a Unicode code point in the range U+DC00 through U+DFFF + /// + /// We dont throw on the second read but then throws continuously - note the loop count difference in the 2 loops + /// + /// BinaryReader was reverting to its original location instead of advancing. This was changed to skip past the char in the surrogate range. + /// The affected method is InternalReadOneChar (IROC). Note that the work here is slightly complicated by the way surrogates are handled by + /// the decoding classes. When IROC calls decoder.GetChars(), if the bytes passed in are surrogates, UnicodeEncoding doesn't report it. + /// charsRead would end up being one value, and since BinaryReader doesn't have the logic telling it exactly how many bytes total to expect, + /// it calls GetChars in a second loop. In that loop, UnicodeEncoding matches up a surrogate pair. If it realizes it's too big for the encoding, + /// then it throws an ArgumentException (chars overflow). This meant that BinaryReader.IROC is advancing past two chars in the surrogate + /// range, which is why the position actually needs to be moved back (but not past the first surrogate char). + /// + /// Note that UnicodeEncoding doesn't always throw when it encounters two successive chars in the surrogate range. The exception + /// encountered here happens if it finds a valid pair but then determines it's too long. If the pair isn't valid (a low then a high), + /// then it returns 0xfffd, which is why BinaryReader.ReadChar needs to do an explicit check. (It always throws when it encounters a surrogate) /// </summary> [Fact] public static void BinaryWriter_WriteCharArrayTest2() @@ -502,18 +493,18 @@ namespace BinaryWriterTests { reader.ReadChar(); - Assert.Equal(i, 1); + Assert.Equal(1, i); } catch (ArgumentException) { - // I guess sometimes it throws and othertimes, it doesn't? - // Based on the comments above. + // ArgumentException is sometimes thrown on ReadChar() due to the + // behavior outlined in the method summary. } } Char[] chars = reader.ReadChars(randomChars.Length); for (int i = 0; i < randomChars.Length; i++) - Assert.Equal(chars[i], randomChars[i]); + Assert.Equal(randomChars[i], chars[i]); reader.Dispose(); writer.Dispose(); @@ -559,11 +550,11 @@ namespace BinaryWriterTests dr2 = new BinaryReader(mstr); chReadArr = new Char[chArr.Length]; ReturnValue = dr2.Read(chReadArr, 0, chArr.Length); - Assert.Equal(ReturnValue, chArr.Length); + Assert.Equal(chArr.Length, ReturnValue); for (ii = 0; ii < chArr.Length; ii++) { - Assert.Equal(chReadArr[ii], chArr[ii]); + Assert.Equal(chArr[ii], chReadArr[ii]); } mstr.Dispose(); diff --git a/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteTests.cs b/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteTests.cs index 448e77085e..24f10bdd2f 100644 --- a/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteTests.cs +++ b/src/System.IO/tests/BinaryWriter/BinaryWriter_WriteTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using Xunit; using System; using System.IO; diff --git a/src/System.IO/tests/MemoryStream/Inputs.cs b/src/System.IO/tests/MemoryStream/Inputs.cs deleted file mode 100644 index 413c927554..0000000000 --- a/src/System.IO/tests/MemoryStream/Inputs.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; - -internal static class Inputs -{ - public static IEnumerable<ArraySegment<byte>> GetArraysVariedByOffsetAndLength() - { - yield return new ArraySegment<byte>(new byte[512], 0, 512); - yield return new ArraySegment<byte>(new byte[512], 1, 511); - yield return new ArraySegment<byte>(new byte[512], 2, 510); - yield return new ArraySegment<byte>(new byte[512], 256, 256); - yield return new ArraySegment<byte>(new byte[512], 512, 0); - yield return new ArraySegment<byte>(new byte[512], 511, 1); - yield return new ArraySegment<byte>(new byte[512], 510, 2); - } - - public static IEnumerable<byte[]> GetArraysVariedBySize() - { - yield return FillWithData(new byte[0]); - yield return FillWithData(new byte[1]); - yield return FillWithData(new byte[2]); - yield return FillWithData(new byte[254]); - yield return FillWithData(new byte[255]); - yield return FillWithData(new byte[256]); - yield return FillWithData(new byte[511]); - yield return FillWithData(new byte[512]); - yield return FillWithData(new byte[513]); - yield return FillWithData(new byte[1023]); - yield return FillWithData(new byte[1024]); - yield return FillWithData(new byte[1025]); - yield return FillWithData(new byte[2047]); - yield return FillWithData(new byte[2048]); - yield return FillWithData(new byte[2049]); - } - - private static byte[] FillWithData(byte[] buffer) - { - for (int i = 0; i < buffer.Length;i ++) - { - buffer[i] = (byte)i; - } - - return buffer; - } -} diff --git a/src/System.IO/tests/MemoryStream/MemoryStream_TryGetBufferTests.cs b/src/System.IO/tests/MemoryStream/MemoryStream_TryGetBufferTests.cs index 2488ae0855..3d928dfb41 100644 --- a/src/System.IO/tests/MemoryStream/MemoryStream_TryGetBufferTests.cs +++ b/src/System.IO/tests/MemoryStream/MemoryStream_TryGetBufferTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using Xunit; using System; using System.IO; @@ -10,10 +13,12 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); + ArraySegment<byte> segment; + Assert.True(stream.TryGetBuffer(out segment)); - Assert.True(result); + Assert.NotNull(segment.Array); + Assert.Equal(0, segment.Offset); + Assert.Equal(0, segment.Count); } [Fact] @@ -21,10 +26,12 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(512); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); + ArraySegment<byte> segment; + Assert.True(stream.TryGetBuffer(out segment)); - Assert.True(result); + Assert.Equal(512, segment.Array.Length); + Assert.Equal(0, segment.Offset); + Assert.Equal(0, segment.Count); } [Fact] @@ -32,10 +39,8 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(new byte[512]); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); - - Assert.False(result); + ArraySegment<byte> segment; + Assert.False(stream.TryGetBuffer(out segment)); } [Fact] @@ -43,10 +48,8 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(new byte[512], writable: true); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); - - Assert.False(result); + ArraySegment<byte> segment; + Assert.False(stream.TryGetBuffer(out segment)); } [Fact] @@ -54,10 +57,8 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(new byte[512], index: 0, count: 512); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); - - Assert.False(result); + ArraySegment<byte> segment; + Assert.False(stream.TryGetBuffer(out segment)); } [Fact] @@ -65,10 +66,8 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(new byte[512], index: 0, count: 512, writable: true); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); - - Assert.False(result); + ArraySegment<byte> segment; + Assert.False(stream.TryGetBuffer(out segment)); } [Fact] @@ -76,10 +75,8 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(new byte[512], index: 0, count: 512, writable: true, publiclyVisible: false); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); - - Assert.False(result); + ArraySegment<byte> segment; + Assert.False(stream.TryGetBuffer(out segment)); } [Fact] @@ -87,95 +84,78 @@ public class MemoryStream_TryGetBufferTests { var stream = new MemoryStream(new byte[512], index: 0, count: 512, writable: true, publiclyVisible: true); - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); + ArraySegment<byte> segment; + Assert.True(stream.TryGetBuffer(out segment)); - Assert.True(result); + Assert.NotNull(segment.Array); + Assert.Equal(512, segment.Array.Length); + Assert.Equal(0, segment.Offset); + Assert.Equal(512, segment.Count); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_AlwaysReturnsEmptyArraySegment() + [Theory] + [MemberData("GetArraysVariedBySize")] + public static void TryGetBuffer_Constructor_ByteArray_AlwaysReturnsEmptyArraySegment(byte[] array) { - var arrays = Inputs.GetArraysVariedBySize(); - - foreach (byte[] array in arrays) - { - var stream = new MemoryStream(array); + var stream = new MemoryStream(array); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.False(stream.TryGetBuffer(out result)); - // publiclyVisible = false; - Assert.True(default(ArraySegment<byte>).Equals(result)); - } + // publiclyVisible = false; + Assert.True(default(ArraySegment<byte>).Equals(result)); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_Bool_AlwaysReturnsEmptyArraySegment() + [Theory] + [MemberData("GetArraysVariedBySize")] + public static void TryGetBuffer_Constructor_ByteArray_Bool_AlwaysReturnsEmptyArraySegment(byte[] array) { - var arrays = Inputs.GetArraysVariedBySize(); - - foreach (byte[] array in arrays) - { - var stream = new MemoryStream(array, writable: true); + var stream = new MemoryStream(array, writable: true); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.False(stream.TryGetBuffer(out result)); - // publiclyVisible = false; - Assert.True(default(ArraySegment<byte>).Equals(result)); - } + // publiclyVisible = false; + Assert.True(default(ArraySegment<byte>).Equals(result)); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_AlwaysReturnsEmptyArraySegment() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_AlwaysReturnsEmptyArraySegment(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); - - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.False(stream.TryGetBuffer(out result)); - // publiclyVisible = false; - Assert.True(default(ArraySegment<byte>).Equals(result)); - } + // publiclyVisible = false; + Assert.True(default(ArraySegment<byte>).Equals(result)); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_AlwaysReturnsEmptyArraySegment() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_AlwaysReturnsEmptyArraySegment(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); - - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.False(stream.TryGetBuffer(out result)); - // publiclyVisible = false; - Assert.True(default(ArraySegment<byte>).Equals(result)); - } + // publiclyVisible = false; + Assert.True(default(ArraySegment<byte>).Equals(result)); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_FalseAsPubliclyVisible_ReturnsEmptyArraySegment() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_FalseAsPubliclyVisible_ReturnsEmptyArraySegment(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); - - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: false); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: false); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.False(stream.TryGetBuffer(out result)); - // publiclyVisible = false; - Assert.True(default(ArraySegment<byte>).Equals(result)); - } + // publiclyVisible = false; + Assert.True(default(ArraySegment<byte>).Equals(result)); } [Fact] @@ -184,7 +164,7 @@ public class MemoryStream_TryGetBufferTests var stream = new MemoryStream(); ArraySegment<byte> result; - stream.TryGetBuffer(out result); + Assert.True(stream.TryGetBuffer(out result)); Assert.Equal(0, result.Offset); @@ -196,25 +176,21 @@ public class MemoryStream_TryGetBufferTests var stream = new MemoryStream(512); ArraySegment<byte> result; - stream.TryGetBuffer(out result); + Assert.True(stream.TryGetBuffer(out result)); Assert.Equal(0, result.Offset); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_ValueAsIndexAndTrueAsPubliclyVisible_AlwaysReturnsOffsetSetToIndex() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_ValueAsIndexAndTrueAsPubliclyVisible_AlwaysReturnsOffsetSetToIndex(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); - - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); - Assert.Equal(array.Offset, result.Offset); - } + Assert.Equal(array.Offset, result.Offset); } [Fact] @@ -223,25 +199,22 @@ public class MemoryStream_TryGetBufferTests var stream = new MemoryStream(); ArraySegment<byte> result; - stream.TryGetBuffer(out result); + Assert.True(stream.TryGetBuffer(out result)); Assert.Equal(0, result.Count); } - [Fact] - public static void TryGetBuffer_Constructor_ReturnsCountSetToWrittenLength() + [Theory] + [MemberData("GetArraysVariedBySize")] + public static void TryGetBuffer_Constructor_ReturnsCountSetToWrittenLength(byte[] array) { - var arrays = Inputs.GetArraysVariedBySize(); - foreach (var array in arrays) - { - var stream = new MemoryStream(); - stream.Write(array, 0, array.Length); + var stream = new MemoryStream(); + stream.Write(array, 0, array.Length); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); - Assert.Equal(array.Length, result.Count); - } + Assert.Equal(array.Length, result.Count); } [Fact] @@ -250,41 +223,34 @@ public class MemoryStream_TryGetBufferTests var stream = new MemoryStream(512); ArraySegment<byte> result; - stream.TryGetBuffer(out result); + Assert.True(stream.TryGetBuffer(out result)); Assert.Equal(0, result.Offset); } - [Fact] - public static void TryGetBuffer_Constructor_Int32_ReturnsCountSetToWrittenLength() + [Theory] + [MemberData("GetArraysVariedBySize")] + public static void TryGetBuffer_Constructor_Int32_ReturnsCountSetToWrittenLength(byte[] array) { - var arrays = Inputs.GetArraysVariedBySize(); - foreach (var array in arrays) - { - var stream = new MemoryStream(512); - stream.Write(array, 0, array.Length); + var stream = new MemoryStream(512); + stream.Write(array, 0, array.Length); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); - Assert.Equal(array.Length, result.Count); - } + Assert.Equal(array.Length, result.Count); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_ValueAsCountAndTrueAsPubliclyVisible_AlwaysReturnsCountSetToCount() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_ValueAsCountAndTrueAsPubliclyVisible_AlwaysReturnsCountSetToCount(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); - Assert.Equal(array.Count, result.Count); - } + Assert.Equal(array.Count, result.Count); } [Fact] @@ -293,7 +259,7 @@ public class MemoryStream_TryGetBufferTests var stream = new MemoryStream(); ArraySegment<byte> result; - stream.TryGetBuffer(out result); + Assert.True(stream.TryGetBuffer(out result)); Assert.NotNull(result.Array); } @@ -305,8 +271,8 @@ public class MemoryStream_TryGetBufferTests ArraySegment<byte> result1; ArraySegment<byte> result2; - stream.TryGetBuffer(out result1); - stream.TryGetBuffer(out result2); + Assert.True(stream.TryGetBuffer(out result1)); + Assert.True(stream.TryGetBuffer(out result2)); Assert.Same(result1.Array, result2.Array); } @@ -318,8 +284,8 @@ public class MemoryStream_TryGetBufferTests ArraySegment<byte> result1; ArraySegment<byte> result2; - stream.TryGetBuffer(out result1); - stream.TryGetBuffer(out result2); + Assert.True(stream.TryGetBuffer(out result1)); + Assert.True(stream.TryGetBuffer(out result2)); Assert.Same(result1.Array, result2.Array); } @@ -330,99 +296,120 @@ public class MemoryStream_TryGetBufferTests var stream = new MemoryStream(512); ArraySegment<byte> result1; - stream.TryGetBuffer(out result1); + Assert.True(stream.TryGetBuffer(out result1)); // Force the stream to resize the underlying array stream.Write(new byte[1024], 0, 1024); ArraySegment<byte> result2; - stream.TryGetBuffer(out result2); + Assert.True(stream.TryGetBuffer(out result2)); Assert.NotSame(result1.Array, result2.Array); } - [Fact] - public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_ValueAsBufferAndTrueAsPubliclyVisible_AlwaysReturnsArraySetToBuffer() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_Constructor_ByteArray_Int32_Int32_Bool_Bool_ValueAsBufferAndTrueAsPubliclyVisible_AlwaysReturnsArraySetToBuffer(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); - Assert.Same(array.Array, result.Array); - } + Assert.Same(array.Array, result.Array); } - [Fact] - public static void TryGetBuffer_WhenDisposed_ReturnsTrue() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_WhenDisposed_ReturnsTrue(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); + stream.Dispose(); - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - stream.Dispose(); - - ArraySegment<byte> _; - bool result = stream.TryGetBuffer(out _); + ArraySegment<byte> segment; + Assert.True(stream.TryGetBuffer(out segment)); - Assert.True(result); - } + Assert.Same(array.Array, segment.Array); + Assert.Equal(array.Offset, segment.Offset); + Assert.Equal(array.Count, segment.Count); } - [Fact] - public static void TryGetBuffer_WhenDisposed_ReturnsOffsetSetToIndex() + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_WhenDisposed_ReturnsOffsetSetToIndex(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); + stream.Dispose(); - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - stream.Dispose(); - - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); - Assert.Equal(array.Offset, result.Offset); - } + Assert.Equal(array.Offset, result.Offset); } + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_WhenDisposed_ReturnsCountSetToCount(ArraySegment<byte> array) + { + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); + stream.Dispose(); - [Fact] - public static void TryGetBuffer_WhenDisposed_ReturnsCountSetToCount() + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); + + Assert.Equal(array.Count, result.Count); + } + + [Theory] + [MemberData("GetArraysVariedByOffsetAndLength")] + public static void TryGetBuffer_WhenDisposed_ReturnsArraySetToBuffer(ArraySegment<byte> array) { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); + var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); + stream.Dispose(); - foreach (var array in arrays) - { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - stream.Dispose(); + ArraySegment<byte> result; + Assert.True(stream.TryGetBuffer(out result)); - ArraySegment<byte> result; - stream.TryGetBuffer(out result); + Assert.Same(array.Array, result.Array); + } - Assert.Equal(array.Count, result.Count); - } + public static IEnumerable<object[]> GetArraysVariedByOffsetAndLength() + { + yield return new object[] { new ArraySegment<byte>(new byte[512], 0, 512) }; + yield return new object[] { new ArraySegment<byte>(new byte[512], 1, 511) }; + yield return new object[] { new ArraySegment<byte>(new byte[512], 2, 510) }; + yield return new object[] { new ArraySegment<byte>(new byte[512], 256, 256) }; + yield return new object[] { new ArraySegment<byte>(new byte[512], 512, 0) }; + yield return new object[] { new ArraySegment<byte>(new byte[512], 511, 1) }; + yield return new object[] { new ArraySegment<byte>(new byte[512], 510, 2) }; } - [Fact] - public static void TryGetBuffer_WhenDisposed_ReturnsArraySetToBuffer() + public static IEnumerable<object[]> GetArraysVariedBySize() { - var arrays = Inputs.GetArraysVariedByOffsetAndLength(); + yield return new object[] { FillWithData(new byte[0]) }; + yield return new object[] { FillWithData(new byte[1]) }; + yield return new object[] { FillWithData(new byte[2]) }; + yield return new object[] { FillWithData(new byte[254]) }; + yield return new object[] { FillWithData(new byte[255]) }; + yield return new object[] { FillWithData(new byte[256]) }; + yield return new object[] { FillWithData(new byte[511]) }; + yield return new object[] { FillWithData(new byte[512]) }; + yield return new object[] { FillWithData(new byte[513]) }; + yield return new object[] { FillWithData(new byte[1023]) }; + yield return new object[] { FillWithData(new byte[1024]) }; + yield return new object[] { FillWithData(new byte[1025]) }; + yield return new object[] { FillWithData(new byte[2047]) }; + yield return new object[] { FillWithData(new byte[2048]) }; + yield return new object[] { FillWithData(new byte[2049]) }; + } - foreach (var array in arrays) + private static byte[] FillWithData(byte[] buffer) + { + for (int i = 0; i < buffer.Length; i++) { - var stream = new MemoryStream(array.Array, index: array.Offset, count: array.Count, writable: true, publiclyVisible: true); - stream.Dispose(); - - ArraySegment<byte> result; - stream.TryGetBuffer(out result); - - Assert.Same(array.Array, result.Array); + buffer[i] = (byte)i; } + + return buffer; } -}
\ No newline at end of file +} diff --git a/src/System.IO/tests/Stream/NullTests.cs b/src/System.IO/tests/Stream/NullTests.cs index 57b4288216..582a87bc51 100644 --- a/src/System.IO/tests/Stream/NullTests.cs +++ b/src/System.IO/tests/Stream/NullTests.cs @@ -1,4 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Xunit; @@ -8,59 +12,16 @@ namespace StreamTests public class NullCtorTests { [Fact] - public static void TestNullStream() - { - var t = TestNullStream(Stream.Null); - t.Wait(); - } - - [Fact] - public static void TestNullTextReader() - { - TestTextReader(TextReader.Null); - } - - [Fact] - public static void TestNullStreamReader() - { - TestTextReader(StreamReader.Null); - } - - [Fact] - public static void TestNullStringReader() - { - TestTextReader(StringReader.Null); - } - - [Fact] - public static void TestNullTextWriter() - { - TestTextWriter(TextWriter.Null); - - } - - [Fact] - public static void TestNullStreamWriter() - { - TestTextWriter(StreamWriter.Null); - } - - [Fact] - public static void TestNullStringWriter() - { - TestTextWriter(StringWriter.Null); - } - - static async Task TestNullStream(Stream s) + public static async Task TestNullStream() { - int n; + Stream s = Stream.Null; s.Flush(); Assert.Equal(-1, s.ReadByte()); s.WriteByte(5); - n = s.Read(new byte[2], 0, 2); + int n = s.Read(new byte[2], 0, 2); Assert.Equal(0, n); s.Write(new byte[2], 0, 2); @@ -70,7 +31,9 @@ namespace StreamTests s.Dispose(); } - static void TestTextReader(TextReader input) + [Theory] + [MemberData("NullReaders")] + public static void TestNullTextReader(TextReader input) { StreamReader sr = input as StreamReader; @@ -89,7 +52,9 @@ namespace StreamTests input.Dispose(); } - static void TestTextWriter(TextWriter output) + [Theory] + [MemberData("NullWriters")] + public static void TextNullTextWriter(TextWriter output) { output.Flush(); output.Dispose(); @@ -100,5 +65,26 @@ namespace StreamTests output.Flush(); output.Dispose(); } + + public static IEnumerable<object[]> NullReaders + { + get + { + yield return new object[] { TextReader.Null }; + yield return new object[] { StreamReader.Null }; + yield return new object[] { StringReader.Null }; + } + } + + public static IEnumerable<object[]> NullWriters + { + get + { + yield return new object[] { TextWriter.Null }; + yield return new object[] { StreamWriter.Null }; + yield return new object[] { StringWriter.Null }; + } + } + } } diff --git a/src/System.IO/tests/Stream/StreamAsyncTests.cs b/src/System.IO/tests/Stream/StreamAsyncTests.cs index 434bca3307..e5e1ea8fd4 100644 --- a/src/System.IO/tests/Stream/StreamAsyncTests.cs +++ b/src/System.IO/tests/Stream/StreamAsyncTests.cs @@ -1,4 +1,6 @@ -using System; +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System.IO; using System.Threading.Tasks; using Xunit; diff --git a/src/System.IO/tests/Stream/StreamMethods.cs b/src/System.IO/tests/Stream/StreamMethods.cs index 412d647847..151c3aafca 100644 --- a/src/System.IO/tests/Stream/StreamMethods.cs +++ b/src/System.IO/tests/Stream/StreamMethods.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; using System.Threading.Tasks; @@ -48,7 +51,7 @@ namespace StreamTests else stream.Position = btArr.Length; - Assert.Equal(stream.Position, btArr.Length); + Assert.Equal(btArr.Length, stream.Position); lngPos = stream.Seek(0, SeekOrigin.Begin); Assert.Equal(0, lngPos); @@ -69,7 +72,7 @@ namespace StreamTests Assert.Equal(i + 1, stream.Position); } - Assert.Throws<IOException>( () => {lngPos = stream.Seek(-5, SeekOrigin.Begin); }); + Assert.Throws<IOException>(() => stream.Seek(-5, SeekOrigin.Begin)); lngPos = stream.Seek(5, SeekOrigin.Begin); Assert.Equal(5, lngPos); @@ -77,7 +80,7 @@ namespace StreamTests lngPos = stream.Seek(5, SeekOrigin.End); Assert.Equal(length + 5, lngPos); - Assert.Throws<IOException>( () => { lngPos = stream.Seek(-(btArr.Length + 1), SeekOrigin.End); }); + Assert.Throws<IOException>(() => stream.Seek(-(btArr.Length + 1), SeekOrigin.End)); lngPos = stream.Seek(-5, SeekOrigin.End); Assert.Equal(btArr.Length - 5, lngPos); @@ -92,7 +95,7 @@ namespace StreamTests Assert.Equal(i - 1, stream.Position); } - Assert.Throws<IOException>( () => {lngPos = stream.Seek(-1, SeekOrigin.Current); }); + Assert.Throws<IOException>(() => stream.Seek(-1, SeekOrigin.Current)); } private static async Task StreamTest(Stream stream, Boolean fSuppress) diff --git a/src/System.IO/tests/Stream/TestLeaveOpen.cs b/src/System.IO/tests/Stream/TestLeaveOpen.cs index 32c6c1aded..b9c654e229 100644 --- a/src/System.IO/tests/Stream/TestLeaveOpen.cs +++ b/src/System.IO/tests/Stream/TestLeaveOpen.cs @@ -1,6 +1,7 @@ -using System; +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System.IO; -using System.Threading.Tasks; using Xunit; namespace StreamTests diff --git a/src/System.IO/tests/Stream/TimeoutTests.cs b/src/System.IO/tests/Stream/TimeoutTests.cs index 710a93e9f4..9adf21e6b4 100644 --- a/src/System.IO/tests/Stream/TimeoutTests.cs +++ b/src/System.IO/tests/Stream/TimeoutTests.cs @@ -1,10 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; using Xunit; namespace StreamTests { - public class MyStream : Stream + public sealed class NopStream : Stream { public override bool CanRead { @@ -47,8 +50,9 @@ namespace StreamTests [Fact] public static void TestReadTimeoutCustomStream() { - TestReadTimeout(new MyStream()); + TestReadTimeout(new NopStream()); } + [Fact] public static void TestReadTimeoutMemoryStream() { @@ -58,15 +62,16 @@ namespace StreamTests private static void TestReadTimeout(Stream stream) { - Assert.Throws<InvalidOperationException>(() => { int readTimeout = stream.ReadTimeout; }); + Assert.Throws<InvalidOperationException>(() => stream.ReadTimeout); - Assert.Throws<InvalidOperationException>(() => { stream.ReadTimeout = 500; }); + Assert.Throws<InvalidOperationException>(() => stream.ReadTimeout = 500); } [Fact] public static void TestWriteTimeoutCustomStream() { - TestWriteTimeout(new MyStream()); + TestWriteTimeout(new NopStream()); } + [Fact] public static void TestWriteTimeoutMemoryStream() { @@ -75,14 +80,14 @@ namespace StreamTests private static void TestWriteTimeout(Stream stream) { - Assert.Throws<InvalidOperationException>(() => { int WriteTimeout = stream.WriteTimeout; }); - Assert.Throws<InvalidOperationException>(() => { stream.WriteTimeout = 500; }); + Assert.Throws<InvalidOperationException>(() => stream.WriteTimeout); + Assert.Throws<InvalidOperationException>(() => stream.WriteTimeout = 500); } [Fact] public static void TestCanTimeoutCustomStream() { - TestCanTimeout(new MyStream()); + TestCanTimeout(new NopStream()); } [Fact] diff --git a/src/System.IO/tests/StreamReader/StreamReaderCtorTests.cs b/src/System.IO/tests/StreamReader/StreamReaderCtorTests.cs index 7b85f6eae2..18ea97cc49 100644 --- a/src/System.IO/tests/StreamReader/StreamReaderCtorTests.cs +++ b/src/System.IO/tests/StreamReader/StreamReaderCtorTests.cs @@ -1,6 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; -using System.Text; using Xunit; namespace StreamReaderTests @@ -10,8 +12,7 @@ namespace StreamReaderTests [Fact] public static void StreamReaderNullPath() { - Assert.Throws<ArgumentNullException>( - () => { new StreamReader((Stream)null, true); }); + Assert.Throws<ArgumentNullException>(() => new StreamReader((Stream)null, true)); } [Fact] public static void InputStreamClosed() @@ -19,8 +20,7 @@ namespace StreamReaderTests var ms2 = new MemoryStream(); ms2.Dispose(); - Assert.Throws<ArgumentException>( - () => { new StreamReader(ms2, false); }); + Assert.Throws<ArgumentException>(() => new StreamReader(ms2, false)); } [Fact] diff --git a/src/System.IO/tests/StreamReader/StreamReaderTests.cs b/src/System.IO/tests/StreamReader/StreamReaderTests.cs index 37a49adc9a..9aef7635c2 100644 --- a/src/System.IO/tests/StreamReader/StreamReaderTests.cs +++ b/src/System.IO/tests/StreamReader/StreamReaderTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.Collections.Generic; using System.IO; @@ -135,7 +138,7 @@ namespace StreamReaderTests var ms = GetSmallStream(); var sw = new StreamReader(ms); - Assert.Equal(sw.BaseStream, ms); + Assert.Same(sw.BaseStream, ms); } [Fact] @@ -148,7 +151,7 @@ namespace StreamReaderTests for (int i = 0; i < baseInfo.Item1.Length; i++) { int tmp = sr.Read(); - Assert.Equal(tmp, (int)baseInfo.Item1[i]); + Assert.Equal((int)baseInfo.Item1[i], tmp); } sr.Dispose(); @@ -168,56 +171,46 @@ namespace StreamReaderTests sr.Read(); } } + [Fact] public static void ArgumentNullOnNullArray() { var baseInfo = GetCharArrayStream(); var sr = baseInfo.Item2; - Assert.Throws<ArgumentNullException>(() => - { - sr.Read(null, 0, 0); - }); + Assert.Throws<ArgumentNullException>(() => sr.Read(null, 0, 0)); } + [Fact] public static void ArgumentOutOfRangeOnInvalidOffset() { var sr = GetCharArrayStream().Item2; - Assert.Throws<ArgumentOutOfRangeException>(() => - { - sr.Read(new char[0], -1, 0); - }); + Assert.Throws<ArgumentOutOfRangeException>(() => sr.Read(new char[0], -1, 0)); } + [Fact] public static void ArgumentOutOfRangeOnNegativCount() { var sr = GetCharArrayStream().Item2; - Assert.Throws<ArgumentException>(() => - { - sr.Read(new char[0], 0, 1); - }); + Assert.Throws<ArgumentException>(() => sr.Read(new char[0], 0, 1)); } + [Fact] public static void ArgumentExceptionOffsetAndCount() { var sr = GetCharArrayStream().Item2; - Assert.Throws<ArgumentException>(() => - { - sr.Read(new Char[0], 2, 0); - }); + Assert.Throws<ArgumentException>(() => sr.Read(new Char[0], 2, 0)); } + [Fact] public static void ObjectDisposedExceptionDisposedStream() { var sr = GetCharArrayStream().Item2; sr.Dispose(); - Assert.Throws<ObjectDisposedException>(() => - { - char[] temp = new char[1]; - sr.Read(temp, 0, 1); - }); + Assert.Throws<ObjectDisposedException>(() => sr.Read(new char[1], 0, 1)); } + [Fact] public static void ObjectDisposedExceptionDisposedBaseStream() { @@ -225,11 +218,7 @@ namespace StreamReaderTests var sr = new StreamReader(ms); ms.Dispose(); - Assert.Throws<ObjectDisposedException>(() => - { - char[] temp = new char[1]; - sr.Read(temp, 0, 1); - }); + Assert.Throws<ObjectDisposedException>(() => sr.Read(new char[1], 0, 1)); } [Fact] @@ -253,10 +242,10 @@ namespace StreamReaderTests var read = sr.Read(chArr, 0, chArr.Length); - Assert.Equal(read, chArr.Length); + Assert.Equal(chArr.Length, read); for (int i = 0; i < baseInfo.Item1.Length; i++) { - Assert.Equal(chArr[i], baseInfo.Item1[i]); + Assert.Equal(baseInfo.Item1[i], chArr[i]); } } @@ -274,9 +263,10 @@ namespace StreamReaderTests Assert.Equal(read, 3); for (int i = 0; i < 3; i++) { - Assert.Equal(chArr[i + 4], baseInfo.Item1[i]); + Assert.Equal(baseInfo.Item1[i], chArr[i + 4]); } } + [Fact] public static void ObjectDisposedReadLine() { @@ -284,11 +274,9 @@ namespace StreamReaderTests var sr = baseInfo.Item2; sr.Dispose(); - Assert.Throws<ObjectDisposedException>(() => - { - sr.ReadLine(); - }); + Assert.Throws<ObjectDisposedException>(() => sr.ReadLine()); } + [Fact] public static void ObjectDisposedReadLineBaseStream() { @@ -296,10 +284,7 @@ namespace StreamReaderTests var sr = new StreamReader(ms); ms.Dispose(); - Assert.Throws<ObjectDisposedException>(() => - { - sr.ReadLine(); - }); + Assert.Throws<ObjectDisposedException>(() => sr.ReadLine()); } [Fact] @@ -342,7 +327,6 @@ namespace StreamReaderTests public static async Task ContinuousNewLinesAndTabsAsync() { var ms = new MemoryStream(); - // ms.Write( var sw = new StreamWriter(ms); sw.Write("\n\n\r\r\n"); sw.Flush(); diff --git a/src/System.IO/tests/StreamWriter/BaseStream.cs b/src/System.IO/tests/StreamWriter/BaseStream.cs index ed2233adc3..521efc8850 100644 --- a/src/System.IO/tests/StreamWriter/BaseStream.cs +++ b/src/System.IO/tests/StreamWriter/BaseStream.cs @@ -1,4 +1,6 @@ -using System; +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System.IO; using Xunit; @@ -12,7 +14,7 @@ namespace StreamWriterTests // [] Get an underlying memorystream MemoryStream memstr2 = new MemoryStream(); StreamWriter sw = new StreamWriter(memstr2); - Assert.Equal(sw.BaseStream, memstr2); + Assert.Same(sw.BaseStream, memstr2); } } } diff --git a/src/System.IO/tests/StreamWriter/CloseTests.cs b/src/System.IO/tests/StreamWriter/CloseTests.cs index 9d3b47923c..cbbfbc46d5 100644 --- a/src/System.IO/tests/StreamWriter/CloseTests.cs +++ b/src/System.IO/tests/StreamWriter/CloseTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; using Xunit; @@ -16,12 +19,12 @@ namespace StreamWriterTests sw2 = new StreamWriter(new MemoryStream()); sw2.Dispose(); - Assert.Throws<ObjectDisposedException>(() => { sw2.Write('A'); }); - Assert.Throws<ObjectDisposedException>(() => { sw2.Write("hello"); }); - Assert.Throws<ObjectDisposedException>(() => { sw2.Flush(); }); + Assert.Throws<ObjectDisposedException>(() => sw2.Write('A')); + Assert.Throws<ObjectDisposedException>(() => sw2.Write("hello")); + Assert.Throws<ObjectDisposedException>(() => sw2.Flush()); Assert.Null(sw2.BaseStream); - Assert.Throws<ObjectDisposedException>(() => { sw2.AutoFlush = true; }); + Assert.Throws<ObjectDisposedException>(() => sw2.AutoFlush = true); } [Fact] @@ -50,7 +53,7 @@ namespace StreamWriterTests StreamWriter sw2 = new StreamWriter(memstr2); sw2.Dispose(); - Assert.Throws<ObjectDisposedException>(() => { sw2.Flush(); }); + Assert.Throws<ObjectDisposedException>(() => sw2.Flush()); } } } diff --git a/src/System.IO/tests/StreamWriter/CtorTests.cs b/src/System.IO/tests/StreamWriter/CtorTests.cs index 66100b333f..a6e338f9b6 100644 --- a/src/System.IO/tests/StreamWriter/CtorTests.cs +++ b/src/System.IO/tests/StreamWriter/CtorTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; using Xunit; @@ -32,7 +35,7 @@ namespace StreamWriterTests // [] Check for ArgumentNullException on null encoding //----------------------------------------------------------------- - Assert.Throws<ArgumentNullException>(() => { new StreamWriter(new MemoryStream(), null); }); + Assert.Throws<ArgumentNullException>(() => new StreamWriter(new MemoryStream(), null)); } [Fact] diff --git a/src/System.IO/tests/StreamWriter/FlushTests.cs b/src/System.IO/tests/StreamWriter/FlushTests.cs index c30c0072b5..2a14828fd1 100644 --- a/src/System.IO/tests/StreamWriter/FlushTests.cs +++ b/src/System.IO/tests/StreamWriter/FlushTests.cs @@ -1,4 +1,6 @@ -using System; +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System.IO; using Xunit; diff --git a/src/System.IO/tests/StreamWriter/WriteTests.cs b/src/System.IO/tests/StreamWriter/WriteTests.cs index be9d1305e4..c031cba78e 100644 --- a/src/System.IO/tests/StreamWriter/WriteTests.cs +++ b/src/System.IO/tests/StreamWriter/WriteTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; using System.Text; @@ -60,7 +63,7 @@ namespace StreamWriterTests MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); - Assert.Throws<ArgumentNullException>(() => { sw.Write(null, 0, 0); }); + Assert.Throws<ArgumentNullException>(() => sw.Write(null, 0, 0)); sw.Dispose(); } [Fact] @@ -72,7 +75,7 @@ namespace StreamWriterTests MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); - Assert.Throws<ArgumentOutOfRangeException>(() => { sw.Write(chArr, -1, 0); }); + Assert.Throws<ArgumentOutOfRangeException>(() => sw.Write(chArr, -1, 0)); sw.Dispose(); } [Fact] @@ -84,7 +87,7 @@ namespace StreamWriterTests MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); - Assert.Throws<ArgumentOutOfRangeException>(() => { sw.Write(chArr, 0, -1); }); + Assert.Throws<ArgumentOutOfRangeException>(() => sw.Write(chArr, 0, -1)); sw.Dispose(); } @@ -139,7 +142,7 @@ namespace StreamWriterTests MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); - Assert.Throws<ArgumentException>(() => { sw.Write(chArr, 1, chArr.Length); }); + Assert.Throws<ArgumentException>(() => sw.Write(chArr, 1, chArr.Length)); sw.Dispose(); } diff --git a/src/System.IO/tests/StringReader/StringReaderCtorTests.cs b/src/System.IO/tests/StringReader/StringReaderCtorTests.cs index 39d3f24bee..e967a6c247 100644 --- a/src/System.IO/tests/StringReader/StringReaderCtorTests.cs +++ b/src/System.IO/tests/StringReader/StringReaderCtorTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; using Xunit; @@ -9,19 +12,7 @@ namespace StringReaderTests [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(); - }); - + Assert.Throws<ArgumentNullException>(() => new StringReader(null)); } [Fact] diff --git a/src/System.IO/tests/StringWriter/StringWriterTests.cs b/src/System.IO/tests/StringWriter/StringWriterTests.cs index d11b609e0f..93f74cf92e 100644 --- a/src/System.IO/tests/StringWriter/StringWriterTests.cs +++ b/src/System.IO/tests/StringWriter/StringWriterTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using Xunit; using System; using System.Globalization; @@ -96,33 +99,28 @@ namespace StreamTests Assert.Equal((int)chArr[i], tmp); } } + [Fact] public static void CantWriteNullArray() { var sw = new StringWriter(); - Assert.Throws<ArgumentNullException>(() => - { - sw.Write(null, 0, 0); - }); + Assert.Throws<ArgumentNullException>(() => sw.Write(null, 0, 0)); } + [Fact] public static void CantWriteNegativeOffset() { var sw = new StringWriter(); - Assert.Throws<ArgumentOutOfRangeException>(() => - { - sw.Write(new char[0], -1, 0); - }); + Assert.Throws<ArgumentOutOfRangeException>(() => sw.Write(new char[0], -1, 0)); } + [Fact] public static void CantWriteNegativeCount() { var sw = new StringWriter(); - Assert.Throws<ArgumentOutOfRangeException>(() => - { - sw.Write(new char[0], 0, -1); - }); + Assert.Throws<ArgumentOutOfRangeException>(() => sw.Write(new char[0], 0, -1)); } + [Fact] public static void CantWriteIndexLargeValues() { @@ -130,12 +128,10 @@ namespace StreamTests for (int i = 0; i < iArrLargeValues.Length; i++) { StringWriter sw = new StringWriter(); - Assert.Throws<ArgumentException>(() => - { - sw.Write(chArr, iArrLargeValues[i], chArr.Length); - }); + Assert.Throws<ArgumentException>(() => sw.Write(chArr, iArrLargeValues[i], chArr.Length)); } } + [Fact] public static void CantWriteCountLargeValues() { @@ -143,10 +139,7 @@ namespace StreamTests for (int i = 0; i < iArrLargeValues.Length; i++) { StringWriter sw = new StringWriter(); - Assert.Throws<ArgumentException>(() => - { - sw.Write(chArr, 0, iArrLargeValues[i]); - }); + Assert.Throws<ArgumentException>(() => sw.Write(chArr, 0, iArrLargeValues[i])); } } @@ -186,7 +179,6 @@ namespace StreamTests } } - [Fact] public static void WriteWithLargeCount() { @@ -291,7 +283,9 @@ namespace StreamTests await sw.WriteLineAsync(new char[] { 'e', 'l', 'l', 'o' }); await sw.WriteLineAsync("World!"); - Assert.Equal("H\r\nello\r\nWorld!\r\n", sw.ToString()); + Assert.Equal( + string.Format("H{0}ello{0}World!{0}", Environment.NewLine), + sw.ToString()); } [Fact] @@ -304,22 +298,31 @@ namespace StreamTests [Fact] public static void TestWriteMisc() { - var sw = new StringWriter(); - - sw.Write(true); - sw.Write((char)'a'); - sw.Write(new Decimal(1234.01)); - sw.Write((double)3452342.01); - sw.Write((int)23456); - sw.Write((long)long.MinValue); - sw.Write((float)1234.50f); - sw.Write((UInt32)UInt32.MaxValue); - sw.Write((UInt64)UInt64.MaxValue); - - Assert.Equal("Truea1234.013452342.0123456-92233720368547758081234.5429496729518446744073709551615", sw.ToString()); + CultureInfo old = CultureInfo.CurrentCulture; + CultureInfo.CurrentCulture = new CultureInfo("en-US"); // floating-point formatting comparison depends on culture + try + { + var sw = new StringWriter(); + + sw.Write(true); + sw.Write((char)'a'); + sw.Write(new Decimal(1234.01)); + sw.Write((double)3452342.01); + sw.Write((int)23456); + sw.Write((long)long.MinValue); + sw.Write((float)1234.50f); + sw.Write((UInt32)UInt32.MaxValue); + sw.Write((UInt64)UInt64.MaxValue); + + Assert.Equal("Truea1234.013452342.0123456-92233720368547758081234.5429496729518446744073709551615", sw.ToString()); + } + finally + { + CultureInfo.CurrentCulture = old; + } } - [Fact] + [Fact] public static void TestWriteObject() { var sw = new StringWriter(); @@ -330,23 +333,27 @@ namespace StreamTests [Fact] public static void TestWriteLineMisc() { - var sw = new StringWriter(); - sw.WriteLine((bool)false); - sw.WriteLine((char)'B'); - sw.WriteLine((int)987); - sw.WriteLine((long)875634); - sw.WriteLine((Single)1.23457f); - sw.WriteLine((UInt32)45634563); - sw.WriteLine((UInt64.MaxValue)); - - Assert.Equal(@"False -B -987 -875634 -1.23457 -45634563 -18446744073709551615 -", sw.ToString()); + CultureInfo old = CultureInfo.CurrentCulture; + CultureInfo.CurrentCulture = new CultureInfo("en-US"); // floating-point formatting comparison depends on culture + try + { + var sw = new StringWriter(); + sw.WriteLine((bool)false); + sw.WriteLine((char)'B'); + sw.WriteLine((int)987); + sw.WriteLine((long)875634); + sw.WriteLine((Single)1.23457f); + sw.WriteLine((UInt32)45634563); + sw.WriteLine((UInt64.MaxValue)); + + Assert.Equal( + string.Format("False{0}B{0}987{0}875634{0}1.23457{0}45634563{0}18446744073709551615{0}", Environment.NewLine), + sw.ToString()); + } + finally + { + CultureInfo.CurrentCulture = old; + } } [Fact] @@ -354,7 +361,7 @@ B { var sw = new StringWriter(); sw.WriteLine(new Object()); - Assert.Equal("System.Object\r\n", sw.ToString()); + Assert.Equal("System.Object" + Environment.NewLine, sw.ToString()); } [Fact] @@ -363,7 +370,7 @@ B StringWriter sw = new StringWriter(); sw.WriteLineAsync(new char[] { 'H', 'e', 'l', 'l', 'o' }); - Assert.Equal("Hello\r\n", sw.ToString()); + Assert.Equal("Hello" + Environment.NewLine, sw.ToString()); } } } diff --git a/src/System.IO/tests/System.IO.Tests.csproj b/src/System.IO/tests/System.IO.Tests.csproj index d05d6b0c11..7339201e66 100644 --- a/src/System.IO/tests/System.IO.Tests.csproj +++ b/src/System.IO/tests/System.IO.Tests.csproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <PropertyGroup> @@ -18,7 +18,6 @@ <Compile Include="BinaryWriter\BinaryWriter_WriteTests.cs" /> <Compile Include="BinaryWriter\BinaryWriterTests.cs" /> <Compile Include="InvalidDataException\InvalidDataExceptionTests.cs" /> - <Compile Include="MemoryStream\Inputs.cs" /> <Compile Include="MemoryStream\MemoryStream_TryGetBufferTests.cs" /> <Compile Include="StreamReader\StreamReaderCtorTests.cs" /> <Compile Include="StreamReader\StreamReaderTests.cs" /> diff --git a/src/System.IO/tests/project.json b/src/System.IO/tests/project.json index 4fe2b9533e..0bb6a952c4 100644 --- a/src/System.IO/tests/project.json +++ b/src/System.IO/tests/project.json @@ -1,17 +1,9 @@ { "dependencies": { -<<<<<<< HEAD - "System.Globalization": "4.0.10", "System.IO": "4.0.10", + "System.Globalization": "4.0.10", + "System.Text.Encoding.CodePages": "4.0.0", "xunit": "2.1.0-beta3-*", -======= - "System.Globalization": "4.0.0-beta-*", - "System.Text.Encoding.CodePages": "4.0.0-beta-*", - "xunit": "2.0.0-beta5-build2785", - "xunit.abstractions.netcore": "1.0.0-prerelease", - "xunit.assert": "2.0.0-beta5-build2785", - "xunit.core.netcore": "1.0.1-prerelease", ->>>>>>> Port additional System.IO tests from ToF "xunit.netcore.extensions": "1.0.0-prerelease-*" }, "frameworks": { diff --git a/src/System.IO/tests/project.lock.json b/src/System.IO/tests/project.lock.json index d29a7a8e0c..2fcc511a5b 100644 --- a/src/System.IO/tests/project.lock.json +++ b/src/System.IO/tests/project.lock.json @@ -3,9 +3,9 @@ "version": -9996, "targets": { "DNXCore,Version=v5.0": { - "System.Collections/4.0.10-beta-23127": { + "System.Collections/4.0.10": { "dependencies": { - "System.Runtime": "4.0.20-beta-23127" + "System.Runtime": "4.0.20" }, "compile": { "ref/dotnet/System.Collections.dll": {} @@ -69,11 +69,11 @@ "lib/DNXCore50/System.Private.Uri.dll": {} } }, - "System.Reflection/4.0.10-beta-23127": { + "System.Reflection/4.0.10": { "dependencies": { - "System.Runtime": "4.0.20-beta-23127", - "System.IO": "4.0.0-beta-23127", - "System.Reflection.Primitives": "4.0.0-beta-23127" + "System.Runtime": "4.0.20", + "System.IO": "4.0.0", + "System.Reflection.Primitives": "4.0.0" }, "compile": { "ref/dotnet/System.Reflection.dll": {} @@ -82,9 +82,9 @@ "lib/DNXCore50/System.Reflection.dll": {} } }, - "System.Reflection.Primitives/4.0.0-beta-23127": { + "System.Reflection.Primitives/4.0.0": { "dependencies": { - "System.Runtime": "4.0.0-beta-23127" + "System.Runtime": "4.0.0" }, "compile": { "ref/dotnet/System.Reflection.Primitives.dll": {} @@ -93,11 +93,11 @@ "lib/DNXCore50/System.Reflection.Primitives.dll": {} } }, - "System.Resources.ResourceManager/4.0.0-beta-23127": { + "System.Resources.ResourceManager/4.0.0": { "dependencies": { - "System.Runtime": "4.0.0-beta-23127", - "System.Reflection": "4.0.0-beta-23127", - "System.Globalization": "4.0.0-beta-23127" + "System.Runtime": "4.0.0", + "System.Reflection": "4.0.0", + "System.Globalization": "4.0.0" }, "compile": { "ref/dotnet/System.Resources.ResourceManager.dll": {} @@ -117,9 +117,9 @@ "lib/DNXCore50/System.Runtime.dll": {} } }, - "System.Runtime.Extensions/4.0.10-beta-23127": { + "System.Runtime.Extensions/4.0.10": { "dependencies": { - "System.Runtime": "4.0.20-beta-23127" + "System.Runtime": "4.0.20" }, "compile": { "ref/dotnet/System.Runtime.Extensions.dll": {} @@ -128,9 +128,9 @@ "lib/DNXCore50/System.Runtime.Extensions.dll": {} } }, - "System.Runtime.Handles/4.0.0-beta-23127": { + "System.Runtime.Handles/4.0.0": { "dependencies": { - "System.Runtime": "4.0.0-beta-23127" + "System.Runtime": "4.0.0" }, "compile": { "ref/dotnet/System.Runtime.Handles.dll": {} @@ -139,12 +139,12 @@ "lib/DNXCore50/System.Runtime.Handles.dll": {} } }, - "System.Runtime.InteropServices/4.0.20-beta-23127": { + "System.Runtime.InteropServices/4.0.20": { "dependencies": { - "System.Runtime": "4.0.0-beta-23127", - "System.Reflection": "4.0.0-beta-23127", - "System.Reflection.Primitives": "4.0.0-beta-23127", - "System.Runtime.Handles": "4.0.0-beta-23127" + "System.Runtime": "4.0.0", + "System.Reflection": "4.0.0", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime.Handles": "4.0.0" }, "compile": { "ref/dotnet/System.Runtime.InteropServices.dll": {} @@ -153,9 +153,9 @@ "lib/DNXCore50/System.Runtime.InteropServices.dll": {} } }, - "System.Text.Encoding/4.0.10-beta-23127": { + "System.Text.Encoding/4.0.10": { "dependencies": { - "System.Runtime": "4.0.0-beta-23127" + "System.Runtime": "4.0.0" }, "compile": { "ref/dotnet/System.Text.Encoding.dll": {} @@ -164,10 +164,31 @@ "lib/DNXCore50/System.Text.Encoding.dll": {} } }, - "System.Threading/4.0.10-beta-23127": { + "System.Text.Encoding.CodePages/4.0.0": { "dependencies": { - "System.Runtime": "4.0.0-beta-23127", - "System.Threading.Tasks": "4.0.0-beta-23127" + "System.Runtime": "4.0.20", + "System.Text.Encoding": "4.0.10", + "System.Runtime.InteropServices": "4.0.20", + "System.Resources.ResourceManager": "4.0.0", + "System.Runtime.Handles": "4.0.0", + "System.IO": "4.0.10", + "System.Collections": "4.0.10", + "System.Threading": "4.0.10", + "System.Reflection": "4.0.10", + "System.Globalization": "4.0.10", + "System.Runtime.Extensions": "4.0.10" + }, + "compile": { + "ref/dotnet/System.Text.Encoding.CodePages.dll": {} + }, + "runtime": { + "lib/dotnet/System.Text.Encoding.CodePages.dll": {} + } + }, + "System.Threading/4.0.10": { + "dependencies": { + "System.Runtime": "4.0.0", + "System.Threading.Tasks": "4.0.0" }, "compile": { "ref/dotnet/System.Threading.dll": {} @@ -237,7 +258,7 @@ "lib/dnxcore50/xunit.execution.dnx.dll": {} } }, - "xunit.netcore.extensions/1.0.0-prerelease-00069": { + "xunit.netcore.extensions/1.0.0-prerelease-00071": { "dependencies": { "System.Diagnostics.Debug": "4.0.10-beta-23127", "System.IO": "4.0.10-beta-23127", @@ -263,12 +284,12 @@ } }, "libraries": { - "System.Collections/4.0.10-beta-23127": { + "System.Collections/4.0.10": { "serviceable": true, - "sha512": "1XSlnhJpGCiRzmHn68jcX6yKPmJEdlUd1iE9KBTOR6posRM9xbFIgVMz8YxNSm76iFi5ukP8PVgs1ks0gWdkZQ==", + "sha512": "ux6ilcZZjV/Gp7JEZpe+2V1eTueq6NuoGRM3eZCFuPM25hLVVgCRuea6STW8hvqreIOE59irJk5/ovpA5xQipw==", "files": [ - "System.Collections.4.0.10-beta-23127.nupkg", - "System.Collections.4.0.10-beta-23127.nupkg.sha512", + "System.Collections.4.0.10.nupkg", + "System.Collections.4.0.10.nupkg.sha512", "System.Collections.nuspec", "lib/DNXCore50/System.Collections.dll", "lib/MonoAndroid10/_._", @@ -440,11 +461,11 @@ "runtimes/win8-aot/lib/netcore50/System.Private.Uri.dll" ] }, - "System.Reflection/4.0.10-beta-23127": { - "sha512": "U7dLeaLgSqelu4hTebGB9L8vhIjvtuS5n4OuQmmyydHHM8/hoATIm6tdY49h9u0EMZEG1j5A4+DFHzjyz5bW4w==", + "System.Reflection/4.0.10": { + "sha512": "WZ+4lEE4gqGx6mrqLhSiW4oi6QLPWwdNjzhhTONmhELOrW8Cw9phlO9tltgvRUuQUqYtBiliFwhO5S5fCJElVw==", "files": [ - "System.Reflection.4.0.10-beta-23127.nupkg", - "System.Reflection.4.0.10-beta-23127.nupkg.sha512", + "System.Reflection.4.0.10.nupkg", + "System.Reflection.4.0.10.nupkg.sha512", "System.Reflection.nuspec", "lib/DNXCore50/System.Reflection.dll", "lib/MonoAndroid10/_._", @@ -472,12 +493,12 @@ "runtimes/win8-aot/lib/netcore50/System.Reflection.dll" ] }, - "System.Reflection.Primitives/4.0.0-beta-23127": { + "System.Reflection.Primitives/4.0.0": { "serviceable": true, - "sha512": "qUjIaT8GBhxh5pyY1xhQd3/Rn5CJMu023GGNWXObr6/I/lX9LWpJD+UJAsPcLMEXOFq3QaKk6+giNjaqIdcf7Q==", + "sha512": "n9S0XpKv2ruc17FSnaiX6nV47VfHTZ1wLjKZlAirUZCvDQCH71mVp+Ohabn0xXLh5pK2PKp45HCxkqu5Fxn/lA==", "files": [ - "System.Reflection.Primitives.4.0.0-beta-23127.nupkg", - "System.Reflection.Primitives.4.0.0-beta-23127.nupkg.sha512", + "System.Reflection.Primitives.4.0.0.nupkg", + "System.Reflection.Primitives.4.0.0.nupkg.sha512", "System.Reflection.Primitives.nuspec", "lib/DNXCore50/System.Reflection.Primitives.dll", "lib/net45/_._", @@ -505,12 +526,12 @@ "runtimes/win8-aot/lib/netcore50/System.Reflection.Primitives.dll" ] }, - "System.Resources.ResourceManager/4.0.0-beta-23127": { + "System.Resources.ResourceManager/4.0.0": { "serviceable": true, - "sha512": "+stu9oGQvmjeFJfhg4zRf/D0jNGa2L7MIkGz3ik70loEFHLE3OrOXFt3T+3eG37Z6md2KCWKe+85ct6VDaEtWA==", + "sha512": "qmqeZ4BJgjfU+G2JbrZt4Dk1LsMxO4t+f/9HarNY6w8pBgweO6jT+cknUH7c3qIrGvyUqraBhU45Eo6UtA0fAw==", "files": [ - "System.Resources.ResourceManager.4.0.0-beta-23127.nupkg", - "System.Resources.ResourceManager.4.0.0-beta-23127.nupkg.sha512", + "System.Resources.ResourceManager.4.0.0.nupkg", + "System.Resources.ResourceManager.4.0.0.nupkg.sha512", "System.Resources.ResourceManager.nuspec", "lib/DNXCore50/System.Resources.ResourceManager.dll", "lib/net45/_._", @@ -571,12 +592,12 @@ "runtimes/win8-aot/lib/netcore50/System.Runtime.dll" ] }, - "System.Runtime.Extensions/4.0.10-beta-23127": { + "System.Runtime.Extensions/4.0.10": { "serviceable": true, - "sha512": "YwtpybYxpRqjF+TnBzmNdgGq2jNtEO9MkxYSIMW36lV7F6qEph+nCcKDLsCslgSz7dn44eSCnnsgBQQsF85eQQ==", + "sha512": "5dsEwf3Iml7d5OZeT20iyOjT+r+okWpN7xI2v+R4cgd3WSj4DeRPTvPFjDpacbVW4skCAZ8B9hxXJYgkCFKJ1A==", "files": [ - "System.Runtime.Extensions.4.0.10-beta-23127.nupkg", - "System.Runtime.Extensions.4.0.10-beta-23127.nupkg.sha512", + "System.Runtime.Extensions.4.0.10.nupkg", + "System.Runtime.Extensions.4.0.10.nupkg.sha512", "System.Runtime.Extensions.nuspec", "lib/DNXCore50/System.Runtime.Extensions.dll", "lib/MonoAndroid10/_._", @@ -604,12 +625,12 @@ "runtimes/win8-aot/lib/netcore50/System.Runtime.Extensions.dll" ] }, - "System.Runtime.Handles/4.0.0-beta-23127": { + "System.Runtime.Handles/4.0.0": { "serviceable": true, - "sha512": "q+CqdcecC00xfyVHTQhtned/RNzZhAtS/04uchISsl5ovKEAnnSRCOPOJJud/dl9iW12U+Lt8YlKub/LoxbZtQ==", + "sha512": "638VhpRq63tVcQ6HDb3um3R/J2BtR1Sa96toHo6PcJGPXEPEsleCuqhBgX2gFCz0y0qkutANwW6VPPY5wQu1XQ==", "files": [ - "System.Runtime.Handles.4.0.0-beta-23127.nupkg", - "System.Runtime.Handles.4.0.0-beta-23127.nupkg.sha512", + "System.Runtime.Handles.4.0.0.nupkg", + "System.Runtime.Handles.4.0.0.nupkg.sha512", "System.Runtime.Handles.nuspec", "lib/DNXCore50/System.Runtime.Handles.dll", "lib/MonoAndroid10/_._", @@ -637,12 +658,12 @@ "runtimes/win8-aot/lib/netcore50/System.Runtime.Handles.dll" ] }, - "System.Runtime.InteropServices/4.0.20-beta-23127": { + "System.Runtime.InteropServices/4.0.20": { "serviceable": true, - "sha512": "oJpQACYOQ/TXcIEZh8MdIqkDlRrnXV9DoPiVnXUgnKYFub7NnKb02sx65eWrNPwutt0ewDD9hNAuPjAGBC1MQA==", + "sha512": "ZgDyBYfEnjWoz/viS6VOswA6XOkDSH2DzgbpczbW50RywhnCgTl+w3JEvtAiOGyIh8cyx1NJq80jsNBSUr8Pig==", "files": [ - "System.Runtime.InteropServices.4.0.20-beta-23127.nupkg", - "System.Runtime.InteropServices.4.0.20-beta-23127.nupkg.sha512", + "System.Runtime.InteropServices.4.0.20.nupkg", + "System.Runtime.InteropServices.4.0.20.nupkg.sha512", "System.Runtime.InteropServices.nuspec", "lib/DNXCore50/System.Runtime.InteropServices.dll", "lib/MonoAndroid10/_._", @@ -670,11 +691,11 @@ "runtimes/win8-aot/lib/netcore50/System.Runtime.InteropServices.dll" ] }, - "System.Text.Encoding/4.0.10-beta-23127": { - "sha512": "XUOP6mx45Fk4fUcinHnUdeXGzQaXGskTBvI4/v195wCyUhsHQXFvnVVDevMoFlrcjb7Lvm6UdIORmqA1y4onmg==", + "System.Text.Encoding/4.0.10": { + "sha512": "fNlSFgy4OuDlJrP9SFFxMlaLazq6ipv15sU5TiEgg9UCVnA/OgoVUfymFp4AOk1jOkW5SVxWbeeIUptcM+m/Vw==", "files": [ - "System.Text.Encoding.4.0.10-beta-23127.nupkg", - "System.Text.Encoding.4.0.10-beta-23127.nupkg.sha512", + "System.Text.Encoding.4.0.10.nupkg", + "System.Text.Encoding.4.0.10.nupkg.sha512", "System.Text.Encoding.nuspec", "lib/DNXCore50/System.Text.Encoding.dll", "lib/MonoAndroid10/_._", @@ -702,12 +723,41 @@ "runtimes/win8-aot/lib/netcore50/System.Text.Encoding.dll" ] }, - "System.Threading/4.0.10-beta-23127": { + "System.Text.Encoding.CodePages/4.0.0": { "serviceable": true, - "sha512": "hIUes/USmGxoe2haJennL0AREdIq8RA50IL0lBSdqant19L8fRydW5Nz5qfWpSKUBtibQzrcJ1c5nFVNUs4Cyw==", + "sha512": "ZHBTr1AXLjY9OuYR7pKx5xfN6QFye1kgd5QAbGrvfCOu7yxRnJs3VUaxERe1fOlnF0mi/xD/Dvb3T3x3HNuPWQ==", "files": [ - "System.Threading.4.0.10-beta-23127.nupkg", - "System.Threading.4.0.10-beta-23127.nupkg.sha512", + "System.Text.Encoding.CodePages.4.0.0.nupkg", + "System.Text.Encoding.CodePages.4.0.0.nupkg.sha512", + "System.Text.Encoding.CodePages.nuspec", + "lib/dotnet/System.Text.Encoding.CodePages.dll", + "lib/MonoAndroid10/_._", + "lib/MonoTouch10/_._", + "lib/xamarinios10/_._", + "lib/xamarinmac20/_._", + "ref/dotnet/System.Text.Encoding.CodePages.dll", + "ref/dotnet/System.Text.Encoding.CodePages.xml", + "ref/dotnet/de/System.Text.Encoding.CodePages.xml", + "ref/dotnet/es/System.Text.Encoding.CodePages.xml", + "ref/dotnet/fr/System.Text.Encoding.CodePages.xml", + "ref/dotnet/it/System.Text.Encoding.CodePages.xml", + "ref/dotnet/ja/System.Text.Encoding.CodePages.xml", + "ref/dotnet/ko/System.Text.Encoding.CodePages.xml", + "ref/dotnet/ru/System.Text.Encoding.CodePages.xml", + "ref/dotnet/zh-hans/System.Text.Encoding.CodePages.xml", + "ref/dotnet/zh-hant/System.Text.Encoding.CodePages.xml", + "ref/MonoAndroid10/_._", + "ref/MonoTouch10/_._", + "ref/xamarinios10/_._", + "ref/xamarinmac20/_._" + ] + }, + "System.Threading/4.0.10": { + "serviceable": true, + "sha512": "0w6pRxIEE7wuiOJeKabkDgeIKmqf4ER1VNrs6qFwHnooEE78yHwi/bKkg5Jo8/pzGLm0xQJw0nEmPXt1QBAIUA==", + "files": [ + "System.Threading.4.0.10.nupkg", + "System.Threading.4.0.10.nupkg.sha512", "System.Threading.nuspec", "lib/DNXCore50/System.Threading.dll", "lib/MonoAndroid10/_._", @@ -869,12 +919,12 @@ "lib/Xamarin.iOS/xunit.execution.iOS-Universal.xml" ] }, - "xunit.netcore.extensions/1.0.0-prerelease-00069": { + "xunit.netcore.extensions/1.0.0-prerelease-00071": { "serviceable": true, - "sha512": "d0z25PO5BYq6m7VolkHOqWvFoaC8RCtdSPoNZVqPpms+/KZ3EG3+3CXBoEvD6XecD+ablnwNmWe+YwCzhHe4Rw==", + "sha512": "Y1Ap0STKRDYZq0tMo897jmy2OLB1RNsAb7wo0V/+G7EvYnrvA13A6i+fDy2v54nK68NFp0xXDbgYZB5qT/XQ5A==", "files": [ - "xunit.netcore.extensions.1.0.0-prerelease-00069.nupkg", - "xunit.netcore.extensions.1.0.0-prerelease-00069.nupkg.sha512", + "xunit.netcore.extensions.1.0.0-prerelease-00071.nupkg", + "xunit.netcore.extensions.1.0.0-prerelease-00071.nupkg.sha512", "xunit.netcore.extensions.nuspec", "lib/dotnet/Xunit.NetCore.Extensions.dll" ] @@ -882,8 +932,9 @@ }, "projectFileDependencyGroups": { "": [ - "System.Globalization >= 4.0.10", "System.IO >= 4.0.10", + "System.Globalization >= 4.0.10", + "System.Text.Encoding.CodePages >= 4.0.0", "xunit >= 2.1.0-beta3-*", "xunit.netcore.extensions >= 1.0.0-prerelease-*" ], |