Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
26bfed96
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
大约 1 年 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
26bfed96
编写于
2月 28, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 28, 2023
浏览文件
操作
浏览文件
下载
差异文件
!600 新增ipc模块c接口的测试用例
Merge pull request !600 from Yanying/master
上级
fa3259a7
bca2e276
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
307 addition
and
3 deletion
+307
-3
ipc/native/test/unittest/common/ipc_c_message_parcel_unittest.cpp
...ve/test/unittest/common/ipc_c_message_parcel_unittest.cpp
+127
-3
ipc/native/test/unittest/common/ipc_c_process_unittest.cpp
ipc/native/test/unittest/common/ipc_c_process_unittest.cpp
+85
-0
ipc/native/test/unittest/common/ipc_c_remote_object_unittest.cpp
...ive/test/unittest/common/ipc_c_remote_object_unittest.cpp
+95
-0
未找到文件。
ipc/native/test/unittest/common/ipc_c_message_parcel_unittest.cpp
浏览文件 @
26bfed96
...
...
@@ -16,6 +16,8 @@
#include <gtest/gtest.h>
#include <refbase.h>
#include <securec.h>
#include "c_ashmem.h"
#include "c_parcel.h"
#include "c_parcel_internal.h"
...
...
@@ -51,9 +53,12 @@ static bool CParcelBytesAllocatorOk(void *stringData, char **buffer, int32_t len
if
(
buffer
==
nullptr
||
len
<
0
)
{
return
false
;
}
*
buffer
=
(
char
*
)
malloc
(
len
);
if
(
*
buffer
==
nullptr
)
{
return
false
;
if
(
len
!=
0
)
{
*
buffer
=
(
char
*
)
malloc
(
len
);
if
(
*
buffer
==
nullptr
)
{
return
false
;
}
(
void
)
memset_s
(
*
buffer
,
len
,
0
,
len
);
}
void
**
ptr
=
reinterpret_cast
<
void
**>
(
stringData
);
if
(
ptr
!=
nullptr
)
{
...
...
@@ -457,4 +462,123 @@ HWTEST_F(IpcCMessageParcelUnitTest, CParcelDataInfo, TestSize.Level1)
EXPECT_TRUE
(
CParcelGetWritePosition
(
parcel
)
==
0
);
CParcelDecStrongRef
(
parcel
);
}
/**
* @tc.name: CParcelContainFileDescriptors
* @tc.desc: Verify whether there is fd with this description
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCMessageParcelUnitTest
,
CParcelContainFileDescriptors
,
TestSize
.
Level1
)
{
CParcel
*
parcel
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
CParcelContainFileDescriptors
(
parcel
);
EXPECT_EQ
(
CParcelGetRawDataSize
(
parcel
),
0
);
CParcelDecStrongRef
(
parcel
);
}
/**
* @tc.name: CParcelClearFileDescriptor
* @tc.desc: Verify clear fd by this description
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCMessageParcelUnitTest
,
CParcelClearFileDescriptor
,
TestSize
.
Level1
)
{
CParcel
*
parcel
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
CParcelClearFileDescriptor
(
parcel
);
EXPECT_EQ
(
CParcelGetRawDataSize
(
parcel
),
0
);
CParcelDecStrongRef
(
parcel
);
}
/**
* @tc.name: CParcelGetRawDataSize
* @tc.desc: Get raw data size
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCMessageParcelUnitTest
,
CParcelGetRawDataSize
,
TestSize
.
Level1
)
{
CParcel
*
parcel
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
EXPECT_EQ
(
CParcelGetRawDataSize
(
parcel
),
0
);
CParcelDecStrongRef
(
parcel
);
}
/**
* @tc.name: CParcelGetRawDataCapacity
* @tc.desc: Get raw data capacity
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCMessageParcelUnitTest
,
CParcelGetRawDataCapacity
,
TestSize
.
Level1
)
{
CParcel
*
parcel
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
EXPECT_EQ
(
CParcelGetRawDataCapacity
(
parcel
),
128
*
1024
*
1024
);
CParcelDecStrongRef
(
parcel
);
}
/**
* @tc.name: CParcelSetClearFdFlag
* @tc.desc: Verify set clear fd flag
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCMessageParcelUnitTest
,
CParcelSetClearFdFlag
,
TestSize
.
Level1
)
{
CParcel
*
parcel
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
CParcelSetClearFdFlag
(
parcel
);
CParcelDecStrongRef
(
parcel
);
}
/**
* @tc.name: CParcelAppend
* @tc.desc: Verify Whether the parcel is appended successfully
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCMessageParcelUnitTest
,
CParcelAppend
,
TestSize
.
Level1
)
{
CParcel
*
parcel
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
CParcel
*
parcel2
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
EXPECT_EQ
(
CParcelAppend
(
parcel
,
parcel2
),
true
);
CParcelDecStrongRef
(
parcel
);
CParcelDecStrongRef
(
parcel2
);
}
/**
* @tc.name: ReadAndWriteAshmemTest
* @tc.desc: Verify the read and write ashmem function
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCMessageParcelUnitTest
,
ReadAndWriteAshmemTest
,
TestSize
.
Level1
)
{
CParcel
*
parcel
=
CParcelObtain
();
EXPECT_NE
(
parcel
,
nullptr
);
std
::
string
name
=
"AshmemIpc"
;
std
::
string
ashmemString
=
"HelloWorld2023"
;
CAshmem
*
ashmem
=
CreateCAshmem
(
name
.
c_str
(),
1024
);
ASSERT_TRUE
(
ashmem
!=
nullptr
);
EXPECT_EQ
(
MapReadAndWriteCAshmem
(
ashmem
),
true
);
EXPECT_EQ
(
WriteToCAshmem
(
ashmem
,
const_cast
<
uint8_t
*>
(
reinterpret_cast
<
const
uint8_t
*>
(
ashmemString
.
c_str
())),
strlen
(
ashmemString
.
c_str
()),
0
),
true
);
EXPECT_EQ
(
CParcelWriteAshmem
(
parcel
,
ashmem
),
true
);
EXPECT_EQ
(
CParcelRewindRead
(
parcel
,
0
),
true
);
CAshmem
*
ashmem2
=
CParcelReadAshmem
(
parcel
);
ASSERT_TRUE
(
ashmem2
!=
nullptr
);
ASSERT_TRUE
(
MapReadOnlyCAshmem
(
ashmem2
));
const
void
*
content
=
ReadFromCAshmem
(
ashmem2
,
strlen
(
ashmemString
.
c_str
()),
0
);
ASSERT_TRUE
(
content
!=
nullptr
);
auto
readContent
=
static_cast
<
const
char
*>
(
content
);
std
::
string
str
(
readContent
,
strlen
(
ashmemString
.
c_str
()));
EXPECT_EQ
(
str
,
ashmemString
);
UnmapCAshmem
(
ashmem
);
CloseCAshmem
(
ashmem
);
UnmapCAshmem
(
ashmem2
);
CloseCAshmem
(
ashmem2
);
}
\ No newline at end of file
ipc/native/test/unittest/common/ipc_c_process_unittest.cpp
浏览文件 @
26bfed96
...
...
@@ -16,6 +16,7 @@
#include <gtest/gtest.h>
#include <nativetoken_kit.h>
#include <securec.h>
#include <token_setproc.h>
#include <unistd.h>
#include "c_process.h"
...
...
@@ -59,6 +60,25 @@ static void InitTokenId(void)
SetSelfTokenID
(
tokenId
);
}
static
bool
BytesAllocator
(
void
*
stringData
,
char
**
buffer
,
int32_t
len
)
{
if
(
buffer
==
nullptr
||
len
<
0
)
{
return
false
;
}
if
(
len
!=
0
)
{
*
buffer
=
(
char
*
)
malloc
(
len
);
if
(
*
buffer
==
nullptr
)
{
return
false
;
}
(
void
)
memset_s
(
*
buffer
,
len
,
0
,
len
);
}
void
**
ptr
=
reinterpret_cast
<
void
**>
(
stringData
);
if
(
ptr
!=
nullptr
)
{
*
ptr
=
*
buffer
;
}
return
true
;
}
/**
* @tc.name: CProcessCallingInfo
* @tc.desc: Verify the CProcess calling info functions
...
...
@@ -72,4 +92,69 @@ HWTEST_F(IpcCProcessUnitTest, CProcessCallingInfo, TestSize.Level1)
EXPECT_EQ
(
GetFirstToekenId
(),
0
);
EXPECT_EQ
(
GetCallingPid
(),
static_cast
<
uint64_t
>
(
getpid
()));
EXPECT_EQ
(
GetCallingUid
(),
static_cast
<
uint64_t
>
(
getuid
()));
}
/**
* @tc.name: SetMaxWorkThreadNum
* @tc.desc: Verify set max work thread
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCProcessUnitTest
,
SetMaxWorkThreadNum
,
TestSize
.
Level1
)
{
EXPECT_EQ
(
true
,
SetMaxWorkThreadNum
(
3
));
}
/**
* @tc.name: CallingIdentity
* @tc.desc: Verify reset and set calling identity
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCProcessUnitTest
,
CallingIdentity
,
TestSize
.
Level1
)
{
void
*
value
=
nullptr
;
bool
ret
=
ResetCallingIdentity
(
reinterpret_cast
<
void
*>
(
&
value
),
BytesAllocator
);
EXPECT_EQ
(
true
,
ret
);
ret
=
SetCallingIdentity
(
reinterpret_cast
<
const
char
*>
(
value
));
EXPECT_EQ
(
false
,
ret
);
if
(
value
!=
nullptr
)
{
free
(
value
);
}
}
/**
* @tc.name: IsLocalCalling
* @tc.desc: Verify whether it is local calling
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCProcessUnitTest
,
IsLocalCalling
,
TestSize
.
Level1
)
{
EXPECT_EQ
(
true
,
IsLocalCalling
());
}
/**
* @tc.name: GetCallingDeviceID
* @tc.desc: Get calling device ID
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCProcessUnitTest
,
GetCallingDeviceID
,
TestSize
.
Level1
)
{
void
*
value
=
nullptr
;
EXPECT_EQ
(
GetCallingDeviceID
(
value
,
BytesAllocator
),
true
);
if
(
value
!=
nullptr
)
{
free
(
value
);
}
}
/**
* @tc.name: GetLocalDeviceID
* @tc.desc: Get local device ID
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCProcessUnitTest
,
GetLocalDeviceID
,
TestSize
.
Level1
)
{
void
*
value
=
nullptr
;
EXPECT_EQ
(
GetLocalDeviceID
(
value
,
BytesAllocator
),
true
);
if
(
value
!=
nullptr
)
{
free
(
value
);
}
}
\ No newline at end of file
ipc/native/test/unittest/common/ipc_c_remote_object_unittest.cpp
浏览文件 @
26bfed96
...
...
@@ -15,6 +15,8 @@
#include <gtest/gtest.h>
#include <cstring>
#include <securec.h>
#include "c_process.h"
#include "c_remote_object.h"
#include "c_remote_object_internal.h"
...
...
@@ -69,6 +71,34 @@ static void OnDeathRecipientDestroy(const void *userData)
(
void
)
userData
;
}
static
bool
Bytes16Allocator
(
void
*
stringData
,
uint16_t
**
buffer
,
int32_t
len
)
{
if
(
buffer
==
nullptr
||
len
<
0
)
{
return
false
;
}
if
(
len
!=
0
)
{
*
buffer
=
(
uint16_t
*
)
malloc
(
len
*
sizeof
(
uint16_t
));
if
(
*
buffer
==
nullptr
)
{
return
false
;
}
(
void
)
memset_s
(
*
buffer
,
len
*
sizeof
(
uint16_t
),
0
,
len
*
sizeof
(
uint16_t
));
}
void
**
ptr
=
reinterpret_cast
<
void
**>
(
stringData
);
if
(
ptr
!=
nullptr
)
{
*
ptr
=
*
buffer
;
}
return
true
;
}
static
bool
StringArrayWrite
(
const
void
*
array
,
const
void
*
value
,
uint32_t
len
)
{
if
(
value
==
nullptr
||
len
<
0
)
{
return
false
;
}
array
=
value
;
return
true
;
}
/**
* @tc.name: CRemoteObjectRefCount
* @tc.desc: Verify the CRemoteObject reference count functions
...
...
@@ -219,4 +249,69 @@ HWTEST_F(IpcCRemoteObjectUnitTest, CDeathRecipient, TestSize.Level1)
// destroy the CDeathRecipient object
DeathRecipientDecStrongRef
(
recipient
);
RemoteObjectDecStrongRef
(
samgr
);
}
/**
* @tc.name: CRemoteObjectIsProxyObject
* @tc.desc: Verify whether the bit proxy object
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCRemoteObjectUnitTest
,
CRemoteObjectIsProxyObject
,
TestSize
.
Level1
)
{
int8_t
userData
;
CRemoteObject
*
remote
=
CreateRemoteStub
(
SERVICE_NAME
,
OnRemoteRequest
,
OnRemoteObjectDestroy
,
&
userData
);
EXPECT_NE
(
remote
,
nullptr
);
bool
ret
=
IsProxyObject
(
remote
);
EXPECT_EQ
(
ret
,
false
);
}
/**
* @tc.name: CRemoteObjectIsObjectDead
* @tc.desc: Verify whether the object is dead
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCRemoteObjectUnitTest
,
CRemoteObjectIsObjectDead
,
TestSize
.
Level1
)
{
int8_t
userData
;
CRemoteObject
*
remote
=
CreateRemoteStub
(
SERVICE_NAME
,
OnRemoteRequest
,
OnRemoteObjectDestroy
,
&
userData
);
EXPECT_NE
(
remote
,
nullptr
);
bool
ret
=
IsObjectDead
(
remote
);
EXPECT_EQ
(
ret
,
false
);
}
/**
* @tc.name: CRemoteObjectGetInterfaceDescriptor
* @tc.desc: Get interface descriptor
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCRemoteObjectUnitTest
,
CRemoteObjectGetInterfaceDescriptor
,
TestSize
.
Level1
)
{
int8_t
userData
;
CRemoteObject
*
remote
=
CreateRemoteStub
(
SERVICE_NAME
,
OnRemoteRequest
,
OnRemoteObjectDestroy
,
&
userData
);
EXPECT_NE
(
remote
,
nullptr
);
void
*
data
=
nullptr
;
bool
ret
=
GetInterfaceDescriptor
(
remote
,
reinterpret_cast
<
void
*>
(
&
data
),
Bytes16Allocator
);
EXPECT_EQ
(
ret
,
false
);
if
(
data
!=
nullptr
)
{
free
(
data
);
}
}
/**
* @tc.name: CRemoteObjectDump
* @tc.desc: Dump the service through the incoming string
* @tc.type: FUNC
*/
HWTEST_F
(
IpcCRemoteObjectUnitTest
,
CRemoteObjectDump
,
TestSize
.
Level1
)
{
int8_t
userData
;
CRemoteObject
*
remote
=
CreateRemoteStub
(
SERVICE_NAME
,
OnRemoteRequest
,
OnRemoteObjectDestroy
,
&
userData
);
EXPECT_NE
(
remote
,
nullptr
);
const
char
*
data
=
SERVICE_NAME
;
int
ret
=
Dump
(
remote
,
0
,
reinterpret_cast
<
const
void
*>
(
&
data
),
strlen
(
data
),
StringArrayWrite
);
EXPECT_EQ
(
ret
,
0
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录