diff --git a/base/BUILD.gn b/base/BUILD.gn index 318bbe7372eb540042eee5efddd3e93d19abdf02..55e4028d04187edadf79b0926973f5014ed5e28c 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -97,7 +97,7 @@ ohos_static_library("utilsbase") { sources = sources_utils configs = [ ":utils_config" ] defines = [ "CONFIG_HILOG" ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ "hilog_native:libhilog" ] } ohos_shared_library("utils") { @@ -105,7 +105,7 @@ ohos_shared_library("utils") { configs = [ ":utils_config" ] subsystem_name = "utils" defines = [ "CONFIG_HILOG" ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ "hilog_native:libhilog" ] part_name = "utils_base" install_images = [ "system", @@ -161,14 +161,16 @@ ohos_static_library("utilsecurec") { configs = [ ":utils_config" ] } -ohos_shared_library("utilsecurec_shared") { - sources = securec_sources - configs = [ ":utils_config" ] - public_configs = [ ":utils_config" ] - part_name = "utils_base" - install_images = [ - "system", - "updater", - ] +if (build_public_version) { + ohos_shared_library("utilsecurec_shared") { + sources = securec_sources + configs = [ ":utils_config" ] + public_configs = [ ":utils_config" ] + part_name = "utils_base" + install_images = [ + "system", + "updater", + ] + } } ############################################################################### diff --git a/base/include/parcel.h b/base/include/parcel.h index 3211a36ae30e979735a0175d27834f7cf86689b4..331c94717983f02f81e140337ea0481058e9ae9a 100755 --- a/base/include/parcel.h +++ b/base/include/parcel.h @@ -148,6 +148,8 @@ public: bool WriteString16WithLength(const char16_t *value, size_t len); + bool WriteString8WithLength(const char *value, size_t len); + bool WriteParcelable(const Parcelable *object); bool WriteStrongParcelable(const sptr &object); @@ -223,6 +225,8 @@ public: const std::u16string ReadString16WithLength(int32_t &len); + const std::string ReadString8WithLength(int32_t &len); + bool RewindRead(size_t newPosition); bool RewindWrite(size_t offsets); diff --git a/base/src/ashmem.cpp b/base/src/ashmem.cpp index c5d4e69f78e1b41b0ab372c9fff02e6bad9460bf..6b6925484a4d7442c47ceeedf46343a9b21a89d4 100755 --- a/base/src/ashmem.cpp +++ b/base/src/ashmem.cpp @@ -68,20 +68,20 @@ static int AshmemOpenLocked() } if (fd < 0) { - UTILS_LOGE("fd is invalid"); + UTILS_LOGE("%{public}s: fd is invalid, fd = %{public}d", __func__, fd); return fd; } struct stat st; int ret = TEMP_FAILURE_RETRY(fstat(fd, &st)); if (ret < 0) { - UTILS_LOGE("Failed to exec fstat"); + UTILS_LOGE("%{public}s: Failed to exec fstat, ret = %{public}d", __func__, ret); close(fd); return ret; } if (!S_ISCHR(st.st_mode) || !st.st_rdev) { - UTILS_LOGE("stat status is invalid"); + UTILS_LOGE("%{public}s: stat status is invalid, st_mode = %{public}u", __func__, st.st_mode); close(fd); return -1; } @@ -106,7 +106,7 @@ int AshmemCreate(const char *name, size_t size) int ret; int fd = AshmemOpen(); if (fd < 0) { - UTILS_LOGE("Failed to exec AshmemOpen"); + UTILS_LOGE("%{public}s: Failed to exec AshmemOpen fd = %{public}d", __func__, fd); return fd; } @@ -114,13 +114,13 @@ int AshmemCreate(const char *name, size_t size) char buf[ASHMEM_NAME_LEN] = {0}; ret = strcpy_s(buf, sizeof(buf), name); if (ret != EOK) { - UTILS_LOGE("Failed to exec strcpy_s"); + UTILS_LOGE("%{public}s: Failed to exec strcpy_s, name= %{public}s, ret= %{public}d", __func__, name, ret); close(fd); return -1; } ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_NAME, buf)); if (ret < 0) { - UTILS_LOGE("Failed to exec ioctl"); + UTILS_LOGE("%{public}s: Failed to set name, name= %{public}s, ret= %{public}d", __func__, name, ret); close(fd); return ret; } @@ -128,7 +128,7 @@ int AshmemCreate(const char *name, size_t size) ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_SIZE, size)); if (ret < 0) { - UTILS_LOGE("Failed to exec ioctl"); + UTILS_LOGE("%{public}s: Failed to set size, size= %{public}zu", __func__, size); close(fd); return ret; } @@ -156,13 +156,13 @@ Ashmem::~Ashmem() sptr Ashmem::CreateAshmem(const char *name, int32_t size) { if ((name == nullptr) || (size <= 0)) { - UTILS_LOGE("Parameter is invalid"); + UTILS_LOGE("%{public}s: Parameter is invalid, size= %{public}d", __func__, size); return nullptr; } int fd = AshmemCreate(name, size); if (fd < 0) { - UTILS_LOGE("Failed to exec AshmemCreate"); + UTILS_LOGE("%{public}s: Failed to exec AshmemCreate, fd= %{public}d", __func__, size); return nullptr; } @@ -266,9 +266,13 @@ bool Ashmem::CheckValid(int32_t size, int32_t offset, int cmd) return false; } if ((size < 0) || (size > memorySize_) || (offset < 0) || (offset > memorySize_)) { + UTILS_LOGE("%{public}s: , invalid parameter, size = %{public}d, memorySize_ = %{public}d, offset = %{public}d", + __func__, size, memorySize_, offset); return false; } if (offset + size > memorySize_) { + UTILS_LOGE("%{public}s: , invalid parameter, size = %{public}d, memorySize_ = %{public}d, offset = %{public}d", + __func__, size, memorySize_, offset); return false; } if (!(static_cast(GetProtection()) & static_cast(cmd)) || diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 83621f214c35afb3f1b72668b46790d829469af7..32c3546445a4bafc3387a6e05ab99e55d83554a8 100755 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -513,6 +513,22 @@ bool Parcel::WriteString16WithLength(const char16_t *value, size_t len) return WriteBuffer(u16str.data(), desireCapacity); } +bool Parcel::WriteString8WithLength(const char *value, size_t len) +{ + if (!value) { + return WriteInt32(-1); + } + + int32_t dataLength = len; + int32_t desireCapacity = (dataLength + 1) * sizeof(char); + + if (!Write(dataLength)) { + return false; + } + + return WriteBuffer(value, desireCapacity); +} + bool Parcel::EnsureObjectsCapacity() { if ((objectsCapacity_ - objectCursor_) >= 1) { @@ -1035,6 +1051,37 @@ const std::u16string Parcel::ReadString16WithLength(int32_t &readLength) return std::u16string(); } +const std::string Parcel::ReadString8WithLength(int32_t &readLength) +{ + int32_t dataLength = 0; + size_t oldCursor = readCursor_; + + if (!Read(dataLength)) { + return std::string(); + } + + if (dataLength < 0) { + readLength = dataLength; + return std::string(); + } + + size_t readCapacity = (dataLength + 1) * sizeof(char); + if ((readCapacity > (size_t)dataLength) && (readCapacity <= GetReadableBytes())) { + const uint8_t *str = ReadBuffer(readCapacity); + if (str != nullptr) { + const auto *u8Str = reinterpret_cast(str); + SkipBytes(GetPadSize(readCapacity)); + if (u8Str[dataLength] == 0) { + readLength = dataLength; + return std::string(u8Str, dataLength); + } + } + } + + readCursor_ = oldCursor; + return std::string(); +} + void *DefaultAllocator::Alloc(size_t size) { return malloc(size); diff --git a/base/src/unicode_ex.cpp b/base/src/unicode_ex.cpp index cad6b4389831ffa35834401e2d86e1e40eb559d6..3ef4f9b74c8fbb311d93f933076bf6ba2cb82b77 100755 --- a/base/src/unicode_ex.cpp +++ b/base/src/unicode_ex.cpp @@ -330,8 +330,6 @@ bool String8ToString16(const string& str8, u16string& str16) { size_t str8len = str8.length(); if (str8len < 1) { - UTILS_LOGE("str8 to str16 failed, str8 is: %{public}s, size is: %{public}zu", - str8.c_str(), str8len); return false; } @@ -346,4 +344,4 @@ bool String8ToString16(const string& str8, u16string& str16) str16Temp = nullptr; return true; } -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/base/test/unittest/common/BUILD.gn b/base/test/unittest/common/BUILD.gn index 85a82da0dea5f54eaa1275ae5c54971d344a0091..c8eb06fd8c97fdd0f118fe00d28af2ab91289801 100644 --- a/base/test/unittest/common/BUILD.gn +++ b/base/test/unittest/common/BUILD.gn @@ -18,362 +18,279 @@ module_output_path = "utils/base" config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ - "../../../include", - ] + include_dirs = [ "../../../include" ] + # library path - lib_dirs = [ - "libs", - ] + lib_dirs = [ "libs" ] } ##############################unittest########################################## ohos_unittest("UtilsStringTest") { module_out_path = module_output_path - sources = [ - "utils_string_test.cpp", - ] + sources = [ "utils_string_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsSecurecTest") { module_out_path = module_output_path - sources = [ - "utils_securec_test.cpp", - ] + sources = [ "utils_securec_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsDirectoryTest") { module_out_path = module_output_path - sources = [ - "utils_directory_test.cpp", - ] + sources = [ "utils_directory_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsDateTimeTest") { module_out_path = module_output_path - sources = [ - "utils_datetime_test.cpp", - ] + sources = [ "utils_datetime_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsParcelTest") { module_out_path = module_output_path - sources = [ - "utils_parcel_test.cpp", - ] + sources = [ "utils_parcel_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsAshmemTest") { module_out_path = module_output_path - sources = [ - "utils_ashmem_test.cpp", - ] + sources = [ "utils_ashmem_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] - external_deps = ["hiviewdfx_hilog_native:libhilog"] + external_deps = [ "hilog_native:libhilog" ] } ##############################unittest########################################## ohos_unittest("UtilsRefbaseTest") { module_out_path = module_output_path - sources = [ - "utils_refbase_test.cpp", - ] + sources = [ "utils_refbase_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } - ##############################unittest########################################## ohos_unittest("UtilsThreadTest") { module_out_path = module_output_path - sources = [ - "utils_thread_test.cpp", - ] + sources = [ "utils_thread_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsFileTest") { module_out_path = module_output_path - sources = [ - "utils_file_test.cpp", - ] + sources = [ "utils_file_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsObserverTest") { module_out_path = module_output_path - sources = [ - "utils_observer_test.cpp", - ] + sources = [ "utils_observer_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsSafeBlockQueueTest") { module_out_path = module_output_path - sources = [ - "utils_safe_block_queue_test.cpp", - ] + sources = [ "utils_safe_block_queue_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsSafeMapTest") { module_out_path = module_output_path - sources = [ - "utils_safe_map_test.cpp", - ] + sources = [ "utils_safe_map_test.cpp" ] configs = [ - ":module_private_config","//build/config/compiler:exceptions", - ] - remove_configs = [ - "//build/config/compiler:no_exceptions", + ":module_private_config", + "//build/config/compiler:exceptions", ] + remove_configs = [ "//build/config/compiler:no_exceptions" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsSafeBlockQueueTrackingTest") { module_out_path = module_output_path - sources = [ - "utils_safe_block_queue_tracking.cpp", - ] + sources = [ "utils_safe_block_queue_tracking.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } - ############################################################################### ohos_unittest("UtilsSafeQueueTest") { module_out_path = module_output_path - sources = [ - "utils_safe_queue_test.cpp", - ] + sources = [ "utils_safe_queue_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsThreadPoolTest") { module_out_path = module_output_path - sources = [ - "utils_thread_pool_test.cpp", - ] + sources = [ "utils_thread_pool_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsSemaphoreTest") { module_out_path = module_output_path - sources = [ - "utils_semaphore_test.cpp", - ] + sources = [ "utils_semaphore_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ##############################unittest########################################## ohos_unittest("UtilsSingletonTest") { module_out_path = module_output_path - sources = [ - "utils_singleton_test.cpp", - ] + sources = [ "utils_singleton_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } + ############################################################################### ohos_unittest("UtilsSortedVectorTest") { module_out_path = module_output_path - sources = [ - "utils_sorted_vector_test.cpp", - ] + sources = [ "utils_sorted_vector_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ############################################################################### ohos_unittest("UtilsUniqueFdTest") { module_out_path = module_output_path - sources = [ - "utils_unique_fd_test.cpp", - ] + sources = [ "utils_unique_fd_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } ############################################################################### ohos_unittest("UtilsTimerTest") { module_out_path = module_output_path - sources = [ - "utils_timer_test.cpp", - ] + sources = [ "utils_timer_test.cpp" ] - configs = [ - ":module_private_config", - ] + configs = [ ":module_private_config" ] deps = [ - "//utils/native/base:utils", "//third_party/googletest:gtest_main", + "//utils/native/base:utils", ] } -############################################################################### +############################################################################### group("unittest") { testonly = true @@ -381,22 +298,22 @@ group("unittest") { deps += [ # deps file - ":UtilsStringTest", - ":UtilsSecurecTest", - ":UtilsDirectoryTest", + ":UtilsAshmemTest", ":UtilsDateTimeTest", - ":UtilsRefbaseTest", - ":UtilsSingletonTest", + ":UtilsDirectoryTest", ":UtilsParcelTest", - ":UtilsAshmemTest", - ":UtilsThreadTest", + ":UtilsRefbaseTest", ":UtilsSafeBlockQueueTest", ":UtilsSafeBlockQueueTrackingTest", - ":UtilsSafeQueueTest", ":UtilsSafeMapTest", + ":UtilsSafeQueueTest", + ":UtilsSecurecTest", + ":UtilsSingletonTest", ":UtilsSortedVectorTest", + ":UtilsStringTest", + ":UtilsThreadTest", + ":UtilsTimerTest", ":UtilsUniqueFdTest", - ":UtilsTimerTest" ] } ############################################################################### diff --git a/base/test/unittest/common/utils_parcel_test.cpp b/base/test/unittest/common/utils_parcel_test.cpp index b94d6796190eb9eb580dee0e0805ee9400f51b40..ddeb369b87110a06abfcf700bf2f6103cc0845e7 100755 --- a/base/test/unittest/common/utils_parcel_test.cpp +++ b/base/test/unittest/common/utils_parcel_test.cpp @@ -20,6 +20,7 @@ #include "directory_ex.h" #include "parcel.h" #include "refbase.h" +#include "securec.h" using namespace testing::ext; using namespace OHOS; @@ -77,6 +78,21 @@ void WriteTestData(Parcel &parcel, const struct TestData &data) EXPECT_EQ(result, true); } +/** + * Here to simulate the scenario of ipc sending data, the buffer will be released when the Parcel object is destructed. +*/ +bool SendData(void *&buffer, size_t size, const uint8_t *data) +{ + if (size <= 0) { + return false; + } + buffer = malloc(size); + if (memcpy_s(buffer, size, data, size) != EOK) { + return false; + } + return true; +} + /** * @tc.name: test_parcel_WriteAndRead_001 * @tc.desc: test parcel primary type read write. @@ -122,7 +138,13 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_002, TestSize.Level1) struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 }; WriteTestData(parcel1, data); - bool result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + bool result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); EXPECT_EQ(result, true); bool readbool = parcel2.ReadBool(); @@ -159,7 +181,13 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_003, TestSize.Level1) struct TestData data = { true, -0x34, 0x5634, -0x12345678, 0x34, 0x5634, 0x12345678 }; WriteTestData(parcel1, data); - bool result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + bool result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); EXPECT_EQ(result, true); bool boolVal = true; @@ -223,7 +251,14 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_004, TestSize.Level1) EXPECT_EQ(readuint64, uint64test); Parcel parcel2(nullptr); - result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); readint64 = parcel2.ReadInt64(); EXPECT_EQ(readint64, int64test); @@ -264,7 +299,14 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String_001, TestSize.Level1) EXPECT_EQ(0, strcmp(strread2.c_str(), strwrite2.c_str())); Parcel parcel2(nullptr); - result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); strread = parcel2.ReadString(); strread1 = parcel2.ReadString(); @@ -297,7 +339,14 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String_002, TestSize.Level1) EXPECT_EQ(0, str16read2.compare(str16write2)); Parcel parcel2(nullptr); - result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); str16read = parcel2.ReadString16(); str16read2 = parcel2.ReadString16(); @@ -406,7 +455,14 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_Float_001, TestSize.Level1) EXPECT_EQ(doublewrite, doubleread); Parcel parcel2(nullptr); - result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); result = parcel2.ReadFloat(floatread); EXPECT_EQ(result, true); EXPECT_EQ(floatwrite, floatread); @@ -453,7 +509,14 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndRead_String_005, TestSize.Level1) EXPECT_EQ(0, strcmp(strread2.c_str(), strwrite2.c_str())); Parcel parcel2(nullptr); - result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); EXPECT_EQ(result, true); result = parcel2.ReadString(strread); @@ -661,7 +724,14 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndReadVector_002, TestSize.Level1) WriteVectorTestData(parcel1, data); Parcel parcel2(nullptr); - bool result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + bool result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); EXPECT_EQ(result, true); ReadVectorTestData(parcel2, data); } @@ -698,7 +768,13 @@ HWTEST_F(UtilsParcelTest, test_parcel_WriteAndReadVector_003, TestSize.Level1) EXPECT_EQ(0, string16test[i].compare(u16stringread[i])); } - result = parcel2.ParseFrom(parcel1.GetData(), parcel1.GetDataSize()); + void *buffer = nullptr; + size_t size = parcel1.GetDataSize(); + if (!SendData(buffer, size, reinterpret_cast(parcel1.GetData()))) { + ASSERT_FALSE(false); + } + + result = parcel2.ParseFrom(reinterpret_cast(buffer), parcel1.GetDataSize()); result = parcel2.ReadStringVector(&stringread); EXPECT_EQ(result, true); for (size_t i = 0; i < stringtest.size(); i++) { @@ -888,7 +964,3 @@ HWTEST_F(UtilsParcelTest, test_SetMaxCapacity_002, TestSize.Level1) ret = parcel.ReadString16Vector(&val); EXPECT_EQ(false, ret); } - - - -