1 // Copyright 2021 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gtest/gtest.h"
6
7 #include "puffin/memory_stream.h"
8 #include "puffin/src/include/puffin/brotli_util.h"
9 #include "puffin/src/puffin_stream.h"
10
11 namespace puffin {
12
13 namespace {
14
15 // echo "puffin test" | xxd -i
16 const Buffer kTestString = {0x70, 0x75, 0x66, 0x66, 0x69, 0x6e,
17 0x20, 0x74, 0x65, 0x73, 0x74, 0x0a};
18 } // namespace
19
TEST(BrotliUtilTest,CompressAndDecompressTest)20 TEST(BrotliUtilTest, CompressAndDecompressTest) {
21 Buffer compressed;
22 ASSERT_TRUE(BrotliEncode(kTestString.data(), kTestString.size(),
23 MemoryStream::CreateForWrite(&compressed)));
24 ASSERT_FALSE(compressed.empty());
25
26 Buffer decompressed;
27 ASSERT_TRUE(BrotliDecode(compressed.data(), compressed.size(),
28 MemoryStream::CreateForWrite(&decompressed)));
29 ASSERT_EQ(kTestString, decompressed);
30 }
31
32 } // namespace puffin
33