Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
868b95aa
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,发现更多精彩内容 >>
未验证
提交
868b95aa
编写于
12月 01, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
!516 分支覆盖率提升
Merge pull request !516 from dengliang/master
上级
f540869f
65f7f131
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
770 addition
and
13 deletion
+770
-13
ipc/native/test/unittest/common/BUILD.gn
ipc/native/test/unittest/common/BUILD.gn
+38
-0
ipc/native/test/unittest/common/binder_invoker_unittest.cpp
ipc/native/test/unittest/common/binder_invoker_unittest.cpp
+278
-10
ipc/native/test/unittest/common/invoker_factory_unittest.cpp
ipc/native/test/unittest/common/invoker_factory_unittest.cpp
+94
-0
ipc/native/test/unittest/common/ipc_binder_databus_invoker_unittest.cpp
...t/unittest/common/ipc_binder_databus_invoker_unittest.cpp
+360
-3
未找到文件。
ipc/native/test/unittest/common/BUILD.gn
浏览文件 @
868b95aa
...
@@ -253,6 +253,43 @@ ohos_unittest("IPCMockUnitTest") {
...
@@ -253,6 +253,43 @@ ohos_unittest("IPCMockUnitTest") {
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
}
}
ohos_unittest("InvokerFactoryTest") {
module_out_path = MODULE_OUTPUT_PATH
include_dirs = [
"//utils/system/safwk/native/include",
"//commonlibrary/c_utils/base/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/communication/ipc/ipc/native/src/mock/include",
"//foundation/communication/ipc/ipc/native/c/rpc/include",
"//foundation/communication/ipc/ipc/native/c/adapter/access_token/include",
]
sources = [ "invoker_factory_unittest.cpp" ]
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
]
deps = [
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"hitrace_native:libhitracechain",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
resource_config_file =
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
}
###############################################################################
###############################################################################
group("unittest") {
group("unittest") {
testonly = true
testonly = true
...
@@ -263,6 +300,7 @@ group("unittest") {
...
@@ -263,6 +300,7 @@ group("unittest") {
":IPCHiTraceUnitTest",
":IPCHiTraceUnitTest",
":IPCMockUnitTest",
":IPCMockUnitTest",
":IPCNativeUnitTest",
":IPCNativeUnitTest",
":InvokerFactoryTest",
]
]
if (support_jsapi) {
if (support_jsapi) {
deps += [ ":IPCNapiUnitTest" ]
deps += [ ":IPCNapiUnitTest" ]
...
...
ipc/native/test/unittest/common/binder_invoker_unittest.cpp
浏览文件 @
868b95aa
...
@@ -17,11 +17,13 @@
...
@@ -17,11 +17,13 @@
#define private public
#define private public
#define protected public
#define protected public
#include "binder_invoker.h"
#include "binder_invoker.h"
#include "binder_connector.h"
#undef protected
#undef protected
#undef private
#undef private
#include "ipc_object_proxy.h"
#include "ipc_object_proxy.h"
#include "ipc_object_stub.h"
#include "ipc_object_stub.h"
#include "ipc_process_skeleton.h"
#include "ipc_process_skeleton.h"
#include "sys_binder.h"
using
namespace
testing
::
ext
;
using
namespace
testing
::
ext
;
using
namespace
OHOS
;
using
namespace
OHOS
;
...
@@ -47,16 +49,33 @@ void BinderInvokerUnitTest::TearDown()
...
@@ -47,16 +49,33 @@ void BinderInvokerUnitTest::TearDown()
{}
{}
/**
/**
* @tc.name: SetCallingIdentity001
* @tc.name: SetCallingIdentity
Test
001
* @tc.desc: Verify the
ReadFileDescriptor
function
* @tc.desc: Verify the
SetCallingIdentityTest001
function
* @tc.type: FUNC
* @tc.type: FUNC
*/
*/
HWTEST_F
(
BinderInvokerUnitTest
,
SetCallingIdentity001
,
TestSize
.
Level1
)
HWTEST_F
(
BinderInvokerUnitTest
,
SetCallingIdentity
Test
001
,
TestSize
.
Level1
)
{
{
BinderInvoker
binderInvoker
;
BinderInvoker
binderInvoker
;
std
::
string
identity
;
std
::
string
identity
;
bool
ret
=
binderInvoker
.
SetCallingIdentity
(
identity
);
bool
ret
=
binderInvoker
.
SetCallingIdentity
(
identity
);
EXPECT_EQ
(
ret
,
false
);
EXPECT_EQ
(
ret
,
false
);
identity
=
"aaa"
;
ret
=
binderInvoker
.
SetCallingIdentity
(
identity
);
EXPECT_EQ
(
ret
,
false
);
}
/**
* @tc.name: SetCallingIdentityTest002
* @tc.desc: Override SetCallingIdentity branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
SetCallingIdentityTest002
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
std
::
string
token
=
binderInvoker
.
ResetCallingIdentity
();
EXPECT_FALSE
(
token
.
empty
());
bool
ret
=
binderInvoker
.
SetCallingIdentity
(
token
);
EXPECT_TRUE
(
ret
);
}
}
/**
/**
...
@@ -72,6 +91,23 @@ HWTEST_F(BinderInvokerUnitTest, ReadFileDescriptor001, TestSize.Level1)
...
@@ -72,6 +91,23 @@ HWTEST_F(BinderInvokerUnitTest, ReadFileDescriptor001, TestSize.Level1)
EXPECT_EQ
(
ret
,
-
1
);
EXPECT_EQ
(
ret
,
-
1
);
}
}
/**
* @tc.name: ReadFileDescriptor002
* @tc.desc: Verify the ReadFileDescriptor function
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
ReadFileDescriptor002
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
Parcel
parcel
;
flat_binder_object
tr
{};
tr
.
flags
=
1
;
tr
.
hdr
.
type
=
-
1
;
parcel
.
WriteBuffer
(
&
tr
,
sizeof
(
flat_binder_object
));
int
ret
=
binderInvoker
.
ReadFileDescriptor
(
parcel
);
EXPECT_EQ
(
ret
,
-
1
);
}
/**
/**
* @tc.name: UnflattenObject001
* @tc.name: UnflattenObject001
* @tc.desc: Verify the UnflattenObject function
* @tc.desc: Verify the UnflattenObject function
...
@@ -86,16 +122,20 @@ HWTEST_F(BinderInvokerUnitTest, UnflattenObject001, TestSize.Level1)
...
@@ -86,16 +122,20 @@ HWTEST_F(BinderInvokerUnitTest, UnflattenObject001, TestSize.Level1)
}
}
/**
/**
* @tc.name:
GetCallerTokenID001
* @tc.name:
UnflattenObject002
* @tc.desc: Verify the
GetCallerTokenID
function
* @tc.desc: Verify the
UnflattenObject
function
* @tc.type: FUNC
* @tc.type: FUNC
*/
*/
HWTEST_F
(
BinderInvokerUnitTest
,
GetCallerTokenID001
,
TestSize
.
Level1
)
HWTEST_F
(
BinderInvokerUnitTest
,
UnflattenObject002
,
TestSize
.
Level1
)
{
{
BinderInvoker
binderInvoker
;
BinderInvoker
binderInvoker
;
binderInvoker
.
firstTokenID_
=
0
;
Parcel
parcel
;
uint32_t
ret
=
binderInvoker
.
GetFirstCallerTokenID
();
flat_binder_object
tr
{};
EXPECT_EQ
((
uint64_t
)
ret
,
RpcGetFirstCallerTokenID
());
tr
.
flags
=
1
;
tr
.
hdr
.
type
=
-
1
;
parcel
.
WriteBuffer
(
&
tr
,
sizeof
(
flat_binder_object
));
sptr
<
IRemoteObject
>
ret
=
binderInvoker
.
UnflattenObject
(
parcel
);
EXPECT_EQ
(
ret
,
nullptr
);
}
}
/**
/**
...
@@ -208,6 +248,23 @@ HWTEST_F(BinderInvokerUnitTest, OnAttemptAcquireTest001, TestSize.Level1)
...
@@ -208,6 +248,23 @@ HWTEST_F(BinderInvokerUnitTest, OnAttemptAcquireTest001, TestSize.Level1)
EXPECT_NE
(
reinterpret_cast
<
RefCounter
*>
(
testStub
->
GetRefCounter
()),
nullptr
);
EXPECT_NE
(
reinterpret_cast
<
RefCounter
*>
(
testStub
->
GetRefCounter
()),
nullptr
);
}
}
/**
* @tc.name: OnAttemptAcquireTest002
* @tc.desc: Verify the OnAttemptAcquire function
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
OnAttemptAcquireTest002
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
void
*
test
=
nullptr
;
binderInvoker
.
input_
.
WritePointer
((
uintptr_t
)
test
);
binderInvoker
.
OnAttemptAcquire
();
uintptr_t
refsPtr
=
binderInvoker
.
input_
.
WritePointer
((
uintptr_t
)
test
);
auto
*
refs
=
reinterpret_cast
<
RefCounter
*>
(
refsPtr
);
EXPECT_TRUE
(
refs
!=
nullptr
);
}
/**
/**
* @tc.name: HandleReplyTest001
* @tc.name: HandleReplyTest001
* @tc.desc: Verify the HandleReply function
* @tc.desc: Verify the HandleReply function
...
@@ -287,6 +344,30 @@ HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest005, TestSize.Level1)
...
@@ -287,6 +344,30 @@ HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest005, TestSize.Level1)
EXPECT_EQ
(
binderInvoker
.
HandleCommandsInner
(
BR_FINISHED
),
-
ERR_TIMED_OUT
);
EXPECT_EQ
(
binderInvoker
.
HandleCommandsInner
(
BR_FINISHED
),
-
ERR_TIMED_OUT
);
}
}
/**
* @tc.name: HandleCommandsInnerTest006
* @tc.desc: Verify the HandleCommandsInner function
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
HandleCommandsInnerTest006
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
uint32_t
cmd
=
BR_DEAD_BINDER
;
EXPECT_EQ
(
binderInvoker
.
HandleCommandsInner
(
cmd
),
ERR_NONE
);
}
/**
* @tc.name: HandleCommandsInnerTest007
* @tc.desc: Verify the HandleCommandsInner function
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
HandleCommandsInnerTest007
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
uint32_t
cmd
=
-
1
;
EXPECT_EQ
(
binderInvoker
.
HandleCommandsInner
(
cmd
),
IPC_INVOKER_ON_TRANSACT_ERR
);
}
/**
/**
* @tc.name: TransactWithDriverTest001
* @tc.name: TransactWithDriverTest001
* @tc.desc: Verify the TransactWithDriver function
* @tc.desc: Verify the TransactWithDriver function
...
@@ -297,4 +378,191 @@ HWTEST_F(BinderInvokerUnitTest, TransactWithDriverTest001, TestSize.Level1)
...
@@ -297,4 +378,191 @@ HWTEST_F(BinderInvokerUnitTest, TransactWithDriverTest001, TestSize.Level1)
BinderInvoker
binderInvoker
;
BinderInvoker
binderInvoker
;
binderInvoker
.
binderConnector_
=
nullptr
;
binderInvoker
.
binderConnector_
=
nullptr
;
EXPECT_EQ
(
binderInvoker
.
TransactWithDriver
(
true
),
IPC_INVOKER_CONNECT_ERR
);
EXPECT_EQ
(
binderInvoker
.
TransactWithDriver
(
true
),
IPC_INVOKER_CONNECT_ERR
);
}
}
\ No newline at end of file
/**
* @tc.name: StartWorkLoopTest001
* @tc.desc: Override StartWorkLoop branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
StartWorkLoopTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binderInvoker
.
input_
.
WriteUint32
(
BR_TRANSACTION
);
binderInvoker
.
isMainWorkThread
=
false
;
binderInvoker
.
StartWorkLoop
();
EXPECT_TRUE
(
binderInvoker
.
HandleCommands
(
BR_TRANSACTION
)
==
IPC_INVOKER_INVALID_DATA_ERR
);
EXPECT_TRUE
(
binderInvoker
.
isMainWorkThread
==
false
);
}
/**
* @tc.name: OnTransactionTest001
* @tc.desc: Override OnTransaction branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
OnTransactionTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binder_transaction_data
tr
{};
tr
.
offsets_size
=
1
;
binderInvoker
.
input_
.
WriteBuffer
(
&
tr
,
sizeof
(
binder_transaction_data
));
const
uint8_t
*
buffer
=
binderInvoker
.
input_
.
ReadBuffer
(
sizeof
(
binder_transaction_data
));
binderInvoker
.
OnTransaction
(
buffer
);
EXPECT_TRUE
(
tr
.
offsets_size
>
0
);
EXPECT_TRUE
(
binderInvoker
.
binderConnector_
->
IsAccessTokenSupported
());
EXPECT_TRUE
(
tr
.
target
.
ptr
==
0
);
}
/**
* @tc.name: HandleCommandsTest001
* @tc.desc: Override HandleCommands branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
HandleCommandsTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
uint32_t
cmd
=
BR_FINISHED
;
int
error
=
binderInvoker
.
HandleCommands
(
cmd
);
EXPECT_EQ
(
error
,
-
ERR_TIMED_OUT
);
}
/**
* @tc.name: JoinProcessThreadTest001
* @tc.desc: Override JoinProcessThread branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
JoinProcessThreadTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
bool
initiative
=
false
;
binderInvoker
.
JoinProcessThread
(
initiative
);
EXPECT_TRUE
(
initiative
==
false
);
}
/**
* @tc.name: WaitForCompletionTest001
* @tc.desc: Override WaitForCompletion branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
WaitForCompletionTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binderInvoker
.
input_
.
WriteUint32
(
BR_FAILED_REPLY
);
MessageParcel
reply
;
int32_t
acquireResult
=
1
;
int
error
=
binderInvoker
.
WaitForCompletion
(
&
reply
,
&
acquireResult
);
EXPECT_EQ
(
error
,
static_cast
<
int
>
(
BR_FAILED_REPLY
));
}
/**
* @tc.name: WaitForCompletionTest002
* @tc.desc: Override WaitForCompletion branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
WaitForCompletionTest002
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binderInvoker
.
input_
.
WriteUint32
(
BR_ACQUIRE_RESULT
);
MessageParcel
reply
;
int32_t
acquireResult
;
int
error
=
binderInvoker
.
WaitForCompletion
(
&
reply
,
&
acquireResult
);
EXPECT_EQ
(
error
,
ERR_NONE
);
}
/**
* @tc.name: WaitForCompletionTest003
* @tc.desc: Override WaitForCompletion branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
WaitForCompletionTest003
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binderInvoker
.
input_
.
WriteUint32
(
BR_TRANSLATION_COMPLETE
);
MessageParcel
reply
;
int32_t
acquireResult
;
int
error
=
binderInvoker
.
WaitForCompletion
(
&
reply
,
&
acquireResult
);
EXPECT_EQ
(
error
,
ERR_NONE
);
}
/**
* @tc.name: GetCallerPidTest001
* @tc.desc: Override GetCallerPid branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
GetCallerPidTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binderInvoker
.
callerPid_
=
1
;
EXPECT_EQ
(
binderInvoker
.
GetCallerPid
(),
1
);
}
/**
* @tc.name: GetCallerUidTest001
* @tc.desc: Override GetCallerUid branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
GetCallerUidTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binderInvoker
.
callerUid_
=
1
;
EXPECT_EQ
(
binderInvoker
.
GetCallerUid
(),
1
);
}
/**
* @tc.name: GetCallerTokenIDTest001
* @tc.desc: Override GetCallerTokenID branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
GetCallerTokenIDTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
binderInvoker
.
callerTokenID_
=
1
;
EXPECT_EQ
(
binderInvoker
.
GetCallerTokenID
(),
1
);
}
/**
* @tc.name: GetLocalDeviceIDTest001
* @tc.desc: Override GetLocalDeviceID branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
GetLocalDeviceIDTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
EXPECT_EQ
(
binderInvoker
.
GetLocalDeviceID
(),
""
);
}
/**
* @tc.name: GetCallerDeviceIDTest001
* @tc.desc: Override GetCallerDeviceID branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
GetCallerDeviceIDTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
EXPECT_EQ
(
binderInvoker
.
GetCallerDeviceID
(),
""
);
}
/**
* @tc.name: IsLocalCallingTest001
* @tc.desc: Override IsLocalCalling branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
IsLocalCallingTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
EXPECT_EQ
(
binderInvoker
.
IsLocalCalling
(),
true
);
}
/**
* @tc.name: FlattenObjectTest001
* @tc.desc: Override FlattenObject branch
* @tc.type: FUNC
*/
HWTEST_F
(
BinderInvokerUnitTest
,
FlattenObjectTest001
,
TestSize
.
Level1
)
{
BinderInvoker
binderInvoker
;
OHOS
::
Parcel
parcel
;
const
IRemoteObject
*
object
=
nullptr
;
EXPECT_EQ
(
binderInvoker
.
FlattenObject
(
parcel
,
object
),
false
);
}
ipc/native/test/unittest/common/invoker_factory_unittest.cpp
0 → 100644
浏览文件 @
868b95aa
/*
* Copyright (C) 2021 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>
#define private public
#include "invoker_factory.h"
#undef private
#include "binder_invoker.h"
#include "iremote_invoker.h"
namespace
OHOS
{
using
namespace
testing
::
ext
;
using
namespace
OHOS
;
class
InvokerFactoryTest
:
public
testing
::
Test
{
public:
static
void
SetUpTestCase
(
void
);
static
void
TearDownTestCase
(
void
);
void
SetUp
();
void
TearDown
();
};
void
InvokerFactoryTest
::
SetUp
()
{}
void
InvokerFactoryTest
::
TearDown
()
{}
void
InvokerFactoryTest
::
SetUpTestCase
()
{}
void
InvokerFactoryTest
::
TearDownTestCase
()
{}
/**
* @tc.name: Register001
* @tc.desc: Register
* @tc.type: FUNC
*/
HWTEST_F
(
InvokerFactoryTest
,
Register001
,
TestSize
.
Level1
)
{
InvokerFactory
&
invokerFactory
=
InvokerFactory
::
Get
();
invokerFactory
.
isAvailable_
=
false
;
int
protocol
=
1
;
IRemoteInvoker
*
invoker
=
nullptr
;
auto
invokerObject
=
[
&
invoker
]()
->
IRemoteInvoker
*
{
invoker
=
new
(
std
::
nothrow
)
BinderInvoker
();
if
(
invoker
==
nullptr
)
{
return
nullptr
;
}
return
invoker
;
};
bool
ret
=
invokerFactory
.
Register
(
protocol
,
invokerObject
);
EXPECT_EQ
(
ret
,
false
);
if
(
invoker
!=
nullptr
)
{
delete
invoker
;
invoker
=
nullptr
;
}
invokerFactory
.
isAvailable_
=
true
;
ret
=
invokerFactory
.
Register
(
protocol
,
invokerObject
);
EXPECT_EQ
(
ret
,
false
);
IRemoteInvoker
*
iRemoteInvoker
=
invokerFactory
.
newInstance
(
protocol
);
EXPECT_NE
(
iRemoteInvoker
,
nullptr
);
if
(
invoker
!=
nullptr
)
{
delete
invoker
;
invoker
=
nullptr
;
}
}
/**
* @tc.name: Unregister001
* @tc.desc: Unregister
* @tc.type: FUNC
*/
HWTEST_F
(
InvokerFactoryTest
,
Unregister001
,
TestSize
.
Level1
)
{
InvokerFactory
&
invokerFactory
=
InvokerFactory
::
Get
();
invokerFactory
.
isAvailable_
=
false
;
int
protocol
=
1
;
invokerFactory
.
Unregister
(
protocol
);
EXPECT_EQ
(
invokerFactory
.
isAvailable_
,
false
);
}
}
// namespace OHOS
ipc/native/test/unittest/common/ipc_binder_databus_invoker_unittest.cpp
浏览文件 @
868b95aa
...
@@ -783,18 +783,18 @@ HWTEST_F(IPCDbinderDataBusInvokerTest, HasCompletePackage001, TestSize.Level1)
...
@@ -783,18 +783,18 @@ HWTEST_F(IPCDbinderDataBusInvokerTest, HasCompletePackage001, TestSize.Level1)
EXPECT_TRUE
(
tmp
!=
nullptr
);
EXPECT_TRUE
(
tmp
!=
nullptr
);
const
char
*
data
=
reinterpret_cast
<
const
char
*>
(
tmp
);
const
char
*
data
=
reinterpret_cast
<
const
char
*>
(
tmp
);
uint32_t
res
=
testInvoker
.
HasCompletePackage
(
data
,
readCursor
,
size
);
uint32_t
res
=
testInvoker
.
HasCompletePackage
(
data
,
readCursor
,
size
);
EXPECT_EQ
(
res
,
0
);
EXPECT_EQ
(
res
,
readCursor
);
tmp
->
magic
=
DBINDER_MAGICWORD
;
tmp
->
magic
=
DBINDER_MAGICWORD
;
data
=
reinterpret_cast
<
const
char
*>
(
tmp
);
data
=
reinterpret_cast
<
const
char
*>
(
tmp
);
res
=
testInvoker
.
HasCompletePackage
(
data
,
readCursor
,
size
);
res
=
testInvoker
.
HasCompletePackage
(
data
,
readCursor
,
size
);
EXPECT_EQ
(
res
,
0
);
EXPECT_EQ
(
res
,
readCursor
);
tmp
->
buffer_size
=
sizeof
(
binder_size_t
);
tmp
->
buffer_size
=
sizeof
(
binder_size_t
);
tmp
->
sizeOfSelf
=
sizeof
(
dbinder_transaction_data
)
+
tmp
->
buffer_size
;
tmp
->
sizeOfSelf
=
sizeof
(
dbinder_transaction_data
)
+
tmp
->
buffer_size
;
data
=
reinterpret_cast
<
const
char
*>
(
tmp
);
data
=
reinterpret_cast
<
const
char
*>
(
tmp
);
res
=
testInvoker
.
HasCompletePackage
(
data
,
readCursor
,
size
);
res
=
testInvoker
.
HasCompletePackage
(
data
,
readCursor
,
size
);
EXPECT_EQ
(
res
,
0
);
EXPECT_EQ
(
res
,
readCursor
);
tmp
->
offsets
=
tmp
->
buffer_size
;
tmp
->
offsets
=
tmp
->
buffer_size
;
tmp
->
flags
=
MessageOption
::
TF_STATUS_CODE
;
tmp
->
flags
=
MessageOption
::
TF_STATUS_CODE
;
...
@@ -803,3 +803,360 @@ HWTEST_F(IPCDbinderDataBusInvokerTest, HasCompletePackage001, TestSize.Level1)
...
@@ -803,3 +803,360 @@ HWTEST_F(IPCDbinderDataBusInvokerTest, HasCompletePackage001, TestSize.Level1)
EXPECT_EQ
(
tmp
->
sizeOfSelf
,
res
);
EXPECT_EQ
(
tmp
->
sizeOfSelf
,
res
);
free
(
tmp
);
free
(
tmp
);
}
}
/**
* @tc.name:CheckAndSetCallerInfo001
* @tc.desc: Verify the CheckAndSetCallerInfo function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
CheckAndSetCallerInfo001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
uint32_t
handle
=
1
;
uint64_t
stubIndex
=
1
;
std
::
shared_ptr
<
DBinderSessionObject
>
sessionObject
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
IPCProcessSkeleton
*
current
=
IPCProcessSkeleton
::
GetCurrent
();
current
->
StubAttachDBinderSession
(
handle
,
sessionObject
);
int
ret
=
testInvoker
.
CheckAndSetCallerInfo
(
0
,
stubIndex
);
EXPECT_EQ
(
ret
,
RPC_DATABUS_INVOKER_INVALID_DATA_ERR
);
ret
=
testInvoker
.
CheckAndSetCallerInfo
(
handle
,
stubIndex
);
EXPECT_EQ
(
ret
,
RPC_DATABUS_INVOKER_INVALID_DATA_ERR
);
}
/**
* @tc.name:CheckAndSetCallerInfo002
* @tc.desc: Verify the CheckAndSetCallerInfo function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
CheckAndSetCallerInfo002
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
uint32_t
handle
=
1
;
uint64_t
stubIndex
=
1
;
std
::
shared_ptr
<
DBinderSessionObject
>
sessionObject
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
std
::
shared_ptr
<
MockSessionImpl
>
sessionMock
=
std
::
make_shared
<
MockSessionImpl
>
();
sessionObject
->
session_
=
sessionMock
;
IPCProcessSkeleton
*
current
=
IPCProcessSkeleton
::
GetCurrent
();
current
->
StubAttachDBinderSession
(
handle
,
sessionObject
);
int
ret
=
testInvoker
.
CheckAndSetCallerInfo
(
handle
,
stubIndex
);
EXPECT_EQ
(
ret
,
RPC_DATABUS_INVOKER_INVALID_DATA_ERR
);
}
/**
* @tc.name: UpdateClientSession001
* @tc.desc: UpdateClientSession return false
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
UpdateClientSession001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
DBinderSessionObject
>
sessionObject
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
bool
ret
=
testInvoker
.
UpdateClientSession
(
sessionObject
);
EXPECT_EQ
(
ret
,
false
);
}
/**
* @tc.name: OnSendMessage001
* @tc.desc: OnSendMessage return -RPC_DATABUS_INVOKER_INVALID_DATA_ERR
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
OnSendMessage001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
DBinderSessionObject
>
sessionOfPeer
=
nullptr
;
int
ret
=
testInvoker
.
OnSendMessage
(
sessionOfPeer
);
EXPECT_EQ
(
ret
,
-
RPC_DATABUS_INVOKER_INVALID_DATA_ERR
);
}
/**
* @tc.name: OnSendMessage002
* @tc.desc: OnSendMessage return RPC_DATABUS_INVOKER_INVALID_DATA_ERR
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
OnSendMessage002
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
DBinderSessionObject
>
sessionOfPeer
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
int
ret
=
testInvoker
.
OnSendMessage
(
sessionOfPeer
);
EXPECT_EQ
(
ret
,
-
RPC_DATABUS_INVOKER_INVALID_DATA_ERR
);
}
/**
* @tc.name: OnSendMessage003
* @tc.desc: OnSendMessage return RPC_DATABUS_INVOKER_INVALID_DATA_ERR
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
OnSendMessage003
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
MockSessionImpl
>
sessionMock
=
std
::
make_shared
<
MockSessionImpl
>
();
std
::
shared_ptr
<
DBinderSessionObject
>
sessionOfPeer
=
std
::
make_shared
<
DBinderSessionObject
>
(
sessionMock
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
int
ret
=
testInvoker
.
OnSendMessage
(
sessionOfPeer
);
EXPECT_EQ
(
ret
,
ERR_NONE
);
}
/**
* @tc.name: OnSendRawData001
* @tc.desc: OnSendRawData return RPC_DATABUS_INVOKER_INVALID_DATA_ERR
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
OnSendRawData001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
DBinderSessionObject
>
session
=
nullptr
;
size_t
size
=
0
;
int
ret
=
testInvoker
.
OnSendRawData
(
session
,
nullptr
,
size
);
EXPECT_EQ
(
ret
,
-
RPC_DATABUS_INVOKER_INVALID_DATA_ERR
);
}
/**
* @tc.name: OnSendRawData002
* @tc.desc: OnSendRawData return RPC_DATABUS_INVOKER_INVALID_DATA_ERR
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
OnSendRawData002
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
DBinderSessionObject
>
session
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
size_t
size
=
0
;
int
ret
=
testInvoker
.
OnSendRawData
(
session
,
nullptr
,
size
);
EXPECT_EQ
(
ret
,
-
RPC_DATABUS_INVOKER_INVALID_DATA_ERR
);
}
/**
* @tc.name: OnSendRawData003
* @tc.desc: OnSendRawData return 0
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
OnSendRawData003
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
MockSessionImpl
>
sessionMock
=
std
::
make_shared
<
MockSessionImpl
>
();
std
::
shared_ptr
<
DBinderSessionObject
>
session
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
session
->
session_
=
sessionMock
;
size_t
size
=
0
;
int
ret
=
testInvoker
.
OnSendRawData
(
session
,
nullptr
,
size
);
EXPECT_EQ
(
ret
,
0
);
}
/**
* @tc.name: SetCallerPid001
* @tc.desc: SetCallerPid
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
SetCallerPid001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
pid_t
pid
=
1
;
testInvoker
.
SetCallerPid
(
pid
);
EXPECT_EQ
(
1
,
testInvoker
.
callerPid_
);
}
/**
* @tc.name: GetCallerUid001
* @tc.desc: GetCallerUid
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
GetCallerUid001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
pid_t
uid
=
1
;
testInvoker
.
SetCallerUid
(
uid
);
uid_t
test
=
testInvoker
.
GetCallerUid
();
EXPECT_EQ
(
test
,
testInvoker
.
callerUid_
);
}
/**
* @tc.name: SetCallerUid001
* @tc.desc: SetCallerUid
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
SetCallerUid001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
pid_t
uid
=
1
;
testInvoker
.
SetCallerUid
(
uid
);
EXPECT_EQ
(
1
,
testInvoker
.
callerUid_
);
}
/**
* @tc.name: SetCallerDeviceID001
* @tc.desc: SetCallerDeviceID
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
SetCallerDeviceID001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
const
std
::
string
deviceId
=
"test"
;
testInvoker
.
SetCallerDeviceID
(
deviceId
);
EXPECT_EQ
(
"test"
,
testInvoker
.
callerDeviceID_
);
}
/**
* @tc.name: SetCallerTokenID001
* @tc.desc: SetCallerTokenID
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
SetCallerTokenID001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
const
uint32_t
tokenId
=
1
;
testInvoker
.
SetCallerTokenID
(
tokenId
);
uint64_t
id
=
1
;
EXPECT_EQ
(
id
,
testInvoker
.
callerTokenID_
);
}
/**
* @tc.name: ConnectRemoteObject2Session001
* @tc.desc: ConnectRemoteObject2Session
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
ConnectRemoteObject2Session001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
IRemoteObject
*
stubObject
=
nullptr
;
uint64_t
stubIndex
=
1
;
const
std
::
shared_ptr
<
DBinderSessionObject
>
sessionObject
=
nullptr
;
bool
test
=
testInvoker
.
ConnectRemoteObject2Session
(
stubObject
,
stubIndex
,
sessionObject
);
EXPECT_TRUE
(
sessionObject
==
nullptr
);
EXPECT_EQ
(
test
,
false
);
}
/**
* @tc.name: FlattenSession001
* @tc.desc: FlattenSession return 0
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
FlattenSession001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
string
serverDeviceId
;
std
::
shared_ptr
<
DBinderSessionObject
>
session
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
serverDeviceId
,
1
,
nullptr
,
1
);
FlatDBinderSession
flatDBinderSession
;
char
*
sessionOffset
=
reinterpret_cast
<
char
*>
(
&
flatDBinderSession
);
uint64_t
stubIndex
=
0
;
uint32_t
ret
=
testInvoker
.
FlattenSession
(
sessionOffset
,
session
,
stubIndex
);
EXPECT_EQ
(
ret
,
0
);
serverDeviceId
=
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
;
ret
=
testInvoker
.
FlattenSession
(
sessionOffset
,
session
,
stubIndex
);
EXPECT_EQ
(
ret
,
0
);
}
/**
* @tc.name: FlattenSession002
* @tc.desc: FlattenSession return 0
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
FlattenSession002
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
string
serviceName
;
std
::
shared_ptr
<
DBinderSessionObject
>
session
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
serviceName
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
FlatDBinderSession
flatDBinderSession
;
char
*
sessionOffset
=
reinterpret_cast
<
char
*>
(
&
flatDBinderSession
);
uint64_t
stubIndex
=
0
;
uint32_t
ret
=
testInvoker
.
FlattenSession
(
sessionOffset
,
session
,
stubIndex
);
EXPECT_EQ
(
ret
,
0
);
serviceName
=
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
;
ret
=
testInvoker
.
FlattenSession
(
sessionOffset
,
session
,
stubIndex
);
EXPECT_EQ
(
ret
,
0
);
}
/**
* @tc.name: FlattenSession003
* @tc.desc: FlattenSession return 0
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
FlattenSession003
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
DBinderSessionObject
>
session
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
FlatDBinderSession
flatDBinderSession
;
char
*
sessionOffset
=
reinterpret_cast
<
char
*>
(
&
flatDBinderSession
);
uint64_t
stubIndex
=
0
;
uint32_t
ret
=
testInvoker
.
FlattenSession
(
sessionOffset
,
session
,
stubIndex
);
EXPECT_EQ
(
ret
,
280
);
}
/**
* @tc.name: UnFlattenSession001
* @tc.desc: UnFlattenSession return nullptr
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
UnFlattenSession001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
uint64_t
stubIndex
=
0
;
FlatDBinderSession
flatDBinderSession
;
flatDBinderSession
.
stubIndex
=
0
;
char
*
sessionOffset
=
reinterpret_cast
<
char
*>
(
&
flatDBinderSession
);
std
::
shared_ptr
<
DBinderSessionObject
>
ret
=
testInvoker
.
UnFlattenSession
(
sessionOffset
,
stubIndex
);
EXPECT_EQ
(
ret
,
nullptr
);
}
/**
* @tc.name: UnFlattenSession002
* @tc.desc: UnFlattenSession return nullptr
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
UnFlattenSession002
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
uint64_t
stubIndex
=
0
;
FlatDBinderSession
flatDBinderSession
;
int
len
=
65
;
strcpy_s
(
flatDBinderSession
.
serviceName
,
len
,
"testServiceName"
);
strcpy_s
(
flatDBinderSession
.
deviceId
,
len
,
"testDeviceId"
);
char
*
sessionOffset
=
reinterpret_cast
<
char
*>
(
&
flatDBinderSession
);
std
::
shared_ptr
<
DBinderSessionObject
>
ret
=
testInvoker
.
UnFlattenSession
(
sessionOffset
,
stubIndex
);
EXPECT_EQ
(
ret
,
nullptr
);
}
/**
* @tc.name: QueryHandleBySession001
* @tc.desc: QueryHandleBySession return 0
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
QueryHandleBySession001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
std
::
shared_ptr
<
DBinderSessionObject
>
session
=
std
::
make_shared
<
DBinderSessionObject
>
(
nullptr
,
SERVICE_NAME_TEST
,
DEVICE_ID_TEST
,
1
,
nullptr
,
1
);
uint32_t
ret
=
testInvoker
.
QueryHandleBySession
(
session
);
EXPECT_EQ
(
ret
,
1
);
}
/**
* @tc.name: MakeStubIndexByRemoteObject001
* @tc.desc: MakeStubIndexByRemoteObject return 0
* @tc.type: FUNC
*/
HWTEST_F
(
IPCDbinderDataBusInvokerTest
,
MakeStubIndexByRemoteObject001
,
TestSize
.
Level1
)
{
DBinderDatabusInvoker
testInvoker
;
IPCObjectProxy
*
iPCObjectProxy
=
nullptr
;
uint32_t
ret
=
testInvoker
.
MakeStubIndexByRemoteObject
(
iPCObjectProxy
);
EXPECT_EQ
(
ret
,
0
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录