Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Unified Diff: remoting/client/audio_decode_scheduler_unittest.cc

Issue 2052723002: Adding an interface to allow extention of the audio player for CRD and iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a unit test for Decoder. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/client/audio_decode_scheduler_unittest.cc
diff --git a/remoting/client/audio_decode_scheduler_unittest.cc b/remoting/client/audio_decode_scheduler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..52313f3daa70eebaf95946aeb2b399b71222fba5
--- /dev/null
+++ b/remoting/client/audio_decode_scheduler_unittest.cc
@@ -0,0 +1,102 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
Lambros 2016/06/17 18:32:29 No (c).
nicholss 2016/06/17 22:35:00 Done.
+// 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/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/threading/thread.h"
+#include "remoting/base/auto_thread.h"
+#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/client/audio_decode_scheduler.h"
+#include "remoting/client/fake_audio_consumer.h"
+#include "remoting/protocol/session_config.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const int kAudioSampleBytes = 4;
+const uint8_t kDummyAudioData = 0x8B;
+
+} // namespace
+
+namespace remoting {
+
+class AudioDecodeSchedulerTest : public ::testing::Test {
Lambros 2016/06/17 18:32:29 I'm a bit puzzled by these tests, since you don't
+ public:
+ AudioDecodeSchedulerTest() {}
+
+ void SetUp() override;
+ void TearDown() override;
+
+ protected:
+ base::MessageLoop message_loop_;
+ base::RunLoop run_loop_;
+ scoped_refptr<AutoThreadTaskRunner> audio_decode_task_runner_;
+ scoped_refptr<AutoThreadTaskRunner> main_task_runner_;
+ std::unique_ptr<protocol::SessionConfig> session_config_;
+};
+
+void AudioDecodeSchedulerTest::SetUp() {
+ main_task_runner_ = new AutoThreadTaskRunner(
+ message_loop_.task_runner(), run_loop_.QuitClosure());
+ audio_decode_task_runner_ = AutoThread::Create("decode", main_task_runner_);
+ session_config_ = protocol::SessionConfig::ForTestWithAudio();
+}
+
+void AudioDecodeSchedulerTest::TearDown() {
+ // Release the task runners, so that the test can quit.
+ audio_decode_task_runner_ = nullptr;
+ main_task_runner_ = nullptr;
+
+ // Run the MessageLoop until everything has torn down.
+ run_loop_.Run();
+}
+
+// TODO:: could share the following in a common class for use other places.
Lambros 2016/06/17 18:32:29 Remove TODO or use correct formatting: TODO(userna
nicholss 2016/06/17 22:35:00 Done.
+std::unique_ptr<AudioPacket> CreatePacketWithSamplingRate_(
+ AudioPacket::SamplingRate rate,
+ int samples) {
+ std::unique_ptr<AudioPacket> packet(new AudioPacket());
+ packet->set_encoding(AudioPacket::ENCODING_RAW);
+ packet->set_sampling_rate(rate);
+ packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2);
+ packet->set_channels(AudioPacket::CHANNELS_STEREO);
+
+ // The data must be a multiple of 4 bytes (channels x bytes_per_sample).
+ std::string data;
+ data.resize(samples * kAudioSampleBytes, kDummyAudioData);
+ packet->add_data(data);
+
+ return packet;
+}
+
+std::unique_ptr<AudioPacket> CreatePacket44100Hz_(int samples) {
+ return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_44100,
+ samples);
+}
+
+std::unique_ptr<AudioPacket> CreatePacket48000Hz_(int samples) {
+ return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_48000,
+ samples);
+}
+
+void Done() {}
Lambros 2016/06/17 18:32:29 Remove (see below).
nicholss 2016/06/17 22:35:00 Done.
+
+TEST_F(AudioDecodeSchedulerTest, Shutdown) {
+
+ std::unique_ptr<FakeAudioConsumer> audio_consumer(new FakeAudioConsumer());
+ std::unique_ptr<AudioDecodeScheduler> audio_scheduler(
+ new AudioDecodeScheduler(main_task_runner_,
+ audio_decode_task_runner_, audio_consumer.get()));
Lambros 2016/06/17 18:32:29 Looks like wrong indentation. Please run git cl fo
nicholss 2016/06/17 22:34:59 Done.
+
+ audio_scheduler->Initialize(*session_config_);
+
+ audio_scheduler->ProcessAudioPacket(CreatePacket44100Hz_(1000),
+ base::Bind(&Done));
Lambros 2016/06/17 18:32:29 base::Bind(&base::DoNothing)
nicholss 2016/06/17 22:34:59 Done.
+
+ audio_scheduler.reset();
+ audio_consumer.reset();
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698