Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
76a50785
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,发现更多精彩内容 >>
提交
76a50785
编写于
12月 09, 2022
作者:
W
wanderer-dl122
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update ut
Signed-off-by:
N
wanderer-dl122
<
dengliang21@huawei.com
>
上级
73d31b0f
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
276 addition
and
0 deletion
+276
-0
ipc/native/test/unittest/common/BUILD.gn
ipc/native/test/unittest/common/BUILD.gn
+3
-0
ipc/native/test/unittest/common/databus_session_callback_unittest.cpp
...est/unittest/common/databus_session_callback_unittest.cpp
+49
-0
ipc/native/test/unittest/common/ipc_file_desc_unittest.cpp
ipc/native/test/unittest/common/ipc_file_desc_unittest.cpp
+51
-0
ipc/native/test/unittest/common/ipc_thread_pool_unittest.cpp
ipc/native/test/unittest/common/ipc_thread_pool_unittest.cpp
+147
-0
ipc/native/test/unittest/common/message_parcel_unittest.cpp
ipc/native/test/unittest/common/message_parcel_unittest.cpp
+26
-0
未找到文件。
ipc/native/test/unittest/common/BUILD.gn
浏览文件 @
76a50785
...
...
@@ -38,6 +38,7 @@ ohos_unittest("IPCNativeUnitTest") {
"ipc_object_proxy_unittest.cpp",
"ipc_process_skeleton_unittest.cpp",
"ipc_thread_skeleton_unittest.cpp",
"ipc_thread_pool_unittest.cpp",
"iremote_object_unitest.cpp",
"message_parcel_unittest.cpp",
]
...
...
@@ -69,6 +70,8 @@ ohos_unittest("IPCFileDescOpsTest") {
include_dirs = [
"//utils/system/safwk/native/include",
"//foundation/communication/ipc/ipc/native/c/rpc/include",
"//foundation/communication/ipc/ipc/native/c/ipc_adapter/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/communication/ipc/interfaces/innerkits/libdbinder/include",
"//foundation/communication/ipc/native/src/core/include",
...
...
ipc/native/test/unittest/common/databus_session_callback_unittest.cpp
浏览文件 @
76a50785
...
...
@@ -16,9 +16,13 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#define private public
#include "databus_session_callback.h"
#include "ipc_thread_skeleton.h"
#include "ipc_types.h"
#include "iremote_object.h"
#include "mock_session_impl.h"
#undef private
using
namespace
testing
::
ext
;
using
namespace
OHOS
;
...
...
@@ -131,3 +135,48 @@ HWTEST_F(DbSessionCallbackUnitTest, OnSessionOpenedTest003, TestSize.Level1)
EXPECT_EQ
(
ret
,
SESSION_UNOPEN_ERR
);
}
/**
* @tc.name: OnSessionOpenedTest004
* @tc.desc: Verify the OnSessionOpened function
* @tc.type: FUNC
*/
HWTEST_F
(
DbSessionCallbackUnitTest
,
OnSessionOpenedTest004
,
TestSize
.
Level1
)
{
std
::
shared_ptr
<
MockSessionImpl
>
session
=
std
::
make_shared
<
MockSessionImpl
>
();
EXPECT_CALL
(
*
session
,
GetChannelId
())
.
WillRepeatedly
(
testing
::
Return
(
1
));
EXPECT_CALL
(
*
session
,
IsServerSide
())
.
WillRepeatedly
(
testing
::
Return
(
true
));
EXPECT_CALL
(
*
session
,
GetPeerPid
())
.
WillRepeatedly
(
testing
::
Return
(
PID_TEST
));
EXPECT_CALL
(
*
session
,
GetPeerUid
())
.
WillRepeatedly
(
testing
::
Return
(
UID_TEST
));
EXPECT_CALL
(
*
session
,
GetPeerDeviceId
())
.
WillRepeatedly
(
testing
::
ReturnRef
(
DEVICE_ID_TEST
));
EXPECT_CALL
(
*
session
,
GetMySessionName
())
.
WillRepeatedly
(
testing
::
ReturnRef
(
SESSION_NAME_TEST
));
EXPECT_CALL
(
*
session
,
GetPeerSessionName
())
.
WillRepeatedly
(
testing
::
ReturnRef
(
PEER_SESSION_NAME_TEST
));
IRemoteInvoker
*
invoker
=
nullptr
;
IPCThreadSkeleton
*
current
=
IPCThreadSkeleton
::
GetCurrent
();
current
->
invokers_
[
IRemoteObject
::
IF_PROT_DATABUS
]
=
invoker
;
DatabusSessionCallback
dbSessionCallback
;
int
ret
=
dbSessionCallback
.
OnSessionOpened
(
session
);
EXPECT_EQ
(
ret
,
SESSION_INVOKER_NULL_ERR
);
char
data
[]
=
"testdata"
;
ssize_t
len
=
strlen
(
data
);
dbSessionCallback
.
OnBytesReceived
(
session
,
data
,
len
);
dbSessionCallback
.
OnSessionClosed
(
session
);
}
\ No newline at end of file
ipc/native/test/unittest/common/ipc_file_desc_unittest.cpp
浏览文件 @
76a50785
...
...
@@ -18,9 +18,14 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <gtest/gtest.h>
#define private public
#include "binder_invoker.h"
#include "ipc_debug.h"
#include "ipc_file_descriptor.h"
#include "log_tags.h"
#include "ipc_thread_skeleton.h"
#undef private
namespace
OHOS
{
using
namespace
testing
::
ext
;
...
...
@@ -90,4 +95,50 @@ HWTEST_F(IPCFileDescOpsTest, fd_parcelable_003, TestSize.Level1)
fdesc
.
SetFd
(
fd
);
EXPECT_EQ
(
fd
,
fdesc
.
GetFd
());
}
HWTEST_F
(
IPCFileDescOpsTest
,
Marshalling001
,
TestSize
.
Level1
)
{
int
fd
=
9876
;
IPCFileDescriptor
fdesc
;
fdesc
.
SetFd
(
fd
);
BinderInvoker
*
invoker
=
nullptr
;
IPCThreadSkeleton
*
current
=
IPCThreadSkeleton
::
GetCurrent
();
current
->
invokers_
[
IRemoteObject
::
IF_PROT_DEFAULT
]
=
invoker
;
Parcel
parcel
;
auto
ret
=
fdesc
.
Marshalling
(
parcel
);
ASSERT_FALSE
(
ret
);
}
HWTEST_F
(
IPCFileDescOpsTest
,
Unmarshalling001
,
TestSize
.
Level1
)
{
int
fd
=
9876
;
IPCFileDescriptor
fdesc
;
fdesc
.
SetFd
(
fd
);
BinderInvoker
*
invoker
=
nullptr
;
IPCThreadSkeleton
*
current
=
IPCThreadSkeleton
::
GetCurrent
();
current
->
invokers_
[
IRemoteObject
::
IF_PROT_DEFAULT
]
=
invoker
;
Parcel
parcel
;
auto
ret
=
fdesc
.
Unmarshalling
(
parcel
);
ASSERT_TRUE
(
ret
==
nullptr
);
}
HWTEST_F
(
IPCFileDescOpsTest
,
Unmarshalling002
,
TestSize
.
Level1
)
{
int
fd
=
9876
;
IPCFileDescriptor
fdesc
;
Parcel
parcel
;
fdesc
.
SetFd
(
fd
);
BinderInvoker
*
invoker
=
new
BinderInvoker
();
invoker
->
WriteFileDescriptor
(
parcel
,
fd
,
true
);
IPCThreadSkeleton
*
current
=
IPCThreadSkeleton
::
GetCurrent
();
current
->
invokers_
[
IRemoteObject
::
IF_PROT_DEFAULT
]
=
invoker
;
auto
ret
=
fdesc
.
Unmarshalling
(
parcel
);
ASSERT_TRUE
(
ret
!=
nullptr
);
}
}
// namespace OHOS
ipc/native/test/unittest/common/ipc_thread_pool_unittest.cpp
0 → 100644
浏览文件 @
76a50785
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#define private public
#include "ipc_types.h"
#include "ipc_thread_pool.h"
#include "ipc_workthread.h"
#undef private
using
namespace
testing
::
ext
;
using
namespace
OHOS
;
class
IPCWorkThreadPoolUnitTest
:
public
testing
::
Test
{
public:
static
void
SetUpTestCase
(
void
);
static
void
TearDownTestCase
(
void
);
void
SetUp
();
void
TearDown
();
};
void
IPCWorkThreadPoolUnitTest
::
SetUpTestCase
()
{
}
void
IPCWorkThreadPoolUnitTest
::
TearDownTestCase
()
{
}
void
IPCWorkThreadPoolUnitTest
::
SetUp
()
{}
void
IPCWorkThreadPoolUnitTest
::
TearDown
()
{}
/**
* @tc.name: RemoveThreadTest001
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCWorkThreadPoolUnitTest
,
RemoveThreadTest001
,
TestSize
.
Level1
)
{
IPCWorkThreadPool
threadPool
(
1
);
std
::
string
threadName
=
"threadName1"
;
auto
ipcThread
=
new
(
std
::
nothrow
)
IPCWorkThread
(
threadName
);
threadPool
.
threads_
[
threadName
]
=
ipcThread
;
ipcThread
->
proto_
=
IRemoteObject
::
IF_PROT_DEFAULT
;
auto
ret
=
threadPool
.
RemoveThread
(
threadName
);
EXPECT_EQ
(
ret
,
true
);
}
/**
* @tc.name: RemoveThreadTest002
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCWorkThreadPoolUnitTest
,
RemoveThreadTest002
,
TestSize
.
Level1
)
{
IPCWorkThreadPool
threadPool
(
1
);
std
::
string
threadName
=
"threadName1"
;
auto
ipcThread
=
new
(
std
::
nothrow
)
IPCWorkThread
(
threadName
);
threadPool
.
threads_
[
threadName
]
=
ipcThread
;
ipcThread
->
proto_
=
IRemoteObject
::
IF_PROT_DATABUS
;
auto
ret
=
threadPool
.
RemoveThread
(
threadName
);
EXPECT_EQ
(
ret
,
true
);
}
/**
* @tc.name: RemoveThreadTest004
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCWorkThreadPoolUnitTest
,
RemoveThreadTest004
,
TestSize
.
Level1
)
{
IPCWorkThreadPool
threadPool
(
1
);
std
::
string
threadName
=
"threadName1"
;
auto
ipcThread
=
new
(
std
::
nothrow
)
IPCWorkThread
(
threadName
);
threadPool
.
threads_
[
threadName
]
=
ipcThread
;
ipcThread
->
proto_
=
IRemoteObject
::
IF_PROT_ERROR
;
auto
ret
=
threadPool
.
RemoveThread
(
threadName
);
EXPECT_EQ
(
ret
,
true
);
}
/**
* @tc.name: RemoveThreadTest005
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCWorkThreadPoolUnitTest
,
RemoveThreadTest005
,
TestSize
.
Level1
)
{
IPCWorkThreadPool
threadPool
(
1
);
std
::
string
threadName
=
"threadName1"
;
threadPool
.
threads_
[
threadName
]
=
nullptr
;
auto
ret
=
threadPool
.
RemoveThread
(
threadName
);
EXPECT_EQ
(
ret
,
false
);
}
/**
* @tc.name: RemoveThreadTest006
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCWorkThreadPoolUnitTest
,
RemoveThreadTest006
,
TestSize
.
Level1
)
{
IPCWorkThreadPool
threadPool
(
1
);
std
::
string
threadName
=
"threadName1"
;
auto
ret
=
threadPool
.
RemoveThread
(
threadName
);
EXPECT_EQ
(
ret
,
false
);
}
/**
* @tc.name: UpdateMaxThreadNumTest001
* @tc.desc: Verify the UpdateMaxThreadNum function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCWorkThreadPoolUnitTest
,
UpdateMaxThreadNumTest001
,
TestSize
.
Level1
)
{
IPCWorkThreadPool
threadPool
(
1
);
threadPool
.
UpdateMaxThreadNum
(
0
);
EXPECT_EQ
(
threadPool
.
maxThreadNum_
,
1
);
}
\ No newline at end of file
ipc/native/test/unittest/common/message_parcel_unittest.cpp
浏览文件 @
76a50785
...
...
@@ -385,3 +385,29 @@ HWTEST_F(MessageParcelTest, WriteAshmemTest001, TestSize.Level1)
ASSERT_TRUE
(
ret
==
true
);
ashmem
->
CloseAshmem
();
}
/**
* @tc.name: ReadAshmemTest001
* @tc.desc: Verify the MessageParcel::ReadAshmem function
* @tc.type: FUNC
*/
HWTEST_F
(
MessageParcelTest
,
ReadAshmemTest001
,
TestSize
.
Level1
)
{
MessageParcel
parcel
;
auto
ret
=
parcel
.
ReadAshmem
();
ASSERT_TRUE
(
ret
==
nullptr
);
}
/**
* @tc.name: AppendTest001
* @tc.desc: Verify the MessageParcel::Append function
* @tc.type: FUNC
*/
HWTEST_F
(
MessageParcelTest
,
AppendTest001
,
TestSize
.
Level1
)
{
MessageParcel
parcel
;
MessageParcel
data
;
auto
ret
=
parcel
.
Append
(
data
);
ASSERT_TRUE
(
ret
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录