Ejemplo n.º 1
0
        public void Large_Write_Writes_Correct_Size()
        {
            //Arrange
            var    functions     = new Mock <Functions>();
            var    writeCalls    = new List <(IntPtr bPointer, ulong offset, uint length)>();
            var    namespaceVirt = (IntPtr)7;
            var    dataStreamId  = Guid.NewGuid();
            var    allocSize     = (2 << 12);
            IntPtr buffer        = Marshal.AllocHGlobal(allocSize);
            var    aligned       = AlignedBufferHandle.FromIntPtr(functions.Object, buffer);
            IntPtr bufferEnd     = buffer + allocSize - 1;

            functions.Setup(f => f.PrjAllocateAlignedBuffer(namespaceVirt, (UIntPtr)allocSize)).Returns(aligned);
            functions.Setup(f => f.PrjFreeAlignedBuffer(buffer));
            functions.Setup(f => f.PrjWriteFileData(namespaceVirt, dataStreamId, It.IsAny <IntPtr>(), It.IsAny <ulong>(), It.IsAny <uint>()))
            .Returns(HRESULT.S_OK)
            .Callback((IntPtr ctx, Guid stream, IntPtr newBuffer, ulong offset, uint length) => writeCalls.Add((newBuffer, offset, length)));
            int totalWriteSize = 16000;
            //Act
            var stream = new FileWriteStream(0, allocSize, namespaceVirt, dataStreamId, functions.Object);

            stream.Write(Enumerable.Repeat <byte>(5, totalWriteSize).ToArray());
            stream.Dispose();

            //Assert
            AssertWriteSizes(writeCalls, buffer, bufferEnd, totalWriteSize);
        }
Ejemplo n.º 2
0
        public void No_Bold_Claims()
        {
            //Arrange
            var    functions     = new Mock <Functions>();
            var    writeCalls    = new List <(long, int)>();
            var    namespaceVirt = (IntPtr)7;
            var    dataStreamId  = Guid.NewGuid();
            var    allocSize     = (2 << 12);
            IntPtr buffer        = Marshal.AllocHGlobal(allocSize);
            var    aligned       = AlignedBufferHandle.FromIntPtr(functions.Object, buffer);

            functions.Setup(f => f.PrjAllocateAlignedBuffer(namespaceVirt, (UIntPtr)allocSize)).Returns(aligned);

            //Act
            var stream = new FileWriteStream(0, allocSize, namespaceVirt, dataStreamId, functions.Object);

            //Assert
            var tempBuffer = new byte[200];

            Assert.False(stream.CanRead);
            Assert.False(stream.CanSeek);
            Assert.True(stream.CanWrite);
            Assert.Throws <NotSupportedException>(() => stream.Read(tempBuffer, 0, tempBuffer.Length));
            Assert.Throws <NotSupportedException>(() => stream.Seek(0, System.IO.SeekOrigin.Begin));
            Assert.Throws <NotSupportedException>(() => stream.SetLength(0));
            Assert.Throws <NotSupportedException>(() => stream.Position = 10);
            Assert.Throws <NotSupportedException>(() => { var item = stream.Position; });
            Assert.Throws <NotSupportedException>(() => { var length = stream.Length; });
        }
Ejemplo n.º 3
0
        public void Unused_Stream_Writes_No_Data()
        {
            //Arrange
            var    functions     = new Mock <Functions>();
            var    writeCalls    = new List <(long, int)>();
            var    namespaceVirt = (IntPtr)7;
            var    dataStreamId  = Guid.NewGuid();
            var    allocSize     = (2 << 12);
            IntPtr buffer        = Marshal.AllocHGlobal(allocSize);
            var    aligned       = AlignedBufferHandle.FromIntPtr(functions.Object, buffer);

            functions.Setup(f => f.PrjAllocateAlignedBuffer(namespaceVirt, (UIntPtr)allocSize)).Returns(aligned);
            functions.Setup(f => f.PrjFreeAlignedBuffer(buffer));

            //Act
            var stream = new FileWriteStream(0, allocSize, namespaceVirt, dataStreamId, functions.Object);

            stream.Dispose();

            //Assert
            functions.VerifyAll();
            functions.VerifyNoOtherCalls();
        }