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/chapter_display_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::ChapterDisplay;
16 using webm::ChapterDisplayParser;
17 using webm::ElementParserTest;
18 using webm::Id;
19 
20 namespace {
21 
22 class ChapterDisplayParserTest
23     : public ElementParserTest<ChapterDisplayParser, Id::kChapterDisplay> {};
24 
TEST_F(ChapterDisplayParserTest,DefaultParse)25 TEST_F(ChapterDisplayParserTest, DefaultParse) {
26   ParseAndVerify();
27 
28   const ChapterDisplay chapter_display = parser_.value();
29 
30   EXPECT_FALSE(chapter_display.string.is_present());
31   EXPECT_EQ("", chapter_display.string.value());
32 
33   ASSERT_EQ(static_cast<std::uint64_t>(1), chapter_display.languages.size());
34   EXPECT_FALSE(chapter_display.languages[0].is_present());
35   EXPECT_EQ("eng", chapter_display.languages[0].value());
36 
37   EXPECT_EQ(static_cast<std::size_t>(0), chapter_display.countries.size());
38 }
39 
TEST_F(ChapterDisplayParserTest,DefaultValues)40 TEST_F(ChapterDisplayParserTest, DefaultValues) {
41   SetReaderData({
42       0x85,  // ID = 0x85 (ChapString).
43       0x40, 0x00,  // Size = 0.
44 
45       0x43, 0x7C,  // ID = 0x437C (ChapLanguage).
46       0x80,  // Size = 0.
47 
48       0x43, 0x7E,  // ID = 0x437E (ChapCountry).
49       0x80,  // Size = 0.
50   });
51 
52   ParseAndVerify();
53 
54   const ChapterDisplay chapter_display = parser_.value();
55 
56   EXPECT_TRUE(chapter_display.string.is_present());
57   EXPECT_EQ("", chapter_display.string.value());
58 
59   ASSERT_EQ(static_cast<std::size_t>(1), chapter_display.languages.size());
60   EXPECT_TRUE(chapter_display.languages[0].is_present());
61   EXPECT_EQ("eng", chapter_display.languages[0].value());
62 
63   ASSERT_EQ(static_cast<std::size_t>(1), chapter_display.countries.size());
64   EXPECT_TRUE(chapter_display.countries[0].is_present());
65   EXPECT_EQ("", chapter_display.countries[0].value());
66 }
67 
TEST_F(ChapterDisplayParserTest,CustomValues)68 TEST_F(ChapterDisplayParserTest, CustomValues) {
69   SetReaderData({
70       0x85,  // ID = 0x85 (ChapString).
71       0x40, 0x05,  // Size = 5.
72       0x68, 0x65, 0x6C, 0x6C, 0x6F,  // Body (value = "hello").
73 
74       0x43, 0x7C,  // ID = 0x437C (ChapLanguage).
75       0x85,  // Size = 5.
76       0x6C, 0x61, 0x6E, 0x67, 0x30,  // body (value = "lang0").
77 
78       0x43, 0x7E,  // ID = 0x437E (ChapCountry).
79       0x85,  // Size = 5.
80       0x61, 0x72, 0x65, 0x61, 0x30,  // Body (value = "area0").
81 
82       0x43, 0x7C,  // ID = 0x437C (ChapLanguage).
83       0x85,  // Size = 5.
84       0x6C, 0x61, 0x6E, 0x67, 0x31,  // body (value = "lang1").
85 
86       0x43, 0x7C,  // ID = 0x437C (ChapLanguage).
87       0x85,  // Size = 5.
88       0x6C, 0x61, 0x6E, 0x67, 0x32,  // body (value = "lang2").
89 
90       0x43, 0x7E,  // ID = 0x437E (ChapCountry).
91       0x85,  // Size = 5.
92       0x61, 0x72, 0x65, 0x61, 0x31,  // Body (value = "area1").
93   });
94 
95   ParseAndVerify();
96 
97   const ChapterDisplay chapter_display = parser_.value();
98 
99   EXPECT_TRUE(chapter_display.string.is_present());
100   EXPECT_EQ("hello", chapter_display.string.value());
101 
102   ASSERT_EQ(static_cast<std::size_t>(3), chapter_display.languages.size());
103   EXPECT_TRUE(chapter_display.languages[0].is_present());
104   EXPECT_EQ("lang0", chapter_display.languages[0].value());
105   EXPECT_TRUE(chapter_display.languages[1].is_present());
106   EXPECT_EQ("lang1", chapter_display.languages[1].value());
107   EXPECT_TRUE(chapter_display.languages[2].is_present());
108   EXPECT_EQ("lang2", chapter_display.languages[2].value());
109 
110   ASSERT_EQ(static_cast<std::size_t>(2), chapter_display.countries.size());
111   EXPECT_TRUE(chapter_display.countries[0].is_present());
112   EXPECT_EQ("area0", chapter_display.countries[0].value());
113   EXPECT_TRUE(chapter_display.countries[1].is_present());
114   EXPECT_EQ("area1", chapter_display.countries[1].value());
115 }
116 
117 }  // namespace
118