1 /*
2  * Copyright (c) 2023-2024 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 #include "jpeg_image_processor_test.h"
16 #include "data_buffer.h"
17 #include "dscreen_errcode.h"
18 #include "iconsumer_surface.h"
19 #include "surface_type.h"
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace DistributedHardware {
SetUpTestCase(void)25 void ScreenImageJpegTest::SetUpTestCase(void) {}
26 
TearDownTestCase(void)27 void ScreenImageJpegTest::TearDownTestCase(void) {}
28 
SetUp(void)29 void ScreenImageJpegTest::SetUp(void)
30 {
31     param_.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH;
32     param_.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT;
33     param_.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH;
34     param_.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT;
35     param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
36     param_.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
37     jpeg_ = std::make_shared<JpegImageProcessor>(param_);
38 }
39 
TearDown(void)40 void ScreenImageJpegTest::TearDown(void) {}
41 
42 /**
43  * @tc.name: SetOutputSurface_001
44  * @tc.desc: Verify the SetOutputSurface function.
45  * @tc.type: FUNC
46  * @tc.require: Issue Number
47  */
48 HWTEST_F(ScreenImageJpegTest, SetOutputSurface_001, TestSize.Level1)
49 {
50     sptr<Surface> jpegSurface = IConsumerSurface::Create();
51     int32_t ret = jpeg_->SetOutputSurface(jpegSurface);
52     EXPECT_EQ(DH_SUCCESS, ret);
53 }
54 
55 /**
56  * @tc.name: SetOutputSurface_002
57  * @tc.desc: Verify the SetOutputSurface function.
58  * @tc.type: FUNC
59  * @tc.require: Issue Number
60  */
61 HWTEST_F(ScreenImageJpegTest, SetOutputSurface_002, TestSize.Level1)
62 {
63     int32_t ret = jpeg_->SetOutputSurface(nullptr);
64     EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret);
65 }
66 
67 /**
68  * @tc.name: FillDirtyImages2Surface_001
69  * @tc.desc: Verify the FillDirtyImages2Surface function.
70  * @tc.type: FUNC
71  * @tc.require: Issue Number
72  */
73 HWTEST_F(ScreenImageJpegTest, FillDirtyImages2Surface_001, TestSize.Level1)
74 {
75     jpeg_->imageSurface_ = nullptr;
76     std::shared_ptr<DataBuffer> dataBuffer = std::make_shared<DataBuffer>(10);
77     DirtyRect rect = {20, 20, 20, 20, 20};
78     dataBuffer->AddDirtyRect(rect);
79     int32_t ret = jpeg_->FillDirtyImages2Surface(dataBuffer, nullptr);
80     EXPECT_EQ(ERR_DH_SCREEN_SURFACE_INVALIED, ret);
81 }
82 
83 /**
84  * @tc.name: FillDirtyImages2Surface_002
85  * @tc.desc: Verify the FillDirtyImages2Surface function.
86  * @tc.type: FUNC
87  * @tc.require: Issue Number
88  */
89 HWTEST_F(ScreenImageJpegTest, FillDirtyImages2Surface_002, TestSize.Level1)
90 {
91     sptr<Surface> consumerSurface = IConsumerSurface::Create();
92     sptr<IBufferProducer> prodecer = consumerSurface->GetProducer();
93     jpeg_->imageSurface_ = Surface::CreateSurfaceAsProducer(prodecer);
94     std::shared_ptr<DataBuffer> dataBuffer = std::make_shared<DataBuffer>(20);
95     DirtyRect rect = {2600, 2800, 20, 20, 20};
96     dataBuffer->AddDirtyRect(rect);
97     uint8_t *lastFrame = new uint8_t[20] {0};
98     int32_t ret = jpeg_->FillDirtyImages2Surface(dataBuffer, lastFrame);
99     delete [] lastFrame;
100     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
101 }
102 
103 /**
104  * @tc.name: ReplaceDamage2LastFrame_001
105  * @tc.desc: Verify the ReplaceDamage2LastFrame function.
106  * @tc.type: FUNC
107  * @tc.require: Issue Number
108  */
109 HWTEST_F(ScreenImageJpegTest, ReplaceDamage2LastFrame_001, TestSize.Level1)
110 {
111     uint8_t *lastframe = new uint8_t[28385280] {125};
112     uint8_t *dirtyImageData = new uint8_t[1600] {125};
113     DirtyRect rect = {20, 20, 20, 24, 20};
114     int32_t ret = jpeg_->ReplaceDamage2LastFrame(lastframe, dirtyImageData, rect);
115     EXPECT_EQ(DH_SUCCESS, ret);
116 }
117 } // namespace DistributedHardware
118 } // namespace OHOS