1 /*
2 * Copyright (c) 2022-2023 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 #define private public
17 #include "data_buffer_test.h"
18 #include "dscreen_errcode.h"
19 #undef private
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace DistributedHardware {
SetUpTestCase(void)25 void DataBufferTest::SetUpTestCase(void) {}
26
TearDownTestCase(void)27 void DataBufferTest::TearDownTestCase(void) {}
28
SetUp()29 void DataBufferTest::SetUp()
30 {
31 dataBuffer_ = std::make_shared<DataBuffer>(capacity);
32 }
33
TearDown()34 void DataBufferTest::TearDown() {}
35
36 /**
37 * @tc.name: Capacity_001
38 * @tc.desc: Verify the Capacity function.
39 * @tc.type: FUNC
40 * @tc.require: Issue Number
41 */
42 HWTEST_F(DataBufferTest, Capacity_001, TestSize.Level1)
43 {
44 size_t actual = dataBuffer_->Capacity();
45 EXPECT_EQ(capacity, actual);
46 }
47
48 /**
49 * @tc.name: Data_001
50 * @tc.desc: Verify the Data function.
51 * @tc.type: FUNC
52 * @tc.require: Issue Number
53 */
54 HWTEST_F(DataBufferTest, Data_001, TestSize.Level1)
55 {
56 uint8_t *actual = dataBuffer_->Data();
57 EXPECT_NE(nullptr, actual);
58 }
59
60 /**
61 * @tc.name: ResetCapcity_001
62 * @tc.desc: Verify the ResetCapcity function.
63 * @tc.type: FUNC
64 * @tc.require: Issue Number
65 */
66 HWTEST_F(DataBufferTest, ResetCapcity_001, TestSize.Level1)
67 {
68 dataBuffer_->ResetCapcity(10);
69 EXPECT_EQ(10, dataBuffer_->Capacity());
70 }
71
72 /**
73 * @tc.name: ResetCapcity_002
74 * @tc.desc: Verify the ResetCapcity function.
75 * @tc.type: FUNC
76 * @tc.require: Issue Number
77 */
78 HWTEST_F(DataBufferTest, ResetCapcity_002, TestSize.Level1)
79 {
80 dataBuffer_->ResetCapcity(0);
81 EXPECT_EQ(1, dataBuffer_->Capacity());
82 }
83
84 /**
85 * @tc.name: AddData_001
86 * @tc.desc: Verify the AddData function.
87 * @tc.type: FUNC
88 * @tc.require: Issue Number
89 */
90 HWTEST_F(DataBufferTest, AddData_001, TestSize.Level1)
91 {
92 unsigned char *inputData = nullptr;
93 dataBuffer_->AddData(10, inputData);
94 EXPECT_EQ(1, dataBuffer_->Capacity());
95 }
96
97 /**
98 * @tc.name: AddData_002
99 * @tc.desc: Verify the AddData function.
100 * @tc.type: FUNC
101 * @tc.require: Issue Number
102 */
103 HWTEST_F(DataBufferTest, AddData_002, TestSize.Level1)
104 {
__anon590bb50e0102null105 unsigned char *inputData = new unsigned char[10] {0};
106 dataBuffer_->ResetCapcity(20);
107 dataBuffer_->SetSize(0);
108 dataBuffer_->AddData(10, inputData);
109 EXPECT_EQ(10, dataBuffer_->Capacity());
110 delete [] inputData;
111 }
112
113 /**
114 * @tc.name: GetData_001
115 * @tc.desc: Verify the GetData function.
116 * @tc.type: FUNC
117 * @tc.require: Issue Number
118 */
119 HWTEST_F(DataBufferTest, GetData_001, TestSize.Level1)
120 {
121 uint8_t *outputData = new uint8_t[10] {0};
122 EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, dataBuffer_->GetData(10, 10, outputData));
123 delete [] outputData;
124 }
125 } // namespace DistributedHardware
126 } // namespace OHOS