1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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.
9 */
10
11 #include <string.h>
12
13 #include "webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
14
15 using namespace webrtc;
16
17 class HardwareBeforeStreamingTest : public AfterInitializationFixture {
18 };
19
20 // Tests that apply to both mobile and desktop:
21
TEST_F(HardwareBeforeStreamingTest,SetAudioDeviceLayerFailsSinceTheVoiceEngineHasBeenInitialized)22 TEST_F(HardwareBeforeStreamingTest,
23 SetAudioDeviceLayerFailsSinceTheVoiceEngineHasBeenInitialized) {
24 EXPECT_NE(0, voe_hardware_->SetAudioDeviceLayer(kAudioPlatformDefault));
25 EXPECT_EQ(VE_ALREADY_INITED, voe_base_->LastError());
26 }
27
28 // Tests that only apply to desktop:
29 #if !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID)
30
31 static const char* kNoDevicesErrorMessage =
32 "Either you have no recording / playout device "
33 "on your system, or the method failed.";
34
TEST_F(HardwareBeforeStreamingTest,GetPlayoutDeviceStatusReturnsTrue)35 TEST_F(HardwareBeforeStreamingTest, GetPlayoutDeviceStatusReturnsTrue) {
36 bool play_available = false;
37 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceStatus(play_available));
38 ASSERT_TRUE(play_available) <<
39 "Ensures that the method works and that hardware is in the right state.";
40 }
41
TEST_F(HardwareBeforeStreamingTest,GetRecordingDeviceStatusReturnsTrue)42 TEST_F(HardwareBeforeStreamingTest, GetRecordingDeviceStatusReturnsTrue) {
43 bool recording_available = false;
44 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceStatus(recording_available));
45 EXPECT_TRUE(recording_available) <<
46 "Ensures that the method works and that hardware is in the right state.";
47 }
48
49 // Win, Mac and Linux sound device tests.
TEST_F(HardwareBeforeStreamingTest,GetRecordingDeviceNameRetrievesDeviceNames)50 TEST_F(HardwareBeforeStreamingTest,
51 GetRecordingDeviceNameRetrievesDeviceNames) {
52 char device_name[128] = {0};
53 char guid_name[128] = {0};
54
55 #ifdef _WIN32
56 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
57 -1, device_name, guid_name));
58 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
59 device_name[0] = '\0';
60
61 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
62 -1, device_name, guid_name));
63 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
64
65 #else
66 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
67 0, device_name, guid_name));
68 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
69 device_name[0] = '\0';
70
71 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
72 0, device_name, guid_name));
73 EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
74 #endif // !WIN32
75 }
76
TEST_F(HardwareBeforeStreamingTest,AllEnumeratedRecordingDevicesCanBeSetAsRecordingDevice)77 TEST_F(HardwareBeforeStreamingTest,
78 AllEnumeratedRecordingDevicesCanBeSetAsRecordingDevice) {
79 // Check recording side.
80 // Extended Win32 enumeration tests: unique GUID outputs on Vista and up:
81 // Win XP and below : device_name is copied to guid_name.
82 // Win Vista and up : device_name is the friendly name and GUID is a unique
83 // identifier.
84 // Other : guid_name is left unchanged.
85 int num_of_recording_devices = 0;
86 EXPECT_EQ(0, voe_hardware_->GetNumOfRecordingDevices(
87 num_of_recording_devices));
88 EXPECT_GT(num_of_recording_devices, 0) << kNoDevicesErrorMessage;
89
90 char device_name[128] = {0};
91 char guid_name[128] = {0};
92
93 for (int i = 0; i < num_of_recording_devices; i++) {
94 EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
95 i, device_name, guid_name));
96 EXPECT_GT(strlen(device_name), 0u) <<
97 "There should be no empty device names "
98 "among the ones the system gives us.";
99 EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(i));
100 }
101 }
102
TEST_F(HardwareBeforeStreamingTest,AllEnumeratedPlayoutDevicesCanBeSetAsPlayoutDevice)103 TEST_F(HardwareBeforeStreamingTest,
104 AllEnumeratedPlayoutDevicesCanBeSetAsPlayoutDevice) {
105 // Check playout side (see recording side test for more info on GUIDs).
106 int num_of_playout_devices = 0;
107 EXPECT_EQ(0, voe_hardware_->GetNumOfPlayoutDevices(
108 num_of_playout_devices));
109 EXPECT_GT(num_of_playout_devices, 0) << kNoDevicesErrorMessage;
110
111 char device_name[128] = {0};
112 char guid_name[128] = {0};
113
114 for (int i = 0; i < num_of_playout_devices; ++i) {
115 EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
116 i, device_name, guid_name));
117 EXPECT_GT(strlen(device_name), 0u) <<
118 "There should be no empty device names "
119 "among the ones the system gives us.";
120 EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(i));
121 }
122 }
123
TEST_F(HardwareBeforeStreamingTest,SetDeviceWithMagicalArgumentsSetsDefaultSoundDevices)124 TEST_F(HardwareBeforeStreamingTest,
125 SetDeviceWithMagicalArgumentsSetsDefaultSoundDevices) {
126 #ifdef _WIN32
127 // -1 means "default device" on Windows.
128 EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(-1));
129 EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(-1));
130 #else
131 EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(0));
132 EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(0));
133 #endif
134 }
135
136 #endif // !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID)
137