1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
media / gpu / windows / d3d11_video_device_format_support_unittest.cc [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "media/base/media_util.h"
#include "media/base/win/d3d11_mocks.h"
#include "media/gpu/windows/d3d11_video_device_format_support.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
using ::testing::Combine;
using ::testing::DoAll;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::Values;
namespace media {
class FormatSupportCheckerUnittest : public ::testing::Test {};
TEST_F(FormatSupportCheckerUnittest, NullDeviceDoesntCrash) {
FormatSupportChecker checker(nullptr);
// Init and Check should both fail, but not crash.
EXPECT_FALSE(checker.Initialize());
EXPECT_FALSE(checker.CheckOutputFormatSupport(DXGI_FORMAT_NV12));
}
TEST_F(FormatSupportCheckerUnittest, CheckInitializationCantCast) {
auto device = MakeComPtr<NiceMock<D3D11DeviceMock>>();
auto vdevice = MakeComPtr<NiceMock<D3D11VideoDeviceMock>>();
auto enumerator = MakeComPtr<NiceMock<D3D11VideoProcessorEnumeratorMock>>();
ON_CALL(*device.Get(), QueryInterface(IID_ID3D11VideoDevice, _))
.WillByDefault(SetComPointeeAndReturnOk<1>(vdevice.Get()));
EXPECT_CALL(*vdevice.Get(), CreateVideoProcessorEnumerator(_, _))
.WillOnce(SetComPointeeAndReturnOk<1>(enumerator.Get()));
EXPECT_CALL(*device.Get(), CheckFormatSupport(_, _)).WillOnce(Return(S_OK));
EXPECT_CALL(*enumerator.Get(), CheckVideoProcessorFormat(_, _))
.WillOnce(Return(S_OK));
FormatSupportChecker checker(device);
EXPECT_TRUE(checker.Initialize());
}
TEST_F(FormatSupportCheckerUnittest, CheckFormatSupportWorks) {
auto device = MakeComPtr<NiceMock<D3D11DeviceMock>>();
auto vdevice = MakeComPtr<NiceMock<D3D11VideoDeviceMock>>();
auto enumerator = MakeComPtr<NiceMock<D3D11VideoProcessorEnumeratorMock>>();
ON_CALL(*device.Get(), QueryInterface(IID_ID3D11VideoDevice, _))
.WillByDefault(SetComPointeeAndReturnOk<1>(vdevice.Get()));
EXPECT_CALL(*vdevice.Get(), CreateVideoProcessorEnumerator(_, _))
.WillOnce(SetComPointeeAndReturnOk<1>(enumerator.Get()));
EXPECT_CALL(*device.Get(), CheckFormatSupport(_, _)).WillOnce(Return(S_OK));
EXPECT_CALL(*enumerator.Get(), CheckVideoProcessorFormat(_, _))
.WillOnce(Return(S_OK));
FormatSupportChecker checker(device);
EXPECT_TRUE(checker.Initialize());
UINT enumerator_outcome = D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_OUTPUT;
UINT device_outcome = D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT;
EXPECT_CALL(*enumerator.Get(), CheckVideoProcessorFormat(_, _))
.WillOnce(DoAll(SetArgPointee<1>(enumerator_outcome), Return(S_OK)));
EXPECT_CALL(*device.Get(), CheckFormatSupport(_, _))
.WillOnce(DoAll(SetArgPointee<1>(device_outcome), Return(S_OK)));
EXPECT_TRUE(checker.CheckOutputFormatSupport(DXGI_FORMAT_NV12));
}
TEST_F(FormatSupportCheckerUnittest, CheckFormatSupportRequiresBoth) {
auto device = MakeComPtr<NiceMock<D3D11DeviceMock>>();
auto vdevice = MakeComPtr<NiceMock<D3D11VideoDeviceMock>>();
auto enumerator = MakeComPtr<NiceMock<D3D11VideoProcessorEnumeratorMock>>();
ON_CALL(*device.Get(), QueryInterface(IID_ID3D11VideoDevice, _))
.WillByDefault(SetComPointeeAndReturnOk<1>(vdevice.Get()));
EXPECT_CALL(*vdevice.Get(), CreateVideoProcessorEnumerator(_, _))
.WillOnce(SetComPointeeAndReturnOk<1>(enumerator.Get()));
EXPECT_CALL(*device.Get(), CheckFormatSupport(_, _)).WillOnce(Return(S_OK));
EXPECT_CALL(*enumerator.Get(), CheckVideoProcessorFormat(_, _))
.WillOnce(Return(S_OK));
FormatSupportChecker checker(device);
EXPECT_TRUE(checker.Initialize());
UINT enumerator_outcome = D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_OUTPUT;
UINT device_outcome = 0;
EXPECT_CALL(*enumerator.Get(), CheckVideoProcessorFormat(_, _))
.WillOnce(DoAll(SetArgPointee<1>(enumerator_outcome), Return(S_OK)));
EXPECT_CALL(*device.Get(), CheckFormatSupport(_, _))
.WillOnce(DoAll(SetArgPointee<1>(device_outcome), Return(S_OK)));
EXPECT_FALSE(checker.CheckOutputFormatSupport(DXGI_FORMAT_NV12));
}
} // namespace media