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 
35   // Win, Mac and Linux sound device tests.
TEST_F(HardwareBeforeStreamingTest,GetRecordingDeviceNameRetrievesDeviceNames)36 TEST_F(HardwareBeforeStreamingTest,
37        GetRecordingDeviceNameRetrievesDeviceNames) {
38   char device_name[128] = {0};
39   char guid_name[128] = {0};
40 
41 #ifdef _WIN32
42   EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
43       -1, device_name, guid_name));
44   EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
45   device_name[0] = '\0';
46 
47   EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
48       -1, device_name, guid_name));
49   EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
50 
51 #else
52   EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
53       0, device_name, guid_name));
54   EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
55   device_name[0] = '\0';
56 
57   EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
58       0, device_name, guid_name));
59   EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
60 #endif  // !WIN32
61 }
62 
TEST_F(HardwareBeforeStreamingTest,AllEnumeratedRecordingDevicesCanBeSetAsRecordingDevice)63 TEST_F(HardwareBeforeStreamingTest,
64        AllEnumeratedRecordingDevicesCanBeSetAsRecordingDevice) {
65   // Check recording side.
66   // Extended Win32 enumeration tests: unique GUID outputs on Vista and up:
67   // Win XP and below : device_name is copied to guid_name.
68   // Win Vista and up : device_name is the friendly name and GUID is a unique
69   //                    identifier.
70   // Other            : guid_name is left unchanged.
71   int num_of_recording_devices = 0;
72   EXPECT_EQ(0, voe_hardware_->GetNumOfRecordingDevices(
73       num_of_recording_devices));
74   EXPECT_GT(num_of_recording_devices, 0) << kNoDevicesErrorMessage;
75 
76   char device_name[128] = {0};
77   char guid_name[128] = {0};
78 
79   for (int i = 0; i < num_of_recording_devices; i++) {
80     EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
81         i, device_name, guid_name));
82     EXPECT_GT(strlen(device_name), 0u) <<
83         "There should be no empty device names "
84         "among the ones the system gives us.";
85     EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(i));
86   }
87 }
88 
TEST_F(HardwareBeforeStreamingTest,AllEnumeratedPlayoutDevicesCanBeSetAsPlayoutDevice)89 TEST_F(HardwareBeforeStreamingTest,
90        AllEnumeratedPlayoutDevicesCanBeSetAsPlayoutDevice) {
91   // Check playout side (see recording side test for more info on GUIDs).
92   int num_of_playout_devices = 0;
93   EXPECT_EQ(0, voe_hardware_->GetNumOfPlayoutDevices(
94       num_of_playout_devices));
95   EXPECT_GT(num_of_playout_devices, 0) << kNoDevicesErrorMessage;
96 
97   char device_name[128] = {0};
98   char guid_name[128] = {0};
99 
100   for (int i = 0; i < num_of_playout_devices; ++i) {
101     EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
102         i, device_name, guid_name));
103     EXPECT_GT(strlen(device_name), 0u) <<
104         "There should be no empty device names "
105         "among the ones the system gives us.";
106     EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(i));
107   }
108 }
109 
TEST_F(HardwareBeforeStreamingTest,SetDeviceWithMagicalArgumentsSetsDefaultSoundDevices)110 TEST_F(HardwareBeforeStreamingTest,
111        SetDeviceWithMagicalArgumentsSetsDefaultSoundDevices) {
112 #ifdef _WIN32
113   // -1 means "default device" on Windows.
114   EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(-1));
115   EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(-1));
116 #else
117   EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(0));
118   EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(0));
119 #endif
120 }
121 
122 #endif // !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID)
123