1 /*
2  * Copyright (c) 2021-2022 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 <gtest/gtest.h>
17 
18 #include "stream_buffer.h"
19 
20 namespace OHOS {
21 namespace MMI {
22 namespace {
23 using namespace testing::ext;
24 } // namespace
25 
26 class StreamBufferTest : public testing::Test {
27 public:
SetUpTestCase(void)28     static void SetUpTestCase(void) {}
TearDownTestCase(void)29     static void TearDownTestCase(void) {}
30 };
31 
32 class StreamBufferUnitTest : public StreamBuffer {
33 public:
ReadBufUnitTest() const34     const char *ReadBufUnitTest() const
35     {
36         return ReadBuf();
37     }
WriteBufUnitTest() const38     const char *WriteBufUnitTest() const
39     {
40         return WriteBuf();
41     }
CloneUnitTest(const StreamBuffer & buf)42     bool CloneUnitTest(const StreamBuffer& buf)
43     {
44         return Clone(buf);
45     }
46 };
47 
48 
49 /**
50  * @tc.name:read_Type1_001
51  * @tc.desc:Verify stream buffer read
52  * @tc.type: FUNC
53  * @tc.require:
54  */
55 HWTEST_F(StreamBufferTest, read_Type1_001, TestSize.Level1)
56 {
57     char buf[] = "";
58     size_t size = 4;
59 
60     StreamBuffer bufObj;
61     StreamBuffer bufObjTmp(bufObj);
62     bool retResult = bufObj.Read(buf, size);
63     EXPECT_FALSE(retResult);
64 }
65 
66 /**
67  * @tc.name:read_Type1_002
68  * @tc.desc:Verify stream buffer read
69  * @tc.type: FUNC
70  * @tc.require:
71  */
72 HWTEST_F(StreamBufferTest, read_Type1_002, TestSize.Level1)
73 {
74     char buf[] = "1234";
75     size_t size = 4;
76 
77     StreamBuffer bufObj;
78     StreamBuffer bufObjTmp(bufObj);
79     bool retResult = bufObj.Read(buf, size);
80     EXPECT_FALSE(retResult);
81 }
82 
83 /**
84  * @tc.name:read_Type2_001
85  * @tc.desc:Verify stream buffer read
86  * @tc.type: FUNC
87  * @tc.require:
88  */
89 HWTEST_F(StreamBufferTest,  read_Type2_001, TestSize.Level1)
90 {
91     std::string buf = "";
92 
93     StreamBuffer bufObj;
94     StreamBuffer bufObjTmp(bufObj);
95     bool retResult = bufObj.Read(buf);
96     ASSERT_FALSE(retResult);
97 }
98 
99 /**
100  * @tc.name:read_Type2_002
101  * @tc.desc:Verify stream buffer read
102  * @tc.type: FUNC
103  * @tc.require:
104  */
105 HWTEST_F(StreamBufferTest, read_Type2_002, TestSize.Level1)
106 {
107     std::string buf = "Stream Data";
108 
109     StreamBuffer bufObj;
110     StreamBuffer bufObjTmp(bufObj);
111     bool retResult = bufObj.Read(buf);
112     ASSERT_FALSE(retResult);
113 }
114 
115 /**
116  * @tc.name:read_Type3_001
117  * @tc.desc:Verify stream buffer read
118  * @tc.type: FUNC
119  * @tc.require:
120  */
121 HWTEST_F(StreamBufferTest,  read_Type3_001, TestSize.Level1)
122 {
123     StreamBuffer buf;
124 
125     StreamBuffer bufObj;
126     StreamBuffer bufObjTmp(bufObj);
127     bool retResult = bufObj.Read(buf);
128     ASSERT_FALSE(retResult);
129 }
130 
131 /**
132  * @tc.name:write_Type1_001
133  * @tc.desc:Verify stream buffer write
134  * @tc.type: FUNC
135  * @tc.require:
136  */
137 HWTEST_F(StreamBufferTest, write_Type1_001, TestSize.Level1)
138 {
139     std::string buf;
140 
141     StreamBuffer streamBuffer;
142     bool retResult = streamBuffer.Write(buf);
143     ASSERT_TRUE(retResult);
144 }
145 
146 /**
147  * @tc.name:write_Type1_002
148  * @tc.desc:Verify stream buffer write
149  * @tc.type: FUNC
150  * @tc.require:
151  */
152 HWTEST_F(StreamBufferTest, write_Type1_002, TestSize.Level1)
153 {
154     std::string buf = "stream data";
155 
156     StreamBuffer streamBuffer;
157     bool retResult = streamBuffer.Write(buf);
158     ASSERT_TRUE(retResult);
159 }
160 
161 /**
162  * @tc.name:write_Type2_001
163  * @tc.desc:Verify stream buffer write
164  * @tc.type: FUNC
165  * @tc.require:
166  */
167 HWTEST_F(StreamBufferTest, write_Type2_001, TestSize.Level1)
168 {
169     StreamBuffer buf;
170     StreamBuffer streamBuffer;
171     bool retResult = streamBuffer.Write(buf);
172     ASSERT_FALSE(retResult);
173 }
174 
175 /**
176  * @tc.name:write_Type3_001
177  * @tc.desc:Verify stream buffer write
178  * @tc.type: FUNC
179  * @tc.require:
180  */
181 HWTEST_F(StreamBufferTest, write_Type3_001, TestSize.Level1)
182 {
183     char buf[100];
184     size_t size = 0;
185 
186     StreamBuffer streamBuffer;
187     bool retResult = streamBuffer.Write(buf, size);
188     EXPECT_FALSE(retResult);
189 }
190 
191 /**
192  * @tc.name:write_Type3_002
193  * @tc.desc:Verify stream buffer write
194  * @tc.type: FUNC
195  * @tc.require:
196  */
197 HWTEST_F(StreamBufferTest, write_Type3_002, TestSize.Level1)
198 {
199     char buf[100] = "stream data type3 001";
200     size_t size = 10;
201 
202     StreamBuffer streamBuffer;
203     bool retResult = streamBuffer.Write(buf, size);
204     EXPECT_TRUE(retResult);
205 }
206 
207 /**
208  * @tc.name:Data
209  * @tc.desc:Verify stream buffer data
210  * @tc.type: FUNC
211  * @tc.require:
212  */
213 HWTEST_F(StreamBufferTest, Data, TestSize.Level1)
214 {
215     StreamBuffer bufObj;
216     const char *retResult = bufObj.Data();
217     EXPECT_TRUE(retResult);
218 }
219 
220 /**
221  * @tc.name:Size_001
222  * @tc.desc:Verify stream buffer size
223  * @tc.type: FUNC
224  * @tc.require:
225  */
226 HWTEST_F(StreamBufferTest, Size_001, TestSize.Level1)
227 {
228     StreamBuffer streamBuffer;
229     ASSERT_FALSE(streamBuffer.Size() != 0);
230 }
231 
232 /**
233  * @tc.name:operatorLeft
234  * @tc.desc:Verify stream buffer operator left
235  * @tc.type: FUNC
236  * @tc.require:
237  */
238 HWTEST_F(StreamBufferTest, operatorLeft, TestSize.Level1)
239 {
240     int32_t val = 111;
241     StreamBuffer buf;
242     StreamBuffer streamBufferSrc;
243     bool retResult = streamBufferSrc.Write(buf);
244     ASSERT_FALSE(retResult);
245     streamBufferSrc << val;
246 }
247 
248 /**
249  * @tc.name:operatorRight
250  * @tc.desc:Verify stream buffer operator right
251  * @tc.type: FUNC
252  * @tc.require:
253  */
254 HWTEST_F(StreamBufferTest, operatorRight, TestSize.Level1)
255 {
256     int32_t val = 111;
257     StreamBuffer buf;
258     StreamBuffer streamBufferSrc;
259     bool retResult = streamBufferSrc.Write(buf);
260     ASSERT_FALSE(retResult);
261     streamBufferSrc << val;
262     streamBufferSrc >> val;
263 }
264 
265 /**
266  * @tc.name:ReadBuf
267  * @tc.desc:Verify stream buffer read buffer
268  * @tc.type: FUNC
269  * @tc.require:
270  */
271 HWTEST_F(StreamBufferTest, ReadBuf, TestSize.Level1)
272 {
273     StreamBufferUnitTest bufObj;
274     const char *retResult = bufObj.ReadBufUnitTest();
275     EXPECT_NE(retResult, nullptr);
276 }
277 
278 /**
279  * @tc.name:WriteBuf
280  * @tc.desc:Verify stream buffer write buffer
281  * @tc.type: FUNC
282  * @tc.require:
283  */
284 HWTEST_F(StreamBufferTest, WriteBuf, TestSize.Level1)
285 {
286     StreamBufferUnitTest bufObj;
287     const char *retResult = bufObj.WriteBufUnitTest();
288     EXPECT_NE(retResult, nullptr);
289 }
290 
291 /**
292  * @tc.name:Clone
293  * @tc.desc:Verify stream buffer clone
294  * @tc.type: FUNC
295  * @tc.require:
296  */
297 HWTEST_F(StreamBufferTest, Clone, TestSize.Level1)
298 {
299     const StreamBuffer buf;
300 
301     StreamBufferUnitTest bufObj;
302     bool retResult = bufObj.CloneUnitTest(buf);
303     EXPECT_FALSE(retResult);
304 }
305 } // namespace MMI
306 } // namespace OHOS
307