This source file includes following definitions.
- cast_environment_
- 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/logging/simple_event_subscriber.h"
#include "media/cast/test/fake_single_thread_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace cast {
class SimpleEventSubscriberTest : public ::testing::Test {
protected:
SimpleEventSubscriberTest()
: 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_)) {
cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_);
}
virtual ~SimpleEventSubscriberTest() {
cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_);
}
base::SimpleTestTickClock* testing_clock_;
scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
scoped_refptr<CastEnvironment> cast_environment_;
SimpleEventSubscriber event_subscriber_;
};
TEST_F(SimpleEventSubscriberTest, GetAndResetEvents) {
cast_environment_->Logging()->InsertFrameEventWithSize(
testing_clock_->NowTicks(), kAudioFrameEncoded, 100u,
0u, 123);
cast_environment_->Logging()->InsertFrameEventWithDelay(
testing_clock_->NowTicks(), kAudioPlayoutDelay, 100u,
0u, base::TimeDelta::FromMilliseconds(100));
cast_environment_->Logging()->InsertFrameEvent(
testing_clock_->NowTicks(), kAudioFrameDecoded, 200u,
0u);
cast_environment_->Logging()->InsertPacketEvent(
testing_clock_->NowTicks(), kAudioPacketReceived, 200u,
0u, 1u, 5u, 100u);
cast_environment_->Logging()->InsertPacketEvent(
testing_clock_->NowTicks(), kVideoFrameDecoded, 200u,
0u, 1u, 5u, 100u);
cast_environment_->Logging()->InsertPacketEvent(
testing_clock_->NowTicks(), kVideoFrameDecoded, 300u,
0u, 1u, 5u, 100u);
cast_environment_->Logging()->InsertGenericEvent(testing_clock_->NowTicks(),
kRttMs, 150);
std::vector<FrameEvent> frame_events;
event_subscriber_.GetFrameEventsAndReset(&frame_events);
EXPECT_EQ(3u, frame_events.size());
std::vector<PacketEvent> packet_events;
event_subscriber_.GetPacketEventsAndReset(&packet_events);
EXPECT_EQ(3u, packet_events.size());
std::vector<GenericEvent> generic_events;
event_subscriber_.GetGenericEventsAndReset(&generic_events);
EXPECT_EQ(1u, generic_events.size());
event_subscriber_.GetFrameEventsAndReset(&frame_events);
event_subscriber_.GetPacketEventsAndReset(&packet_events);
event_subscriber_.GetGenericEventsAndReset(&generic_events);
EXPECT_TRUE(frame_events.empty());
EXPECT_TRUE(packet_events.empty());
EXPECT_TRUE(generic_events.empty());
}
}
}