1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/webm/webm_webvtt_parser.h"
6 #include "testing/gmock/include/gmock/gmock.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 using ::testing::InSequence
;
13 typedef std::vector
<uint8
> Cue
;
15 static Cue
EncodeCue(const std::string
& id
,
16 const std::string
& settings
,
17 const std::string
& content
) {
18 const std::string result
= id
+ '\n' + settings
+ '\n' + content
;
19 const uint8
* const buf
= reinterpret_cast<const uint8
*>(result
.data());
20 return Cue(buf
, buf
+ result
.length());
23 static void DecodeCue(const Cue
& cue
,
25 std::string
* settings
,
26 std::string
* content
) {
27 WebMWebVTTParser::Parse(&cue
[0], static_cast<int>(cue
.size()),
28 id
, settings
, content
);
31 class WebMWebVTTParserTest
: public testing::Test
{
33 WebMWebVTTParserTest() {}
36 TEST_F(WebMWebVTTParserTest
, Blank
) {
39 const Cue cue
= EncodeCue("", "", "Subtitle");
40 std::string id
, settings
, content
;
42 DecodeCue(cue
, &id
, &settings
, &content
);
44 EXPECT_EQ(settings
, "");
45 EXPECT_EQ(content
, "Subtitle");
48 TEST_F(WebMWebVTTParserTest
, Id
) {
51 for (int i
= 1; i
<= 9; ++i
) {
52 const std::string
idsrc(1, '0'+i
);
53 const Cue cue
= EncodeCue(idsrc
, "", "Subtitle");
54 std::string id
, settings
, content
;
56 DecodeCue(cue
, &id
, &settings
, &content
);
58 EXPECT_EQ(settings
, "");
59 EXPECT_EQ(content
, "Subtitle");
63 TEST_F(WebMWebVTTParserTest
, Settings
) {
66 enum { kSettingsCount
= 4 };
67 const char* const settings_str
[kSettingsCount
] = {
71 "vertical:rl line:42% position:100%" };
73 for (int i
= 0; i
< kSettingsCount
; ++i
) {
74 const Cue cue
= EncodeCue("", settings_str
[i
], "Subtitle");
75 std::string id
, settings
, content
;
77 DecodeCue(cue
, &id
, &settings
, &content
);
79 EXPECT_EQ(settings
, settings_str
[i
]);
80 EXPECT_EQ(content
, "Subtitle");
84 TEST_F(WebMWebVTTParserTest
, Content
) {
87 enum { kContentCount
= 4 };
88 const char* const content_str
[kContentCount
] = {
91 "Yet Another Subtitle",
92 "Another Subtitle\nSplit Across Two Lines" };
94 for (int i
= 0; i
< kContentCount
; ++i
) {
95 const Cue cue
= EncodeCue("", "", content_str
[i
]);
96 std::string id
, settings
, content
;
98 DecodeCue(cue
, &id
, &settings
, &content
);
100 EXPECT_EQ(settings
, "");
101 EXPECT_EQ(content
, content_str
[i
]);