public Read ( long offset, byte buffer, int offsetInBuffer, int count ) : long | ||
offset | long | |
buffer | byte | |
offsetInBuffer | int | |
count | int | |
return | long |
// The Read/Write/ReadByte/WriteByte simply delegates to SqlBytes public override int Read(byte[] buffer, int offset, int count) { CheckIfStreamClosed("Read"); if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0 || offset > buffer.Length) { throw new ArgumentOutOfRangeException("offset"); } if (count < 0 || count > buffer.Length - offset) { throw new ArgumentOutOfRangeException("count"); } int iBytesRead = (int)m_sb.Read(m_lPosition, buffer, offset, count); m_lPosition += iBytesRead; return(iBytesRead); }
public void Read_InvalidCountTest2 () { ExceptionAssert.Throws<ArgumentOutOfRangeException>( delegate { byte [] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes (b1); byte [] b2 = new byte [5]; bytes.Read (0, b2, 3, 4); Assert.Fail ("#12 Should throw ArgumentOutOfRangeException"); }); }
public void Read_NullBufferAndInstanceValueTest () { ExceptionAssert.Throws<ArgumentNullException>( delegate { byte [] b2 = null; SqlBytes bytes = new SqlBytes (); bytes.Read (0, b2, 8, 4); Assert.Fail ("#10 Should throw ArgumentNullException"); }); }
public void Read_SuccessTest2 () { byte [] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes (b1); byte [] b2 = new byte [10]; bytes.Read (5, b2, 0, 10); Assert.AreEqual (bytes.Value [5], b2 [0], "#8 Should be same"); Assert.AreEqual (bytes.Value [9], b2 [4], "#9 Should be same"); }
public void Read_NullInstanceValueTest () { ExceptionAssert.Throws<SqlNullValueException>( delegate { byte [] b2 = new byte [5]; SqlBytes bytes = new SqlBytes (); bytes.Read (0, b2, 8, 4); Assert.Fail ("#7 Should throw SqlNullValueException"); }); }
public void Read_NegativeOffsetInBufferTest () { ExceptionAssert.Throws<ArgumentOutOfRangeException>( delegate { byte [] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes (b1); byte [] b2 = new byte [5]; bytes.Read (0, b2, -1, 4); Assert.Fail ("#5 Should throw ArgumentOutOfRangeException"); }); }
public void Read_NullBufferTest () { ExceptionAssert.Throws<ArgumentNullException>( delegate { byte [] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes (b1); byte [] b2 = null; bytes.Read (0, b2, 0, 10); Assert.Fail ("#2 Should throw ArgumentNullException"); }); }
public void Read_NullBufferTest() { byte[] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes(b1); byte[] b2 = null; Assert.Throws<ArgumentNullException>(() => bytes.Read(0, b2, 0, 10)); }
public void Read_NegativeCountTest () { byte [] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes (b1); byte [] b2 = new byte [5]; bytes.Read (0, b2, 0, -1); Assert.Fail ("#11 Should throw ArgumentOutOfRangeException"); }
public void Read_InvalidOffsetInBufferTest () { byte [] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes (b1); byte [] b2 = new byte [5]; bytes.Read (0, b2, 8, 4); Assert.Fail ("#6 Should throw ArgumentOutOfRangeException"); }
private static void SetSqlBytes_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlBytes value, int offset, long length) { if (value.IsNull) { setters.SetDBNull(sink, ordinal); sink.ProcessMessagesAndThrow(); } else { int num4; long num5; if ((length > 0x1f40L) || (length < 0L)) { num4 = 0x1f40; } else { num4 = (int) length; } byte[] buffer = new byte[num4]; long num2 = 1L; long num = offset; for (long i = 0L; ((length < 0L) || (i < length)) && ((0L != (num5 = value.Read(num, buffer, 0, num4))) && (0L != num2)); i += num2) { num2 = setters.SetBytes(sink, ordinal, num, buffer, 0, (int) num5); sink.ProcessMessagesAndThrow(); num += num2; } setters.SetBytesLength(sink, ordinal, num); sink.ProcessMessagesAndThrow(); } }
public void Read_InvalidCountTest2() { byte[] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes(b1); byte[] b2 = new byte[5]; Assert.Throws<ArgumentOutOfRangeException>(() => bytes.Read(0, b2, 3, 4)); }
public void Read_NullBufferAndInstanceValueTest() { byte[] b2 = null; SqlBytes bytes = new SqlBytes(); Assert.Throws<SqlNullValueException>(() => bytes.Read(0, b2, 8, 4)); }
public void Read_NegativeOffsetInBufferTest() { byte[] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes(b1); byte[] b2 = new byte[5]; Assert.Throws<ArgumentOutOfRangeException>(() => bytes.Read(0, b2, -1, 4)); }
public void Read_SuccessTest1 () { byte [] b1 = { 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 }; SqlBytes bytes = new SqlBytes (b1); byte [] b2 = new byte [10]; bytes.Read (0, b2, 0, (int) bytes.Length); Assert.AreEqual (bytes.Value [5], b2 [5], "#1 Should be equal"); }
// note: length < 0 indicates write everything private static void SetSqlBytes_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlBytes value, int offset, long length ) { if ( value.IsNull ) { setters.SetDBNull( sink, ordinal ); sink.ProcessMessagesAndThrow(); } else { int chunkSize; if ( length > __maxByteChunkSize || length < 0 ) { chunkSize = __maxByteChunkSize; } else { chunkSize = checked( (int)length ); } byte[] buffer = new byte[ chunkSize ]; long bytesRead; long bytesWritten = 1; // prime value to get into write loop long currentOffset = offset; long lengthWritten = 0; while ( (length < 0 || lengthWritten < length) && 0 != ( bytesRead = value.Read( currentOffset, buffer, 0, chunkSize ) ) && 0 != bytesWritten ) { bytesWritten = setters.SetBytes( sink, ordinal, currentOffset, buffer, 0, checked( (int) bytesRead ) ); sink.ProcessMessagesAndThrow(); checked{ currentOffset += bytesWritten; } checked{ lengthWritten += bytesWritten; } } // Make sure to trim any left-over data setters.SetBytesLength( sink, ordinal, currentOffset ); sink.ProcessMessagesAndThrow(); } }
public void Read_NullBufferAndInstanceValueTest () { byte [] b2 = null; SqlBytes bytes = new SqlBytes (); bytes.Read (0, b2, 8, 4); }