• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 }
36 
TearDownTestCase()37 void HdiDeviceTest::TearDownTestCase()
38 {
39     hdiDevice_ = nullptr;
40 }
41 
42 namespace {
43 /*
44 * Function: DeviceFuncs001
45 * Type: Function
46 * Rank: Important(3)
47 * EnvConditions: N/A
48 * CaseDescription: 1. call DeviceFuncs
49 *                  2. check ret
50 */
51 HWTEST_F(HdiDeviceTest, DeviceFuncs001, Function | MediumTest| Level3)
52 {
53     ASSERT_EQ(HdiDeviceTest::hdiDevice_->RegHotPlugCallback(nullptr, nullptr), GRAPHIC_DISPLAY_SUCCESS);
54     uint32_t screenId = 1, screenModeId = 0, screenLightLevel = 0;
55     ASSERT_EQ(HdiDeviceTest::hdiDevice_->RegScreenVBlankCallback(screenId, nullptr, nullptr),
56               GRAPHIC_DISPLAY_SUCCESS);
57     bool enabled = false, needFlush = false;
58     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenVsyncEnabled(screenId, enabled), GRAPHIC_DISPLAY_SUCCESS);
59     GraphicDisplayCapability dcpInfo;
60     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCapability(screenId, dcpInfo), GRAPHIC_DISPLAY_SUCCESS);
61     std::vector<GraphicDisplayModeInfo> dmodes;
62     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenSupportedModes(screenId, dmodes), GRAPHIC_DISPLAY_SUCCESS);
63     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenMode(screenId, screenModeId), GRAPHIC_DISPLAY_SUCCESS);
64     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenMode(screenId, screenModeId), GRAPHIC_DISPLAY_SUCCESS);
65     GraphicDispPowerStatus dstatus = GRAPHIC_POWER_STATUS_ON;
66     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
67     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
68     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
69     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
70     ASSERT_EQ(HdiDeviceTest::hdiDevice_->PrepareScreenLayers(screenId, needFlush), GRAPHIC_DISPLAY_SUCCESS);
71     std::vector<uint32_t> layersId;
72     std::vector<int32_t> types;
73     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCompChange(screenId, layersId, types), GRAPHIC_DISPLAY_SUCCESS);
74     BufferHandle *buffer = nullptr;
75     sptr<SyncFence> fence = nullptr;
76     uint32_t cacheIndex = 0;
77     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
78               GRAPHIC_DISPLAY_NULL_PTR);
79     buffer = new BufferHandle();
80     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
81               GRAPHIC_DISPLAY_NULL_PTR);
82     fence = new SyncFence(-1);
83     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
84               GRAPHIC_DISPLAY_SUCCESS);
85     std::vector<GraphicIRect> damageRects = { {0, 0, 0, 0} };
86     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientDamage(screenId, damageRects), GRAPHIC_DISPLAY_SUCCESS);
87     std::vector<uint32_t> layers;
88     std::vector<sptr<SyncFence>> fences;
89     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenReleaseFence(screenId, layers, fences), GRAPHIC_DISPLAY_SUCCESS);
90     std::vector<GraphicColorGamut> gamuts;
91     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenSupportedColorGamuts(screenId, gamuts), GRAPHIC_DISPLAY_NOT_SUPPORT);
92     GraphicColorGamut gamut = GRAPHIC_COLOR_GAMUT_INVALID;
93     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
94     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
95     GraphicGamutMap gamutMap = GRAPHIC_GAMUT_MAP_CONSTANT;
96     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
97     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
98     std::vector<float> matrix = { 0.0 };
99     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorTransform(screenId, matrix), GRAPHIC_DISPLAY_NOT_SUPPORT);
100 }
101 
102 /*
103 * Function: DeviceFuncs002
104 * Type: Function
105 * Rank: Important(3)
106 * EnvConditions: N/A
107 * CaseDescription: 1. call DeviceFuncs
108 *                  2. check ret
109 */
110 HWTEST_F(HdiDeviceTest, DeviceFuncs002, Function | MediumTest| Level3)
111 {
112     uint32_t screenId = 1;
113     GraphicHDRCapability info;
114     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetHDRCapabilityInfos(screenId, info), GRAPHIC_DISPLAY_NOT_SUPPORT);
115     std::vector<GraphicHDRMetadataKey> keys;
116     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedMetaDataKey(screenId, keys), GRAPHIC_DISPLAY_NOT_SUPPORT);
117 }
118 
119 /*
120 * Function: LayerFuncs001
121 * Type: Function
122 * Rank: Important(3)
123 * EnvConditions: N/A
124 * CaseDescription: 1. call LayerFuncs
125 *                  2. check ret
126 */
127 HWTEST_F(HdiDeviceTest, LayerFuncs001, Function | MediumTest| Level3)
128 {
129     uint32_t screenId = 1, layerId = 0, zorder = 0;
130     GraphicLayerAlpha alpha;
131     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerAlpha(screenId, layerId, alpha), GRAPHIC_DISPLAY_SUCCESS);
132     GraphicIRect layerRect = {0, 0, 0, 0};
133     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerSize(screenId, layerId, layerRect), GRAPHIC_DISPLAY_SUCCESS);
134     GraphicTransformType type = GRAPHIC_ROTATE_NONE;
135     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetTransformMode(screenId, layerId, type), GRAPHIC_DISPLAY_SUCCESS);
136     std::vector<GraphicIRect> visibles = { {0, 0, 0, 0} };
137     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerVisibleRegion(screenId, layerId, visibles), GRAPHIC_DISPLAY_SUCCESS);
138     std::vector<GraphicIRect> dirtyRegions = { {0, 0, 0, 0} };
139     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerDirtyRegion(screenId, layerId, dirtyRegions),
140               GRAPHIC_DISPLAY_SUCCESS);
141     BufferHandle *handle = nullptr;
142     sptr<SyncFence> acquireFence = nullptr;
143     std::vector<uint32_t> deletingList = {};
144     uint32_t cacheIndex = 0;
145     GraphicLayerBuffer layerBuffer = {handle, cacheIndex, acquireFence, deletingList};
146     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_NULL_PTR);
147     GraphicCompositionType cmpType = GRAPHIC_COMPOSITION_CLIENT;
148     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCompositionType(screenId, layerId, cmpType), GRAPHIC_DISPLAY_SUCCESS);
149     GraphicBlendType blendType = GRAPHIC_BLEND_NONE;
150     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBlendType(screenId, layerId, blendType), GRAPHIC_DISPLAY_SUCCESS);
151     GraphicIRect crop = {0, 0, 0, 0};
152     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCrop(screenId, layerId, crop), GRAPHIC_DISPLAY_SUCCESS);
153     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerZorder(screenId, layerId, zorder), GRAPHIC_DISPLAY_SUCCESS);
154     bool isPreMulti = false;
155     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPreMulti(screenId, layerId, isPreMulti), GRAPHIC_DISPLAY_SUCCESS);
156     std::vector<float> matrix = { 0.0 };
157     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorTransform(screenId, layerId, matrix),
158               GRAPHIC_DISPLAY_NOT_SUPPORT);
159     GraphicColorDataSpace colorSpace = GRAPHIC_COLOR_DATA_SPACE_UNKNOWN;
160     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorDataSpace(screenId, layerId, colorSpace),
161               GRAPHIC_DISPLAY_NOT_SUPPORT);
162     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetLayerColorDataSpace(screenId, layerId, colorSpace),
163               GRAPHIC_DISPLAY_NOT_SUPPORT);
164     std::vector<GraphicHDRMetaData> metaData;
165     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaData(screenId, layerId, metaData), GRAPHIC_DISPLAY_NOT_SUPPORT);
166     GraphicHDRMetadataKey key = GRAPHIC_MATAKEY_RED_PRIMARY_X;
167     std::vector<uint8_t> metaDatas;
168     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaDataSet(screenId, layerId, key, metaDatas),
169               GRAPHIC_DISPLAY_NOT_SUPPORT);
170     GraphicExtDataHandle *extDataHandle = nullptr;
171     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerTunnelHandle(screenId, layerId, extDataHandle),
172               GRAPHIC_DISPLAY_NOT_SUPPORT);
173     GraphicPresentTimestampType presentTimesType = GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
174     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedPresentTimestampType(screenId, layerId, presentTimesType),
175               GRAPHIC_DISPLAY_NOT_SUPPORT);
176 }
177 
178 /*
179 * Function: LayerFuncs002
180 * Type: Function
181 * Rank: Important(3)
182 * EnvConditions: N/A
183 * CaseDescription: 1. call LayerFuncs
184 *                  2. check ret
185 */
186 HWTEST_F(HdiDeviceTest, LayerFuncs002, Function | MediumTest| Level3)
187 {
188     uint32_t screenId = 1, layerId = 0;
189     GraphicPresentTimestamp timestamp;
190     ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetPresentTimestamp(screenId, layerId, timestamp),
191               GRAPHIC_DISPLAY_NOT_SUPPORT);
192     uint32_t layerMask = 0;
193     ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMaskInfo(screenId, layerId, layerMask), GRAPHIC_DISPLAY_SUCCESS);
194     GraphicLayerInfo layerInfo;
195     uint32_t cacheCount = 1;
196     ASSERT_EQ(HdiDeviceTest::hdiDevice_->CreateLayer(screenId, layerInfo, cacheCount, layerId),
197               GRAPHIC_DISPLAY_SUCCESS);
198     ASSERT_EQ(HdiDeviceTest::hdiDevice_->CloseLayer(screenId, layerId), GRAPHIC_DISPLAY_SUCCESS);
199 }
200 } // namespace
201 } // namespace Rosen
202 } // namespace OHOS