src/net/third_party/quiche/src/http2/tools/random_decoder_test.cc
// Decode |original| multiple times, with different segmentations, validating
// after each decode, returning on the first failure.
Decode |original| multiple times, with different segmentations, validating
after each decode, returning on the first failure.
Decode |original| multiple times with different segmentations validating after each decode returning on the first failure .
AssertionResult RandomDecoderTest::DecodeAndValidateSeveralWays(
    DecodeBuffer* original,
    bool return_non_zero_on_first,
    const Validator& validator) {
  const uint32_t original_remaining = original->Remaining();
  HTTP2_VLOG(1) << "DecodeAndValidateSeveralWays - Start, remaining = "
                << original_remaining;
  uint32_t first_consumed;
  {
    DecodeBuffer input(original->cursor(), original_remaining);
    HTTP2_VLOG(2) << "DecodeSegmentsAndValidate with SelectRemaining";
    VERIFY_SUCCESS(
        DecodeSegmentsAndValidate(&input, SelectRemaining(), validator))
        << "\nFailed with SelectRemaining; input.Offset=" << input.Offset()
        << "; input.Remaining=" << input.Remaining();
    first_consumed = input.Offset();
  }
  if (original_remaining <= 30) {
    DecodeBuffer input(original->cursor(), original_remaining);
    HTTP2_VLOG(2) << "DecodeSegmentsAndValidate with SelectOne";
    VERIFY_SUCCESS(DecodeSegmentsAndValidate(&input, SelectOne(), validator))
        << "\nFailed with SelectOne; input.Offset=" << input.Offset()
        << "; input.Remaining=" << input.Remaining();
    VERIFY_EQ(first_consumed, input.Offset()) << "\nFailed with SelectOne";
  }
  if (original_remaining <= 20) {
    DecodeBuffer input(original->cursor(), original_remaining);
    HTTP2_VLOG(2) << "DecodeSegmentsAndValidate with SelectZeroAndOne";
    VERIFY_SUCCESS(DecodeSegmentsAndValidate(
        &input, SelectZeroAndOne(return_non_zero_on_first), validator))
        << "\nFailed with SelectZeroAndOne";
    VERIFY_EQ(first_consumed, input.Offset())
        << "\nFailed with SelectZeroAndOne; input.Offset=" << input.Offset()
        << "; input.Remaining=" << input.Remaining();
  }
  {
    DecodeBuffer input(original->cursor(), original_remaining);
    HTTP2_VLOG(2) << "DecodeSegmentsAndValidate with SelectRandom";
    VERIFY_SUCCESS(DecodeSegmentsAndValidate(
        &input, SelectRandom(return_non_zero_on_first), validator))
        << "\nFailed with SelectRandom; input.Offset=" << input.Offset()
        << "; input.Remaining=" << input.Remaining();
    VERIFY_EQ(first_consumed, input.Offset()) << "\nFailed with SelectRandom";
  }
  VERIFY_EQ(original_remaining, original->Remaining());
  original->AdvanceCursor(first_consumed);
  HTTP2_VLOG(1) << "DecodeAndValidateSeveralWays - SUCCESS";
  return ::testing::AssertionSuccess();
}
AssertionResult RandomDecoderTest :: DecodeAndValidateSeveralWays ( DecodeBuffer * original , bool return_non_zero_on_first , const Validator & validator ) { const uint32_t original_remaining = original -> Remaining ( ) ; HTTP2_VLOG ( 1 ) << " " << original_remaining ; uint32_t first_consumed ; { DecodeBuffer input ( original -> cursor ( ) , original_remaining ) ; HTTP2_VLOG ( 2 ) << " " ; VERIFY_SUCCESS ( DecodeSegmentsAndValidate ( & input , SelectRemaining ( ) , validator ) ) << " \n " << input . Offset ( ) << " " << input . Remaining ( ) ; first_consumed = input . Offset ( ) ; } if ( original_remaining <= 30 ) { DecodeBuffer input ( original -> cursor ( ) , original_remaining ) ; HTTP2_VLOG ( 2 ) << " " ; VERIFY_SUCCESS ( DecodeSegmentsAndValidate ( & input , SelectOne ( ) , validator ) ) << " \n " << input . Offset ( ) << " " << input . Remaining ( ) ; VERIFY_EQ ( first_consumed , input . Offset ( ) ) << " \n " ; } if ( original_remaining <= 20 ) { DecodeBuffer input ( original -> cursor ( ) , original_remaining ) ; HTTP2_VLOG ( 2 ) << " " ; VERIFY_SUCCESS ( DecodeSegmentsAndValidate ( & input , SelectZeroAndOne ( return_non_zero_on_first ) , validator ) ) << " \n " ; VERIFY_EQ ( first_consumed , input . Offset ( ) ) << " \n " << input . Offset ( ) << " " << input . Remaining ( ) ; } { DecodeBuffer input ( original -> cursor ( ) , original_remaining ) ; HTTP2_VLOG ( 2 ) << " " ; VERIFY_SUCCESS ( DecodeSegmentsAndValidate ( & input , SelectRandom ( return_non_zero_on_first ) , validator ) ) << " \n " << input . Offset ( ) << " " << input . Remaining ( ) ; VERIFY_EQ ( first_consumed , input . Offset ( ) ) << " \n " ; } VERIFY_EQ ( original_remaining , original -> Remaining ( ) ) ; original -> AdvanceCursor ( first_consumed ) ; HTTP2_VLOG ( 1 ) << " " ; return :: testing :: AssertionSuccess ( ) ; }
Decode |original| multiple times, with different segmentations, validating
after each decode, returning on the first failure.
Decode |original| multiple times with different segmentations validating after each decode returning on the first failure .
// Fast decode (no stopping unless decoder does so). // Decode again, one byte at a time. // Decode again, one or zero bytes at a time. // Decode again, with randomly selected segment sizes.