diff options
author | andrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-01-09 17:07:02 +0000 |
---|---|---|
committer | andrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-01-09 17:07:02 +0000 |
commit | 8ba1e50f0afc8f9d63f20573c0b06737df7fc129 (patch) | |
tree | 31af39954032bccc594cd6a2cefab9cd12d8c82f /voice_engine | |
parent | b790741419ee844ae75d0abed27b8e4f0f0f1598 (diff) | |
download | webrtc-8ba1e50f0afc8f9d63f20573c0b06737df7fc129.tar.gz |
Allow for some error in volume testing.
BUG=616
TESTED=voe_auto_test:VolumeTest.* now passes on a MacBook
Review URL: https://webrtc-codereview.appspot.com/1028005
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@3348 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'voice_engine')
-rw-r--r-- | voice_engine/test/auto_test/standard/volume_test.cc | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/voice_engine/test/auto_test/standard/volume_test.cc b/voice_engine/test/auto_test/standard/volume_test.cc index 9328ad3a..d7b192fc 100644 --- a/voice_engine/test/auto_test/standard/volume_test.cc +++ b/voice_engine/test/auto_test/standard/volume_test.cc @@ -10,6 +10,20 @@ #include "after_streaming_fixture.h" +namespace { + +void ExpectVolumeNear(int expected, int actual) { + // The hardware volume may be more coarsely quantized than [0, 255], so + // it is not always reasonable to expect to get exactly what we set. This + // allows for some error. + const int kMaxVolumeError = 10; + EXPECT_NEAR(expected, actual, kMaxVolumeError); + EXPECT_GE(actual, 0); + EXPECT_LE(actual, 255); +} + +} // namespace + class VolumeTest : public AfterStreamingFixture { }; @@ -33,20 +47,20 @@ TEST_F(VolumeTest, SetVolumeBeforePlayoutWorks) { EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(200)); unsigned int volume; EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); - EXPECT_EQ(200u, volume); + ExpectVolumeNear(200u, volume); PausePlaying(); ResumePlaying(); EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); // Ensure the volume has not changed after resuming playout. - EXPECT_EQ(200u, volume); + ExpectVolumeNear(200u, volume); PausePlaying(); EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(100)); ResumePlaying(); // Ensure the volume set while paused is retained. EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); - EXPECT_EQ(100u, volume); + ExpectVolumeNear(100u, volume); EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(original_volume)); } @@ -60,20 +74,20 @@ TEST_F(VolumeTest, ManualSetVolumeWorks) { EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(0)); unsigned int volume; EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); - EXPECT_EQ(0u, volume); + ExpectVolumeNear(0u, volume); Sleep(1000); TEST_LOG("Setting speaker volume to 100 out of 255.\n"); EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(100)); EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); - EXPECT_EQ(100u, volume); + ExpectVolumeNear(100u, volume); Sleep(1000); // Set the volume to 255 very briefly so we don't blast the poor user // listening to this. This is just to test the call succeeds. EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(255)); EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); - EXPECT_EQ(255u, volume); + ExpectVolumeNear(255u, volume); TEST_LOG("Setting speaker volume to the original %d out of 255.\n", original_volume); |