xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/win/screen_capturer_win_directx_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_capturer_win_directx.h"
12 
13 #include <string>
14 #include <vector>
15 
16 #include "modules/desktop_capture/desktop_capturer.h"
17 #include "test/gtest.h"
18 
19 namespace webrtc {
20 
21 // This test cannot ensure GetScreenListFromDeviceNames() won't reorder the
22 // devices in its output, since the device name is missing.
TEST(ScreenCaptureUtilsTest,GetScreenListFromDeviceNamesAndGetIndex)23 TEST(ScreenCaptureUtilsTest, GetScreenListFromDeviceNamesAndGetIndex) {
24   const std::vector<std::string> device_names = {
25       "\\\\.\\DISPLAY0",
26       "\\\\.\\DISPLAY1",
27       "\\\\.\\DISPLAY2",
28   };
29   DesktopCapturer::SourceList screens;
30   ASSERT_TRUE(ScreenCapturerWinDirectx::GetScreenListFromDeviceNames(
31       device_names, &screens));
32   ASSERT_EQ(device_names.size(), screens.size());
33 
34   for (size_t i = 0; i < screens.size(); i++) {
35     ASSERT_EQ(ScreenCapturerWinDirectx::GetIndexFromScreenId(screens[i].id,
36                                                              device_names),
37               static_cast<int>(i));
38   }
39 }
40 
41 }  // namespace webrtc
42