Index: components/copresence/handlers/audio/audio_directive_handler_unittest.cc |
diff --git a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc |
index 31c5f58adb911f6e5c7ccdeebf939b366de15c86..bfe47f1eb982abbbe1c7b886037803dff6e755d6 100644 |
--- a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc |
+++ b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc |
@@ -5,11 +5,9 @@ |
#include "components/copresence/handlers/audio/audio_directive_handler.h" |
#include "base/bind.h" |
+#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.h" |
-#include "components/copresence/mediums/audio/audio_player.h" |
-#include "components/copresence/mediums/audio/audio_recorder.h" |
-#include "components/copresence/test/audio_test_support.h" |
-#include "media/base/audio_bus.h" |
+#include "components/copresence/mediums/audio/audio_manager.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -18,62 +16,44 @@ using ::testing::Le; |
namespace copresence { |
-class TestAudioPlayer : public AudioPlayer { |
+class TestAudioManager : public AudioManager { |
Daniel Erat
2014/10/18 21:21:18
i agree that you should create an pure virtual Aud
rkc
2014/10/20 16:45:37
Though I agree that there are benefits to having a
Charlie
2014/10/20 20:06:54
It's a little hard to talk about this without goin
rkc
2014/10/20 20:17:53
Its complexity may not grow at the same rate as th
Charlie
2014/10/20 20:33:05
We talked about this already. See crbug/424781.
rkc
2014/10/21 01:25:04
I don't necessarily agree with everything said in
|
public: |
- TestAudioPlayer() {} |
- virtual ~TestAudioPlayer() {} |
- |
- // AudioPlayer overrides: |
- virtual void Initialize() override {} |
- virtual void Play( |
- const scoped_refptr<media::AudioBusRefCounted>& /* samples */) override { |
- set_is_playing(true); |
+ TestAudioManager() : AudioManager() {} |
+ virtual ~TestAudioManager() {} |
+ |
+ // AudioManager overrides: |
+ virtual void Initialize(const DecodeSamplesCallback&, |
Daniel Erat
2014/10/18 21:21:18
it's cleaner to keep Initialize methods in the imp
rkc
2014/10/20 16:45:38
I'm confused about how this would work, maybe I am
Charlie
2014/10/20 20:06:54
Let's call it AudioManager or AudioManagerInterfac
rkc
2014/10/20 20:17:53
That doesn't fix the issue. The issue is that the
Charlie
2014/10/20 20:33:05
By "container class", do you mean AudioDirectiveHa
rkc
2014/10/21 01:25:04
What's the difference between this and just creati
Charlie
2014/10/21 16:27:09
set_*_for_testing() methods are sub-optimal becaus
|
+ const EncodeTokenCallback&) override {} |
+ virtual void StartPlaying(AudioType type) override { |
+ set_playing_for_testing(type, true); |
Daniel Erat
2014/10/18 21:21:18
it would also be cleaner if this stub class had it
rkc
2014/10/20 16:45:37
The TestAudioPlayer/Recorder are technically deleg
|
} |
- virtual void Stop() override { set_is_playing(false); } |
- virtual void Finalize() override { delete this; } |
- |
- private: |
- DISALLOW_COPY_AND_ASSIGN(TestAudioPlayer); |
-}; |
- |
-class TestAudioRecorder : public AudioRecorder { |
- public: |
- TestAudioRecorder() : AudioRecorder(AudioRecorder::DecodeSamplesCallback()) {} |
- virtual ~TestAudioRecorder() {} |
- |
- // AudioRecorder overrides: |
- virtual void Initialize() override {} |
- virtual void Record() override { set_is_recording(true); } |
- virtual void Stop() override { set_is_recording(false); } |
- virtual void Finalize() override { delete this; } |
+ virtual void StopPlaying(AudioType type) override { |
+ set_playing_for_testing(type, false); |
+ } |
+ virtual void StartRecording(AudioType type) override { |
+ set_recording_for_testing(type, true); |
+ } |
+ virtual void StopRecording(AudioType type) override { |
+ set_recording_for_testing(type, false); |
+ } |
+ virtual void SetToken(AudioType, const std::string&) override {} |
private: |
- DISALLOW_COPY_AND_ASSIGN(TestAudioRecorder); |
+ DISALLOW_COPY_AND_ASSIGN(TestAudioManager); |
}; |
class AudioDirectiveHandlerTest : public testing::Test { |
public: |
AudioDirectiveHandlerTest() |
- : directive_handler_(new AudioDirectiveHandler( |
- AudioRecorder::DecodeSamplesCallback(), |
- base::Bind(&AudioDirectiveHandlerTest::EncodeToken, |
- base::Unretained(this)))) { |
- directive_handler_->set_player_audible_for_testing(new TestAudioPlayer()); |
- directive_handler_->set_player_inaudible_for_testing(new TestAudioPlayer()); |
- directive_handler_->set_recorder_for_testing(new TestAudioRecorder()); |
+ : directive_handler_(new AudioDirectiveHandler()) { |
+ directive_handler_->set_audio_manager_for_testing( |
+ make_scoped_ptr(new TestAudioManager())); |
} |
virtual ~AudioDirectiveHandlerTest() {} |
void DirectiveAdded() {} |
protected: |
- void EncodeToken(const std::string& token, |
- bool audible, |
- const AudioDirectiveHandler::SamplesCallback& callback) { |
- callback.Run( |
- token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331)); |
- } |
- |
copresence::TokenInstruction CreateTransmitInstruction( |
const std::string& token, |
bool audible) { |
@@ -85,12 +65,22 @@ class AudioDirectiveHandlerTest : public testing::Test { |
return instruction; |
} |
- copresence::TokenInstruction CreateReceiveInstruction() { |
+ copresence::TokenInstruction CreateReceiveInstruction(bool audible) { |
copresence::TokenInstruction instruction; |
instruction.set_token_instruction_type(copresence::RECEIVE); |
+ instruction.set_medium(audible ? AUDIO_AUDIBLE_DTMF |
+ : AUDIO_ULTRASOUND_PASSBAND); |
return instruction; |
} |
+ bool IsPlaying(AudioType type) { |
+ return directive_handler_->audio_manager_->is_playing_for_testing(type); |
+ } |
+ |
+ bool IsRecording(AudioType type) { |
+ return directive_handler_->audio_manager_->is_recording_for_testing(type); |
+ } |
+ |
// This order is important. We want the message loop to get created before |
// our the audio directive handler since the directive list ctor (invoked |
// from the directive handler ctor) will post tasks. |
@@ -110,30 +100,34 @@ TEST_F(AudioDirectiveHandlerTest, Basic) { |
directive_handler_->AddInstruction( |
CreateTransmitInstruction("token", false), "op_id2", kTtl); |
directive_handler_->AddInstruction( |
- CreateReceiveInstruction(), "op_id1", kTtl); |
+ CreateReceiveInstruction(false), "op_id1", kTtl); |
directive_handler_->AddInstruction( |
- CreateReceiveInstruction(), "op_id2", kTtl); |
+ CreateReceiveInstruction(true), "op_id2", kTtl); |
directive_handler_->AddInstruction( |
- CreateReceiveInstruction(), "op_id3", kTtl); |
+ CreateReceiveInstruction(false), "op_id3", kTtl); |
- EXPECT_EQ(true, directive_handler_->player_audible_->IsPlaying()); |
- EXPECT_EQ(true, directive_handler_->player_inaudible_->IsPlaying()); |
- EXPECT_EQ(true, directive_handler_->recorder_->IsRecording()); |
+ EXPECT_TRUE(IsPlaying(AUDIBLE)); |
+ EXPECT_TRUE(IsPlaying(INAUDIBLE)); |
+ EXPECT_TRUE(IsRecording(AUDIBLE)); |
+ EXPECT_TRUE(IsRecording(INAUDIBLE)); |
directive_handler_->RemoveInstructions("op_id1"); |
- EXPECT_FALSE(directive_handler_->player_audible_->IsPlaying()); |
- EXPECT_EQ(true, directive_handler_->player_inaudible_->IsPlaying()); |
- EXPECT_EQ(true, directive_handler_->recorder_->IsRecording()); |
+ EXPECT_FALSE(IsPlaying(AUDIBLE)); |
+ EXPECT_TRUE(IsPlaying(INAUDIBLE)); |
+ EXPECT_TRUE(IsRecording(AUDIBLE)); |
+ EXPECT_TRUE(IsRecording(INAUDIBLE)); |
directive_handler_->RemoveInstructions("op_id2"); |
- EXPECT_FALSE(directive_handler_->player_inaudible_->IsPlaying()); |
- EXPECT_EQ(true, directive_handler_->recorder_->IsRecording()); |
+ EXPECT_FALSE(IsPlaying(INAUDIBLE)); |
+ EXPECT_FALSE(IsRecording(AUDIBLE)); |
+ EXPECT_TRUE(IsRecording(INAUDIBLE)); |
directive_handler_->RemoveInstructions("op_id3"); |
- EXPECT_FALSE(directive_handler_->recorder_->IsRecording()); |
+ EXPECT_FALSE(IsRecording(INAUDIBLE)); |
} |
// TODO(rkc): Write more tests that check more convoluted sequences of |
// transmits/receives. |
+// TODO(rkc): Write tests to move time back and forth and test functionality. |
} // namespace copresence |