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/slices_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::ElementParserTest;
16 using webm::Id;
17 using webm::Slices;
18 using webm::SlicesParser;
19 using webm::TimeSlice;
20
21 namespace {
22
23 class SlicesParserTest : public ElementParserTest<SlicesParser, Id::kSlices> {};
24
TEST_F(SlicesParserTest,DefaultParse)25 TEST_F(SlicesParserTest, DefaultParse) {
26 ParseAndVerify();
27
28 const Slices slices = parser_.value();
29
30 EXPECT_EQ(static_cast<std::size_t>(0), slices.slices.size());
31 }
32
TEST_F(SlicesParserTest,DefaultValues)33 TEST_F(SlicesParserTest, DefaultValues) {
34 SetReaderData({
35 0xE8, // ID = 0xE8 (TimeSlice).
36 0x80, // Size = 0.
37 });
38
39 ParseAndVerify();
40
41 const Slices slices = parser_.value();
42
43 ASSERT_EQ(static_cast<std::size_t>(1), slices.slices.size());
44 EXPECT_TRUE(slices.slices[0].is_present());
45 EXPECT_EQ(TimeSlice{}, slices.slices[0].value());
46 }
47
TEST_F(SlicesParserTest,CustomValues)48 TEST_F(SlicesParserTest, CustomValues) {
49 SetReaderData({
50 0xE8, // ID = 0xE8 (TimeSlice).
51 0x83, // Size = 3.
52
53 0xCC, // ID = 0xCC (LaceNumber).
54 0x81, // Size = 1.
55 0x01, // Body (value = 1).
56
57 0xE8, // ID = 0xE8 (TimeSlice).
58 0x83, // Size = 3.
59
60 0xCC, // ID = 0xCC (LaceNumber).
61 0x81, // Size = 1.
62 0x02, // Body (value = 2).
63 });
64
65 ParseAndVerify();
66
67 const Slices slices = parser_.value();
68
69 TimeSlice expected;
70
71 ASSERT_EQ(static_cast<std::size_t>(2), slices.slices.size());
72 expected.lace_number.Set(1, true);
73 EXPECT_TRUE(slices.slices[0].is_present());
74 EXPECT_EQ(expected, slices.slices[0].value());
75 expected.lace_number.Set(2, true);
76 EXPECT_TRUE(slices.slices[1].is_present());
77 EXPECT_EQ(expected, slices.slices[1].value());
78 }
79
80 } // namespace
81