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