screen_capture_utils_unittest.cc (2480B)
1 /* 2 * Copyright (c) 2017 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 "modules/desktop_capture/win/screen_capture_utils.h" 12 13 #include <string> 14 #include <vector> 15 16 #include "modules/desktop_capture/desktop_capture_types.h" 17 #include "modules/desktop_capture/desktop_capturer.h" 18 #include "rtc_base/logging.h" 19 #include "test/gtest.h" 20 21 namespace webrtc { 22 23 TEST(ScreenCaptureUtilsTest, GetScreenList) { 24 DesktopCapturer::SourceList screens; 25 std::vector<std::string> device_names; 26 27 ASSERT_TRUE(GetScreenList(&screens)); 28 screens.clear(); 29 ASSERT_TRUE(GetScreenList(&screens, &device_names)); 30 31 ASSERT_EQ(screens.size(), device_names.size()); 32 } 33 34 TEST(ScreenCaptureUtilsTest, DeviceIndexToHmonitor) { 35 DesktopCapturer::SourceList screens; 36 ASSERT_TRUE(GetScreenList(&screens)); 37 if (screens.empty()) { 38 RTC_LOG(LS_INFO) 39 << "Skip ScreenCaptureUtilsTest on systems with no monitors."; 40 GTEST_SKIP(); 41 } 42 43 HMONITOR hmonitor; 44 ASSERT_TRUE(GetHmonitorFromDeviceIndex(screens[0].id, &hmonitor)); 45 ASSERT_TRUE(IsMonitorValid(hmonitor)); 46 } 47 48 TEST(ScreenCaptureUtilsTest, FullScreenDeviceIndexToHmonitor) { 49 if (!HasActiveDisplay()) { 50 RTC_LOG(LS_INFO) 51 << "Skip ScreenCaptureUtilsTest on systems with no monitors."; 52 GTEST_SKIP(); 53 } 54 55 HMONITOR hmonitor; 56 ASSERT_TRUE(GetHmonitorFromDeviceIndex(kFullDesktopScreenId, &hmonitor)); 57 ASSERT_EQ(hmonitor, static_cast<HMONITOR>(0)); 58 ASSERT_TRUE(IsMonitorValid(hmonitor)); 59 } 60 61 TEST(ScreenCaptureUtilsTest, NoMonitors) { 62 if (HasActiveDisplay()) { 63 RTC_LOG(LS_INFO) << "Skip ScreenCaptureUtilsTest designed specifically for " 64 "systems with no monitors"; 65 GTEST_SKIP(); 66 } 67 68 HMONITOR hmonitor; 69 ASSERT_TRUE(GetHmonitorFromDeviceIndex(kFullDesktopScreenId, &hmonitor)); 70 ASSERT_EQ(hmonitor, static_cast<HMONITOR>(0)); 71 72 // The monitor should be invalid since the system has no attached displays. 73 ASSERT_FALSE(IsMonitorValid(hmonitor)); 74 } 75 76 TEST(ScreenCaptureUtilsTest, InvalidDeviceIndexToHmonitor) { 77 HMONITOR hmonitor; 78 ASSERT_FALSE(GetHmonitorFromDeviceIndex(kInvalidScreenId, &hmonitor)); 79 } 80 81 } // namespace webrtc