1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hdi_device.h"
17 #include <gtest/gtest.h>
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 class HdiDeviceTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28
29 static inline HdiDevice* hdiDevice_ = nullptr;
30 };
31
SetUpTestCase()32 void HdiDeviceTest::SetUpTestCase()
33 {
34 hdiDevice_ = HdiDevice::GetInstance();
35 hdiDevice_->ResetHdiFuncs();
36 }
37
TearDownTestCase()38 void HdiDeviceTest::TearDownTestCase()
39 {
40 hdiDevice_ = nullptr;
41 }
42
43 namespace {
44 /*
45 * Function: all DeviceFuncs
46 * Type: Function
47 * Rank: Important(3)
48 * EnvConditions: N/A
49 * CaseDescription: 1. call all DeviceFuncs
50 * 2. check ret
51 */
52 HWTEST_F(HdiDeviceTest, DeviceFuncs001, Function | MediumTest| Level3)
53 {
54 HotPlugCallback hotPlugCallback = nullptr;
55 ASSERT_EQ(HdiDeviceTest::hdiDevice_->RegHotPlugCallback(hotPlugCallback, nullptr), DISPLAY_NULL_PTR);
56 uint32_t screenId = 0, screenModeId = 0, screenLightLevel = 0, num = 1;
57 VBlankCallback vblCallback = nullptr;
58 ASSERT_EQ(HdiDeviceTest::hdiDevice_->RegScreenVBlankCallback(screenId, vblCallback, nullptr), DISPLAY_NULL_PTR);
59 bool enabled = false, needFlush = false;
60 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenVsyncEnabled(screenId, enabled), DISPLAY_NULL_PTR);
61 DisplayCapability dcpInfo;
62 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCapability(screenId, dcpInfo), DISPLAY_NULL_PTR);
63 std::vector<DisplayModeInfo> dmodes;
64 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenSupportedModes(screenId, dmodes), DISPLAY_NULL_PTR);
65 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenMode(screenId, screenModeId), DISPLAY_NULL_PTR);
66 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenMode(screenId, screenModeId), DISPLAY_NULL_PTR);
67 DispPowerStatus dstatus = POWER_STATUS_ON;
68 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenPowerStatus(screenId, dstatus), DISPLAY_NULL_PTR);
69 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenPowerStatus(screenId, dstatus), DISPLAY_NULL_PTR);
70 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenBacklight(screenId, screenLightLevel), DISPLAY_NULL_PTR);
71 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenBacklight(screenId, screenLightLevel), DISPLAY_NULL_PTR);
72 ASSERT_EQ(HdiDeviceTest::hdiDevice_->PrepareScreenLayers(screenId, needFlush), DISPLAY_NULL_PTR);
73 std::vector<uint32_t> layersId;
74 std::vector<int32_t> types;
75 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCompChange(screenId, layersId, types), DISPLAY_NULL_PTR);
76 BufferHandle *buffer = nullptr;
77 sptr<SyncFence> fence = nullptr;
78 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, fence), DISPLAY_NULL_PTR);
79 IRect damageRect = {0, 0, 0, 0};
80 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientDamage(screenId, num, damageRect), DISPLAY_NULL_PTR);
81 std::vector<uint32_t> layers;
82 std::vector<sptr<SyncFence>> fences;
83 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenReleaseFence(screenId, layers, fences), DISPLAY_NULL_PTR);
84 std::vector<GraphicColorGamut> gamuts;
85 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenSupportedColorGamuts(screenId, gamuts), DISPLAY_NULL_PTR);
86 GraphicColorGamut gamut = GRAPHIC_COLOR_GAMUT_INVALID;
87 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorGamut(screenId, gamut), DISPLAY_NULL_PTR);
88 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenColorGamut(screenId, gamut), DISPLAY_NULL_PTR);
89 GamutMap gamutMap = GAMUT_MAP_CONSTANT;
90 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenGamutMap(screenId, gamutMap), DISPLAY_NULL_PTR);
91 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenGamutMap(screenId, gamutMap), DISPLAY_NULL_PTR);
92 const float *matrix;
93 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorTransform(screenId, matrix), DISPLAY_NULL_PTR);
94 HDRCapability info;
95 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetHDRCapabilityInfos(screenId, info), DISPLAY_NULL_PTR);
96 std::vector<GraphicHDRMetadataKey> keys;
97 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedMetaDataKey(screenId, keys), DISPLAY_NULL_PTR);
98 ASSERT_EQ(HdiDeviceTest::hdiDevice_->Commit(screenId, fence), DISPLAY_NULL_PTR);
99 }
100
101 /*
102 * Function: all LayerFuncs
103 * Type: Function
104 * Rank: Important(3)
105 * EnvConditions: N/A
106 * CaseDescription: 1. call all LayerFuncs
107 * 2. check ret
108 */
109 HWTEST_F(HdiDeviceTest, LayerFuncs001, Function | MediumTest| Level3)
110 {
111 uint32_t screenId = 0, layerId = 0;
112 GraphicLayerAlpha alpha;
113 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerAlpha(screenId, layerId, alpha), DISPLAY_NULL_PTR);
114 IRect layerRect = {0, 0, 0, 0};
115 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerSize(screenId, layerId, layerRect), DISPLAY_NULL_PTR);
116 GraphicTransformType type = GRAPHIC_ROTATE_NONE;
117 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetTransformMode(screenId, layerId, type), DISPLAY_NULL_PTR);
118 uint32_t num = 1;
119 IRect visible = {0, 0, 0, 0};
120 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerVisibleRegion(screenId, layerId, num, visible), DISPLAY_NULL_PTR);
121 IRect dirty = {0, 0, 0, 0};
122 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerDirtyRegion(screenId, layerId, dirty), DISPLAY_NULL_PTR);
123 BufferHandle *handle = nullptr;
124 sptr<SyncFence> acquireFence = nullptr;
125 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, handle, acquireFence), DISPLAY_NULL_PTR);
126 GraphicCompositionType cmpType = GRAPHIC_COMPOSITION_CLIENT;
127 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCompositionType(screenId, layerId, cmpType), DISPLAY_NULL_PTR);
128 GraphicBlendType blendType = GRAPHIC_BLEND_NONE;
129 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBlendType(screenId, layerId, blendType), DISPLAY_NULL_PTR);
130 IRect crop = {0, 0, 0, 0};
131 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCrop(screenId, layerId, crop), DISPLAY_NULL_PTR);
132 uint32_t zorder = 0;
133 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerZorder(screenId, layerId, zorder), DISPLAY_NULL_PTR);
134 bool isPreMulti = false;
135 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPreMulti(screenId, layerId, isPreMulti), DISPLAY_NULL_PTR);
136 float *matrix;
137 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorTransform(screenId, layerId, matrix), DISPLAY_NULL_PTR);
138 GraphicColorDataSpace colorSpace = GRAPHIC_COLOR_DATA_SPACE_UNKNOWN;
139 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorDataSpace(screenId, layerId, colorSpace), DISPLAY_NULL_PTR);
140 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetLayerColorDataSpace(screenId, layerId, colorSpace), DISPLAY_NULL_PTR);
141 std::vector<GraphicHDRMetaData> metaData;
142 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaData(screenId, layerId, metaData), DISPLAY_NULL_PTR);
143 GraphicHDRMetadataKey key = GRAPHIC_MATAKEY_RED_PRIMARY_X;
144 std::vector<uint8_t> metaDatas;
145 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaDataSet(screenId, layerId, key, metaDatas), DISPLAY_NULL_PTR);
146 GraphicExtDataHandle *extDataHandle = nullptr;
147 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerTunnelHandle(screenId, layerId, extDataHandle), DISPLAY_NULL_PTR);
148 GraphicPresentTimestampType presentTimesType = GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
149 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedPresentTimestampType(screenId, layerId, presentTimesType),
150 DISPLAY_NULL_PTR);
151 GraphicPresentTimestamp timestamp;
152 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetPresentTimestamp(screenId, layerId, timestamp), DISPLAY_NULL_PTR);
153 GraphicLayerInfo layerInfo;
154 ASSERT_EQ(HdiDeviceTest::hdiDevice_->CreateLayer(screenId, layerInfo, layerId), DISPLAY_NULL_PTR);
155 ASSERT_EQ(HdiDeviceTest::hdiDevice_->CloseLayer(screenId, layerId), DISPLAY_NULL_PTR);
156 }
157
158 } // namespace
159 } // namespace Rosen
160 } // namespace OHOS