1#include <gtest/gtest.h>
2
3#include <base/system.h>
4#include <engine/shared/huffman.h>
5
6TEST(Huffman, CompressionShouldNotChangeData)
7{
8 CHuffman Huffman;
9 Huffman.Init();
10
11 unsigned char aInput[64];
12 unsigned char aCompressed[2048];
13
14 mem_zero(block: aInput, size: sizeof(aInput));
15 mem_zero(block: aCompressed, size: sizeof(aCompressed));
16
17 int Size = Huffman.Compress(pInput: aInput, InputSize: sizeof(aInput), pOutput: aCompressed, OutputSize: sizeof(aCompressed));
18
19 unsigned char aDecompressed[2048];
20 Huffman.Decompress(pInput: aCompressed, InputSize: sizeof(aCompressed), pOutput: aDecompressed, OutputSize: sizeof(aDecompressed));
21
22 int match = mem_comp(a: aInput, b: aDecompressed, size: Size);
23 EXPECT_EQ(match, 0);
24}
25
26TEST(Huffman, CompressionCompatible)
27{
28 CHuffman Huffman;
29 Huffman.Init();
30
31 unsigned char aInput[64];
32 unsigned char aCompressed[2048];
33
34 mem_zero(block: aInput, size: sizeof(aInput));
35 mem_zero(block: aCompressed, size: sizeof(aCompressed));
36
37 // compress 1-7 followed by a bunch of nullbytes
38 for(int i = 0; i < 8; i++)
39 aInput[i] = i;
40
41 int Size = Huffman.Compress(pInput: aInput, InputSize: sizeof(aInput), pOutput: aCompressed, OutputSize: sizeof(aCompressed));
42
43 unsigned char aExpected[] = {0x51, 0x58, 0x78, 0x76, 0x1B, 0xB7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xc5, 0x0D};
44
45 int match = mem_comp(a: aCompressed, b: aExpected, size: Size);
46 EXPECT_EQ(match, 0) << "The compression is not compatible with older/other implementations anymore";
47 EXPECT_EQ(Size, 15);
48}
49