Beispiel #1
0
        public void AlwaysCompressCorrectly()
        {
            using var imgStream = File.OpenRead("G:\\KH2.IMG");
            new Img(imgStream, File.OpenRead("G:\\KH2.IDX").Using(Idx.Read), true)
            .Entries.ToList()
            .Where(x => x.IsCompressed)
            .Where(x => !x.IsStreamed)
            .Select(x => new
            {
                Name  = IdxName.Lookup(x),
                Entry = x,
                Data  = imgStream
                        .SetPosition(x.Offset * 0x800)
                        .ReadBytes((x.BlockLength + 1) * 0x800)
            })
            .ToList()
            .AsParallel()
            .WithDegreeOfParallelism(16)
            .ForAll(x =>
            {
                new MemoryStream(Img.Decompress(x.Data)).Using(stream =>
                {
                    Helpers.AssertStream(stream, inStream =>
                    {
                        var compressedData   = Img.Compress(inStream.ReadAllBytes());
                        var decompressedData = Img.Decompress(compressedData);

                        return(new MemoryStream(decompressedData));
                    });
                });
            });
        }
Beispiel #2
0
        public void TestDecompression(string fileName)
        {
            using (var fileCompressed = File.OpenRead($"kh2/res/{fileName}.cmp"))
            {
                using (var fileExpected = File.OpenRead($"kh2/res/{fileName}.dec"))
                {
                    var decompressedStream = Img.Decompress(fileCompressed);

                    int matched = 0;
                    for (int i = 0; i < decompressedStream.Length; i++)
                    {
                        int expected = fileExpected.ReadByte();
                        int actual   = decompressedStream[i];
                        if (expected == actual)
                        {
                            matched++;
                        }
                    }

                    Assert.Equal(fileExpected.Length, matched);
                }
            }
        }
Beispiel #3
0
        public void CreateEmptyFileIfCompressedSourceIsEmpty()
        {
            var input = Enumerable.Range(0, 0x1000).Select(_ => (byte)0).ToArray();

            Assert.Empty(Img.Decompress(input));
        }
Beispiel #4
0
 public void CompressCorrectlyWhenKeyIsFoundInTheData() =>
 new MemoryStream(Enumerable.Range(0, 0x100).Select(x => (byte)x).ToArray()).Using(stream =>
 {
     Helpers.AssertStream(stream, inStream =>
                          new MemoryStream(Img.Decompress(Img.Compress(inStream.ReadAllBytes()))));
 });
Beispiel #5
0
 public void CompressCorrectly(string fileName) =>
 File.OpenRead($"kh2/res/{fileName}.dec").Using(stream =>
 {
     Helpers.AssertStream(stream, inStream =>
                          new MemoryStream(Img.Decompress(Img.Compress(inStream.ReadAllBytes()))));
 });