未验证 提交 02f51d64 编写于 作者: O openharmony_ci 提交者: Gitee

!534 IPC分支覆盖率用例补充

Merge pull request !534 from 张泊远yg/master
......@@ -295,6 +295,44 @@ ohos_unittest("InvokerFactoryTest") {
"//foundation/communication/ipc/test/resource/ipc/ohos_test.xml"
}
ohos_unittest("RPCFeatureUnitTest") {
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",
"//foundation/communication/ipc/ipc/native/c/rpc/src/",
]
sources = [ "rpc_feature_set_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
......@@ -306,6 +344,7 @@ group("unittest") {
":IPCMockUnitTest",
":IPCNativeUnitTest",
":InvokerFactoryTest",
":RPCFeatureUnitTest",
]
if (support_jsapi) {
deps += [ ":IPCNapiUnitTest" ]
......
/*
* 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 "securec.h"
#include "string_ex.h"
#include "rpc_feature_set.h"
using namespace testing::ext;
using namespace OHOS;
class RpcFeatureSetTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void RpcFeatureSetTest::SetUpTestCase()
{
}
void RpcFeatureSetTest::TearDownTestCase()
{
}
void RpcFeatureSetTest::SetUp()
{
}
void RpcFeatureSetTest::TearDown()
{
}
/**
* @tc.name: SetFeatureTransData001
* @tc.desc: Verify the IPCObjectProxy::SetFeatureTransData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, SetFeatureTransData001, TestSize.Level1)
{
FeatureTransData *data = nullptr;
uint32_t size = (uint32_t)sizeof(FeatureTransData);
bool res = SetFeatureTransData(data, size);
EXPECT_EQ(res, false);
}
/**
* @tc.name: SetFeatureTransData002
* @tc.desc: Verify the IPCObjectProxy::SetFeatureTransData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, SetFeatureTransData002, TestSize.Level1)
{
FeatureTransData data;
data.magicNum = 123456;
uint32_t size = 0;
bool res = SetFeatureTransData(&data, size);
EXPECT_EQ(res, false);
}
/**
* @tc.name: SetFeatureTransData003
* @tc.desc: Verify the IPCObjectProxy::SetFeatureTransData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, SetFeatureTransData003, TestSize.Level1)
{
FeatureTransData data;
data.magicNum = 123456;
data.tag = 1;
data.tokenId = 54321;
uint32_t size = (uint32_t)sizeof(FeatureTransData);
bool res = SetFeatureTransData(&data, size);
EXPECT_EQ(res, true);
}
/**
* @tc.name: GetTokenFromData001
* @tc.desc: Verify the IPCObjectProxy::GetTokenFromData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, GetTokenFromData001, TestSize.Level1)
{
FeatureTransData *data = nullptr;
uint32_t size = (uint32_t)sizeof(FeatureTransData);
uint32_t ret = GetTokenFromData(data, size);
EXPECT_EQ(ret, 0x0);
}
/**
* @tc.name: GetTokenFromData001
* @tc.desc: Verify the IPCObjectProxy::GetTokenFromData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, GetTokenFromData002, TestSize.Level1)
{
FeatureTransData data;
data.magicNum = 123456;
uint32_t size = 0;
uint32_t ret = GetTokenFromData(&data, size);
EXPECT_EQ(ret, 0x0);
}
/**
* @tc.name: GetTokenFromData001
* @tc.desc: Verify the IPCObjectProxy::GetTokenFromData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, GetTokenFromData003, TestSize.Level1)
{
FeatureTransData data;
data.magicNum = 123456;
data.tag = 0;
uint32_t size = (uint32_t)sizeof(FeatureTransData);
uint32_t ret = GetTokenFromData(&data, size);
EXPECT_EQ(ret, 0x0);
}
/**
* @tc.name: GetTokenFromData004
* @tc.desc: Verify the IPCObjectProxy::GetTokenFromData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, GetTokenFromData004, TestSize.Level1)
{
FeatureTransData data;
data.magicNum = ('R' << 24) | ('F' << 16) | ('S' << 8) | 43;
data.tag = 3;
uint32_t size = (uint32_t)sizeof(FeatureTransData);
uint32_t ret = GetTokenFromData(&data, size);
EXPECT_EQ(ret, 0x0);
}
/**
* @tc.name: GetTokenFromData005
* @tc.desc: Verify the IPCObjectProxy::GetTokenFromData function
* @tc.type: FUNC
*/
HWTEST_F(RpcFeatureSetTest, GetTokenFromData005, TestSize.Level1)
{
FeatureTransData data;
data.tokenId = 123456;
data.magicNum = ('R' << 24) | ('F' << 16) | ('S' << 8) | 43;
data.tag = 0;
uint32_t size = (uint32_t)sizeof(FeatureTransData);
uint32_t ret = GetTokenFromData(&data, size);
EXPECT_EQ(ret, 123456);
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ ohos_unittest("RPCDbinderTest") {
]
sources = [
"dbinder_death_recipient_unittest.cpp",
"dbinder_remote_listener_unittest.cpp",
"dbinder_service_stub_unittest.cpp",
"dbinder_service_unittest.cpp",
......
/*
* 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 "dbinder_service.h"
#include "gtest/gtest.h"
#include "rpc_log.h"
#include "log_tags.h"
#include "session_impl.h"
#define private public
#include "dbinder_death_recipient.h"
#undef private
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::HiviewDFX;
using Communication::SoftBus::Session;
using Communication::SoftBus::SessionImpl;
class DbinderDeathRecipientUnitTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_RPC, "DBinderRemoteListenerUnitTest" };
};
void DbinderDeathRecipientUnitTest::SetUp() {}
void DbinderDeathRecipientUnitTest::TearDown() {}
void DbinderDeathRecipientUnitTest::SetUpTestCase() {}
void DbinderDeathRecipientUnitTest::TearDownTestCase() {}
HWTEST_F(DbinderDeathRecipientUnitTest, OnRemoteDied001, TestSize.Level1)
{
DbinderDeathRecipient dbinderDeathRecipient;
wptr<IRemoteObject> remote = nullptr;
dbinderDeathRecipient.OnRemoteDied(remote);
}
\ No newline at end of file
......@@ -125,17 +125,114 @@ HWTEST_F(DBinderRemoteListenerUnitTest, senddatatoremote_002, TestSize.Level1)
EXPECT_EQ(dBinderRemoteListener_.SendDataToRemote(deviceId, &message), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, senddatatoremote_003, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "123";
DHandleEntryTxRx message;
message.head.len = sizeof(DHandleEntryTxRx);
EXPECT_EQ(dBinderRemoteListener_.SendDataToRemote(deviceId, &message), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, startlistener_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<DBinderRemoteListener> listener = nullptr;
EXPECT_EQ(dBinderRemoteListener_.StartListener(listener), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, startlistener_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<DBinderRemoteListener> listener = nullptr;
listener = std::make_shared<DBinderRemoteListener>(DBinderService::GetInstance());
EXPECT_EQ(dBinderRemoteListener_.StartListener(listener), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, StopListener_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
dBinderRemoteListener_.softbusManager_ = nullptr;
EXPECT_EQ(dBinderRemoteListener_.StopListener(), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, StopListener_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.StopListener(), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, closedatabussession_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "";
EXPECT_EQ(dBinderRemoteListener_.CloseDatabusSession(deviceId), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, closedatabussession_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "123";
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.CloseDatabusSession(deviceId), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, QueryOrNewDeviceLock_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "";
dBinderRemoteListener_.QueryOrNewDeviceLock(deviceId);
const std::string deviceId1 = "123456";
std::shared_ptr<DeviceLock> lockInfo = nullptr;
lockInfo = dBinderRemoteListener_.QueryOrNewDeviceLock(deviceId1);
EXPECT_TRUE(lockInfo != nullptr);
}
HWTEST_F(DBinderRemoteListenerUnitTest, SendDataReply_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "";
EXPECT_EQ(dBinderRemoteListener_.SendDataReply(deviceId, nullptr), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, SendDataReply_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "";
DHandleEntryTxRx message;
message.deviceIdInfo.fromDeviceId[0] = 't';
EXPECT_EQ(dBinderRemoteListener_.SendDataReply(deviceId, &message), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, SendDataReply_003, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "12345";
DHandleEntryTxRx message;
message.deviceIdInfo.fromDeviceId[0] = 't';
EXPECT_EQ(dBinderRemoteListener_.SendDataReply(deviceId, &message), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, OpenSoftbusSession_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string peerDeviceId = "12345";
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.OpenSoftbusSession(peerDeviceId), nullptr);
}
HWTEST_F(DBinderRemoteListenerUnitTest, OpenSoftbusSession_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string peerDeviceId = "";
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.OpenSoftbusSession(peerDeviceId), nullptr);
}
HWTEST_F(DBinderRemoteListenerUnitTest, GetPeerSession_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string peerDeviceId = "";
EXPECT_EQ(dBinderRemoteListener_.OpenSoftbusSession(peerDeviceId), nullptr);
}
\ No newline at end of file
......@@ -152,6 +152,25 @@ HWTEST_F(DBinderServiceStubUnitTest, ProcessProto002, TestSize.Level1)
EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
}
/**
* @tc.name: ProcessProto003
* @tc.desc: Verify the ProcessProto function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceStubUnitTest, ProcessProto003, 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);
}
/**
* @tc.name: OnRemoteRequest001
* @tc.desc: Verify the OnRemoteRequest function
......
......@@ -108,6 +108,21 @@ HWTEST_F(DBinderServiceUnitTest, StartDBinderService002, TestSize.Level1)
EXPECT_EQ(res, false);
}
/**
* @tc.name: StartDBinderService003
* @tc.desc: Verify the StartDBinderService function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, StartDBinderService003, TestSize.Level1)
{
sptr<DBinderService> dBinderService;
std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
DBinderService::mainThreadCreated_ = false;
dBinderService->remoteListener_ = nullptr;
bool res = dBinderService->StartDBinderService(callbackImpl);
EXPECT_EQ(res, false);
}
/**
* @tc.name: ReStartRemoteListener001
* @tc.desc: Verify the ReStartRemoteListener function
......@@ -134,6 +149,20 @@ HWTEST_F(DBinderServiceUnitTest, StartRemoteListener001, TestSize.Level1)
EXPECT_EQ(res, false);
}
/**
* @tc.name: StartRemoteListener002
* @tc.desc: Verify the StartRemoteListener function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, StartRemoteListener002, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>(dBinderService);
bool res = dBinderService->StartRemoteListener();
EXPECT_EQ(res, true);
}
/**
* @tc.name: RegisterRemoteProxy001
* @tc.desc: Verify the RegisterRemoteProxy function
......@@ -261,7 +290,7 @@ HWTEST_F(DBinderServiceUnitTest, StopRemoteListener001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::shared_ptr<DBinderRemoteListener> testListener = std::make_shared<DBinderRemoteListener>(dBinderService);
EXPECT_EQ(dBinderService->StartRemoteListener(), false);
EXPECT_EQ(dBinderService->StartRemoteListener(), true);
dBinderService->StopRemoteListener();
}
......@@ -1092,4 +1121,118 @@ HWTEST_F(DBinderServiceUnitTest, PopLoadSaItemTest001, TestSize.Level1)
dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject);
remoteObject = new IPCObjectProxy(1);
dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject);
}
/**
* @tc.name: SendMessageToRemote001
* @tc.desc: Verify the SendMessageToRemote function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, SendMessageToRemote001, TestSize.Level1)
{
uint32_t dBinderCode = 4;
uint32_t reason = 0;
std::shared_ptr<DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>(dBinderService);
dBinderService->SendMessageToRemote(dBinderCode, reason, replyMessage);
dBinderCode = 1;
dBinderService->SendMessageToRemote(dBinderCode, reason, replyMessage);
DBinderService *temp = new DBinderService();
DBinderService::instance_ = temp;
dBinderService = DBinderService::GetInstance();
EXPECT_EQ(dBinderService, DBinderService::instance_);
}
/**
* @tc.name: StartThreadPool001
* @tc.desc: Verify the StartThreadPool function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, StartThreadPool001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
dBinderService->threadPoolStarted_ = true;
bool res1 = dBinderService->StartThreadPool();
EXPECT_EQ(res1, true);
dBinderService->threadPoolStarted_ = false;
dBinderService->threadPool_ = nullptr;
dBinderService->StartThreadPool();
dBinderService->threadPool_ = std::make_unique<ThreadPool>("DBinderRemoteListener");
bool res2 = dBinderService->StartThreadPool();
EXPECT_EQ(res2, true);
}
/**
* @tc.name: StopThreadPool001
* @tc.desc: Verify the StopThreadPool function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, StopThreadPool001, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
dBinderService->threadPoolStarted_ = true;
dBinderService->StartThreadPool();
dBinderService->threadPoolStarted_ = false;
bool res = dBinderService->StartThreadPool();
EXPECT_EQ(res, false);
}
/**
* @tc.name: AddAsynMessageTask001
* @tc.desc: Verify the AddAsynMessageTask function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, AddAsynMessageTask001, TestSize.Level1)
{
std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<struct DHandleEntryTxRx>();
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
dBinderService->AddAsynMessageTask(message);
}
/**
* @tc.name: IsSameSession002
* @tc.desc: Verify the IsSameSession function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, IsSameSession002, TestSize.Level1)
{
std::shared_ptr<struct SessionInfo> oldSession= std::make_shared<struct SessionInfo>();
std::shared_ptr<struct SessionInfo> newSession= std::make_shared<struct SessionInfo>();
oldSession->stubIndex = 1;
oldSession->toPort = 2;
oldSession->fromPort = 3;
oldSession->type = 4;
oldSession->serviceName[0] = 't';
newSession->stubIndex = 2;
newSession->toPort = 2;
newSession->fromPort = 3;
newSession->type = 4;
newSession->serviceName[0] = 't';
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
newSession->stubIndex = 1;
newSession->toPort = 12;
EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
newSession->toPort = 2;
newSession->fromPort = 13;
EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
newSession->fromPort = 3;
newSession->type = 14;
EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
newSession->type = 4;
EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), true);
}
/**
* @tc.name: AttachSessionObject001
* @tc.desc: Verify the AttachSessionObject function
* @tc.type: FUNC
*/
HWTEST_F(DBinderServiceUnitTest, AttachSessionObject001, TestSize.Level1)
{
std::shared_ptr<struct SessionInfo> object = nullptr;
binder_uintptr_t stub = 0;
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
EXPECT_EQ(dBinderService->AttachSessionObject(object, stub), true);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册