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