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_enc_aes_settings_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::AesSettingsCipherMode;
16 using webm::ContentEncAesSettings;
17 using webm::ContentEncAesSettingsParser;
18 using webm::ElementParserTest;
19 using webm::Id;
20 
21 namespace {
22 
23 class ContentEncAesSettingsParserTest
24     : public ElementParserTest<ContentEncAesSettingsParser,
25                                Id::kContentEncAesSettings> {};
26 
TEST_F(ContentEncAesSettingsParserTest,DefaultParse)27 TEST_F(ContentEncAesSettingsParserTest, DefaultParse) {
28   ParseAndVerify();
29 
30   const ContentEncAesSettings content_enc_aes_settings = parser_.value();
31 
32   EXPECT_FALSE(content_enc_aes_settings.aes_settings_cipher_mode.is_present());
33   EXPECT_EQ(AesSettingsCipherMode::kCtr,
34             content_enc_aes_settings.aes_settings_cipher_mode.value());
35 }
36 
TEST_F(ContentEncAesSettingsParserTest,DefaultValues)37 TEST_F(ContentEncAesSettingsParserTest, DefaultValues) {
38   SetReaderData({
39       0x47, 0xE8,  // ID = 0x47E8 (AESSettingsCipherMode).
40       0x80,  // Size = 0.
41   });
42 
43   ParseAndVerify();
44 
45   const ContentEncAesSettings content_enc_aes_settings = parser_.value();
46 
47   EXPECT_TRUE(content_enc_aes_settings.aes_settings_cipher_mode.is_present());
48   EXPECT_EQ(AesSettingsCipherMode::kCtr,
49             content_enc_aes_settings.aes_settings_cipher_mode.value());
50 }
51 
TEST_F(ContentEncAesSettingsParserTest,CustomValues)52 TEST_F(ContentEncAesSettingsParserTest, CustomValues) {
53   SetReaderData({
54       0x47, 0xE8,  // ID = 0x47E8 (AESSettingsCipherMode).
55       0x81,  // Size = 1.
56       0x00,  // Body (value = 0).
57   });
58 
59   ParseAndVerify();
60 
61   const ContentEncAesSettings content_enc_aes_settings = parser_.value();
62 
63   EXPECT_TRUE(content_enc_aes_settings.aes_settings_cipher_mode.is_present());
64   EXPECT_EQ(static_cast<AesSettingsCipherMode>(0),
65             content_enc_aes_settings.aes_settings_cipher_mode.value());
66 }
67 
68 }  // namespace
69