OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <vector> | |
6 | |
7 #include "media/base/mock_filters.h" | |
8 #include "media/filters/decoder_base.h" | |
9 #include "testing/gmock/include/gmock/gmock.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 using ::testing::NotNull; | |
13 | |
14 namespace media { | |
15 | |
16 class MockOutput : public StreamSample { | |
17 MOCK_CONST_METHOD0(IsEndOfStream, bool()); | |
18 }; | |
19 | |
20 class MockDecoder : public MediaFilter {}; | |
21 | |
22 class MockBuffer : public Buffer { | |
23 public: | |
24 MOCK_CONST_METHOD0(GetData, const uint8*()); | |
25 MOCK_CONST_METHOD0(GetDataSize, size_t()); | |
26 }; | |
27 | |
28 ACTION(Initialize) { | |
29 AutoTaskRunner done_runner(arg2); | |
30 *arg1 = true; | |
31 } | |
32 | |
33 ACTION_P(SaveDecodeRequest, list) { | |
34 scoped_refptr<Buffer> buffer = arg0; | |
35 list->push_back(arg1); | |
36 } | |
37 | |
38 ACTION(CompleteDemuxRequest) { | |
39 arg0->Run(new MockBuffer()); | |
40 delete arg0; | |
41 } | |
42 | |
43 class MockDecoderImpl : public DecoderBase<MockDecoder, MockOutput> { | |
44 public: | |
45 MockDecoderImpl() { | |
46 media_format_.SetAsString(MediaFormat::kMimeType, "mock"); | |
47 } | |
48 | |
49 // DecoderBase Implementations. | |
50 MOCK_METHOD3(DoInitialize, | |
51 void(DemuxerStream* demuxer_stream, bool* success, | |
52 Task* done_cb)); | |
53 MOCK_METHOD0(DoStop, void()); | |
54 MOCK_METHOD2(DoSeek, void(base::TimeDelta time, Task* done_cb)); | |
55 MOCK_METHOD2(DoDecode, void(Buffer* input, Task* done_cb)); | |
56 | |
57 private: | |
58 FRIEND_TEST(DecoderBaseTest, FlowControl); | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(MockDecoderImpl); | |
61 }; | |
62 | |
63 class MockReadCallback { | |
64 public: | |
65 MockReadCallback() {} | |
66 MOCK_METHOD1(ReadCallback, void(MockOutput* output)); | |
67 | |
68 private: | |
69 DISALLOW_COPY_AND_ASSIGN(MockReadCallback); | |
70 }; | |
71 | |
72 // Test the flow control of decoder base by the following sequnce of actions: | |
73 // - Read() -> DecoderStream | |
74 // \ Read() -> DemuxerStream | |
75 // - Read() -> DecoderBase | |
76 // \ Read() -> DemixerStream | |
77 // - ReadCallback() -> DecoderBase | |
78 // \ DoDecode() -> Decoder | |
79 // - ReadCallback() -> DecoderBase | |
80 // \ DoDecode() -> Decoder | |
81 // - DecodeCallback() -> DecoderBase | |
82 // \ ReadCallback() -> client | |
83 // - DecodeCallback() -> DecoderBase | |
84 // \ ReadCallback() -> client | |
85 TEST(DecoderBaseTest, FlowControl) { | |
86 MessageLoop message_loop; | |
87 scoped_refptr<MockDecoderImpl> decoder = new MockDecoderImpl(); | |
88 scoped_refptr<MockDemuxerStream> demuxer_stream = new MockDemuxerStream(); | |
89 MockFilterCallback callback; | |
90 MockReadCallback read_callback; | |
91 decoder->set_message_loop(&message_loop); | |
92 | |
93 // Initailize. | |
94 EXPECT_CALL(callback, OnFilterCallback()); | |
95 EXPECT_CALL(callback, OnCallbackDestroyed()); | |
96 EXPECT_CALL(*decoder, DoInitialize(NotNull(), NotNull(), NotNull())) | |
97 .WillOnce(Initialize()); | |
98 decoder->Initialize(demuxer_stream.get(), callback.NewCallback()); | |
99 message_loop.RunAllPending(); | |
100 | |
101 // Read. | |
102 std::vector<Task*> decode_requests; | |
103 EXPECT_CALL(*demuxer_stream, Read(NotNull())) | |
104 .Times(2) | |
105 .WillRepeatedly(CompleteDemuxRequest()); | |
106 EXPECT_CALL(*decoder, DoDecode(NotNull(), NotNull())) | |
107 .Times(2) | |
108 .WillRepeatedly(SaveDecodeRequest(&decode_requests)); | |
109 decoder->Read(NewCallback(&read_callback, | |
110 &MockReadCallback::ReadCallback)); | |
scherkus (not reviewing)
2010/02/26 22:03:17
make sure this passes on try servesr.. I had to us
| |
111 decoder->Read(NewCallback(&read_callback, | |
112 &MockReadCallback::ReadCallback)); | |
113 message_loop.RunAllPending(); | |
114 | |
115 // Fulfill the decode request. | |
116 EXPECT_CALL(read_callback, ReadCallback(NotNull())).Times(2); | |
117 for (size_t i = 0; i < decode_requests.size(); ++i) { | |
118 decoder->EnqueueResult(new MockOutput()); | |
119 AutoTaskRunner done_cb(decode_requests[i]); | |
120 } | |
121 decode_requests.clear(); | |
122 message_loop.RunAllPending(); | |
123 | |
124 // Stop. | |
125 EXPECT_CALL(*decoder, DoStop()); | |
126 decoder->Stop(); | |
127 message_loop.RunAllPending(); | |
128 } | |
129 | |
130 } // namespace media | |
OLD | NEW |