Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: media/filters/ffmpeg_glue_unittest.cc

Issue 7658017: Revert 96974 - Remove mock_ffmpeg and update media unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/filters/ffmpeg_glue.cc ('k') | media/filters/ffmpeg_h264_bitstream_converter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "media/base/mock_ffmpeg.h"
7 #include "media/base/mock_filters.h" 8 #include "media/base/mock_filters.h"
8 #include "media/ffmpeg/ffmpeg_common.h" 9 #include "media/ffmpeg/ffmpeg_common.h"
9 #include "media/filters/ffmpeg_glue.h" 10 #include "media/filters/ffmpeg_glue.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 using ::testing::_; 13 using ::testing::_;
13 using ::testing::DoAll; 14 using ::testing::DoAll;
14 using ::testing::InSequence; 15 using ::testing::InSequence;
15 using ::testing::Return; 16 using ::testing::Return;
16 using ::testing::SetArgumentPointee; 17 using ::testing::SetArgumentPointee;
(...skipping 11 matching lines...) Expand all
28 MOCK_METHOD1(SetPosition, bool(int64 position)); 29 MOCK_METHOD1(SetPosition, bool(int64 position));
29 MOCK_METHOD1(GetSize, bool(int64* size_out)); 30 MOCK_METHOD1(GetSize, bool(int64* size_out));
30 MOCK_METHOD0(IsStreaming, bool()); 31 MOCK_METHOD0(IsStreaming, bool());
31 32
32 private: 33 private:
33 DISALLOW_COPY_AND_ASSIGN(MockProtocol); 34 DISALLOW_COPY_AND_ASSIGN(MockProtocol);
34 }; 35 };
35 36
36 class FFmpegGlueTest : public ::testing::Test { 37 class FFmpegGlueTest : public ::testing::Test {
37 public: 38 public:
38 FFmpegGlueTest() : protocol_(NULL) {} 39 FFmpegGlueTest() {}
39 40
40 static void SetUpTestCase() { 41 virtual void SetUp() {
41 // Singleton should initialize FFmpeg. 42 // Singleton should initialize FFmpeg.
42 CHECK(FFmpegGlue::GetInstance()); 43 CHECK(FFmpegGlue::GetInstance());
43 }
44 44
45 virtual void SetUp() {
46 // Assign our static copy of URLProtocol for the rest of the tests. 45 // Assign our static copy of URLProtocol for the rest of the tests.
47 protocol_ = FFmpegGlue::url_protocol(); 46 protocol_ = MockFFmpeg::protocol();
48 CHECK(protocol_); 47 CHECK(protocol_);
49 } 48 }
50 49
51 MOCK_METHOD1(CheckPoint, void(int val));
52
53 // Helper to open a URLContext pointing to the given mocked protocol. 50 // Helper to open a URLContext pointing to the given mocked protocol.
54 // Callers are expected to close the context at the end of their test. 51 // Callers are expected to close the context at the end of their test.
55 virtual void OpenContext(MockProtocol* protocol, URLContext* context) { 52 virtual void OpenContext(MockProtocol* protocol, URLContext* context) {
56 // IsStreaming() is called when opening. 53 // IsStreaming() is called when opening.
57 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); 54 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true));
58 55
59 // Add the protocol to the glue layer and open a context. 56 // Add the protocol to the glue layer and open a context.
60 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol); 57 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol);
61 memset(context, 0, sizeof(*context)); 58 memset(context, 0, sizeof(*context));
62 EXPECT_EQ(0, protocol_->url_open(context, key.c_str(), 0)); 59 EXPECT_EQ(0, protocol_->url_open(context, key.c_str(), 0));
63 FFmpegGlue::GetInstance()->RemoveProtocol(protocol); 60 FFmpegGlue::GetInstance()->RemoveProtocol(protocol);
64 } 61 }
65 62
66 protected: 63 protected:
67 // Fixture members. 64 // Fixture members.
68 URLProtocol* protocol_; 65 MockFFmpeg mock_ffmpeg_;
66 static URLProtocol* protocol_;
69 67
70 private: 68 private:
71 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueTest); 69 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueTest);
72 }; 70 };
73 71
72 URLProtocol* FFmpegGlueTest::protocol_ = NULL;
73
74 TEST_F(FFmpegGlueTest, InitializeFFmpeg) { 74 TEST_F(FFmpegGlueTest, InitializeFFmpeg) {
75 // Make sure URLProtocol was filled out correctly. 75 // Make sure URLProtocol was filled out correctly.
76 EXPECT_STREQ("http", protocol_->name); 76 EXPECT_STREQ("http", protocol_->name);
77 EXPECT_TRUE(protocol_->url_close); 77 EXPECT_TRUE(protocol_->url_close);
78 EXPECT_TRUE(protocol_->url_open); 78 EXPECT_TRUE(protocol_->url_open);
79 EXPECT_TRUE(protocol_->url_read); 79 EXPECT_TRUE(protocol_->url_read);
80 EXPECT_TRUE(protocol_->url_seek); 80 EXPECT_TRUE(protocol_->url_seek);
81 EXPECT_TRUE(protocol_->url_write); 81 EXPECT_TRUE(protocol_->url_write);
82 } 82 }
83 83
(...skipping 27 matching lines...) Expand all
111 std::string key_a2 = glue->AddProtocol(protocol_a.get()); 111 std::string key_a2 = glue->AddProtocol(protocol_a.get());
112 EXPECT_EQ(key_a, key_a2); 112 EXPECT_EQ(key_a, key_a2);
113 glue->GetProtocol(key_a2, &protocol_c); 113 glue->GetProtocol(key_a2, &protocol_c);
114 EXPECT_EQ(protocol_a.get(), protocol_c); 114 EXPECT_EQ(protocol_a.get(), protocol_c);
115 115
116 // Removes the protocols then releases our references. They should be 116 // Removes the protocols then releases our references. They should be
117 // destroyed. 117 // destroyed.
118 InSequence s; 118 InSequence s;
119 EXPECT_CALL(*protocol_a, OnDestroy()); 119 EXPECT_CALL(*protocol_a, OnDestroy());
120 EXPECT_CALL(*protocol_b, OnDestroy()); 120 EXPECT_CALL(*protocol_b, OnDestroy());
121 EXPECT_CALL(*this, CheckPoint(0)); 121 EXPECT_CALL(mock_ffmpeg_, CheckPoint(0));
122 122
123 glue->RemoveProtocol(protocol_a.get()); 123 glue->RemoveProtocol(protocol_a.get());
124 glue->GetProtocol(key_a, &protocol_c); 124 glue->GetProtocol(key_a, &protocol_c);
125 EXPECT_FALSE(protocol_c); 125 EXPECT_FALSE(protocol_c);
126 glue->GetProtocol(key_b, &protocol_d); 126 glue->GetProtocol(key_b, &protocol_d);
127 EXPECT_EQ(protocol_b.get(), protocol_d); 127 EXPECT_EQ(protocol_b.get(), protocol_d);
128 glue->RemoveProtocol(protocol_b.get()); 128 glue->RemoveProtocol(protocol_b.get());
129 glue->GetProtocol(key_b, &protocol_d); 129 glue->GetProtocol(key_b, &protocol_d);
130 EXPECT_FALSE(protocol_d); 130 EXPECT_FALSE(protocol_d);
131 protocol_a.reset(); 131 protocol_a.reset();
132 protocol_b.reset(); 132 protocol_b.reset();
133 133
134 // Data sources should be deleted by this point. 134 // Data sources should be deleted by this point.
135 CheckPoint(0); 135 mock_ffmpeg_.CheckPoint(0);
136 } 136 }
137 137
138 TEST_F(FFmpegGlueTest, OpenClose) { 138 TEST_F(FFmpegGlueTest, OpenClose) {
139 // Prepare testing data. 139 // Prepare testing data.
140 FFmpegGlue* glue = FFmpegGlue::GetInstance(); 140 FFmpegGlue* glue = FFmpegGlue::GetInstance();
141 141
142 // Create our protocol and add them to the glue layer. 142 // Create our protocol and add them to the glue layer.
143 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( 143 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol(
144 new StrictMock<Destroyable<MockProtocol> >()); 144 new StrictMock<Destroyable<MockProtocol> >());
145 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); 145 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true));
146 std::string key = glue->AddProtocol(protocol.get()); 146 std::string key = glue->AddProtocol(protocol.get());
147 147
148 // Prepare FFmpeg URLContext structure. 148 // Prepare FFmpeg URLContext structure.
149 URLContext context; 149 URLContext context;
150 memset(&context, 0, sizeof(context)); 150 memset(&context, 0, sizeof(context));
151 151
152 // Test opening a URLContext with a protocol that doesn't exist. 152 // Test opening a URLContext with a protocol that doesn't exist.
153 EXPECT_EQ(AVERROR(EIO), protocol_->url_open(&context, "foobar", 0)); 153 EXPECT_EQ(AVERROR(EIO), protocol_->url_open(&context, "foobar", 0));
154 154
155 // Test opening a URLContext with our protocol. 155 // Test opening a URLContext with our protocol.
156 EXPECT_EQ(0, protocol_->url_open(&context, key.c_str(), 0)); 156 EXPECT_EQ(0, protocol_->url_open(&context, key.c_str(), 0));
157 EXPECT_EQ(URL_RDONLY, context.flags); 157 EXPECT_EQ(URL_RDONLY, context.flags);
158 EXPECT_EQ(protocol.get(), context.priv_data); 158 EXPECT_EQ(protocol.get(), context.priv_data);
159 EXPECT_TRUE(context.is_streamed); 159 EXPECT_TRUE(context.is_streamed);
160 160
161 // We're going to remove references one by one until the last reference is 161 // We're going to remove references one by one until the last reference is
162 // held by FFmpeg. Once we close the URLContext, the protocol should be 162 // held by FFmpeg. Once we close the URLContext, the protocol should be
163 // destroyed. 163 // destroyed.
164 InSequence s; 164 InSequence s;
165 EXPECT_CALL(*this, CheckPoint(0)); 165 EXPECT_CALL(mock_ffmpeg_, CheckPoint(0));
166 EXPECT_CALL(*this, CheckPoint(1)); 166 EXPECT_CALL(mock_ffmpeg_, CheckPoint(1));
167 EXPECT_CALL(*protocol, OnDestroy()); 167 EXPECT_CALL(*protocol, OnDestroy());
168 EXPECT_CALL(*this, CheckPoint(2)); 168 EXPECT_CALL(mock_ffmpeg_, CheckPoint(2));
169 169
170 // Remove the protocol from the glue layer, releasing a reference. 170 // Remove the protocol from the glue layer, releasing a reference.
171 glue->RemoveProtocol(protocol.get()); 171 glue->RemoveProtocol(protocol.get());
172 CheckPoint(0); 172 mock_ffmpeg_.CheckPoint(0);
173 173
174 // Remove our own reference -- URLContext should maintain a reference. 174 // Remove our own reference -- URLContext should maintain a reference.
175 CheckPoint(1); 175 mock_ffmpeg_.CheckPoint(1);
176 protocol.reset(); 176 protocol.reset();
177 177
178 // Close the URLContext, which should release the final reference. 178 // Close the URLContext, which should release the final reference.
179 EXPECT_EQ(0, protocol_->url_close(&context)); 179 EXPECT_EQ(0, protocol_->url_close(&context));
180 CheckPoint(2); 180 mock_ffmpeg_.CheckPoint(2);
181 } 181 }
182 182
183 TEST_F(FFmpegGlueTest, Write) { 183 TEST_F(FFmpegGlueTest, Write) {
184 scoped_ptr<StrictMock<MockProtocol> > protocol( 184 scoped_ptr<StrictMock<MockProtocol> > protocol(
185 new StrictMock<MockProtocol>()); 185 new StrictMock<MockProtocol>());
186 URLContext context; 186 URLContext context;
187 OpenContext(protocol.get(), &context); 187 OpenContext(protocol.get(), &context);
188 188
189 const int kBufferSize = 16; 189 const int kBufferSize = 16;
190 uint8 buffer[kBufferSize]; 190 uint8 buffer[kBufferSize];
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 302
303 TEST_F(FFmpegGlueTest, Destroy) { 303 TEST_F(FFmpegGlueTest, Destroy) {
304 // Create our protocol and add them to the glue layer. 304 // Create our protocol and add them to the glue layer.
305 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( 305 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol(
306 new StrictMock<Destroyable<MockProtocol> >()); 306 new StrictMock<Destroyable<MockProtocol> >());
307 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol.get()); 307 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol.get());
308 308
309 // We should expect the protocol to get destroyed when the unit test 309 // We should expect the protocol to get destroyed when the unit test
310 // exits. 310 // exits.
311 InSequence s; 311 InSequence s;
312 EXPECT_CALL(*this, CheckPoint(0)); 312 EXPECT_CALL(mock_ffmpeg_, CheckPoint(0));
313 EXPECT_CALL(*protocol, OnDestroy()); 313 EXPECT_CALL(*protocol, OnDestroy());
314 314
315 // Remove our own reference, we shouldn't be destroyed yet. 315 // Remove our own reference, we shouldn't be destroyed yet.
316 CheckPoint(0); 316 mock_ffmpeg_.CheckPoint(0);
317 protocol.reset(); 317 protocol.reset();
318 318
319 // ~FFmpegGlue() will be called when this unit test finishes execution. By 319 // ~FFmpegGlue() will be called when this unit test finishes execution. By
320 // leaving something inside FFmpegGlue's map we get to test our cleanup code. 320 // leaving something inside FFmpegGlue's map we get to test our cleanup code.
321 } 321 }
322 322
323 } // namespace media 323 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_glue.cc ('k') | media/filters/ffmpeg_h264_bitstream_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698