1c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Copyright 2008 Google Inc. 2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Author: Lincoln Smith 3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// 4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Licensed under the Apache License, Version 2.0 (the "License"); 5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// you may not use this file except in compliance with the License. 6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// You may obtain a copy of the License at 7c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// 8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// http://www.apache.org/licenses/LICENSE-2.0 9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// 10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Unless required by applicable law or agreed to in writing, software 11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// distributed under the License is distributed on an "AS IS" BASIS, 12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// See the License for the specific language governing permissions and 14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// limitations under the License. 15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include <config.h> 17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "google/vcdecoder.h" 18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "testing.h" 19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "vcdecoder_test.h" 20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "vcdiff_defs.h" // VCD_SOURCE 21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottnamespace open_vcdiff { 23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// These are the same tests as for VCDiffStandardDecoderTest, with the added 25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// complication that instead of calling DecodeChunk() once with the entire data 26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// set, DecodeChunk() is called once for each byte of input. This is intended 27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// to shake out any bugs with rewind and resume while parsing chunked data. 28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scotttypedef VCDiffStandardDecoderTest VCDiffStandardDecoderTestByteByByte; 30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DecodeHeaderOnly) { 32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_header_.size(); ++i) { 34c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_header_[i], 1, &output_)); 35c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 36c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.FinishDecoding()); 37c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 38c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 39c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 40c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, Decode) { 41c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 42c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 43c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 44c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 45c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.FinishDecoding()); 46c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(expected_target_, output_); 47c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 48c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 49c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DecodeNoVcdTarget) { 50c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.SetAllowVcdTarget(false); 51c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 52c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 53c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 54c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 55c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.FinishDecoding()); 56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(expected_target_, output_); 57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 59c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Remove one byte from the length of the chunk to process, and 60c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// verify that an error is returned for FinishDecoding(). 61c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, FinishAfterDecodingPartialWindow) { 62c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_.resize(delta_file_.size() - 1); 63c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 64c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 65c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 66c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 67c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_FALSE(decoder_.FinishDecoding()); 68c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 69c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 70c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 71c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 72c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 73c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott FinishAfterDecodingPartialWindowHeader) { 74c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_.resize(delta_file_header_.size() 75c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott + delta_window_header_.size() - 1); 76c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 77c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 78c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 79c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 80c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_FALSE(decoder_.FinishDecoding()); 81c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 82c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 83c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 84c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// If we add a checksum to a standard-format delta file (without using format 85c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// extensions), it will be interpreted as random bytes inserted into the middle 86c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// of the file. The decode operation should fail, but where exactly it fails is 87c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// undefined. 88c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 89c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott StandardFormatDoesNotSupportChecksum) { 90c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ComputeAndAddChecksum(); 91c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott InitializeDeltaFile(); 92c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 93c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 94c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 95c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 96c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 97c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 98c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 99c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 100c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 102c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 103c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 104c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 105c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetMatchesWindowSizeLimit) { 106c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.SetMaximumTargetWindowSize(expected_target_.size()); 107c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 108c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 109c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 110c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 111c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.FinishDecoding()); 112c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(expected_target_, output_); 113c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 114c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 115c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetMatchesFileSizeLimit) { 116c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.SetMaximumTargetFileSize(expected_target_.size()); 117c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 118c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 119c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 120c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 121c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.FinishDecoding()); 122c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(expected_target_, output_); 123c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 124c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 125c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetExceedsWindowSizeLimit) { 126c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.SetMaximumTargetWindowSize(expected_target_.size() - 1); 127c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 128c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 129c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 130c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 131c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 132c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 133c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 134c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 135c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 136c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 137c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 138c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 139c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetExceedsFileSizeLimit) { 140c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.SetMaximumTargetFileSize(expected_target_.size() - 1); 141c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 142c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 143c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 144c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 145c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 146c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 147c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 148c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 149c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 150c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 151c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 152c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 153c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Fuzz bits to make sure decoder does not violently crash. 154c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// This test has no expected behavior except that no crashes should occur. 155c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// In some cases, changing bits will still decode to the correct target; 156c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// for example, changing unused bits within a bitfield. 157c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, FuzzBits) { 158c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott while (FuzzOneByteInDeltaFile()) { 159c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 160c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 161c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 162c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 163c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 164c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 165c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 166c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 167c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!failed) { 168c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.FinishDecoding(); 169c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 170c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 171c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 172c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott InitializeDeltaFile(); 173c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott output_.clear(); 174c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 175c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 176c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 177c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Change each element of the delta file window to an erroneous value 178c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// and make sure it's caught as an error. 179c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 180c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 181c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WinIndicatorHasBothSourceAndTarget) { 182c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size()] = VCD_SOURCE + VCD_TARGET; 183c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 184c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 185c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 186c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 187c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 188c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail at the position that was altered 189c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size(), i); 190c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 191c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 192c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 193c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 194c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 195c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 196c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 197c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, OkayToSetUpperBitsOfWinIndicator) { 198c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It is not an error to set any of the other bits in Win_Indicator 199c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // besides VCD_SOURCE and VCD_TARGET. 200c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size()] = 0xFD; 201c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 202c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 203c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 204c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 205c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.FinishDecoding()); 206c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(expected_target_, output_); 207c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 208c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 209c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 210c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CopyInstructionsShouldFailIfNoSourceSegment) { 211c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Replace the Win_Indicator and the source size and source offset with a 212c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // single 0 byte (a Win_Indicator for a window with no source segment.) 213c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_window_header_.replace(0, 4, "\0", 1); 214c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott InitializeDeltaFile(); 215c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 216c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 217c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 218c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 219c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 220c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The first COPY instruction should fail. With the standard format, 221c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // it may need to see the whole delta window before knowing that it is 222c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // invalid. 223c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 224c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 225c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 226c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 227c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 228c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 229c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 230c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 231c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott SourceSegmentSizeExceedsDictionarySize) { 232c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 2]; // increment size 233c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 234c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 235c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 236c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 237c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 238c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment size 239c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 2, i); 240c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 241c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 242c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 243c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 244c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 245c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 246c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 247c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, SourceSegmentSizeMaxInt) { 248c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(1, 2); 249c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 250c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 251c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 252c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 253c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 254c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment size 255c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 5, i); 256c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 257c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 258c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 259c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 260c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 261c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 262c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 263c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, SourceSegmentSizeNegative) { 264c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(1, 2); 265c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 266c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 267c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 268c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 269c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 270c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment size 271c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 4, i); 272c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 273c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 274c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 275c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 276c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 277c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 278c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 279c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, SourceSegmentSizeInvalid) { 280c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(1, 2); 281c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 282c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 283c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 284c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 285c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 286c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment size 287c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + 6, i); 288c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 289c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 290c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 291c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 292c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 293c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 294c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 295c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 296c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott SourceSegmentEndExceedsDictionarySize) { 297c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 3]; // increment start pos 298c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 299c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 300c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 301c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 302c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 303c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment end 304c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 3, i); 305c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 306c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 307c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 308c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 309c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 310c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 311c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 312c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, SourceSegmentPosMaxInt) { 313c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(3, 1); 314c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 315c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 316c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 317c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 318c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 319c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment pos 320c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 7, i); 321c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 322c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 323c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 324c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 325c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 326c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 327c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 328c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, SourceSegmentPosNegative) { 329c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(3, 1); 330c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 331c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 332c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 333c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 334c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 335c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment pos 336c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 6, i); 337c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 338c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 339c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 340c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 341c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 342c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 343c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 344c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, SourceSegmentPosInvalid) { 345c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(3, 1); 346c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 347c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 348c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 349c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 350c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 351c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the source segment pos 352c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + 8, i); 353c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 354c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 355c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 356c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 357c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 358c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 359c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 360c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DeltaEncodingLengthZero) { 361c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 4] = 0; 362c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 363c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 364c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 365c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 366c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 367c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 368c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 369c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 370c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 371c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 372c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 373c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 374c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 375c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 376c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DeltaEncodingLengthTooLargeByOne) { 377c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 4]; 378c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 379c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 380c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 381c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 382c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 383c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 384c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 385c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 386c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 387c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 388c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 389c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 390c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 391c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 392c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DeltaEncodingLengthTooSmallByOne) { 393c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 4]; 394c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 395c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 396c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 397c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 398c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 399c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 400c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 401c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 402c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 403c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 404c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 405c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 406c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 407c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 408c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DeltaEncodingLengthMaxInt) { 409c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(4, 1); 410c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 411c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 412c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 413c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 414c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 415c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail before finishing the window header 416c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + delta_window_header_.size() + 4, 417c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott i); 418c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 419c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 420c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 421c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 422c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 423c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 424c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 425c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DeltaEncodingLengthNegative) { 426c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(4, 1); 427c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 428c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 429c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 430c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 431c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 432c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the delta encoding length 433c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 7, i); 434c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 435c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 436c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 437c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 438c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 439c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 440c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 441c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DeltaEncodingLengthInvalid) { 442c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(4, 1); 443c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 444c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 445c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 446c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 447c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 448c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the delta encoding length 449c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + 9, i); 450c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 451c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 452c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 453c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 454c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 455c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 456c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 457c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetWindowSizeZero) { 458c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott static const char zero_size[] = { 0x00 }; 459c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_.replace(delta_file_header_.size() + 5, 2, zero_size, 1); 460c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 461c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 462c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 463c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 464c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 465c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 466c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 467c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 468c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 469c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 470c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 471c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 472c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetWindowSizeTooLargeByOne) { 473c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 6]; 474c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 475c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 476c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 477c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 478c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 479c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 480c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 481c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 482c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 483c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 484c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 485c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 486c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 487c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetWindowSizeTooSmallByOne) { 488c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 6]; 489c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 490c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 491c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 492c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 493c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 494c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 495c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 496c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 497c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 498c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 499c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 500c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 501c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 502c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetWindowSizeMaxInt) { 503c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(5, 2); 504c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 505c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 506c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 507c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 508c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 509c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the target window size 510c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 9, i); 511c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 512c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 513c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 514c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 515c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 516c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 517c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 518c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetWindowSizeNegative) { 519c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(5, 2); 520c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 521c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 522c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 523c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 524c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 525c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the target window size 526c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 8, i); 527c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 528c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 529c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 530c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 531c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 532c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 533c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 534c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, TargetWindowSizeInvalid) { 535c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(5, 2); 536c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 537c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 538c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 539c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 540c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 541c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the target window size 542c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + 10, i); 543c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 544c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 545c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 546c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 547c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 548c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 549c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 550c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 551c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott OkayToSetUpperBitsOfDeltaIndicator) { 552c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 7] = 0xF8; 553c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 554c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 555c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.DecodeChunk(&delta_file_[i], 1, &output_)); 556c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 557c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(decoder_.FinishDecoding()); 558c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(expected_target_, output_); 559c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 560c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 561c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, DataCompressionNotSupported) { 562c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 7] = 0x01; 563c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 564c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 565c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 566c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 567c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 568c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the delta indicator 569c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 7, i); 570c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 571c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 572c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 573c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 574c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 575c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 576c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 577c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, 578c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott InstructionCompressionNotSupported) { 579c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 7] = 0x02; 580c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 581c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 582c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 583c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 584c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 585c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the delta indicator 586c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 7, i); 587c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 588c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 589c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 590c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 591c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 592c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 593c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 594c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddressCompressionNotSupported) { 595c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 7] = 0x04; 596c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 597c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 598c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 599c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 600c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 601c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the delta indicator 602c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 7, i); 603c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 604c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 605c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 606c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 607c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 608c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 609c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 610c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddRunDataSizeZero) { 611c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 8] = 0; 612c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 613c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 614c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 615c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 616c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 617c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 618c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 619c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 620c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 621c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 622c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 623c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 624c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 625c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 626c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddRunDataSizeTooLargeByOne) { 627c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 8]; 628c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 629c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 630c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 631c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 632c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 633c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 634c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 635c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 636c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 637c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 638c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 639c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 640c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 641c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 642c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddRunDataSizeTooSmallByOne) { 643c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 8]; 644c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 645c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 646c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 647c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 648c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 649c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 650c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 651c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 652c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 653c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 654c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 655c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 656c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 657c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 658c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddRunDataSizeMaxInt) { 659c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(8, 1); 660c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 661c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 662c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 663c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 664c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 665c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail before finishing the window header 666c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + delta_window_header_.size() + 4, 667c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott i); 668c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 669c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 670c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 671c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 672c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 673c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 674c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 675c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddRunDataSizeNegative) { 676c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(8, 1); 677c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 678c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 679c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 680c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 681c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 682c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the add/run data segment size 683c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 11, i); 684c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 685c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 686c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 687c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 688c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 689c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 690c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 691c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddRunDataSizeInvalid) { 692c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(8, 1); 693c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 694c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 695c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 696c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 697c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 698c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the add/run data segment size 699c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + 13, i); 700c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 701c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 702c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 703c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 704c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 705c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 706c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 707c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, InstructionsSizeZero) { 708c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 9] = 0; 709c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 710c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 711c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 712c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 713c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 714c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 715c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 716c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 717c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 718c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 719c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 720c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 721c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 722c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 723c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, InstructionsSizeTooLargeByOne) { 724c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 9]; 725c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 726c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 727c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 728c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 729c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 730c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 731c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 732c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 733c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 734c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 735c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 736c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 737c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 738c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 739c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, InstructionsSizeTooSmallByOne) { 740c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 9]; 741c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 742c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 743c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 744c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 745c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 746c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 747c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 748c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 749c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 750c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 751c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 752c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 753c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 754c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 755c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, InstructionsSizeMaxInt) { 756c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(9, 1); 757c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 758c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 759c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 760c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 761c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 762c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail before finishing the window header 763c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + delta_window_header_.size() + 4, 764c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott i); 765c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 766c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 767c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 768c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 769c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 770c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 771c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 772c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, InstructionsSizeNegative) { 773c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(9, 1); 774c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 775c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 776c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 777c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 778c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 779c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the instructions segment size 780c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 12, i); 781c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 782c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 783c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 784c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 785c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 786c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 787c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 788c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, InstructionsSizeInvalid) { 789c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(9, 1); 790c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 791c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 792c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 793c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 794c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 795c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the instructions segment size 796c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + 14, i); 797c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 798c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 799c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 800c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 801c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 802c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 803c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 804c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressSizeZero) { 805c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 10] = 0; 806c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 807c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 808c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 809c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 810c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 811c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 812c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 813c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 814c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 815c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 816c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 817c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 818c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 819c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 820c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressSizeTooLargeByOne) { 821c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 10]; 822c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 823c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 824c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 825c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 826c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 827c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 828c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 829c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 830c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 831c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 832c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 833c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 834c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 835c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 836c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressSizeTooSmallByOne) { 837c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 10]; 838c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 839c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 840c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 841c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 842c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 843c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 844c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 10, i); 845c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 846c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 847c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 848c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 849c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 850c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 851c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 852c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressSizeMaxInt) { 853c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(10, 1); 854c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 855c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 856c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 857c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 858c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 859c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 860c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 14, i); 861c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 862c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 863c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 864c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 865c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 866c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 867c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 868c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressSizeNegative) { 869c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(10, 1); 870c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 871c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 872c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 873c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 874c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 875c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 876c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ(delta_file_header_.size() + 13, i); 877c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 878c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 879c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 880c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 881c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 882c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 883c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 884c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressSizeInvalid) { 885c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(10, 1); 886c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 887c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 888c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 889c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 890c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 891c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // It should fail after decoding the copy address segment size 892c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(delta_file_header_.size() + 15, i); 893c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 894c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 895c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 896c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 897c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_EQ("", output_); 898c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 899c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 900c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, InstructionsEndEarly) { 901c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 9]; 902c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 10]; 903c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 904c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 905c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 906c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 907c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 908c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 909c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 910c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 911c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 912c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 913c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 914c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 915c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 916c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// From this point on, the tests should also be run against the interleaved 917c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// format. 918c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 919c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyMoreThanExpectedTarget) { 920c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x70] = 921c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott FirstByteOfStringLength(kExpectedTarget); 922c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x71] = 923c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott SecondByteOfStringLength(kExpectedTarget) + 1; 924c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 925c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 926c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 927c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 928c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 929c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 930c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 931c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 932c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 933c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 934c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 935c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 936c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 937c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopySizeZero) { 938c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x70] = 0; 939c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 940c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 941c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 942c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 943c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 944c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 945c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 946c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 947c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 948c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 949c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 950c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 951c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 952c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopySizeTooLargeByOne) { 953c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 0x70]; 954c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 955c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 956c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 957c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 958c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 959c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 960c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 961c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 962c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 963c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 964c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 965c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 966c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 967c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopySizeTooSmallByOne) { 968c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 0x70]; 969c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 970c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 971c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 972c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 973c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 974c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 975c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 976c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 977c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 978c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 979c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 980c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 981c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 982c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopySizeMaxInt) { 983c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(0x70, 1); 984c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 985c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 986c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 987c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 988c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 989c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 990c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 991c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 992c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 993c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 994c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 995c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 996c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 997c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopySizeNegative) { 998c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(0x70, 1); 999c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1000c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1001c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1002c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1003c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1004c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1005c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1006c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1007c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1008c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1009c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1010c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1011c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1012c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopySizeInvalid) { 1013c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(0x70, 1); 1014c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1015c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1016c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1017c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1018c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1019c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1020c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1021c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1022c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1023c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1024c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1025c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1026c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1027c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressBeyondHereAddress) { 1028c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x7B] = 1029c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott FirstByteOfStringLength(kDictionary); 1030c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x7C] = 1031c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott SecondByteOfStringLength(kDictionary); 1032c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1033c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1034c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1035c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1036c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1037c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1038c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1039c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1040c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1041c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1042c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1043c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1044c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1045c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressMaxInt) { 1046c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(0x7B, 1); 1047c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1048c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1049c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1050c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1051c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1052c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1053c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1054c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1055c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1056c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1057c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1058c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1059c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1060c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressNegative) { 1061c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(0x70, 1); 1062c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1063c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1064c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1065c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1066c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1067c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1068c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1069c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1070c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1071c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1072c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1073c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1074c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1075c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, CopyAddressInvalid) { 1076c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(0x70, 1); 1077c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1078c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1079c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1080c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1081c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1082c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1083c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1084c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1085c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1086c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1087c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1088c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1089c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1090c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddMoreThanExpectedTarget) { 1091c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x72] = 1092c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott FirstByteOfStringLength(kExpectedTarget); 1093c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x73] = 1094c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott SecondByteOfStringLength(kExpectedTarget) + 1; 1095c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1096c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1097c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1098c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1099c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1100c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1102c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1103c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1104c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1105c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1106c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1107c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1108c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddSizeZero) { 1109c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x72] = 0; 1110c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1111c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1112c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1113c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1114c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1115c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1116c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1117c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1118c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1119c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1120c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1121c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1122c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1123c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddSizeTooLargeByOne) { 1124c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 0x72]; 1125c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1126c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1127c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1128c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1129c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1130c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1131c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1132c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1133c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1134c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1135c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1136c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1137c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1138c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddSizeTooSmallByOne) { 1139c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 0x72]; 1140c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1141c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1142c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1143c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1144c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1145c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1146c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1147c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1148c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1149c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1150c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1151c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1152c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1153c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddSizeMaxInt) { 1154c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(0x72, 1); 1155c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1156c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1157c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1158c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1159c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1160c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1161c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1162c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1163c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1164c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1165c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1166c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1167c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1168c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddSizeNegative) { 1169c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(0x72, 1); 1170c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1171c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1172c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1173c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1174c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1175c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1176c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1177c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1178c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1179c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1180c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1181c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1182c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1183c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, AddSizeInvalid) { 1184c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(0x72, 1); 1185c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1186c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1187c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1188c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1189c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1190c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1191c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1192c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1193c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1194c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1195c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1196c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1197c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1198c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, RunMoreThanExpectedTarget) { 1199c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x78] = 1200c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott FirstByteOfStringLength(kExpectedTarget); 1201c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x79] = 1202c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott SecondByteOfStringLength(kExpectedTarget) + 1; 1203c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1204c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1205c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1206c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1207c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1208c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1209c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1210c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1211c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1212c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1213c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1214c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1215c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1216c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, RunSizeZero) { 1217c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott delta_file_[delta_file_header_.size() + 0x78] = 0; 1218c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1219c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1220c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1221c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1222c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1223c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1224c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1225c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1226c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1227c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1228c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1229c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1230c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1231c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, RunSizeTooLargeByOne) { 1232c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ++delta_file_[delta_file_header_.size() + 0x78]; 1233c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1234c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1235c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1236c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1237c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1238c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1239c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1240c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1241c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1242c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1243c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1244c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1245c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1246c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, RunSizeTooSmallByOne) { 1247c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott --delta_file_[delta_file_header_.size() + 0x78]; 1248c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1249c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1250c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1251c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1252c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1253c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1254c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1255c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1256c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1257c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1258c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1259c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1260c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1261c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, RunSizeMaxInt) { 1262c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteMaxVarintAtOffset(0x78, 1); 1263c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1264c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1265c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1266c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1267c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1268c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1269c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1270c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1271c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1272c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1273c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1274c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1275c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1276c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, RunSizeNegative) { 1277c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteNegativeVarintAtOffset(0x78, 1); 1278c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1279c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1280c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1281c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1282c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1283c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1284c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1285c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1286c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1287c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1288c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1289c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1290c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1291c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottTEST_F(VCDiffStandardDecoderTestByteByByte, RunSizeInvalid) { 1292c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott WriteInvalidVarintAtOffset(0x78, 1); 1293c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott decoder_.StartDecoding(dictionary_.data(), dictionary_.size()); 1294c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool failed = false; 1295c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for (size_t i = 0; i < delta_file_.size(); ++i) { 1296c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott if (!decoder_.DecodeChunk(&delta_file_[i], 1, &output_)) { 1297c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott failed = true; 1298c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott break; 1299c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1300c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 1301c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_TRUE(failed); 1302c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // The decoder should not create more target bytes than were expected. 1303c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott EXPECT_GE(expected_target_.size(), output_.size()); 1304c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 1305c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1306c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} // namespace open_vcdiff 1307