// Copyright 2017 The Chromium OS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <algorithm> #include <string> #include <vector> #include "gtest/gtest.h" #include "puffin/memory_stream.h" #include "puffin/src/bit_reader.h" #include "puffin/src/bit_writer.h" #include "puffin/src/include/puffin/common.h" #include "puffin/src/include/puffin/huffer.h" #include "puffin/src/include/puffin/puffer.h" #include "puffin/src/include/puffin/utils.h" #include "puffin/src/logging.h" #include "puffin/src/puff_reader.h" #include "puffin/src/puff_writer.h" #include "puffin/src/puffin_stream.h" #include "puffin/src/unittest_common.h" string; vector; namespace puffin { namespace { // Uncompressed deflate block. const Buffer kRawEmpty = …; const Buffer kRaw1 = …; const Buffer kRaw2 = …; const Buffer kRaw5 = …; } // namespace class PuffinTest : public ::testing::Test { … }; // Tests a simple buffer with uncompressed deflate block. TEST_F(PuffinTest, UncompressedTest) { … } // Tests a simple buffer with uncompressed deflate block with length zero. TEST_F(PuffinTest, ZeroLengthUncompressedTest) { … } // Tests a Fixed Huffman table compressed buffer with only one literal. TEST_F(PuffinTest, OneLiteralFixedHuffmanTableTest) { … } // Tests deflate of an empty buffer. TEST_F(PuffinTest, EmptyTest) { … } // Tests a simple buffer with compress deflate block using fixed Huffman table. TEST_F(PuffinTest, FixedHuffmanTableCompressedTest) { … } // Tests that uncompressed deflate blocks are not ignored when the output // deflate location pointer is null. TEST_F(PuffinTest, NoIgnoreUncompressedBlocksTest) { … } // Tests that uncompressed deflate blocks are ignored when the output // deflate location pointer is valid. TEST_F(PuffinTest, IgnoreUncompressedBlocksTest) { … } namespace { // It is actuall the content of the copyright header. const Buffer kDynamicHTRaw = …; // Dynamic huffman compressed deflate. const Buffer kDynamicHTDeflate = …; const Buffer kDynamicHTPuff = …; } // namespace // Tests a compressed deflate block using dynamic Huffman table. TEST_F(PuffinTest, DynamicHuffmanTableTest) { … } // Tests an uncompressed deflate block with invalid LEN/NLEN. TEST_F(PuffinTest, PuffInvalidUncompressedLengthDeflateTest) { … } // Tests puffing a block with invalid block header. TEST_F(PuffinTest, PuffInvalidBlockHeaderDeflateTest) { … } // Tests puffing a block with final block bit unset so it returns false. TEST_F(PuffinTest, PuffDeflateNoFinalBlockBitTest) { … } // Tests two deflate buffers concatenated, neither have their final bit set. It // is a valid deflate and puff buffer. TEST_F(PuffinTest, MultipleDeflateBufferNoFinabBitsTest) { … } // Tests two deflate buffers concatenated, the first one has final bit set, // second one not. It is a valid deflate and puff buffer. TEST_F(PuffinTest, MultipleDeflateBufferOneFinalBitTest) { … } // Tests two deflate buffers concatenated, both have final bits set. It is a // valid deflate and puff buffer. TEST_F(PuffinTest, MultipleDeflateBufferBothFinalBitTest) { … } // When locating deflates, the puffer has to end when it hit a final block. Test // that with two deflate buffers concatenated and both have final bits set. TEST_F(PuffinTest, EndOnFinalBitTest) { … } // TODO(ahassani): Add unittests for Failhuff too. namespace { // The following is a sequence of bits starting from the top right and ends in // bottom left. It represents the bits in |kGapDeflates|. Bits inside the // brackets (including bits exactly under brackets) represent a deflate stream. // // } { } { }{ } // 11000101 10000000 10001100 01010000 00010001 10001000 00000100 01100010 // 0xC5 0x80 0x8C 0x50 0x11 0x88 0x04 0x62 // // } { } { } { // 10001011 11111100 00000100 01100010 00000001 00011000 10111000 00001000 // 0x8B 0xFC 0x04 0x62 0x01 0x18 0xB8 0x08 // // } { } { }{ // 10001011 00000001 00011000 10111111 11000000 01000110 00100000 00010001 // 0x8B 0x01 0x18 0xBF 0xC0 0x46 0x20 0x11 // // { } { } { // 11111100 00000100 01100010 11111111 00000001 00011000 10110000 00010001 // 0xFC 0x04 0x62 0xFF 0x01 0x18 0xB0 0x11 // const Buffer kGapDeflates = …; const Buffer kGapPuffs = …; // raw 95 // The fifth deflate (and its puff in kGapPuffExtents) is for zero length // deflate corner case. const vector<BitExtent> kGapSubblockDeflateExtents = …; const vector<ByteExtent> kGapPuffExtents = …; } // namespace TEST_F(PuffinTest, BitExtentPuffAndHuffTest) { … } TEST_F(PuffinTest, ExcludeBadDistanceCaches) { … } TEST_F(PuffinTest, NoExcludeBadDistanceCaches) { … } } // namespace puffin