public void AddFileTest2()
        {
            byte[] data = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 };

            TestIPlatformService platform = new TestIPlatformService {
                ReadFileFunc = x => new MemoryStream(data)
            };
            TestIEncodingOutputStream stream  = new TestIEncodingOutputStream();
            HuffmanEncoder            encoder = new HuffmanEncoder();

            builder.Initialize(platform, CreateEncodingToken(encoder, data), stream);

            builder.AddFile(new FileSegment(@"data.bin", @"C:\data.bin"), CancellationToken.None, null);
            IReadOnlyList <Bit> bitList = BitListHelper.CreateBuilder()
                                          .AddByte(0x00)
                                          .AddInt(0x10)
                                          .AddChar('d')
                                          .AddChar('a')
                                          .AddChar('t')
                                          .AddChar('a')
                                          .AddChar('.')
                                          .AddChar('b')
                                          .AddChar('i')
                                          .AddChar('n')
                                          .AddLong(0x19)//bits
                                          .AddByte(0x20)
                                          .AddByte(0x55)
                                          .AddByte(0xFF)
                                          .AddByte(0x01).BitList;

            Assert.AreEqual(bitList, stream.BitList);
        }
        public void AddFileTest1()
        {
            TestIPlatformService platform = new TestIPlatformService {
                ReadFileFunc = x => new MemoryStream()
            };
            TestIEncodingOutputStream stream = new TestIEncodingOutputStream();

            builder.Initialize(platform, EmptyEncodingToken.Instance, stream);

            builder.AddFile(new FileSegment(@"file.bin", @"C:\file.bin"), CancellationToken.None, null);
            IReadOnlyList <Bit> bitList = BitListHelper.CreateBuilder()
                                          .AddByte(0x00)
                                          .AddInt(0x10)
                                          .AddChar('f')
                                          .AddChar('i')
                                          .AddChar('l')
                                          .AddChar('e')
                                          .AddChar('.')
                                          .AddChar('b')
                                          .AddChar('i')
                                          .AddChar('n')
                                          .AddLong(0x0).BitList;

            Assert.AreEqual(bitList, stream.BitList);
        }
Пример #3
0
        private FileDecodingOutputStream CreateFileDecodingOutputStream(Stream stream)
        {
            TestIPlatformService platform = new TestIPlatformService {
                WriteFileFunc = x => stream
            };

            return(new FileDecodingOutputStream("file", platform));
        }
Пример #4
0
        private FileDecodingInputStream CreateFileDecodingInputStream(byte[] data)
        {
            TestIPlatformService platform = new TestIPlatformService {
                ReadFileFunc = x => new MemoryStream(data)
            };

            return(new FileDecodingInputStream("file", platform));
        }
 public void SetUp()
 {
     this.platform = new TestIPlatformService {
         WriteFileFunc = _ => new MemoryStream()
     };
     this.fileDecoder  = new TestIFileDecoder();
     this.streamParser = new TestIStreamParser(fileDecoder);
     this.service      = new DefaultHuffmanDecodingService(platform, streamParser);
 }
        public void SetUp()
        {
            this.fileSystem = new TestIFileSystemService();

            this.platform = new TestIPlatformService {
                ReadFileFunc  = x => new MemoryStream(),
                WriteFileFunc = x => new MemoryStream()
            };
            this.streamBuilder = new TestIStreamBuilder();
            this.service       = new DefaultHuffmanEncodingService(fileSystem, platform, streamBuilder);
        }
Пример #7
0
        public async Task EncodingStatisticsTest()
        {
            TestIFileSelectorService fileSelector = new TestIFileSelectorService();

            fileSelector.FilePath         = @"path";
            viewModel.FileSelectorService = fileSelector;
            viewModel.Path = @"C:\dir\";

            TestIInputDataService inputDataService = new TestIInputDataService();

            inputDataService.InputCommand = InputCommand.Encode;
            viewModel.InputDataService    = inputDataService;

            TestIFileSystemService fileSystem = new TestIFileSystemService();

            fileSystem.EnumFileSystemEntriesFunc = _ => {
                return(new[] {
                    new FileSystemEntry(FileSystemEntryType.Directory, "dir", @"C:\dir\"),
                    new FileSystemEntry(FileSystemEntryType.File, "f1.dat", @"C:\dir\f1.dat"),
                    new FileSystemEntry(FileSystemEntryType.File, "f2.dat", @"C:\dir\f2.dat"),
                });
            };

            WritableMemoryStream outputStream = new WritableMemoryStream();
            TestIPlatformService platform     = new TestIPlatformService();

            platform.WriteFileFunc = _ => outputStream;

            platform.ReadFileFunc = x => {
                switch (x)
                {
                case @"C:\dir\f1.dat": return(new MemoryStream(new byte[200 * 1024]));

                case @"C:\dir\f2.dat": return(new MemoryStream(new byte[300 * 1024]));

                default: throw new NotImplementedException();
                }
            };
            viewModel.EncodingService = new DefaultHuffmanEncodingService(fileSystem, platform, new DefaultStreamBuilder());

            await viewModel.Run();

            window.UpdateLayout();

            TextBlock inputSizeTextBlock  = window.EncodingResultControl.GetContentTemplateControl <TextBlock>("InputSizeTextBlock");
            TextBlock outputSizeTextBlock = window.EncodingResultControl.GetContentTemplateControl <TextBlock>("OutputSizeTextBlock");
            TextBlock saveFactorTextBlock = window.EncodingResultControl.GetContentTemplateControl <TextBlock>("SaveFactorTextBlock");

            Assert.AreEqual("Input Size: 512 Kb", inputSizeTextBlock.Text);
            Assert.AreEqual("Output Size: 64.1 Kb", outputSizeTextBlock.Text);
            Assert.AreEqual("Save Factor: 87.48%", saveFactorTextBlock.Text);
        }
Пример #8
0
        public async Task EncodingCancellationTest1()
        {
            TestIFileSelectorService fileSelector = new TestIFileSelectorService();

            fileSelector.FilePath         = @"path";
            viewModel.FileSelectorService = fileSelector;
            viewModel.Path = @"C:\dir\";

            TestIInputDataService inputDataService = new TestIInputDataService();

            inputDataService.InputCommand = InputCommand.Encode;
            viewModel.InputDataService    = inputDataService;

            TestIFileSystemService fileSystem = new TestIFileSystemService();

            fileSystem.EnumFileSystemEntriesFunc = _ => {
                return(new[] {
                    new FileSystemEntry(FileSystemEntryType.Directory, "dir", @"C:\dir\"),
                    new FileSystemEntry(FileSystemEntryType.File, "f1.dat", @"C:\dir\f1.dat"),
                    new FileSystemEntry(FileSystemEntryType.File, "f2.dat", @"C:\dir\f2.dat"),
                });
            };

            WritableMemoryStream outputStream = new WritableMemoryStream();
            TestIPlatformService platform     = new TestIPlatformService();

            platform.WriteFileFunc = _ => outputStream;

            int fileRequest = 0;

            platform.ReadFileFunc = x => {
                if (++fileRequest == 4)
                {
                    viewModel.Cancel();
                }
                switch (x)
                {
                case @"C:\dir\f1.dat": return(new MemoryStream(new byte[200 * 1024]));

                case @"C:\dir\f2.dat": return(new MemoryStream(new byte[300 * 1024]));

                default: throw new NotImplementedException();
                }
            };
            viewModel.EncodingService = new DefaultHuffmanEncodingService(fileSystem, platform, new DefaultStreamBuilder());

            await viewModel.Run();

            Assert.AreEqual(32855, outputStream.Length);
        }
Пример #9
0
        public async Task EncodingCancellationTest2()
        {
            TestIFolderSelectorService folderSelector = new TestIFolderSelectorService();

            folderSelector.FolderPath       = @"C:\folder\";
            viewModel.FolderSelectorService = folderSelector;
            viewModel.Path = @"C:\dir\";

            TestIInputDataService inputDataService = new TestIInputDataService();

            inputDataService.InputCommand = InputCommand.Decode;
            viewModel.InputDataService    = inputDataService;

            WritableMemoryStream outputStream = new WritableMemoryStream();
            TestIPlatformService platform     = new TestIPlatformService();

            platform.WriteFileFunc = x => {
                if (string.Equals(x, @"C:\folder\dir\f2.dat", StringComparison.OrdinalIgnoreCase))
                {
                    viewModel.Cancel();
                }
                return(outputStream);
            };
            platform.ReadFileFunc = x => new BufferBuilder()
                                    .AddByte(0x2)
                                    .AddInt(0x9)
                                    .AddByte(0x0)
                                    .AddLong(0x1)
                                    .AddByte(0x1)
                                    .AddInt(0x6)
                                    .AddString("dir")
                                    .AddInt(2)
                                    .AddByte(0x0)
                                    .AddInt(0xC)
                                    .AddString("f1.dat")
                                    .AddLong(200 * 1024 * 8) // 200Kb
                                    .AddByte(0x0, 200 * 1024)
                                    .AddByte(0x0)
                                    .AddInt(0xC)
                                    .AddString("f2.dat")
                                    .AddLong(300 * 1024 * 8) // 300Kb
                                    .AddByte(0x0, 300 * 1024).GetStream();

            viewModel.DecodingService = new DefaultHuffmanDecodingService(platform, new DefaultStreamParser());
            await viewModel.Run();

            Assert.AreEqual(256 * 1024 * 8, outputStream.Length);
        }
 public void SetUp()
 {
     this.fileSystem = new TestIFileSystemService();
     this.platform   = new TestIPlatformService();
     this.service    = new DefaultHuffmanEncodingService(fileSystem, platform, new DefaultStreamBuilder());
 }
 public void SetUp()
 {
     this.fileSystemService = new TestIFileSystemService();
     this.platform          = new TestIPlatformService();
 }
 public void SetUp()
 {
     this.platform = new TestIPlatformService();
     this.service  = new DefaultHuffmanDecodingService(platform, new DefaultStreamParser());
 }
Пример #13
0
 public void SetUp()
 {
     this.platform = new TestIPlatformService();
     this.service  = new DefaultInputDataService(platform);
 }