Commit ba0c9a6b authored by Olga Sharonova's avatar Olga Sharonova Committed by Commit Bot

Make AudioSystem unit tests reusable for different implementations

Introducing type-parametrized tests verifying that a given AudioSystem implementation is correct.
This will allow to re-use tests for AudioSystem implementation on top of Mojo Audio service.

Bug: 740943
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: If69ee76bce05f0dcfab6abeb31af95959149ca9d
Reviewed-on: https://chromium-review.googlesource.com/707142
Commit-Queue: Olga Sharonova <olka@chromium.org>
Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517807}
parent 45fce0dc
...@@ -333,6 +333,8 @@ static_library("test_support") { ...@@ -333,6 +333,8 @@ static_library("test_support") {
sources = [ sources = [
"audio_device_info_accessor_for_tests.cc", "audio_device_info_accessor_for_tests.cc",
"audio_device_info_accessor_for_tests.h", "audio_device_info_accessor_for_tests.h",
"audio_system_test_util.cc",
"audio_system_test_util.h",
"audio_unittest_util.cc", "audio_unittest_util.cc",
"audio_unittest_util.h", "audio_unittest_util.h",
"mock_audio_manager.cc", "mock_audio_manager.cc",
......
This diff is collapsed.
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/audio_system_test_util.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
namespace media {
bool operator==(const AudioDeviceDescription& lhs,
const AudioDeviceDescription& rhs) {
return lhs.device_name == rhs.device_name && lhs.unique_id == rhs.unique_id &&
lhs.group_id == rhs.group_id;
}
AudioSystem::OnAudioParamsCallback
AudioSystemCallbackExpectations::GetAudioParamsCallback(
const base::Location& location,
base::OnceClosure on_cb_received,
const base::Optional<AudioParameters>& expected_params) {
return base::BindOnce(&AudioSystemCallbackExpectations::OnAudioParams,
base::Unretained(this), location.ToString(),
std::move(on_cb_received), expected_params);
}
AudioSystem::OnBoolCallback AudioSystemCallbackExpectations::GetBoolCallback(
const base::Location& location,
base::OnceClosure on_cb_received,
bool expected) {
return base::BindOnce(&AudioSystemCallbackExpectations::OnBool,
base::Unretained(this), location.ToString(),
std::move(on_cb_received), expected);
}
AudioSystem::OnDeviceDescriptionsCallback
AudioSystemCallbackExpectations::GetDeviceDescriptionsCallback(
const base::Location& location,
base::OnceClosure on_cb_received,
const AudioDeviceDescriptions& expected_descriptions) {
return base::BindOnce(&AudioSystemCallbackExpectations::OnDeviceDescriptions,
base::Unretained(this), location.ToString(),
std::move(on_cb_received), expected_descriptions);
}
AudioSystem::OnInputDeviceInfoCallback
AudioSystemCallbackExpectations::GetInputDeviceInfoCallback(
const base::Location& location,
base::OnceClosure on_cb_received,
const base::Optional<AudioParameters>& expected_input,
const base::Optional<AudioParameters>& expected_associated_output,
const std::string& expected_associated_device_id) {
return base::BindOnce(&AudioSystemCallbackExpectations::OnInputDeviceInfo,
base::Unretained(this), location.ToString(),
std::move(on_cb_received), expected_input,
expected_associated_output,
expected_associated_device_id);
}
AudioSystem::OnDeviceIdCallback
AudioSystemCallbackExpectations::GetDeviceIdCallback(
const base::Location& location,
base::OnceClosure on_cb_received,
const std::string& expected_id) {
return base::BindOnce(&AudioSystemCallbackExpectations::OnDeviceId,
base::Unretained(this), location.ToString(),
std::move(on_cb_received), expected_id);
}
void AudioSystemCallbackExpectations::OnAudioParams(
const std::string& from_here,
base::OnceClosure on_cb_received,
const base::Optional<AudioParameters>& expected,
const base::Optional<AudioParameters>& received) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_) << from_here;
if (expected) {
EXPECT_TRUE(received) << from_here;
EXPECT_EQ(expected->AsHumanReadableString(),
received->AsHumanReadableString())
<< from_here;
} else {
EXPECT_FALSE(received) << from_here;
}
std::move(on_cb_received).Run();
}
void AudioSystemCallbackExpectations::OnBool(const std::string& from_here,
base::OnceClosure on_cb_received,
bool expected,
bool result) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_) << from_here;
EXPECT_EQ(expected, result) << from_here;
std::move(on_cb_received).Run();
}
void AudioSystemCallbackExpectations::OnDeviceDescriptions(
const std::string& from_here,
base::OnceClosure on_cb_received,
const AudioDeviceDescriptions& expected_descriptions,
AudioDeviceDescriptions descriptions) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_) << from_here;
EXPECT_EQ(expected_descriptions, descriptions);
std::move(on_cb_received).Run();
}
void AudioSystemCallbackExpectations::OnInputDeviceInfo(
const std::string& from_here,
base::OnceClosure on_cb_received,
const base::Optional<AudioParameters>& expected_input,
const base::Optional<AudioParameters>& expected_associated_output,
const std::string& expected_associated_device_id,
const base::Optional<AudioParameters>& input,
const base::Optional<AudioParameters>& associated_output,
const std::string& associated_device_id) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_) << from_here;
if (expected_input) {
EXPECT_TRUE(input) << from_here;
EXPECT_EQ(expected_input->AsHumanReadableString(),
input->AsHumanReadableString())
<< from_here;
} else {
EXPECT_FALSE(input) << from_here;
}
if (expected_associated_output) {
EXPECT_TRUE(associated_output) << from_here;
EXPECT_EQ(expected_associated_output->AsHumanReadableString(),
associated_output->AsHumanReadableString())
<< from_here;
} else {
EXPECT_FALSE(associated_output) << from_here;
}
EXPECT_EQ(expected_associated_device_id, associated_device_id) << from_here;
std::move(on_cb_received).Run();
}
void AudioSystemCallbackExpectations::OnDeviceId(
const std::string& from_here,
base::OnceClosure on_cb_received,
const std::string& expected_id,
const std::string& result_id) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_) << from_here;
EXPECT_EQ(expected_id, result_id) << from_here;
std::move(on_cb_received).Run();
}
} // namespace media
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment