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/content_encodings_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::ContentEncoding;
16 using webm::ContentEncodings;
17 using webm::ContentEncodingsParser;
18 using webm::ElementParserTest;
19 using webm::Id;
20
21 namespace {
22
23 class ContentEncodingsParserTest
24 : public ElementParserTest<ContentEncodingsParser, Id::kContentEncodings> {
25 };
26
TEST_F(ContentEncodingsParserTest,DefaultParse)27 TEST_F(ContentEncodingsParserTest, DefaultParse) {
28 ParseAndVerify();
29
30 const ContentEncodings content_encodings = parser_.value();
31
32 EXPECT_EQ(static_cast<std::size_t>(0), content_encodings.encodings.size());
33 }
34
TEST_F(ContentEncodingsParserTest,DefaultValues)35 TEST_F(ContentEncodingsParserTest, DefaultValues) {
36 SetReaderData({
37 0x62, 0x40, // ID = 0x6240 (ContentEncoding).
38 0x80, // Size = 0.
39 });
40
41 ParseAndVerify();
42
43 const ContentEncodings content_encodings = parser_.value();
44
45 ASSERT_EQ(static_cast<std::size_t>(1), content_encodings.encodings.size());
46 EXPECT_TRUE(content_encodings.encodings[0].is_present());
47 EXPECT_EQ(ContentEncoding{}, content_encodings.encodings[0].value());
48 }
49
TEST_F(ContentEncodingsParserTest,CustomValues)50 TEST_F(ContentEncodingsParserTest, CustomValues) {
51 SetReaderData({
52 0x62, 0x40, // ID = 0x6240 (ContentEncoding).
53 0x84, // Size = 4.
54
55 0x50, 0x31, // ID = 0x5031 (ContentEncodingOrder).
56 0x81, // Size = 1.
57 0x01, // Body (value = 1).
58
59 0x62, 0x40, // ID = 0x6240 (ContentEncoding).
60 0x84, // Size = 4.
61
62 0x50, 0x31, // ID = 0x5031 (ContentEncodingOrder).
63 0x81, // Size = 1.
64 0x02, // Body (value = 2).
65 });
66
67 ParseAndVerify();
68
69 const ContentEncodings content_encodings = parser_.value();
70
71 ContentEncoding expected;
72
73 ASSERT_EQ(static_cast<std::size_t>(2), content_encodings.encodings.size());
74 expected.order.Set(1, true);
75 EXPECT_TRUE(content_encodings.encodings[0].is_present());
76 EXPECT_EQ(expected, content_encodings.encodings[0].value());
77 expected.order.Set(2, true);
78 EXPECT_TRUE(content_encodings.encodings[1].is_present());
79 EXPECT_EQ(expected, content_encodings.encodings[1].value());
80 }
81
82 } // namespace
83