Esempio n. 1
0
        private void TestRandomSetLengthOperation(FileStream targetStream, AlignedWriteStream writeStream, long length)
        {
            long position = targetStream.Position;

            targetStream.SetLength(length);
            writeStream.SetLength(length);

            Assert.AreEqual(targetStream.Position, writeStream.Position, string.Format("Position mismatch (Original: {0})", position));
            Assert.AreEqual(targetStream.Length, writeStream.Length, "Length mismatch");
        }
Esempio n. 2
0
        private void TestAlignedWriteStreamLength(string targetFilename)
        {
            var buffer = new byte[1024];
            using (FileStream targetFileStream = new FileStream(targetFilename, FileMode.Create, FileAccess.ReadWrite, FileShare.Write, 8,
                FileOptions.WriteThrough | Win32.FileFlagNoBuffering))
            {
                using (AlignedWriteStream writeStream = new AlignedWriteStream(targetFileStream))
                {
                    writeStream.Write(buffer, 0, 1000);
                    Assert.AreEqual(1000, writeStream.Position, "Invlid position");
                    Assert.AreEqual(512, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(1000, writeStream.Length, "Invlid length");
                    Assert.AreEqual(512, targetFileStream.Length, "Invlid length");
                    writeStream.SetLength(1024);
                    Assert.AreEqual(1000, writeStream.Position, "Invlid position");
                    Assert.AreEqual(512, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(1024, writeStream.Length, "Invlid length");
                    Assert.AreEqual(1024, targetFileStream.Length, "Invlid length");
                    writeStream.SetLength(512);
                    Assert.AreEqual(512, writeStream.Position, "Invlid position");
                    Assert.AreEqual(512, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(512, writeStream.Length, "Invlid length");
                    Assert.AreEqual(512, targetFileStream.Length, "Invlid length");
                    writeStream.Write(buffer, 0, 1000);
                    Assert.AreEqual(1512, writeStream.Position, "Invlid position");
                    Assert.AreEqual(1024, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(1512, writeStream.Length, "Invlid length");
                    Assert.AreEqual(1024, targetFileStream.Length, "Invlid length");
                    writeStream.SetLength(2048);
                    Assert.AreEqual(1512, writeStream.Position, "Invlid position");
                    Assert.AreEqual(1024, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(2048, writeStream.Length, "Invlid length");
                    Assert.AreEqual(2048, targetFileStream.Length, "Invlid length");
                    writeStream.Write(buffer, 345, 38);
                    Assert.AreEqual(1550, writeStream.Position, "Invlid position");
                    Assert.AreEqual(1536, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(2048, writeStream.Length, "Invlid length");
                    Assert.AreEqual(2048, targetFileStream.Length, "Invlid length");
                    writeStream.SetLength(0);
                    Assert.AreEqual(0, writeStream.Position, "Invlid position");
                    Assert.AreEqual(0, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(0, writeStream.Length, "Invlid length");
                    Assert.AreEqual(0, targetFileStream.Length, "Invlid length");
                    writeStream.Flush();
                    Assert.AreEqual(0, writeStream.Position, "Invlid position");
                    Assert.AreEqual(0, targetFileStream.Position, "Invlid position");
                    Assert.AreEqual(0, writeStream.Length, "Invlid length");
                    Assert.AreEqual(0, targetFileStream.Length, "Invlid length");

                }
                Assert.AreEqual(0, targetFileStream.Position, "Invlid position");
                Assert.AreEqual(0, targetFileStream.Length, "Invlid position");
            }
        }