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