Home | History | Annotate | Download | only in devices
      1 /*
      2  * libjingle
      3  * Copyright 2004 Google Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are met:
      7  *
      8  *  1. Redistributions of source code must retain the above copyright notice,
      9  *     this list of conditions and the following disclaimer.
     10  *  2. Redistributions in binary form must reproduce the above copyright notice,
     11  *     this list of conditions and the following disclaimer in the documentation
     12  *     and/or other materials provided with the distribution.
     13  *  3. The name of the author may not be used to endorse or promote products
     14  *     derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #include "talk/media/devices/dummydevicemanager.h"
     29 #include "webrtc/base/gunit.h"
     30 
     31 using cricket::Device;
     32 using cricket::DummyDeviceManager;
     33 
     34 // Test that we startup/shutdown properly.
     35 TEST(DummyDeviceManagerTest, StartupShutdown) {
     36   DummyDeviceManager dm;
     37   EXPECT_TRUE(dm.Init());
     38   dm.Terminate();
     39 }
     40 
     41 // Test enumerating capabilities.
     42 TEST(DummyDeviceManagerTest, GetCapabilities) {
     43   DummyDeviceManager dm;
     44   int capabilities = dm.GetCapabilities();
     45   EXPECT_EQ((cricket::AUDIO_SEND | cricket::AUDIO_RECV |
     46       cricket::VIDEO_SEND | cricket::VIDEO_RECV), capabilities);
     47 }
     48 
     49 // Test enumerating devices.
     50 TEST(DummyDeviceManagerTest, GetDevices) {
     51   DummyDeviceManager dm;
     52   EXPECT_TRUE(dm.Init());
     53   std::vector<Device> audio_ins, audio_outs, video_ins;
     54   EXPECT_TRUE(dm.GetAudioInputDevices(&audio_ins));
     55   EXPECT_TRUE(dm.GetAudioOutputDevices(&audio_outs));
     56   EXPECT_TRUE(dm.GetVideoCaptureDevices(&video_ins));
     57 }
     58 
     59 // Test that we return correct ids for default and bogus devices.
     60 TEST(DummyDeviceManagerTest, GetAudioDeviceIds) {
     61   DummyDeviceManager dm;
     62   Device device;
     63   EXPECT_TRUE(dm.Init());
     64   EXPECT_TRUE(dm.GetAudioInputDevice(
     65       cricket::DeviceManagerInterface::kDefaultDeviceName, &device));
     66   EXPECT_EQ("-1", device.id);
     67   EXPECT_TRUE(dm.GetAudioOutputDevice(
     68       cricket::DeviceManagerInterface::kDefaultDeviceName, &device));
     69   EXPECT_EQ("-1", device.id);
     70   EXPECT_FALSE(dm.GetAudioInputDevice("_NOT A REAL DEVICE_", &device));
     71   EXPECT_FALSE(dm.GetAudioOutputDevice("_NOT A REAL DEVICE_", &device));
     72 }
     73 
     74 // Test that we get the video capture device by name properly.
     75 TEST(DummyDeviceManagerTest, GetVideoDeviceIds) {
     76   DummyDeviceManager dm;
     77   Device device;
     78   EXPECT_TRUE(dm.Init());
     79   EXPECT_FALSE(dm.GetVideoCaptureDevice("_NOT A REAL DEVICE_", &device));
     80   EXPECT_TRUE(dm.GetVideoCaptureDevice(
     81       cricket::DeviceManagerInterface::kDefaultDeviceName, &device));
     82 }
     83 
     84 TEST(DummyDeviceManagerTest, VerifyDevicesListsAreCleared) {
     85   const std::string imaginary("_NOT A REAL DEVICE_");
     86   DummyDeviceManager dm;
     87   std::vector<Device> audio_ins, audio_outs, video_ins;
     88   audio_ins.push_back(Device(imaginary, imaginary));
     89   audio_outs.push_back(Device(imaginary, imaginary));
     90   video_ins.push_back(Device(imaginary, imaginary));
     91   EXPECT_TRUE(dm.Init());
     92   EXPECT_TRUE(dm.GetAudioInputDevices(&audio_ins));
     93   EXPECT_TRUE(dm.GetAudioOutputDevices(&audio_outs));
     94   EXPECT_TRUE(dm.GetVideoCaptureDevices(&video_ins));
     95   for (size_t i = 0; i < audio_ins.size(); ++i) {
     96     EXPECT_NE(imaginary, audio_ins[i].name);
     97   }
     98   for (size_t i = 0; i < audio_outs.size(); ++i) {
     99     EXPECT_NE(imaginary, audio_outs[i].name);
    100   }
    101   for (size_t i = 0; i < video_ins.size(); ++i) {
    102     EXPECT_NE(imaginary, video_ins[i].name);
    103   }
    104 }
    105