1 /*
2  * Copyright (c) 2022-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 
16 #include "data_buffer_test.h"
17 #include "dscreen_errcode.h"
18 
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace DistributedHardware {
SetUpTestCase(void)23 void DataBufferTest::SetUpTestCase(void) {}
24 
TearDownTestCase(void)25 void DataBufferTest::TearDownTestCase(void) {}
26 
SetUp()27 void DataBufferTest::SetUp()
28 {
29     dataBuffer_ = std::make_shared<DataBuffer>(capacity);
30 }
31 
TearDown()32 void DataBufferTest::TearDown()
33 {
34     if (dataBuffer_ != nullptr) {
35         dataBuffer_ = nullptr;
36     }
37 }
38 
39 /**
40  * @tc.name: Capacity_001
41  * @tc.desc: Verify the Capacity function.
42  * @tc.type: FUNC
43  * @tc.require: Issue Number
44  */
45 HWTEST_F(DataBufferTest, Capacity_001, TestSize.Level1)
46 {
47     size_t actual = dataBuffer_->Capacity();
48     EXPECT_EQ(capacity, actual);
49 }
50 
51 /**
52  * @tc.name: Data_001
53  * @tc.desc: Verify the Data function.
54  * @tc.type: FUNC
55  * @tc.require: Issue Number
56  */
57 HWTEST_F(DataBufferTest, Data_001, TestSize.Level1)
58 {
59     uint8_t *actual = dataBuffer_->Data();
60     EXPECT_NE(nullptr, actual);
61 }
62 
63 /**
64  * @tc.name: SetDataNumber_001
65  * @tc.desc: Verify the SetDataNumber function.
66  * @tc.type: FUNC
67  * @tc.require: Issue Number
68  */
69 HWTEST_F(DataBufferTest, SetDataNumber_001, TestSize.Level1)
70 {
71     dataBuffer_->SetDataNumber(10);
72     EXPECT_EQ(10, dataBuffer_->DataNumber());
73 }
74 
75 /**
76  * @tc.name: SetDataType_001
77  * @tc.desc: Verify the SetDataType function.
78  * @tc.type: FUNC
79  * @tc.require: Issue Number
80  */
81 HWTEST_F(DataBufferTest, SetDataType_001, TestSize.Level1)
82 {
83     dataBuffer_->SetDataType(VIDEO_PART_SCREEN_DATA);
84     EXPECT_EQ(VIDEO_PART_SCREEN_DATA, dataBuffer_->DataType());
85 }
86 
87 /**
88  * @tc.name: ResetCapcity_001
89  * @tc.desc: Verify the ResetCapcity function.
90  * @tc.type: FUNC
91  * @tc.require: Issue Number
92  */
93 HWTEST_F(DataBufferTest, ResetCapcity_001, TestSize.Level1)
94 {
95     dataBuffer_->ResetCapcity(10);
96     EXPECT_EQ(10, dataBuffer_->Capacity());
97 }
98 
99 /**
100  * @tc.name: ResetCapcity_002
101  * @tc.desc: Verify the ResetCapcity function.
102  * @tc.type: FUNC
103  * @tc.require: Issue Number
104  */
105 HWTEST_F(DataBufferTest, ResetCapcity_002, TestSize.Level1)
106 {
107     dataBuffer_->ResetCapcity(0);
108     EXPECT_EQ(1, dataBuffer_->Capacity());
109 }
110 
111 /**
112  * @tc.name: AddData_001
113  * @tc.desc: Verify the AddData function.
114  * @tc.type: FUNC
115  * @tc.require: Issue Number
116  */
117 HWTEST_F(DataBufferTest, AddData_001, TestSize.Level1)
118 {
119     unsigned char *inputData = nullptr;
120     dataBuffer_->AddData(10, inputData);
121     EXPECT_EQ(1, dataBuffer_->Capacity());
122 }
123 
124 /**
125  * @tc.name: AddData_002
126  * @tc.desc: Verify the AddData function.
127  * @tc.type: FUNC
128  * @tc.require: Issue Number
129  */
130 HWTEST_F(DataBufferTest, AddData_002, TestSize.Level1)
131 {
__anon036f55c70102null132     unsigned char *inputData = new unsigned char[10] {0};
133     dataBuffer_->ResetCapcity(20);
134     dataBuffer_->SetSize(0);
135     dataBuffer_->AddData(10, inputData);
136     EXPECT_EQ(10, dataBuffer_->Capacity());
137     delete [] inputData;
138 }
139 
140 /**
141  * @tc.name: AddData_003
142  * @tc.desc: Verify the AddData function.
143  * @tc.type: FUNC
144  * @tc.require: Issue Number
145  */
146 HWTEST_F(DataBufferTest, AddData_003, TestSize.Level1)
147 {
__anon036f55c70202null148     unsigned char *inputData = new unsigned char[10] {0};
149     dataBuffer_->~DataBuffer();
150     EXPECT_EQ(nullptr, dataBuffer_->data_);
151     dataBuffer_->AddData(10, inputData);
152     EXPECT_NE(10, dataBuffer_->Capacity());
153     delete [] inputData;
154 }
155 
156 /**
157  * @tc.name: GetData_001
158  * @tc.desc: Verify the GetData function.
159  * @tc.type: FUNC
160  * @tc.require: Issue Number
161  */
162 HWTEST_F(DataBufferTest, GetData_001, TestSize.Level1)
163 {
164     uint8_t *outputData = new uint8_t[10] {0};
165     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, dataBuffer_->GetData(10, 10, outputData));
166     delete [] outputData;
167 }
168 
169 /**
170  * @tc.name: GetData_002
171  * @tc.desc: Verify the GetData function.
172  * @tc.type: FUNC
173  * @tc.require: Issue Number
174  */
175 HWTEST_F(DataBufferTest, GetData_002, TestSize.Level1)
176 {
177     uint8_t *outputData = nullptr;
178     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, dataBuffer_->GetData(0, 0, outputData));
179 }
180 
181 /**
182  * @tc.name: GetData_003
183  * @tc.desc: Verify the GetData function.
184  * @tc.type: FUNC
185  * @tc.require: Issue Number
186  */
187 HWTEST_F(DataBufferTest, GetData_003, TestSize.Level1)
188 {
189     uint8_t *outputData = new uint8_t[1] {0};
190     dataBuffer_->~DataBuffer();
191     EXPECT_EQ(nullptr, dataBuffer_->data_);
192     EXPECT_NE(DH_SUCCESS, dataBuffer_->GetData(0, 0, outputData));
193     delete [] outputData;
194 }
195 
196 /**
197  * @tc.name: AddDirtyRect_001
198  * @tc.desc: Verify the AddDirtyRect function.
199  * @tc.type: FUNC
200  * @tc.require: Issue Number
201  */
202 HWTEST_F(DataBufferTest, AddDirtyRect_001, TestSize.Level1)
203 {
204     DirtyRect rect = {1, 1, 1, 1, 1};
205     dataBuffer_->AddDirtyRect(rect);
206     EXPECT_NE(0, dataBuffer_->GetDirtyRectVec().size());
207 }
208 } // namespace DistributedHardware
209 } // namespace OHOS