2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
13 #include "webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
15 using namespace webrtc;
17 class HardwareBeforeStreamingTest : public AfterInitializationFixture {
20 // Tests that apply to both mobile and desktop:
22 TEST_F(HardwareBeforeStreamingTest,
23 SetAudioDeviceLayerFailsSinceTheVoiceEngineHasBeenInitialized) {
24 EXPECT_NE(0, voe_hardware_->SetAudioDeviceLayer(kAudioPlatformDefault));
25 EXPECT_EQ(VE_ALREADY_INITED, voe_base_->LastError());
28 TEST_F(HardwareBeforeStreamingTest,
29 GetCPULoadSucceedsOnWindowsButNotOtherPlatforms) {
32 EXPECT_EQ(0, voe_hardware_->GetCPULoad(load_percent));
34 EXPECT_NE(0, voe_hardware_->GetCPULoad(load_percent)) <<
35 "Should fail on non-Windows platforms.";
39 // Tests that only apply to mobile:
42 TEST_F(HardwareBeforeStreamingTest, ResetsAudioDeviceOnIphone) {
43 EXPECT_EQ(0, voe_hardware_->ResetAudioDevice());
47 // Tests that only apply to desktop:
48 #if !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID)
50 static const char* kNoDevicesErrorMessage =
51 "Either you have no recording / playout device "
52 "on your system, or the method failed.";
54 TEST_F(HardwareBeforeStreamingTest, GetPlayoutDeviceStatusReturnsTrue) {
55 bool play_available = false;
56 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceStatus(play_available));
57 ASSERT_TRUE(play_available) <<
58 "Ensures that the method works and that hardware is in the right state.";
61 TEST_F(HardwareBeforeStreamingTest, GetRecordingDeviceStatusReturnsTrue) {
62 bool recording_available = false;
63 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceStatus(recording_available));
64 EXPECT_TRUE(recording_available) <<
65 "Ensures that the method works and that hardware is in the right state.";
68 // Win, Mac and Linux sound device tests.
69 TEST_F(HardwareBeforeStreamingTest,
70 GetRecordingDeviceNameRetrievesDeviceNames) {
71 char device_name[128] = {0};
72 char guid_name[128] = {0};
75 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
76 -1, device_name, guid_name));
77 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
78 device_name[0] = '\0';
80 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
81 -1, device_name, guid_name));
82 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
85 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
86 0, device_name, guid_name));
87 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
88 device_name[0] = '\0';
90 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
91 0, device_name, guid_name));
92 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
96 TEST_F(HardwareBeforeStreamingTest,
97 AllEnumeratedRecordingDevicesCanBeSetAsRecordingDevice) {
98 // Check recording side.
99 // Extended Win32 enumeration tests: unique GUID outputs on Vista and up:
100 // Win XP and below : device_name is copied to guid_name.
101 // Win Vista and up : device_name is the friendly name and GUID is a unique
103 // Other : guid_name is left unchanged.
104 int num_of_recording_devices = 0;
105 EXPECT_EQ(0, voe_hardware_->GetNumOfRecordingDevices(
106 num_of_recording_devices));
107 EXPECT_GT(num_of_recording_devices, 0) << kNoDevicesErrorMessage;
109 char device_name[128] = {0};
110 char guid_name[128] = {0};
112 for (int i = 0; i < num_of_recording_devices; i++) {
113 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
114 i, device_name, guid_name));
115 EXPECT_GT(strlen(device_name), 0u) <<
116 "There should be no empty device names "
117 "among the ones the system gives us.";
118 EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(i));
122 TEST_F(HardwareBeforeStreamingTest,
123 AllEnumeratedPlayoutDevicesCanBeSetAsPlayoutDevice) {
124 // Check playout side (see recording side test for more info on GUIDs).
125 int num_of_playout_devices = 0;
126 EXPECT_EQ(0, voe_hardware_->GetNumOfPlayoutDevices(
127 num_of_playout_devices));
128 EXPECT_GT(num_of_playout_devices, 0) << kNoDevicesErrorMessage;
130 char device_name[128] = {0};
131 char guid_name[128] = {0};
133 for (int i = 0; i < num_of_playout_devices; ++i) {
134 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
135 i, device_name, guid_name));
136 EXPECT_GT(strlen(device_name), 0u) <<
137 "There should be no empty device names "
138 "among the ones the system gives us.";
139 EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(i));
143 TEST_F(HardwareBeforeStreamingTest,
144 SetDeviceWithMagicalArgumentsSetsDefaultSoundDevices) {
146 // -1 means "default device" on Windows.
147 EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(-1));
148 EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(-1));
150 EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(0));
151 EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(0));
155 #endif // !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID)