andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 50ff6a5 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <string.h> |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | be72fe4 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 13 | #include "webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h" |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace webrtc; |
| 16 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 17 | class HardwareBeforeStreamingTest : public AfterInitializationFixture { |
| 18 | }; |
| 19 | |
| 20 | // Tests that apply to both mobile and desktop: |
| 21 | |
| 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 | TEST_F(HardwareBeforeStreamingTest, |
| 29 | GetCPULoadSucceedsOnWindowsButNotOtherPlatforms) { |
| 30 | int load_percent; |
| 31 | #if defined(_WIN32) |
| 32 | EXPECT_EQ(0, voe_hardware_->GetCPULoad(load_percent)); |
| 33 | #else |
| 34 | EXPECT_NE(0, voe_hardware_->GetCPULoad(load_percent)) << |
| 35 | "Should fail on non-Windows platforms."; |
| 36 | #endif |
| 37 | } |
| 38 | |
| 39 | // Tests that only apply to mobile: |
| 40 | |
| 41 | #ifdef WEBRTC_IOS |
| 42 | TEST_F(HardwareBeforeStreamingTest, ResetsAudioDeviceOnIphone) { |
| 43 | EXPECT_EQ(0, voe_hardware_->ResetAudioDevice()); |
| 44 | } |
| 45 | #endif |
| 46 | |
| 47 | // Tests that only apply to desktop: |
| 48 | #if !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID) |
| 49 | |
fischman@webrtc.org | a738ae3 | 2014-04-15 20:26:41 +0000 | [diff] [blame] | 50 | static const char* kNoDevicesErrorMessage = |
| 51 | "Either you have no recording / playout device " |
| 52 | "on your system, or the method failed."; |
| 53 | |
henrika@webrtc.org | 28e9b66 | 2014-05-09 11:10:50 +0000 | [diff] [blame^] | 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."; |
| 59 | } |
| 60 | |
| 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."; |
| 66 | } |
| 67 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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}; |
| 73 | |
| 74 | #ifdef _WIN32 |
| 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'; |
| 79 | |
| 80 | EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName( |
| 81 | -1, device_name, guid_name)); |
| 82 | EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage; |
| 83 | |
| 84 | #else |
| 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'; |
| 89 | |
| 90 | EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName( |
| 91 | 0, device_name, guid_name)); |
| 92 | EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage; |
| 93 | #endif // !WIN32 |
| 94 | } |
| 95 | |
| 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 |
| 102 | // identifier. |
| 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; |
| 108 | |
| 109 | char device_name[128] = {0}; |
| 110 | char guid_name[128] = {0}; |
| 111 | |
| 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)); |
| 119 | } |
| 120 | } |
| 121 | |
| 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; |
| 129 | |
| 130 | char device_name[128] = {0}; |
| 131 | char guid_name[128] = {0}; |
| 132 | |
| 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)); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | TEST_F(HardwareBeforeStreamingTest, |
| 144 | SetDeviceWithMagicalArgumentsSetsDefaultSoundDevices) { |
| 145 | #ifdef _WIN32 |
| 146 | // -1 means "default device" on Windows. |
| 147 | EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(-1)); |
| 148 | EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(-1)); |
| 149 | #else |
| 150 | EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(0)); |
| 151 | EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(0)); |
| 152 | #endif |
| 153 | } |
| 154 | |
| 155 | #endif // !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID) |