mirror of
https://github.com/openharmony/utils_native.git
synced 2026-07-19 14:13:37 -04:00
add home fix bug to native
Signed-off-by: hongtao <hongtao11@huawei.com>
This commit is contained in:
+13
-11
@@ -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",
|
||||
]
|
||||
}
|
||||
}
|
||||
###############################################################################
|
||||
|
||||
@@ -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<Parcelable> &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);
|
||||
|
||||
+13
-9
@@ -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> 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<uint32_t>(GetProtection()) & static_cast<uint32_t>(cmd)) ||
|
||||
|
||||
@@ -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<int32_t>(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<int32_t>(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<const char *>(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);
|
||||
|
||||
@@ -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
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -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",
|
||||
":UtilsDateTimeTest",
|
||||
":UtilsRefbaseTest",
|
||||
":UtilsSingletonTest",
|
||||
":UtilsParcelTest",
|
||||
":UtilsAshmemTest",
|
||||
":UtilsThreadTest",
|
||||
":UtilsDateTimeTest",
|
||||
":UtilsDirectoryTest",
|
||||
":UtilsParcelTest",
|
||||
":UtilsRefbaseTest",
|
||||
":UtilsSafeBlockQueueTest",
|
||||
":UtilsSafeBlockQueueTrackingTest",
|
||||
":UtilsSafeQueueTest",
|
||||
":UtilsSafeMapTest",
|
||||
":UtilsSafeQueueTest",
|
||||
":UtilsSecurecTest",
|
||||
":UtilsSingletonTest",
|
||||
":UtilsSortedVectorTest",
|
||||
":UtilsStringTest",
|
||||
":UtilsThreadTest",
|
||||
":UtilsTimerTest",
|
||||
":UtilsUniqueFdTest",
|
||||
":UtilsTimerTest"
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
|
||||
@@ -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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
bool result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
bool result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
bool result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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<const uint8_t *>(parcel1.GetData()))) {
|
||||
ASSERT_FALSE(false);
|
||||
}
|
||||
|
||||
result = parcel2.ParseFrom(reinterpret_cast<uintptr_t>(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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user