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
20namespace OHOS {
21namespace MMI {
22namespace {
23using namespace testing::ext;
24} // namespace
25
26class StreamBufferTest : public testing::Test {
27public:
28    static void SetUpTestCase(void) {}
29    static void TearDownTestCase(void) {}
30};
31
32class StreamBufferUnitTest : public StreamBuffer {
33public:
34    const char *ReadBufUnitTest() const
35    {
36        return ReadBuf();
37    }
38    const char *WriteBufUnitTest() const
39    {
40        return WriteBuf();
41    }
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 */
55HWTEST_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 */
72HWTEST_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 */
89HWTEST_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 */
105HWTEST_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 */
121HWTEST_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 */
137HWTEST_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 */
152HWTEST_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 */
167HWTEST_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 */
181HWTEST_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 */
197HWTEST_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 */
213HWTEST_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 */
226HWTEST_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 */
238HWTEST_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 */
254HWTEST_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 */
271HWTEST_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 */
284HWTEST_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 */
297HWTEST_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