Beispiel #1
0
 public void SeekTest()
 {
     using SafeHGlobalHandle m = new SafeHGlobalHandle(1000);
     using MarshalingStream ms = new MarshalingStream(m, m.Size);
     Assert.That(ms.Seek(20, SeekOrigin.Begin), Is.EqualTo(20));
     Assert.That(ms.Seek(20, SeekOrigin.Current), Is.EqualTo(40));
     Assert.That(ms.Seek(-100, SeekOrigin.End), Is.EqualTo(900));
     Assert.That(() => ms.Seek(-1, SeekOrigin.Begin), Throws.ArgumentException);
     Assert.That(() => ms.Seek(1, SeekOrigin.End), Throws.ArgumentException);
 }
Beispiel #2
0
 public void PokeTest()
 {
     using SafeHGlobalHandle m = new SafeHGlobalHandle(10);
     using MarshalingStream ms = new MarshalingStream(m, m.Size);
     Assert.That(() => ms.Write(0x000001FF), Throws.Nothing);
     Assert.That(ms.Position, Is.EqualTo(sizeof(int)));
     ms.Seek(0, SeekOrigin.Begin);
     byte[] ba = new byte[] { 0x2 };
     Assert.That(() => ms.Poke(null, 0), Throws.ArgumentNullException);
     Assert.That(() => ms.Poke(ba, 1000), Throws.ArgumentException);
     Assert.That(() => ms.Poke(ba, -1), Throws.TypeOf <ArgumentOutOfRangeException>());
     ms.Poke(ba, 1);
     Assert.That(ms.Read <int>(), Is.EqualTo(0x00000102));
     Assert.That(() => ms.Read <ulong>(), Throws.TypeOf <ArgumentOutOfRangeException>());
 }
 public void PokeTest()
 {
     using (var m = new SafeHGlobalHandle(10))
         using (var ms = new MarshalingStream((IntPtr)m, m.Size))
         {
             Assert.That(() => ms.Write(0x000001FF), Throws.Nothing);
             Assert.That(ms.Position, Is.EqualTo(sizeof(int)));
             ms.Seek(0, SeekOrigin.Begin);
             var ba = new byte[] { 0x2 };
             Assert.That(() => ms.Poke(null, 0), Throws.ArgumentNullException);
             Assert.That(() => ms.Poke(ba, 1000), Throws.ArgumentException);
             Assert.That(() => ms.Poke(ba, -1), Throws.TypeOf <ArgumentOutOfRangeException>());
             ms.Poke(ba, 1);
             Assert.That(ms.Read <int>(), Is.EqualTo(0x00000102));
             Assert.That(() => ms.Read <Vanara.PInvoke.User32_Gdi.ICONINFO>(), Throws.TypeOf <ArgumentOutOfRangeException>());
         }
 }
Beispiel #4
0
 public void PokeTest1()
 {
     using SafeHGlobalHandle m = new SafeHGlobalHandle(100);
     using MarshalingStream ms = new MarshalingStream(m, m.Size);
     Assert.That(ms.Position, Is.Zero);
     Assert.That(() => ms.Write(new[] { 1L, 2L }), Throws.Nothing);
     byte[] bytes = new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 };
     ms.Write(bytes, 0, bytes.Length);
     Assert.That(ms.Position, Is.EqualTo(sizeof(long) * 2 + 8));
     ms.Seek(0, SeekOrigin.Begin);
     Assert.That(() => ms.Poke(IntPtr.Zero, 1002), Throws.ArgumentException);
     Assert.That(() => ms.Poke(IntPtr.Zero, -1), Throws.TypeOf <ArgumentOutOfRangeException>());
     ms.Poke(IntPtr.Zero, sizeof(long));
     byte[] buf = new byte[24];
     ms.Read(buf, 0, buf.Length);
     Assert.That(buf, Is.EquivalentTo(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 }));
     Assert.That(() => ms.Read(null, 0, 0), Throws.ArgumentNullException);
     Assert.That(() => ms.Read(buf, 0, 30), Throws.ArgumentException);
     Assert.That(() => ms.Read(buf, -1, 0), Throws.TypeOf <ArgumentOutOfRangeException>());
     ms.Position = m.Size - 10;
     Assert.That(() => ms.Read(buf, 0, buf.Length), Throws.Nothing);
 }