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" | |
| 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; | |
| 12 using ::testing::_; | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 class WebMWebVTTParserTest : public testing::Test { | |
| 17 public: | |
| 18 WebMWebVTTParserTest() {} | |
| 19 }; | |
| 20 | |
| 21 TEST_F(WebMWebVTTParserTest, TestBlank) { | |
| 22 InSequence s; | |
| 23 | |
| 24 const char* const str = "\n\nSubtitle"; | |
| 25 const uint8* const buf = reinterpret_cast<const uint8*>(str); | |
| 26 const int buflen = static_cast<int>(strlen(str)); | |
| 27 | |
| 28 std::string id, settings, content; | |
| 29 | |
| 30 WebMWebVTTParser::Parse(buf, buflen, &id, &settings, &content); | |
| 31 EXPECT_EQ(id, ""); | |
| 32 EXPECT_EQ(settings, ""); | |
| 33 EXPECT_EQ(content, "Subtitle"); | |
| 34 } | |
| 35 | |
| 36 TEST_F(WebMWebVTTParserTest, TestId) { | |
| 37 InSequence s; | |
| 38 | |
| 39 for (int i = 1; i <= 9; ++i) { | |
| 40 std::string strbuf; | |
| 41 | |
| 42 const char c = '0' + i; | |
| 43 strbuf += c; | |
| 44 | |
| 45 strbuf += "\n\nSubtitle"; | |
| 46 | |
| 47 const uint8* const buf = reinterpret_cast<const uint8*>(strbuf.data()); | |
| 48 const int buflen = static_cast<int>(strbuf.length()); | |
| 49 | |
| 50 std::string id, settings, content; | |
| 51 | |
| 52 WebMWebVTTParser::Parse(buf, buflen, &id, &settings, &content); | |
| 53 ASSERT_EQ(id.length(), 1); | |
| 54 EXPECT_EQ(id[0], c); | |
| 55 EXPECT_EQ(settings, ""); | |
| 56 EXPECT_EQ(content, "Subtitle"); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 TEST_F(WebMWebVTTParserTest, TestSettings) { | |
| 61 InSequence s; | |
| 62 | |
| 63 enum { kSettingsCount = 4 }; | |
| 64 const char* const settings_str[kSettingsCount] = { | |
| 65 "vertical:lr", | |
| 66 "line:50%", | |
| 67 "position:42%", | |
| 68 "vertical:rl line:42% position:100%" }; | |
| 69 | |
| 70 for (int i = 0; i < kSettingsCount; ++i) { | |
| 71 std::string strbuf; | |
| 72 | |
| 73 // blank id | |
| 74 strbuf += "\n"; | |
|
acolwell GONE FROM CHROMIUM
2013/05/15 22:42:36
nit: If you create a helper function along the lin
Matthew Heaney (Chromium)
2013/05/16 22:05:22
Done.
| |
| 75 | |
| 76 // settings | |
| 77 strbuf += settings_str[i]; | |
| 78 strbuf += "\n"; | |
| 79 | |
| 80 // content | |
| 81 strbuf += "Subtitle"; | |
| 82 | |
| 83 const uint8* const buf = reinterpret_cast<const uint8*>(strbuf.data()); | |
| 84 const int buflen = static_cast<int>(strbuf.length()); | |
| 85 | |
| 86 std::string id, settings, content; | |
| 87 | |
| 88 WebMWebVTTParser::Parse(buf, buflen, &id, &settings, &content); | |
| 89 EXPECT_EQ(id, ""); | |
| 90 EXPECT_EQ(settings, settings_str[i]); | |
| 91 EXPECT_EQ(content, "Subtitle"); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 TEST_F(WebMWebVTTParserTest, TestContent) { | |
| 96 InSequence s; | |
| 97 | |
| 98 enum { kContentCount = 4 }; | |
| 99 const char* const content_str[kContentCount] = { | |
| 100 "Subtitle", | |
| 101 "Another Subtitle", | |
| 102 "Yet Another Subtitle", | |
| 103 "Another Subtitle\nSplit Across Two Lines" }; | |
| 104 | |
| 105 for (int i = 0; i < kContentCount; ++i) { | |
| 106 std::string strbuf; | |
| 107 | |
| 108 // blank id | |
| 109 strbuf += "\n"; | |
| 110 | |
| 111 // blank settings | |
| 112 strbuf += "\n"; | |
| 113 | |
| 114 // content | |
| 115 strbuf += content_str[i]; | |
| 116 | |
| 117 const uint8* const buf = reinterpret_cast<const uint8*>(strbuf.data()); | |
| 118 const int buflen = static_cast<int>(strbuf.length()); | |
| 119 | |
| 120 std::string id, settings, content; | |
| 121 | |
| 122 WebMWebVTTParser::Parse(buf, buflen, &id, &settings, &content); | |
| 123 EXPECT_EQ(id, ""); | |
| 124 EXPECT_EQ(settings, ""); | |
| 125 EXPECT_EQ(content, content_str[i]); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 } // namespace media | |
| OLD | NEW |