예제 #1
0
        public override void ToHalf(int index, Half expected, byte[] byteArray)
        {
            byteArray = RangeToLittleEndian(byteArray, index, 2);
            ReadOnlySpan <byte> span = new ReadOnlySpan <byte>(byteArray);

            Assert.Equal(expected, BitConverter.ToHalf(span.Slice(index)));
        }
예제 #2
0
 public static void StartIndexPlusNeededLengthTooLong()
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToBoolean(new byte[0], 0));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToChar(new byte[2], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToDouble(new byte[8], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToHalf(new byte[2], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToInt16(new byte[2], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToInt32(new byte[4], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToInt64(new byte[8], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToSingle(new byte[4], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToUInt16(new byte[2], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToUInt32(new byte[4], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToUInt64(new byte[8], 1));
     AssertExtensions.Throws <ArgumentException>("value", null, () => BitConverter.ToString(new byte[2], 1, 2));
 }
예제 #3
0
 public static void ValueArgumentNull()
 {
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToBoolean(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToChar(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToDouble(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToHalf(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToInt16(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToInt32(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToInt64(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToSingle(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToUInt16(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToUInt32(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToUInt64(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToString(null));
     AssertExtensions.Throws <ArgumentNullException>("value", () => BitConverter.ToString(null, 0));
     AssertExtensions.Throws <ArgumentNullException>("value", null /* param name varies in .NET Framework */, () => BitConverter.ToString(null, 0, 0));
 }
예제 #4
0
 public override void ToHalf(int index, Half expected, byte[] byteArray)
 {
     Assert.Equal(expected, BitConverter.ToHalf(byteArray, index));
 }
예제 #5
0
        public override void ToHalf(int index, Half expected, byte[] byteArray)
        {
            ReadOnlySpan <byte> span = new ReadOnlySpan <byte>(byteArray);

            Assert.Equal(expected, BitConverter.ToHalf(span.Slice(index)));
        }
예제 #6
0
        public static void StartIndexBeyondLength()
        {
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToBoolean(new byte[1], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToBoolean(new byte[1], 1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToBoolean(new byte[1], 2));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToChar(new byte[2], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToChar(new byte[2], 2));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToChar(new byte[2], 3));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToDouble(new byte[8], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToDouble(new byte[8], 8));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToDouble(new byte[8], 9));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToHalf(new byte[2], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToHalf(new byte[2], 2));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToHalf(new byte[2], 3));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt16(new byte[2], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt16(new byte[2], 2));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt16(new byte[2], 3));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt32(new byte[4], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt32(new byte[4], 4));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt32(new byte[4], 5));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt64(new byte[8], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt64(new byte[8], 8));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToInt64(new byte[8], 9));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToSingle(new byte[4], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToSingle(new byte[4], 4));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToSingle(new byte[4], 5));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt16(new byte[2], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt16(new byte[2], 2));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt16(new byte[2], 3));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt32(new byte[4], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt32(new byte[4], 4));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt32(new byte[4], 5));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt64(new byte[8], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt64(new byte[8], 8));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToUInt64(new byte[8], 9));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToString(new byte[1], -1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToString(new byte[1], 1));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToString(new byte[1], 2));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToString(new byte[1], -1, 0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToString(new byte[1], 1, 0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("startIndex", () => BitConverter.ToString(new byte[1], 2, 0));

            AssertExtensions.Throws <ArgumentOutOfRangeException>("length", () => BitConverter.ToString(new byte[1], 0, -1));
        }
예제 #7
0
 public override void ToHalf(int index, Half expected, byte[] byteArray)
 {
     byteArray = RangeToLittleEndian(byteArray, index, 2);
     Assert.Equal(expected, BitConverter.ToHalf(byteArray, index));
 }