audiopolicy: Add unit tests build target
This change adds audiopolicy_tests target for running
unit tests of AudioPolicyManager class.
AudioPolicyManager class is modified to allow
finer control over the configuration loading.
Test: audiopolicy_tests
Change-Id: Icf0cd7ff5b3b8b827b4f6909ff2c138ac2a2b82e
diff --git a/services/audiopolicy/tests/Android.mk b/services/audiopolicy/tests/Android.mk
new file mode 100644
index 0000000..62869a4
--- /dev/null
+++ b/services/audiopolicy/tests/Android.mk
@@ -0,0 +1,30 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_C_INCLUDES := \
+ frameworks/av/services/audiopolicy \
+ frameworks/av/services/audiopolicy/common/include \
+ frameworks/av/services/audiopolicy/engine/interface \
+ frameworks/av/services/audiopolicy/utilities
+
+LOCAL_SHARED_LIBRARIES := \
+ libaudiopolicymanagerdefault \
+ libbase \
+ liblog \
+ libmedia_helper \
+ libutils \
+
+LOCAL_STATIC_LIBRARIES := \
+ libaudiopolicycomponents \
+
+LOCAL_SRC_FILES := \
+ audiopolicymanager_tests.cpp \
+
+LOCAL_MODULE := audiopolicy_tests
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_CFLAGS := -Werror -Wall
+
+include $(BUILD_NATIVE_TEST)
diff --git a/services/audiopolicy/tests/AudioPolicyTestClient.h b/services/audiopolicy/tests/AudioPolicyTestClient.h
new file mode 100644
index 0000000..c4da98a
--- /dev/null
+++ b/services/audiopolicy/tests/AudioPolicyTestClient.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "AudioPolicyInterface.h"
+
+namespace android {
+
+class AudioPolicyTestClient : public AudioPolicyClientInterface
+{
+public:
+ virtual ~AudioPolicyTestClient() {}
+
+ // AudioPolicyClientInterface Implementation
+ audio_module_handle_t loadHwModule(const char* /*name*/) override { return 0; }
+ status_t openOutput(audio_module_handle_t /*module*/,
+ audio_io_handle_t* /*output*/,
+ audio_config_t* /*config*/,
+ audio_devices_t* /*devices*/,
+ const String8& /*address*/,
+ uint32_t* /*latencyMs*/,
+ audio_output_flags_t /*flags*/) override { return 0; }
+ audio_io_handle_t openDuplicateOutput(audio_io_handle_t /*output1*/,
+ audio_io_handle_t /*output2*/) override { return 0; }
+ status_t closeOutput(audio_io_handle_t /*output*/) override { return 0; }
+ status_t suspendOutput(audio_io_handle_t /*output*/) override { return 0; }
+ status_t restoreOutput(audio_io_handle_t /*output*/) override { return 0; }
+ status_t openInput(audio_module_handle_t /*module*/,
+ audio_io_handle_t* /*input*/,
+ audio_config_t* /*config*/,
+ audio_devices_t* /*device*/,
+ const String8& /*address*/,
+ audio_source_t /*source*/,
+ audio_input_flags_t /*flags*/) override { return 0; }
+ status_t closeInput(audio_io_handle_t /*input*/) override { return 0; }
+ status_t setStreamVolume(audio_stream_type_t /*stream*/,
+ float /*volume*/,
+ audio_io_handle_t /*output*/,
+ int /*delayMs*/) override { return 0; }
+ status_t invalidateStream(audio_stream_type_t /*stream*/) override { return 0; }
+ void setParameters(audio_io_handle_t /*ioHandle*/,
+ const String8& /*keyValuePairs*/,
+ int /*delayMs*/) override { }
+ String8 getParameters(audio_io_handle_t /*ioHandle*/,
+ const String8& /*keys*/) override { return String8(); }
+ status_t startTone(audio_policy_tone_t /*tone*/,
+ audio_stream_type_t /*stream*/) override { return 0; }
+ status_t stopTone() override { return 0; }
+ status_t setVoiceVolume(float /*volume*/, int /*delayMs*/) override { return 0; }
+ status_t moveEffects(audio_session_t /*session*/,
+ audio_io_handle_t /*srcOutput*/,
+ audio_io_handle_t /*dstOutput*/) override { return 0; }
+ status_t createAudioPatch(const struct audio_patch* /*patch*/,
+ audio_patch_handle_t* /*handle*/,
+ int /*delayMs*/) override { return 0; }
+ status_t releaseAudioPatch(audio_patch_handle_t /*handle*/,
+ int /*delayMs*/) override { return 0; }
+ status_t setAudioPortConfig(const struct audio_port_config* /*config*/,
+ int /*delayMs*/) override { return 0; }
+ void onAudioPortListUpdate() override { }
+ void onAudioPatchListUpdate() override { }
+ audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t /*use*/) override { return 0; }
+ void onDynamicPolicyMixStateUpdate(String8 /*regId*/, int32_t /*state*/) override { }
+ void onRecordingConfigurationUpdate(int /*event*/,
+ const record_client_info_t* /*clientInfo*/,
+ const struct audio_config_base* /*clientConfig*/,
+ const struct audio_config_base* /*deviceConfig*/,
+ audio_patch_handle_t /*patchHandle*/) override { }
+};
+
+} // namespace android
diff --git a/services/audiopolicy/tests/AudioPolicyTestManager.h b/services/audiopolicy/tests/AudioPolicyTestManager.h
new file mode 100644
index 0000000..fe543a6
--- /dev/null
+++ b/services/audiopolicy/tests/AudioPolicyTestManager.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "managerdefault/AudioPolicyManager.h"
+
+namespace android {
+
+class AudioPolicyTestManager : public AudioPolicyManager {
+ public:
+ explicit AudioPolicyTestManager(AudioPolicyClientInterface *clientInterface)
+ : AudioPolicyManager(clientInterface, true /*forTesting*/) { }
+ using AudioPolicyManager::getConfig;
+ using AudioPolicyManager::initialize;
+};
+
+} // namespace android
diff --git a/services/audiopolicy/tests/audiopolicymanager_tests.cpp b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
new file mode 100644
index 0000000..33b15c7
--- /dev/null
+++ b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include "AudioPolicyTestClient.h"
+#include "AudioPolicyTestManager.h"
+
+using namespace android;
+
+TEST(AudioPolicyManager, CreateWithDummyClient) {
+ AudioPolicyTestClient client;
+ AudioPolicyTestManager manager(&client);
+ manager.getConfig().setDefault();
+ ASSERT_EQ(NO_INIT, manager.initialize());
+}