Chromium Code Reviews| Index: media/base/encoded_bitstream_buffer_unittest.cc |
| diff --git a/media/base/encoded_bitstream_buffer_unittest.cc b/media/base/encoded_bitstream_buffer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d94fa75ff28c685f8ef51bd7ab3e5917f02f6133 |
| --- /dev/null |
| +++ b/media/base/encoded_bitstream_buffer_unittest.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/bind.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/message_loop.h" |
| +#include "media/base/encoded_bitstream_buffer.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using ::testing::StrictMock; |
| + |
| +namespace media { |
| + |
| +class MockEncodedBitstreamBuffer : public EncodedBitstreamBuffer { |
| + public: |
| + MockEncodedBitstreamBuffer() |
| + : EncodedBitstreamBuffer(0, base::Time::Now(), 0) {} |
| + MOCK_METHOD0(Die, void()); |
| + virtual ~MockEncodedBitstreamBuffer() { |
| + Die(); |
| + } |
| +}; |
| + |
| +static void TestTask(scoped_refptr<EncodedBitstreamBuffer> b) { |
| + ASSERT_TRUE(b.get() != NULL); |
| + // Just let die and scoped_refptr should go. |
| +} |
| + |
| +TEST(EncodedBitstreamBufferTests, BasicTest) { |
| + { |
|
wjia(left Chromium)
2013/02/28 18:46:26
It seems this extra pair of braces is not needed.
vmr
2013/03/01 14:24:00
Done.
|
| + scoped_refptr<StrictMock<MockEncodedBitstreamBuffer> > a = |
| + new StrictMock<MockEncodedBitstreamBuffer>(); |
| + EXPECT_EQ(a->key_frame(), false); |
| + EXPECT_EQ(a->altref_frame(), false); |
| + EXPECT_EQ(a->golden_frame(), false); |
| + EXPECT_EQ(a->droppable(), false); |
| + EXPECT_EQ(a->layer_sync(), false); |
| + a->MarkKeyFrame(); |
| + a->MarkAltRef(); |
| + a->MarkGolden(); |
| + a->MarkDroppable(); |
| + a->MarkLayerSync(); |
| + EXPECT_EQ(a->key_frame(), true); |
| + EXPECT_EQ(a->altref_frame(), true); |
| + EXPECT_EQ(a->golden_frame(), true); |
| + EXPECT_EQ(a->droppable(), true); |
| + EXPECT_EQ(a->layer_sync(), true); |
| + EXPECT_CALL(*a.get(), Die()); |
| + } |
| +} |
| + |
| +TEST(EncodedBitstreamBufferTests, CrossThreadTest) { |
| + MessageLoop message_loop; |
| + { |
| + scoped_refptr<StrictMock<MockEncodedBitstreamBuffer> > a = |
| + new StrictMock<MockEncodedBitstreamBuffer>(); |
| + base::Closure task = base::Bind(&TestTask, a); |
| + message_loop.PostTask(FROM_HERE, task); |
| + EXPECT_CALL(*a.get(), Die()); |
| + } // Now our reference should be gone. |
| + // When TestTask finishes, destructor should be called. |
| + message_loop.RunUntilIdle(); |
| +} |
| + |
| +} // namespace media |
| + |