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/targets_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::Targets;
18 using webm::TargetsParser;
19
20 namespace {
21
22 class TargetsParserTest
23 : public ElementParserTest<TargetsParser, Id::kTargets> {};
24
TEST_F(TargetsParserTest,DefaultParse)25 TEST_F(TargetsParserTest, DefaultParse) {
26 ParseAndVerify();
27
28 const Targets targets = parser_.value();
29
30 EXPECT_FALSE(targets.type_value.is_present());
31 EXPECT_EQ(static_cast<std::uint64_t>(50), targets.type_value.value());
32
33 EXPECT_FALSE(targets.type.is_present());
34 EXPECT_EQ("", targets.type.value());
35
36 EXPECT_EQ(static_cast<std::size_t>(0), targets.track_uids.size());
37 }
38
TEST_F(TargetsParserTest,DefaultValues)39 TEST_F(TargetsParserTest, DefaultValues) {
40 SetReaderData({
41 0x68, 0xCA, // ID = 0x68CA (TargetTypeValue).
42 0x80, // Size = 0.
43
44 0x63, 0xCA, // ID = 0x63CA (TargetType).
45 0x80, // Size = 0.
46
47 0x63, 0xC5, // ID = 0x63C5 (TagTrackUID).
48 0x80, // Size = 0.
49 });
50
51 ParseAndVerify();
52
53 const Targets targets = parser_.value();
54
55 EXPECT_TRUE(targets.type_value.is_present());
56 EXPECT_EQ(static_cast<std::uint64_t>(50), targets.type_value.value());
57
58 EXPECT_TRUE(targets.type.is_present());
59 EXPECT_EQ("", targets.type.value());
60
61 ASSERT_EQ(static_cast<std::size_t>(1), targets.track_uids.size());
62 EXPECT_TRUE(targets.track_uids[0].is_present());
63 EXPECT_EQ(static_cast<std::uint64_t>(0), targets.track_uids[0].value());
64 }
65
TEST_F(TargetsParserTest,CustomValues)66 TEST_F(TargetsParserTest, CustomValues) {
67 SetReaderData({
68 0x68, 0xCA, // ID = 0x68CA (TargetTypeValue).
69 0x81, // Size = 1.
70 0x00, // Body (value = 0).
71
72 0x63, 0xCA, // ID = 0x63CA (TargetType).
73 0x82, // Size = 2.
74 0x48, 0x69, // Body (value = "Hi").
75
76 0x63, 0xC5, // ID = 0x63C5 (TagTrackUID).
77 0x81, // Size = 1.
78 0x01, // Body (value = 1).
79
80 0x63, 0xC5, // ID = 0x63C5 (TagTrackUID).
81 0x81, // Size = 1.
82 0x02, // Body (value = 2).
83 });
84
85 ParseAndVerify();
86
87 const Targets targets = parser_.value();
88
89 EXPECT_TRUE(targets.type_value.is_present());
90 EXPECT_EQ(static_cast<std::uint64_t>(0), targets.type_value.value());
91
92 EXPECT_TRUE(targets.type.is_present());
93 EXPECT_EQ("Hi", targets.type.value());
94
95 ASSERT_EQ(static_cast<std::size_t>(2), targets.track_uids.size());
96 EXPECT_TRUE(targets.track_uids[0].is_present());
97 EXPECT_EQ(static_cast<std::uint64_t>(1), targets.track_uids[0].value());
98 EXPECT_TRUE(targets.track_uids[1].is_present());
99 EXPECT_EQ(static_cast<std::uint64_t>(2), targets.track_uids[1].value());
100 }
101
102 } // namespace
103