Chromium Code Reviews

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

Issue 5581008: Add a new GetInstance() method for singleton classes, take 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
7 #include "media/base/mock_ffmpeg.h" 7 #include "media/base/mock_ffmpeg.h"
8 #include "media/base/mock_filters.h" 8 #include "media/base/mock_filters.h"
9 #include "media/ffmpeg/ffmpeg_common.h" 9 #include "media/ffmpeg/ffmpeg_common.h"
10 #include "media/filters/ffmpeg_glue.h" 10 #include "media/filters/ffmpeg_glue.h"
(...skipping 25 matching lines...)
36 36
37 class FFmpegGlueTest : public ::testing::Test { 37 class FFmpegGlueTest : public ::testing::Test {
38 public: 38 public:
39 FFmpegGlueTest() { 39 FFmpegGlueTest() {
40 } 40 }
41 41
42 virtual void SetUp() { 42 virtual void SetUp() {
43 MockFFmpeg::set(&mock_ffmpeg_); 43 MockFFmpeg::set(&mock_ffmpeg_);
44 44
45 // Singleton should initialize FFmpeg. 45 // Singleton should initialize FFmpeg.
46 CHECK(FFmpegGlue::get()); 46 CHECK(FFmpegGlue::GetInstance());
47 47
48 // Assign our static copy of URLProtocol for the rest of the tests. 48 // Assign our static copy of URLProtocol for the rest of the tests.
49 protocol_ = MockFFmpeg::protocol(); 49 protocol_ = MockFFmpeg::protocol();
50 CHECK(protocol_); 50 CHECK(protocol_);
51 } 51 }
52 52
53 virtual void TearDown() { 53 virtual void TearDown() {
54 MockFFmpeg::set(NULL); 54 MockFFmpeg::set(NULL);
55 } 55 }
56 56
57 // Helper to open a URLContext pointing to the given mocked protocol. 57 // Helper to open a URLContext pointing to the given mocked protocol.
58 // Callers are expected to close the context at the end of their test. 58 // Callers are expected to close the context at the end of their test.
59 virtual void OpenContext(MockProtocol* protocol, URLContext* context) { 59 virtual void OpenContext(MockProtocol* protocol, URLContext* context) {
60 // IsStreaming() is called when opening. 60 // IsStreaming() is called when opening.
61 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); 61 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true));
62 62
63 // Add the protocol to the glue layer and open a context. 63 // Add the protocol to the glue layer and open a context.
64 std::string key = FFmpegGlue::get()->AddProtocol(protocol); 64 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol);
65 memset(context, 0, sizeof(*context)); 65 memset(context, 0, sizeof(*context));
66 EXPECT_EQ(0, protocol_->url_open(context, key.c_str(), 0)); 66 EXPECT_EQ(0, protocol_->url_open(context, key.c_str(), 0));
67 FFmpegGlue::get()->RemoveProtocol(protocol); 67 FFmpegGlue::GetInstance()->RemoveProtocol(protocol);
68 } 68 }
69 69
70 protected: 70 protected:
71 // Fixture members. 71 // Fixture members.
72 MockFFmpeg mock_ffmpeg_; 72 MockFFmpeg mock_ffmpeg_;
73 static URLProtocol* protocol_; 73 static URLProtocol* protocol_;
74 74
75 private: 75 private:
76 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueTest); 76 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueTest);
77 }; 77 };
78 78
79 URLProtocol* FFmpegGlueTest::protocol_ = NULL; 79 URLProtocol* FFmpegGlueTest::protocol_ = NULL;
80 80
81 TEST_F(FFmpegGlueTest, InitializeFFmpeg) { 81 TEST_F(FFmpegGlueTest, InitializeFFmpeg) {
82 // Make sure URLProtocol was filled out correctly. 82 // Make sure URLProtocol was filled out correctly.
83 EXPECT_STREQ("http", protocol_->name); 83 EXPECT_STREQ("http", protocol_->name);
84 EXPECT_TRUE(protocol_->url_close); 84 EXPECT_TRUE(protocol_->url_close);
85 EXPECT_TRUE(protocol_->url_open); 85 EXPECT_TRUE(protocol_->url_open);
86 EXPECT_TRUE(protocol_->url_read); 86 EXPECT_TRUE(protocol_->url_read);
87 EXPECT_TRUE(protocol_->url_seek); 87 EXPECT_TRUE(protocol_->url_seek);
88 EXPECT_TRUE(protocol_->url_write); 88 EXPECT_TRUE(protocol_->url_write);
89 } 89 }
90 90
91 TEST_F(FFmpegGlueTest, AddRemoveGetProtocol) { 91 TEST_F(FFmpegGlueTest, AddRemoveGetProtocol) {
92 // Prepare testing data. 92 // Prepare testing data.
93 FFmpegGlue* glue = FFmpegGlue::get(); 93 FFmpegGlue* glue = FFmpegGlue::GetInstance();
94 94
95 // Create our protocols and add them to the glue layer. 95 // Create our protocols and add them to the glue layer.
96 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol_a( 96 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol_a(
97 new StrictMock<Destroyable<MockProtocol> >()); 97 new StrictMock<Destroyable<MockProtocol> >());
98 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol_b( 98 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol_b(
99 new StrictMock<Destroyable<MockProtocol> >()); 99 new StrictMock<Destroyable<MockProtocol> >());
100 100
101 // Make sure the keys are unique. 101 // Make sure the keys are unique.
102 std::string key_a = glue->AddProtocol(protocol_a.get()); 102 std::string key_a = glue->AddProtocol(protocol_a.get());
103 std::string key_b = glue->AddProtocol(protocol_b.get()); 103 std::string key_b = glue->AddProtocol(protocol_b.get());
(...skipping 33 matching lines...)
137 EXPECT_FALSE(protocol_d); 137 EXPECT_FALSE(protocol_d);
138 protocol_a.reset(); 138 protocol_a.reset();
139 protocol_b.reset(); 139 protocol_b.reset();
140 140
141 // Data sources should be deleted by this point. 141 // Data sources should be deleted by this point.
142 mock_ffmpeg_.CheckPoint(0); 142 mock_ffmpeg_.CheckPoint(0);
143 } 143 }
144 144
145 TEST_F(FFmpegGlueTest, OpenClose) { 145 TEST_F(FFmpegGlueTest, OpenClose) {
146 // Prepare testing data. 146 // Prepare testing data.
147 FFmpegGlue* glue = FFmpegGlue::get(); 147 FFmpegGlue* glue = FFmpegGlue::GetInstance();
148 148
149 // Create our protocol and add them to the glue layer. 149 // Create our protocol and add them to the glue layer.
150 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( 150 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol(
151 new StrictMock<Destroyable<MockProtocol> >()); 151 new StrictMock<Destroyable<MockProtocol> >());
152 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); 152 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true));
153 std::string key = glue->AddProtocol(protocol.get()); 153 std::string key = glue->AddProtocol(protocol.get());
154 154
155 // Prepare FFmpeg URLContext structure. 155 // Prepare FFmpeg URLContext structure.
156 URLContext context; 156 URLContext context;
157 memset(&context, 0, sizeof(context)); 157 memset(&context, 0, sizeof(context));
(...skipping 146 matching lines...)
304 EXPECT_EQ(16, protocol_->url_seek(&context, 0, AVSEEK_SIZE)); 304 EXPECT_EQ(16, protocol_->url_seek(&context, 0, AVSEEK_SIZE));
305 305
306 // Destroy the protocol. 306 // Destroy the protocol.
307 protocol_->url_close(&context); 307 protocol_->url_close(&context);
308 } 308 }
309 309
310 TEST_F(FFmpegGlueTest, Destroy) { 310 TEST_F(FFmpegGlueTest, Destroy) {
311 // Create our protocol and add them to the glue layer. 311 // Create our protocol and add them to the glue layer.
312 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( 312 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol(
313 new StrictMock<Destroyable<MockProtocol> >()); 313 new StrictMock<Destroyable<MockProtocol> >());
314 std::string key = FFmpegGlue::get()->AddProtocol(protocol.get()); 314 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol.get());
315 315
316 // We should expect the protocol to get destroyed when the unit test 316 // We should expect the protocol to get destroyed when the unit test
317 // exits. 317 // exits.
318 InSequence s; 318 InSequence s;
319 EXPECT_CALL(mock_ffmpeg_, CheckPoint(0)); 319 EXPECT_CALL(mock_ffmpeg_, CheckPoint(0));
320 EXPECT_CALL(*protocol, OnDestroy()); 320 EXPECT_CALL(*protocol, OnDestroy());
321 321
322 // Remove our own reference, we shouldn't be destroyed yet. 322 // Remove our own reference, we shouldn't be destroyed yet.
323 mock_ffmpeg_.CheckPoint(0); 323 mock_ffmpeg_.CheckPoint(0);
324 protocol.reset(); 324 protocol.reset();
325 325
326 // ~FFmpegGlue() will be called when this unit test finishes execution. By 326 // ~FFmpegGlue() will be called when this unit test finishes execution. By
327 // leaving something inside FFmpegGlue's map we get to test our cleanup code. 327 // leaving something inside FFmpegGlue's map we get to test our cleanup code.
328 } 328 }
329 329
330 } // namespace media 330 } // namespace media
OLDNEW

Powered by Google App Engine