예제 #1
0
        public void WriteAndReadIntsViaDiskFile()
        {
            var file = new DiskFile("test11.dat", "rwb");

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

            var data0 = new int[4];

            for (var i = 0; i < data0.Length; ++i)
            {
                data0[i] = i + 32000000;
            }
            file.WriteInts(data0);
            file.Flush();
            Assert.Equal(data0.Length * sizeof(int), file.Position);
            file.Seek(0);

            var data1 = new int[data0.Length];
            var rd    = file.ReadInts(data1, data0.Length);

            Assert.Equal(rd, data0.Length);
            Assert.Equal(data0.Length * sizeof(int), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.Equal(data0[i], data1[i]);
            }
            file.Close();
            Assert.False(file.IsOpen);
        }