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/block_more_parser.h"
9 
10 #include "gtest/gtest.h"
11 
12 #include "test_utils/element_parser_test.h"
13 #include "webm/id.h"
14 
15 using webm::BlockMore;
16 using webm::BlockMoreParser;
17 using webm::ElementParserTest;
18 using webm::Id;
19 
20 namespace {
21 
22 class BlockMoreParserTest
23     : public ElementParserTest<BlockMoreParser, Id::kBlockMore> {};
24 
TEST_F(BlockMoreParserTest,DefaultParse)25 TEST_F(BlockMoreParserTest, DefaultParse) {
26   ParseAndVerify();
27 
28   const BlockMore block_more = parser_.value();
29 
30   EXPECT_FALSE(block_more.id.is_present());
31   EXPECT_EQ(static_cast<std::uint64_t>(1), block_more.id.value());
32 
33   EXPECT_FALSE(block_more.data.is_present());
34   EXPECT_EQ(std::vector<std::uint8_t>{}, block_more.data.value());
35 }
36 
TEST_F(BlockMoreParserTest,DefaultValues)37 TEST_F(BlockMoreParserTest, DefaultValues) {
38   SetReaderData({
39       0xEE,  // ID = 0xEE (BlockAddID).
40       0x80,  // Size = 0.
41 
42       0xA5,  // ID = 0xA5 (BlockAdditional).
43       0x80,  // Size = 0.
44   });
45 
46   ParseAndVerify();
47 
48   const BlockMore block_more = parser_.value();
49 
50   EXPECT_TRUE(block_more.id.is_present());
51   EXPECT_EQ(static_cast<std::uint64_t>(1), block_more.id.value());
52 
53   EXPECT_TRUE(block_more.data.is_present());
54   EXPECT_EQ(std::vector<std::uint8_t>{}, block_more.data.value());
55 }
56 
TEST_F(BlockMoreParserTest,CustomValues)57 TEST_F(BlockMoreParserTest, CustomValues) {
58   SetReaderData({
59       0xEE,  // ID = 0xEE (BlockAddID).
60       0x81,  // Size = 1.
61       0x02,  // Body (value = 2).
62 
63       0xA5,  // ID = 0xA5 (BlockAdditional).
64       0x81,  // Size = 1.
65       0x00,  // Body.
66   });
67 
68   ParseAndVerify();
69 
70   const BlockMore block_more = parser_.value();
71 
72   EXPECT_TRUE(block_more.id.is_present());
73   EXPECT_EQ(static_cast<std::uint64_t>(2), block_more.id.value());
74 
75   EXPECT_TRUE(block_more.data.is_present());
76   EXPECT_EQ(std::vector<std::uint8_t>{0x00}, block_more.data.value());
77 }
78 
79 }  // namespace
80