13f4cbf05Sopenharmony_ci/*
23f4cbf05Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
33f4cbf05Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43f4cbf05Sopenharmony_ci * you may not use this file except in compliance with the License.
53f4cbf05Sopenharmony_ci * You may obtain a copy of the License at
63f4cbf05Sopenharmony_ci *
73f4cbf05Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
83f4cbf05Sopenharmony_ci *
93f4cbf05Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103f4cbf05Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113f4cbf05Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123f4cbf05Sopenharmony_ci * See the License for the specific language governing permissions and
133f4cbf05Sopenharmony_ci * limitations under the License.
143f4cbf05Sopenharmony_ci */
153f4cbf05Sopenharmony_ci
163f4cbf05Sopenharmony_ci#include <gtest/gtest.h>
173f4cbf05Sopenharmony_ci#include <algorithm>
183f4cbf05Sopenharmony_ci#include <fstream>
193f4cbf05Sopenharmony_ci#include <iostream>
203f4cbf05Sopenharmony_ci#include "directory_ex.h"
213f4cbf05Sopenharmony_ci#include "parcel.h"
223f4cbf05Sopenharmony_ci#include "refbase.h"
233f4cbf05Sopenharmony_ci#include "securec.h"
243f4cbf05Sopenharmony_ciusing namespace testing::ext;
253f4cbf05Sopenharmony_ciusing namespace std;
263f4cbf05Sopenharmony_ci
273f4cbf05Sopenharmony_cinamespace OHOS {
283f4cbf05Sopenharmony_cinamespace {
293f4cbf05Sopenharmony_cistatic const int BINDER_TYPE_HANDLE = 0x73682a85; // binder header type handle
303f4cbf05Sopenharmony_cistatic const int BINDER_TYPE_FD = 0x66642a85; // binder header type fd
313f4cbf05Sopenharmony_ciconst int MAX_PARCEL_SIZE = 1000;
323f4cbf05Sopenharmony_cichar g_data[MAX_PARCEL_SIZE];
333f4cbf05Sopenharmony_ciclass UtilsParcelTest : public testing::Test {
343f4cbf05Sopenharmony_cipublic:
353f4cbf05Sopenharmony_ci    static constexpr size_t DEFAULT_CPACITY = 204800; // 200K
363f4cbf05Sopenharmony_ci    static constexpr size_t CAPACITY_THRESHOLD = 4096; // 4k
373f4cbf05Sopenharmony_ci    static void TearDownTestCase(void);
383f4cbf05Sopenharmony_ci};
393f4cbf05Sopenharmony_ci
403f4cbf05Sopenharmony_civoid UtilsParcelTest::TearDownTestCase(void)
413f4cbf05Sopenharmony_ci{
423f4cbf05Sopenharmony_ci    for (int i = 0; i < MAX_PARCEL_SIZE; i++) {
433f4cbf05Sopenharmony_ci        g_data[i] = 0;
443f4cbf05Sopenharmony_ci    }
453f4cbf05Sopenharmony_ci}
463f4cbf05Sopenharmony_ci
473f4cbf05Sopenharmony_ciclass RemoteObject : public virtual Parcelable {
483f4cbf05Sopenharmony_cipublic:
493f4cbf05Sopenharmony_ci    RemoteObject() { asRemote_ = true; };
503f4cbf05Sopenharmony_ci    bool Marshalling(Parcel &parcel) const override;
513f4cbf05Sopenharmony_ci    static sptr<RemoteObject> Unmarshalling(Parcel &parcel);
523f4cbf05Sopenharmony_ci};
533f4cbf05Sopenharmony_ci
543f4cbf05Sopenharmony_cibool RemoteObject::Marshalling(Parcel &parcel) const
553f4cbf05Sopenharmony_ci{
563f4cbf05Sopenharmony_ci    parcel_flat_binder_object flat;
573f4cbf05Sopenharmony_ci    flat.hdr.type = 0xff;
583f4cbf05Sopenharmony_ci    flat.flags = 0x7f;
593f4cbf05Sopenharmony_ci    flat.binder = 0;
603f4cbf05Sopenharmony_ci    flat.handle = (uint32_t)(-1);
613f4cbf05Sopenharmony_ci    flat.cookie = reinterpret_cast<uintptr_t>(this);
623f4cbf05Sopenharmony_ci    bool status = parcel.WriteBuffer(&flat, sizeof(parcel_flat_binder_object));
633f4cbf05Sopenharmony_ci    if (!status) {
643f4cbf05Sopenharmony_ci        return false;
653f4cbf05Sopenharmony_ci    }
663f4cbf05Sopenharmony_ci    return true;
673f4cbf05Sopenharmony_ci}
683f4cbf05Sopenharmony_ci
693f4cbf05Sopenharmony_cisptr<RemoteObject> RemoteObject::Unmarshalling(Parcel &parcel)
703f4cbf05Sopenharmony_ci{
713f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(sizeof(parcel_flat_binder_object), false);
723f4cbf05Sopenharmony_ci    if (buffer == nullptr) {
733f4cbf05Sopenharmony_ci        return nullptr;
743f4cbf05Sopenharmony_ci    }
753f4cbf05Sopenharmony_ci    sptr<RemoteObject> obj = new RemoteObject();
763f4cbf05Sopenharmony_ci    return obj;
773f4cbf05Sopenharmony_ci}
783f4cbf05Sopenharmony_ci
793f4cbf05Sopenharmony_ciclass RemoteFdObject : public virtual Parcelable {
803f4cbf05Sopenharmony_cipublic:
813f4cbf05Sopenharmony_ci    RemoteFdObject() { asRemote_ = true; };
823f4cbf05Sopenharmony_ci    bool Marshalling(Parcel &parcel) const override;
833f4cbf05Sopenharmony_ci    static sptr<RemoteFdObject> Unmarshalling(Parcel &parcel);
843f4cbf05Sopenharmony_ci};
853f4cbf05Sopenharmony_ci
863f4cbf05Sopenharmony_cibool RemoteFdObject::Marshalling(Parcel &parcel) const
873f4cbf05Sopenharmony_ci{
883f4cbf05Sopenharmony_ci    parcel_flat_binder_object flat;
893f4cbf05Sopenharmony_ci    flat.hdr.type = BINDER_TYPE_FD;
903f4cbf05Sopenharmony_ci    flat.flags = 0x7f;
913f4cbf05Sopenharmony_ci    flat.binder = 0;
923f4cbf05Sopenharmony_ci    flat.handle = (uint32_t)(-1);
933f4cbf05Sopenharmony_ci    flat.cookie = reinterpret_cast<uintptr_t>(this);
943f4cbf05Sopenharmony_ci    bool status = parcel.WriteBuffer(&flat, sizeof(parcel_flat_binder_object));
953f4cbf05Sopenharmony_ci    if (!status) {
963f4cbf05Sopenharmony_ci        return false;
973f4cbf05Sopenharmony_ci    }
983f4cbf05Sopenharmony_ci    return true;
993f4cbf05Sopenharmony_ci}
1003f4cbf05Sopenharmony_ci
1013f4cbf05Sopenharmony_cisptr<RemoteFdObject> RemoteFdObject::Unmarshalling(Parcel &parcel)
1023f4cbf05Sopenharmony_ci{
1033f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(sizeof(parcel_flat_binder_object), false);
1043f4cbf05Sopenharmony_ci    if (buffer == nullptr) {
1053f4cbf05Sopenharmony_ci        return nullptr;
1063f4cbf05Sopenharmony_ci    }
1073f4cbf05Sopenharmony_ci    sptr<RemoteFdObject> obj = new RemoteFdObject();
1083f4cbf05Sopenharmony_ci    return obj;
1093f4cbf05Sopenharmony_ci}
1103f4cbf05Sopenharmony_ci
1113f4cbf05Sopenharmony_ciclass RemoteHandleObject : public virtual Parcelable {
1123f4cbf05Sopenharmony_cipublic:
1133f4cbf05Sopenharmony_ci    RemoteHandleObject() { asRemote_ = true; };
1143f4cbf05Sopenharmony_ci    bool Marshalling(Parcel &parcel) const override;
1153f4cbf05Sopenharmony_ci    static sptr<RemoteHandleObject> Unmarshalling(Parcel &parcel);
1163f4cbf05Sopenharmony_ci};
1173f4cbf05Sopenharmony_ci
1183f4cbf05Sopenharmony_cibool RemoteHandleObject::Marshalling(Parcel &parcel) const
1193f4cbf05Sopenharmony_ci{
1203f4cbf05Sopenharmony_ci    parcel_flat_binder_object flat;
1213f4cbf05Sopenharmony_ci    flat.hdr.type = BINDER_TYPE_HANDLE;
1223f4cbf05Sopenharmony_ci    flat.flags = 0x7f;
1233f4cbf05Sopenharmony_ci    flat.binder = 0;
1243f4cbf05Sopenharmony_ci    flat.handle = (uint32_t)(-1);
1253f4cbf05Sopenharmony_ci    flat.cookie = reinterpret_cast<uintptr_t>(this);
1263f4cbf05Sopenharmony_ci    bool status = parcel.WriteBuffer(&flat, sizeof(parcel_flat_binder_object));
1273f4cbf05Sopenharmony_ci    if (!status) {
1283f4cbf05Sopenharmony_ci        return false;
1293f4cbf05Sopenharmony_ci    }
1303f4cbf05Sopenharmony_ci    return true;
1313f4cbf05Sopenharmony_ci}
1323f4cbf05Sopenharmony_ci
1333f4cbf05Sopenharmony_cisptr<RemoteHandleObject> RemoteHandleObject::Unmarshalling(Parcel &parcel)
1343f4cbf05Sopenharmony_ci{
1353f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(sizeof(parcel_flat_binder_object), false);
1363f4cbf05Sopenharmony_ci    if (buffer == nullptr) {
1373f4cbf05Sopenharmony_ci        return nullptr;
1383f4cbf05Sopenharmony_ci    }
1393f4cbf05Sopenharmony_ci    sptr<RemoteHandleObject> obj = new RemoteHandleObject();
1403f4cbf05Sopenharmony_ci    return obj;
1413f4cbf05Sopenharmony_ci}
1423f4cbf05Sopenharmony_ci
1433f4cbf05Sopenharmony_ci/*-------------------------------base data------------------------------------*/
1443f4cbf05Sopenharmony_ci
1453f4cbf05Sopenharmony_cistruct TestData {
1463f4cbf05Sopenharmony_ci    bool booltest;
1473f4cbf05Sopenharmony_ci    int8_t int8test;
1483f4cbf05Sopenharmony_ci    int16_t int16test;
1493f4cbf05Sopenharmony_ci    int32_t int32test;
1503f4cbf05Sopenharmony_ci    uint8_t uint8test;
1513f4cbf05Sopenharmony_ci    uint16_t uint16test;
1523f4cbf05Sopenharmony_ci    uint32_t uint32test;
1533f4cbf05Sopenharmony_ci};
1543f4cbf05Sopenharmony_ci
1553f4cbf05Sopenharmony_civoid WriteTestData(Parcel &parcel, const struct TestData &data)
1563f4cbf05Sopenharmony_ci{
1573f4cbf05Sopenharmony_ci    bool result = false;
1583f4cbf05Sopenharmony_ci
1593f4cbf05Sopenharmony_ci    result = parcel.WriteBool(data.booltest);
1603f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1613f4cbf05Sopenharmony_ci
1623f4cbf05Sopenharmony_ci    result = parcel.WriteInt8(data.int8test);
1633f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1643f4cbf05Sopenharmony_ci
1653f4cbf05Sopenharmony_ci    result = parcel.WriteInt16(data.int16test);
1663f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1673f4cbf05Sopenharmony_ci
1683f4cbf05Sopenharmony_ci    result = parcel.WriteInt32(data.int32test);
1693f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1703f4cbf05Sopenharmony_ci
1713f4cbf05Sopenharmony_ci    result = parcel.WriteUint8(data.uint8test);
1723f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1733f4cbf05Sopenharmony_ci
1743f4cbf05Sopenharmony_ci    result = parcel.WriteUint16(data.uint16test);
1753f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1763f4cbf05Sopenharmony_ci
1773f4cbf05Sopenharmony_ci    result = parcel.WriteUint32(data.uint32test);
1783f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1793f4cbf05Sopenharmony_ci}
1803f4cbf05Sopenharmony_ci
1813f4cbf05Sopenharmony_civoid WriteUnalignedTestData(Parcel &parcel, const struct TestData &data)
1823f4cbf05Sopenharmony_ci{
1833f4cbf05Sopenharmony_ci    bool result = false;
1843f4cbf05Sopenharmony_ci
1853f4cbf05Sopenharmony_ci    result = parcel.WriteBoolUnaligned(data.booltest);
1863f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1873f4cbf05Sopenharmony_ci
1883f4cbf05Sopenharmony_ci    result = parcel.WriteInt8Unaligned(data.int8test);
1893f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1903f4cbf05Sopenharmony_ci
1913f4cbf05Sopenharmony_ci    result = parcel.WriteInt16Unaligned(data.int16test);
1923f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1933f4cbf05Sopenharmony_ci
1943f4cbf05Sopenharmony_ci    result = parcel.WriteUint8Unaligned(data.uint8test);
1953f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1963f4cbf05Sopenharmony_ci
1973f4cbf05Sopenharmony_ci    result = parcel.WriteUint16Unaligned(data.uint16test);
1983f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
1993f4cbf05Sopenharmony_ci}
2003f4cbf05Sopenharmony_ci
2013f4cbf05Sopenharmony_civoid ReadTestData(Parcel &parcel, const struct TestData &data)
2023f4cbf05Sopenharmony_ci{
2033f4cbf05Sopenharmony_ci    bool readbool = parcel.ReadBool();
2043f4cbf05Sopenharmony_ci    EXPECT_EQ(readbool, data.booltest);
2053f4cbf05Sopenharmony_ci
2063f4cbf05Sopenharmony_ci    int8_t readint8 = parcel.ReadInt8();
2073f4cbf05Sopenharmony_ci    EXPECT_EQ(readint8, data.int8test);
2083f4cbf05Sopenharmony_ci
2093f4cbf05Sopenharmony_ci    int16_t readint16 = parcel.ReadInt16();
2103f4cbf05Sopenharmony_ci    EXPECT_EQ(readint16, data.int16test);
2113f4cbf05Sopenharmony_ci
2123f4cbf05Sopenharmony_ci    int32_t readint32 = parcel.ReadInt32();
2133f4cbf05Sopenharmony_ci    EXPECT_EQ(readint32, data.int32test);
2143f4cbf05Sopenharmony_ci
2153f4cbf05Sopenharmony_ci    uint8_t readuint8 = parcel.ReadUint8();
2163f4cbf05Sopenharmony_ci    EXPECT_EQ(readuint8, data.uint8test);
2173f4cbf05Sopenharmony_ci
2183f4cbf05Sopenharmony_ci    uint16_t readuint16 = parcel.ReadUint16();
2193f4cbf05Sopenharmony_ci    EXPECT_EQ(readuint16, data.uint16test);
2203f4cbf05Sopenharmony_ci
2213f4cbf05Sopenharmony_ci    uint32_t readuint32 = parcel.ReadUint32();
2223f4cbf05Sopenharmony_ci    EXPECT_EQ(readuint32, data.uint32test);
2233f4cbf05Sopenharmony_ci}
2243f4cbf05Sopenharmony_ci
2253f4cbf05Sopenharmony_civoid ReadUnalignedTestData(Parcel &parcel, const struct TestData &data)
2263f4cbf05Sopenharmony_ci{
2273f4cbf05Sopenharmony_ci    bool readbool = parcel.ReadBoolUnaligned();
2283f4cbf05Sopenharmony_ci    EXPECT_EQ(readbool, data.booltest);
2293f4cbf05Sopenharmony_ci
2303f4cbf05Sopenharmony_ci    int8_t readint8;
2313f4cbf05Sopenharmony_ci    EXPECT_TRUE(parcel.ReadInt8Unaligned(readint8));
2323f4cbf05Sopenharmony_ci    EXPECT_EQ(readint8, data.int8test);
2333f4cbf05Sopenharmony_ci
2343f4cbf05Sopenharmony_ci    int16_t readint16;
2353f4cbf05Sopenharmony_ci    EXPECT_TRUE(parcel.ReadInt16Unaligned(readint16));
2363f4cbf05Sopenharmony_ci    EXPECT_EQ(readint16, data.int16test);
2373f4cbf05Sopenharmony_ci
2383f4cbf05Sopenharmony_ci    uint8_t readuint8;
2393f4cbf05Sopenharmony_ci    EXPECT_TRUE(parcel.ReadUint8Unaligned(readuint8));
2403f4cbf05Sopenharmony_ci    EXPECT_EQ(readuint8, data.uint8test);
2413f4cbf05Sopenharmony_ci
2423f4cbf05Sopenharmony_ci    uint16_t readuint16;
2433f4cbf05Sopenharmony_ci    EXPECT_TRUE(parcel.ReadUint16Unaligned(readuint16));
2443f4cbf05Sopenharmony_ci    EXPECT_EQ(readuint16, data.uint16test);
2453f4cbf05Sopenharmony_ci}
2463f4cbf05Sopenharmony_ci
2473f4cbf05Sopenharmony_civoid ReadTestDataWithTarget(Parcel &parcel, const struct TestData &data)
2483f4cbf05Sopenharmony_ci{
2493f4cbf05Sopenharmony_ci    bool result = false;
2503f4cbf05Sopenharmony_ci    bool boolVal = true;
2513f4cbf05Sopenharmony_ci    result = parcel.ReadBool(boolVal);
2523f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
2533f4cbf05Sopenharmony_ci    EXPECT_EQ(boolVal, data.booltest);
2543f4cbf05Sopenharmony_ci
2553f4cbf05Sopenharmony_ci    int8_t int8Val;
2563f4cbf05Sopenharmony_ci    result = parcel.ReadInt8(int8Val);
2573f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
2583f4cbf05Sopenharmony_ci    EXPECT_EQ(int8Val, data.int8test);
2593f4cbf05Sopenharmony_ci
2603f4cbf05Sopenharmony_ci    int16_t int16Val;
2613f4cbf05Sopenharmony_ci    result = parcel.ReadInt16(int16Val);
2623f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
2633f4cbf05Sopenharmony_ci    EXPECT_EQ(int16Val, data.int16test);
2643f4cbf05Sopenharmony_ci
2653f4cbf05Sopenharmony_ci    int32_t int32Val;
2663f4cbf05Sopenharmony_ci    result = parcel.ReadInt32(int32Val);
2673f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
2683f4cbf05Sopenharmony_ci    EXPECT_EQ(int32Val, data.int32test);
2693f4cbf05Sopenharmony_ci
2703f4cbf05Sopenharmony_ci    uint8_t uint8Val;
2713f4cbf05Sopenharmony_ci    result = parcel.ReadUint8(uint8Val);
2723f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
2733f4cbf05Sopenharmony_ci    EXPECT_EQ(uint8Val, data.uint8test);
2743f4cbf05Sopenharmony_ci
2753f4cbf05Sopenharmony_ci    uint16_t uint16Val;
2763f4cbf05Sopenharmony_ci    result = parcel.ReadUint16(uint16Val);
2773f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
2783f4cbf05Sopenharmony_ci    EXPECT_EQ(uint16Val, data.uint16test);
2793f4cbf05Sopenharmony_ci
2803f4cbf05Sopenharmony_ci    uint32_t uint32Val;
2813f4cbf05Sopenharmony_ci    result = parcel.ReadUint32(uint32Val);
2823f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
2833f4cbf05Sopenharmony_ci    EXPECT_EQ(uint32Val, data.uint32test);
2843f4cbf05Sopenharmony_ci}
2853f4cbf05Sopenharmony_ci
2863f4cbf05Sopenharmony_ci/**
2873f4cbf05Sopenharmony_ci * Here to simulate the scenario of ipc sending data, the buffer will be released when the Parcel object is destructed.
2883f4cbf05Sopenharmony_ci*/
2893f4cbf05Sopenharmony_cibool SendData(void *&buffer, size_t size, const uint8_t *data)
2903f4cbf05Sopenharmony_ci{
2913f4cbf05Sopenharmony_ci    if (size <= 0) {
2923f4cbf05Sopenharmony_ci        return false;
2933f4cbf05Sopenharmony_ci    }
2943f4cbf05Sopenharmony_ci    buffer = malloc(size);
2953f4cbf05Sopenharmony_ci    if (buffer == nullptr) {
2963f4cbf05Sopenharmony_ci        return false;
2973f4cbf05Sopenharmony_ci    }
2983f4cbf05Sopenharmony_ci    if (memcpy_s(buffer, size, data, size) != EOK) {
2993f4cbf05Sopenharmony_ci        return false;
3003f4cbf05Sopenharmony_ci    }
3013f4cbf05Sopenharmony_ci    return true;
3023f4cbf05Sopenharmony_ci}
3033f4cbf05Sopenharmony_ci
3043f4cbf05Sopenharmony_ci/**
3053f4cbf05Sopenharmony_ci * @tc.name: test_parcel_001
3063f4cbf05Sopenharmony_ci * @tc.desc: test parcel CheckOffsets, WriteRemoteObject, RewindRead and
3073f4cbf05Sopenharmony_ci * RewindWrite failed.
3083f4cbf05Sopenharmony_ci * @tc.type: FUNC
3093f4cbf05Sopenharmony_ci */
3103f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_001, TestSize.Level0)
3113f4cbf05Sopenharmony_ci{
3123f4cbf05Sopenharmony_ci    Parcel parcel;
3133f4cbf05Sopenharmony_ci    bool result = parcel.CheckOffsets();
3143f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3153f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(nullptr);
3163f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3173f4cbf05Sopenharmony_ci    result = parcel.RewindRead(parcel.GetDataSize() + 1);
3183f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3193f4cbf05Sopenharmony_ci    result = parcel.RewindWrite(parcel.GetDataSize() + 1);
3203f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3213f4cbf05Sopenharmony_ci}
3223f4cbf05Sopenharmony_ci
3233f4cbf05Sopenharmony_ci/**
3243f4cbf05Sopenharmony_ci * @tc.name: test_parcel_readvec_001
3253f4cbf05Sopenharmony_ci * @tc.desc: test parcel read vector failed with invlalid input.
3263f4cbf05Sopenharmony_ci * @tc.type: FUNC
3273f4cbf05Sopenharmony_ci */
3283f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_readvec_001, TestSize.Level0)
3293f4cbf05Sopenharmony_ci{
3303f4cbf05Sopenharmony_ci    Parcel parcel;
3313f4cbf05Sopenharmony_ci
3323f4cbf05Sopenharmony_ci    bool result = parcel.ReadBoolVector(nullptr);
3333f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3343f4cbf05Sopenharmony_ci
3353f4cbf05Sopenharmony_ci    result = parcel.ReadInt8Vector(nullptr);
3363f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3373f4cbf05Sopenharmony_ci
3383f4cbf05Sopenharmony_ci    result = parcel.ReadInt16Vector(nullptr);
3393f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3403f4cbf05Sopenharmony_ci
3413f4cbf05Sopenharmony_ci    result = parcel.ReadInt32Vector(nullptr);
3423f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3433f4cbf05Sopenharmony_ci
3443f4cbf05Sopenharmony_ci    result = parcel.ReadInt64Vector(nullptr);
3453f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3463f4cbf05Sopenharmony_ci
3473f4cbf05Sopenharmony_ci    result = parcel.ReadUInt8Vector(nullptr);
3483f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3493f4cbf05Sopenharmony_ci
3503f4cbf05Sopenharmony_ci    result = parcel.ReadUInt16Vector(nullptr);
3513f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3523f4cbf05Sopenharmony_ci
3533f4cbf05Sopenharmony_ci    result = parcel.ReadUInt32Vector(nullptr);
3543f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3553f4cbf05Sopenharmony_ci
3563f4cbf05Sopenharmony_ci    result = parcel.ReadUInt64Vector(nullptr);
3573f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3583f4cbf05Sopenharmony_ci
3593f4cbf05Sopenharmony_ci    result = parcel.ReadFloatVector(nullptr);
3603f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3613f4cbf05Sopenharmony_ci
3623f4cbf05Sopenharmony_ci    result = parcel.ReadDoubleVector(nullptr);
3633f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3643f4cbf05Sopenharmony_ci
3653f4cbf05Sopenharmony_ci    result = parcel.ReadStringVector(nullptr);
3663f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3673f4cbf05Sopenharmony_ci
3683f4cbf05Sopenharmony_ci    result = parcel.ReadString16Vector(nullptr);
3693f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3703f4cbf05Sopenharmony_ci}
3713f4cbf05Sopenharmony_ci
3723f4cbf05Sopenharmony_cistatic void ReadvecTestTwoFunc01()
3733f4cbf05Sopenharmony_ci{
3743f4cbf05Sopenharmony_ci    Parcel parcel1;
3753f4cbf05Sopenharmony_ci    parcel1.WriteInt32(-1);
3763f4cbf05Sopenharmony_ci    std::vector<bool> val1;
3773f4cbf05Sopenharmony_ci    bool x1 = true;
3783f4cbf05Sopenharmony_ci    val1.push_back(x1);
3793f4cbf05Sopenharmony_ci    bool result = parcel1.ReadBoolVector(&val1);
3803f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3813f4cbf05Sopenharmony_ci
3823f4cbf05Sopenharmony_ci    Parcel parcel2;
3833f4cbf05Sopenharmony_ci    parcel2.WriteInt32(-1);
3843f4cbf05Sopenharmony_ci    std::vector<int8_t> val2;
3853f4cbf05Sopenharmony_ci    int8_t x2 = 1;
3863f4cbf05Sopenharmony_ci    val2.push_back(x2);
3873f4cbf05Sopenharmony_ci    result = parcel2.ReadInt8Vector(&val2);
3883f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3893f4cbf05Sopenharmony_ci
3903f4cbf05Sopenharmony_ci    Parcel parcel3;
3913f4cbf05Sopenharmony_ci    parcel3.WriteInt32(-1);
3923f4cbf05Sopenharmony_ci    std::vector<int16_t> val3;
3933f4cbf05Sopenharmony_ci    int16_t x3 = 1;
3943f4cbf05Sopenharmony_ci    val3.push_back(x3);
3953f4cbf05Sopenharmony_ci    result = parcel3.ReadInt16Vector(&val3);
3963f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
3973f4cbf05Sopenharmony_ci
3983f4cbf05Sopenharmony_ci    Parcel parcel4;
3993f4cbf05Sopenharmony_ci    parcel4.WriteInt32(-1);
4003f4cbf05Sopenharmony_ci    std::vector<int32_t> val4;
4013f4cbf05Sopenharmony_ci    int32_t x4 = 1;
4023f4cbf05Sopenharmony_ci    val4.push_back(x4);
4033f4cbf05Sopenharmony_ci    result = parcel4.ReadInt32Vector(&val4);
4043f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4053f4cbf05Sopenharmony_ci}
4063f4cbf05Sopenharmony_ci
4073f4cbf05Sopenharmony_cistatic void ReadvecTestTwoFunc02()
4083f4cbf05Sopenharmony_ci{
4093f4cbf05Sopenharmony_ci    Parcel parcel1;
4103f4cbf05Sopenharmony_ci    parcel1.WriteInt32(-1);
4113f4cbf05Sopenharmony_ci    std::vector<int64_t> val1;
4123f4cbf05Sopenharmony_ci    int64_t x1 = 1;
4133f4cbf05Sopenharmony_ci    val1.push_back(x1);
4143f4cbf05Sopenharmony_ci    bool result = parcel1.ReadInt64Vector(&val1);
4153f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4163f4cbf05Sopenharmony_ci
4173f4cbf05Sopenharmony_ci    Parcel parcel2;
4183f4cbf05Sopenharmony_ci    parcel2.WriteInt32(-1);
4193f4cbf05Sopenharmony_ci    std::vector<uint8_t> val2;
4203f4cbf05Sopenharmony_ci    uint8_t x2 = 1;
4213f4cbf05Sopenharmony_ci    val2.push_back(x2);
4223f4cbf05Sopenharmony_ci    result = parcel2.ReadUInt8Vector(&val2);
4233f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4243f4cbf05Sopenharmony_ci
4253f4cbf05Sopenharmony_ci    Parcel parcel3;
4263f4cbf05Sopenharmony_ci    parcel3.WriteInt32(-1);
4273f4cbf05Sopenharmony_ci    std::vector<uint16_t> val3;
4283f4cbf05Sopenharmony_ci    uint16_t x3 = 1;
4293f4cbf05Sopenharmony_ci    val3.push_back(x3);
4303f4cbf05Sopenharmony_ci    result = parcel3.ReadUInt16Vector(&val3);
4313f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4323f4cbf05Sopenharmony_ci
4333f4cbf05Sopenharmony_ci    Parcel parcel4;
4343f4cbf05Sopenharmony_ci    parcel4.WriteInt32(-1);
4353f4cbf05Sopenharmony_ci    std::vector<uint32_t> val4;
4363f4cbf05Sopenharmony_ci    uint32_t x4 = 1;
4373f4cbf05Sopenharmony_ci    val4.push_back(x4);
4383f4cbf05Sopenharmony_ci    result = parcel4.ReadUInt32Vector(&val4);
4393f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4403f4cbf05Sopenharmony_ci}
4413f4cbf05Sopenharmony_ci
4423f4cbf05Sopenharmony_cistatic void ReadvecTestTwoFunc03()
4433f4cbf05Sopenharmony_ci{
4443f4cbf05Sopenharmony_ci    Parcel parcel1;
4453f4cbf05Sopenharmony_ci    parcel1.WriteInt32(-1);
4463f4cbf05Sopenharmony_ci    std::vector<uint64_t> val1;
4473f4cbf05Sopenharmony_ci    uint64_t x1 = 1;
4483f4cbf05Sopenharmony_ci    val1.push_back(x1);
4493f4cbf05Sopenharmony_ci    bool result = parcel1.ReadUInt64Vector(&val1);
4503f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4513f4cbf05Sopenharmony_ci
4523f4cbf05Sopenharmony_ci    Parcel parcel2;
4533f4cbf05Sopenharmony_ci    parcel2.WriteInt32(-1);
4543f4cbf05Sopenharmony_ci    std::vector<float> val2;
4553f4cbf05Sopenharmony_ci    float x2 = 1;
4563f4cbf05Sopenharmony_ci    val2.push_back(x2);
4573f4cbf05Sopenharmony_ci    result = parcel2.ReadFloatVector(&val2);
4583f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4593f4cbf05Sopenharmony_ci
4603f4cbf05Sopenharmony_ci    Parcel parcel3;
4613f4cbf05Sopenharmony_ci    parcel3.WriteInt32(-1);
4623f4cbf05Sopenharmony_ci    std::vector<double> val3;
4633f4cbf05Sopenharmony_ci    double x3 = 1;
4643f4cbf05Sopenharmony_ci    val3.push_back(x3);
4653f4cbf05Sopenharmony_ci    result = parcel3.ReadDoubleVector(&val3);
4663f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4673f4cbf05Sopenharmony_ci
4683f4cbf05Sopenharmony_ci    Parcel parcel4;
4693f4cbf05Sopenharmony_ci    parcel4.WriteInt32(-1);
4703f4cbf05Sopenharmony_ci    std::vector<std::string> val4;
4713f4cbf05Sopenharmony_ci    std::string x4 = "test";
4723f4cbf05Sopenharmony_ci    val4.push_back(x4);
4733f4cbf05Sopenharmony_ci    result = parcel4.ReadStringVector(&val4);
4743f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4753f4cbf05Sopenharmony_ci
4763f4cbf05Sopenharmony_ci    Parcel parcel5;
4773f4cbf05Sopenharmony_ci    parcel5.WriteInt32(-1);
4783f4cbf05Sopenharmony_ci    std::vector<std::u16string> val5;
4793f4cbf05Sopenharmony_ci    std::u16string x5 = u"test";
4803f4cbf05Sopenharmony_ci    val5.push_back(x5);
4813f4cbf05Sopenharmony_ci    result = parcel5.ReadString16Vector(&val5);
4823f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
4833f4cbf05Sopenharmony_ci}
4843f4cbf05Sopenharmony_ci
4853f4cbf05Sopenharmony_ci/**
4863f4cbf05Sopenharmony_ci * @tc.name: test_parcel_readvec_002
4873f4cbf05Sopenharmony_ci * @tc.desc: test parcel read vector failed with invlalid vector length -1.
4883f4cbf05Sopenharmony_ci * @tc.type: FUNC
4893f4cbf05Sopenharmony_ci */
4903f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_readvec_002, TestSize.Level0)
4913f4cbf05Sopenharmony_ci{
4923f4cbf05Sopenharmony_ci    ReadvecTestTwoFunc01();
4933f4cbf05Sopenharmony_ci    ReadvecTestTwoFunc02();
4943f4cbf05Sopenharmony_ci    ReadvecTestTwoFunc03();
4953f4cbf05Sopenharmony_ci}
4963f4cbf05Sopenharmony_ci
4973f4cbf05Sopenharmony_cistatic void ReadvecTestThreeFunc01()
4983f4cbf05Sopenharmony_ci{
4993f4cbf05Sopenharmony_ci    Parcel parcel1;
5003f4cbf05Sopenharmony_ci    std::vector<bool> val1;
5013f4cbf05Sopenharmony_ci    bool x1 = true;
5023f4cbf05Sopenharmony_ci    val1.push_back(x1);
5033f4cbf05Sopenharmony_ci    parcel1.WriteInt32(val1.max_size());
5043f4cbf05Sopenharmony_ci    bool result = parcel1.ReadBoolVector(&val1);
5053f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5063f4cbf05Sopenharmony_ci
5073f4cbf05Sopenharmony_ci    Parcel parcel2;
5083f4cbf05Sopenharmony_ci    std::vector<int8_t> val2;
5093f4cbf05Sopenharmony_ci    int8_t x2 = 1;
5103f4cbf05Sopenharmony_ci    val2.push_back(x2);
5113f4cbf05Sopenharmony_ci    parcel2.WriteInt32(val2.max_size());
5123f4cbf05Sopenharmony_ci    result = parcel2.ReadInt8Vector(&val2);
5133f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5143f4cbf05Sopenharmony_ci
5153f4cbf05Sopenharmony_ci    Parcel parcel3;
5163f4cbf05Sopenharmony_ci    std::vector<int16_t> val3;
5173f4cbf05Sopenharmony_ci    int16_t x3 = 1;
5183f4cbf05Sopenharmony_ci    val3.push_back(x3);
5193f4cbf05Sopenharmony_ci    parcel3.WriteInt32(val3.max_size());
5203f4cbf05Sopenharmony_ci    result = parcel3.ReadInt16Vector(&val3);
5213f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5223f4cbf05Sopenharmony_ci
5233f4cbf05Sopenharmony_ci    Parcel parcel4;
5243f4cbf05Sopenharmony_ci    std::vector<int32_t> val4;
5253f4cbf05Sopenharmony_ci    int32_t x4 = 1;
5263f4cbf05Sopenharmony_ci    val4.push_back(x4);
5273f4cbf05Sopenharmony_ci    parcel4.WriteInt32(val4.max_size());
5283f4cbf05Sopenharmony_ci    result = parcel4.ReadInt32Vector(&val4);
5293f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5303f4cbf05Sopenharmony_ci}
5313f4cbf05Sopenharmony_ci
5323f4cbf05Sopenharmony_cistatic void ReadvecTestThreeFunc02()
5333f4cbf05Sopenharmony_ci{
5343f4cbf05Sopenharmony_ci    Parcel parcel1;
5353f4cbf05Sopenharmony_ci    std::vector<int64_t> val1;
5363f4cbf05Sopenharmony_ci    int64_t x1 = 1;
5373f4cbf05Sopenharmony_ci    val1.push_back(x1);
5383f4cbf05Sopenharmony_ci    parcel1.WriteInt32(val1.max_size());
5393f4cbf05Sopenharmony_ci    bool result = parcel1.ReadInt64Vector(&val1);
5403f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5413f4cbf05Sopenharmony_ci
5423f4cbf05Sopenharmony_ci    Parcel parcel2;
5433f4cbf05Sopenharmony_ci    std::vector<uint8_t> val2;
5443f4cbf05Sopenharmony_ci    uint8_t x2 = 1;
5453f4cbf05Sopenharmony_ci    val2.push_back(x2);
5463f4cbf05Sopenharmony_ci    parcel2.WriteInt32(val2.max_size());
5473f4cbf05Sopenharmony_ci    result = parcel2.ReadUInt8Vector(&val2);
5483f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5493f4cbf05Sopenharmony_ci
5503f4cbf05Sopenharmony_ci    Parcel parcel3;
5513f4cbf05Sopenharmony_ci    std::vector<uint16_t> val3;
5523f4cbf05Sopenharmony_ci    uint16_t x3 = 1;
5533f4cbf05Sopenharmony_ci    val3.push_back(x3);
5543f4cbf05Sopenharmony_ci    parcel3.WriteInt32(val3.max_size());
5553f4cbf05Sopenharmony_ci    result = parcel3.ReadUInt16Vector(&val3);
5563f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5573f4cbf05Sopenharmony_ci
5583f4cbf05Sopenharmony_ci    Parcel parcel4;
5593f4cbf05Sopenharmony_ci    std::vector<uint32_t> val4;
5603f4cbf05Sopenharmony_ci    uint32_t x4 = 1;
5613f4cbf05Sopenharmony_ci    val4.push_back(x4);
5623f4cbf05Sopenharmony_ci    parcel4.WriteInt32(val4.max_size());
5633f4cbf05Sopenharmony_ci    result = parcel4.ReadUInt32Vector(&val4);
5643f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5653f4cbf05Sopenharmony_ci}
5663f4cbf05Sopenharmony_ci
5673f4cbf05Sopenharmony_cistatic void ReadvecTestThreeFunc03()
5683f4cbf05Sopenharmony_ci{
5693f4cbf05Sopenharmony_ci    Parcel parcel1;
5703f4cbf05Sopenharmony_ci    std::vector<uint64_t> val1;
5713f4cbf05Sopenharmony_ci    uint64_t x1 = 1;
5723f4cbf05Sopenharmony_ci    val1.push_back(x1);
5733f4cbf05Sopenharmony_ci    parcel1.WriteInt32(val1.max_size());
5743f4cbf05Sopenharmony_ci    bool result = parcel1.ReadUInt64Vector(&val1);
5753f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5763f4cbf05Sopenharmony_ci
5773f4cbf05Sopenharmony_ci    Parcel parcel2;
5783f4cbf05Sopenharmony_ci    std::vector<float> val2;
5793f4cbf05Sopenharmony_ci    float x2 = 1;
5803f4cbf05Sopenharmony_ci    val2.push_back(x2);
5813f4cbf05Sopenharmony_ci    parcel2.WriteInt32(val2.max_size());
5823f4cbf05Sopenharmony_ci    result = parcel2.ReadFloatVector(&val2);
5833f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5843f4cbf05Sopenharmony_ci
5853f4cbf05Sopenharmony_ci    Parcel parcel3;
5863f4cbf05Sopenharmony_ci    std::vector<double> val3;
5873f4cbf05Sopenharmony_ci    double x3 = 1;
5883f4cbf05Sopenharmony_ci    val3.push_back(x3);
5893f4cbf05Sopenharmony_ci    parcel3.WriteInt32(val3.max_size());
5903f4cbf05Sopenharmony_ci    result = parcel3.ReadDoubleVector(&val3);
5913f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
5923f4cbf05Sopenharmony_ci
5933f4cbf05Sopenharmony_ci    Parcel parcel4;
5943f4cbf05Sopenharmony_ci    std::vector<std::string> val4;
5953f4cbf05Sopenharmony_ci    std::string x4 = "test";
5963f4cbf05Sopenharmony_ci    val4.push_back(x4);
5973f4cbf05Sopenharmony_ci    parcel4.WriteInt32(val4.max_size());
5983f4cbf05Sopenharmony_ci    result = parcel4.ReadStringVector(&val4);
5993f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6003f4cbf05Sopenharmony_ci
6013f4cbf05Sopenharmony_ci    Parcel parcel5;
6023f4cbf05Sopenharmony_ci    std::vector<std::u16string> val5;
6033f4cbf05Sopenharmony_ci    std::u16string x5 = u"test";
6043f4cbf05Sopenharmony_ci    val5.push_back(x5);
6053f4cbf05Sopenharmony_ci    parcel5.WriteInt32(val5.max_size());
6063f4cbf05Sopenharmony_ci    result = parcel5.ReadString16Vector(&val5);
6073f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6083f4cbf05Sopenharmony_ci}
6093f4cbf05Sopenharmony_ci
6103f4cbf05Sopenharmony_ci/**
6113f4cbf05Sopenharmony_ci * @tc.name: test_parcel_readvec_003
6123f4cbf05Sopenharmony_ci * @tc.desc: test parcel read vector failed with invlalid vector length
6133f4cbf05Sopenharmony_ci * std::vector::max_size().
6143f4cbf05Sopenharmony_ci * @tc.type: FUNC
6153f4cbf05Sopenharmony_ci */
6163f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_readvec_003, TestSize.Level0)
6173f4cbf05Sopenharmony_ci{
6183f4cbf05Sopenharmony_ci    ReadvecTestThreeFunc01();
6193f4cbf05Sopenharmony_ci    ReadvecTestThreeFunc02();
6203f4cbf05Sopenharmony_ci    ReadvecTestThreeFunc03();
6213f4cbf05Sopenharmony_ci}
6223f4cbf05Sopenharmony_ci
6233f4cbf05Sopenharmony_cistatic void WritevecTestOneFunc01(const size_t cap)
6243f4cbf05Sopenharmony_ci{
6253f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
6263f4cbf05Sopenharmony_ci    std::vector<bool> val1;
6273f4cbf05Sopenharmony_ci    bool x1 = true;
6283f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(bool); i++) {
6293f4cbf05Sopenharmony_ci        val1.push_back(x1);
6303f4cbf05Sopenharmony_ci    }
6313f4cbf05Sopenharmony_ci    bool result = parcel.WriteBoolVector(val1);
6323f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6333f4cbf05Sopenharmony_ci
6343f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
6353f4cbf05Sopenharmony_ci    std::vector<int8_t> val2;
6363f4cbf05Sopenharmony_ci    int8_t x2 = 1;
6373f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(int8_t); i++) {
6383f4cbf05Sopenharmony_ci        val2.push_back(x2);
6393f4cbf05Sopenharmony_ci    }
6403f4cbf05Sopenharmony_ci    result = parcel.WriteInt8Vector(val2);
6413f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6423f4cbf05Sopenharmony_ci
6433f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
6443f4cbf05Sopenharmony_ci    std::vector<int16_t> val3;
6453f4cbf05Sopenharmony_ci    int16_t x3 = 1;
6463f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(int16_t); i++) {
6473f4cbf05Sopenharmony_ci        val3.push_back(x3);
6483f4cbf05Sopenharmony_ci    }
6493f4cbf05Sopenharmony_ci    result = parcel.WriteInt16Vector(val3);
6503f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6513f4cbf05Sopenharmony_ci
6523f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
6533f4cbf05Sopenharmony_ci    std::vector<int32_t> val4;
6543f4cbf05Sopenharmony_ci    int32_t x4 = 1;
6553f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(int32_t); i++) {
6563f4cbf05Sopenharmony_ci        val4.push_back(x4);
6573f4cbf05Sopenharmony_ci    }
6583f4cbf05Sopenharmony_ci    result = parcel.WriteInt32Vector(val4);
6593f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6603f4cbf05Sopenharmony_ci}
6613f4cbf05Sopenharmony_ci
6623f4cbf05Sopenharmony_cistatic void WritevecTestOneFunc02(const size_t cap)
6633f4cbf05Sopenharmony_ci{
6643f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
6653f4cbf05Sopenharmony_ci    std::vector<int64_t> val1;
6663f4cbf05Sopenharmony_ci    int64_t x1 = 1;
6673f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(int64_t); i++) {
6683f4cbf05Sopenharmony_ci        val1.push_back(x1);
6693f4cbf05Sopenharmony_ci    }
6703f4cbf05Sopenharmony_ci    bool result = parcel.WriteInt64Vector(val1);
6713f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6723f4cbf05Sopenharmony_ci
6733f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
6743f4cbf05Sopenharmony_ci    std::vector<uint8_t> val2;
6753f4cbf05Sopenharmony_ci    uint8_t x2 = 1;
6763f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(uint8_t); i++) {
6773f4cbf05Sopenharmony_ci        val2.push_back(x2);
6783f4cbf05Sopenharmony_ci    }
6793f4cbf05Sopenharmony_ci    result = parcel.WriteUInt8Vector(val2);
6803f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6813f4cbf05Sopenharmony_ci
6823f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
6833f4cbf05Sopenharmony_ci    std::vector<uint16_t> val3;
6843f4cbf05Sopenharmony_ci    uint16_t x3 = 1;
6853f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(uint16_t); i++) {
6863f4cbf05Sopenharmony_ci        val3.push_back(x3);
6873f4cbf05Sopenharmony_ci    }
6883f4cbf05Sopenharmony_ci    result = parcel.WriteUInt16Vector(val3);
6893f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6903f4cbf05Sopenharmony_ci
6913f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
6923f4cbf05Sopenharmony_ci    std::vector<uint32_t> val4;
6933f4cbf05Sopenharmony_ci    uint32_t x4 = 1;
6943f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(uint32_t); i++) {
6953f4cbf05Sopenharmony_ci        val4.push_back(x4);
6963f4cbf05Sopenharmony_ci    }
6973f4cbf05Sopenharmony_ci    result = parcel.WriteUInt32Vector(val4);
6983f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
6993f4cbf05Sopenharmony_ci}
7003f4cbf05Sopenharmony_ci
7013f4cbf05Sopenharmony_cistatic void WritevecTestOneFunc03(const size_t cap)
7023f4cbf05Sopenharmony_ci{
7033f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
7043f4cbf05Sopenharmony_ci    std::vector<uint64_t> val1;
7053f4cbf05Sopenharmony_ci    uint64_t x1 = 1;
7063f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(uint64_t); i++) {
7073f4cbf05Sopenharmony_ci        val1.push_back(x1);
7083f4cbf05Sopenharmony_ci    }
7093f4cbf05Sopenharmony_ci    bool result = parcel.WriteUInt64Vector(val1);
7103f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
7113f4cbf05Sopenharmony_ci
7123f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
7133f4cbf05Sopenharmony_ci    std::vector<float> val2;
7143f4cbf05Sopenharmony_ci    float x2 = 1;
7153f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(float); i++) {
7163f4cbf05Sopenharmony_ci        val2.push_back(x2);
7173f4cbf05Sopenharmony_ci    }
7183f4cbf05Sopenharmony_ci    result = parcel.WriteFloatVector(val2);
7193f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
7203f4cbf05Sopenharmony_ci
7213f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
7223f4cbf05Sopenharmony_ci    std::vector<double> val3;
7233f4cbf05Sopenharmony_ci    double x3 = 1;
7243f4cbf05Sopenharmony_ci    for (int i = 0; i < cap / sizeof(double); i++) {
7253f4cbf05Sopenharmony_ci        val3.push_back(x3);
7263f4cbf05Sopenharmony_ci    }
7273f4cbf05Sopenharmony_ci    result = parcel.WriteDoubleVector(val3);
7283f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
7293f4cbf05Sopenharmony_ci
7303f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
7313f4cbf05Sopenharmony_ci    std::vector<std::string> val4;
7323f4cbf05Sopenharmony_ci    std::string x4((cap / sizeof(char)), 't');
7333f4cbf05Sopenharmony_ci    val4.push_back(x4);
7343f4cbf05Sopenharmony_ci    result = parcel.WriteStringVector(val4);
7353f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
7363f4cbf05Sopenharmony_ci
7373f4cbf05Sopenharmony_ci    parcel.FlushBuffer();
7383f4cbf05Sopenharmony_ci    std::vector<std::u16string> val5;
7393f4cbf05Sopenharmony_ci    std::u16string x5((cap / sizeof(char16_t)), u't');
7403f4cbf05Sopenharmony_ci    val5.push_back(x5);
7413f4cbf05Sopenharmony_ci    result = parcel.WriteString16Vector(val5);
7423f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
7433f4cbf05Sopenharmony_ci}
7443f4cbf05Sopenharmony_ci
7453f4cbf05Sopenharmony_ci/**
7463f4cbf05Sopenharmony_ci * @tc.name: test_parcel_writevec_001
7473f4cbf05Sopenharmony_ci * @tc.desc: test parcel write vector failed with writting data out of the
7483f4cbf05Sopenharmony_ci * maximum capacity.
7493f4cbf05Sopenharmony_ci * @tc.type: FUNC
7503f4cbf05Sopenharmony_ci */
7513f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0)
7523f4cbf05Sopenharmony_ci{
7533f4cbf05Sopenharmony_ci    size_t cap = DEFAULT_CPACITY;
7543f4cbf05Sopenharmony_ci
7553f4cbf05Sopenharmony_ci    WritevecTestOneFunc01(cap);
7563f4cbf05Sopenharmony_ci    WritevecTestOneFunc02(cap);
7573f4cbf05Sopenharmony_ci    WritevecTestOneFunc03(cap);
7583f4cbf05Sopenharmony_ci}
7593f4cbf05Sopenharmony_ci
7603f4cbf05Sopenharmony_ci/**
7613f4cbf05Sopenharmony_ci * @tc.name: test_parcel_SetMaxCapacity_001
7623f4cbf05Sopenharmony_ci * @tc.desc: test parcel primary type read write.
7633f4cbf05Sopenharmony_ci * @tc.type: FUNC
7643f4cbf05Sopenharmony_ci */
7653f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_SetMaxCapacity_001, TestSize.Level0)
7663f4cbf05Sopenharmony_ci{
7673f4cbf05Sopenharmony_ci    size_t cap = DEFAULT_CPACITY;
7683f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
7693f4cbf05Sopenharmony_ci    EXPECT_TRUE(parcel.SetMaxCapacity(cap + 1));
7703f4cbf05Sopenharmony_ci    EXPECT_FALSE(parcel.SetMaxCapacity(cap - 1));
7713f4cbf05Sopenharmony_ci}
7723f4cbf05Sopenharmony_ci
7733f4cbf05Sopenharmony_ci/**
7743f4cbf05Sopenharmony_ci * @tc.name: test_parcel_SetAllocator_001
7753f4cbf05Sopenharmony_ci * @tc.desc: test setting allocator to parcels with and without existed allocator.
7763f4cbf05Sopenharmony_ci * @tc.type: FUNC
7773f4cbf05Sopenharmony_ci */
7783f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_SetAllocator_001, TestSize.Level0)
7793f4cbf05Sopenharmony_ci{
7803f4cbf05Sopenharmony_ci    Allocator* alloc = new DefaultAllocator();
7813f4cbf05Sopenharmony_ci    Parcel parcel(alloc);
7823f4cbf05Sopenharmony_ci    EXPECT_FALSE(parcel.SetAllocator(alloc));
7833f4cbf05Sopenharmony_ci    EXPECT_FALSE(parcel.SetAllocator(nullptr));
7843f4cbf05Sopenharmony_ci
7853f4cbf05Sopenharmony_ci    struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 };
7863f4cbf05Sopenharmony_ci
7873f4cbf05Sopenharmony_ci    WriteTestData(parcel, data);
7883f4cbf05Sopenharmony_ci    parcel.SetAllocator(new DefaultAllocator());
7893f4cbf05Sopenharmony_ci    ReadTestData(parcel, data);
7903f4cbf05Sopenharmony_ci}
7913f4cbf05Sopenharmony_ci
7923f4cbf05Sopenharmony_ci/**
7933f4cbf05Sopenharmony_ci * @tc.name: test_parcel_write_001
7943f4cbf05Sopenharmony_ci * @tc.desc: test parcel write failed.
7953f4cbf05Sopenharmony_ci * @tc.type: FUNC
7963f4cbf05Sopenharmony_ci */
7973f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_write_001, TestSize.Level0)
7983f4cbf05Sopenharmony_ci{
7993f4cbf05Sopenharmony_ci    Parcel parcel1;
8003f4cbf05Sopenharmony_ci    parcel1.WriteBool(true);
8013f4cbf05Sopenharmony_ci    Parcel parcel2;
8023f4cbf05Sopenharmony_ci    void *buffer = nullptr;
8033f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
8043f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
8053f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
8063f4cbf05Sopenharmony_ci    }
8073f4cbf05Sopenharmony_ci    parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
8083f4cbf05Sopenharmony_ci
8093f4cbf05Sopenharmony_ci    string str8write;
8103f4cbf05Sopenharmony_ci    bool result = parcel2.WriteString(str8write);
8113f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8123f4cbf05Sopenharmony_ci
8133f4cbf05Sopenharmony_ci    u16string str16Write;
8143f4cbf05Sopenharmony_ci    result = parcel2.WriteString16(str16Write);
8153f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8163f4cbf05Sopenharmony_ci
8173f4cbf05Sopenharmony_ci    result = parcel2.WriteBool(false);
8183f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8193f4cbf05Sopenharmony_ci
8203f4cbf05Sopenharmony_ci    result = parcel2.WriteBoolUnaligned(false);
8213f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8223f4cbf05Sopenharmony_ci
8233f4cbf05Sopenharmony_ci    result = parcel2.WriteInt8(false);
8243f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8253f4cbf05Sopenharmony_ci
8263f4cbf05Sopenharmony_ci    result = parcel2.WriteInt8Unaligned(false);
8273f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8283f4cbf05Sopenharmony_ci
8293f4cbf05Sopenharmony_ci    result = parcel2.WriteInt32(false);
8303f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8313f4cbf05Sopenharmony_ci
8323f4cbf05Sopenharmony_ci    result = parcel2.WriteInt64(false);
8333f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8343f4cbf05Sopenharmony_ci
8353f4cbf05Sopenharmony_ci    result = parcel2.WriteUint8(false);
8363f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8373f4cbf05Sopenharmony_ci
8383f4cbf05Sopenharmony_ci    result = parcel2.WriteUint16(false);
8393f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8403f4cbf05Sopenharmony_ci
8413f4cbf05Sopenharmony_ci    result = parcel2.WriteUint8Unaligned(false);
8423f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8433f4cbf05Sopenharmony_ci
8443f4cbf05Sopenharmony_ci    result = parcel2.WriteUint16Unaligned(false);
8453f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8463f4cbf05Sopenharmony_ci
8473f4cbf05Sopenharmony_ci    result = parcel2.WriteUint32(false);
8483f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8493f4cbf05Sopenharmony_ci
8503f4cbf05Sopenharmony_ci    result = parcel2.WriteUint64(false);
8513f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8523f4cbf05Sopenharmony_ci
8533f4cbf05Sopenharmony_ci    result = parcel2.WriteFloat(false);
8543f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8553f4cbf05Sopenharmony_ci
8563f4cbf05Sopenharmony_ci    result = parcel2.WriteDouble(false);
8573f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8583f4cbf05Sopenharmony_ci
8593f4cbf05Sopenharmony_ci    result = parcel2.WritePointer(false);
8603f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
8613f4cbf05Sopenharmony_ci}
8623f4cbf05Sopenharmony_ci
8633f4cbf05Sopenharmony_ci/**
8643f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_001
8653f4cbf05Sopenharmony_ci * @tc.desc: test parcel primary type read write.
8663f4cbf05Sopenharmony_ci * @tc.type: FUNC
8673f4cbf05Sopenharmony_ci */
8683f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_001, TestSize.Level0)
8693f4cbf05Sopenharmony_ci{
8703f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
8713f4cbf05Sopenharmony_ci    struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 };
8723f4cbf05Sopenharmony_ci    WriteTestData(parcel, data);
8733f4cbf05Sopenharmony_ci    ReadTestData(parcel, data);
8743f4cbf05Sopenharmony_ci
8753f4cbf05Sopenharmony_ci    WriteUnalignedTestData(parcel, data);
8763f4cbf05Sopenharmony_ci    ReadUnalignedTestData(parcel, data);
8773f4cbf05Sopenharmony_ci}
8783f4cbf05Sopenharmony_ci
8793f4cbf05Sopenharmony_ci/**
8803f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_002
8813f4cbf05Sopenharmony_ci * @tc.desc: test parcel primary type read write.
8823f4cbf05Sopenharmony_ci * @tc.type: FUNC
8833f4cbf05Sopenharmony_ci */
8843f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_002, TestSize.Level0)
8853f4cbf05Sopenharmony_ci{
8863f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
8873f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
8883f4cbf05Sopenharmony_ci    struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 };
8893f4cbf05Sopenharmony_ci    WriteTestData(parcel1, data);
8903f4cbf05Sopenharmony_ci    WriteUnalignedTestData(parcel1, data);
8913f4cbf05Sopenharmony_ci
8923f4cbf05Sopenharmony_ci    void *buffer = nullptr;
8933f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
8943f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
8953f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
8963f4cbf05Sopenharmony_ci    }
8973f4cbf05Sopenharmony_ci
8983f4cbf05Sopenharmony_ci    bool result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
8993f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
9003f4cbf05Sopenharmony_ci
9013f4cbf05Sopenharmony_ci    ReadTestData(parcel2, data);
9023f4cbf05Sopenharmony_ci    ReadUnalignedTestData(parcel2, data);
9033f4cbf05Sopenharmony_ci}
9043f4cbf05Sopenharmony_ci
9053f4cbf05Sopenharmony_ci/**
9063f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_003
9073f4cbf05Sopenharmony_ci * @tc.desc: test parcel primary type read write.
9083f4cbf05Sopenharmony_ci * @tc.type: FUNC
9093f4cbf05Sopenharmony_ci */
9103f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_003, TestSize.Level0)
9113f4cbf05Sopenharmony_ci{
9123f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
9133f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
9143f4cbf05Sopenharmony_ci    struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 };
9153f4cbf05Sopenharmony_ci    WriteTestData(parcel1, data);
9163f4cbf05Sopenharmony_ci
9173f4cbf05Sopenharmony_ci    void *buffer = nullptr;
9183f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
9193f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
9203f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
9213f4cbf05Sopenharmony_ci    }
9223f4cbf05Sopenharmony_ci
9233f4cbf05Sopenharmony_ci    bool result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
9243f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
9253f4cbf05Sopenharmony_ci
9263f4cbf05Sopenharmony_ci    ReadTestDataWithTarget(parcel2, data);
9273f4cbf05Sopenharmony_ci}
9283f4cbf05Sopenharmony_ci
9293f4cbf05Sopenharmony_ci/**
9303f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_004
9313f4cbf05Sopenharmony_ci * @tc.desc: test parcel primary type read write.
9323f4cbf05Sopenharmony_ci * @tc.type: FUNC
9333f4cbf05Sopenharmony_ci */
9343f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_004, TestSize.Level0)
9353f4cbf05Sopenharmony_ci{
9363f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
9373f4cbf05Sopenharmony_ci
9383f4cbf05Sopenharmony_ci    int64_t int64test = -0x1234567887654321;
9393f4cbf05Sopenharmony_ci    bool result = parcel1.WriteInt64(int64test);
9403f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
9413f4cbf05Sopenharmony_ci
9423f4cbf05Sopenharmony_ci    uint64_t uint64test = 0x1234567887654321;
9433f4cbf05Sopenharmony_ci    result = parcel1.WriteUint64(uint64test);
9443f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
9453f4cbf05Sopenharmony_ci
9463f4cbf05Sopenharmony_ci    int64_t readint64 = parcel1.ReadInt64();
9473f4cbf05Sopenharmony_ci    EXPECT_EQ(readint64, int64test);
9483f4cbf05Sopenharmony_ci
9493f4cbf05Sopenharmony_ci    uint64_t readuint64 = parcel1.ReadUint64();
9503f4cbf05Sopenharmony_ci    EXPECT_EQ(readuint64, uint64test);
9513f4cbf05Sopenharmony_ci
9523f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
9533f4cbf05Sopenharmony_ci
9543f4cbf05Sopenharmony_ci    void *buffer = nullptr;
9553f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
9563f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
9573f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
9583f4cbf05Sopenharmony_ci    }
9593f4cbf05Sopenharmony_ci
9603f4cbf05Sopenharmony_ci    result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
9613f4cbf05Sopenharmony_ci
9623f4cbf05Sopenharmony_ci    readint64 = parcel2.ReadInt64();
9633f4cbf05Sopenharmony_ci    EXPECT_EQ(readint64, int64test);
9643f4cbf05Sopenharmony_ci
9653f4cbf05Sopenharmony_ci    readuint64 = parcel2.ReadUint64();
9663f4cbf05Sopenharmony_ci    EXPECT_EQ(readuint64, uint64test);
9673f4cbf05Sopenharmony_ci}
9683f4cbf05Sopenharmony_ci
9693f4cbf05Sopenharmony_ci/**
9703f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_String_001
9713f4cbf05Sopenharmony_ci * @tc.desc: test parcel string read write.
9723f4cbf05Sopenharmony_ci * @tc.type: FUNC
9733f4cbf05Sopenharmony_ci */
9743f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String_001, TestSize.Level0)
9753f4cbf05Sopenharmony_ci{
9763f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
9773f4cbf05Sopenharmony_ci
9783f4cbf05Sopenharmony_ci    string strWrite = "test";
9793f4cbf05Sopenharmony_ci    bool result = parcel1.WriteString(strWrite);
9803f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
9813f4cbf05Sopenharmony_ci
9823f4cbf05Sopenharmony_ci    string strWrite1 =
9833f4cbf05Sopenharmony_ci        "test for write string padded**********************************************************##################";
9843f4cbf05Sopenharmony_ci    result = parcel1.WriteString(strWrite1);
9853f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
9863f4cbf05Sopenharmony_ci
9873f4cbf05Sopenharmony_ci    string strWrite2 =
9883f4cbf05Sopenharmony_ci        "test for write string padded**********************************************************##################";
9893f4cbf05Sopenharmony_ci    result = parcel1.WriteString(strWrite2);
9903f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
9913f4cbf05Sopenharmony_ci
9923f4cbf05Sopenharmony_ci    string strRead = parcel1.ReadString();
9933f4cbf05Sopenharmony_ci    string strRead1 = parcel1.ReadString();
9943f4cbf05Sopenharmony_ci    string strRead2 = parcel1.ReadString();
9953f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead.c_str(), strWrite.c_str()));
9963f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead1.c_str(), strWrite1.c_str()));
9973f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead2.c_str(), strWrite2.c_str()));
9983f4cbf05Sopenharmony_ci
9993f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
10003f4cbf05Sopenharmony_ci
10013f4cbf05Sopenharmony_ci    void *buffer = nullptr;
10023f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
10033f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
10043f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
10053f4cbf05Sopenharmony_ci    }
10063f4cbf05Sopenharmony_ci
10073f4cbf05Sopenharmony_ci    result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
10083f4cbf05Sopenharmony_ci
10093f4cbf05Sopenharmony_ci    strRead = parcel2.ReadString();
10103f4cbf05Sopenharmony_ci    strRead1 = parcel2.ReadString();
10113f4cbf05Sopenharmony_ci    strRead2 = parcel2.ReadString();
10123f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead.c_str(), strWrite.c_str()));
10133f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead1.c_str(), strWrite1.c_str()));
10143f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead2.c_str(), strWrite2.c_str()));
10153f4cbf05Sopenharmony_ci}
10163f4cbf05Sopenharmony_ci
10173f4cbf05Sopenharmony_ci/**
10183f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_String_002
10193f4cbf05Sopenharmony_ci * @tc.desc: test parcel string read write.
10203f4cbf05Sopenharmony_ci * @tc.type: FUNC
10213f4cbf05Sopenharmony_ci */
10223f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String_002, TestSize.Level0)
10233f4cbf05Sopenharmony_ci{
10243f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
10253f4cbf05Sopenharmony_ci
10263f4cbf05Sopenharmony_ci    u16string str16Write = u"12345";
10273f4cbf05Sopenharmony_ci    bool result = parcel1.WriteString16(str16Write);
10283f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
10293f4cbf05Sopenharmony_ci
10303f4cbf05Sopenharmony_ci    u16string str16Write2 = u"12345 test for write16string padded*********";
10313f4cbf05Sopenharmony_ci    result = parcel1.WriteString16(str16Write2);
10323f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
10333f4cbf05Sopenharmony_ci
10343f4cbf05Sopenharmony_ci    u16string str16Read = parcel1.ReadString16();
10353f4cbf05Sopenharmony_ci    u16string str16Read2 = parcel1.ReadString16();
10363f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16Read.compare(str16Write));
10373f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16Read2.compare(str16Write2));
10383f4cbf05Sopenharmony_ci
10393f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
10403f4cbf05Sopenharmony_ci
10413f4cbf05Sopenharmony_ci    void *buffer = nullptr;
10423f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
10433f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
10443f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
10453f4cbf05Sopenharmony_ci    }
10463f4cbf05Sopenharmony_ci
10473f4cbf05Sopenharmony_ci    result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
10483f4cbf05Sopenharmony_ci
10493f4cbf05Sopenharmony_ci    str16Read = parcel2.ReadString16();
10503f4cbf05Sopenharmony_ci    str16Read2 = parcel2.ReadString16();
10513f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16Read.compare(str16Write));
10523f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16Read2.compare(str16Write2));
10533f4cbf05Sopenharmony_ci}
10543f4cbf05Sopenharmony_ci
10553f4cbf05Sopenharmony_ci/**
10563f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_String_003
10573f4cbf05Sopenharmony_ci * @tc.desc: test parcel CString read write.
10583f4cbf05Sopenharmony_ci * @tc.type: FUNC
10593f4cbf05Sopenharmony_ci */
10603f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String_003, TestSize.Level0)
10613f4cbf05Sopenharmony_ci{
10623f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
10633f4cbf05Sopenharmony_ci    string test1 = "12345";
10643f4cbf05Sopenharmony_ci    string test2 = "23456";
10653f4cbf05Sopenharmony_ci    string test3 = "34567";
10663f4cbf05Sopenharmony_ci    string test4 = "45678";
10673f4cbf05Sopenharmony_ci    bool result = parcel.WriteCString(nullptr);
10683f4cbf05Sopenharmony_ci    EXPECT_FALSE(result);
10693f4cbf05Sopenharmony_ci    result = parcel.WriteCString(test1.c_str());
10703f4cbf05Sopenharmony_ci    EXPECT_TRUE(result);
10713f4cbf05Sopenharmony_ci    result = parcel.WriteCString(test2.c_str());
10723f4cbf05Sopenharmony_ci    EXPECT_TRUE(result);
10733f4cbf05Sopenharmony_ci    result = parcel.WriteCString(test3.c_str());
10743f4cbf05Sopenharmony_ci    EXPECT_TRUE(result);
10753f4cbf05Sopenharmony_ci    result = parcel.WriteCString(test4.c_str());
10763f4cbf05Sopenharmony_ci    EXPECT_TRUE(result);
10773f4cbf05Sopenharmony_ci
10783f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(test1.c_str(), parcel.ReadCString()));
10793f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(test2.c_str(), parcel.ReadCString()));
10803f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(test3.c_str(), parcel.ReadCString()));
10813f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(test4.c_str(), parcel.ReadCString()));
10823f4cbf05Sopenharmony_ci}
10833f4cbf05Sopenharmony_ci
10843f4cbf05Sopenharmony_ci/**
10853f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_String004
10863f4cbf05Sopenharmony_ci * @tc.desc: test parcel CString read write.
10873f4cbf05Sopenharmony_ci * @tc.type: FUNC
10883f4cbf05Sopenharmony_ci */
10893f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String004, TestSize.Level0)
10903f4cbf05Sopenharmony_ci{
10913f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
10923f4cbf05Sopenharmony_ci    bool result = false;
10933f4cbf05Sopenharmony_ci
10943f4cbf05Sopenharmony_ci    // write from Java, read from C++
10953f4cbf05Sopenharmony_ci    result = parcel1.WriteString16WithLength(nullptr, 0);
10963f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
10973f4cbf05Sopenharmony_ci
10983f4cbf05Sopenharmony_ci    u16string str16write = u"12345";
10993f4cbf05Sopenharmony_ci    char16_t *value1 = str16write.data();
11003f4cbf05Sopenharmony_ci    result = parcel1.WriteString16WithLength(value1, str16write.length());
11013f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11023f4cbf05Sopenharmony_ci
11033f4cbf05Sopenharmony_ci    u16string str16write2 = u"12345 test for write16string padded*********";
11043f4cbf05Sopenharmony_ci    char16_t *value2 = str16write2.data();
11053f4cbf05Sopenharmony_ci    result = parcel1.WriteString16WithLength(value2, str16write2.length());
11063f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11073f4cbf05Sopenharmony_ci
11083f4cbf05Sopenharmony_ci    u16string str16readNull = parcel1.ReadString16();
11093f4cbf05Sopenharmony_ci    u16string str16read1 = parcel1.ReadString16();
11103f4cbf05Sopenharmony_ci    u16string str16read2 = parcel1.ReadString16();
11113f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16readNull.compare(std::u16string()));
11123f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16read1.compare(str16write));
11133f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16read2.compare(str16write2));
11143f4cbf05Sopenharmony_ci
11153f4cbf05Sopenharmony_ci    // write from C++, read from Java
11163f4cbf05Sopenharmony_ci    result = parcel1.WriteString16(str16write);
11173f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11183f4cbf05Sopenharmony_ci
11193f4cbf05Sopenharmony_ci    result = parcel1.WriteString16(str16write2);
11203f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11213f4cbf05Sopenharmony_ci
11223f4cbf05Sopenharmony_ci    int32_t readLength1 = 0;
11233f4cbf05Sopenharmony_ci    u16string str16read3 = parcel1.ReadString16WithLength(readLength1);
11243f4cbf05Sopenharmony_ci    EXPECT_EQ(readLength1, static_cast<int32_t>(str16write.length()));
11253f4cbf05Sopenharmony_ci
11263f4cbf05Sopenharmony_ci    int32_t readLength2 = 0;
11273f4cbf05Sopenharmony_ci    u16string str16read4 = parcel1.ReadString16WithLength(readLength2);
11283f4cbf05Sopenharmony_ci    EXPECT_EQ(readLength2, static_cast<int32_t>(str16write2.length()));
11293f4cbf05Sopenharmony_ci
11303f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16read3.compare(str16write));
11313f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16read4.compare(str16write2));
11323f4cbf05Sopenharmony_ci}
11333f4cbf05Sopenharmony_ci
11343f4cbf05Sopenharmony_ci/**
11353f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_String005
11363f4cbf05Sopenharmony_ci * @tc.desc: test parcel CString read write.
11373f4cbf05Sopenharmony_ci * @tc.type: FUNC
11383f4cbf05Sopenharmony_ci */
11393f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String005, TestSize.Level0)
11403f4cbf05Sopenharmony_ci{
11413f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
11423f4cbf05Sopenharmony_ci    bool result = false;
11433f4cbf05Sopenharmony_ci
11443f4cbf05Sopenharmony_ci    // write from Java, read from C++
11453f4cbf05Sopenharmony_ci    result = parcel1.WriteString8WithLength(nullptr, 0);
11463f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11473f4cbf05Sopenharmony_ci
11483f4cbf05Sopenharmony_ci    string str8write = "12345";
11493f4cbf05Sopenharmony_ci    char *value1 = str8write.data();
11503f4cbf05Sopenharmony_ci    result = parcel1.WriteString8WithLength(value1, str8write.length());
11513f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11523f4cbf05Sopenharmony_ci
11533f4cbf05Sopenharmony_ci    string str8write2 = "12345 test for write16string padded*********";
11543f4cbf05Sopenharmony_ci    char *value2 = str8write2.data();
11553f4cbf05Sopenharmony_ci    result = parcel1.WriteString8WithLength(value2, str8write2.length());
11563f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11573f4cbf05Sopenharmony_ci
11583f4cbf05Sopenharmony_ci    string str8readNull = parcel1.ReadString();
11593f4cbf05Sopenharmony_ci    string str8read1 = parcel1.ReadString();
11603f4cbf05Sopenharmony_ci    string str8read2 = parcel1.ReadString();
11613f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str8readNull.compare(std::string()));
11623f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str8read1.compare(str8write));
11633f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str8read2.compare(str8write2));
11643f4cbf05Sopenharmony_ci
11653f4cbf05Sopenharmony_ci    // write from C++, read from Java
11663f4cbf05Sopenharmony_ci    result = parcel1.WriteString(str8write);
11673f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11683f4cbf05Sopenharmony_ci
11693f4cbf05Sopenharmony_ci    result = parcel1.WriteString(str8write2);
11703f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11713f4cbf05Sopenharmony_ci
11723f4cbf05Sopenharmony_ci    int32_t readLength1 = 0;
11733f4cbf05Sopenharmony_ci    string str8read3 = parcel1.ReadString8WithLength(readLength1);
11743f4cbf05Sopenharmony_ci    EXPECT_EQ(readLength1, static_cast<int32_t>(str8write.length()));
11753f4cbf05Sopenharmony_ci
11763f4cbf05Sopenharmony_ci    int32_t readLength2 = 0;
11773f4cbf05Sopenharmony_ci    string str8read4 = parcel1.ReadString8WithLength(readLength2);
11783f4cbf05Sopenharmony_ci    EXPECT_EQ(readLength2, static_cast<int32_t>(str8write2.length()));
11793f4cbf05Sopenharmony_ci
11803f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str8read3.compare(str8write));
11813f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str8read4.compare(str8write2));
11823f4cbf05Sopenharmony_ci}
11833f4cbf05Sopenharmony_ci
11843f4cbf05Sopenharmony_ci/**
11853f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_Float_001
11863f4cbf05Sopenharmony_ci * @tc.desc: test parcel float types read write.
11873f4cbf05Sopenharmony_ci * @tc.type: FUNC
11883f4cbf05Sopenharmony_ci */
11893f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_Float_001, TestSize.Level0)
11903f4cbf05Sopenharmony_ci{
11913f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
11923f4cbf05Sopenharmony_ci
11933f4cbf05Sopenharmony_ci    float floatwrite = 12.345678f;
11943f4cbf05Sopenharmony_ci    bool result = parcel1.WriteFloat(floatwrite);
11953f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
11963f4cbf05Sopenharmony_ci
11973f4cbf05Sopenharmony_ci    double doublewrite = 1345.7653;
11983f4cbf05Sopenharmony_ci    result = parcel1.WriteDouble(doublewrite);
11993f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12003f4cbf05Sopenharmony_ci
12013f4cbf05Sopenharmony_ci    float floatread;
12023f4cbf05Sopenharmony_ci    result = parcel1.ReadFloat(floatread);
12033f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12043f4cbf05Sopenharmony_ci    EXPECT_EQ(floatwrite, floatread);
12053f4cbf05Sopenharmony_ci
12063f4cbf05Sopenharmony_ci    double doubleread;
12073f4cbf05Sopenharmony_ci    doubleread = parcel1.ReadDouble();
12083f4cbf05Sopenharmony_ci    EXPECT_EQ(doublewrite, doubleread);
12093f4cbf05Sopenharmony_ci
12103f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
12113f4cbf05Sopenharmony_ci
12123f4cbf05Sopenharmony_ci    void *buffer = nullptr;
12133f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
12143f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
12153f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
12163f4cbf05Sopenharmony_ci    }
12173f4cbf05Sopenharmony_ci
12183f4cbf05Sopenharmony_ci    result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
12193f4cbf05Sopenharmony_ci    result = parcel2.ReadFloat(floatread);
12203f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12213f4cbf05Sopenharmony_ci    EXPECT_EQ(floatwrite, floatread);
12223f4cbf05Sopenharmony_ci
12233f4cbf05Sopenharmony_ci    doubleread = parcel2.ReadDouble();
12243f4cbf05Sopenharmony_ci    EXPECT_EQ(doublewrite, doubleread);
12253f4cbf05Sopenharmony_ci}
12263f4cbf05Sopenharmony_ci
12273f4cbf05Sopenharmony_ci/**
12283f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndRead_String_005
12293f4cbf05Sopenharmony_ci * @tc.desc: test parcel String type read write.
12303f4cbf05Sopenharmony_ci * @tc.type: FUNC
12313f4cbf05Sopenharmony_ci */
12323f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String_005, TestSize.Level0)
12333f4cbf05Sopenharmony_ci{
12343f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
12353f4cbf05Sopenharmony_ci
12363f4cbf05Sopenharmony_ci    string strwrite = "test";
12373f4cbf05Sopenharmony_ci    bool result = parcel1.WriteString(strwrite);
12383f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12393f4cbf05Sopenharmony_ci
12403f4cbf05Sopenharmony_ci    string strwrite1 =
12413f4cbf05Sopenharmony_ci        "test for write string padded**********************************************************##################";
12423f4cbf05Sopenharmony_ci    result = parcel1.WriteString(strwrite1);
12433f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12443f4cbf05Sopenharmony_ci
12453f4cbf05Sopenharmony_ci    string strwrite2 =
12463f4cbf05Sopenharmony_ci        "test for write string padded**********************************************************##################";
12473f4cbf05Sopenharmony_ci    result = parcel1.WriteString(strwrite2);
12483f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12493f4cbf05Sopenharmony_ci
12503f4cbf05Sopenharmony_ci    string strread;
12513f4cbf05Sopenharmony_ci    string strread1;
12523f4cbf05Sopenharmony_ci    string strread2;
12533f4cbf05Sopenharmony_ci    result = parcel1.ReadString(strread);
12543f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12553f4cbf05Sopenharmony_ci    result = parcel1.ReadString(strread1);
12563f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12573f4cbf05Sopenharmony_ci    result = parcel1.ReadString(strread2);
12583f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12593f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strread.c_str(), strwrite.c_str()));
12603f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strread1.c_str(), strwrite1.c_str()));
12613f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strread2.c_str(), strwrite2.c_str()));
12623f4cbf05Sopenharmony_ci
12633f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
12643f4cbf05Sopenharmony_ci
12653f4cbf05Sopenharmony_ci    void *buffer = nullptr;
12663f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
12673f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
12683f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
12693f4cbf05Sopenharmony_ci    }
12703f4cbf05Sopenharmony_ci
12713f4cbf05Sopenharmony_ci    result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
12723f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12733f4cbf05Sopenharmony_ci
12743f4cbf05Sopenharmony_ci    result = parcel2.ReadString(strread);
12753f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12763f4cbf05Sopenharmony_ci    result = parcel2.ReadString(strread1);
12773f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12783f4cbf05Sopenharmony_ci    result = parcel2.ReadString(strread2);
12793f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
12803f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strread.c_str(), strwrite.c_str()));
12813f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strread1.c_str(), strwrite1.c_str()));
12823f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strread2.c_str(), strwrite2.c_str()));
12833f4cbf05Sopenharmony_ci}
12843f4cbf05Sopenharmony_ci
12853f4cbf05Sopenharmony_cistruct Padded {
12863f4cbf05Sopenharmony_ci    char title;
12873f4cbf05Sopenharmony_ci    int32_t handle;
12883f4cbf05Sopenharmony_ci    uint64_t cookie;
12893f4cbf05Sopenharmony_ci};
12903f4cbf05Sopenharmony_ci
12913f4cbf05Sopenharmony_cistruct Unpadded {
12923f4cbf05Sopenharmony_ci    char tip;
12933f4cbf05Sopenharmony_ci};
12943f4cbf05Sopenharmony_ci
12953f4cbf05Sopenharmony_civoid ValidatePadded(const struct Padded &left, const struct Padded &right)
12963f4cbf05Sopenharmony_ci{
12973f4cbf05Sopenharmony_ci    EXPECT_EQ(left.title, right.title);
12983f4cbf05Sopenharmony_ci    EXPECT_EQ(left.handle, right.handle);
12993f4cbf05Sopenharmony_ci    EXPECT_EQ(left.cookie, right.cookie);
13003f4cbf05Sopenharmony_ci}
13013f4cbf05Sopenharmony_ci
13023f4cbf05Sopenharmony_civoid ValidateUnpadded(const struct Unpadded &left, const struct Unpadded &right)
13033f4cbf05Sopenharmony_ci{
13043f4cbf05Sopenharmony_ci    EXPECT_EQ(left.tip, right.tip);
13053f4cbf05Sopenharmony_ci}
13063f4cbf05Sopenharmony_ci
13073f4cbf05Sopenharmony_ci/**
13083f4cbf05Sopenharmony_ci * @tc.name: test_CalcNewCapacity_001
13093f4cbf05Sopenharmony_ci * @tc.desc: test kinds of input to CalcNewCapacity.
13103f4cbf05Sopenharmony_ci * @tc.type: FUNC
13113f4cbf05Sopenharmony_ci */
13123f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_CalcNewCapacity_001, TestSize.Level0)
13133f4cbf05Sopenharmony_ci{
13143f4cbf05Sopenharmony_ci    Parcel parcel;
13153f4cbf05Sopenharmony_ci
13163f4cbf05Sopenharmony_ci    size_t newMaxCapacity;
13173f4cbf05Sopenharmony_ci    size_t minNewCapacity = CAPACITY_THRESHOLD;
13183f4cbf05Sopenharmony_ci    const string strLenThreshd = string(minNewCapacity, 't');
13193f4cbf05Sopenharmony_ci    bool ret = parcel.WriteUnpadBuffer(static_cast<const void *>(strLenThreshd.data()), minNewCapacity);
13203f4cbf05Sopenharmony_ci    EXPECT_EQ(true, ret); // calculated capacity = CAPACITY_THRESHOLD
13213f4cbf05Sopenharmony_ci
13223f4cbf05Sopenharmony_ci    newMaxCapacity = CAPACITY_THRESHOLD - 1;
13233f4cbf05Sopenharmony_ci    minNewCapacity = newMaxCapacity;
13243f4cbf05Sopenharmony_ci    const string strLessThreshd = string(minNewCapacity, 'l');
13253f4cbf05Sopenharmony_ci    parcel.SetMaxCapacity(newMaxCapacity);
13263f4cbf05Sopenharmony_ci    ret = parcel.WriteUnpadBuffer(static_cast<const void *>(strLessThreshd.data()), minNewCapacity);
13273f4cbf05Sopenharmony_ci    EXPECT_EQ(true, ret); // calculated capacity = newMaxCapacity
13283f4cbf05Sopenharmony_ci
13293f4cbf05Sopenharmony_ci    newMaxCapacity = -1; // minNewCapacity = CAPACITY_THRESHOLD - 1
13303f4cbf05Sopenharmony_ci    const string strNoMaxCap = string(minNewCapacity, 'n');
13313f4cbf05Sopenharmony_ci    parcel.SetMaxCapacity(newMaxCapacity);
13323f4cbf05Sopenharmony_ci    ret = parcel.WriteUnpadBuffer(static_cast<const void *>(strNoMaxCap.data()), minNewCapacity);
13333f4cbf05Sopenharmony_ci    EXPECT_EQ(ret, true); // calculated capacity = CAPACITY_THRESHOLD
13343f4cbf05Sopenharmony_ci
13353f4cbf05Sopenharmony_ci    minNewCapacity = CAPACITY_THRESHOLD + 1; // newMaxCapacity = -1
13363f4cbf05Sopenharmony_ci    const string strExtThreshd = string(minNewCapacity, 'e');
13373f4cbf05Sopenharmony_ci    parcel.SetMaxCapacity(newMaxCapacity);
13383f4cbf05Sopenharmony_ci    ret = parcel.WriteUnpadBuffer(static_cast<const void *>(strExtThreshd.data()), minNewCapacity);
13393f4cbf05Sopenharmony_ci    EXPECT_EQ(ret, true); // calculated capacity = 2 * CAPACITY_THRESHOLD
13403f4cbf05Sopenharmony_ci
13413f4cbf05Sopenharmony_ci    newMaxCapacity = CAPACITY_THRESHOLD; // minNewCapacity = CAPACITY_THRESHOLD + 1
13423f4cbf05Sopenharmony_ci    const string strCapThreshd = string(minNewCapacity, 'e');
13433f4cbf05Sopenharmony_ci    parcel.SetMaxCapacity(newMaxCapacity);
13443f4cbf05Sopenharmony_ci    ret = parcel.WriteUnpadBuffer(static_cast<const void *>(strCapThreshd.data()), minNewCapacity);
13453f4cbf05Sopenharmony_ci    EXPECT_EQ(ret, true); // calculated capacity = CAPACITY_THRESHOLD
13463f4cbf05Sopenharmony_ci}
13473f4cbf05Sopenharmony_ci
13483f4cbf05Sopenharmony_ci/**
13493f4cbf05Sopenharmony_ci * @tc.name: test_SetDataCapacity_001
13503f4cbf05Sopenharmony_ci * @tc.desc: test kinds of input to SetDataCapacity.
13513f4cbf05Sopenharmony_ci * @tc.type: FUNC
13523f4cbf05Sopenharmony_ci */
13533f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_SetDataCapacity_001, TestSize.Level0)
13543f4cbf05Sopenharmony_ci{
13553f4cbf05Sopenharmony_ci    Parcel parcel;
13563f4cbf05Sopenharmony_ci    struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 };
13573f4cbf05Sopenharmony_ci
13583f4cbf05Sopenharmony_ci    WriteTestData(parcel, data);
13593f4cbf05Sopenharmony_ci    bool result = parcel.SetDataCapacity(0);
13603f4cbf05Sopenharmony_ci    EXPECT_FALSE(result);
13613f4cbf05Sopenharmony_ci}
13623f4cbf05Sopenharmony_ci
13633f4cbf05Sopenharmony_ci/**
13643f4cbf05Sopenharmony_ci * @tc.name: test_SetDataSize_001
13653f4cbf05Sopenharmony_ci * @tc.desc: test kinds of input to SetDataSize.
13663f4cbf05Sopenharmony_ci * @tc.type: FUNC
13673f4cbf05Sopenharmony_ci */
13683f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_SetDataSize_001, TestSize.Level0)
13693f4cbf05Sopenharmony_ci{
13703f4cbf05Sopenharmony_ci    Parcel parcel;
13713f4cbf05Sopenharmony_ci
13723f4cbf05Sopenharmony_ci    bool result = parcel.SetDataCapacity(sizeof(bool));
13733f4cbf05Sopenharmony_ci    EXPECT_TRUE(result);
13743f4cbf05Sopenharmony_ci    result = parcel.WriteBool(true);
13753f4cbf05Sopenharmony_ci    EXPECT_TRUE(result);
13763f4cbf05Sopenharmony_ci    result = parcel.SetDataSize(DEFAULT_CPACITY + 1);
13773f4cbf05Sopenharmony_ci    EXPECT_FALSE(result);
13783f4cbf05Sopenharmony_ci}
13793f4cbf05Sopenharmony_ci
13803f4cbf05Sopenharmony_ci/**
13813f4cbf05Sopenharmony_ci * @tc.name: test_parcel_Data_Structure_001
13823f4cbf05Sopenharmony_ci * @tc.desc: test parcel struct data related function.
13833f4cbf05Sopenharmony_ci * @tc.type: FUNC
13843f4cbf05Sopenharmony_ci */
13853f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_Data_Structure_001, TestSize.Level0)
13863f4cbf05Sopenharmony_ci{
13873f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
13883f4cbf05Sopenharmony_ci
13893f4cbf05Sopenharmony_ci    const struct Padded pad = { 'p', 0x34567890, -0x2345678998765432 };
13903f4cbf05Sopenharmony_ci    const struct Unpadded unpad = { 'u' };
13913f4cbf05Sopenharmony_ci
13923f4cbf05Sopenharmony_ci    bool result = parcel.WriteBuffer(static_cast<const void *>(&pad), sizeof(struct Padded));
13933f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
13943f4cbf05Sopenharmony_ci    const struct Padded *padRead = reinterpret_cast<const struct Padded *>(parcel.ReadBuffer(sizeof(struct Padded)));
13953f4cbf05Sopenharmony_ci    ValidatePadded(*padRead, pad);
13963f4cbf05Sopenharmony_ci    EXPECT_EQ(parcel.GetWritePosition(), parcel.GetReadPosition());
13973f4cbf05Sopenharmony_ci
13983f4cbf05Sopenharmony_ci    result = parcel.WriteBuffer(static_cast<const void *>(&unpad), sizeof(struct Unpadded));
13993f4cbf05Sopenharmony_ci    const struct Unpadded *unpadRead =
14003f4cbf05Sopenharmony_ci        reinterpret_cast<const struct Unpadded *>(parcel.ReadBuffer(sizeof(struct Unpadded)));
14013f4cbf05Sopenharmony_ci    ValidateUnpadded(*unpadRead, unpad);
14023f4cbf05Sopenharmony_ci    EXPECT_NE(parcel.GetWritePosition(), parcel.GetReadPosition());
14033f4cbf05Sopenharmony_ci
14043f4cbf05Sopenharmony_ci    parcel.RewindRead(0);
14053f4cbf05Sopenharmony_ci    parcel.RewindWrite(0);
14063f4cbf05Sopenharmony_ci    EXPECT_EQ(parcel.GetWritePosition(), parcel.GetReadPosition());
14073f4cbf05Sopenharmony_ci
14083f4cbf05Sopenharmony_ci    result = parcel.WriteUnpadBuffer(static_cast<const void *>(&pad), sizeof(struct Padded));
14093f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
14103f4cbf05Sopenharmony_ci    const struct Padded *padReadNew =
14113f4cbf05Sopenharmony_ci        reinterpret_cast<const struct Padded *>(parcel.ReadUnpadBuffer(sizeof(struct Padded)));
14123f4cbf05Sopenharmony_ci    ValidatePadded(*padReadNew, pad);
14133f4cbf05Sopenharmony_ci    EXPECT_EQ(parcel.GetWritePosition(), parcel.GetReadPosition());
14143f4cbf05Sopenharmony_ci
14153f4cbf05Sopenharmony_ci    result = parcel.WriteUnpadBuffer(static_cast<const void *>(&unpad), sizeof(struct Unpadded));
14163f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
14173f4cbf05Sopenharmony_ci    const struct Unpadded *unpadReadNew =
14183f4cbf05Sopenharmony_ci        reinterpret_cast<const struct Unpadded *>(parcel.ReadUnpadBuffer(sizeof(struct Unpadded)));
14193f4cbf05Sopenharmony_ci    ValidateUnpadded(*unpadReadNew, unpad);
14203f4cbf05Sopenharmony_ci    EXPECT_EQ(parcel.GetWritePosition(), parcel.GetReadPosition());
14213f4cbf05Sopenharmony_ci}
14223f4cbf05Sopenharmony_ci
14233f4cbf05Sopenharmony_ci/**
14243f4cbf05Sopenharmony_ci * @tc.name: test_parcel_Data_Structure_002
14253f4cbf05Sopenharmony_ci * @tc.desc: test invalid input to WriteBuffer and WriteBufferAddTerminator.
14263f4cbf05Sopenharmony_ci * @tc.type: FUNC
14273f4cbf05Sopenharmony_ci */
14283f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_Data_Structure_002, TestSize.Level0)
14293f4cbf05Sopenharmony_ci{
14303f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
14313f4cbf05Sopenharmony_ci
14323f4cbf05Sopenharmony_ci    const string str = "test invalid input";
14333f4cbf05Sopenharmony_ci    const string strOverflow = "test write with SIZE_MAX bytes";
14343f4cbf05Sopenharmony_ci    const string strWriteFail = string((DEFAULT_CPACITY + 1) / sizeof(char), 'f');
14353f4cbf05Sopenharmony_ci    const string strWriteTermFail = string((DEFAULT_CPACITY - 2) / sizeof(char), 't');
14363f4cbf05Sopenharmony_ci
14373f4cbf05Sopenharmony_ci    bool result = parcel.WriteBuffer(nullptr, sizeof(string));
14383f4cbf05Sopenharmony_ci    EXPECT_EQ(false, result);
14393f4cbf05Sopenharmony_ci    result = parcel.WriteBufferAddTerminator(nullptr, sizeof(string), sizeof(char));
14403f4cbf05Sopenharmony_ci    EXPECT_EQ(false, result);
14413f4cbf05Sopenharmony_ci
14423f4cbf05Sopenharmony_ci    result = parcel.WriteBuffer(static_cast<const void *>(str.data()), 0);
14433f4cbf05Sopenharmony_ci    EXPECT_EQ(false, result);
14443f4cbf05Sopenharmony_ci    result = parcel.WriteBufferAddTerminator(static_cast<const void *>(str.data()), 0, sizeof(char));
14453f4cbf05Sopenharmony_ci    EXPECT_EQ(false, result);
14463f4cbf05Sopenharmony_ci
14473f4cbf05Sopenharmony_ci    result = parcel.WriteBuffer(static_cast<const void *>(strWriteFail.data()), strWriteFail.length());
14483f4cbf05Sopenharmony_ci    EXPECT_EQ(false, result);
14493f4cbf05Sopenharmony_ci    result = parcel.WriteBufferAddTerminator(static_cast<const void *>(strWriteFail.data()),
14503f4cbf05Sopenharmony_ci                                             strWriteFail.length(), sizeof(char));
14513f4cbf05Sopenharmony_ci    EXPECT_EQ(false, result);
14523f4cbf05Sopenharmony_ci
14533f4cbf05Sopenharmony_ci    result = parcel.WriteBufferAddTerminator(static_cast<const void *>(str.data()), str.length(), sizeof(char));
14543f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
14553f4cbf05Sopenharmony_ci
14563f4cbf05Sopenharmony_ci    Parcel recvParcel(nullptr);
14573f4cbf05Sopenharmony_ci    void *buffer = nullptr;
14583f4cbf05Sopenharmony_ci    size_t size = parcel.GetDataSize();
14593f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel.GetData()))) {
14603f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
14613f4cbf05Sopenharmony_ci    }
14623f4cbf05Sopenharmony_ci    result = recvParcel.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel.GetDataSize());
14633f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14643f4cbf05Sopenharmony_ci    result = recvParcel.WriteBufferAddTerminator(static_cast<const void *>(&str), str.length() + 1, sizeof(char));
14653f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
14663f4cbf05Sopenharmony_ci}
14673f4cbf05Sopenharmony_ci
14683f4cbf05Sopenharmony_cistruct VectorTestData {
14693f4cbf05Sopenharmony_ci    vector<bool> booltest = { false, false, true, false, true };
14703f4cbf05Sopenharmony_ci    vector<int8_t> int8test = { 0x01, 0x10, -0x20, 0x30, 0x40 };
14713f4cbf05Sopenharmony_ci    vector<int16_t> int16test = { 0x1234, -0x2345, 0x3456, -0x4567, 0x5678 };
14723f4cbf05Sopenharmony_ci    vector<int32_t> int32test = { 0x12345678, -0x23456789, 0x34567890, -0x45678901 };
14733f4cbf05Sopenharmony_ci    vector<int64_t> int64test = { 0x1234567887654321, -0x2345678998765432 };
14743f4cbf05Sopenharmony_ci    vector<uint8_t> uint8test = { 0x01, 0x10, 0x20, 0x30, 0x40 };
14753f4cbf05Sopenharmony_ci    vector<uint16_t> uint16test = { 0x1234, 0x2345, 0x3456, 0x4567, 0x5678 };
14763f4cbf05Sopenharmony_ci    vector<uint32_t> uint32test = { 0x12345678, 0x23456789, 0x34567890, 0x45678901 };
14773f4cbf05Sopenharmony_ci    vector<uint64_t> uint64test = { 0x1234567887654321, 0x2345678998765432 };
14783f4cbf05Sopenharmony_ci};
14793f4cbf05Sopenharmony_ci
14803f4cbf05Sopenharmony_civoid WriteVectorTestData(Parcel &parcel, const VectorTestData &data)
14813f4cbf05Sopenharmony_ci{
14823f4cbf05Sopenharmony_ci    bool result = parcel.WriteBoolVector(data.booltest);
14833f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14843f4cbf05Sopenharmony_ci    result = parcel.WriteInt8Vector(data.int8test);
14853f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14863f4cbf05Sopenharmony_ci    result = parcel.WriteInt16Vector(data.int16test);
14873f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14883f4cbf05Sopenharmony_ci    result = parcel.WriteInt32Vector(data.int32test);
14893f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14903f4cbf05Sopenharmony_ci    result = parcel.WriteInt64Vector(data.int64test);
14913f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14923f4cbf05Sopenharmony_ci    result = parcel.WriteUInt8Vector(data.uint8test);
14933f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14943f4cbf05Sopenharmony_ci    result = parcel.WriteUInt16Vector(data.uint16test);
14953f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14963f4cbf05Sopenharmony_ci    result = parcel.WriteUInt32Vector(data.uint32test);
14973f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
14983f4cbf05Sopenharmony_ci    result = parcel.WriteUInt64Vector(data.uint64test);
14993f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15003f4cbf05Sopenharmony_ci}
15013f4cbf05Sopenharmony_ci
15023f4cbf05Sopenharmony_civoid ReadVectorTestDataFunc01(Parcel &parcel, const VectorTestData &data)
15033f4cbf05Sopenharmony_ci{
15043f4cbf05Sopenharmony_ci    vector<bool> boolread;
15053f4cbf05Sopenharmony_ci    vector<int8_t> int8read;
15063f4cbf05Sopenharmony_ci    vector<int16_t> int16read;
15073f4cbf05Sopenharmony_ci    vector<int32_t> int32read;
15083f4cbf05Sopenharmony_ci    vector<int64_t> int64read;
15093f4cbf05Sopenharmony_ci
15103f4cbf05Sopenharmony_ci    bool result = parcel.ReadBoolVector(&boolread);
15113f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15123f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.booltest.size(); i++) {
15133f4cbf05Sopenharmony_ci        EXPECT_EQ(data.booltest[i], boolread[i]);
15143f4cbf05Sopenharmony_ci    }
15153f4cbf05Sopenharmony_ci
15163f4cbf05Sopenharmony_ci    result = parcel.ReadInt8Vector(&int8read);
15173f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15183f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.int8test.size(); i++) {
15193f4cbf05Sopenharmony_ci        EXPECT_EQ(data.int8test[i], int8read[i]);
15203f4cbf05Sopenharmony_ci    }
15213f4cbf05Sopenharmony_ci
15223f4cbf05Sopenharmony_ci    result = parcel.ReadInt16Vector(&int16read);
15233f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15243f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.int16test.size(); i++) {
15253f4cbf05Sopenharmony_ci        EXPECT_EQ(data.int16test[i], int16read[i]);
15263f4cbf05Sopenharmony_ci    }
15273f4cbf05Sopenharmony_ci
15283f4cbf05Sopenharmony_ci    result = parcel.ReadInt32Vector(&int32read);
15293f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15303f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.int32test.size(); i++) {
15313f4cbf05Sopenharmony_ci        EXPECT_EQ(data.int32test[i], int32read[i]);
15323f4cbf05Sopenharmony_ci    }
15333f4cbf05Sopenharmony_ci
15343f4cbf05Sopenharmony_ci    result = parcel.ReadInt64Vector(&int64read);
15353f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15363f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.int64test.size(); i++) {
15373f4cbf05Sopenharmony_ci        EXPECT_EQ(data.int64test[i], int64read[i]);
15383f4cbf05Sopenharmony_ci    }
15393f4cbf05Sopenharmony_ci}
15403f4cbf05Sopenharmony_ci
15413f4cbf05Sopenharmony_civoid ReadVectorTestDataFunc02(Parcel &parcel, const VectorTestData &data)
15423f4cbf05Sopenharmony_ci{
15433f4cbf05Sopenharmony_ci    vector<uint8_t> uint8read;
15443f4cbf05Sopenharmony_ci    vector<uint16_t> uint16read;
15453f4cbf05Sopenharmony_ci    vector<uint32_t> uint32read;
15463f4cbf05Sopenharmony_ci    vector<uint64_t> uint64read;
15473f4cbf05Sopenharmony_ci
15483f4cbf05Sopenharmony_ci    bool result = parcel.ReadUInt8Vector(&uint8read);
15493f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15503f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.uint8test.size(); i++) {
15513f4cbf05Sopenharmony_ci        EXPECT_EQ(data.uint8test[i], uint8read[i]);
15523f4cbf05Sopenharmony_ci    }
15533f4cbf05Sopenharmony_ci
15543f4cbf05Sopenharmony_ci    result = parcel.ReadUInt16Vector(&uint16read);
15553f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15563f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.uint16test.size(); i++) {
15573f4cbf05Sopenharmony_ci        EXPECT_EQ(data.uint16test[i], uint16read[i]);
15583f4cbf05Sopenharmony_ci    }
15593f4cbf05Sopenharmony_ci
15603f4cbf05Sopenharmony_ci    result = parcel.ReadUInt32Vector(&uint32read);
15613f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15623f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.uint32test.size(); i++) {
15633f4cbf05Sopenharmony_ci        EXPECT_EQ(data.uint32test[i], uint32read[i]);
15643f4cbf05Sopenharmony_ci    }
15653f4cbf05Sopenharmony_ci
15663f4cbf05Sopenharmony_ci    result = parcel.ReadUInt64Vector(&uint64read);
15673f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
15683f4cbf05Sopenharmony_ci    for (size_t i = 0; i < data.uint64test.size(); i++) {
15693f4cbf05Sopenharmony_ci        EXPECT_EQ(data.uint64test[i], uint64read[i]);
15703f4cbf05Sopenharmony_ci    }
15713f4cbf05Sopenharmony_ci}
15723f4cbf05Sopenharmony_ci
15733f4cbf05Sopenharmony_civoid ReadVectorTestData(Parcel &parcel, const VectorTestData &data)
15743f4cbf05Sopenharmony_ci{
15753f4cbf05Sopenharmony_ci    ReadVectorTestDataFunc01(parcel, data);
15763f4cbf05Sopenharmony_ci    ReadVectorTestDataFunc02(parcel, data);
15773f4cbf05Sopenharmony_ci}
15783f4cbf05Sopenharmony_ci
15793f4cbf05Sopenharmony_ci/**
15803f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndReadVector_001
15813f4cbf05Sopenharmony_ci * @tc.desc: test vector parcel read and write.
15823f4cbf05Sopenharmony_ci * @tc.type: FUNC
15833f4cbf05Sopenharmony_ci */
15843f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndReadVector_001, TestSize.Level0)
15853f4cbf05Sopenharmony_ci{
15863f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
15873f4cbf05Sopenharmony_ci    struct VectorTestData data;
15883f4cbf05Sopenharmony_ci
15893f4cbf05Sopenharmony_ci    WriteVectorTestData(parcel, data);
15903f4cbf05Sopenharmony_ci    ReadVectorTestData(parcel, data);
15913f4cbf05Sopenharmony_ci}
15923f4cbf05Sopenharmony_ci
15933f4cbf05Sopenharmony_ci/**
15943f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndReadVector_002
15953f4cbf05Sopenharmony_ci * @tc.desc: test vector parcel read and write.
15963f4cbf05Sopenharmony_ci * @tc.type: FUNC
15973f4cbf05Sopenharmony_ci */
15983f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndReadVector_002, TestSize.Level0)
15993f4cbf05Sopenharmony_ci{
16003f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
16013f4cbf05Sopenharmony_ci    struct VectorTestData data;
16023f4cbf05Sopenharmony_ci    WriteVectorTestData(parcel1, data);
16033f4cbf05Sopenharmony_ci
16043f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
16053f4cbf05Sopenharmony_ci
16063f4cbf05Sopenharmony_ci    void *buffer = nullptr;
16073f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
16083f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
16093f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
16103f4cbf05Sopenharmony_ci    }
16113f4cbf05Sopenharmony_ci
16123f4cbf05Sopenharmony_ci    bool result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
16133f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16143f4cbf05Sopenharmony_ci    ReadVectorTestData(parcel2, data);
16153f4cbf05Sopenharmony_ci}
16163f4cbf05Sopenharmony_ci
16173f4cbf05Sopenharmony_ci/**
16183f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndReadVector_003
16193f4cbf05Sopenharmony_ci * @tc.desc: test vector parcel read and write.
16203f4cbf05Sopenharmony_ci * @tc.type: FUNC
16213f4cbf05Sopenharmony_ci */
16223f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndReadVector_003, TestSize.Level0)
16233f4cbf05Sopenharmony_ci{
16243f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
16253f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
16263f4cbf05Sopenharmony_ci
16273f4cbf05Sopenharmony_ci    vector<string> stringtest{ "test", "test for", "test for write", "test for write vector" };
16283f4cbf05Sopenharmony_ci    vector<u16string> string16test{ u"test", u"test for", u"test for write", u"test for write vector" };
16293f4cbf05Sopenharmony_ci
16303f4cbf05Sopenharmony_ci    bool result = parcel1.WriteStringVector(stringtest);
16313f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16323f4cbf05Sopenharmony_ci    result = parcel1.WriteString16Vector(string16test);
16333f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16343f4cbf05Sopenharmony_ci
16353f4cbf05Sopenharmony_ci    vector<string> stringread;
16363f4cbf05Sopenharmony_ci    result = parcel1.ReadStringVector(&stringread);
16373f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16383f4cbf05Sopenharmony_ci    for (size_t i = 0; i < stringtest.size(); i++) {
16393f4cbf05Sopenharmony_ci        EXPECT_EQ(stringtest[i], stringread[i]);
16403f4cbf05Sopenharmony_ci    }
16413f4cbf05Sopenharmony_ci
16423f4cbf05Sopenharmony_ci    vector<u16string> u16stringread;
16433f4cbf05Sopenharmony_ci    result = parcel1.ReadString16Vector(&u16stringread);
16443f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16453f4cbf05Sopenharmony_ci    for (size_t i = 0; i < string16test.size(); i++) {
16463f4cbf05Sopenharmony_ci        EXPECT_EQ(0, string16test[i].compare(u16stringread[i]));
16473f4cbf05Sopenharmony_ci    }
16483f4cbf05Sopenharmony_ci
16493f4cbf05Sopenharmony_ci    void *buffer = nullptr;
16503f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
16513f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
16523f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
16533f4cbf05Sopenharmony_ci    }
16543f4cbf05Sopenharmony_ci
16553f4cbf05Sopenharmony_ci    result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
16563f4cbf05Sopenharmony_ci    result = parcel2.ReadStringVector(&stringread);
16573f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16583f4cbf05Sopenharmony_ci    for (size_t i = 0; i < stringtest.size(); i++) {
16593f4cbf05Sopenharmony_ci        EXPECT_EQ(stringtest[i], stringread[i]);
16603f4cbf05Sopenharmony_ci    }
16613f4cbf05Sopenharmony_ci
16623f4cbf05Sopenharmony_ci    result = parcel2.ReadString16Vector(&u16stringread);
16633f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16643f4cbf05Sopenharmony_ci    for (size_t i = 0; i < string16test.size(); i++) {
16653f4cbf05Sopenharmony_ci        EXPECT_EQ(0, string16test[i].compare(u16stringread[i]));
16663f4cbf05Sopenharmony_ci    }
16673f4cbf05Sopenharmony_ci}
16683f4cbf05Sopenharmony_ci
16693f4cbf05Sopenharmony_ci/**
16703f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndReadVector_004
16713f4cbf05Sopenharmony_ci * @tc.desc: test vector parcel read and write.
16723f4cbf05Sopenharmony_ci * @tc.type: FUNC
16733f4cbf05Sopenharmony_ci */
16743f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndReadVector_004, TestSize.Level0)
16753f4cbf05Sopenharmony_ci{
16763f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
16773f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
16783f4cbf05Sopenharmony_ci
16793f4cbf05Sopenharmony_ci    vector<float> floattest{ 11221.132313, 11221.45678 };
16803f4cbf05Sopenharmony_ci    vector<double> doubletest{ 1122.132313, 1122.45678 };
16813f4cbf05Sopenharmony_ci
16823f4cbf05Sopenharmony_ci    bool result = parcel1.WriteFloatVector(floattest);
16833f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16843f4cbf05Sopenharmony_ci
16853f4cbf05Sopenharmony_ci    result = parcel1.WriteDoubleVector(doubletest);
16863f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16873f4cbf05Sopenharmony_ci
16883f4cbf05Sopenharmony_ci    vector<float> floatread;
16893f4cbf05Sopenharmony_ci    vector<double> doubleread;
16903f4cbf05Sopenharmony_ci
16913f4cbf05Sopenharmony_ci    result = parcel1.ReadFloatVector(&floatread);
16923f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16933f4cbf05Sopenharmony_ci    for (size_t i = 0; i < floattest.size(); i++) {
16943f4cbf05Sopenharmony_ci        EXPECT_EQ(floattest[i], floatread[i]);
16953f4cbf05Sopenharmony_ci    }
16963f4cbf05Sopenharmony_ci
16973f4cbf05Sopenharmony_ci    result = parcel1.ReadDoubleVector(&doubleread);
16983f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
16993f4cbf05Sopenharmony_ci    for (size_t i = 0; i < doubletest.size(); i++) {
17003f4cbf05Sopenharmony_ci        EXPECT_EQ(doubletest[i], doubleread[i]);
17013f4cbf05Sopenharmony_ci    }
17023f4cbf05Sopenharmony_ci}
17033f4cbf05Sopenharmony_ci
17043f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<bool> &vectorTest)
17053f4cbf05Sopenharmony_ci{
17063f4cbf05Sopenharmony_ci    return parcel.WriteBoolVector(vectorTest);
17073f4cbf05Sopenharmony_ci}
17083f4cbf05Sopenharmony_ci
17093f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<int8_t> &vectorTest)
17103f4cbf05Sopenharmony_ci{
17113f4cbf05Sopenharmony_ci    return parcel.WriteInt8Vector(vectorTest);
17123f4cbf05Sopenharmony_ci}
17133f4cbf05Sopenharmony_ci
17143f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<int16_t> &vectorTest)
17153f4cbf05Sopenharmony_ci{
17163f4cbf05Sopenharmony_ci    return parcel.WriteInt16Vector(vectorTest);
17173f4cbf05Sopenharmony_ci}
17183f4cbf05Sopenharmony_ci
17193f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<int32_t> &vectorTest)
17203f4cbf05Sopenharmony_ci{
17213f4cbf05Sopenharmony_ci    return parcel.WriteInt32Vector(vectorTest);
17223f4cbf05Sopenharmony_ci}
17233f4cbf05Sopenharmony_ci
17243f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<int64_t> &vectorTest)
17253f4cbf05Sopenharmony_ci{
17263f4cbf05Sopenharmony_ci    return parcel.WriteInt64Vector(vectorTest);
17273f4cbf05Sopenharmony_ci}
17283f4cbf05Sopenharmony_ci
17293f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<uint8_t> &vectorTest)
17303f4cbf05Sopenharmony_ci{
17313f4cbf05Sopenharmony_ci    return parcel.WriteUInt8Vector(vectorTest);
17323f4cbf05Sopenharmony_ci}
17333f4cbf05Sopenharmony_ci
17343f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<uint16_t> &vectorTest)
17353f4cbf05Sopenharmony_ci{
17363f4cbf05Sopenharmony_ci    return parcel.WriteUInt16Vector(vectorTest);
17373f4cbf05Sopenharmony_ci}
17383f4cbf05Sopenharmony_ci
17393f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<uint32_t> &vectorTest)
17403f4cbf05Sopenharmony_ci{
17413f4cbf05Sopenharmony_ci    return parcel.WriteUInt32Vector(vectorTest);
17423f4cbf05Sopenharmony_ci}
17433f4cbf05Sopenharmony_ci
17443f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<uint64_t> &vectorTest)
17453f4cbf05Sopenharmony_ci{
17463f4cbf05Sopenharmony_ci    return parcel.WriteUInt64Vector(vectorTest);
17473f4cbf05Sopenharmony_ci}
17483f4cbf05Sopenharmony_ci
17493f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<float> &vectorTest)
17503f4cbf05Sopenharmony_ci{
17513f4cbf05Sopenharmony_ci    return parcel.WriteFloatVector(vectorTest);
17523f4cbf05Sopenharmony_ci}
17533f4cbf05Sopenharmony_ci
17543f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<double> &vectorTest)
17553f4cbf05Sopenharmony_ci{
17563f4cbf05Sopenharmony_ci    return parcel.WriteDoubleVector(vectorTest);
17573f4cbf05Sopenharmony_ci}
17583f4cbf05Sopenharmony_ci
17593f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<std::string> &vectorTest)
17603f4cbf05Sopenharmony_ci{
17613f4cbf05Sopenharmony_ci    return parcel.WriteStringVector(vectorTest);
17623f4cbf05Sopenharmony_ci}
17633f4cbf05Sopenharmony_ci
17643f4cbf05Sopenharmony_cibool CallWriteVector(Parcel &parcel, const std::vector<std::u16string> &vectorTest)
17653f4cbf05Sopenharmony_ci{
17663f4cbf05Sopenharmony_ci    return parcel.WriteString16Vector(vectorTest);
17673f4cbf05Sopenharmony_ci}
17683f4cbf05Sopenharmony_ci
17693f4cbf05Sopenharmony_citemplate <typename T>
17703f4cbf05Sopenharmony_civoid ParcelWriteVector(const std::vector<T> &vectorTest)
17713f4cbf05Sopenharmony_ci{
17723f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
17733f4cbf05Sopenharmony_ci    Parcel parcel2(nullptr);
17743f4cbf05Sopenharmony_ci    bool result = CallWriteVector(parcel1, vectorTest);
17753f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
17763f4cbf05Sopenharmony_ci
17773f4cbf05Sopenharmony_ci    void *buffer = nullptr;
17783f4cbf05Sopenharmony_ci    size_t size = parcel1.GetDataSize();
17793f4cbf05Sopenharmony_ci    if (!SendData(buffer, size, reinterpret_cast<const uint8_t *>(parcel1.GetData()))) {
17803f4cbf05Sopenharmony_ci        ASSERT_FALSE(false);
17813f4cbf05Sopenharmony_ci    }
17823f4cbf05Sopenharmony_ci    result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(buffer), parcel1.GetDataSize());
17833f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
17843f4cbf05Sopenharmony_ci
17853f4cbf05Sopenharmony_ci    result = CallWriteVector(parcel2, vectorTest);
17863f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
17873f4cbf05Sopenharmony_ci}
17883f4cbf05Sopenharmony_ci
17893f4cbf05Sopenharmony_ci/**
17903f4cbf05Sopenharmony_ci * @tc.name: test_parcel_WriteAndReadVector_005
17913f4cbf05Sopenharmony_ci * @tc.desc: test vector parcel write failed.
17923f4cbf05Sopenharmony_ci * @tc.type: FUNC
17933f4cbf05Sopenharmony_ci */
17943f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_WriteAndReadVector_005, TestSize.Level0)
17953f4cbf05Sopenharmony_ci{
17963f4cbf05Sopenharmony_ci    vector<bool> boolVectorTest { true, false };
17973f4cbf05Sopenharmony_ci    vector<int8_t> int8VectorTest { 1, 0 };
17983f4cbf05Sopenharmony_ci    vector<int16_t> int16VectorTest { 1, 0 };
17993f4cbf05Sopenharmony_ci    vector<int32_t> int32VectorTest { 1, 0 };
18003f4cbf05Sopenharmony_ci    vector<int64_t> int64VectorTest { 1, 0 };
18013f4cbf05Sopenharmony_ci    vector<uint8_t> uint8VectorTest { 1, 0 };
18023f4cbf05Sopenharmony_ci    vector<uint16_t> uint16VectorTest { 1, 0 };
18033f4cbf05Sopenharmony_ci    vector<uint32_t> uint32VectorTest { 1, 0 };
18043f4cbf05Sopenharmony_ci    vector<uint64_t> uint64VectorTest { 1, 0 };
18053f4cbf05Sopenharmony_ci    vector<float> floatVectorTest { 1.1, 0 };
18063f4cbf05Sopenharmony_ci    vector<double> doubleVectorTest { 1.1, 0 };
18073f4cbf05Sopenharmony_ci    vector<std::string> stringVectorTest { "true", "false" };
18083f4cbf05Sopenharmony_ci    vector<std::u16string> string16VectorTest { u"true", u"false" };
18093f4cbf05Sopenharmony_ci
18103f4cbf05Sopenharmony_ci    ParcelWriteVector(boolVectorTest);
18113f4cbf05Sopenharmony_ci    ParcelWriteVector(int8VectorTest);
18123f4cbf05Sopenharmony_ci    ParcelWriteVector(int16VectorTest);
18133f4cbf05Sopenharmony_ci    ParcelWriteVector(int32VectorTest);
18143f4cbf05Sopenharmony_ci    ParcelWriteVector(int64VectorTest);
18153f4cbf05Sopenharmony_ci    ParcelWriteVector(uint8VectorTest);
18163f4cbf05Sopenharmony_ci    ParcelWriteVector(uint16VectorTest);
18173f4cbf05Sopenharmony_ci    ParcelWriteVector(uint32VectorTest);
18183f4cbf05Sopenharmony_ci    ParcelWriteVector(uint64VectorTest);
18193f4cbf05Sopenharmony_ci    ParcelWriteVector(floatVectorTest);
18203f4cbf05Sopenharmony_ci    ParcelWriteVector(doubleVectorTest);
18213f4cbf05Sopenharmony_ci    ParcelWriteVector(stringVectorTest);
18223f4cbf05Sopenharmony_ci    ParcelWriteVector(string16VectorTest);
18233f4cbf05Sopenharmony_ci}
18243f4cbf05Sopenharmony_ci
18253f4cbf05Sopenharmony_ciclass TestParcelable : public virtual Parcelable {
18263f4cbf05Sopenharmony_cipublic:
18273f4cbf05Sopenharmony_ci    TestParcelable() = default;
18283f4cbf05Sopenharmony_ci    ~TestParcelable() = default;
18293f4cbf05Sopenharmony_ci
18303f4cbf05Sopenharmony_ci    bool Marshalling(Parcel &parcel) const override;
18313f4cbf05Sopenharmony_ci    static TestParcelable *Unmarshalling(Parcel &parcel);
18323f4cbf05Sopenharmony_ci
18333f4cbf05Sopenharmony_cipublic:
18343f4cbf05Sopenharmony_ci    int32_t int32Write_ = -0x12345678;
18353f4cbf05Sopenharmony_ci    int32_t int32Read_;
18363f4cbf05Sopenharmony_ci};
18373f4cbf05Sopenharmony_ci
18383f4cbf05Sopenharmony_cibool TestParcelable::Marshalling(Parcel &parcel) const
18393f4cbf05Sopenharmony_ci{
18403f4cbf05Sopenharmony_ci    bool result = parcel.WriteInt32(this->int32Write_);
18413f4cbf05Sopenharmony_ci    return result;
18423f4cbf05Sopenharmony_ci}
18433f4cbf05Sopenharmony_ci
18443f4cbf05Sopenharmony_ciTestParcelable *TestParcelable::Unmarshalling(Parcel &parcel)
18453f4cbf05Sopenharmony_ci{
18463f4cbf05Sopenharmony_ci    auto *read = new TestParcelable();
18473f4cbf05Sopenharmony_ci    read->int32Read_ = parcel.ReadInt32();
18483f4cbf05Sopenharmony_ci    return read;
18493f4cbf05Sopenharmony_ci}
18503f4cbf05Sopenharmony_ci
18513f4cbf05Sopenharmony_ci/**
18523f4cbf05Sopenharmony_ci * @tc.name: test_parcel_parcelable_001
18533f4cbf05Sopenharmony_ci * @tc.desc: test parcel read and write parcelable obj.
18543f4cbf05Sopenharmony_ci * @tc.type: FUNC
18553f4cbf05Sopenharmony_ci */
18563f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_parcelable_001, TestSize.Level0)
18573f4cbf05Sopenharmony_ci{
18583f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
18593f4cbf05Sopenharmony_ci    sptr<TestParcelable> parcelableWrite = new TestParcelable();
18603f4cbf05Sopenharmony_ci    bool result = false;
18613f4cbf05Sopenharmony_ci
18623f4cbf05Sopenharmony_ci    result = parcel.WriteParcelable(parcelableWrite);
18633f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
18643f4cbf05Sopenharmony_ci    EXPECT_EQ(parcel.GetWritePosition(), parcel.GetDataSize());
18653f4cbf05Sopenharmony_ci
18663f4cbf05Sopenharmony_ci    sptr<TestParcelable> parcelableRead = parcel.ReadParcelable<TestParcelable>();
18673f4cbf05Sopenharmony_ci    EXPECT_EQ(parcelableWrite->int32Write_, parcelableRead->int32Read_);
18683f4cbf05Sopenharmony_ci    EXPECT_EQ(parcel.GetReadPosition(), parcel.GetDataSize());
18693f4cbf05Sopenharmony_ci}
18703f4cbf05Sopenharmony_ci
18713f4cbf05Sopenharmony_ci/**
18723f4cbf05Sopenharmony_ci * @tc.name: test_parcel_parcelable_002
18733f4cbf05Sopenharmony_ci * @tc.desc: test parcel read and write parcelable obj.
18743f4cbf05Sopenharmony_ci * @tc.type: FUNC
18753f4cbf05Sopenharmony_ci */
18763f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_parcelable_002, TestSize.Level0)
18773f4cbf05Sopenharmony_ci{
18783f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
18793f4cbf05Sopenharmony_ci
18803f4cbf05Sopenharmony_ci    bool result = parcel.WriteParcelable(nullptr);
18813f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
18823f4cbf05Sopenharmony_ci
18833f4cbf05Sopenharmony_ci    sptr<TestParcelable> parcelableRead = parcel.ReadParcelable<TestParcelable>();
18843f4cbf05Sopenharmony_ci    EXPECT_EQ(nullptr, parcelableRead);
18853f4cbf05Sopenharmony_ci}
18863f4cbf05Sopenharmony_ci
18873f4cbf05Sopenharmony_ci/**
18883f4cbf05Sopenharmony_ci * @tc.name: test_parcel_parcelable_003
18893f4cbf05Sopenharmony_ci * @tc.desc: test parcel read and write parcelable obj.
18903f4cbf05Sopenharmony_ci * @tc.type: FUNC
18913f4cbf05Sopenharmony_ci */
18923f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_parcel_parcelable_003, TestSize.Level0)
18933f4cbf05Sopenharmony_ci{
18943f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
18953f4cbf05Sopenharmony_ci    sptr<TestParcelable> parcelableWriteNull;
18963f4cbf05Sopenharmony_ci    bool result = parcel.WriteStrongParcelable(parcelableWriteNull);
18973f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
18983f4cbf05Sopenharmony_ci
18993f4cbf05Sopenharmony_ci    sptr<TestParcelable> parcelableWrite = new TestParcelable();
19003f4cbf05Sopenharmony_ci
19013f4cbf05Sopenharmony_ci    bool test = parcelableWrite->TestBehavior(Parcelable::BehaviorFlag::HOLD_OBJECT);
19023f4cbf05Sopenharmony_ci    EXPECT_EQ(false, test);
19033f4cbf05Sopenharmony_ci    test = parcelableWrite->TestBehavior(Parcelable::BehaviorFlag::IPC);
19043f4cbf05Sopenharmony_ci    EXPECT_EQ(false, test);
19053f4cbf05Sopenharmony_ci    test = parcelableWrite->TestBehavior(Parcelable::BehaviorFlag::RPC);
19063f4cbf05Sopenharmony_ci    EXPECT_EQ(false, test);
19073f4cbf05Sopenharmony_ci
19083f4cbf05Sopenharmony_ci    result = parcel.WriteStrongParcelable(parcelableWrite);
19093f4cbf05Sopenharmony_ci    EXPECT_EQ(true, result);
19103f4cbf05Sopenharmony_ci
19113f4cbf05Sopenharmony_ci    sptr<TestParcelable> parcelableReadNull = parcel.ReadParcelable<TestParcelable>();
19123f4cbf05Sopenharmony_ci    EXPECT_EQ(nullptr, parcelableReadNull);
19133f4cbf05Sopenharmony_ci
19143f4cbf05Sopenharmony_ci    sptr<TestParcelable> parcelableRead = parcel.ReadParcelable<TestParcelable>();
19153f4cbf05Sopenharmony_ci    EXPECT_EQ(parcelableWrite->int32Write_, parcelableRead->int32Read_);
19163f4cbf05Sopenharmony_ci
19173f4cbf05Sopenharmony_ci    test = parcelableWrite->TestBehavior(Parcelable::BehaviorFlag::HOLD_OBJECT);
19183f4cbf05Sopenharmony_ci    EXPECT_EQ(true, test);
19193f4cbf05Sopenharmony_ci    test = parcelableWrite->TestBehavior(Parcelable::BehaviorFlag::IPC);
19203f4cbf05Sopenharmony_ci    EXPECT_EQ(false, test);
19213f4cbf05Sopenharmony_ci    test = parcelableWrite->TestBehavior(Parcelable::BehaviorFlag::RPC);
19223f4cbf05Sopenharmony_ci    EXPECT_EQ(false, test);
19233f4cbf05Sopenharmony_ci
19243f4cbf05Sopenharmony_ci    parcelableWrite->ClearBehavior(Parcelable::BehaviorFlag::HOLD_OBJECT);
19253f4cbf05Sopenharmony_ci    test = parcelableWrite->TestBehavior(Parcelable::BehaviorFlag::HOLD_OBJECT);
19263f4cbf05Sopenharmony_ci    EXPECT_EQ(false, test);
19273f4cbf05Sopenharmony_ci}
19283f4cbf05Sopenharmony_ci
19293f4cbf05Sopenharmony_ci/**
19303f4cbf05Sopenharmony_ci * @tc.name: test_SetMaxCapacity_001
19313f4cbf05Sopenharmony_ci * @tc.desc: test parcel capacity function.
19323f4cbf05Sopenharmony_ci * @tc.type: FUNC
19333f4cbf05Sopenharmony_ci */
19343f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_SetMaxCapacity_001, TestSize.Level0)
19353f4cbf05Sopenharmony_ci{
19363f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
19373f4cbf05Sopenharmony_ci    char test[48] = {0};
19383f4cbf05Sopenharmony_ci    bool ret = parcel.WriteBuffer(test, 48);
19393f4cbf05Sopenharmony_ci    EXPECT_EQ(true, ret);
19403f4cbf05Sopenharmony_ci    // because default maxCap is 200 * 1024, so reset it more
19413f4cbf05Sopenharmony_ci    parcel.SetMaxCapacity(201 * 1024);
19423f4cbf05Sopenharmony_ci    // test write data over max capacity: 205780 + 48 > 201 * 1024
19433f4cbf05Sopenharmony_ci    char test2[205780] = {0};
19443f4cbf05Sopenharmony_ci    ret = parcel.WriteBuffer(test2, 205780);
19453f4cbf05Sopenharmony_ci    EXPECT_EQ(false, ret);
19463f4cbf05Sopenharmony_ci}
19473f4cbf05Sopenharmony_ci
19483f4cbf05Sopenharmony_ci/**
19493f4cbf05Sopenharmony_ci * @tc.name: test_SetMaxCapacity_002
19503f4cbf05Sopenharmony_ci * @tc.desc: test parcel capacity function.
19513f4cbf05Sopenharmony_ci * @tc.type: FUNC
19523f4cbf05Sopenharmony_ci */
19533f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_SetMaxCapacity_002, TestSize.Level0)
19543f4cbf05Sopenharmony_ci{
19553f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
19563f4cbf05Sopenharmony_ci    char test[48] = {0};
19573f4cbf05Sopenharmony_ci    bool ret = parcel.WriteInt32(5767168);
19583f4cbf05Sopenharmony_ci    EXPECT_EQ(true, ret);
19593f4cbf05Sopenharmony_ci    ret = parcel.WriteBuffer(test, 48);
19603f4cbf05Sopenharmony_ci    EXPECT_EQ(true, ret);
19613f4cbf05Sopenharmony_ci    vector<std::u16string> val;
19623f4cbf05Sopenharmony_ci    ret = parcel.ReadString16Vector(&val);
19633f4cbf05Sopenharmony_ci    EXPECT_EQ(false, ret);
19643f4cbf05Sopenharmony_ci}
19653f4cbf05Sopenharmony_ci
19663f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_ValidateReadData_001, TestSize.Level0)
19673f4cbf05Sopenharmony_ci{
19683f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
19693f4cbf05Sopenharmony_ci    parcel.WriteBool(true);
19703f4cbf05Sopenharmony_ci    string strWrite = "test";
19713f4cbf05Sopenharmony_ci    bool result = parcel.WriteString(strWrite);
19723f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
19733f4cbf05Sopenharmony_ci
19743f4cbf05Sopenharmony_ci    RemoteObject obj1;
19753f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj1);
19763f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
19773f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
19783f4cbf05Sopenharmony_ci    RemoteObject obj2;
19793f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj2);
19803f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
19813f4cbf05Sopenharmony_ci    u16string str16Write = u"12345";
19823f4cbf05Sopenharmony_ci    result = parcel.WriteString16(str16Write);
19833f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
19843f4cbf05Sopenharmony_ci
19853f4cbf05Sopenharmony_ci    bool readBool = parcel.ReadBool();
19863f4cbf05Sopenharmony_ci    EXPECT_EQ(readBool, true);
19873f4cbf05Sopenharmony_ci
19883f4cbf05Sopenharmony_ci    string strRead = parcel.ReadString();
19893f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead.c_str(), strWrite.c_str()));
19903f4cbf05Sopenharmony_ci
19913f4cbf05Sopenharmony_ci    sptr<RemoteObject> readObj1 = parcel.ReadObject<RemoteObject>();
19923f4cbf05Sopenharmony_ci    EXPECT_EQ(true, readObj1.GetRefPtr() != nullptr);
19933f4cbf05Sopenharmony_ci
19943f4cbf05Sopenharmony_ci    int32_t readInt32 = parcel.ReadInt32();
19953f4cbf05Sopenharmony_ci    EXPECT_EQ(readInt32, 5);
19963f4cbf05Sopenharmony_ci
19973f4cbf05Sopenharmony_ci    sptr<RemoteObject> readObj2 = parcel.ReadObject<RemoteObject>();
19983f4cbf05Sopenharmony_ci    EXPECT_EQ(true, readObj2.GetRefPtr() != nullptr);
19993f4cbf05Sopenharmony_ci
20003f4cbf05Sopenharmony_ci    u16string str16Read = parcel.ReadString16();
20013f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16Read.compare(str16Write));
20023f4cbf05Sopenharmony_ci}
20033f4cbf05Sopenharmony_ci
20043f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_ValidateReadData_002, TestSize.Level0)
20053f4cbf05Sopenharmony_ci{
20063f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
20073f4cbf05Sopenharmony_ci    parcel.WriteBool(true);
20083f4cbf05Sopenharmony_ci    string strWrite = "test";
20093f4cbf05Sopenharmony_ci    bool result = parcel.WriteString(strWrite);
20103f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20113f4cbf05Sopenharmony_ci
20123f4cbf05Sopenharmony_ci    RemoteObject obj1;
20133f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj1);
20143f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20153f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
20163f4cbf05Sopenharmony_ci    RemoteObject obj2;
20173f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj2);
20183f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20193f4cbf05Sopenharmony_ci    u16string str16Write = u"12345";
20203f4cbf05Sopenharmony_ci    result = parcel.WriteString16(str16Write);
20213f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20223f4cbf05Sopenharmony_ci
20233f4cbf05Sopenharmony_ci    bool readBool = parcel.ReadBool();
20243f4cbf05Sopenharmony_ci    EXPECT_EQ(readBool, true);
20253f4cbf05Sopenharmony_ci
20263f4cbf05Sopenharmony_ci    string strRead = parcel.ReadString();
20273f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead.c_str(), strWrite.c_str()));
20283f4cbf05Sopenharmony_ci
20293f4cbf05Sopenharmony_ci    int32_t readInt32 = parcel.ReadInt32();
20303f4cbf05Sopenharmony_ci    EXPECT_EQ(readInt32, 0);
20313f4cbf05Sopenharmony_ci
20323f4cbf05Sopenharmony_ci    u16string str16Read = parcel.ReadString16();
20333f4cbf05Sopenharmony_ci    EXPECT_EQ(0, str16Read.compare(std::u16string()));
20343f4cbf05Sopenharmony_ci
20353f4cbf05Sopenharmony_ci    sptr<RemoteObject> readObj1 = parcel.ReadObject<RemoteObject>();
20363f4cbf05Sopenharmony_ci    EXPECT_EQ(true, readObj1.GetRefPtr() == nullptr);
20373f4cbf05Sopenharmony_ci}
20383f4cbf05Sopenharmony_ci
20393f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_multiRemoteObjectReadBuffer_001, TestSize.Level0)
20403f4cbf05Sopenharmony_ci{
20413f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
20423f4cbf05Sopenharmony_ci
20433f4cbf05Sopenharmony_ci    RemoteFdObject obj1;
20443f4cbf05Sopenharmony_ci    bool result = parcel.WriteRemoteObject(&obj1);
20453f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20463f4cbf05Sopenharmony_ci
20473f4cbf05Sopenharmony_ci    RemoteHandleObject obj2;
20483f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj2);
20493f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20503f4cbf05Sopenharmony_ci
20513f4cbf05Sopenharmony_ci    RemoteObject obj3;
20523f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj3);
20533f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20543f4cbf05Sopenharmony_ci
20553f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(sizeof(parcel_flat_binder_object) * 3);
20563f4cbf05Sopenharmony_ci    EXPECT_EQ(true, buffer == nullptr);
20573f4cbf05Sopenharmony_ci}
20583f4cbf05Sopenharmony_ci
20593f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_multiRemoteObjectReadBuffer_002, TestSize.Level0)
20603f4cbf05Sopenharmony_ci{
20613f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
20623f4cbf05Sopenharmony_ci
20633f4cbf05Sopenharmony_ci    RemoteFdObject obj1;
20643f4cbf05Sopenharmony_ci    bool result = parcel.WriteRemoteObject(&obj1);
20653f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20663f4cbf05Sopenharmony_ci
20673f4cbf05Sopenharmony_ci    RemoteObject obj2;
20683f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj2);
20693f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20703f4cbf05Sopenharmony_ci
20713f4cbf05Sopenharmony_ci    RemoteHandleObject obj3;
20723f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj3);
20733f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20743f4cbf05Sopenharmony_ci
20753f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(sizeof(parcel_flat_binder_object) * 3);
20763f4cbf05Sopenharmony_ci    EXPECT_EQ(true, buffer == nullptr);
20773f4cbf05Sopenharmony_ci}
20783f4cbf05Sopenharmony_ci
20793f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_multiRemoteObjectReadBuffer_003, TestSize.Level0)
20803f4cbf05Sopenharmony_ci{
20813f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
20823f4cbf05Sopenharmony_ci
20833f4cbf05Sopenharmony_ci    RemoteObject obj1;
20843f4cbf05Sopenharmony_ci    bool result = parcel.WriteRemoteObject(&obj1);
20853f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20863f4cbf05Sopenharmony_ci
20873f4cbf05Sopenharmony_ci    RemoteHandleObject obj2;
20883f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj2);
20893f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20903f4cbf05Sopenharmony_ci
20913f4cbf05Sopenharmony_ci    RemoteFdObject obj3;
20923f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj3);
20933f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
20943f4cbf05Sopenharmony_ci
20953f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(sizeof(parcel_flat_binder_object) * 3);
20963f4cbf05Sopenharmony_ci    EXPECT_EQ(true, buffer == nullptr);
20973f4cbf05Sopenharmony_ci}
20983f4cbf05Sopenharmony_ci
20993f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_multiRemoteObjectReadBuffer_004, TestSize.Level0)
21003f4cbf05Sopenharmony_ci{
21013f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
21023f4cbf05Sopenharmony_ci
21033f4cbf05Sopenharmony_ci    RemoteFdObject obj1;
21043f4cbf05Sopenharmony_ci    bool result = parcel.WriteRemoteObject(&obj1);
21053f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21063f4cbf05Sopenharmony_ci
21073f4cbf05Sopenharmony_ci    RemoteHandleObject obj2;
21083f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj2);
21093f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21103f4cbf05Sopenharmony_ci
21113f4cbf05Sopenharmony_ci    RemoteFdObject obj3;
21123f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj3);
21133f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21143f4cbf05Sopenharmony_ci
21153f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(sizeof(parcel_flat_binder_object) * 3);
21163f4cbf05Sopenharmony_ci    EXPECT_EQ(true, buffer != nullptr);
21173f4cbf05Sopenharmony_ci}
21183f4cbf05Sopenharmony_ci
21193f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_multiRemoteObjectReadBuffer_005, TestSize.Level0)
21203f4cbf05Sopenharmony_ci{
21213f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
21223f4cbf05Sopenharmony_ci
21233f4cbf05Sopenharmony_ci    RemoteFdObject obj1;
21243f4cbf05Sopenharmony_ci    bool result = parcel.WriteRemoteObject(&obj1);
21253f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21263f4cbf05Sopenharmony_ci
21273f4cbf05Sopenharmony_ci    RemoteObject obj2;
21283f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj2);
21293f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21303f4cbf05Sopenharmony_ci
21313f4cbf05Sopenharmony_ci    RemoteHandleObject obj3;
21323f4cbf05Sopenharmony_ci    result = parcel.WriteRemoteObject(&obj3);
21333f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21343f4cbf05Sopenharmony_ci
21353f4cbf05Sopenharmony_ci    size_t readLength = 36;
21363f4cbf05Sopenharmony_ci    const uint8_t *buffer = parcel.ReadBuffer(readLength);
21373f4cbf05Sopenharmony_ci    EXPECT_EQ(true, buffer == nullptr);
21383f4cbf05Sopenharmony_ci}
21393f4cbf05Sopenharmony_ci
21403f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_RewindWrite_001, TestSize.Level0)
21413f4cbf05Sopenharmony_ci{
21423f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
21433f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
21443f4cbf05Sopenharmony_ci    string strWrite = "test";
21453f4cbf05Sopenharmony_ci    parcel.WriteString(strWrite);
21463f4cbf05Sopenharmony_ci    RemoteObject obj1;
21473f4cbf05Sopenharmony_ci    parcel.WriteRemoteObject(&obj1);
21483f4cbf05Sopenharmony_ci    size_t pos = parcel.GetWritePosition();
21493f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
21503f4cbf05Sopenharmony_ci    RemoteObject obj2;
21513f4cbf05Sopenharmony_ci    parcel.WriteRemoteObject(&obj2);
21523f4cbf05Sopenharmony_ci    u16string str16Write = u"12345";
21533f4cbf05Sopenharmony_ci    parcel.WriteString16(str16Write);
21543f4cbf05Sopenharmony_ci
21553f4cbf05Sopenharmony_ci    bool result = parcel.RewindWrite(pos);
21563f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21573f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
21583f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
21593f4cbf05Sopenharmony_ci
21603f4cbf05Sopenharmony_ci    int32_t readint32 = parcel.ReadInt32();
21613f4cbf05Sopenharmony_ci    EXPECT_EQ(readint32, 5);
21623f4cbf05Sopenharmony_ci    string strRead = parcel.ReadString();
21633f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead.c_str(), strWrite.c_str()));
21643f4cbf05Sopenharmony_ci    sptr<RemoteObject> readObj1 = parcel.ReadObject<RemoteObject>();
21653f4cbf05Sopenharmony_ci    EXPECT_EQ(true, readObj1.GetRefPtr() != nullptr);
21663f4cbf05Sopenharmony_ci    readint32 = parcel.ReadInt32();
21673f4cbf05Sopenharmony_ci    EXPECT_EQ(readint32, 5);
21683f4cbf05Sopenharmony_ci    sptr<RemoteObject> readObj2 = parcel.ReadObject<RemoteObject>();
21693f4cbf05Sopenharmony_ci    EXPECT_EQ(true, readObj2.GetRefPtr() == nullptr);
21703f4cbf05Sopenharmony_ci    readint32 = parcel.ReadInt32();
21713f4cbf05Sopenharmony_ci    EXPECT_EQ(readint32, 5);
21723f4cbf05Sopenharmony_ci}
21733f4cbf05Sopenharmony_ci
21743f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_RewindWrite_002, TestSize.Level0)
21753f4cbf05Sopenharmony_ci{
21763f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
21773f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
21783f4cbf05Sopenharmony_ci    string strWrite = "test";
21793f4cbf05Sopenharmony_ci    parcel.WriteString(strWrite);
21803f4cbf05Sopenharmony_ci    RemoteObject obj1;
21813f4cbf05Sopenharmony_ci    parcel.WriteRemoteObject(&obj1);
21823f4cbf05Sopenharmony_ci    parcel.WriteInt32(5);
21833f4cbf05Sopenharmony_ci    RemoteObject obj2;
21843f4cbf05Sopenharmony_ci    parcel.WriteRemoteObject(&obj2);
21853f4cbf05Sopenharmony_ci    size_t pos = parcel.GetWritePosition();
21863f4cbf05Sopenharmony_ci    u16string str16Write = u"12345";
21873f4cbf05Sopenharmony_ci    parcel.WriteString16(str16Write);
21883f4cbf05Sopenharmony_ci
21893f4cbf05Sopenharmony_ci    bool result = parcel.RewindWrite(pos);
21903f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
21913f4cbf05Sopenharmony_ci
21923f4cbf05Sopenharmony_ci    int32_t readint32 = parcel.ReadInt32();
21933f4cbf05Sopenharmony_ci    EXPECT_EQ(readint32, 5);
21943f4cbf05Sopenharmony_ci    string strRead = parcel.ReadString();
21953f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strcmp(strRead.c_str(), strWrite.c_str()));
21963f4cbf05Sopenharmony_ci    uint32_t readUint32 = parcel.ReadUint32();
21973f4cbf05Sopenharmony_ci    EXPECT_EQ(readUint32, 0);
21983f4cbf05Sopenharmony_ci    string strRead2 = parcel.ReadString();
21993f4cbf05Sopenharmony_ci    EXPECT_EQ(0, strRead2.compare(std::string()));
22003f4cbf05Sopenharmony_ci    sptr<RemoteObject> readObj1 = parcel.ReadObject<RemoteObject>();
22013f4cbf05Sopenharmony_ci    EXPECT_EQ(true, readObj1.GetRefPtr() == nullptr);
22023f4cbf05Sopenharmony_ci    double readDouble = parcel.ReadDouble();
22033f4cbf05Sopenharmony_ci    EXPECT_EQ(readDouble, 0);
22043f4cbf05Sopenharmony_ci}
22053f4cbf05Sopenharmony_ci
22063f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_RewindWrite_003, TestSize.Level0)
22073f4cbf05Sopenharmony_ci{
22083f4cbf05Sopenharmony_ci    Parcel parcel(nullptr);
22093f4cbf05Sopenharmony_ci    std::vector<int32_t> val{1, 2, 3, 4, 5};
22103f4cbf05Sopenharmony_ci    EXPECT_EQ(val.size(), 5);
22113f4cbf05Sopenharmony_ci    bool result = parcel.WriteInt32Vector(val);
22123f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22133f4cbf05Sopenharmony_ci    size_t pos = parcel.GetWritePosition() - sizeof(int32_t);
22143f4cbf05Sopenharmony_ci    result = parcel.RewindWrite(pos);
22153f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22163f4cbf05Sopenharmony_ci    RemoteObject obj;
22173f4cbf05Sopenharmony_ci    parcel.WriteRemoteObject(&obj);
22183f4cbf05Sopenharmony_ci
22193f4cbf05Sopenharmony_ci    std::vector<int32_t> int32Read;
22203f4cbf05Sopenharmony_ci    result = parcel.ReadInt32Vector(&int32Read);
22213f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
22223f4cbf05Sopenharmony_ci    EXPECT_EQ(int32Read.size(), 5);
22233f4cbf05Sopenharmony_ci    EXPECT_EQ(int32Read[0], 1);
22243f4cbf05Sopenharmony_ci    EXPECT_EQ(int32Read[1], 2);
22253f4cbf05Sopenharmony_ci    EXPECT_EQ(int32Read[2], 3);
22263f4cbf05Sopenharmony_ci    EXPECT_EQ(int32Read[3], 4);
22273f4cbf05Sopenharmony_ci    EXPECT_EQ(int32Read[4], 0);
22283f4cbf05Sopenharmony_ci}
22293f4cbf05Sopenharmony_ci
22303f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_VectorDataPadding_001, TestSize.Level0)
22313f4cbf05Sopenharmony_ci{
22323f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
22333f4cbf05Sopenharmony_ci    std::vector<bool> val1(121, true);
22343f4cbf05Sopenharmony_ci    bool result = parcel1.WriteBoolVector(val1);
22353f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22363f4cbf05Sopenharmony_ci
22373f4cbf05Sopenharmony_ci    int32_t targetVal = 123;
22383f4cbf05Sopenharmony_ci    parcel1.WriteInt32(targetVal);
22393f4cbf05Sopenharmony_ci
22403f4cbf05Sopenharmony_ci    std::vector<bool> val2;
22413f4cbf05Sopenharmony_ci    result = parcel1.ReadBoolVector(&val2);
22423f4cbf05Sopenharmony_ci    int32_t target = parcel1.ReadInt32();
22433f4cbf05Sopenharmony_ci    EXPECT_EQ(target, targetVal);
22443f4cbf05Sopenharmony_ci}
22453f4cbf05Sopenharmony_ci
22463f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_VectorDataPadding_002, TestSize.Level0)
22473f4cbf05Sopenharmony_ci{
22483f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
22493f4cbf05Sopenharmony_ci    std::vector<bool> val1(15, true);
22503f4cbf05Sopenharmony_ci    bool result = parcel1.WriteBoolVector(val1);
22513f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22523f4cbf05Sopenharmony_ci
22533f4cbf05Sopenharmony_ci    std::vector<bool> val2(16, true);
22543f4cbf05Sopenharmony_ci    result = parcel1.WriteBoolVector(val2);
22553f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22563f4cbf05Sopenharmony_ci
22573f4cbf05Sopenharmony_ci    std::vector<bool> val3;
22583f4cbf05Sopenharmony_ci    result = parcel1.ReadBoolVector(&val3);
22593f4cbf05Sopenharmony_ci    for (int i = 0; i < val1.size(); i++) {
22603f4cbf05Sopenharmony_ci        EXPECT_EQ(val1[i], val3[i]);
22613f4cbf05Sopenharmony_ci    }
22623f4cbf05Sopenharmony_ci
22633f4cbf05Sopenharmony_ci    std::vector<bool> val4;
22643f4cbf05Sopenharmony_ci    result = parcel1.ReadBoolVector(&val4);
22653f4cbf05Sopenharmony_ci    for (int i = 0; i < val2.size(); i++) {
22663f4cbf05Sopenharmony_ci        EXPECT_EQ(val2[i], val4[i]);
22673f4cbf05Sopenharmony_ci    }
22683f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
22693f4cbf05Sopenharmony_ci
22703f4cbf05Sopenharmony_ci    result = parcel1.WriteBoolVector(val2);
22713f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22723f4cbf05Sopenharmony_ci    result = parcel1.WriteBoolVector(val1);
22733f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22743f4cbf05Sopenharmony_ci
22753f4cbf05Sopenharmony_ci    std::vector<bool> val5;
22763f4cbf05Sopenharmony_ci    result = parcel1.ReadBoolVector(&val5);
22773f4cbf05Sopenharmony_ci    for (int i = 0; i < val2.size(); i++) {
22783f4cbf05Sopenharmony_ci        EXPECT_EQ(val2[i], val5[i]);
22793f4cbf05Sopenharmony_ci    }
22803f4cbf05Sopenharmony_ci
22813f4cbf05Sopenharmony_ci    std::vector<bool> val6;
22823f4cbf05Sopenharmony_ci    result = parcel1.ReadBoolVector(&val6);
22833f4cbf05Sopenharmony_ci    for (int i = 0; i < val1.size(); i++) {
22843f4cbf05Sopenharmony_ci        EXPECT_EQ(val1[i], val6[i]);
22853f4cbf05Sopenharmony_ci    }
22863f4cbf05Sopenharmony_ci}
22873f4cbf05Sopenharmony_ci
22883f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_VectorDataPadding_003, TestSize.Level0)
22893f4cbf05Sopenharmony_ci{
22903f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
22913f4cbf05Sopenharmony_ci    std::vector<bool> val1(17, true);
22923f4cbf05Sopenharmony_ci    bool result = parcel1.WriteBoolVector(val1);
22933f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22943f4cbf05Sopenharmony_ci
22953f4cbf05Sopenharmony_ci    std::vector<int16_t> val2(18, 1);
22963f4cbf05Sopenharmony_ci    result = parcel1.WriteInt16Vector(val2);
22973f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
22983f4cbf05Sopenharmony_ci
22993f4cbf05Sopenharmony_ci    std::vector<bool> val3;
23003f4cbf05Sopenharmony_ci    result = parcel1.ReadBoolVector(&val3);
23013f4cbf05Sopenharmony_ci    for (int i = 0; i < val1.size(); i++) {
23023f4cbf05Sopenharmony_ci        EXPECT_EQ(val1[i], val3[i]);
23033f4cbf05Sopenharmony_ci    }
23043f4cbf05Sopenharmony_ci
23053f4cbf05Sopenharmony_ci    std::vector<int16_t> val4;
23063f4cbf05Sopenharmony_ci    result = parcel1.ReadInt16Vector(&val4);
23073f4cbf05Sopenharmony_ci    for (int i = 0; i < val2.size(); i++) {
23083f4cbf05Sopenharmony_ci        EXPECT_EQ(val2[i], val4[i]);
23093f4cbf05Sopenharmony_ci    }
23103f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
23113f4cbf05Sopenharmony_ci
23123f4cbf05Sopenharmony_ci    result = parcel1.WriteInt16Vector(val2);
23133f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
23143f4cbf05Sopenharmony_ci    result = parcel1.WriteBoolVector(val1);
23153f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
23163f4cbf05Sopenharmony_ci
23173f4cbf05Sopenharmony_ci    std::vector<int16_t> val5;
23183f4cbf05Sopenharmony_ci    result = parcel1.ReadInt16Vector(&val5);
23193f4cbf05Sopenharmony_ci    for (int i = 0; i < val2.size(); i++) {
23203f4cbf05Sopenharmony_ci        EXPECT_EQ(val2[i], val5[i]);
23213f4cbf05Sopenharmony_ci    }
23223f4cbf05Sopenharmony_ci
23233f4cbf05Sopenharmony_ci    std::vector<bool> val6;
23243f4cbf05Sopenharmony_ci    result = parcel1.ReadBoolVector(&val6);
23253f4cbf05Sopenharmony_ci    for (int i = 0; i < val1.size(); i++) {
23263f4cbf05Sopenharmony_ci        EXPECT_EQ(val1[i], val6[i]);
23273f4cbf05Sopenharmony_ci    }
23283f4cbf05Sopenharmony_ci}
23293f4cbf05Sopenharmony_ci
23303f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_VectorDataPadding_004, TestSize.Level0)
23313f4cbf05Sopenharmony_ci{
23323f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
23333f4cbf05Sopenharmony_ci    std::vector<int16_t> val1(19, 1);
23343f4cbf05Sopenharmony_ci    bool result = parcel1.WriteInt16Vector(val1);
23353f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
23363f4cbf05Sopenharmony_ci
23373f4cbf05Sopenharmony_ci    std::vector<int16_t> val2(20, 1);
23383f4cbf05Sopenharmony_ci    result = parcel1.WriteInt16Vector(val2);
23393f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
23403f4cbf05Sopenharmony_ci
23413f4cbf05Sopenharmony_ci    std::vector<int16_t> val3;
23423f4cbf05Sopenharmony_ci    result = parcel1.ReadInt16Vector(&val3);
23433f4cbf05Sopenharmony_ci    for (int i = 0; i < val1.size(); i++) {
23443f4cbf05Sopenharmony_ci        EXPECT_EQ(val1[i], val3[i]);
23453f4cbf05Sopenharmony_ci    }
23463f4cbf05Sopenharmony_ci
23473f4cbf05Sopenharmony_ci    std::vector<int16_t> val4;
23483f4cbf05Sopenharmony_ci    result = parcel1.ReadInt16Vector(&val4);
23493f4cbf05Sopenharmony_ci    for (int i = 0; i < val2.size(); i++) {
23503f4cbf05Sopenharmony_ci        EXPECT_EQ(val2[i], val4[i]);
23513f4cbf05Sopenharmony_ci    }
23523f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
23533f4cbf05Sopenharmony_ci
23543f4cbf05Sopenharmony_ci    result = parcel1.WriteInt16Vector(val2);
23553f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
23563f4cbf05Sopenharmony_ci    result = parcel1.WriteInt16Vector(val1);
23573f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
23583f4cbf05Sopenharmony_ci
23593f4cbf05Sopenharmony_ci    std::vector<int16_t> val5;
23603f4cbf05Sopenharmony_ci    result = parcel1.ReadInt16Vector(&val5);
23613f4cbf05Sopenharmony_ci    for (int i = 0; i < val2.size(); i++) {
23623f4cbf05Sopenharmony_ci        EXPECT_EQ(val2[i], val5[i]);
23633f4cbf05Sopenharmony_ci    }
23643f4cbf05Sopenharmony_ci
23653f4cbf05Sopenharmony_ci    std::vector<int16_t> val6;
23663f4cbf05Sopenharmony_ci    result = parcel1.ReadInt16Vector(&val6);
23673f4cbf05Sopenharmony_ci    for (int i = 0; i < val1.size(); i++) {
23683f4cbf05Sopenharmony_ci        EXPECT_EQ(val1[i], val6[i]);
23693f4cbf05Sopenharmony_ci    }
23703f4cbf05Sopenharmony_ci}
23713f4cbf05Sopenharmony_ci
23723f4cbf05Sopenharmony_ci#ifdef __aarch64__
23733f4cbf05Sopenharmony_ciHWTEST_F(UtilsParcelTest, test_WriteStringDataLength_001, TestSize.Level0)
23743f4cbf05Sopenharmony_ci{
23753f4cbf05Sopenharmony_ci    Parcel parcel1(nullptr);
23763f4cbf05Sopenharmony_ci
23773f4cbf05Sopenharmony_ci    std::string veryLongString(static_cast<size_t>(INT32_MAX) + 1, '#');
23783f4cbf05Sopenharmony_ci    bool result = parcel1.WriteCString(veryLongString.c_str());
23793f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
23803f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
23813f4cbf05Sopenharmony_ci
23823f4cbf05Sopenharmony_ci    result = parcel1.WriteString(veryLongString);
23833f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
23843f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
23853f4cbf05Sopenharmony_ci
23863f4cbf05Sopenharmony_ci    std::u16string veryLongStringU16(static_cast<size_t>(INT32_MAX) / 2, '#');
23873f4cbf05Sopenharmony_ci    result = parcel1.WriteString16(veryLongStringU16);
23883f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
23893f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
23903f4cbf05Sopenharmony_ci
23913f4cbf05Sopenharmony_ci    result = parcel1.WriteString16WithLength(veryLongStringU16.c_str(), static_cast<size_t>(INT32_MAX) / 2);
23923f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
23933f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
23943f4cbf05Sopenharmony_ci
23953f4cbf05Sopenharmony_ci    result = parcel1.WriteString8WithLength(veryLongString.c_str(), static_cast<size_t>(INT32_MAX) + 1);
23963f4cbf05Sopenharmony_ci    EXPECT_EQ(result, false);
23973f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
23983f4cbf05Sopenharmony_ci
23993f4cbf05Sopenharmony_ci    result = parcel1.WriteCString(veryLongString.substr(0, DEFAULT_CPACITY - 1).c_str());
24003f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
24013f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
24023f4cbf05Sopenharmony_ci
24033f4cbf05Sopenharmony_ci    result = parcel1.WriteString(veryLongString.substr(0, DEFAULT_CPACITY - 5));
24043f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
24053f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
24063f4cbf05Sopenharmony_ci
24073f4cbf05Sopenharmony_ci    result = parcel1.WriteString16(veryLongStringU16.substr(0, (DEFAULT_CPACITY - 4) / 2 - 1));
24083f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
24093f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
24103f4cbf05Sopenharmony_ci
24113f4cbf05Sopenharmony_ci    result = parcel1.WriteString16WithLength(veryLongStringU16.c_str(), (DEFAULT_CPACITY - 4) / 2 - 1);
24123f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
24133f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
24143f4cbf05Sopenharmony_ci
24153f4cbf05Sopenharmony_ci    result = parcel1.WriteString8WithLength(veryLongString.c_str(), DEFAULT_CPACITY - 5);
24163f4cbf05Sopenharmony_ci    EXPECT_EQ(result, true);
24173f4cbf05Sopenharmony_ci    parcel1.FlushBuffer();
24183f4cbf05Sopenharmony_ci}
24193f4cbf05Sopenharmony_ci#endif
24203f4cbf05Sopenharmony_ci}  // namespace
24213f4cbf05Sopenharmony_ci}  // namespace OHOS
2422