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/time_slice_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::TimeSlice;
18 using webm::TimeSliceParser;
19 
20 namespace {
21 
22 class TimeSliceParserTest
23     : public ElementParserTest<TimeSliceParser, Id::kTimeSlice> {};
24 
TEST_F(TimeSliceParserTest,DefaultParse)25 TEST_F(TimeSliceParserTest, DefaultParse) {
26   ParseAndVerify();
27 
28   const TimeSlice time_slice = parser_.value();
29 
30   EXPECT_FALSE(time_slice.lace_number.is_present());
31   EXPECT_EQ(static_cast<std::uint64_t>(0), time_slice.lace_number.value());
32 }
33 
TEST_F(TimeSliceParserTest,DefaultValues)34 TEST_F(TimeSliceParserTest, DefaultValues) {
35   SetReaderData({
36       0xCC,  // ID = 0xCC (LaceNumber).
37       0x80,  // Size = 0.
38   });
39 
40   ParseAndVerify();
41 
42   const TimeSlice time_slice = parser_.value();
43 
44   EXPECT_TRUE(time_slice.lace_number.is_present());
45   EXPECT_EQ(static_cast<std::uint64_t>(0), time_slice.lace_number.value());
46 }
47 
TEST_F(TimeSliceParserTest,CustomValues)48 TEST_F(TimeSliceParserTest, CustomValues) {
49   SetReaderData({
50       0xCC,  // ID = 0xCC (LaceNumber).
51       0x81,  // Size = 1.
52       0x01,  // Body (value = 1).
53   });
54 
55   ParseAndVerify();
56 
57   const TimeSlice time_slice = parser_.value();
58 
59   EXPECT_TRUE(time_slice.lace_number.is_present());
60   EXPECT_EQ(static_cast<std::uint64_t>(1), time_slice.lace_number.value());
61 }
62 
63 }  // namespace
64