This source file includes following definitions.
- cast_environment_
- TearDown
- Init
- InsertEvents
- TEST_F
- TEST_F
- TEST_F
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/tick_clock.h"
#include "media/cast/cast_environment.h"
#include "media/cast/logging/logging_defines.h"
#include "media/cast/rtcp/receiver_rtcp_event_subscriber.h"
#include "media/cast/test/fake_single_thread_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace cast {
namespace {
const size_t kMaxEventEntries = 10u;
const int64 kDelayMs = 20L;
}
class ReceiverRtcpEventSubscriberTest : public ::testing::Test {
protected:
ReceiverRtcpEventSubscriberTest()
: testing_clock_(new base::SimpleTestTickClock()),
task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)),
cast_environment_(new CastEnvironment(
scoped_ptr<base::TickClock>(testing_clock_).Pass(),
task_runner_,
task_runner_,
task_runner_)) {}
virtual ~ReceiverRtcpEventSubscriberTest() {}
virtual void TearDown() OVERRIDE {
if (event_subscriber_) {
cast_environment_->Logging()->RemoveRawEventSubscriber(
event_subscriber_.get());
}
}
void Init(ReceiverRtcpEventSubscriber::Type type) {
event_subscriber_.reset(
new ReceiverRtcpEventSubscriber(kMaxEventEntries, type));
cast_environment_->Logging()->AddRawEventSubscriber(
event_subscriber_.get());
}
void InsertEvents() {
cast_environment_->Logging()->InsertFrameEventWithDelay(
testing_clock_->NowTicks(), kVideoRenderDelay, 100u,
2u, base::TimeDelta::FromMilliseconds(kDelayMs));
cast_environment_->Logging()->InsertFrameEvent(
testing_clock_->NowTicks(), kVideoFrameDecoded, 200u,
1u);
cast_environment_->Logging()->InsertPacketEvent(
testing_clock_->NowTicks(), kVideoPacketReceived,
200u, 2u, 1u,
10u, 1024u);
cast_environment_->Logging()->InsertFrameEventWithDelay(
testing_clock_->NowTicks(), kAudioPlayoutDelay, 300u,
4u, base::TimeDelta::FromMilliseconds(kDelayMs));
cast_environment_->Logging()->InsertFrameEvent(
testing_clock_->NowTicks(), kAudioFrameDecoded, 400u,
3u);
cast_environment_->Logging()->InsertPacketEvent(
testing_clock_->NowTicks(), kAudioPacketReceived,
400u, 5u, 1u,
10u, 128u);
cast_environment_->Logging()->InsertFrameEvent(
testing_clock_->NowTicks(), kVideoFrameReceived, 100u,
1u);
cast_environment_->Logging()->InsertFrameEvent(
testing_clock_->NowTicks(), kAudioFrameReceived, 100u,
1u);
cast_environment_->Logging()->InsertGenericEvent(testing_clock_->NowTicks(),
kRttMs, 100);
}
base::SimpleTestTickClock* testing_clock_;
scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
scoped_refptr<CastEnvironment> cast_environment_;
scoped_ptr<ReceiverRtcpEventSubscriber> event_subscriber_;
};
TEST_F(ReceiverRtcpEventSubscriberTest, LogVideoEvents) {
Init(ReceiverRtcpEventSubscriber::kVideoEventSubscriber);
InsertEvents();
ReceiverRtcpEventSubscriber::RtcpEventMultiMap rtcp_events;
event_subscriber_->GetRtcpEventsAndReset(&rtcp_events);
EXPECT_EQ(3u, rtcp_events.size());
}
TEST_F(ReceiverRtcpEventSubscriberTest, LogAudioEvents) {
Init(ReceiverRtcpEventSubscriber::kAudioEventSubscriber);
InsertEvents();
ReceiverRtcpEventSubscriber::RtcpEventMultiMap rtcp_events;
event_subscriber_->GetRtcpEventsAndReset(&rtcp_events);
EXPECT_EQ(3u, rtcp_events.size());
}
TEST_F(ReceiverRtcpEventSubscriberTest, DropEventsWhenSizeExceeded) {
Init(ReceiverRtcpEventSubscriber::kVideoEventSubscriber);
for (uint32 i = 1u; i <= 10u; ++i) {
cast_environment_->Logging()->InsertFrameEvent(
testing_clock_->NowTicks(), kVideoFrameDecoded,
i * 10, i);
}
ReceiverRtcpEventSubscriber::RtcpEventMultiMap rtcp_events;
event_subscriber_->GetRtcpEventsAndReset(&rtcp_events);
EXPECT_EQ(10u, rtcp_events.size());
}
}
}