/* * Copyright (c) 2018, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
TEST(AomLeb128, DecodeTest) { const size_t num_leb128_bytes = 3; const uint8_t leb128_bytes[num_leb128_bytes] = { 0xE5, 0x8E, 0x26 }; const uint64_t expected_value = 0x98765; // 624485 const size_t expected_length = 3;
uint64_t value = ~0ULL; // make sure value is cleared by the function
size_t length;
ASSERT_EQ(
aom_uleb_decode(&leb128_bytes[0], num_leb128_bytes, &value, &length), 0);
ASSERT_EQ(expected_value, value);
ASSERT_EQ(expected_length, length);
// Make sure the decoder stops on the last marked LEB128 byte.
aom_uleb_decode(&leb128_bytes[0], num_leb128_bytes + 1, &value, &length);
ASSERT_EQ(expected_value, value);
ASSERT_EQ(expected_length, length);
}
TEST(AomLeb128, SizeTest) { for (size_t i = 0; i < kSizeTestNumValues; ++i) {
ASSERT_EQ(kSizeTestExpectedSizes[i],
aom_uleb_size_in_bytes(kSizeTestInputs[i]));
}
}
TEST(AomLeb128, DecodeFailTest) { // Input buffer containing what would be a valid 9 byte LEB128 encoded // unsigned integer. const uint8_t kAllPadBytesBuffer[kMaximumLeb128CodedSize + 1] = {
kLeb128PadByte, kLeb128PadByte, kLeb128PadByte,
kLeb128PadByte, kLeb128PadByte, kLeb128PadByte,
kLeb128PadByte, kLeb128PadByte, 0
};
uint64_t decoded_value;
// Test that decode fails when result would be valid 9 byte integer.
ASSERT_EQ(aom_uleb_decode(&kAllPadBytesBuffer[0], kMaximumLeb128CodedSize + 1,
&decoded_value, nullptr),
-1);
// Test that encoded value missing terminator byte within available buffer // range causes decode error.
ASSERT_EQ(aom_uleb_decode(&kAllPadBytesBuffer[0], kMaximumLeb128CodedSize,
&decoded_value, nullptr),
-1);
// Test that LEB128 input that decodes to a value larger than 32-bits fails.
size_t value_size = 0;
ASSERT_EQ(aom_uleb_decode(&kOutOfRangeLeb128Value[0], sizeof(kOutOfRangeLeb128Value), &decoded_value,
&value_size),
-1);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.