private static void TestImpl( int architecture, string filename, int index, int length, int level, int expectedCompressedLength, uint expectedChecksum, string expectedBytes64) { // we cannot test 64-bit codec when ran in 32-bit environment // such tests get reported as successful but actually they are not executed if (architecture > IntPtr.Size) { return; } LZ4Codec.EnforceA7 = LZ4Codec.Enforce32 = architecture < IntPtr.Size; try { var src = Tools.LoadChunk(Tools.FindFile(filename), index, length); var dst = CurrentLZ4.Encode(src, 0, src.Length, (LZ4Level)level); var cmp = CurrentLZ4.Decode(dst, 0, dst.Length, src.Length); string AsHex(uint value) => $"0x{value:x8}"; Tools.SameBytes(src, cmp); var expectedBytes = Convert.FromBase64String(expectedBytes64); Tools.SameBytes(expectedBytes, dst, expectedBytes.Length); Assert.Equal(expectedCompressedLength, dst.Length); Assert.Equal(AsHex(expectedChecksum), AsHex(Tools.Adler32(dst))); } finally { LZ4Codec.EnforceA7 = LZ4Codec.Enforce32 = false; } }
private static void Roundtrip(byte[] source, bool enforce32) { LZ4Codec.Enforce32 = enforce32; try { var legacy = LegacyLZ4.Encode(source, 0, source.Length); var baseline = BaselineLZ4.Encode(source, 0, source.Length); var current = CurrentLZ4.Encode(source, 0, source.Length, LZ4Level.L00_FAST); void TestDecode(byte[] compressed, Func <byte[], int, int, int, byte[]> func) => Tools.SameBytes(source, func(compressed, 0, compressed.Length, source.Length)); TestDecode(current, LegacyLZ4.Decode); TestDecode(current, BaselineLZ4.Decode); TestDecode(current, CurrentLZ4.Decode); TestDecode(legacy, CurrentLZ4.Decode); TestDecode(baseline, CurrentLZ4.Decode); } finally { LZ4Codec.Enforce32 = false; } }