summaryrefslogtreecommitdiff
path: root/test/decompress.cc
blob: 35c447790e7e40a21feba4b03f0ab6f425d4daa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <gtest/gtest.h>

#include "decompress.hh"

TEST(z_decompress, empty) {
  static const unsigned char data[] = {
    0x1f, 0x8b, 0x08, 0x08, 0x33, 0xd4, 0xbd, 0x68,
    0x02, 0x03, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x00,
    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00
  };
  auto reader = decompress::gzip(io::memory(std::string(
      reinterpret_cast<const char*>(data), sizeof(data))));
  char buf[10];
  auto got = reader->read(buf, sizeof(buf));
  ASSERT_TRUE(got.has_value());
  EXPECT_EQ(0, got.value());
}

TEST(z_decompress, hello) {
  static const unsigned char data[] = {
    0x1f, 0x8b, 0x08, 0x08, 0xf7, 0xd5, 0xbd, 0x68,
    0x02, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00,
    0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x07, 0x00, 0x82,
    0x89, 0xd1, 0xf7, 0x05, 0x00, 0x00, 0x00,
  };
  auto reader = decompress::gzip(io::memory(std::string(
      reinterpret_cast<const char*>(data), sizeof(data))));
  char buf[10];
  auto got = reader->read(buf, sizeof(buf));
  ASSERT_TRUE(got.has_value());
  EXPECT_EQ(5, got.value());
  buf[5] = '\0';
  EXPECT_STREQ("Hello", buf);
}

TEST(xz_decompress, empty) {
  static const unsigned char data[] = {
    0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x04,
    0xe6, 0xd6, 0xb4, 0x46, 0x00, 0x00, 0x00, 0x00,
    0x1c, 0xdf, 0x44, 0x21, 0x1f, 0xb6, 0xf3, 0x7d,
    0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x59, 0x5a
  };
  auto reader = decompress::xz(io::memory(std::string(
      reinterpret_cast<const char*>(data), sizeof(data))));
  char buf[10];
  auto got = reader->read(buf, sizeof(buf));
  ASSERT_TRUE(got.has_value());
  EXPECT_EQ(0, got.value());
}

TEST(xz_decompress, hello) {
  static const unsigned char data[] = {
    0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x04,
    0xe6, 0xd6, 0xb4, 0x46, 0x04, 0xc0, 0x09, 0x05,
    0x21, 0x01, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x76, 0xe9, 0x07, 0x70,
    0x01, 0x00, 0x04, 0x48, 0x65, 0x6c, 0x6c, 0x6f,
    0x00, 0x00, 0x00, 0x00, 0xc8, 0xac, 0x7b, 0xc8,
    0x3b, 0x5c, 0xcf, 0x51, 0x00, 0x01, 0x25, 0x05,
    0x43, 0x91, 0x1f, 0xb8, 0x1f, 0xb6, 0xf3, 0x7d,
    0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x59, 0x5a,
  };
  auto reader = decompress::xz(io::memory(std::string(
      reinterpret_cast<const char*>(data), sizeof(data))));
  char buf[10];
  auto got = reader->read(buf, sizeof(buf));
  ASSERT_TRUE(got.has_value());
  EXPECT_EQ(5, got.value());
  buf[5] = '\0';
  EXPECT_STREQ("Hello", buf);
}