OLD | NEW |
1 // Copyright (c) 2010 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/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" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 17 matching lines...) Expand all Loading... |
29 MOCK_METHOD1(SetPosition, bool(int64 position)); | 29 MOCK_METHOD1(SetPosition, bool(int64 position)); |
30 MOCK_METHOD1(GetSize, bool(int64* size_out)); | 30 MOCK_METHOD1(GetSize, bool(int64* size_out)); |
31 MOCK_METHOD0(IsStreaming, bool()); | 31 MOCK_METHOD0(IsStreaming, bool()); |
32 | 32 |
33 private: | 33 private: |
34 DISALLOW_COPY_AND_ASSIGN(MockProtocol); | 34 DISALLOW_COPY_AND_ASSIGN(MockProtocol); |
35 }; | 35 }; |
36 | 36 |
37 class FFmpegGlueTest : public ::testing::Test { | 37 class FFmpegGlueTest : public ::testing::Test { |
38 public: | 38 public: |
39 FFmpegGlueTest() { | 39 FFmpegGlueTest() {} |
40 } | |
41 | 40 |
42 virtual void SetUp() { | 41 virtual void SetUp() { |
43 MockFFmpeg::set(&mock_ffmpeg_); | |
44 | |
45 // Singleton should initialize FFmpeg. | 42 // Singleton should initialize FFmpeg. |
46 CHECK(FFmpegGlue::GetInstance()); | 43 CHECK(FFmpegGlue::GetInstance()); |
47 | 44 |
48 // 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. |
49 protocol_ = MockFFmpeg::protocol(); | 46 protocol_ = MockFFmpeg::protocol(); |
50 CHECK(protocol_); | 47 CHECK(protocol_); |
51 } | 48 } |
52 | 49 |
53 virtual void TearDown() { | |
54 MockFFmpeg::set(NULL); | |
55 } | |
56 | |
57 // Helper to open a URLContext pointing to the given mocked protocol. | 50 // 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. | 51 // Callers are expected to close the context at the end of their test. |
59 virtual void OpenContext(MockProtocol* protocol, URLContext* context) { | 52 virtual void OpenContext(MockProtocol* protocol, URLContext* context) { |
60 // IsStreaming() is called when opening. | 53 // IsStreaming() is called when opening. |
61 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); | 54 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); |
62 | 55 |
63 // Add the protocol to the glue layer and open a context. | 56 // Add the protocol to the glue layer and open a context. |
64 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol); | 57 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol); |
65 memset(context, 0, sizeof(*context)); | 58 memset(context, 0, sizeof(*context)); |
66 EXPECT_EQ(0, protocol_->url_open(context, key.c_str(), 0)); | 59 EXPECT_EQ(0, protocol_->url_open(context, key.c_str(), 0)); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 314 |
322 // Remove our own reference, we shouldn't be destroyed yet. | 315 // Remove our own reference, we shouldn't be destroyed yet. |
323 mock_ffmpeg_.CheckPoint(0); | 316 mock_ffmpeg_.CheckPoint(0); |
324 protocol.reset(); | 317 protocol.reset(); |
325 | 318 |
326 // ~FFmpegGlue() will be called when this unit test finishes execution. By | 319 // ~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. | 320 // leaving something inside FFmpegGlue's map we get to test our cleanup code. |
328 } | 321 } |
329 | 322 |
330 } // namespace media | 323 } // namespace media |
OLD | NEW |