提交 4658241e 编写于 作者: 1 18392170496

ipc ut branch

Sig:SIG_ApplicationFramework
Feature or Bugfix:Bugfix
Binary Source:No
Signed-off-by: N@ma-gentang <magentang3@huawei.com>
Signed-off-by: N18392170496 <magentang3@huawei.com>
上级 60eb9b93
......@@ -20,9 +20,24 @@ MODULE_OUTPUT_PATH = "ipc"
ohos_unittest("IPCNativeUnitTest") {
module_out_path = MODULE_OUTPUT_PATH
include_dirs = [ "//utils/system/safwk/native/include" ]
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",
]
sources = [ "ipc_core_unittest.cpp" ]
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",
]
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
......@@ -31,6 +46,7 @@ ohos_unittest("IPCNativeUnitTest") {
deps = [
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
......@@ -54,6 +70,34 @@ 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",
......@@ -63,6 +107,40 @@ ohos_unittest("IPCFileDescOpsTest") {
"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",
]
external_deps = [
"c_utils:utils",
"hitrace_native:libhitracechain",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
resource_config_file =
......@@ -83,6 +161,7 @@ ohos_unittest("IPCHiTraceUnitTest") {
deps = [
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
......@@ -112,6 +191,7 @@ if (support_jsapi) {
deps = [
"//foundation/arkui/napi:ace_napi",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
......@@ -125,12 +205,52 @@ 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 "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 Huawei Device Co., Ltd.
* Copyright (C) 2021-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
......@@ -14,9 +14,15 @@
*/
#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"
......@@ -24,8 +30,12 @@
#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
......@@ -34,8 +44,12 @@ using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::HiviewDFX;
static constexpr int MAX_TEST_COUNT = 1000;
static constexpr bool SUPPORT_ZBINDER = false;
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;
}
class IPCNativeUnitTest : public testing::Test {
public:
......@@ -90,6 +104,18 @@ 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
......@@ -104,6 +130,230 @@ 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
......@@ -116,6 +366,120 @@ 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
......@@ -429,7 +793,6 @@ HWTEST_F(IPCNativeUnitTest, SyncTransaction008, TestSize.Level1)
ASSERT_EQ(readDescriptor, descriptor);
}
/**
* @tc.name: SyncTransaction009
* @tc.desc: Test IPC stub data Normal release.
......@@ -473,6 +836,33 @@ 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.
......@@ -487,6 +877,32 @@ 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
......@@ -514,4 +930,151 @@ HWTEST_F(IPCNativeUnitTest, AccessTokenid001, TestSize.Level1)
} else {
ZLOGE(LABEL, "Got Stub node");
}
}
/**
* @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.
*/
#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,8 +41,39 @@ 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 = [ ":RPCDbinderTest" ]
deps = [
":DbinderServiceStubTest",
":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,6 +13,9 @@
* 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"
......@@ -40,9 +43,222 @@ void DBinderServiceUnitTest::SetUpTestCase() {}
void DBinderServiceUnitTest::TearDownTestCase() {}
HWTEST_F(DBinderServiceUnitTest, process_closesession_001, TestSize.Level1)
/**
* @tc.name: ProcessOnSessionClosed001
* @tc.desc: Verify the ProcessOnSessionClosed function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed001, TestSize.Level1)
{
sptr<DBinderService> dBinderService_;
sptr<DBinderService> dBinderService;
std::shared_ptr<Session> session = nullptr;
EXPECT_EQ(dBinderService_->ProcessOnSessionClosed(session), false);
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);
}
\ No newline at end of file
......@@ -45,4 +45,10 @@
<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.
先完成此消息的编辑!
想要评论请 注册