OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" // For |arraysize()|. | 7 #include "base/basictypes.h" // For |arraysize()|. |
8 #include "ppapi/c/ppb_audio_config.h" | 8 #include "ppapi/c/ppb_audio_config.h" |
9 #include "ppapi/cpp/module.h" | 9 #include "ppapi/cpp/module.h" |
10 #include "ppapi/tests/testing_instance.h" | 10 #include "ppapi/tests/testing_instance.h" |
11 | 11 |
12 REGISTER_TEST_CASE(AudioConfig); | 12 REGISTER_TEST_CASE(AudioConfig); |
13 | 13 |
14 bool TestAudioConfig::Init() { | 14 bool TestAudioConfig::Init() { |
15 audio_config_interface_ = static_cast<PPB_AudioConfig const*>( | 15 audio_config_interface_ = static_cast<PPB_AudioConfig const*>( |
16 pp::Module::Get()->GetBrowserInterface(PPB_AUDIO_CONFIG_INTERFACE)); | 16 pp::Module::Get()->GetBrowserInterface(PPB_AUDIO_CONFIG_INTERFACE)); |
17 core_interface_ = static_cast<const PPB_Core*>( | 17 core_interface_ = static_cast<const PPB_Core*>( |
18 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | 18 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); |
19 return audio_config_interface_ && core_interface_; | 19 return audio_config_interface_ && core_interface_; |
20 } | 20 } |
21 | 21 |
22 void TestAudioConfig::RunTests(const std::string& filter) { | 22 void TestAudioConfig::RunTests(const std::string& filter) { |
23 RUN_TEST(Everything, filter); | 23 RUN_TEST(ValidConfigs, filter); |
| 24 RUN_TEST(InvalidConfigs, filter); |
24 } | 25 } |
25 | 26 |
26 std::string TestAudioConfig::TestEverything() { | 27 std::string TestAudioConfig::TestValidConfigs() { |
27 static const PP_AudioSampleRate kSampleRates[] = { | 28 static const PP_AudioSampleRate kSampleRates[] = { |
28 PP_AUDIOSAMPLERATE_44100, | 29 PP_AUDIOSAMPLERATE_44100, |
29 PP_AUDIOSAMPLERATE_48000 | 30 PP_AUDIOSAMPLERATE_48000 |
30 }; | 31 }; |
31 static const uint32_t kRequestFrameCounts[] = { | 32 static const uint32_t kRequestFrameCounts[] = { |
32 PP_AUDIOMINSAMPLEFRAMECOUNT, | 33 PP_AUDIOMINSAMPLEFRAMECOUNT, |
33 PP_AUDIOMAXSAMPLEFRAMECOUNT, | 34 PP_AUDIOMAXSAMPLEFRAMECOUNT, |
34 // Include some "okay-looking" frame counts; check their validity below. | 35 // Include some "okay-looking" frame counts; check their validity below. |
35 1024, | 36 1024, |
36 2048, | 37 2048, |
(...skipping 19 matching lines...) Expand all Loading... |
56 ASSERT_TRUE(audio_config_interface_->IsAudioConfig(ac)); | 57 ASSERT_TRUE(audio_config_interface_->IsAudioConfig(ac)); |
57 ASSERT_EQ(sample_rate, audio_config_interface_->GetSampleRate(ac)); | 58 ASSERT_EQ(sample_rate, audio_config_interface_->GetSampleRate(ac)); |
58 ASSERT_EQ(frame_count, audio_config_interface_->GetSampleFrameCount(ac)); | 59 ASSERT_EQ(frame_count, audio_config_interface_->GetSampleFrameCount(ac)); |
59 | 60 |
60 core_interface_->ReleaseResource(ac); | 61 core_interface_->ReleaseResource(ac); |
61 } | 62 } |
62 } | 63 } |
63 | 64 |
64 PASS(); | 65 PASS(); |
65 } | 66 } |
| 67 |
| 68 std::string TestAudioConfig::TestInvalidConfigs() { |
| 69 // |PP_AUDIOSAMPLERATE_NONE| is not a valid rate, so this should fail. |
| 70 PP_Resource ac = audio_config_interface_->CreateStereo16Bit( |
| 71 instance_->pp_instance(), |
| 72 PP_AUDIOSAMPLERATE_NONE, |
| 73 PP_AUDIOMINSAMPLEFRAMECOUNT); |
| 74 ASSERT_EQ(0, ac); |
| 75 |
| 76 // Test invalid frame counts. |
| 77 ASSERT_TRUE(PP_AUDIOMINSAMPLEFRAMECOUNT >= 1); |
| 78 ac = audio_config_interface_->CreateStereo16Bit( |
| 79 instance_->pp_instance(), |
| 80 PP_AUDIOSAMPLERATE_44100, |
| 81 PP_AUDIOMINSAMPLEFRAMECOUNT - 1u); |
| 82 ASSERT_EQ(0, ac); |
| 83 ac = audio_config_interface_->CreateStereo16Bit( |
| 84 instance_->pp_instance(), |
| 85 PP_AUDIOSAMPLERATE_44100, |
| 86 PP_AUDIOMAXSAMPLEFRAMECOUNT + 1u); |
| 87 ASSERT_EQ(0, ac); |
| 88 |
| 89 // Test rest of API whose failure cases are defined. |
| 90 ASSERT_FALSE(audio_config_interface_->IsAudioConfig(0)); |
| 91 ASSERT_EQ(PP_AUDIOSAMPLERATE_NONE, audio_config_interface_->GetSampleRate(0)); |
| 92 ASSERT_EQ(0u, audio_config_interface_->GetSampleFrameCount(0)); |
| 93 |
| 94 PASS(); |
| 95 } |
OLD | NEW |