Exemple #1
0
        public void WriteAndReadStorageCharsViaDiskFile()
        {
            const int size = 10;

            var file = new DiskFile("test15c.dat", "rwb");

            Assert.NotNull(file);
            Assert.True(file.CanWrite);

            var storage0 = new MemoryFile.CharStorage(size);

            for (var i = 0; i < size; ++i)
            {
                storage0[i] = (byte)i;
            }

            file.WriteChars(storage0);
            Assert.Equal(size * sizeof(byte), file.Position);
            file.Seek(0);

            var storage1 = new MemoryFile.CharStorage(size);
            var rd       = file.ReadChars(storage1);

            Assert.Equal(rd, size);
            Assert.Equal(size * sizeof(byte), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.Equal(storage0[i], storage1[i]);
            }

            file.Close();
            Assert.False(file.IsOpen);
        }