Loading services/audiopolicy/tests/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ cc_test { cc_test { cc_test { name: "audio_health_tests", name: "audio_health_tests", require_root: true, shared_libs: [ shared_libs: [ "libaudiofoundation", "libaudiofoundation", Loading services/audiopolicy/tests/audio_health_tests.cpp +41 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "AudioPolicy_Boot_Test" #define LOG_TAG "AudioPolicy_Boot_Test" #include <string> #include <unordered_set> #include <unordered_set> #include <gtest/gtest.h> #include <gtest/gtest.h> Loading Loading @@ -74,3 +75,43 @@ TEST(AudioHealthTest, AttachedDeviceFound) { ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type())); ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type())); } } } } TEST(AudioHealthTest, ConnectSupportedDevice) { AudioPolicyManagerTestClient client; AudioPolicyTestManager manager(&client); manager.loadConfig(); ASSERT_NE("AudioPolicyConfig::setDefault", manager.getConfig().getSource()); DeviceVector devices; for (const auto& hwModule : manager.getConfig().getHwModules()) { for (const auto& profile : hwModule->getOutputProfiles()) { devices.merge(profile->getSupportedDevices()); } for (const auto& profile : hwModule->getInputProfiles()) { devices.merge(profile->getSupportedDevices()); } } for (const auto& device : devices) { if (!audio_is_bluetooth_out_sco_device(device->type()) && !audio_is_bluetooth_in_sco_device(device->type())) { // There are two reasons to only test connecting BT devices. // 1) It is easier to construct a fake address. // 2) This test will be run in presubmit. In that case, it makes sense to make the test // processing time short. continue; } std::string address = "11:22:33:44:55:66"; ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, AudioSystem::getDeviceConnectionState(device->type(), address.c_str())); ASSERT_EQ(NO_ERROR, AudioSystem::setDeviceConnectionState( device->type(), AUDIO_POLICY_DEVICE_STATE_AVAILABLE, address.c_str(), "" /*device_name*/, AUDIO_FORMAT_DEFAULT)); ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_AVAILABLE, AudioSystem::getDeviceConnectionState(device->type(), address.c_str())); ASSERT_EQ(NO_ERROR, AudioSystem::setDeviceConnectionState( device->type(), AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, address.c_str(), "" /*device_name*/, AUDIO_FORMAT_DEFAULT)); ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, AudioSystem::getDeviceConnectionState(device->type(), address.c_str())); } } Loading
services/audiopolicy/tests/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ cc_test { cc_test { cc_test { name: "audio_health_tests", name: "audio_health_tests", require_root: true, shared_libs: [ shared_libs: [ "libaudiofoundation", "libaudiofoundation", Loading
services/audiopolicy/tests/audio_health_tests.cpp +41 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "AudioPolicy_Boot_Test" #define LOG_TAG "AudioPolicy_Boot_Test" #include <string> #include <unordered_set> #include <unordered_set> #include <gtest/gtest.h> #include <gtest/gtest.h> Loading Loading @@ -74,3 +75,43 @@ TEST(AudioHealthTest, AttachedDeviceFound) { ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type())); ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type())); } } } } TEST(AudioHealthTest, ConnectSupportedDevice) { AudioPolicyManagerTestClient client; AudioPolicyTestManager manager(&client); manager.loadConfig(); ASSERT_NE("AudioPolicyConfig::setDefault", manager.getConfig().getSource()); DeviceVector devices; for (const auto& hwModule : manager.getConfig().getHwModules()) { for (const auto& profile : hwModule->getOutputProfiles()) { devices.merge(profile->getSupportedDevices()); } for (const auto& profile : hwModule->getInputProfiles()) { devices.merge(profile->getSupportedDevices()); } } for (const auto& device : devices) { if (!audio_is_bluetooth_out_sco_device(device->type()) && !audio_is_bluetooth_in_sco_device(device->type())) { // There are two reasons to only test connecting BT devices. // 1) It is easier to construct a fake address. // 2) This test will be run in presubmit. In that case, it makes sense to make the test // processing time short. continue; } std::string address = "11:22:33:44:55:66"; ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, AudioSystem::getDeviceConnectionState(device->type(), address.c_str())); ASSERT_EQ(NO_ERROR, AudioSystem::setDeviceConnectionState( device->type(), AUDIO_POLICY_DEVICE_STATE_AVAILABLE, address.c_str(), "" /*device_name*/, AUDIO_FORMAT_DEFAULT)); ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_AVAILABLE, AudioSystem::getDeviceConnectionState(device->type(), address.c_str())); ASSERT_EQ(NO_ERROR, AudioSystem::setDeviceConnectionState( device->type(), AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, address.c_str(), "" /*device_name*/, AUDIO_FORMAT_DEFAULT)); ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, AudioSystem::getDeviceConnectionState(device->type(), address.c_str())); } }