1 /*
2 * Copyright (c) 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 #include <iostream>
18 #include <unistd.h>
19 #include <csignal>
20 #include <sys/param.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include "serializer.h"
24
25 using namespace testing::ext;
26 using namespace std;
27
28 const int BUFFER_SIZE = 200;
29 const int SMALL_BUFFER_SIZE = 100;
30
31 class UtilsSerializerTest : public testing::Test {
32 public:
SetUpTestCase()33 static void SetUpTestCase() { }
TearDownTestCase()34 static void TearDownTestCase() { }
SetUp()35 void SetUp() { }
TearDown()36 void TearDown() { }
37 };
38 struct TestData {
39 bool boolTest;
40 int8_t int8Test;
41 int16_t int16Test;
42 int32_t int32Test;
43 uint8_t uint8Test;
44 uint16_t uint16Test;
45 uint32_t uint32Test;
46 };
47 struct Padded {
48 char title;
49 int32_t handle;
50 uint64_t cookie;
51 };
52 struct Unpadded {
53 char tip;
54 };
55
WriteTestData(IpcIo * io,const struct TestData & data)56 void WriteTestData(IpcIo* io, const struct TestData &data)
57 {
58 bool result = false;
59
60 result = WriteBool(io, data.boolTest);
61 EXPECT_EQ(result, true);
62
63 result = WriteInt8(io, data.int8Test);
64 EXPECT_EQ(result, true);
65
66 result = WriteInt16(io, data.int16Test);
67 EXPECT_EQ(result, true);
68
69 result = WriteInt32(io, data.int32Test);
70 EXPECT_EQ(result, true);
71
72 result = WriteUint8(io, data.uint8Test);
73 EXPECT_EQ(result, true);
74
75 result = WriteUint16(io, data.uint16Test);
76 EXPECT_EQ(result, true);
77
78 result = WriteUint32(io, data.uint32Test);
79 EXPECT_EQ(result, true);
80 }
81
ReadTestData(IpcIo * io,const struct TestData & data)82 void ReadTestData(IpcIo* io, const struct TestData &data)
83 {
84 bool boolVal;
85 bool result = ReadBool(io, &boolVal);
86 EXPECT_EQ(result, true);
87 EXPECT_EQ(boolVal, data.boolTest);
88
89 int8_t int8Val;
90 result = ReadInt8(io, &int8Val);
91 EXPECT_EQ(result, true);
92 EXPECT_EQ(int8Val, data.int8Test);
93
94 int16_t int16Val;
95 result = ReadInt16(io, &int16Val);
96 EXPECT_EQ(result, true);
97 EXPECT_EQ(int16Val, data.int16Test);
98
99 int32_t int32Val;
100 result = ReadInt32(io, &int32Val);
101 EXPECT_EQ(result, true);
102 EXPECT_EQ(int32Val, data.int32Test);
103
104 uint8_t uint8Val;
105 result = ReadUint8(io, &uint8Val);
106 EXPECT_EQ(result, true);
107 EXPECT_EQ(uint8Val, data.uint8Test);
108
109 uint16_t uint16Val;
110 result = ReadUint16(io, &uint16Val);
111 EXPECT_EQ(result, true);
112 EXPECT_EQ(uint16Val, data.uint16Test);
113
114 uint32_t uint32Val;
115 result = ReadUint32(io, &uint32Val);
116 EXPECT_EQ(result, true);
117 EXPECT_EQ(uint32Val, data.uint32Test);
118 }
119
120 /**
121 * @tc.name: test_serializer_WriteAndRead_001
122 * @tc.desc: test serializer primary type read write.
123 * @tc.type: FUNC
124 * @tc.require:
125 */
126 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_001, TestSize.Level0)
127 {
128 uint8_t buffer[BUFFER_SIZE] = {0};
129 int pid = -1;
130 int ret = -1;
131 int fd[2];
132
133 if (pipe(fd) < 0) {
134 perror("pipe error!\n");
135 return;
136 }
137
138 struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 };
139 pid = fork();
140 if (pid < 0) {
141 return;
142 }
143 else if (pid == 0) {
144 close(fd[0]);
145 IpcIo io;
146 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
147
148 WriteTestData(&io, data);
149 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
150 sleep(1);
151 close(fd[1]);
152 _exit(pid);
153
154 } else {
155 close(fd[1]);
156
157 IpcIo io;
158 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
159
160 sleep(2);
161 ret = read(fd[0], buffer, BUFFER_SIZE);
162
163 ReadTestData(&io, data);
164 close(fd[0]);
165 }
166 }
167
WriteTestDataUnaligned(IpcIo * io,const struct TestData & data)168 void WriteTestDataUnaligned(IpcIo* io, const struct TestData &data)
169 {
170 bool result = false;
171
172 result = WriteBoolUnaligned(io, data.boolTest);
173 EXPECT_EQ(result, true);
174
175 result = WriteInt8Unaligned(io, data.int8Test);
176 EXPECT_EQ(result, true);
177
178 result = WriteInt16Unaligned(io, data.int16Test);
179 EXPECT_EQ(result, true);
180
181 result = WriteUint8Unaligned(io, data.uint8Test);
182 EXPECT_EQ(result, true);
183
184 result = WriteUint16Unaligned(io, data.uint16Test);
185 EXPECT_EQ(result, true);
186 }
187
ReadTestDataUnaligned(IpcIo * io,const struct TestData & data)188 void ReadTestDataUnaligned(IpcIo* io, const struct TestData &data)
189 {
190 bool result = false;
191
192 bool boolVal;
193 result = ReadBoolUnaligned(io, &boolVal);
194 EXPECT_EQ(boolVal, data.boolTest);
195
196 int8_t int8Val;
197 result = ReadInt8Unaligned(io, &int8Val);
198 EXPECT_EQ(result, true);
199 EXPECT_EQ(int8Val, data.int8Test);
200
201 int16_t int16Val;
202 result = ReadInt16Unaligned(io, &int16Val);
203 EXPECT_EQ(result, true);
204 EXPECT_EQ(int16Val, data.int16Test);
205
206 uint8_t uint8Val;
207 result = ReadUInt8Unaligned(io, &uint8Val);
208 EXPECT_EQ(result, true);
209 EXPECT_EQ(uint8Val, data.uint8Test);
210
211 uint16_t uint16Val;
212 result = ReadUInt16Unaligned(io, &uint16Val);
213 EXPECT_EQ(result, true);
214 EXPECT_EQ(uint16Val, data.uint16Test);
215 }
216
217 /**
218 * @tc.name: test_serializer_WriteAndRead_002
219 * @tc.desc: test serializer primary type read write.
220 * @tc.type: FUNC
221 * @tc.require:
222 */
223 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_002, TestSize.Level0)
224 {
225 uint8_t buffer[BUFFER_SIZE] = {0};
226 int pid = -1;
227 int ret = -1;
228 int fd[2];
229
230 if (pipe(fd) < 0) {
231 perror("pipe error!\n");
232 return;
233 }
234 struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 };
235 pid = fork();
236 if (pid < 0) {
237 return;
238 } else if (pid == 0) {
239 close(fd[0]);
240 IpcIo io;
241 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
242
243 WriteTestDataUnaligned(&io, data);
244 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
245 sleep(1);
246 close(fd[1]);
247 _exit(pid);
248 } else {
249 close(fd[1]);
250
251 IpcIo io;
252 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
253 sleep(2);
254 ret = read(fd[0], buffer, BUFFER_SIZE);
255 ReadTestDataUnaligned(&io, data);
256 close(fd[0]);
257 }
258 }
259
260 /**
261 * @tc.name: test_serializer_WriteAndRead_003
262 * @tc.desc: test serializer primary type read write.
263 * @tc.type: FUNC
264 */
265 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_003, TestSize.Level0)
266 {
267 uint8_t buffer[BUFFER_SIZE] = {0};
268 int pid = -1;
269 int ret = -1;
270 int fd[2];
271 if (pipe(fd) < 0) {
272 return;
273 }
274 bool result;
275 int64_t int64Test = -0x1234567887654321;
276 uint64_t uint64Test = 0x1234567887654321;
277 pid = fork();
278 if (pid < 0) {
279 return;
280 }
281 else if (pid == 0) {
282 close(fd[0]);
283 IpcIo io;
284 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
285 result = WriteInt64(&io, int64Test);
286 EXPECT_EQ(result, true);
287 result = WriteUint64(&io, uint64Test);
288 EXPECT_EQ(result, true);
289 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
290 sleep(1);
291 close(fd[1]);
292 _exit(pid);
293 } else {
294 close(fd[1]);
295 IpcIo io;
296 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
297 sleep(2);
298 ret = read(fd[0], buffer, BUFFER_SIZE);
299 int64_t int64Read;
300 result = ReadInt64(&io, &int64Read);
301 EXPECT_EQ(result, true);
302 EXPECT_EQ(int64Read, int64Test);
303 uint64_t uint64Read;
304 result = ReadUint64(&io, &uint64Read);
305 EXPECT_EQ(result, true);
306 EXPECT_EQ(uint64Read, uint64Test);
307 close(fd[0]);
308 }
309 }
310
311 /**
312 * @tc.name: test_serializer_String_001
313 * @tc.desc: test serializer string read write.
314 * @tc.type: FUNC
315 */
316 HWTEST_F(UtilsSerializerTest, test_serializer_String_001, TestSize.Level0)
317 {
318 uint8_t buffer[BUFFER_SIZE] = {0};
319 int pid = -1;
320 int ret = -1;
321 int fd[2];
322
323 if (pipe(fd) < 0) {
324 return;
325 }
326 bool result;
327 const char stringWrite1[] = "asdfgh";
328 const char stringWrite2[] = "123456";
329 pid = fork();
330 if (pid < 0) {
331 return;
332 } else if (pid == 0) {
333 close(fd[0]);
334 IpcIo io;
335 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
336 result = WriteString(&io, stringWrite1);
337 EXPECT_EQ(result, true);
338 result = WriteString(&io, stringWrite2);
339 EXPECT_EQ(result, true);
340 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
341 sleep(1);
342 close(fd[1]);
343 _exit(pid);
344 } else {
345 close(fd[1]);
346 IpcIo io;
347 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
348 sleep(2);
349 ret = read(fd[0], buffer, BUFFER_SIZE);
350
351 uint8_t* stringRead1 = nullptr;
352 size_t len;
353 stringRead1 = ReadString(&io, &len);
354 for (size_t i = 0; i < len; i++) {
355 EXPECT_EQ(stringWrite1[i], stringRead1[i]);
356 }
357 uint8_t* stringRead2 = nullptr;
358 stringRead2 = ReadString(&io, &len);
359 for (size_t i = 0; i < len; i++) {
360 EXPECT_EQ(stringWrite2[i], stringRead2[i]);
361 }
362 close(fd[0]);
363 }
364 }
365
366 /**
367 * @tc.name: test_serializer_WriteAndRead_String_002
368 * @tc.desc: test serializer string read write.
369 * @tc.type: FUNC
370 */
371 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_String_002, TestSize.Level0)
372 {
373 uint8_t buffer[BUFFER_SIZE] = {0};
374 int pid = -1;
375 int ret = -1;
376 int fd[2];
377 if (pipe(fd) < 0) {
378 return;
379 }
380 bool result;
381 uint16_t str16Write[] = { 0x5634, 0x5635, 0x5636, 0x5637, 0x5638, 0x5639,
382 0x5640, 0x5641, 0x5642, 0x5643, 0x5644, 0x5645 };
383 size_t length = sizeof(str16Write) / sizeof(uint16_t);
384 pid = fork();
385 if (pid < 0) {
386 return;
387 } else if (pid == 0) {
388 close(fd[0]);
389 IpcIo io;
390 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
391 result = WriteString16(&io, str16Write, length);
392 EXPECT_EQ(result, true);
393 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
394 sleep(1);
395 close(fd[1]);
396 _exit(pid);
397 } else {
398 close(fd[1]);
399 IpcIo io;
400 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
401 sleep(2);
402 ret = read(fd[0], buffer, BUFFER_SIZE);
403
404 uint16_t* str16Read = nullptr;
405 str16Read = ReadString16(&io, &length);
406 for (size_t i = 0; i < length; i++) {
407 EXPECT_EQ(str16Write[i], str16Read[i]);
408 }
409 close(fd[0]);
410 }
411 }
412
413 /**
414 * @tc.name: test_serializer_WriteAndRead_Float_001
415 * @tc.desc: test serializer float and double types read write.
416 * @tc.type: FUNC
417 */
418 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Float_001, TestSize.Level0)
419 {
420 uint8_t buffer[BUFFER_SIZE] = {0};
421 int pid = -1;
422 int ret = -1;
423 int fd[2];
424 if (pipe(fd) < 0) {
425 return;
426 }
427 bool result;
428 float floatWrite = 12.345678f;
429 double doubleWrite = 1345.7653;
430 pid = fork();
431 if (pid < 0) {
432 return;
433 } else if (pid == 0) {
434 close(fd[0]);
435 IpcIo io;
436 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
437 result = WriteFloat(&io, floatWrite);
438 EXPECT_EQ(result, true);
439 result = WriteDouble(&io, doubleWrite);
440 EXPECT_EQ(result, true);
441 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
442 sleep(1);
443 close(fd[1]);
444 _exit(pid);
445 } else {
446 close(fd[1]);
447 IpcIo io;
448 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
449 sleep(2);
450 ret = read(fd[0], buffer, BUFFER_SIZE);
451
452 float floatRead;
453 result = ReadFloat(&io, &floatRead);
454 EXPECT_EQ(result, true);
455 EXPECT_EQ(floatWrite, floatRead);
456 double doubleRead;
457 result = ReadDouble(&io, &doubleRead);
458 EXPECT_EQ(doubleWrite, doubleRead);
459 close(fd[0]);
460 }
461 }
462
463 /**
464 * @tc.name: test_serializer_Data_Structure_001
465 * @tc.desc: test serializer struct data related function.
466 * @tc.type: FUNC
467 */
468 HWTEST_F(UtilsSerializerTest, test_serializer_Data_Structure_001, TestSize.Level0)
469 {
470 uint8_t buffer[BUFFER_SIZE] = {0};
471 int pid = -1;
472 int ret = -1;
473 int fd[2];
474 if (pipe(fd) < 0) {
475 return;
476 }
477 bool result;
478 const struct Padded pad = { 'p', 0x34567890, 0x2345678998765432 };
479 const struct Unpadded unpad = { 'u' };
480 pid = fork();
481 if (pid < 0) {
482 return;
483 } else if (pid == 0) {
484 close(fd[0]);
485 IpcIo io;
486 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
487
488 result = WriteBuffer(&io, static_cast<const void*>(&pad), sizeof(struct Padded));
489 EXPECT_EQ(true, result);
490 result = WriteBuffer(&io, static_cast<const void*>(&unpad), sizeof(struct Unpadded));
491 EXPECT_EQ(true, result);
492 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
493 sleep(1);
494 close(fd[1]);
495 _exit(pid);
496 } else {
497 close(fd[1]);
498 IpcIo io;
499 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
500 sleep(2);
501 ret = read(fd[0], buffer, BUFFER_SIZE);
502 const struct Padded* padRead = reinterpret_cast<const struct Padded*>(ReadBuffer(&io, sizeof(struct Padded)));
503 EXPECT_EQ(pad.title, padRead->title);
504 EXPECT_EQ(pad.handle, padRead->handle);
505 EXPECT_EQ(pad.cookie, padRead->cookie);
506 const struct Unpadded* unpadRead =
507 reinterpret_cast<const struct Unpadded *>(ReadBuffer(&io, sizeof(struct Unpadded)));
508 EXPECT_EQ(unpad.tip, unpadRead->tip);
509 close(fd[0]);
510 }
511 }
512
513 /**
514 * @tc.name: test_serializer_WriteAndReadVector_Bool_001
515 * @tc.desc: test bool vector serializer write and read.
516 * @tc.type: FUNC
517 */
518 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndReadVector_Bool_001, TestSize.Level0)
519 {
520 uint8_t buffer[BUFFER_SIZE] = {0};
521 int pid = -1;
522 int ret = -1;
523 int fd[2];
524 if (pipe(fd) < 0) {
525 return;
526 }
527 bool result;
528 const bool boolTest[12] = { true, false, false, true, false, false, true, false, true, true, false, true };
529 size_t sizeBool = sizeof(boolTest) / sizeof(bool);
530 pid = fork();
531 if (pid < 0) {
532 return;
533 } else if (pid == 0) {
534 close(fd[0]);
535 IpcIo io;
536 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
537 result = WriteBoolVector(&io, boolTest, sizeBool);
538 EXPECT_EQ(result, true);
539 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
540 sleep(1);
541 close(fd[1]);
542 _exit(pid);
543 } else {
544 close(fd[1]);
545 IpcIo io;
546 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
547 sleep(2);
548 ret = read(fd[0], buffer, BUFFER_SIZE);
549
550 bool* boolRead = nullptr;
551 size_t readLen = 0;
552 boolRead = ReadBoolVector(&io, &readLen);
553 EXPECT_EQ(readLen, sizeBool);
554 for (size_t i = 0; i < readLen; i++) {
555 EXPECT_EQ(boolTest[i], boolRead[i]);
556 }
557 free(boolRead);
558 close(fd[0]);
559 }
560 }
561
562 /**
563 * @tc.name: test_serializer_Vector_001
564 * @tc.desc: test int8_t and int16_t vector serializer write and read.
565 * @tc.type: FUNC
566 */
567 HWTEST_F(UtilsSerializerTest, test_serializer_Vector_001, TestSize.Level0)
568 {
569 uint8_t buffer[BUFFER_SIZE] = {0};
570 int pid = -1;
571 int ret = -1;
572 int fd[2];
573 if (pipe(fd) < 0) {
574 return;
575 }
576 bool result;
577 const int8_t int8Test[12] = { -0x27, -0x28, -0x29, -0x30, 0x31, 0x32, -0x33, -0x34, -0x35, -0x36, -0x37, -0x38 };
578 size_t sizeInt8 = sizeof(int8Test) / sizeof(int8_t);
579 const int16_t int16Test[12] = { 0x1234, -0x2345, 0x3456, -0x4567, 0x5678,
580 -0x1235, 0x1236, 0x1237, 0x1238, -0x1239, 0x1240, 0x1241 };
581 size_t sizeInt16 = sizeof(int16Test) / sizeof(int16_t);
582 pid = fork();
583 if (pid == 0) {
584 IpcIo io;
585 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
586 result = WriteInt8Vector(&io, int8Test, sizeInt8);
587 EXPECT_EQ(result, true);
588 result = WriteInt16Vector(&io, int16Test, sizeInt16);
589 EXPECT_EQ(result, true);
590 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
591 sleep(1);
592 close(fd[1]);
593 _exit(pid);
594 } else {
595 IpcIo io;
596 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
597 sleep(2);
598 ret = read(fd[0], buffer, BUFFER_SIZE);
599 int8_t* int8Read = nullptr;
600 size_t readLen = 0;
601 int8Read = ReadInt8Vector(&io, &readLen);
602 EXPECT_EQ(readLen, sizeInt8);
603 for (size_t i = 0; i < readLen; i++) {
604 EXPECT_EQ(int8Test[i], int8Read[i]);
605 }
606 int16_t* int16Read = nullptr;
607 int16Read = ReadInt16Vector(&io, &readLen);
608 EXPECT_EQ(readLen, sizeInt16);
609 for (size_t i = 0; i < readLen; i++) {
610 EXPECT_EQ(int16Test[i], int16Read[i]);
611 }
612 free(int16Read);
613 close(fd[0]);
614 }
615 }
616
617 /**
618 * @tc.name: test_serializer_Vector_002
619 * @tc.desc: test int32_t and int64_t vector serializer write and read.
620 * @tc.type: FUNC
621 */
622 HWTEST_F(UtilsSerializerTest, test_serializer_Vector_002, TestSize.Level0)
623 {
624 uint8_t buffer[BUFFER_SIZE] = {0};
625 int pid = -1;
626 int ret = -1;
627 int fd[2];
628 if (pipe(fd) < 0) {
629 return;
630 }
631 bool result;
632 const int32_t int32Test[12] = { 0x12345678, -0x23456789, 0x34567890, -0x45678901, 0x12345778, 0x12345878,
633 -0x12345978, 0x12345878, -0x12345818, 0x12345828, 0x12345838, 0x12345848 };
634 size_t sizeInt32 = sizeof(int32Test) / sizeof(int32_t);
635 const int64_t int64Test[12] = { 0x1234567887654321, -0x2345678998765432, 0x1234567887654300,
636 0x1234567887654301, 0x1234567887654302, 0x1234567887654303, -0x1234567887654304, 0x1234567887654305,
637 0x1234567887654306, 0x1234567887654307, 0x1234567887654308, 0x1234567887654309 };
638 size_t sizeInt64 = sizeof(int64Test) / sizeof(int64_t);
639 pid = fork();
640 if (pid == 0) {
641 IpcIo io;
642 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
643 result = WriteInt32Vector(&io, int32Test, sizeInt32);
644 EXPECT_EQ(result, true);
645 result = WriteInt64Vector(&io, int64Test, sizeInt64);
646 EXPECT_EQ(result, true);
647 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
648 sleep(1);
649 close(fd[1]);
650 _exit(pid);
651 } else {
652 IpcIo io;
653 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
654 sleep(2);
655 ret = read(fd[0], buffer, BUFFER_SIZE);
656 size_t readLen = 0;
657 int32_t* int32Read = nullptr;
658 int32Read = ReadInt32Vector(&io, &readLen);
659 EXPECT_EQ(readLen, sizeInt32);
660 for (size_t i = 0; i < readLen; i++) {
661 EXPECT_EQ(int32Test[i], int32Read[i]);
662 }
663 int64_t* int64Read = nullptr;
664 int64Read = ReadInt64Vector(&io, &readLen);
665 EXPECT_EQ(readLen, sizeInt64);
666 for (size_t i = 0; i < readLen; i++) {
667 EXPECT_EQ(int64Test[i], int64Read[i]);
668 }
669 close(fd[0]);
670 }
671 }
672 /**
673 * @tc.name: test_serializer_Vector_003
674 * @tc.desc: test uint8_t and uint16_t vector serializer write and read.
675 * @tc.type: FUNC
676 */
677 HWTEST_F(UtilsSerializerTest, test_serializer_Vector_003, TestSize.Level0)
678 {
679 uint8_t buffer[BUFFER_SIZE] = {0};
680 int pid = -1;
681 int ret = -1;
682 int fd[2];
683 if (pipe(fd) < 0) {
684 return;
685 }
686 bool result;
687 const uint8_t uint8Test[12] = { 0x01, 0x10, 0x20, 0x30, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 };
688 size_t sizeUint8 = sizeof(uint8Test) / sizeof(uint8_t);
689 const uint16_t uint16Test[12] = { 0x1234, 0x2345, 0x3456, 0x4567, 0x5678, 0x1235, 0x1236,
690 0x1237, 0x1238, 0x1239, 0x1240, 0x1241 };
691 size_t sizeUint16 = sizeof(uint16Test) / sizeof(uint16_t);
692 pid = fork();
693 if (pid == 0) {
694 IpcIo io;
695 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
696 result = WriteUInt8Vector(&io, uint8Test, sizeUint8);
697 EXPECT_EQ(result, true);
698 result = WriteUInt16Vector(&io, uint16Test, sizeUint16);
699 EXPECT_EQ(result, true);
700 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
701 sleep(1);
702 close(fd[1]);
703 _exit(pid);
704 } else {
705 IpcIo io;
706 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
707 sleep(2);
708 ret = read(fd[0], buffer, BUFFER_SIZE);
709 size_t readLen = 0;
710 uint8_t* uint8Read = nullptr;
711 uint8Read = ReadUInt8Vector(&io, &readLen);
712 EXPECT_EQ(readLen, sizeUint8);
713 for (size_t i = 0; i < readLen; i++) {
714 EXPECT_EQ(uint8Test[i], uint8Read[i]);
715 }
716 uint16_t* uint16Read = nullptr;
717 uint16Read = ReadUInt16Vector(&io, &readLen);
718 EXPECT_EQ(readLen, sizeUint16);
719 for (size_t i = 0; i < readLen; i++) {
720 EXPECT_EQ(uint16Test[i], uint16Read[i]);
721 }
722 close(fd[0]);
723 }
724 }
725
726 /**
727 * @tc.name: test_serializer_Vector_004
728 * @tc.desc: test int32_t and int64_t tvector serializer write and read.
729 * @tc.type: FUNC
730 */
731 HWTEST_F(UtilsSerializerTest, test_serializer_Vector_004, TestSize.Level0)
732 {
733 uint8_t buffer[BUFFER_SIZE] = {0};
734 int pid = -1;
735 int ret = -1;
736 int fd[2];
737 if (pipe(fd) < 0) {
738 return;
739 }
740 bool result;
741 const uint32_t uint32Test[12] = { 0x12345678, 0x23456789, 0x34567890, 0x45678901, 0x12345778, 0x12345878,
742 0x12345978, 0x12345878, 0x12345818, 0x12345828, 0x12345838, 0x12345848 };
743 size_t sizeUint32 = sizeof(uint32Test) / sizeof(uint32_t);
744 const uint64_t uint64Test[12] = { 0x1234567887654321, 0x2345678998765432, 0x1234567887654300, 0x1234567887654301,
745 0x1234567887654302, 0x1234567887654303, 0x1234567887654304, 0x1234567887654305, 0x1234567887654306,
746 0x1234567887654307, 0x1234567887654308, 0x1234567887654309 };
747 size_t sizeUint64 = sizeof(uint64Test) / sizeof(uint64_t);
748 pid = fork();
749 if (pid == 0) {
750 IpcIo io;
751 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
752 result = WriteUInt32Vector(&io, uint32Test, sizeUint32);
753 EXPECT_EQ(result, true);
754 result = WriteUInt64Vector(&io, uint64Test, sizeUint64);
755 EXPECT_EQ(result, true);
756 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
757 sleep(1);
758 close(fd[1]);
759 _exit(pid);
760 } else {
761 IpcIo io;
762 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
763 sleep(2);
764 ret = read(fd[0], buffer, BUFFER_SIZE);
765 size_t readLen = 0;
766 uint32_t* uint32Read = nullptr;
767 uint32Read = ReadUInt32Vector(&io, &readLen);
768 EXPECT_EQ(readLen, sizeUint32);
769 for (size_t i = 0; i < readLen; i++) {
770 EXPECT_EQ(uint32Test[i], uint32Read[i]);
771 }
772 uint64_t* uint64Read = nullptr;
773 uint64Read = ReadUInt64Vector(&io, &readLen);
774 EXPECT_EQ(readLen, sizeUint64);
775 for (size_t i = 0; i < readLen; i++) {
776 EXPECT_EQ(uint64Test[i], uint64Read[i]);
777 }
778 close(fd[0]);
779 }
780 }
781
782 /**
783 * @tc.name: test_serializer_Vector_005
784 * @tc.desc: test vector serializer read and write.
785 * @tc.type: FUNC
786 */
787 HWTEST_F(UtilsSerializerTest, test_serializer_Vector_005, TestSize.Level0)
788 {
789 uint8_t buffer[BUFFER_SIZE] = {0};
790 int pid = -1;
791 int ret = -1;
792 int fd[2];
793 if (pipe(fd) < 0) {
794 return;
795 }
796 bool result;
797 const float floatTest[12] = { 11221.132313, 11221.45678, 11221.45608, 11221.45618, 11221.45628,
798 11221.45638, 11221.45648, 11221.45658, 11221.45668, 11221.45678, 11221.45688, 11221.45698 };
799 size_t sizeFloat = sizeof(floatTest) / sizeof(float);
800 const double doubleTest[12] = { 1122.132313, 1122.45678, 1122.45678, 1122.45660, 1122.45661, 1122.45662,
801 1122.45663, 1122.45664, 1122.456765, 1122.45666, 1122.45667, 1122.45668 };
802 size_t sizeDouble = sizeof(doubleTest) / sizeof(double);
803 pid = fork();
804 if (pid == 0) {
805 IpcIo io;
806 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
807 result = WriteFloatVector(&io, floatTest, sizeFloat);
808 EXPECT_EQ(result, true);
809 result = WriteDoubleVector(&io, doubleTest, sizeDouble);
810 EXPECT_EQ(result, true);
811 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
812 sleep(1);
813 close(fd[1]);
814 _exit(pid);
815 } else {
816 IpcIo io;
817 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
818 sleep(2);
819 ret = read(fd[0], buffer, BUFFER_SIZE);
820 float* floatRead = nullptr;
821 floatRead = ReadFloatVector(&io, &sizeFloat);
822 for (size_t i = 0; i < sizeFloat; i++) {
823 EXPECT_EQ(floatTest[i], floatRead[i]);
824 }
825 double* doubleRead = nullptr;
826 doubleRead = ReadDoubleVector(&io, &sizeDouble);
827 for (size_t i = 0; i < sizeDouble; i++) {
828 EXPECT_EQ(doubleTest[i], doubleRead[i]);
829 }
830 close(fd[0]);
831 }
832 }
833
834 /**
835 * @tc.name: test_serializer_WriteAndRead_String_003
836 * @tc.desc: test string serializer read and write.
837 * @tc.type: FUNC
838 */
839 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_String_003, TestSize.Level0)
840 {
841 uint8_t buffer[BUFFER_SIZE] = {0};
842 int pid = -1;
843 int ret = -1;
844 int fd[2];
845 if (pipe(fd) < 0) {
846 return;
847 }
848 bool result;
849 const uint16_t interfaceTest[] = { 0x5634, 0x5635, 0x5636, 0x5637, 0x5638, 0x5639,
850 0x5640, 0x5641, 0x5642, 0x5643, 0x5644, 0x5645 };
851 size_t len = sizeof(interfaceTest) / sizeof(uint16_t);
852 const double doubleTest[12] = { 1122.132313, 1122.45678, 1122.45678, 1122.45660, 1122.45661,
853 1122.45662, 1122.45663, 1122.45664, 1122.456765, 1122.45666, 1122.45667, 1122.45668 };
854 size_t sizeDouble = sizeof(doubleTest) / sizeof(double);
855 pid = fork();
856 if (pid == 0) {
857 IpcIo io;
858 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
859 result = WriteInterfaceToken(&io, interfaceTest, len);
860 EXPECT_EQ(result, true);
861 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
862 sleep(1);
863 close(fd[1]);
864 _exit(pid);
865 } else {
866 IpcIo io;
867 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
868 sleep(2);
869 ret = read(fd[0], buffer, BUFFER_SIZE);
870 uint16_t* interfaceRead = nullptr;
871 size_t length;
872 interfaceRead = ReadInterfaceToken(&io, &length);
873 for (size_t i = 0; i < length; i++) {
874 EXPECT_EQ(interfaceTest[i], interfaceRead[i]);
875 }
876 close(fd[0]);
877 }
878 }
879
880 /**
881 * @tc.name: test_serializer_WriteAndRead_String_004
882 * @tc.desc: test string serializer read and write.
883 * @tc.type: FUNC
884 */
885 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_String_004, TestSize.Level0)
886 {
887 uint8_t buffer[BUFFER_SIZE] = {0};
888 int pid = -1;
889 int ret = -1;
890 int fd[2];
891 if (pipe(fd) < 0) {
892 return;
893 }
894 bool result;
895 const struct Padded testData = { 'p', 0x34567890, 0x2345678998765432 };
896 size_t size = sizeof(struct Padded);
897 const double doubleTest[12] = { 1122.132313, 1122.45678, 1122.45678, 1122.45660, 1122.45661, 1122.45662,
898 1122.45663, 1122.45664, 1122.456765, 1122.45666, 1122.45667, 1122.45668 };
899 size_t sizeDouble = sizeof(doubleTest) / sizeof(double);
900 pid = fork();
901 if (pid == 0) {
902 IpcIo io;
903 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
904 result = WriteRawData(&io, &testData, size);
905 EXPECT_EQ(result, true);
906 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
907 sleep(1);
908 close(fd[1]);
909 _exit(pid);
910 } else {
911 IpcIo io;
912 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
913 sleep(2);
914 ret = read(fd[0], buffer, BUFFER_SIZE);
915 struct Padded* dataRead = nullptr;
916 dataRead = reinterpret_cast<struct Padded*>(ReadRawData(&io, sizeof(struct Padded)));
917 EXPECT_EQ(testData.title, dataRead->title);
918 EXPECT_EQ(testData.handle, dataRead->handle);
919 EXPECT_EQ(testData.cookie, dataRead->cookie);
920 close(fd[0]);
921 }
922 }
923
924 /**
925 * @tc.name: test_serializer_WriteAndRead_Pointer_001
926 * @tc.desc: test pointer serializer read and write.
927 * @tc.type: FUNC
928 */
929 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Pointer_001, TestSize.Level0)
930 {
931 uint8_t buffer[BUFFER_SIZE] = {0};
932 int pid = -1;
933 int ret = -1;
934 int fd[2];
935 if (pipe(fd) < 0) {
936 return;
937 }
938 bool result;
939 char* testData = "sjf";
940 pid = fork();
941 if (pid == 0) {
942 IpcIo io;
943 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
944 result = WritePointer(&io, (uintptr_t)testData);
945 EXPECT_EQ(result, true);
946 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
947 sleep(1);
948 close(fd[1]);
949 _exit(pid);
950 } else {
951 IpcIo io;
952 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
953 sleep(2);
954 ret = read(fd[0], buffer, BUFFER_SIZE);
955 uintptr_t valueRead = ReadPointer(&io);
956 EXPECT_EQ(0, strcmp(testData, (char*)valueRead));
957 close(fd[0]);
958 }
959 }
960
961 /**
962 * @tc.name: test_serializer_WriteAndRead_threshold_001
963 * @tc.desc: test threshold serializer read and write.
964 * @tc.type: FUNC
965 */
966 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_threshold_001, TestSize.Level0)
967 {
968 IpcIo io;
969 uint8_t buffer[SMALL_BUFFER_SIZE] = { 0 };
970 IpcIoInit(&io, buffer, SMALL_BUFFER_SIZE, 0);
971 const char* strwrite = "test for write string threshold********************************************************\
972 #####################################################";
973
974 bool result = WriteString(&io, strwrite);
975 EXPECT_EQ(result, false);
976 }
977
978 /**
979 * @tc.name: test_serializer_WriteAndRead_ioUninitialized_001
980 * @tc.desc: test io uninitialized serializer read and write.
981 * @tc.type: FUNC
982 */
983 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_ioUninitialized_001, TestSize.Level0)
984 {
985 IpcIo io;
986 bool boolTest = false;
987 bool result = WriteBool(&io, boolTest);
988 EXPECT_EQ(result, false);
989
990 int8_t int8Test = -0x34;
991 result = WriteInt8(&io, int8Test);
992 EXPECT_EQ(result, false);
993 }
994
995 /**
996 * @tc.name: test_serializer_WriteAndRead_Maximum_001
997 * @tc.desc: test serializer Maximum of primary type read write.
998 * @tc.type: FUNC
999 * @tc.require:
1000 */
1001 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Maximum_001, TestSize.Level0)
1002 {
1003 uint8_t buffer[BUFFER_SIZE] = {0};
1004 int pid = -1;
1005 int ret = -1;
1006 int fd[2];
1007 if (pipe(fd) < 0) {
1008 return;
1009 }
1010 bool result;
1011 struct TestData data = { true, 0x7F, 0x7FFF, 0x7FFFFFFF, 0xFF, 0xFFFF, 0xFFFFFFFF };
1012 pid = fork();
1013 if (pid < 0) {
1014 return;
1015 } else if (pid == 0) {
1016 close(fd[0]);
1017 IpcIo io;
1018 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1019 WriteTestData(&io, data);
1020 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
1021 sleep(1);
1022 close(fd[1]);
1023 _exit(pid);
1024 } else {
1025 close(fd[1]);
1026 IpcIo io;
1027 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1028 sleep(2);
1029 ret = read(fd[0], buffer, BUFFER_SIZE);
1030 ReadTestData(&io, data);
1031 close(fd[0]);
1032 }
1033 }
1034
1035 /**
1036 * @tc.name: test_serializer_WriteAndRead_Maximum_002
1037 * @tc.desc: test serializer Maximum of primary type read write.
1038 * @tc.type: FUNC
1039 * @tc.require:
1040 */
1041 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Maximum_002, TestSize.Level0)
1042 {
1043 uint8_t buffer[BUFFER_SIZE] = {0};
1044 int pid = -1;
1045 int ret = -1;
1046 int fd[2];
1047 if (pipe(fd) < 0) {
1048 perror("pipe error!\n");
1049 return;
1050 }
1051 bool result;
1052 struct TestData data = { true, 0x7F, 0x7FFF, 0x7FFFFFFF, 0xFF, 0xFFFF, 0xFFFFFFFF };
1053 pid = fork();
1054 if (pid < 0) {
1055 return;
1056 }
1057 else if (pid == 0) {
1058 close(fd[0]);
1059 IpcIo io;
1060 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1061 WriteTestDataUnaligned(&io, data);
1062 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
1063 sleep(1);
1064 close(fd[1]);
1065 _exit(pid);
1066 } else {
1067 close(fd[1]);
1068 IpcIo io;
1069 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1070 sleep(2);
1071 ret = read(fd[0], buffer, BUFFER_SIZE);
1072 ReadTestDataUnaligned(&io, data);
1073 close(fd[0]);
1074 }
1075 }
1076
1077 /**
1078 * @tc.name: test_serializer_WriteAndRead_Maximum_003
1079 * @tc.desc: test serializer primary type read write.
1080 * @tc.type: FUNC
1081 */
1082 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Maximum_003, TestSize.Level0)
1083 {
1084 uint8_t buffer[BUFFER_SIZE] = {0};
1085 int pid = -1;
1086 int ret = -1;
1087 int fd[2];
1088 if (pipe(fd) < 0) {
1089 return;
1090 }
1091 bool result;
1092 int64_t int64Test = 0x7FFFFFFFFFFFFFFF;
1093 uint64_t uint64Test = 0xFFFFFFFFFFFFFFFF;
1094 pid = fork();
1095 if (pid < 0) {
1096 return;
1097 } else if (pid == 0) {
1098 close(fd[0]);
1099 IpcIo io;
1100 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1101 result = WriteInt64(&io, int64Test);
1102 EXPECT_EQ(result, true);
1103 result = WriteUint64(&io, uint64Test);
1104 EXPECT_EQ(result, true);
1105 ret = write(fd[1], buffer, io.bufferCur - io.bufferBase);
1106 sleep(1);
1107 close(fd[1]);
1108 _exit(pid);
1109 } else {
1110 close(fd[1]);
1111 IpcIo io;
1112 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1113 sleep(2);
1114 ret = read(fd[0], buffer, BUFFER_SIZE);
1115 int64_t int64Read;
1116 result = ReadInt64(&io, &int64Read);
1117 EXPECT_EQ(result, true);
1118 EXPECT_EQ(int64Read, int64Test);
1119 uint64_t uint64Read;
1120 result = ReadUint64(&io, &uint64Read);
1121 EXPECT_EQ(result, true);
1122 EXPECT_EQ(uint64Read, uint64Test);
1123 close(fd[0]);
1124 }
1125 }
1126
1127 /**
1128 * @tc.name: test_serializer_WriteAndRead_Abnormal_String_001
1129 * @tc.desc: test serializer Abnormal scene read write.
1130 * @tc.type: FUNC
1131 */
1132 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_String_001, TestSize.Level2)
1133 {
1134 IpcIo io;
1135 uint8_t buffer[BUFFER_SIZE] = { 0 };
1136 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1137
1138 const char *stringWrite = nullptr;
1139 bool result = WriteString(&io, stringWrite);
1140 EXPECT_EQ(result, false);
1141 }
1142
1143 /**
1144 * @tc.name: test_serializer_WriteAndRead_Abnormal_String16_001
1145 * @tc.desc: test serializer Abnormal scene read write.
1146 * @tc.type: FUNC
1147 */
1148 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_String16_001, TestSize.Level2)
1149 {
1150 IpcIo io;
1151 uint8_t buffer[BUFFER_SIZE] = { 0 };
1152 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1153
1154 uint16_t str16Write[] = {};
1155 size_t length = sizeof(str16Write) / sizeof(uint16_t);
1156 bool result = WriteString16(&io, str16Write, length);
1157 EXPECT_EQ(result, false);
1158 }
1159
1160 /**
1161 * @tc.name: test_serializer_WriteAndRead_Abnormal_Buffer_001
1162 * @tc.desc: test serializer Abnormal scene read write.
1163 * @tc.type: FUNC
1164 */
1165 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_Buffer_001, TestSize.Level2)
1166 {
1167 IpcIo io;
1168 uint8_t buffer[BUFFER_SIZE] = { 0 };
1169 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1170
1171 struct Padded pad;
1172 bool result = WriteBuffer(&io, static_cast<const void*>(&pad), 0);
1173 EXPECT_EQ(result, false);
1174 }
1175
1176 /**
1177 * @tc.name: test_serializer_WriteAndRead_Abnormal_InterfaceToken_001
1178 * @tc.desc: test serializer Abnormal scene read write.
1179 * @tc.type: FUNC
1180 */
1181 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_InterfaceToken_001, TestSize.Level2)
1182 {
1183 IpcIo io;
1184 uint8_t buffer[BUFFER_SIZE] = { 0 };
1185 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1186
1187 const uint16_t interfaceTest[] = {};
1188 size_t len = sizeof(interfaceTest) / sizeof(uint16_t);
1189 bool result = WriteInterfaceToken(&io, interfaceTest, len);
1190 EXPECT_EQ(result, false);
1191 }
1192
1193 /**
1194 * @tc.name: test_serializer_WriteAndRead_Abnormal_RawData_001
1195 * @tc.desc: test serializer Abnormal scene read write.
1196 * @tc.type: FUNC
1197 */
1198 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_RawData_001, TestSize.Level2)
1199 {
1200 IpcIo io;
1201 uint8_t buffer[BUFFER_SIZE] = { 0 };
1202 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1203
1204 struct Padded rawDataTest;
1205 bool result = WriteRawData(&io, &rawDataTest, 0);
1206 EXPECT_EQ(result, false);
1207 }
1208
1209 /**
1210 * @tc.name: test_serializer_WriteAndRead_Abnormal_BoolVector_001
1211 * @tc.desc: test serializer Abnormal scene read write.
1212 * @tc.type: FUNC
1213 */
1214 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_BoolVector_001, TestSize.Level2)
1215 {
1216 IpcIo io;
1217 uint8_t buffer[BUFFER_SIZE] = { 0 };
1218 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1219
1220 const bool boolTest[] = {};
1221 size_t sizeBool = sizeof(boolTest) / sizeof(bool);
1222 bool result = WriteBoolVector(&io, boolTest, sizeBool);
1223 EXPECT_EQ(result, false);
1224 }
1225
1226 /**
1227 * @tc.name: test_serializer_WriteAndRead_Abnormal_Int8Vector_001
1228 * @tc.desc: test serializer Abnormal scene read write.
1229 * @tc.type: FUNC
1230 */
1231 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_Int8Vector_001, TestSize.Level2)
1232 {
1233 IpcIo io;
1234 uint8_t buffer[BUFFER_SIZE] = { 0 };
1235 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1236
1237 const int8_t int8Test[] = {};
1238 size_t sizeInt8 = sizeof(int8Test) / sizeof(int8_t);
1239 bool result = WriteInt8Vector(&io, int8Test, sizeInt8);
1240 EXPECT_EQ(result, false);
1241 }
1242
1243 /**
1244 * @tc.name: test_serializer_WriteAndRead_Abnormal_Int16Vector_001
1245 * @tc.desc: test serializer Abnormal scene read write.
1246 * @tc.type: FUNC
1247 */
1248 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_Int16Vector_001, TestSize.Level2)
1249 {
1250 IpcIo io;
1251 uint8_t buffer[BUFFER_SIZE] = { 0 };
1252 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1253
1254 const int16_t int16Test[] = {};
1255 size_t sizeInt16 = sizeof(int16Test) / sizeof(int16_t);
1256 bool result = WriteInt16Vector(&io, int16Test, sizeInt16);
1257 EXPECT_EQ(result, false);
1258 }
1259
1260 /**
1261 * @tc.name: test_serializer_WriteAndRead_Abnormal_Int32Vector_001
1262 * @tc.desc: test serializer Abnormal scene read write.
1263 * @tc.type: FUNC
1264 */
1265 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_Int32Vector_001, TestSize.Level2)
1266 {
1267 IpcIo io;
1268 uint8_t buffer[BUFFER_SIZE] = { 0 };
1269 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1270
1271 const int32_t int32Test[] = {};
1272 size_t sizeInt32 = sizeof(int32Test) / sizeof(int32_t);
1273 bool result = WriteInt32Vector(&io, int32Test, sizeInt32);
1274 EXPECT_EQ(result, false);
1275 }
1276
1277 /**
1278 * @tc.name: test_serializer_WriteAndRead_Abnormal_Int64Vector_001
1279 * @tc.desc: test serializer Abnormal scene read write.
1280 * @tc.type: FUNC
1281 */
1282 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_Int64Vector_001, TestSize.Level2)
1283 {
1284 IpcIo io;
1285 uint8_t buffer[BUFFER_SIZE] = { 0 };
1286 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1287
1288 const int64_t int64Test[] = {};
1289 size_t sizeInt64 = sizeof(int64Test) / sizeof(int64_t);
1290 bool result = WriteInt64Vector(&io, int64Test, sizeInt64);
1291 EXPECT_EQ(result, false);
1292 }
1293
1294 /**
1295 * @tc.name: test_serializer_WriteAndRead_Abnormal_UInt8Vector_001
1296 * @tc.desc: test serializer Abnormal scene read write.
1297 * @tc.type: FUNC
1298 */
1299 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_UInt8Vector_001, TestSize.Level2)
1300 {
1301 IpcIo io;
1302 uint8_t buffer[BUFFER_SIZE] = { 0 };
1303 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1304
1305 const uint8_t uint8Test[] = {};
1306 size_t sizeUint8 = sizeof(uint8Test) / sizeof(uint8_t);
1307 bool result = WriteUInt8Vector(&io, uint8Test, sizeUint8);
1308 EXPECT_EQ(result, false);
1309 }
1310
1311 /**
1312 * @tc.name: test_serializer_WriteAndRead_Abnormal_UInt16Vector_001
1313 * @tc.desc: test serializer Abnormal scene read write.
1314 * @tc.type: FUNC
1315 */
1316 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_UInt16Vector_001, TestSize.Level2)
1317 {
1318 IpcIo io;
1319 uint8_t buffer[BUFFER_SIZE] = { 0 };
1320 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1321
1322 const uint16_t uint16Test[] = {};
1323 size_t sizeUint16 = sizeof(uint16Test) / sizeof(uint16_t);
1324 bool result = WriteUInt16Vector(&io, uint16Test, sizeUint16);
1325 EXPECT_EQ(result, false);
1326 }
1327
1328 /**
1329 * @tc.name: test_serializer_WriteAndRead_Abnormal_UInt32Vector_001
1330 * @tc.desc: test serializer Abnormal scene read write.
1331 * @tc.type: FUNC
1332 */
1333 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_UInt32Vector_001, TestSize.Level2)
1334 {
1335 IpcIo io;
1336 uint8_t buffer[BUFFER_SIZE] = { 0 };
1337 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1338
1339 const uint32_t uint32Test[] = {};
1340 size_t sizeUint32 = sizeof(uint32Test) / sizeof(uint32_t);
1341 bool result = WriteUInt32Vector(&io, uint32Test, sizeUint32);
1342 EXPECT_EQ(result, false);
1343 }
1344
1345 /**
1346 * @tc.name: test_serializer_WriteAndRead_Abnormal_UInt64Vector_001
1347 * @tc.desc: test serializer Abnormal scene read write.
1348 * @tc.type: FUNC
1349 */
1350 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_UInt64Vector_001, TestSize.Level2)
1351 {
1352 IpcIo io;
1353 uint8_t buffer[BUFFER_SIZE] = { 0 };
1354 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1355
1356 const uint64_t uint64Test[] = {};
1357 size_t sizeUint64 = sizeof(uint64Test) / sizeof(uint64_t);
1358 bool result = WriteUInt64Vector(&io, uint64Test, sizeUint64);
1359 EXPECT_EQ(result, false);
1360 }
1361
1362 /**
1363 * @tc.name: test_serializer_WriteAndRead_Abnormal_FloatVector_001
1364 * @tc.desc: test serializer Abnormal scene read write.
1365 * @tc.type: FUNC
1366 */
1367 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_FloatVector_001, TestSize.Level2)
1368 {
1369 IpcIo io;
1370 uint8_t buffer[BUFFER_SIZE] = { 0 };
1371 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1372
1373 const float floatTest[] = {};
1374 size_t sizeFloat = sizeof(floatTest) / sizeof(float);
1375 bool result = WriteFloatVector(&io, floatTest, sizeFloat);
1376 EXPECT_EQ(result, false);
1377 }
1378
1379 /**
1380 * @tc.name: test_serializer_WriteAndRead_Abnormal_DoubleVector_001
1381 * @tc.desc: test serializer Abnormal scene read write.
1382 * @tc.type: FUNC
1383 */
1384 HWTEST_F(UtilsSerializerTest, test_serializer_WriteAndRead_Abnormal_DoubleVector_001, TestSize.Level2)
1385 {
1386 IpcIo io;
1387 uint8_t buffer[BUFFER_SIZE] = { 0 };
1388 IpcIoInit(&io, buffer, BUFFER_SIZE, 0);
1389
1390 const double doubleTest[] = {};
1391 size_t sizeDouble = sizeof(doubleTest) / sizeof(double);
1392 bool result = WriteDoubleVector(&io, doubleTest, sizeDouble);
1393 EXPECT_EQ(result, false);
1394 }
1395