Ai
2 Star 0 Fork 0

mirrors_android_source/bsdiff

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
brotli_decompressor_unittest.cc 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2018 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 "bsdiff/brotli_decompressor.h"
#include <memory>
#include <string>
#include <vector>
#include <gtest/gtest.h>
namespace {
// echo -n "Hello!" | brotli -9 | hexdump -v -e '" " 11/1 "0x%02x, " "\n"'
constexpr uint8_t kBrotliHello[] = {
0x8b, 0x02, 0x80, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0x03,
};
} // namespace
namespace bsdiff {
class BrotliDecompressorTest : public testing::Test {
protected:
void SetUp() {
decompressor_.reset(new BrotliDecompressor());
EXPECT_NE(nullptr, decompressor_.get());
}
std::unique_ptr<BrotliDecompressor> decompressor_;
};
TEST_F(BrotliDecompressorTest, SmokeTest) {
EXPECT_TRUE(decompressor_->SetInputData(kBrotliHello, sizeof(kBrotliHello)));
std::vector<uint8_t> output_data(6);
EXPECT_TRUE(decompressor_->Read(output_data.data(), output_data.size()));
std::string hello = "Hello!";
EXPECT_EQ(std::vector<uint8_t>(hello.begin(), hello.end()), output_data);
}
TEST_F(BrotliDecompressorTest, ReadingFromEmptyFileTest) {
uint8_t data = 0;
EXPECT_TRUE(decompressor_->SetInputData(&data, 0));
uint8_t output_data[10];
EXPECT_FALSE(decompressor_->Read(output_data, sizeof(output_data)));
}
// Check that we fail to read from a truncated file.
TEST_F(BrotliDecompressorTest, ReadingFromTruncatedFileTest) {
// We feed only half of the compressed file.
EXPECT_TRUE(
decompressor_->SetInputData(kBrotliHello, sizeof(kBrotliHello) / 2));
uint8_t output_data[6];
EXPECT_FALSE(decompressor_->Read(output_data, sizeof(output_data)));
}
// Check that we fail to read more than it is available in the file.
TEST_F(BrotliDecompressorTest, ReadingMoreThanAvailableTest) {
EXPECT_TRUE(decompressor_->SetInputData(kBrotliHello, sizeof(kBrotliHello)));
uint8_t output_data[1000];
EXPECT_FALSE(decompressor_->Read(output_data, sizeof(output_data)));
}
} // namespace bsdiff
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_android_source/bsdiff.git
git@gitee.com:mirrors_android_source/bsdiff.git
mirrors_android_source
bsdiff
bsdiff
main

搜索帮助