• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_additions_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::BlockAdditions;
16 using webm::BlockAdditionsParser;
17 using webm::BlockMore;
18 using webm::ElementParserTest;
19 using webm::Id;
20 
21 namespace {
22 
23 class BlockAdditionsParserTest
24     : public ElementParserTest<BlockAdditionsParser, Id::kBlockAdditions> {};
25 
TEST_F(BlockAdditionsParserTest,DefaultParse)26 TEST_F(BlockAdditionsParserTest, DefaultParse) {
27   ParseAndVerify();
28 
29   const BlockAdditions block_additions = parser_.value();
30 
31   const std::size_t kExpectedBlockMoresSize = 0;
32   EXPECT_EQ(kExpectedBlockMoresSize, block_additions.block_mores.size());
33 }
34 
TEST_F(BlockAdditionsParserTest,DefaultValues)35 TEST_F(BlockAdditionsParserTest, DefaultValues) {
36   SetReaderData({
37       0xA6,  // ID = 0xA6 (BlockMore).
38       0x80,  // Size = 0.
39   });
40 
41   ParseAndVerify();
42 
43   const BlockAdditions block_additions = parser_.value();
44 
45   ASSERT_EQ(static_cast<std::size_t>(1), block_additions.block_mores.size());
46   EXPECT_TRUE(block_additions.block_mores[0].is_present());
47   EXPECT_EQ(BlockMore{}, block_additions.block_mores[0].value());
48 }
49 
TEST_F(BlockAdditionsParserTest,CustomValues)50 TEST_F(BlockAdditionsParserTest, CustomValues) {
51   SetReaderData({
52       0xA6,  // ID = 0xA6 (BlockMore).
53       0x83,  // Size = 3.
54 
55       0xEE,  //   ID = 0xEE (BlockAddID).
56       0x81,  //   Size = 1.
57       0x02,  //   Body (value = 2).
58 
59       0xA6,  // ID = 0xA6 (BlockMore).
60       0x83,  // Size = 3.
61 
62       0xEE,  //   ID = 0xEE (BlockAddID).
63       0x81,  //   Size = 1.
64       0x03,  //   Body (value = 3).
65   });
66 
67   ParseAndVerify();
68 
69   const BlockAdditions block_additions = parser_.value();
70 
71   BlockMore expected;
72 
73   ASSERT_EQ(static_cast<std::size_t>(2), block_additions.block_mores.size());
74   expected.id.Set(2, true);
75   EXPECT_TRUE(block_additions.block_mores[0].is_present());
76   EXPECT_EQ(expected, block_additions.block_mores[0].value());
77   expected.id.Set(3, true);
78   EXPECT_TRUE(block_additions.block_mores[1].is_present());
79   EXPECT_EQ(expected, block_additions.block_mores[1].value());
80 }
81 
82 }  // namespace
83