1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "src/var_int_parser.h"
9 
10 #include "gtest/gtest.h"
11 
12 #include "test_utils/parser_test.h"
13 #include "webm/status.h"
14 
15 using webm::ParserTest;
16 using webm::Status;
17 using webm::VarIntParser;
18 
19 namespace {
20 
21 class VarIntParserTest : public ParserTest<VarIntParser> {};
22 
TEST_F(VarIntParserTest,NoMarkerBit)23 TEST_F(VarIntParserTest, NoMarkerBit) {
24   SetReaderData({0x00});
25   ParseAndExpectResult(Status::kInvalidElementValue);
26 }
27 
TEST_F(VarIntParserTest,EarlyEndOfFile)28 TEST_F(VarIntParserTest, EarlyEndOfFile) {
29   SetReaderData({0x01});
30   ParseAndExpectResult(Status::kEndOfFile);
31 }
32 
TEST_F(VarIntParserTest,ValidValue)33 TEST_F(VarIntParserTest, ValidValue) {
34   SetReaderData({0x80});
35   ParseAndVerify();
36   EXPECT_EQ(static_cast<std::uint64_t>(0), parser_.value());
37   EXPECT_EQ(1, parser_.encoded_length());
38 
39   ResetParser();
40   SetReaderData({0x01, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE});
41   ParseAndVerify();
42   EXPECT_EQ(static_cast<std::uint64_t>(0x123456789ABCDE), parser_.value());
43   EXPECT_EQ(8, parser_.encoded_length());
44 }
45 
TEST_F(VarIntParserTest,IncrementalParse)46 TEST_F(VarIntParserTest, IncrementalParse) {
47   SetReaderData({0x11, 0x23, 0x45, 0x67});
48   IncrementalParseAndVerify();
49   EXPECT_EQ(static_cast<std::uint64_t>(0x01234567), parser_.value());
50   EXPECT_EQ(4, parser_.encoded_length());
51 }
52 
53 }  // namespace
54