Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 //#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.
| |
| 6 #include "media/webm/webm_webvtt_parser.h" | |
| 7 #include "testing/gmock/include/gmock/gmock.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 using ::testing::InSequence; | |
| 11 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.
| |
| 12 using ::testing::_; | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 typedef std::vector<uint8> Cue; | |
| 17 | |
| 18 static Cue EncodeCue(const std::string& id, | |
| 19 const std::string& settings, | |
| 20 const std::string& content) { | |
| 21 const std::string result = id + '\n' + settings + '\n' + content; | |
| 22 | |
| 23 const uint8* const buf = reinterpret_cast<const uint8*>(result.data()); | |
| 24 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.
| |
| 25 | |
| 26 return Cue(buf, buf + buflen); | |
| 27 } | |
| 28 | |
| 29 static void DecodeCue(const Cue& cue, | |
| 30 std::string* id, | |
| 31 std::string* settings, | |
| 32 std::string* content) { | |
| 33 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.
| |
| 34 const int len = static_cast<int>(cue.size()); | |
| 35 WebMWebVTTParser::Parse(buf, len, id, settings, content); | |
| 36 } | |
| 37 | |
| 38 class WebMWebVTTParserTest : public testing::Test { | |
| 39 public: | |
| 40 WebMWebVTTParserTest() {} | |
| 41 }; | |
| 42 | |
| 43 TEST_F(WebMWebVTTParserTest, TestBlank) { | |
| 44 InSequence s; | |
| 45 | |
| 46 const Cue cue = EncodeCue("", "", "Subtitle"); | |
| 47 std::string id, settings, content; | |
| 48 | |
| 49 DecodeCue(cue, &id, &settings, &content); | |
| 50 EXPECT_EQ(id, ""); | |
| 51 EXPECT_EQ(settings, ""); | |
| 52 EXPECT_EQ(content, "Subtitle"); | |
| 53 } | |
| 54 | |
| 55 TEST_F(WebMWebVTTParserTest, TestId) { | |
| 56 InSequence s; | |
| 57 | |
| 58 for (int i = 1; i <= 9; ++i) { | |
| 59 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.
| |
| 60 const std::string idsrc(1, c); | |
| 61 | |
| 62 const Cue cue = EncodeCue(idsrc, "", "Subtitle"); | |
| 63 std::string id, settings, content; | |
| 64 | |
| 65 DecodeCue(cue, &id, &settings, &content); | |
| 66 ASSERT_EQ(id.length(), 1); | |
| 67 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.
| |
| 68 EXPECT_EQ(settings, ""); | |
| 69 EXPECT_EQ(content, "Subtitle"); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 TEST_F(WebMWebVTTParserTest, TestSettings) { | |
| 74 InSequence s; | |
| 75 | |
| 76 enum { kSettingsCount = 4 }; | |
| 77 const char* const settings_str[kSettingsCount] = { | |
| 78 "vertical:lr", | |
| 79 "line:50%", | |
| 80 "position:42%", | |
| 81 "vertical:rl line:42% position:100%" }; | |
| 82 | |
| 83 for (int i = 0; i < kSettingsCount; ++i) { | |
| 84 const Cue cue = EncodeCue("", settings_str[i], "Subtitle"); | |
| 85 std::string id, settings, content; | |
| 86 | |
| 87 DecodeCue(cue, &id, &settings, &content); | |
| 88 EXPECT_EQ(id, ""); | |
| 89 EXPECT_EQ(settings, settings_str[i]); | |
| 90 EXPECT_EQ(content, "Subtitle"); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 TEST_F(WebMWebVTTParserTest, TestContent) { | |
| 95 InSequence s; | |
| 96 | |
| 97 enum { kContentCount = 4 }; | |
| 98 const char* const content_str[kContentCount] = { | |
| 99 "Subtitle", | |
| 100 "Another Subtitle", | |
| 101 "Yet Another Subtitle", | |
| 102 "Another Subtitle\nSplit Across Two Lines" }; | |
| 103 | |
| 104 for (int i = 0; i < kContentCount; ++i) { | |
| 105 const Cue cue = EncodeCue("", "", content_str[i]); | |
| 106 std::string id, settings, content; | |
| 107 | |
| 108 DecodeCue(cue, &id, &settings, &content); | |
| 109 EXPECT_EQ(id, ""); | |
| 110 EXPECT_EQ(settings, ""); | |
| 111 EXPECT_EQ(content, content_str[i]); | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 } // namespace media | |
| OLD | NEW |