未验证 提交 b4e53a63 编写于 作者: 马根堂 提交者: Gitee

回退 'Pull Request !472 : [master]increase ipc ut branch'

上级 455995d5
......@@ -20,24 +20,9 @@ MODULE_OUTPUT_PATH = "ipc"
ohos_unittest("IPCNativeUnitTest") {
module_out_path = MODULE_OUTPUT_PATH
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",
]
include_dirs = [ "//utils/system/safwk/native/include" ]
sources = [
"buffer_object_unittest.cpp",
"databus_session_callback_unittest.cpp",
"dbinder_callback_stub_unittest.cpp",
"dbinder_session_object_unittest.cpp",
"ipc_core_unittest.cpp",
"ipc_object_proxy_unittest.cpp",
"ipc_process_skeleton_unittest.cpp",
]
sources = [ "ipc_core_unittest.cpp" ]
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
......@@ -46,7 +31,6 @@ ohos_unittest("IPCNativeUnitTest") {
deps = [
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
......@@ -70,66 +54,6 @@ ohos_unittest("IPCFileDescOpsTest") {
"$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",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
resource_config_file =
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
}
ohos_unittest("BinderConnectorTest") {
module_out_path = MODULE_OUTPUT_PATH
include_dirs = [ "//utils/system/safwk/native/include" ]
sources = [ "ipc_connector_unittest.cpp" ]
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
]
deps = [
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
resource_config_file =
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
}
ohos_unittest("BinderInvokerUnitTest") {
module_out_path = MODULE_OUTPUT_PATH
include_dirs = [
"//utils/system/safwk/native/include",
"//foundation/communication/ipc/ipc/native/c/adapter/access_token/include",
"//foundation/communication/ipc/ipc/native/c/rpc/include",
]
sources = [ "binder_invoker_unittest.cpp" ]
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
]
deps = [
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gtest_main",
......@@ -137,10 +61,8 @@ ohos_unittest("BinderInvokerUnitTest") {
external_deps = [
"c_utils:utils",
"hitrace_native:libhitracechain",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
resource_config_file =
......@@ -161,7 +83,6 @@ ohos_unittest("IPCHiTraceUnitTest") {
deps = [
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
......@@ -191,7 +112,6 @@ if (support_jsapi) {
deps = [
"//foundation/arkui/napi:ace_napi",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
......@@ -205,52 +125,12 @@ if (support_jsapi) {
}
}
ohos_unittest("IPCMockUnitTest") {
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 = [ "ipc_binder_databus_invoker_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") {
testonly = true
deps = [
":BinderConnectorTest",
":BinderInvokerUnitTest",
":IPCFileDescOpsTest",
":IPCHiTraceUnitTest",
":IPCMockUnitTest",
":IPCNativeUnitTest",
]
if (support_jsapi) {
......
/*
* 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 "access_token_adapter.h"
#define private public
#define protected public
#include "binder_invoker.h"
#undef protected
#undef private
#include "ipc_object_proxy.h"
#include "ipc_object_stub.h"
#include "ipc_process_skeleton.h"
using namespace testing::ext;
using namespace OHOS;
class BinderInvokerUnitTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void BinderInvokerUnitTest::SetUpTestCase()
{}
void BinderInvokerUnitTest::TearDownTestCase()
{}
void BinderInvokerUnitTest::SetUp()
{}
void BinderInvokerUnitTest::TearDown()
{}
/**
* @tc.name: SetCallingIdentity001
* @tc.desc: Verify the ReadFileDescriptor function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, SetCallingIdentity001, TestSize.Level1)
{
BinderInvoker binderInvoker;
std::string identity;
bool ret = binderInvoker.SetCallingIdentity(identity);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: ReadFileDescriptor001
* @tc.desc: Verify the ReadFileDescriptor function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, ReadFileDescriptor001, TestSize.Level1)
{
BinderInvoker binderInvoker;
Parcel parcel;
int ret = binderInvoker.ReadFileDescriptor(parcel);
EXPECT_EQ(ret, -1);
}
/**
* @tc.name: UnflattenObject001
* @tc.desc: Verify the UnflattenObject function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, UnflattenObject001, TestSize.Level1)
{
BinderInvoker binderInvoker;
Parcel parcel;
sptr<IRemoteObject> ret = binderInvoker.UnflattenObject(parcel);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: GetCallerTokenID001
* @tc.desc: Verify the GetCallerTokenID function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, GetCallerTokenID001, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.firstTokenID_ = 0;
int ret = binderInvoker.GetFirstTokenID();
EXPECT_EQ(ret, (uint32_t)RpcGetFirstCallerTokenID());
}
/**
* @tc.name: SetRegistryObject001
* @tc.desc: Verify the SetRegistryObject function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, SetRegistryObject001, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.binderConnector_->driverFD_ = 0;
sptr<IRemoteObject> testStub = new IPCObjectStub(u"testStub");
bool ret = binderInvoker.SetRegistryObject(testStub);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: SetRegistryObject002
* @tc.desc: Verify the SetRegistryObject function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, SetRegistryObject002, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.binderConnector_ = nullptr;
sptr<IRemoteObject> testStub = new IPCObjectStub(u"testStub");
bool ret = binderInvoker.SetRegistryObject(testStub);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: SetRegistryObject003
* @tc.desc: Verify the SetRegistryObject function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, SetRegistryObject003, TestSize.Level1)
{
BinderInvoker binderInvoker;
sptr<IRemoteObject> testProxy = new IPCObjectProxy(5, u"testproxy");
bool ret = binderInvoker.SetRegistryObject(testProxy);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: TranslateProxyTest001
* @tc.desc: Verify the TranslateProxy function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, TranslateProxyTest001, TestSize.Level1)
{
#ifndef CONFIG_IPC_SINGLE
BinderInvoker binderInvoker;
binderInvoker.binderConnector_ = nullptr;
EXPECT_EQ(binderInvoker.TranslateProxy(0, 0), -IPC_INVOKER_CONNECT_ERR);
#endif
}
/**
* @tc.name: TranslateProxyTest002
* @tc.desc: Verify the TranslateProxy function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, TranslateProxyTest002, TestSize.Level1)
{
#ifndef CONFIG_IPC_SINGLE
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.TranslateProxy(1, 0), -IPC_INVOKER_TRANSLATE_ERR);
#endif
}
/**
* @tc.name: TranslateStubTest001
* @tc.desc: Verify the TranslateStub function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, TranslateStubTest001, TestSize.Level1)
{
#ifndef CONFIG_IPC_SINGLE
BinderInvoker binderInvoker;
binderInvoker.binderConnector_ = nullptr;
EXPECT_EQ(binderInvoker.TranslateStub(0, 0, 0, 0), -IPC_INVOKER_CONNECT_ERR);
#endif
}
/**
* @tc.name: TranslateStubTest002
* @tc.desc: Verify the TranslateStub function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, TranslateStubTest002, TestSize.Level1)
{
#ifndef CONFIG_IPC_SINGLE
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.TranslateStub(60, 90, 0, 0), -IPC_INVOKER_TRANSLATE_ERR);
#endif
}
/**
* @tc.name: GetSAMgrObjectTest001
* @tc.desc: Verify the GetSAMgrObject function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, GetSAMgrObjectTest001, TestSize.Level1)
{
#ifndef CONFIG_IPC_SINGLE
BinderInvoker binderInvoker;
IPCProcessSkeleton* current = IPCProcessSkeleton::GetCurrent();
if (current != nullptr) {
EXPECT_EQ(binderInvoker.GetSAMgrObject(), current->GetRegistryObject());
} else {
EXPECT_EQ(binderInvoker.GetSAMgrObject(), nullptr);
}
#endif
}
/**
* @tc.name: SetMaxWorkThreadTest001
* @tc.desc: Verify the SetMaxWorkThread function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, SetMaxWorkThreadTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.binderConnector_ = nullptr;
EXPECT_EQ(binderInvoker.SetMaxWorkThread(10), false);
}
/**
* @tc.name: FlushCommandsTest001
* @tc.desc: Verify the FlushCommands function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, FlushCommandsTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.binderConnector_ = nullptr;
EXPECT_EQ(binderInvoker.FlushCommands(nullptr), IPC_INVOKER_CONNECT_ERR);
}
/**
* @tc.name: ExitCurrentThreadTest001
* @tc.desc: Verify the ExitCurrentThread function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, ExitCurrentThreadTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.binderConnector_ = nullptr;
binderInvoker.ExitCurrentThread();
EXPECT_EQ(true, true);
}
/**
* @tc.name: OnAttemptAcquireTest001
* @tc.desc: Verify the OnAttemptAcquire function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, OnAttemptAcquireTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
binderInvoker.input_.WritePointer((uintptr_t)testStub.GetRefPtr());
binderInvoker.OnAttemptAcquire();
EXPECT_EQ(true, true);
}
/**
* @tc.name: HandleReplyTest001
* @tc.desc: Verify the HandleReply function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, HandleReplyTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.HandleReply(nullptr), IPC_INVOKER_INVALID_DATA_ERR);
}
/**
* @tc.name: HandleReplyTest002
* @tc.desc: Verify the HandleReply function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, HandleReplyTest002, TestSize.Level1)
{
binder_transaction_data transactionData;
BinderInvoker binderInvoker;
binderInvoker.input_.WriteBuffer(&transactionData, sizeof(binder_transaction_data));
EXPECT_EQ(binderInvoker.HandleReply(nullptr), IPC_INVOKER_INVALID_REPLY_ERR);
}
/**
* @tc.name: HandleCommandsInnerTest001
* @tc.desc: Verify the HandleCommandsInner function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_ERROR), ERR_NONE);
}
/**
* @tc.name: HandleCommandsInnerTest002
* @tc.desc: Verify the HandleCommandsInner function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest002, TestSize.Level1)
{
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_ATTEMPT_ACQUIRE), ERR_NONE);
}
/**
* @tc.name: HandleCommandsInnerTest003
* @tc.desc: Verify the HandleCommandsInner function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest003, TestSize.Level1)
{
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_TRANSACTION), IPC_INVOKER_INVALID_DATA_ERR);
}
/**
* @tc.name: HandleCommandsInnerTest004
* @tc.desc: Verify the HandleCommandsInner function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest004, TestSize.Level1)
{
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_SPAWN_LOOPER), ERR_NONE);
}
/**
* @tc.name: HandleCommandsInnerTest005
* @tc.desc: Verify the HandleCommandsInner function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest005, TestSize.Level1)
{
BinderInvoker binderInvoker;
EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_FINISHED), -ERR_TIMED_OUT);
}
/**
* @tc.name: JoinProcessThreadTest001
* @tc.desc: Verify the JoinProcessThread function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, JoinProcessThreadTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.JoinProcessThread(false);
EXPECT_EQ(true, true);
}
/**
* @tc.name: TransactWithDriverTest001
* @tc.desc: Verify the TransactWithDriver function
* @tc.type: FUNC
*/
HWTEST_F(BinderInvokerUnitTest, TransactWithDriverTest001, TestSize.Level1)
{
BinderInvoker binderInvoker;
binderInvoker.binderConnector_ = nullptr;
EXPECT_EQ(binderInvoker.TransactWithDriver(true), IPC_INVOKER_CONNECT_ERR);
}
\ No newline at end of file
/*
* 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 "buffer_object.h"
#include "ipc_types.h"
#undef private
using namespace testing::ext;
using namespace OHOS;
namespace {
constexpr uint32_t BUFF_SIZE_TEST = 128;
constexpr ssize_t BUFFER_WRITE_CURSOR_TEST = 8;
constexpr ssize_t BUFFER_READ_CURSOR_TEST = 6;
}
class BufferObjectUnitTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void BufferObjectUnitTest::SetUpTestCase()
{
}
void BufferObjectUnitTest::TearDownTestCase()
{
}
void BufferObjectUnitTest::SetUp() {}
void BufferObjectUnitTest::TearDown() {}
/**
* @tc.name: UpdateSendBufferTest001
* @tc.desc: Verify the UpdateSendBuffer function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, UpdateSendBufferTest001, TestSize.Level1)
{
BufferObject object;
object.SetSendBufferWriteCursor(1);
object.SetSendBufferReadCursor(1);
object.UpdateSendBuffer();
EXPECT_EQ(object.GetSendBufferReadCursor(), 0);
EXPECT_EQ(object.GetSendBufferWriteCursor(), 0);
}
/**
* @tc.name: UpdateSendBufferTest002
* @tc.desc: Verify the UpdateSendBuffer function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, UpdateSendBufferTest002, TestSize.Level1)
{
BufferObject object;
object.sendBuffSize_ = BUFF_SIZE_TEST;
object.SetSendBufferWriteCursor(BUFFER_WRITE_CURSOR_TEST);
object.SetSendBufferReadCursor(BUFFER_READ_CURSOR_TEST);
object.sendBuffer_ = new (std::nothrow) char[BUFF_SIZE_TEST]();
object.UpdateSendBuffer();
EXPECT_EQ(object.GetSendBufferWriteCursor(),
BUFFER_WRITE_CURSOR_TEST - BUFFER_READ_CURSOR_TEST);
}
/**
* @tc.name: UpdateSendBufferTest003
* @tc.desc: Verify the UpdateSendBuffer function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, UpdateSendBufferTest003, TestSize.Level1)
{
BufferObject object;
object.sendBuffSize_ = BUFF_SIZE_TEST;
object.SetSendBufferWriteCursor(BUFFER_WRITE_CURSOR_TEST);
object.SetSendBufferReadCursor(BUFFER_READ_CURSOR_TEST);
object.UpdateSendBuffer();
EXPECT_EQ(object.GetSendBufferReadCursor(), 0);
EXPECT_EQ(object.GetSendBufferWriteCursor(), 0);
}
/**
* @tc.name: UpdateReceiveBufferTest001
* @tc.desc: Verify the UpdateReceiveBuffer function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, UpdateReceiveBufferTest001, TestSize.Level1)
{
BufferObject object;
object.SetReceiveBufferWriteCursor(1);
object.SetReceiveBufferReadCursor(1);
object.UpdateReceiveBuffer();
EXPECT_EQ(object.GetReceiveBufferReadCursor(), 0);
EXPECT_EQ(object.GetReceiveBufferWriteCursor(), 0);
}
/**
* @tc.name: UpdateReceiveBufferTest002
* @tc.desc: Verify the UpdateReceiveBuffer function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, UpdateReceiveBufferTest002, TestSize.Level1)
{
BufferObject object;
object.recvBuffSize_ = BUFF_SIZE_TEST;
object.SetReceiveBufferWriteCursor(BUFFER_WRITE_CURSOR_TEST);
object.SetReceiveBufferReadCursor(BUFFER_READ_CURSOR_TEST);
object.receiveBuffer_ = new (std::nothrow)char[BUFF_SIZE_TEST]();
object.UpdateReceiveBuffer();
EXPECT_EQ(object.GetReceiveBufferWriteCursor(),
BUFFER_WRITE_CURSOR_TEST - BUFFER_READ_CURSOR_TEST);
}
/**
* @tc.name: UpdateReceiveBufferTest003
* @tc.desc: Verify the UpdateReceiveBuffer function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, UpdateReceiveBufferTest003, TestSize.Level1)
{
BufferObject object;
object.recvBuffSize_ = BUFF_SIZE_TEST;
object.SetReceiveBufferWriteCursor(BUFFER_WRITE_CURSOR_TEST);
object.SetReceiveBufferReadCursor(BUFFER_READ_CURSOR_TEST);
object.UpdateReceiveBuffer();
EXPECT_EQ(object.GetReceiveBufferReadCursor(), 0);
EXPECT_EQ(object.GetReceiveBufferWriteCursor(), 0);
}
/**
* @tc.name: GetSendBufferAndLockTest001
* @tc.desc: Verify the GetSendBufferAndLock function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetSendBufferAndLockTest001, TestSize.Level1)
{
BufferObject object;
object.sendBuffSize_ = BUFF_SIZE_TEST;
char * buffer = object.GetSendBufferAndLock(SOCKET_BUFF_SIZE_USER_HUGE + 1);
EXPECT_EQ(buffer, nullptr);
}
/**
* @tc.name: GetSendBufferAndLockTest002
* @tc.desc: Verify the GetSendBufferAndLock function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetSendBufferAndLockTest002, TestSize.Level1)
{
BufferObject object;
object.sendBuffSize_ = BUFF_SIZE_TEST;
object.sendBuffer_ = new (std::nothrow) char[BUFF_SIZE_TEST]();
char * buffer = object.GetSendBufferAndLock(SOCKET_BUFF_SIZE_USER_S);
EXPECT_NE(buffer, nullptr);
EXPECT_EQ(object.GetSendBufferSize(), SOCKET_BUFF_SIZE_USER_S);
}
/**
* @tc.name: GetSendBufferAndLockTest003
* @tc.desc: Verify the GetSendBufferAndLock function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetSendBufferAndLockTest003, TestSize.Level1)
{
BufferObject object;
object.sendBuffSize_ = 0;
object.sendBuffer_ = new (std::nothrow) char[BUFF_SIZE_TEST]();
char * buffer = object.GetSendBufferAndLock(SOCKET_BUFF_SIZE_USER_S);
EXPECT_NE(buffer, nullptr);
}
/**
* @tc.name: GetReceiveBufferAndLockTest001
* @tc.desc: Verify the GetReceiveBufferAndLock function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetReceiveBufferAndLockTest001, TestSize.Level1)
{
BufferObject object;
object.recvBuffSize_ = BUFF_SIZE_TEST;
char * buffer = object.GetReceiveBufferAndLock(SOCKET_BUFF_SIZE_USER_HUGE + 1);
EXPECT_EQ(buffer, nullptr);
}
/**
* @tc.name: GetReceiveBufferAndLockTest002
* @tc.desc: Verify the GetReceiveBufferAndLock function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetReceiveBufferAndLockTest002, TestSize.Level1)
{
BufferObject object;
object.recvBuffSize_ = BUFF_SIZE_TEST;
object.receiveBuffer_ = new (std::nothrow) char[BUFF_SIZE_TEST]();
char * buffer = object.GetReceiveBufferAndLock(SOCKET_BUFF_SIZE_USER_S);
EXPECT_NE(buffer, nullptr);
EXPECT_EQ(object.GetRecvBufferSize(), SOCKET_BUFF_SIZE_USER_S);
}
/**
* @tc.name: GetReceiveBufferAndLockTest003
* @tc.desc: Verify the GetReceiveBufferAndLock function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetReceiveBufferAndLockTest003, TestSize.Level1)
{
BufferObject object;
object.recvBuffSize_ = 0;
object.receiveBuffer_ = new (std::nothrow) char[BUFF_SIZE_TEST]();
char * buffer = object.GetReceiveBufferAndLock(SOCKET_BUFF_SIZE_USER_S);
EXPECT_NE(buffer, nullptr);
}
/**
* @tc.name: SetSendBufferWriteCursorTest001
* @tc.desc: Verify the SetSendBufferWriteCursor function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, SetSendBufferWriteCursorTest001, TestSize.Level1)
{
BufferObject object;
object.SetSendBufferWriteCursor(1);
EXPECT_EQ(object.GetSendBufferWriteCursor(), 1);
}
/**
* @tc.name: SetSendBufferReadTest001
* @tc.desc: Verify the SetSendBufferRead function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, SetSendBufferReadTest001, TestSize.Level1)
{
BufferObject object;
object.SetSendBufferReadCursor(1);
EXPECT_EQ(object.GetSendBufferReadCursor(), 1);
}
/**
* @tc.name: SetReceiveBufferWriteCursorTest001
* @tc.desc: Verify the SetReceiveBufferWriteCursor function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, SetReceiveBufferWriteCursorTest001, TestSize.Level1)
{
BufferObject object;
object.SetReceiveBufferWriteCursor(1);
EXPECT_EQ(object.GetReceiveBufferWriteCursor(), 1);
}
/**
* @tc.name: SetReceiveBufferReadCursorTest001
* @tc.desc: Verify the SetReceiveBufferReadCursor function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, SetReceiveBufferReadCursorTest001, TestSize.Level1)
{
BufferObject object;
object.SetReceiveBufferReadCursor(1);
EXPECT_EQ(object.GetReceiveBufferReadCursor(), 1);
}
/**
* @tc.name: GetNeedBufferSizeTest001
* @tc.desc: Verify the GetNeedBufferSize function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetNeedBufferSizeTest001, TestSize.Level1)
{
BufferObject object;
EXPECT_EQ(object.GetNeedBufferSize(SOCKET_BUFF_SIZE_USER_S), SOCKET_BUFF_SIZE_USER_S);
}
/**
* @tc.name: GetNeedBufferSizeTest002
* @tc.desc: Verify the GetNeedBufferSize function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetNeedBufferSizeTest002, TestSize.Level1)
{
BufferObject object;
EXPECT_EQ(object.GetNeedBufferSize(SOCKET_BUFF_SIZE_USER_M), SOCKET_BUFF_SIZE_USER_M);
}
/**
* @tc.name: GetNeedBufferSizeTest003
* @tc.desc: Verify the GetNeedBufferSize function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetNeedBufferSizeTest003, TestSize.Level1)
{
BufferObject object;
EXPECT_EQ(object.GetNeedBufferSize(SOCKET_BUFF_SIZE_USER_L), SOCKET_BUFF_SIZE_USER_L);
}
/**
* @tc.name: GetNeedBufferSizeTest004
* @tc.desc: Verify the GetNeedBufferSize function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetNeedBufferSizeTest004, TestSize.Level1)
{
BufferObject object;
EXPECT_EQ(object.GetNeedBufferSize(SOCKET_BUFF_SIZE_USER_HUGE), SOCKET_BUFF_SIZE_USER_HUGE);
}
/**
* @tc.name: GetNeedBufferSizeTest005
* @tc.desc: Verify the GetNeedBufferSize function
* @tc.type: FUNC
*/
HWTEST_F(BufferObjectUnitTest, GetNeedBufferSizeTest005, TestSize.Level1)
{
BufferObject object;
uint32_t ret = 0;
EXPECT_EQ(object.GetNeedBufferSize(SOCKET_BUFF_SIZE_USER_HUGE + 1), ret);
}
\ No newline at end of file
/*
* 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>
#include "databus_session_callback.h"
#include "ipc_types.h"
#include "mock_session_impl.h"
using namespace testing::ext;
using namespace OHOS;
namespace {
constexpr int UID_TEST = 100;
constexpr int PID_TEST = 200;
const std::string DEVICE_ID_TEST = "deviceidTest";
const std::string SESSION_NAME_TEST = "sessionNameTest";
const std::string PEER_SESSION_NAME_TEST = "PeersessionNameTest";
}
class DbSessionCallbackUnitTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void DbSessionCallbackUnitTest::SetUpTestCase()
{
}
void DbSessionCallbackUnitTest::TearDownTestCase()
{
}
void DbSessionCallbackUnitTest::SetUp() {}
void DbSessionCallbackUnitTest::TearDown() {}
/**
* @tc.name: OnSessionOpenedTest001
* @tc.desc: Verify the OnSessionOpened function
* @tc.type: FUNC
*/
HWTEST_F(DbSessionCallbackUnitTest, OnSessionOpenedTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.Times(1)
.WillOnce(testing::Return(-1));
DatabusSessionCallback dbSessionCallback;
int ret = dbSessionCallback.OnSessionOpened(session);
EXPECT_EQ(ret, SESSION_WRONG_FD_ERR);
}
/**
* @tc.name: OnSessionOpenedTest002
* @tc.desc: Verify the OnSessionOpened function
* @tc.type: FUNC
*/
HWTEST_F(DbSessionCallbackUnitTest, OnSessionOpenedTest002, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.Times(1)
.WillOnce(testing::Return(1));
EXPECT_CALL(*session, IsServerSide())
.Times(1)
.WillOnce(testing::Return(false));
DatabusSessionCallback dbSessionCallback;
int ret = dbSessionCallback.OnSessionOpened(session);
EXPECT_EQ(ret, 0);
}
/**
* @tc.name: OnSessionOpenedTest003
* @tc.desc: Verify the OnSessionOpened function
* @tc.type: FUNC
*/
HWTEST_F(DbSessionCallbackUnitTest, OnSessionOpenedTest003, 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));
DatabusSessionCallback dbSessionCallback;
int ret = dbSessionCallback.OnSessionOpened(session);
EXPECT_EQ(ret, SESSION_UNOPEN_ERR);
char data[] = "testdata";
ssize_t len = strlen(data);
dbSessionCallback.OnBytesReceived(session, data, len);
dbSessionCallback.OnSessionClosed(session);
}
\ No newline at end of file
/*
* 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>
#include "dbinder_callback_stub.h"
#include "ipc_types.h"
using namespace testing::ext;
using namespace OHOS;
namespace {
const std::string SERVICE_TEST = "serviceTest";
const std::string DEVICE_TEST = "deviceTest";
const std::string LOCALDEVICE_TEST = "localDeviceTest";
constexpr uint64_t STUBINDEX_TEST = 1;
constexpr uint32_t HANDLE_TEST = 1;
}
class DBinderCallbackStubTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
sptr<DBinderCallbackStub> fakeStub_;
};
void DBinderCallbackStubTest::SetUpTestCase()
{
}
void DBinderCallbackStubTest::TearDownTestCase()
{
}
void DBinderCallbackStubTest::SetUp()
{
std::shared_ptr<FeatureSetData> feature = std::make_shared<FeatureSetData>();
fakeStub_ = new (std::nothrow) DBinderCallbackStub(
SERVICE_TEST, DEVICE_TEST, LOCALDEVICE_TEST, STUBINDEX_TEST, HANDLE_TEST, feature);
}
void DBinderCallbackStubTest::TearDown()
{
}
/**
* @tc.name: GetServiceNameTest001
* @tc.desc: Verify the GetServiceName function
* @tc.type: FUNC
*/
HWTEST_F(DBinderCallbackStubTest, GetServiceNameTest001, TestSize.Level1)
{
ASSERT_TRUE(fakeStub_ != nullptr);
std::string ret = fakeStub_->GetServiceName();
EXPECT_STREQ(ret.c_str(), SERVICE_TEST.c_str());
}
/**
* @tc.name:GetFeatureSetTest001
* @tc.desc: Verify the GetFeatureSet function
* @tc.type: FUNC
*/
HWTEST_F(DBinderCallbackStubTest, GetFeatureSetTest001, TestSize.Level1)
{
ASSERT_TRUE(fakeStub_ != nullptr);
std::shared_ptr<FeatureSetData> ret = fakeStub_->GetFeatureSet();
EXPECT_NE(ret, nullptr);
}
/**
* @tc.name:GetDeviceIDTest001
* @tc.desc: Verify the GetDeviceID function
* @tc.type: FUNC
*/
HWTEST_F(DBinderCallbackStubTest, GetDeviceIDTest001, TestSize.Level1)
{
ASSERT_TRUE(fakeStub_ != nullptr);
std::string ret = fakeStub_->GetDeviceID();
EXPECT_STREQ(ret.c_str(), DEVICE_TEST.c_str());
}
/**
* @tc.name:GetStubIndexTest001
* @tc.desc: Verify the GetStubIndex function
* @tc.type: FUNC
*/
HWTEST_F(DBinderCallbackStubTest, GetStubIndexTest001, TestSize.Level1)
{
ASSERT_TRUE(fakeStub_ != nullptr);
uint64_t ret = fakeStub_->GetStubIndex();
EXPECT_EQ(ret, STUBINDEX_TEST);
}
/**
* @tc.name: ProcessProtoTest001
* @tc.desc: Verify the ProcessProto function
* @tc.type: FUNC
*/
HWTEST_F(DBinderCallbackStubTest, ProcessProtoTest001, TestSize.Level1)
{
ASSERT_TRUE(fakeStub_ != nullptr);
uint32_t code = GET_PROTO_INFO;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int32_t ret = fakeStub_->ProcessProto(code, data, reply, option);
EXPECT_EQ(ret, DBINDER_SERVICE_WRONG_SESSION);
}
/**
* @tc.name: OnRemoteRequestTest001
* @tc.desc: Verify the OnRemoteRequest function
* @tc.type: FUNC
*/
HWTEST_F(DBinderCallbackStubTest, OnRemoteRequestTest001, TestSize.Level1)
{
ASSERT_TRUE(fakeStub_ != nullptr);
uint32_t code = GET_PROTO_INFO;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int32_t ret = fakeStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, DBINDER_SERVICE_WRONG_SESSION);
}
/**
* @tc.name: OnRemoteRequestTest002
* @tc.desc: Verify the OnRemoteRequest function
* @tc.type: FUNC
*/
HWTEST_F(DBinderCallbackStubTest, OnRemoteRequestTest002, TestSize.Level1)
{
ASSERT_TRUE(fakeStub_ != nullptr);
uint32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int32_t ret = fakeStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, DBINDER_CALLBACK_ERR);
}
\ No newline at end of file
/*
* 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>
#include "dbinder_session_object.h"
#include "ipc_types.h"
#include "mock_session_impl.h"
using namespace testing::ext;
using namespace OHOS;
namespace {
const std::string SERVICE_TEST = "serviceTest";
const std::string DEVICE_TEST = "deviceTest";
const std::string LOCALDEVICE_TEST = "localDeviceTest";
}
class DBinderSessionObjectTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void DBinderSessionObjectTest::SetUpTestCase()
{
}
void DBinderSessionObjectTest::TearDownTestCase()
{
}
void DBinderSessionObjectTest::SetUp()
{
}
void DBinderSessionObjectTest::TearDown()
{
}
/**
* @tc.name: SetBusSessionTest001
* @tc.desc: Verify the DBinderSessionObject::SetBusSession function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, SetBusSessionTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(sessionMock, serviceName, serverDeviceId);
object.SetBusSession(sessionMock);
auto session = object.GetBusSession();
EXPECT_NE(session, nullptr);
}
/**
* @tc.name: GetBusSessionTest001
* @tc.desc: Verify the DBinderSessionObject::GetBusSession function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, GetBusSessionTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(sessionMock, serviceName, serverDeviceId);
EXPECT_CALL(*sessionMock, GetChannelId())
.Times(1)
.WillOnce(testing::Return(1));
EXPECT_CALL(*sessionMock, GetSessionId())
.Times(1)
.WillOnce(testing::Return(1));
auto session = object.GetBusSession();
EXPECT_NE(session, nullptr);
object.CloseDatabusSession();
}
/**
* @tc.name: GetSessionBuffTest001
* @tc.desc: Verify the DBinderSessionObject::GetSessionBuff function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, GetSessionBuffTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(sessionMock, serviceName, serverDeviceId);
std::shared_ptr<BufferObject> buffer = object.GetSessionBuff();
EXPECT_NE(buffer, nullptr);
}
/**
* @tc.name: SetServiceNameTest001
* @tc.desc: Verify the DBinderSessionObject::SetServiceName function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, SetServiceNameTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(session, serviceName, serverDeviceId);
std::string name = "testname";
object.SetServiceName(name);
EXPECT_STREQ(name.c_str(), object.GetServiceName().c_str());
}
/**
* @tc.name: SetDeviceIdTest001
* @tc.desc: Verify the DBinderSessionObject::SetDeviceId function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, SetDeviceIdTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(session, serviceName, serverDeviceId);
std::string deviceId = "testid";
object.SetDeviceId(deviceId);
EXPECT_STREQ(deviceId.c_str(), object.GetDeviceId().c_str());
}
/**
* @tc.name: SetFeatureSetTest001
* @tc.desc: Verify the DBinderSessionObject::SetFeatureSet function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, SetFeatureSetTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(session, serviceName, serverDeviceId);
std::shared_ptr<FeatureSetData> rpcFeatureSet = std::make_shared<FeatureSetData>();
object.SetFeatureSet(rpcFeatureSet);
EXPECT_NE(object.GetFeatureSet(), nullptr);
}
/**
* @tc.name: GetFlatSessionLenTest001
* @tc.desc: Verify the DBinderSessionObject::GetFlatSessionLen function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, GetFlatSessionLenTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(session, serviceName, serverDeviceId);
uint32_t len = object.GetFlatSessionLen();
EXPECT_EQ(sizeof(FlatDBinderSession), len);
}
/**
* @tc.name: GetSessionHandleTest001
* @tc.desc: Verify the DBinderSessionObject::GetSessionHandle function
* @tc.type: FUNC
*/
HWTEST_F(DBinderSessionObjectTest, GetSessionHandleTest001, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
std::string serviceName = "testserviceName";
std::string serverDeviceId = "testserverDeviceId";
DBinderSessionObject object(sessionMock, serviceName, serverDeviceId);
EXPECT_CALL(*sessionMock, GetChannelId())
.Times(1)
.WillOnce(testing::Return(1));
uint32_t ret = object.GetSessionHandle();
uint32_t id = 1;
EXPECT_EQ(ret, id);
}
\ No newline at end of file
/*
* 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>
#include "ipc_debug.h"
#include "ipc_skeleton.h"
#include "ipc_test_helper.h"
#include "log_tags.h"
#include "access_token_adapter.h"
#include "sys_binder.h"
#define private public
#include "dbinder_databus_invoker.h"
#undef private
#include "mock_session_impl.h"
using namespace testing::ext;
using namespace OHOS;
class IPCDbinderDataBusInvokerTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCUnitTest" };
private:
static inline IPCTestHelper *g_globalHelper = { nullptr };
};
void IPCDbinderDataBusInvokerTest::SetUpTestCase()
{
if (g_globalHelper == nullptr) {
g_globalHelper = new IPCTestHelper();
bool res = g_globalHelper->PrepareTestSuite();
ASSERT_TRUE(res);
}
}
void IPCDbinderDataBusInvokerTest::TearDownTestCase()
{
if (g_globalHelper != nullptr) {
bool res = g_globalHelper->TearDownTestSuite();
ASSERT_TRUE(res);
delete g_globalHelper;
g_globalHelper = nullptr;
}
}
/**
* @tc.name: AcquireHandle001
* @tc.desc: AcquireHandle
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, AcquireHandle001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
int32_t handle = 0;
bool res = testInvoker.AcquireHandle(handle);
EXPECT_TRUE(res);
}
/**
* @tc.name: ReleaseHandle001
* @tc.desc: ReleaseHandle
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, ReleaseHandle001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
int32_t handle = 0;
bool res = testInvoker.ReleaseHandle(handle);
EXPECT_TRUE(res);
}
/**
* @tc.name: FlattenObjectTest001
* @tc.desc: StopWorkThread
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, StopWorkThreadTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
testInvoker.StopWorkThread();
EXPECT_TRUE(testInvoker.stopWorkThread_);
}
/**
* @tc.name: FlattenObjectTest005
* @tc.desc: FlattenObject
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, FlattenObjectTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
MessageParcel data;
IRemoteObject *object = nullptr;
bool ret = testInvoker.FlattenObject(data, object);
EXPECT_TRUE(ret);
}
/**
* @tc.name: UnflattenObjectTest001
* @tc.desc: UnflattenObject
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, UnflattenObjectTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
MessageParcel data;
sptr<IRemoteObject> object = testInvoker.UnflattenObject(data);
EXPECT_TRUE(object == nullptr);
}
/**
* @tc.name: ReadFileDescriptorTest001
* @tc.desc: ReadFileDescriptor
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, ReadFileDescriptorTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
MessageParcel data;
int ret = testInvoker.ReadFileDescriptor(data);
EXPECT_EQ(ret, -1);
}
/**
* @tc.name: WriteFileDescriptorTest001
* @tc.desc: WriteFileDescriptor
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, WriteFileDescriptorTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
MessageParcel data;
int fd = -1;
bool ret = testInvoker.WriteFileDescriptor(data, fd, true);
EXPECT_TRUE(ret);
}
/**
* @tc.name: GetCallerPidTest001
* @tc.desc: GetCallerPid
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, GetCallerPidTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
pid_t pid = 1;
testInvoker.callerPid_ = pid;
pid_t ret = testInvoker.GetCallerPid();
EXPECT_EQ(ret, pid);
}
/**
* @tc.name: GetCallerTokenIDTest001
* @tc.desc: GetCallerTokenID
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, GetCallerTokenIDTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t tokenId = 1;
testInvoker.callerTokenID_ = tokenId;
uint32_t ret = testInvoker.GetCallerTokenID();
EXPECT_EQ(ret, tokenId);
}
/**
* @tc.name: GetFirstTokenIDTest001
* @tc.desc: GetFirstTokenID
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, GetFirstTokenIDTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t tokenId = 1;
testInvoker.firstTokenID_ = tokenId;
uint32_t ret = testInvoker.GetFirstTokenID();
EXPECT_EQ(ret, tokenId);
}
/**
* @tc.name: GetStatusTest001
* @tc.desc: GetStatus
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, GetStatusTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t status = 1;
testInvoker.SetStatus(status);
uint32_t ret = testInvoker.GetStatus();
EXPECT_EQ(ret, status);
}
/**
* @tc.name: IsLocalCallingTest001
* @tc.desc: IsLocalCalling
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, IsLocalCallingTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
bool ret = testInvoker.IsLocalCalling();
EXPECT_FALSE(ret);
}
/**
* @tc.name: GetLocalDeviceIDTest001
* @tc.desc: GetLocalDeviceID
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, GetLocalDeviceIDTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
std::string deviceId = testInvoker.GetLocalDeviceID();
EXPECT_TRUE(deviceId.empty());
}
/**
* @tc.name: GetCallerDeviceIDTest001
* @tc.desc: GetCallerDeviceID
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, GetCallerDeviceIDTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
std::string src = "test device id";
testInvoker.callerDeviceID_ = src;
std::string deviceId = testInvoker.GetCallerDeviceID();
EXPECT_TRUE(src == testInvoker.callerDeviceID_);
}
/**
* @tc.name: NewSessionOfBinderProxy001
* @tc.desc: NewSessionOfBinderProxy
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, NewSessionOfBinderProxy001, TestSize.Level1)
{
uint32_t handle = 0;
std::shared_ptr<DBinderSessionObject> remoteSession = nullptr;
DBinderDatabusInvoker testInvoker;
std::shared_ptr<DBinderSessionObject> res = testInvoker.NewSessionOfBinderProxy(handle, remoteSession);
EXPECT_TRUE(res == nullptr);
}
/**
* @tc.name: NewSessionOfBinderProxy002
* @tc.desc: NewSessionOfBinderProxy
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, NewSessionOfBinderProxy002, TestSize.Level1)
{
uint32_t handle = 0;
std::string serverName = "serverName";
std::string deviceId = "7001005458323933328a519c2fa83800";
std::shared_ptr<DBinderSessionObject> remoteSession =
std::make_shared<DBinderSessionObject>(nullptr, serverName, deviceId);
EXPECT_TRUE (remoteSession != nullptr);
DBinderDatabusInvoker testInvoker;
std::shared_ptr<DBinderSessionObject> res = testInvoker.NewSessionOfBinderProxy(handle, remoteSession);
EXPECT_TRUE (remoteSession != nullptr);
}
/**
* @tc.name: AuthSession2Proxy001
* @tc.desc: AuthSession2Proxy
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, AuthSession2Proxy001, TestSize.Level1)
{
uint32_t handle = 0;
std::shared_ptr<DBinderSessionObject> remoteSession = nullptr;
DBinderDatabusInvoker testInvoker;
bool res = testInvoker.AuthSession2Proxy(handle, remoteSession);
EXPECT_FALSE(res);
}
/**
* @tc.name: AuthSession2Proxy002
* @tc.desc: AuthSession2Proxy
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, AuthSession2Proxy002, TestSize.Level1)
{
uint32_t handle = 0;
std::string serverName = "serverName";
std::string deviceId = "7001005458323933328a519c2fa83800";
std::shared_ptr<DBinderSessionObject> remoteSession =
std::make_shared<DBinderSessionObject>(nullptr, serverName, deviceId);
EXPECT_TRUE (remoteSession != nullptr);
DBinderDatabusInvoker testInvoker;
bool res = testInvoker.AuthSession2Proxy(handle, remoteSession);
EXPECT_FALSE(res);
}
/**
* @tc.name: AuthSession2Proxy003
* @tc.desc: AuthSession2Proxy
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, AuthSession2Proxy003, TestSize.Level1)
{
uint32_t handle = 0;
std::string serverName = "serverName";
std::string deviceId = "7001005458323933328a519c2fa83800";
std::shared_ptr<DBinderSessionObject> remoteSession =
std::make_shared<DBinderSessionObject>(nullptr, serverName, deviceId);
EXPECT_TRUE (remoteSession != nullptr);
remoteSession->SetBusSession(nullptr);
EXPECT_TRUE(remoteSession->GetBusSession() == nullptr);
DBinderDatabusInvoker testInvoker;
bool res = testInvoker.AuthSession2Proxy(handle, remoteSession);
EXPECT_FALSE(res);
}
/**
* @tc.name: QuerySessionOfBinderProxy001
* @tc.desc: QuerySessionOfBinderProxy
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, QuerySessionOfBinderProxy001, TestSize.Level1)
{
uint32_t handle = 0;
std::string serverName = "serverName";
std::string deviceId = "7001005458323933328a519c2fa83800";
std::shared_ptr<DBinderSessionObject> remoteSession =
std::make_shared<DBinderSessionObject>(nullptr, serverName, deviceId);
EXPECT_TRUE (remoteSession != nullptr);
DBinderDatabusInvoker testInvoker;
std::shared_ptr<DBinderSessionObject> res = testInvoker.QuerySessionOfBinderProxy(handle, remoteSession);
EXPECT_TRUE(res == nullptr);
}
/**
* @tc.name: QueryClientSessionObjectTest001
* @tc.desc: QueryClientSessionObject
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, QueryClientSessionObjectTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t handle = 0;
std::shared_ptr<DBinderSessionObject> ret = testInvoker.QueryClientSessionObject(handle);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: QueryClientSessionObjectTest002
* @tc.desc: QueryClientSessionObject
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, QueryClientSessionObjectTest002, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t handle = 1;
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
EXPECT_TRUE (current != nullptr);
std::string serverName = "serverName";
std::string deviceId = "7001005458323933328a519c2fa83800";
std::shared_ptr<DBinderSessionObject> remoteSession =
std::make_shared<DBinderSessionObject>(nullptr, serverName, deviceId);
EXPECT_TRUE (remoteSession != nullptr);
bool ret = current->StubAttachDBinderSession(handle, remoteSession);
EXPECT_TRUE(ret);
std::shared_ptr<DBinderSessionObject> session = testInvoker.QueryClientSessionObject(handle);
EXPECT_TRUE(session != nullptr);
}
/**
* @tc.name: QueryServerSessionObjectTest001
* @tc.desc: QueryServerSessionObject
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, QueryServerSessionObjectTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t handle = 0;
std::shared_ptr<DBinderSessionObject> ret = testInvoker.QueryServerSessionObject(handle);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: QueryServerSessionObjectTest002
* @tc.desc: QueryServerSessionObject
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, QueryServerSessionObjectTest002, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t handle = 1;
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
EXPECT_TRUE (current != nullptr);
std::string serverName = "serverName";
std::string deviceId = "7001005458323933328a519c2fa83800";
std::shared_ptr<DBinderSessionObject> remoteSession =
std::make_shared<DBinderSessionObject>(nullptr, serverName, deviceId);
EXPECT_TRUE (remoteSession != nullptr);
bool ret = current->ProxyAttachDBinderSession(handle, remoteSession);
EXPECT_TRUE(ret);
std::shared_ptr<DBinderSessionObject> session = testInvoker.QueryServerSessionObject(handle);
EXPECT_TRUE(session != nullptr);
}
/**
* @tc.name: CreateProcessThreadTest001
* @tc.desc: CreateProcessThread
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, CreateProcessThreadTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
current->threadPool_ = nullptr;
bool ret = testInvoker.CreateProcessThread();
EXPECT_FALSE(ret);
ret = testInvoker.CreateProcessThread();
EXPECT_FALSE(ret);
}
/**
* @tc.name: CreateProcessThreadTest002
* @tc.desc: CreateProcessThread
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, CreateProcessThreadTest002, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
int maxThreadNum = 3;
EXPECT_TRUE(current->SetMaxWorkThread(maxThreadNum));
bool ret = testInvoker.CreateProcessThread();
EXPECT_TRUE(ret);
}
/**
* @tc.name: CreateServerSessionObjectTest001
* @tc.desc: CreateServerSessionObject
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, CreateServerSessionObjectTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
binder_uintptr_t binder = 0;
uint64_t stubIndex = 0;
std::shared_ptr<DBinderSessionObject> sessionObject = nullptr;
std::shared_ptr<DBinderSessionObject> ret = testInvoker.CreateServerSessionObject(binder, stubIndex, sessionObject);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: FlushCommandsTest001
* @tc.desc: FlushCommands
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, FlushCommandsTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
IRemoteObject *object = nullptr;
int ret = testInvoker.FlushCommands(object);
EXPECT_EQ(ret, RPC_DATABUS_INVOKER_INVALID_DATA_ERR);
}
/**
* @tc.name: OnDatabusSessionClosedTest001
* @tc.desc: OnDatabusSessionClosed
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, OnDatabusSessionClosedTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
std::shared_ptr<Session> session = nullptr;
bool ret = testInvoker.OnDatabusSessionClosed(session);
EXPECT_FALSE(ret);
}
/**
* @tc.name: ResetCallingIdentityTest001
* @tc.desc: ResetCallingIdentity
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, ResetCallingIdentityTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
std::string token = testInvoker.ResetCallingIdentity();
EXPECT_FALSE(token.empty());
bool ret = testInvoker.SetCallingIdentity(token);
EXPECT_FALSE(ret);
}
/**
* @tc.name: SetCallingIdentityTest001
* @tc.desc: SetCallingIdentity
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, SetCallingIdentityTest001, TestSize.Level1)
{
#define DEVICEID_LENGTH_TEST 64
uint64_t tokenId = 1;
uint64_t pid = 1;
char buf[ACCESS_TOKEN_MAX_LEN + 1] = {0};
std::string deviceId;
int ret = sprintf_s(buf, ACCESS_TOKEN_MAX_LEN + 1, "%010u", tokenId);
EXPECT_FALSE(ret < 0);
std::string accessToken(buf);
for (int i = 0; i < DEVICEID_LENGTH_TEST; i++) {
deviceId += "A";
}
std::string token = std::to_string(static_cast<uint64_t>(pid));
std::string identity = accessToken + deviceId + token;
DBinderDatabusInvoker testInvoker;
bool result = testInvoker.SetCallingIdentity(identity);
EXPECT_TRUE(result);
}
/**
* @tc.name: TranslateProxyTest001
* @tc.desc: TranslateProxy
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, TranslateProxyTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
uint32_t handle = 0;
uint32_t flag = 0;
int ret = testInvoker.TranslateProxy(handle, flag);
EXPECT_EQ(ret, -IPC_INVOKER_TRANSLATE_ERR);
}
/**
* @tc.name: TranslateStubTest001
* @tc.desc: TranslateStub
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, TranslateStubTest001, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
binder_uintptr_t cookie = 0;
binder_uintptr_t ptr = 0;
uint32_t flag = 0;
int cmd = 0;
int ret = testInvoker.TranslateStub(cookie, ptr, flag, cmd);
EXPECT_EQ(ret, -IPC_INVOKER_TRANSLATE_ERR);
}
/**
* @tc.name: OnMessageAvailable001
* @tc.desc: OnMessageAvailable
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, OnMessageAvailable001, TestSize.Level1)
{
std::shared_ptr<Session> session = nullptr;
DBinderDatabusInvoker testInvoker;;
testInvoker.OnMessageAvailable(session, nullptr, 0);
EXPECT_TRUE(session == nullptr);
}
/**
* @tc.name: OnMessageAvailable002
* @tc.desc: OnMessageAvailable return at first branch
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, OnMessageAvailable002, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
const char *data = nullptr;
testInvoker.OnMessageAvailable(sessionMock, data, 0);
EXPECT_TRUE(data == nullptr);
uint32_t size = sizeof(dbinder_transaction_data) + SOCKET_MAX_BUFF_SIZE;
dbinder_transaction_data *tmp = (dbinder_transaction_data *)malloc(size);
EXPECT_TRUE(tmp != nullptr);
data = reinterpret_cast<const char *>(tmp);
ssize_t len = 0;
testInvoker.OnMessageAvailable(sessionMock, data, len);
EXPECT_TRUE(len < static_cast<ssize_t>(sizeof(dbinder_transaction_data)));
len = static_cast<ssize_t>(MAX_RAWDATA_SIZE) + 1;
testInvoker.OnMessageAvailable(sessionMock, data, len);
EXPECT_TRUE(len > static_cast<ssize_t>(MAX_RAWDATA_SIZE));
free(tmp);
}
/**
* @tc.name: OnMessageAvailable003
* @tc.desc: OnMessageAvailable return tr->sizeOfSelf in HasRawDataPackage
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, OnMessageAvailable003, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
uint32_t size = sizeof(dbinder_transaction_data) + SOCKET_MAX_BUFF_SIZE;
dbinder_transaction_data *tmp = (dbinder_transaction_data *)malloc(size);
EXPECT_TRUE(tmp != nullptr);
tmp->magic = DBINDER_MAGICWORD;
tmp->cmd = BC_SEND_RAWDATA;
tmp->sizeOfSelf = sizeof(dbinder_transaction_data) + SOCKET_MAX_BUFF_SIZE;;
const char *data = reinterpret_cast<const char *>(tmp);
ssize_t len = sizeof(dbinder_transaction_data) + SOCKET_MAX_BUFF_SIZE;
testInvoker.OnMessageAvailable(sessionMock, data, len);
EXPECT_TRUE(tmp->sizeOfSelf == static_cast<uint32_t>(len));
free(tmp);
}
/**
* @tc.name: OnMessageAvailable004
* @tc.desc: OnMessageAvailable return 0 in HasRawDataPackage
* @tc.type: FUNC
*/
HWTEST_F(IPCDbinderDataBusInvokerTest, OnMessageAvailable004, TestSize.Level1)
{
DBinderDatabusInvoker testInvoker;
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
uint32_t size = sizeof(dbinder_transaction_data) + SOCKET_MAX_BUFF_SIZE;
dbinder_transaction_data *tmp = (dbinder_transaction_data *)malloc(size);
EXPECT_TRUE(tmp != nullptr);
tmp->magic = 0;
const char *data = reinterpret_cast<const char *>(tmp);
ssize_t len = sizeof(dbinder_transaction_data) + SOCKET_MAX_BUFF_SIZE;
testInvoker.OnMessageAvailable(sessionMock, data, len);
EXPECT_FALSE(tmp->magic == DBINDER_MAGICWORD);
tmp->magic = DBINDER_MAGICWORD;
testInvoker.OnMessageAvailable(sessionMock, data, len);
EXPECT_FALSE(tmp->cmd == BC_SEND_RAWDATA);
tmp->cmd = BC_SEND_RAWDATA;
testInvoker.OnMessageAvailable(sessionMock, data, len);
EXPECT_FALSE(tmp->sizeOfSelf == static_cast<uint32_t>(len));
free(tmp);
}
/*
* 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>
#include "sys_binder.h"
#define private public
#include "binder_connector.h"
#undef private
using namespace testing::ext;
using namespace OHOS;
class BinderConnectorTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void BinderConnectorTest::SetUpTestCase()
{
}
void BinderConnectorTest::TearDownTestCase()
{
}
void BinderConnectorTest::SetUp()
{
}
void BinderConnectorTest::TearDown()
{
}
/**
* @tc.name: OpenDriver001
* @tc.desc: Verify the OpenDriver function
* @tc.type: FUNC
*/
HWTEST_F(BinderConnectorTest, OpenDriver001, TestSize.Level1)
{
std::string deviceName("test");
BinderConnector binderConnector(deviceName);
bool res = binderConnector.OpenDriver();
EXPECT_EQ(res, false);
}
/**
* @tc.name: ExitCurrentThread001
* @tc.desc: Verify the ExitCurrentThread function
* @tc.type: FUNC
*/
HWTEST_F(BinderConnectorTest, ExitCurrentThread001, TestSize.Level1)
{
BinderConnector* binderConnector = BinderConnector::GetInstance();
binderConnector->ExitCurrentThread(BINDER_THREAD_EXIT);
EXPECT_EQ(true, true);
}
/*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* 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
......@@ -14,15 +14,9 @@
*/
#include <gtest/gtest.h>
#define private public
#include "comm_auth_info.h"
#include "databus_session_callback.h"
#include "dbinder_session_object.h"
#include "ipc_debug.h"
#include "ipc_skeleton.h"
#include "ipc_object_proxy.h"
#include "ipc_object_stub.h"
#include "test_service_skeleton.h"
#include "test_service.h"
#include "test_service_command.h"
......@@ -30,12 +24,8 @@
#include "ipc_test_helper.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "dbinder_session_object.h"
#include "message_option.h"
#include "stub_refcount_object.h"
#include "system_ability_definition.h"
#include "log_tags.h"
#undef private
#ifndef CONFIG_STANDARD_SYSTEM
#include "jni_help.h"
#endif
......@@ -44,12 +34,8 @@ using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::HiviewDFX;
namespace {
constexpr int MAX_TEST_COUNT = 1000;
constexpr bool SUPPORT_ZBINDER = false;
constexpr uint32_t INVAL_TOKEN_ID = 0x0;
constexpr int MAX_WAIT_TIME = 3000;
}
static constexpr int MAX_TEST_COUNT = 1000;
static constexpr bool SUPPORT_ZBINDER = false;
class IPCNativeUnitTest : public testing::Test {
public:
......@@ -104,18 +90,6 @@ HWTEST_F(IPCNativeUnitTest, DeathRecipient002, TestSize.Level1)
EXPECT_FALSE(res);
}
/**
* @tc.name: GetObjectRefCountTest001
* @tc.desc: Verify the GetObjectRefCount function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetObjectRefCountTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
int count = testStub->GetObjectRefCount();
EXPECT_GE(count, 0);
}
/**
* @tc.name: DumpTest001
* @tc.desc: The Stub should not support Dump
......@@ -130,230 +104,6 @@ HWTEST_F(IPCNativeUnitTest, DumpTest001, TestSize.Level1)
EXPECT_EQ(res, 0);
}
/**
* @tc.name: OnRemoteDumpTest001
* @tc.desc: Verify the OnRemoteDump function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, OnRemoteDumpTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->OnRemoteDump(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest001
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = INTERFACE_TRANSACTION;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: SendRequestTest002
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest002, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = SYNCHRONIZE_REFERENCE;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: SendRequestTest003
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest003, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = DUMP_TRANSACTION;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest004
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest004, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = GET_PROTO_INFO;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: SendRequestTest005
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest005, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = INVOKE_LISTEN_THREAD;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVOKE_THREAD_ERR);
}
/**
* @tc.name: SendRequestTest007
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest007, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = DBINDER_INCREFS_TRANSACTION;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest008
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest008, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = DBINDER_DECREFS_TRANSACTION;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest009
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest009, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = DBINDER_DECREFS_TRANSACTION;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest010
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest010, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = DBINDER_ADD_COMMAUTH;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest011
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest011, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = DBINDER_TRANS_COMMAUTH;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest012
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest012, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = GET_UIDPID_INFO;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: SendRequestTest013
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest013, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = GRANT_DATABUS_NAME;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: SendRequestTest014
* @tc.desc: Verify the SendRequest function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, SendRequestTest014, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t code = TRANS_DATABUS_NAME;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int result = testStub->SendRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: ProxyJudgment001
* @tc.desc: act as stub role, should return false
......@@ -366,120 +116,6 @@ HWTEST_F(IPCNativeUnitTest, ProxyJudgment001, TestSize.Level1)
EXPECT_FALSE(res);
}
/**
* @tc.name: GetCallingPidTest001
* @tc.desc: Verify the GetCallingPid function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetCallingPidTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
pid_t id = testStub->GetCallingPid();
EXPECT_NE(id, -1);
}
/**
* @tc.name: GetCallingUidTest001
* @tc.desc: Verify the GetCallingUid function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetCallingUidTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
pid_t id = testStub->GetCallingUid();
EXPECT_NE(id, -1);
}
/**
* @tc.name: GetCallingTokenIDTest001
* @tc.desc: Verify the GetCallingTokenID function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetCallingTokenIDTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t token = testStub->GetCallingTokenID();
EXPECT_NE(token, INVAL_TOKEN_ID);
}
/**
* @tc.name: GetFirstTokenIDTest001
* @tc.desc: Verify the GetFirstTokenID function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetFirstTokenIDTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t token = testStub->GetFirstTokenID();
EXPECT_EQ(token, INVAL_TOKEN_ID);
}
/**
* @tc.name: AddAuthInfoeTest001
* @tc.desc: Verify the AddAuthInfoe function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, AddAuthInfoeTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
MessageParcel data;
MessageParcel reply;
uint32_t code = 0;
int32_t ret = testStub->AddAuthInfo(data, reply, code);
EXPECT_EQ(ret, IPC_STUB_INVALID_DATA_ERR);
}
/**
* @tc.name: GetObjectTypeTest001
* @tc.desc: Verify the GetObjectType function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetObjectTypeTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
int ret = testStub->GetObjectType();
EXPECT_EQ(ret, IPCObjectStub::OBJECT_TYPE_NATIVE);
}
/**
* @tc.name: IsDeviceIdIllegalTest001
* @tc.desc: Verify the IsDeviceIdIllegal function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, IsDeviceIdIllegalTest001, TestSize.Level1)
{
std::string deviceID = "test";
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"test");
bool ret = testStub->IsDeviceIdIllegal(deviceID);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: IsDeviceIdIllegalTest002
* @tc.desc: Verify the IsDeviceIdIllegal function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, IsDeviceIdIllegalTest002, TestSize.Level1)
{
std::string deviceID = "";
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"test");
bool ret = testStub->IsDeviceIdIllegal(deviceID);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: IsDeviceIdIllegalTest003
* @tc.desc: Verify the IsDeviceIdIllegal function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, IsDeviceIdIllegalTest003, TestSize.Level1)
{
std::string deviceID(DEVICEID_LENGTH + 1, '1');
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"test");
bool ret = testStub->IsDeviceIdIllegal(deviceID);
EXPECT_EQ(ret, true);
}
#ifndef CONFIG_STANDARD_SYSTEM
/**
* @tc.name: ProxyJudgment002
......@@ -793,6 +429,7 @@ HWTEST_F(IPCNativeUnitTest, SyncTransaction008, TestSize.Level1)
ASSERT_EQ(readDescriptor, descriptor);
}
/**
* @tc.name: SyncTransaction009
* @tc.desc: Test IPC stub data Normal release.
......@@ -836,33 +473,6 @@ HWTEST_F(IPCNativeUnitTest, SyncTransaction010, TestSize.Level1)
ASSERT_EQ(parcel.ReadException(), 0);
}
/**
* @tc.name: GetRawDataCapacityTest001
* @tc.desc: Verify the GetRawDataCapacity function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetRawDataCapacityTest001, TestSize.Level1)
{
MessageParcel parcel;
size_t ret = parcel.GetRawDataCapacity();
EXPECT_EQ(ret, MAX_RAWDATA_SIZE);
}
/**
* @tc.name: GetRawDataCapacityTest002
* @tc.desc: Verify the GetRawDataCapacity function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetRawDataCapacityTest002, TestSize.Level1)
{
MessageParcel data;
uint8_t bytes[8] = {0};
data.WriteBuffer(bytes, 8);
MessageParcel parcel;
bool ret = parcel.Append(data);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: MessageOptionTest001
* @tc.desc: Test set waiting time.
......@@ -877,32 +487,6 @@ HWTEST_F(IPCNativeUnitTest, MessageOptionTest001, TestSize.Level1)
ASSERT_EQ(messageOption.GetWaitTime(), MessageOption::TF_WAIT_TIME);
}
/**
* @tc.name: MessageOptionTest002
* @tc.desc: Verify the SetWaitTime function
* @tc.type: FUNC
* @tc.require: AR000ER7PF
*/
HWTEST_F(IPCNativeUnitTest, MessageOptionTest002, TestSize.Level1)
{
MessageOption messageOption;
messageOption.SetWaitTime(MAX_WAIT_TIME + 1);
ASSERT_EQ(messageOption.GetWaitTime(), MAX_WAIT_TIME);
}
/**
* @tc.name: MessageOptionTest003
* @tc.desc: Verify the SetWaitTime function
* @tc.type: FUNC
* @tc.require: AR000ER7PF
*/
HWTEST_F(IPCNativeUnitTest, MessageOptionTest003, TestSize.Level1)
{
MessageOption messageOption;
messageOption.SetWaitTime(MessageOption::TF_ASYNC);
ASSERT_EQ(messageOption.GetWaitTime(), MessageOption::TF_ASYNC);
}
/**
* @tc.name: AccessTokenid001
* @tc.desc: Test IPC AccessTokenid transport
......@@ -931,150 +515,3 @@ HWTEST_F(IPCNativeUnitTest, AccessTokenid001, TestSize.Level1)
ZLOGE(LABEL, "Got Stub node");
}
}
\ No newline at end of file
/**
* @tc.name: GetStubObjectTest001
* @tc.desc: Verify the StubRefCountObject class
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetStubObjectTest001, TestSize.Level1)
{
sptr<IRemoteObject> remoteObj = IPCSkeleton::GetContextObject();
ASSERT_TRUE(remoteObj != nullptr);
IRemoteObject *stub = remoteObj.GetRefPtr();
int remotePid = 1;
std::string deviceId = "test";
StubRefCountObject object(stub, remotePid, deviceId);
EXPECT_NE(object.GetStubObject(), nullptr);
}
/**
* @tc.name: GetRemotePidTest002
* @tc.desc: Verify the StubRefCountObject::GetRemotePid function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetRemotePidTest002, TestSize.Level1)
{
sptr<IRemoteObject> remoteObj = IPCSkeleton::GetContextObject();
ASSERT_TRUE(remoteObj != nullptr);
IRemoteObject *stub = remoteObj.GetRefPtr();
int remotePid = 1;
std::string deviceId = "test";
StubRefCountObject object(stub, remotePid, deviceId);
int pid = object.GetRemotePid();
EXPECT_EQ(pid, 1);
}
/**
* @tc.name: GetDeviceIdTest003
* @tc.desc: Verify the StubRefCountObject::GetDeviceId function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, GetDeviceIdTest003, TestSize.Level1)
{
sptr<IRemoteObject> remoteObj = IPCSkeleton::GetContextObject();
ASSERT_TRUE(remoteObj != nullptr);
IRemoteObject *stub = remoteObj.GetRefPtr();
int remotePid = 1;
std::string deviceId = "test";
StubRefCountObject object(stub, remotePid, deviceId);
std::string res = object.GetDeviceId();
EXPECT_STREQ(res.c_str(), deviceId.c_str());
}
/**
* @tc.name: FlushCommandsTest001
* @tc.desc: Verify the StubRefCountObject class
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, FlushCommandsTest001, TestSize.Level1)
{
sptr<IRemoteObject> remoteObj = IPCSkeleton::GetContextObject();
ASSERT_TRUE(remoteObj != nullptr);
int ret = IPCSkeleton::FlushCommands(remoteObj);
EXPECT_EQ(ret, ERR_NONE);
}
/**
* @tc.name: CommAuthInfoGetStubObjectTest001
* @tc.desc: Verify the CommAuthInfo::GetStubObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetStubObjectTest001, TestSize.Level1)
{
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sptr<IRemoteObject> object = saMgr->AsObject();
std::shared_ptr<FeatureSetData> rpcFeatureSet = std::make_shared<FeatureSetData>();
std::string deviceId = "testdeviceId";
CommAuthInfo commAuthInfo(object, 1, 1, deviceId, rpcFeatureSet);
ASSERT_TRUE(commAuthInfo.GetStubObject() != nullptr);
}
/**
* @tc.name: CommAuthInfoGetRemotePidTest001
* @tc.desc: Verify the CommAuthInfo::GetRemotePid function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemotePidTest001, TestSize.Level1)
{
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sptr<IRemoteObject> object = saMgr->AsObject();
std::shared_ptr<FeatureSetData> rpcFeatureSet = std::make_shared<FeatureSetData>();
std::string deviceId = "testdeviceId";
CommAuthInfo commAuthInfo(object, 1, 1, deviceId, rpcFeatureSet);
EXPECT_EQ(commAuthInfo.GetRemotePid(), 1);
}
/**
* @tc.name: CommAuthInfoGetRemoteUidTest001
* @tc.desc: Verify the CommAuthInfo::GetRemoteUid function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemoteUidTest001, TestSize.Level1)
{
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sptr<IRemoteObject> object = saMgr->AsObject();
std::shared_ptr<FeatureSetData> rpcFeatureSet = std::make_shared<FeatureSetData>();
std::string deviceId = "testdeviceId";
CommAuthInfo commAuthInfo(object, 1, 1, deviceId, rpcFeatureSet);
EXPECT_EQ(commAuthInfo.GetRemoteUid(), 1);
}
/**
* @tc.name: CommAuthInfoGetRemoteDeviceIdTest001
* @tc.desc: Verify the CommAuthInfo::GetRemoteDeviceId function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemoteDeviceIdTest001, TestSize.Level1)
{
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sptr<IRemoteObject> object = saMgr->AsObject();
std::shared_ptr<FeatureSetData> rpcFeatureSet = std::make_shared<FeatureSetData>();
std::string deviceId = "testdeviceId";
CommAuthInfo commAuthInfo(object, 1, 1, deviceId, rpcFeatureSet);
EXPECT_STREQ(commAuthInfo.GetRemoteDeviceId().c_str(), deviceId.c_str());
}
/**
* @tc.name: CommAuthInfoGetFeatureSetTest001
* @tc.desc: Verify the CommAuthInfo::GetFeatureSet function
* @tc.type: FUNC
*/
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetFeatureSetTest001, TestSize.Level1)
{
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sptr<IRemoteObject> object = saMgr->AsObject();
std::shared_ptr<FeatureSetData> rpcFeatureSet = std::make_shared<FeatureSetData>();
std::string deviceId = "testdeviceId";
CommAuthInfo commAuthInfo(object, 1, 1, deviceId, rpcFeatureSet);
EXPECT_NE(commAuthInfo.GetFeatureSet(), nullptr);
}
\ No newline at end of file
/*
* 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>
#include "ipc_object_proxy.h"
#include "ipc_types.h"
using namespace testing::ext;
using namespace OHOS;
class IPCObjectProxyTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void IPCObjectProxyTest::SetUpTestCase()
{
}
void IPCObjectProxyTest::TearDownTestCase()
{
}
void IPCObjectProxyTest::SetUp()
{
}
void IPCObjectProxyTest::TearDown()
{
}
/**
* @tc.name: GetPidAndUidInfoTest001
* @tc.desc: Verify the IPCObjectProxy::GetPidAndUidInfo function
* @tc.type: FUNC
*/
HWTEST_F(IPCObjectProxyTest, GetPidAndUidInfoTest001, TestSize.Level1)
{
IPCObjectProxy object(1);
std::string ret = object.GetPidAndUidInfo(1);
EXPECT_NE(ret.size(), 0);
}
/**
* @tc.name: GetDataBusNameTest001
* @tc.desc: Verify the IPCObjectProxy::GetDataBusName function
* @tc.type: FUNC
*/
HWTEST_F(IPCObjectProxyTest, GetDataBusNameTest001, TestSize.Level1)
{
IPCObjectProxy object(1);
std::string ret = object.GetDataBusName(1);
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.name: TransDataBusNameTest001
* @tc.desc: Verify the IPCObjectProxy::TransDataBusName function
* @tc.type: FUNC
*/
HWTEST_F(IPCObjectProxyTest, TransDataBusNameTest001, TestSize.Level1)
{
IPCObjectProxy object(1);
std::string ret = object.TransDataBusName(1, 1);
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.name: GetInterfaceDescriptorTest001
* @tc.desc: Verify the IPCObjectProxy::GetInterfaceDescriptor function
* @tc.type: FUNC
*/
HWTEST_F(IPCObjectProxyTest, GetInterfaceDescriptorTest001, TestSize.Level1)
{
IPCObjectProxy object(1);
std::u16string ret = object.GetInterfaceDescriptor();
EXPECT_NE(ret.size(), 0);
}
\ No newline at end of file
/*
* 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 "dbinder_session_object.h"
#include "mock_session_impl.h"
#include "ipc_process_skeleton.h"
#include "ipc_types.h"
#include "iremote_object.h"
#include "ipc_object_stub.h"
#include "ipc_thread_pool.h"
#undef private
using namespace testing::ext;
using namespace OHOS;
namespace {
constexpr int THREAD_NUM_2 = 2;
constexpr uint32_t INDEX_2 = 2;
constexpr uint32_t INDEX_3 = 3;
constexpr uint32_t INDEX_4 = 4;
}
class IPCProcessSkeletonUnitTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void IPCProcessSkeletonUnitTest::SetUpTestCase()
{
}
void IPCProcessSkeletonUnitTest::TearDownTestCase()
{
}
void IPCProcessSkeletonUnitTest::SetUp() {}
void IPCProcessSkeletonUnitTest::TearDown() {}
/**
* @tc.name: GetRegistryObjectTest001
* @tc.desc: Verify the GetRegistryObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetRegistryObjectTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
sptr<IRemoteObject> object = skeleton->GetRegistryObject();
EXPECT_NE(object, nullptr);
}
/**
* @tc.name: MakeHandleDescriptorTest001
* @tc.desc: Verify the MakeHandleDescriptor function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, MakeHandleDescriptorTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::u16string str = skeleton->MakeHandleDescriptor(1);
unsigned int size = 0;
EXPECT_NE(str.size(), size);
}
/**
* @tc.name: FindOrNewObjectTest001
* @tc.desc: Verify the FindOrNewObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, FindOrNewObjectTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
sptr<IRemoteObject> object = skeleton->FindOrNewObject(1);
EXPECT_NE(object, nullptr);
}
/**
* @tc.name: SetMaxWorkThreadTest001
* @tc.desc: Verify the SetMaxWorkThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, SetMaxWorkThreadTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
bool ret = skeleton->SetMaxWorkThread(-1);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: SetMaxWorkThreadTest002
* @tc.desc: Verify the SetMaxWorkThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, SetMaxWorkThreadTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
bool ret = skeleton->SetMaxWorkThread(1);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: SetRegistryObjectTest001
* @tc.desc: Verify the SetRegistryObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, SetRegistryObjectTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
sptr<IRemoteObject> object = nullptr;
bool ret = skeleton->SetRegistryObject(object);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: SetRegistryObjectTest002
* @tc.desc: Verify the SetRegistryObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, SetRegistryObjectTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
sptr<IRemoteObject> object = new IPCObjectStub(u"test");
bool ret = skeleton->SetRegistryObject(object);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: SpawnThreadTest001
* @tc.desc: Verify the SpawnThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, SpawnThreadTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->SetMaxWorkThread(1);
int policy = 1;
int proto = IRemoteObject::IF_PROT_DATABUS;
bool ret = skeleton->SpawnThread(policy, proto);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: SpawnThreadTest002
* @tc.desc: Verify the SpawnThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, SpawnThreadTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->SetMaxWorkThread(1);
int policy = 1;
int proto = IRemoteObject::IF_PROT_ERROR;
bool ret = skeleton->SpawnThread(policy, proto);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: OnThreadTerminatedTest001
* @tc.desc: Verify the OnThreadTerminated function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, OnThreadTerminatedTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->SetMaxWorkThread(1);
std::string threadName = "threadname";
bool ret = skeleton->OnThreadTerminated(threadName);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: QueryObjectTest001
* @tc.desc: Verify the QueryObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryObjectTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::u16string descriptor = u"test";
auto object = skeleton->QueryObject(descriptor);
EXPECT_EQ(object, nullptr);
}
/**
* @tc.name: QueryObjectTest002
* @tc.desc: Verify the QueryObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryObjectTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::u16string descriptor = u"";
auto object = skeleton->QueryObject(descriptor);
EXPECT_EQ(object, nullptr);
}
/**
* @tc.name: IsContainsObjectTest001
* @tc.desc: Verify the IsContainsObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, IsContainsObjectTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
sptr<IRemoteObject> object = new IPCObjectStub(u"testObject");
skeleton->AttachObjectInner(object);
bool ret = skeleton->IsContainsObject(object.GetRefPtr());
EXPECT_EQ(ret, true);
}
/**
* @tc.name: IsHandleMadeByUserTest001
* @tc.desc: Verify the IsHandleMadeByUser function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, IsHandleMadeByUserTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
uint32_t handle = IPCProcessSkeleton::DBINDER_HANDLE_BASE + 1;
bool ret = skeleton->IsHandleMadeByUser(handle);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: IsHandleMadeByUserTest002
* @tc.desc: Verify the IsHandleMadeByUser function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, IsHandleMadeByUserTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
uint32_t handle = IPCProcessSkeleton::DBINDER_HANDLE_BASE;
bool ret = skeleton->IsHandleMadeByUser(handle);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: GetDBinderIdleHandleTest001
* @tc.desc: Verify the GetDBinderIdleHandle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetDBinderIdleHandleTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
uint64_t stubIndex = 1;
uint32_t ret = skeleton->GetDBinderIdleHandle(stubIndex);
EXPECT_EQ(ret, IPCProcessSkeleton::DBINDER_HANDLE_BASE + 1);
}
/**
* @tc.name: GetDBinderIdleHandleTest002
* @tc.desc: Verify the GetDBinderIdleHandle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetDBinderIdleHandleTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->dBinderHandle_ = 1;
uint64_t stubIndex = 1;
uint32_t ret = skeleton->GetDBinderIdleHandle(stubIndex);
EXPECT_EQ(ret, IPCProcessSkeleton::DBINDER_HANDLE_BASE + INDEX_2);
}
/**
* @tc.name: GetDBinderIdleHandleTest003
* @tc.desc: Verify the GetDBinderIdleHandle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetDBinderIdleHandleTest003, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->dBinderHandle_ =
IPCProcessSkeleton::DBINDER_HANDLE_BASE + IPCProcessSkeleton::DBINDER_HANDLE_BASE + 1;
uint64_t stubIndex = 1;
uint32_t ret = skeleton->GetDBinderIdleHandle(stubIndex);
EXPECT_EQ(ret, IPCProcessSkeleton::DBINDER_HANDLE_BASE + INDEX_3);
}
/**
* @tc.name: GetDBinderIdleHandleTest004
* @tc.desc: Verify the GetDBinderIdleHandle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetDBinderIdleHandleTest004, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->dBinderHandle_ = IPCProcessSkeleton::DBINDER_HANDLE_BASE;
uint64_t stubIndex = 1;
uint32_t ret = skeleton->GetDBinderIdleHandle(stubIndex);
EXPECT_EQ(ret, IPCProcessSkeleton::DBINDER_HANDLE_BASE + INDEX_4);
}
/**
* @tc.name: QueryHandleToIndexTest001
* @tc.desc: Verify the QueryHandleToIndex function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryHandleToIndexTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->handleToStubIndex_.insert(std::pair<uint32_t, uint64_t>(1, 1));
uint64_t handle = 1;
EXPECT_EQ(handle, skeleton->QueryHandleToIndex(1));
}
/**
* @tc.name: QueryHandleToIndexTest003
* @tc.desc: Verify the QueryHandleToIndex function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryHandleToIndexTest003, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::list<uint32_t> handleList { 1 };
skeleton->handleToStubIndex_.insert(std::pair<uint32_t, uint64_t>(1, 1));
uint32_t hd = 1;
uint64_t ret = skeleton->QueryHandleToIndex(handleList, hd);
uint64_t handle = 1;
EXPECT_EQ(ret, handle);
}
/**
* @tc.name: ProxyAttachDBinderSessionTest004
* @tc.desc: Verify the ProxyAttachDBinderSession function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, ProxyAttachDBinderSessionTest004, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::string name("nameTest");
std::string deviceId("deviceIdTest");
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
auto object = std::make_shared<DBinderSessionObject>(sessionMock, name, deviceId);
uint32_t handle = 1;
bool ret = skeleton->ProxyAttachDBinderSession(handle, object);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: ProxyQueryDBinderSessionTest001
* @tc.desc: Verify the ProxyQueryDBinderSession function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, ProxyQueryDBinderSessionTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::string name("nameTest");
std::string deviceId("deviceIdTest");
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
auto object = std::make_shared<DBinderSessionObject>(sessionMock, name, deviceId);
uint32_t handle = 1;
skeleton->proxyToSession_.insert(
std::pair<uint32_t, std::shared_ptr<DBinderSessionObject>>(handle, object));
auto ret = skeleton->ProxyQueryDBinderSession(handle);
EXPECT_NE(ret, nullptr);
}
/**
* @tc.name: QueryProxyBySessionHandleTest001
* @tc.desc: Verify the QueryProxyBySessionHandle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryProxyBySessionHandleTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::string name("nameTest");
std::string deviceId("deviceIdTest");
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
auto object = std::make_shared<DBinderSessionObject>(sessionMock, name, deviceId);
uint32_t handle = 1;
std::vector<uint32_t> proxyHandle { 1 };
skeleton->proxyToSession_.insert(
std::pair<uint32_t, std::shared_ptr<DBinderSessionObject>>(handle, object));
auto ret = skeleton->QueryProxyBySessionHandle(handle, proxyHandle);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: QueryHandleByDatabusSessionTest001
* @tc.desc: Verify the QueryHandleByDatabusSession function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryHandleByDatabusSessionTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
const std::string name("nameTest");
const std::string deviceId("deviceIdTest");
uint64_t index = 1;
skeleton->handleToStubIndex_.insert(std::pair<uint32_t, uint64_t>(1, 1));
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
auto object = std::make_shared<DBinderSessionObject>(sessionMock, name, deviceId);
uint32_t handle = 1;
skeleton->proxyToSession_.insert(
std::pair<uint32_t, std::shared_ptr<DBinderSessionObject>>(handle, object));
auto ret = skeleton->QueryHandleByDatabusSession(name, deviceId, index);
EXPECT_EQ(ret, handle);
}
/**
* @tc.name: QuerySessionByInfoTest001
* @tc.desc: Verify the QuerySessionByInfo function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QuerySessionByInfoTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
const std::string name("nameTest");
const std::string deviceId("deviceIdTest");
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
auto object = std::make_shared<DBinderSessionObject>(sessionMock, name, deviceId);
uint32_t handle = 1;
skeleton->proxyToSession_.insert(
std::pair<uint32_t, std::shared_ptr<DBinderSessionObject>>(handle, object));
auto ret = skeleton->QuerySessionByInfo(name, deviceId);
EXPECT_NE(ret, nullptr);
}
/**
* @tc.name: QueryThreadLockInfoTest001
* @tc.desc: Verify the SetRegistryObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryThreadLockInfoTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::shared_ptr<SocketThreadLockInfo> object =
std::make_shared<SocketThreadLockInfo>();
std::thread::id threadId;
skeleton->AttachThreadLockInfo(object, threadId);
auto ret = skeleton->QueryThreadLockInfo(threadId);
EXPECT_NE(ret, nullptr);
}
/**
* @tc.name: DeleteDataThreadFromIdleTest001
* @tc.desc: Verify the DeleteDataThreadFromIdle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, DeleteDataThreadFromIdleTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::thread::id threadId;
skeleton->AddDataThreadToIdle(threadId);
bool ret = skeleton->DeleteDataThreadFromIdle(threadId);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: GetIdleDataThreadTest001
* @tc.desc: Verify the GetIdleDataThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetIdleDataThreadTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::thread::id threadId;
skeleton->AddDataThreadToIdle(threadId);
auto ret = skeleton->GetIdleDataThread();
EXPECT_EQ(threadId, ret);
}
/**
* @tc.name: GetSocketIdleThreadNumTest001
* @tc.desc: Verify the GetSocketIdleThreadNum function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetSocketIdleThreadNumTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->SetMaxWorkThread(THREAD_NUM_2);
ASSERT_TRUE(skeleton->threadPool_ != nullptr);
int num = skeleton->threadPool_->GetSocketIdleThreadNum();
int ret = skeleton->GetSocketIdleThreadNum();
EXPECT_EQ(num, ret);
}
/**
* @tc.name: GetSocketTotalThreadNumTest002
* @tc.desc: Verify the GetSocketTotalThreadNum function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetSocketTotalThreadNumTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->SetMaxWorkThread(THREAD_NUM_2);
ASSERT_TRUE(skeleton->threadPool_ != nullptr);
int ret = skeleton->GetSocketTotalThreadNum();
int num = skeleton->threadPool_->GetSocketTotalThreadNum();
EXPECT_EQ(num, ret);
}
/**
* @tc.name: PopDataInfoFromThreadTest001
* @tc.desc: Verify the PopDataInfoFromThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, PopDataInfoFromThreadTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::thread::id threadId;
std::shared_ptr<ThreadProcessInfo> processInfo =
std::make_shared<ThreadProcessInfo>();
skeleton->AddDataInfoToThread(threadId, processInfo);
auto ret = skeleton->PopDataInfoFromThread(threadId);
EXPECT_NE(ret, nullptr);
}
/**
* @tc.name: GetSeqNumberTest001
* @tc.desc: Verify the GetSeqNumber function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetSeqNumberTest001, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->seqNumber_ = 0;
uint64_t num = skeleton->GetSeqNumber();
ASSERT_TRUE(num != 0);
}
/**
* @tc.name: GetSeqNumberTest002
* @tc.desc: Verify the GetSeqNumber function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetSeqNumberTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->seqNumber_ = std::numeric_limits<uint64_t>::max();
uint64_t num = skeleton->GetSeqNumber();
ASSERT_TRUE(num != 0);
}
/**
* @tc.name: IsContainsObjectTest002
* @tc.desc: Verify the IsContainsObject function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, IsContainsObjectTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
sptr<IRemoteObject> object = new IPCObjectStub(u"testObject");
skeleton->isContainStub_.clear();
bool ret = skeleton->IsContainsObject(object.GetRefPtr());
EXPECT_EQ(ret, false);
}
/**
* @tc.name: QueryHandleToIndexTest004
* @tc.desc: Verify the QueryHandleToIndex function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryHandleToIndexTest004, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::list<uint32_t> handleList { 1 };
uint32_t handle = 1;
skeleton->handleToStubIndex_.clear();
uint64_t ret = skeleton->QueryHandleToIndex(handleList, handle);
uint64_t hd = 0;
EXPECT_EQ(ret, hd);
}
/**
* @tc.name: ProxyQueryDBinderSessionTest002
* @tc.desc: Verify the ProxyQueryDBinderSession function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, ProxyQueryDBinderSessionTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
uint32_t handle = 1;
skeleton->proxyToSession_.clear();
auto ret = skeleton->ProxyQueryDBinderSession(handle);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: QueryHandleToIndexTest002
* @tc.desc: Verify the QueryHandleToIndex function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryHandleToIndexTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
uint32_t handle = 1;
skeleton->handleToStubIndex_.clear();
uint64_t ret = skeleton->QueryHandleToIndex(handle);
EXPECT_EQ(ret, 0);
}
/**
* @tc.name: QueryProxyBySessionHandleTest002
* @tc.desc: Verify the QueryProxyBySessionHandle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryProxyBySessionHandleTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
uint32_t handle = 1;
std::vector<uint32_t> proxyHandle { 1 };
skeleton->proxyToSession_.clear();
auto ret = skeleton->QueryProxyBySessionHandle(handle, proxyHandle);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: QueryHandleByDatabusSessionTest002
* @tc.desc: Verify the QueryHandleByDatabusSession function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryHandleByDatabusSessionTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
skeleton->handleToStubIndex_.clear();
skeleton->proxyToSession_.clear();
const std::string name("nameTest");
const std::string deviceId("deviceIdTest");
uint64_t index = 1;
skeleton->handleToStubIndex_.insert(std::pair<uint32_t, uint64_t>(1, 1));
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
auto object = std::make_shared<DBinderSessionObject>(sessionMock, name, deviceId);
uint32_t handle = 1;
skeleton->proxyToSession_.insert(
std::pair<uint32_t, std::shared_ptr<DBinderSessionObject>>(handle, object));
auto ret = skeleton->QueryHandleByDatabusSession(name, deviceId, index);
EXPECT_EQ(ret, handle);
}
/**
* @tc.name: QuerySessionByInfoTest002
* @tc.desc: Verify the QuerySessionByInfo function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QuerySessionByInfoTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
const std::string name("name");
const std::string deviceId("deviceId");
const std::string deviceIdTest("deviceIdTest");
skeleton->proxyToSession_.clear();
std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
auto object = std::make_shared<DBinderSessionObject>(sessionMock, name, deviceId);
uint32_t handle = 1;
skeleton->proxyToSession_.insert(
std::pair<uint32_t, std::shared_ptr<DBinderSessionObject>>(handle, object));
auto ret = skeleton->QuerySessionByInfo(name, deviceIdTest);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: QuerySessionByInfoTest003
* @tc.desc: Verify the QuerySessionByInfo function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QuerySessionByInfoTest003, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
const std::string name("nameTest");
const std::string deviceId("deviceIdTest");
skeleton->proxyToSession_.clear();
auto ret = skeleton->QuerySessionByInfo(name, deviceId);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: QueryThreadLockInfoTest002
* @tc.desc: Verify the QueryThreadLockInfo function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, QueryThreadLockInfoTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::thread::id threadId;
skeleton->threadLockInfo_.clear();
auto ret = skeleton->QueryThreadLockInfo(threadId);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.name: DeleteDataThreadFromIdleTest002
* @tc.desc: Verify the DeleteDataThreadFromIdle function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, DeleteDataThreadFromIdleTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::thread::id threadId;
skeleton->idleDataThreads_.clear();
bool ret = skeleton->DeleteDataThreadFromIdle(threadId);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: GetIdleDataThreadTest002
* @tc.desc: Verify the GetIdleDataThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetIdleDataThreadTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::thread::id threadId;
skeleton->idleDataThreads_.clear();
auto ret = skeleton->GetIdleDataThread();
EXPECT_EQ(threadId, ret);
}
/**
* @tc.name: GetSocketIdleThreadNumTest002
* @tc.desc: Verify the GetSocketIdleThreadNum function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetSocketIdleThreadNumTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
delete skeleton->threadPool_;
skeleton->threadPool_ = nullptr;
auto ret = skeleton->GetSocketIdleThreadNum();
EXPECT_EQ(0, ret);
}
/**
* @tc.name: GetSocketTotalThreadNumTest002
* @tc.desc: Verify the GetSocketTotalThreadNum function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, GetSocketTotalThreadNumTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
delete skeleton->threadPool_;
skeleton->threadPool_ = nullptr;
auto ret = skeleton->GetSocketTotalThreadNum();
EXPECT_EQ(0, ret);
}
/**
* @tc.name: PopDataInfoFromThreadTest002
* @tc.desc: Verify the PopDataInfoFromThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCProcessSkeletonUnitTest, PopDataInfoFromThreadTest002, TestSize.Level1)
{
IPCProcessSkeleton *skeleton = IPCProcessSkeleton::GetCurrent();
ASSERT_TRUE(skeleton != nullptr);
std::thread::id threadId;
std::shared_ptr<ThreadProcessInfo> processInfo =
std::make_shared<ThreadProcessInfo>();
skeleton->AddDataInfoToThread(threadId, processInfo);
ASSERT_TRUE(!(skeleton->dataInfoQueue_[threadId]).empty());
(skeleton->dataInfoQueue_[threadId]).clear();
auto ret = skeleton->PopDataInfoFromThread(threadId);
EXPECT_EQ(ret, nullptr);
}
\ No newline at end of file
/*
* 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.
*/
#ifndef OHOS_MOCK_SESSION_IMPL_H
#define OHOS_MOCK_SESSION_IMPL_H
#include <string>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "Session.h"
using Communication::SoftBus::Session;
namespace OHOS {
class MockSessionImpl : public std::enable_shared_from_this<MockSessionImpl>, public Session {
public:
MockSessionImpl() = default;
~MockSessionImpl() = default;
MOCK_CONST_METHOD0(GetMySessionName, const std::string &());
MOCK_CONST_METHOD0(GetPeerSessionName, const std::string &());
MOCK_CONST_METHOD0(GetDeviceId, const std::string &());
MOCK_CONST_METHOD0(GetPeerDeviceId, const std::string &());
MOCK_CONST_METHOD0(GetChannelId, int64_t());
MOCK_CONST_METHOD0(GetPeerUid, uid_t());
MOCK_CONST_METHOD0(GetPeerPid, pid_t());
MOCK_CONST_METHOD0(IsServerSide, bool());
MOCK_CONST_METHOD2(SendBytes, int(const void *buf, ssize_t len));
MOCK_CONST_METHOD0(GetSessionId, int());
MOCK_METHOD1(SetSessionId, void(int sessionId));
MOCK_METHOD1(SetMySessionName, void(const std::string &name));
MOCK_METHOD1(SetPeerSessionName, void(const std::string &name));
MOCK_METHOD1(SetPeerDeviceId, void(const std::string &name));
MOCK_METHOD1(SetDeviceId, void(const std::string &name));
MOCK_METHOD1(SetIsServer, void(bool isServer));
MOCK_METHOD1(SetPeerUid, void(uid_t peerUid));
MOCK_METHOD1(SetPeerPid, void(pid_t peerPid));
}; // namespace OHOS
}
#endif // OHOS_MOCK_SESSION_IMPL_H
......@@ -41,39 +41,8 @@ ohos_unittest("RPCDbinderTest") {
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
}
ohos_unittest("DbinderServiceStubTest") {
module_out_path = MODULE_OUTPUT_PATH
include_dirs = [
"//foundation/communication/ipc/ipc/native/c/manager/include",
"//foundation/communication/ipc/utils/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
]
sources = [ "dbinder_service_stub_unittest.cpp" ]
configs = []
deps = [
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:libdbinder",
]
resource_config_file =
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
}
###############################################################################
group("unittest") {
testonly = true
deps = [
":DbinderServiceStubTest",
":RPCDbinderTest",
]
deps = [ ":RPCDbinderTest" ]
}
/*
* 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 "rpc_log.h"
#include "log_tags.h"
#include "message_parcel.h"
#define private public
#define protected public
#include "dbinder_service_stub.h"
#undef protected
#undef private
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::HiviewDFX;
typedef unsigned long long binder_uintptr_t;
class DBinderServiceStubUnitTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void DBinderServiceStubUnitTest::SetUp()
{}
void DBinderServiceStubUnitTest::TearDown()
{}
void DBinderServiceStubUnitTest::SetUpTestCase()
{}
void DBinderServiceStubUnitTest::TearDownTestCase()
{}
/**
* @tc.name: DBinderServiceStub001
* @tc.desc: Verify the DBinderServiceStub function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceStubUnitTest, DBinderServiceStub001, TestSize.Level1)
{
const std::string service = "serviceTest";
const std::string device = "deviceTest";
binder_uintptr_t object = 11;
DBinderServiceStub dBinderServiceStub(service, device, object);
}
/**
* @tc.name: GetServiceName001
* @tc.desc: Verify the GetServiceName function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceStubUnitTest, GetServiceName001, TestSize.Level1)
{
const std::string service = "serviceTest";
const std::string device = "deviceTest";
binder_uintptr_t object = 11;
DBinderServiceStub dBinderServiceStub(service, device, object);
std::string ret = dBinderServiceStub.GetServiceName();
EXPECT_EQ(ret, "serviceTest");
}
/**
* @tc.name: GetDeviceID001
* @tc.desc: Verify the GetDeviceID function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceStubUnitTest, GetDeviceID001, TestSize.Level1)
{
const std::string service = "serviceTest";
const std::string device = "deviceTest";
binder_uintptr_t object = 11;
DBinderServiceStub dBinderServiceStub(service, device, object);
std::string ret = dBinderServiceStub.GetDeviceID();
EXPECT_EQ(ret, "deviceTest");
}
/**
* @tc.name: GetBinderObject001
* @tc.desc: Verify the GetBinderObject function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceStubUnitTest, GetBinderObject001, TestSize.Level1)
{
const std::string service = "serviceTest";
const std::string device = "deviceTest";
binder_uintptr_t object = 11;
DBinderServiceStub dBinderServiceStub(service, device, object);
binder_uintptr_t ret = dBinderServiceStub.GetBinderObject();
EXPECT_EQ(ret, 11);
}
/**
* @tc.name: ProcessProto001
* @tc.desc: Verify the ProcessProto function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceStubUnitTest, ProcessProto001, TestSize.Level1)
{
const std::string service = "serviceTest";
const std::string device = "deviceTest";
binder_uintptr_t object = 11;
DBinderServiceStub dBinderServiceStub(service, device, object);
uint32_t code = 11;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int32_t ret = dBinderServiceStub.ProcessProto(code, data, reply, option);
EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
}
......@@ -13,9 +13,6 @@
* limitations under the License.
*/
#define private public
#include "dbinder_service.h"
#undef private
#include "dbinder_service.h"
#include "gtest/gtest.h"
#include "rpc_log.h"
......@@ -43,222 +40,9 @@ void DBinderServiceUnitTest::SetUpTestCase() {}
void DBinderServiceUnitTest::TearDownTestCase() {}
/**
* @tc.name: ProcessOnSessionClosed001
* @tc.desc: Verify the ProcessOnSessionClosed function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed001, TestSize.Level1)
HWTEST_F(DBinderServiceUnitTest, process_closesession_001, TestSize.Level1)
{
sptr<DBinderService> dBinderService;
sptr<DBinderService> dBinderService_;
std::shared_ptr<Session> session = nullptr;
EXPECT_EQ(dBinderService->ProcessOnSessionClosed(session), false);
}
/**
* @tc.name: StartDBinderService001
* @tc.desc: Verify the StartDBinderService function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, StartDBinderService001, TestSize.Level1)
{
sptr<DBinderService> dBinderService ;
std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
bool res = dBinderService->StartDBinderService(callbackImpl);
EXPECT_EQ(res, false);
}
/**
* @tc.name: StartDBinderService002
* @tc.desc: Verify the StartDBinderService function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, StartDBinderService002, TestSize.Level1)
{
sptr<DBinderService> dBinderService ;
std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
DBinderService::mainThreadCreated_ = true;
bool res = dBinderService->StartDBinderService(callbackImpl);
EXPECT_EQ(res, false);
}
/**
* @tc.name: ReStartRemoteListener001
* @tc.desc: Verify the ReStartRemoteListener function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ReStartRemoteListener001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
dBinderService->remoteListener_ = nullptr;
bool res = dBinderService->ReStartRemoteListener();
EXPECT_EQ(res, false);
}
/**
* @tc.name: StartRemoteListener001
* @tc.desc: Verify the StartRemoteListener function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, StartRemoteListener001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
dBinderService->remoteListener_ = nullptr;
bool res = dBinderService->StartRemoteListener();
EXPECT_EQ(res, false);
}
/**
* @tc.name: RegisterRemoteProxy001
* @tc.desc: Verify the RegisterRemoteProxy function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy001, TestSize.Level1)
{
sptr<DBinderService> dBinderService ;
std::u16string serviceName = std::u16string();
sptr<IRemoteObject> binderObject = nullptr;
bool res = dBinderService->RegisterRemoteProxy(serviceName, binderObject);
EXPECT_EQ(res, false);
}
/**
* @tc.name: RegisterRemoteProxy002
* @tc.desc: Verify the RegisterRemoteProxy function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy002, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::u16string serviceName = std::u16string();
int32_t systemAbilityId = 0;
EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
}
/**
* @tc.name: QuerySessionObject001
* @tc.desc: Verify the QuerySessionObject function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, QuerySessionObject001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
binder_uintptr_t stub = 0;
std::shared_ptr<struct SessionInfo> testSession = nullptr;
testSession = dBinderService->QuerySessionObject(stub);
EXPECT_EQ(testSession, nullptr);
}
/**
* @tc.name: AttachDeathRecipient001
* @tc.desc: Verify the AttachDeathRecipient function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, AttachDeathRecipient001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
sptr<IRemoteObject> object = nullptr;
sptr<IRemoteObject::DeathRecipient> deathRecipient = nullptr;
bool res = dBinderService->AttachDeathRecipient(object, deathRecipient);
EXPECT_TRUE(res);
}
/**
* @tc.name: AttachCallbackProxy001
* @tc.desc: Verify the AttachCallbackProxy function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, AttachCallbackProxy001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
sptr<IRemoteObject> object = nullptr;
DBinderServiceStub *dbStub = nullptr;
bool res = dBinderService->AttachCallbackProxy(object, dbStub);
EXPECT_TRUE(res);
}
/**
* @tc.name: DetachProxyObject001
* @tc.desc: Verify the DetachProxyObject function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, DetachProxyObject001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
binder_uintptr_t binderObject = 0;
bool res = dBinderService->DetachProxyObject(binderObject);
EXPECT_EQ(res, false);
}
/**
* @tc.name: ReGrantPermissionTest001
* @tc.desc: Verify the ReGrantPermission function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ReGrantPermissionTest001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::string sessionName;
EXPECT_EQ(dBinderService->ReGrantPermission(sessionName), false);
}
/**
* @tc.name: ReGrantPermissionTest002
* @tc.desc: Verify the ReGrantPermission function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ReGrantPermissionTest002, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::string sessionName("testSession");
EXPECT_EQ(dBinderService->ReGrantPermission(sessionName), false);
}
/**
* @tc.name: ReGrantPermissionTest003
* @tc.desc: Verify the ReGrantPermission function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ReGrantPermissionTest003, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::string sessionName("000000123_456000000");
EXPECT_EQ(dBinderService->ReGrantPermission(sessionName), false);
}
/**
* @tc.name: ConvertToSecureDeviceIDTest001
* @tc.desc: Verify the ConvertToSecureDeviceID function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::string deviceID;
EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID), "****");
}
/**
* @tc.name: ConvertToSecureDeviceIDTest002
* @tc.desc: Verify the ConvertToSecureDeviceID function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest002, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::string deviceID("123456");
EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID),
deviceID.substr(0, ENCRYPT_LENGTH) + "****" + deviceID.substr(strlen(deviceID.c_str()) - ENCRYPT_LENGTH));
}
/**
* @tc.name: GetRemoteTransTypeTest003
* @tc.desc: Verify the GetRemoteTransType function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, GetRemoteTransTypeTest003, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
EXPECT_EQ(dBinderService->GetRemoteTransType(), IRemoteObject::DATABUS_TYPE);
EXPECT_EQ(dBinderService_->ProcessOnSessionClosed(session), false);
}
\ No newline at end of file
......@@ -45,10 +45,4 @@
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib" src="out"/>
</preparer>
</target>
<target name="IPCMockUnitTest">
<preparer>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib64" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib" src="out"/>
</preparer>
</target>
</configuration>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册