public void Allocate_6000Bytes()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var file = new CompoundFile(path))
     {
         var ix = file.Allocate(6000);
         Assert.AreEqual((uint) 1, ix);
     }
     if (File.Exists(path)) File.Delete(path);
 }
 public void Allocate_FullChapter_Test()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var file = new CompoundFile(path))
     {
         for (int i=0;i<4096;i++)
         {
             var ix = file.Allocate();
         }
     }
     if (File.Exists(path)) File.Delete(path);
 }
 public void Allocate_Write_TwoPages()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var file = new CompoundFile(path))
     {
         var ix = file.Allocate();
         var data = new byte[6000];
         for (int i = 0; i < 6000; i++)
             data[i] = (byte) (i%255);
         file.Write(ix, data, 0, 6000);
     }
     if (File.Exists(path)) File.Delete(path);
 }
 public void Allocate_Write_SinglePage()
 {
     var path = Path.GetTempFileName();
     if (File.Exists(path)) File.Delete(path);
     using (var file = new CompoundFile(path))
     {
         var ix = file.Allocate();
         var data = new byte[255];
         for (byte i = 0; i < 255; i++)
             data[i] = i;
         file.Write(ix, data, 0, 255);
     }
     if (File.Exists(path)) File.Delete(path);
 }
        public void ReadAt_MultiplePages_NonZeroOffset()
        {
            const string path = "xxx";
            var msf = new UndisposableMemoryStreamFactory();
            using (var file = new CompoundFile(path, new CompoundFile.CompoundFileOptions(), msf))
            {
                var handle = file.Allocate();
                var data = new byte[8000];
                for (int i = 0; i < 8000; i++) data[i] = (byte)(i % 255);
                file.Write(handle, data, 0, 8000);

                var readData = new byte[4000];
                var readBytes = file.ReadAt(handle, readData, 2000, 4000);
                for (int i = 0; i < 4000; i++) Assert.AreEqual(data[i + 2000], readData[i]);
                Assert.AreEqual((uint)4000, readBytes);
            }
            var stream = msf.Stream;
            stream.AllowDispose = true;
            stream.Dispose();            
        }
        public void ReadAt_BufferSmallerThanCount_ExpectsException()
        {
            const string path = "xxx";
            var msf = new UndisposableMemoryStreamFactory();
            using (var file = new CompoundFile(path, new CompoundFile.CompoundFileOptions(), msf))
            {
                var handle = file.Allocate();
                var data = new byte[255];
                for (byte i = 0; i < 255; i++) data[i] = i;
                file.Write(handle, data, 0, 255);

                var readData = new byte[255];
                var readBytes = file.ReadAt(handle, readData, 0, 512);
                for (byte i = 0; i < 255; i++) Assert.AreEqual(i, readData[i]);
                Assert.AreEqual((uint)255, readBytes);
            }
            var stream = msf.Stream;
            stream.AllowDispose = true;
            stream.Dispose();                                    
        }
        public void InitializeFile_ReadAt_ExpectsOk()
        {
            const string path = "xxx";
            var msf = new UndisposableMemoryStreamFactory();
            using (var file = new CompoundFile(path, new CompoundFile.CompoundFileOptions(), msf))
            {
                var handle = file.Allocate();
                var data = new byte[255];
                for (byte i = 0; i < 255; i++) data[i] = i;
                file.Write(handle, data, 0, 255);

                var readData = new byte[10];
                file.ReadAt(handle, readData, 10, 10);
                for(byte i=0;i<10;i++) Assert.AreEqual(i + 10, readData[i]);
            }
            var stream = msf.Stream;
            stream.AllowDispose = true;
            stream.Dispose();
        }