Chromium Code Reviews| Index: media/webm/webm_webvtt_parser_unittest.cc |
| diff --git a/media/webm/webm_webvtt_parser_unittest.cc b/media/webm/webm_webvtt_parser_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f0a020b457b8729d56ff2ae9b106fe63f2fe180 |
| --- /dev/null |
| +++ b/media/webm/webm_webvtt_parser_unittest.cc |
| @@ -0,0 +1,115 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +//#include "base/logging.h" |
|
acolwell GONE FROM CHROMIUM
2013/05/17 16:32:08
nit: Remove
Matthew Heaney (Chromium)
2013/05/18 01:35:48
Done.
|
| +#include "media/webm/webm_webvtt_parser.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using ::testing::InSequence; |
| +using ::testing::Return; |
|
acolwell GONE FROM CHROMIUM
2013/05/17 16:32:08
nit: I don't think this or the line below is neede
Matthew Heaney (Chromium)
2013/05/18 01:35:48
Done.
|
| +using ::testing::_; |
| + |
| +namespace media { |
| + |
| +typedef std::vector<uint8> Cue; |
| + |
| +static Cue EncodeCue(const std::string& id, |
| + const std::string& settings, |
| + const std::string& content) { |
| + const std::string result = id + '\n' + settings + '\n' + content; |
| + |
| + const uint8* const buf = reinterpret_cast<const uint8*>(result.data()); |
| + const Cue::size_type buflen = Cue::size_type(result.length()); |
|
acolwell GONE FROM CHROMIUM
2013/05/17 16:32:08
nit: You should just use "buf + result.length()" i
Matthew Heaney (Chromium)
2013/05/18 01:35:48
Done.
|
| + |
| + return Cue(buf, buf + buflen); |
| +} |
| + |
| +static void DecodeCue(const Cue& cue, |
| + std::string* id, |
| + std::string* settings, |
| + std::string* content) { |
| + const uint8* const buf = &cue[0]; |
|
acolwell GONE FROM CHROMIUM
2013/05/17 16:32:08
nit: Inline these.
Matthew Heaney (Chromium)
2013/05/18 01:35:48
Done.
|
| + const int len = static_cast<int>(cue.size()); |
| + WebMWebVTTParser::Parse(buf, len, id, settings, content); |
| +} |
| + |
| +class WebMWebVTTParserTest : public testing::Test { |
| + public: |
| + WebMWebVTTParserTest() {} |
| +}; |
| + |
| +TEST_F(WebMWebVTTParserTest, TestBlank) { |
| + InSequence s; |
| + |
| + const Cue cue = EncodeCue("", "", "Subtitle"); |
| + std::string id, settings, content; |
| + |
| + DecodeCue(cue, &id, &settings, &content); |
| + EXPECT_EQ(id, ""); |
| + EXPECT_EQ(settings, ""); |
| + EXPECT_EQ(content, "Subtitle"); |
| +} |
| + |
| +TEST_F(WebMWebVTTParserTest, TestId) { |
| + InSequence s; |
| + |
| + for (int i = 1; i <= 9; ++i) { |
| + const char c = '0' + i; |
|
acolwell GONE FROM CHROMIUM
2013/05/17 16:32:08
nit: inline
Matthew Heaney (Chromium)
2013/05/18 01:35:48
Done.
|
| + const std::string idsrc(1, c); |
| + |
| + const Cue cue = EncodeCue(idsrc, "", "Subtitle"); |
| + std::string id, settings, content; |
| + |
| + DecodeCue(cue, &id, &settings, &content); |
| + ASSERT_EQ(id.length(), 1); |
| + EXPECT_EQ(id[0], c); |
|
acolwell GONE FROM CHROMIUM
2013/05/17 16:32:08
nit: Just compare id to idsrc instead of using the
Matthew Heaney (Chromium)
2013/05/18 01:35:48
Done.
|
| + EXPECT_EQ(settings, ""); |
| + EXPECT_EQ(content, "Subtitle"); |
| + } |
| +} |
| + |
| +TEST_F(WebMWebVTTParserTest, TestSettings) { |
| + InSequence s; |
| + |
| + enum { kSettingsCount = 4 }; |
| + const char* const settings_str[kSettingsCount] = { |
| + "vertical:lr", |
| + "line:50%", |
| + "position:42%", |
| + "vertical:rl line:42% position:100%" }; |
| + |
| + for (int i = 0; i < kSettingsCount; ++i) { |
| + const Cue cue = EncodeCue("", settings_str[i], "Subtitle"); |
| + std::string id, settings, content; |
| + |
| + DecodeCue(cue, &id, &settings, &content); |
| + EXPECT_EQ(id, ""); |
| + EXPECT_EQ(settings, settings_str[i]); |
| + EXPECT_EQ(content, "Subtitle"); |
| + } |
| +} |
| + |
| +TEST_F(WebMWebVTTParserTest, TestContent) { |
| + InSequence s; |
| + |
| + enum { kContentCount = 4 }; |
| + const char* const content_str[kContentCount] = { |
| + "Subtitle", |
| + "Another Subtitle", |
| + "Yet Another Subtitle", |
| + "Another Subtitle\nSplit Across Two Lines" }; |
| + |
| + for (int i = 0; i < kContentCount; ++i) { |
| + const Cue cue = EncodeCue("", "", content_str[i]); |
| + std::string id, settings, content; |
| + |
| + DecodeCue(cue, &id, &settings, &content); |
| + EXPECT_EQ(id, ""); |
| + EXPECT_EQ(settings, ""); |
| + EXPECT_EQ(content, content_str[i]); |
| + } |
| +} |
| + |
| +} // namespace media |