| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/tests/test_audio_config.h" | 5 #include "ppapi/tests/test_audio_config.h" |
| 6 | 6 |
| 7 #include "ppapi/c/ppb_audio_config.h" | 7 #include "ppapi/c/ppb_audio_config.h" |
| 8 #include "ppapi/cpp/module.h" | 8 #include "ppapi/cpp/module.h" |
| 9 #include "ppapi/tests/testing_instance.h" | 9 #include "ppapi/tests/testing_instance.h" |
| 10 | 10 |
| 11 REGISTER_TEST_CASE(AudioConfig); | 11 REGISTER_TEST_CASE(AudioConfig); |
| 12 | 12 |
| 13 bool TestAudioConfig::Init() { | 13 bool TestAudioConfig::Init() { |
| 14 audio_config_interface_ = static_cast<const PPB_AudioConfig*>( | 14 audio_config_interface_ = static_cast<const PPB_AudioConfig*>( |
| 15 pp::Module::Get()->GetBrowserInterface(PPB_AUDIO_CONFIG_INTERFACE)); | 15 pp::Module::Get()->GetBrowserInterface(PPB_AUDIO_CONFIG_INTERFACE)); |
| 16 core_interface_ = static_cast<const PPB_Core*>( | 16 core_interface_ = static_cast<const PPB_Core*>( |
| 17 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | 17 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); |
| 18 return audio_config_interface_ && core_interface_; | 18 return audio_config_interface_ && core_interface_; |
| 19 } | 19 } |
| 20 | 20 |
| 21 void TestAudioConfig::RunTests(const std::string& filter) { | 21 void TestAudioConfig::RunTests(const std::string& filter) { |
| 22 RUN_TEST(RecommendSampleRate, filter); |
| 22 RUN_TEST(ValidConfigs, filter); | 23 RUN_TEST(ValidConfigs, filter); |
| 23 RUN_TEST(InvalidConfigs, filter); | 24 RUN_TEST(InvalidConfigs, filter); |
| 24 } | 25 } |
| 25 | 26 |
| 27 std::string TestAudioConfig::TestRecommendSampleRate() { |
| 28 // Ask PPB_AudioConfig about the recommended sample rate. |
| 29 PP_AudioSampleRate sample_rate = audio_config_interface_->RecommendSampleRate( |
| 30 instance_->pp_instance()); |
| 31 ASSERT_TRUE(sample_rate == PP_AUDIOSAMPLERATE_NONE || |
| 32 sample_rate == PP_AUDIOSAMPLERATE_44100 || |
| 33 sample_rate == PP_AUDIOSAMPLERATE_48000); |
| 34 |
| 35 PASS(); |
| 36 } |
| 37 |
| 26 std::string TestAudioConfig::TestValidConfigs() { | 38 std::string TestAudioConfig::TestValidConfigs() { |
| 27 static const PP_AudioSampleRate kSampleRates[] = { | 39 static const PP_AudioSampleRate kSampleRates[] = { |
| 28 PP_AUDIOSAMPLERATE_44100, | 40 PP_AUDIOSAMPLERATE_44100, |
| 29 PP_AUDIOSAMPLERATE_48000 | 41 PP_AUDIOSAMPLERATE_48000 |
| 30 }; | 42 }; |
| 31 static const uint32_t kRequestFrameCounts[] = { | 43 static const uint32_t kRequestFrameCounts[] = { |
| 32 PP_AUDIOMINSAMPLEFRAMECOUNT, | 44 PP_AUDIOMINSAMPLEFRAMECOUNT, |
| 33 PP_AUDIOMAXSAMPLEFRAMECOUNT, | 45 PP_AUDIOMAXSAMPLEFRAMECOUNT, |
| 34 // Include some "okay-looking" frame counts; check their validity below. | 46 // Include some "okay-looking" frame counts; check their validity below. |
| 35 1024, | 47 1024, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 PP_AUDIOMAXSAMPLEFRAMECOUNT + 1u); | 99 PP_AUDIOMAXSAMPLEFRAMECOUNT + 1u); |
| 88 ASSERT_EQ(0, ac); | 100 ASSERT_EQ(0, ac); |
| 89 | 101 |
| 90 // Test rest of API whose failure cases are defined. | 102 // Test rest of API whose failure cases are defined. |
| 91 ASSERT_FALSE(audio_config_interface_->IsAudioConfig(0)); | 103 ASSERT_FALSE(audio_config_interface_->IsAudioConfig(0)); |
| 92 ASSERT_EQ(PP_AUDIOSAMPLERATE_NONE, audio_config_interface_->GetSampleRate(0)); | 104 ASSERT_EQ(PP_AUDIOSAMPLERATE_NONE, audio_config_interface_->GetSampleRate(0)); |
| 93 ASSERT_EQ(0u, audio_config_interface_->GetSampleFrameCount(0)); | 105 ASSERT_EQ(0u, audio_config_interface_->GetSampleFrameCount(0)); |
| 94 | 106 |
| 95 PASS(); | 107 PASS(); |
| 96 } | 108 } |
| OLD | NEW |