mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-11-23 07:50:24 +00:00
fix:add test cases
Signed-off-by: weimengxue <weimengxue1@h-partners.com>
This commit is contained in:
parent
a34a8711a0
commit
785ca340e7
@ -851,11 +851,11 @@ HWTEST_F(IPCNativeUnitTest, FlushCommandsTest001, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfoGetStubObjectTest001
|
||||
* @tc.name: CommAuthInfo_GetStubObjectTest001
|
||||
* @tc.desc: Verify the CommAuthInfo::GetStubObject function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetStubObjectTest001, TestSize.Level1)
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_GetStubObjectTest001, TestSize.Level1)
|
||||
{
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
@ -866,11 +866,11 @@ HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetStubObjectTest001, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfoGetRemotePidTest001
|
||||
* @tc.name: CommAuthInfo_GetRemotePidTest001
|
||||
* @tc.desc: Verify the CommAuthInfo::GetRemotePid function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemotePidTest001, TestSize.Level1)
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_GetRemotePidTest001, TestSize.Level1)
|
||||
{
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
@ -881,11 +881,11 @@ HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemotePidTest001, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfoGetRemoteUidTest001
|
||||
* @tc.name: CommAuthInfo_GetRemoteUidTest001
|
||||
* @tc.desc: Verify the CommAuthInfo::GetRemoteUid function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemoteUidTest001, TestSize.Level1)
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_GetRemoteUidTest001, TestSize.Level1)
|
||||
{
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
@ -896,11 +896,11 @@ HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemoteUidTest001, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfoGetRemoteDeviceIdTest001
|
||||
* @tc.name: CommAuthInfo_GetRemoteDeviceIdTest001
|
||||
* @tc.desc: Verify the CommAuthInfo::GetRemoteDeviceId function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemoteDeviceIdTest001, TestSize.Level1)
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_GetRemoteDeviceIdTest001, TestSize.Level1)
|
||||
{
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
@ -909,3 +909,69 @@ HWTEST_F(IPCNativeUnitTest, CommAuthInfoGetRemoteDeviceIdTest001, TestSize.Level
|
||||
CommAuthInfo commAuthInfo(object, 1, 1, 1, deviceId);
|
||||
EXPECT_STREQ(commAuthInfo.GetRemoteDeviceId().c_str(), deviceId.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfo_GetRemoteSocketIdTest001
|
||||
* @tc.desc: Verify the CommAuthInfo::GetRemoteSocketId function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_GetRemoteSocketIdTest001, TestSize.Level1)
|
||||
{
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
|
||||
std::string deviceId = "testdeviceId";
|
||||
CommAuthInfo commAuthInfo(object, 1, 1, 1, deviceId, 1);
|
||||
EXPECT_EQ(commAuthInfo.GetRemoteSocketId(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfo_SetRemoteSocketIdTest001
|
||||
* @tc.desc: Verify the CommAuthInfo::GetRemoteSocketId function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_SetRemoteSocketIdTest001, TestSize.Level1)
|
||||
{
|
||||
int32_t expectedSocketId = 12345;
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
|
||||
std::string deviceId = "testdeviceId";
|
||||
CommAuthInfo commAuthInfo(object, 1, 1, 1, deviceId, 1);
|
||||
commAuthInfo.SetRemoteSocketId(expectedSocketId);
|
||||
ASSERT_EQ(commAuthInfo.socketId_, expectedSocketId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfo_SetRemoteSocketIdTest002
|
||||
* @tc.desc: Verify the CommAuthInfo::GetRemoteSocketId function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_SetRemoteSocketIdTest002, TestSize.Level1)
|
||||
{
|
||||
int32_t expectedSocketId = -12345;
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
|
||||
std::string deviceId = "testdeviceId";
|
||||
CommAuthInfo commAuthInfo(object, 1, 1, 1, deviceId, 1);
|
||||
commAuthInfo.SetRemoteSocketId(expectedSocketId);
|
||||
ASSERT_EQ(commAuthInfo.socketId_, expectedSocketId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CommAuthInfo_SetRemoteSocketIdTest003
|
||||
* @tc.desc: Verify the CommAuthInfo::GetRemoteSocketId function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCNativeUnitTest, CommAuthInfo_SetRemoteSocketIdTest003, TestSize.Level1)
|
||||
{
|
||||
int32_t expectedSocketId = 0;
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> object = saMgr->AsObject();
|
||||
|
||||
std::string deviceId = "testdeviceId";
|
||||
CommAuthInfo commAuthInfo(object, 1, 1, 1, deviceId, 1);
|
||||
commAuthInfo.SetRemoteSocketId(expectedSocketId);
|
||||
ASSERT_EQ(commAuthInfo.socketId_, expectedSocketId);
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
#include "ipc_file_descriptor.h"
|
||||
#include "log_tags.h"
|
||||
#include "ipc_thread_skeleton.h"
|
||||
#include "iremote_invoker.h"
|
||||
#undef private
|
||||
|
||||
namespace OHOS {
|
||||
@ -111,6 +112,19 @@ HWTEST_F(IPCFileDescOpsTest, Marshalling001, TestSize.Level1)
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
HWTEST_F(IPCFileDescOpsTest, Marshalling002, TestSize.Level1)
|
||||
{
|
||||
IPCFileDescriptor fdesc;
|
||||
BinderInvoker *invoker = nullptr;
|
||||
IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
|
||||
current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = invoker;
|
||||
sptr<IPCFileDescriptor> object(new IPCFileDescriptor());
|
||||
|
||||
Parcel parcel;
|
||||
auto ret = fdesc.Marshalling(parcel, object);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
HWTEST_F(IPCFileDescOpsTest, Unmarshalling001, TestSize.Level1)
|
||||
{
|
||||
int fd = 9876;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "message_parcel.h"
|
||||
#include "rpc_log.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "securec.h"
|
||||
#include <iostream>
|
||||
|
||||
#define private public
|
||||
@ -753,4 +754,127 @@ HWTEST_F(DBinderServiceStubUnitTest, Marshalling003, TestSize.Level1)
|
||||
Parcel parcel;
|
||||
bool result = dBinderServiceStub1.Marshalling(parcel, stubObject);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveDBinderData001
|
||||
* @tc.desc: Verify the SaveDBinderData function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DBinderServiceStubUnitTest, SaveDBinderData001, TestSize.Level1)
|
||||
{
|
||||
const std::string service1 = "serviceTest1";
|
||||
const std::string device1 = "deviceTest1";
|
||||
binder_uintptr_t object = BINDER_OBJECT;
|
||||
DBinderServiceStub dbinderServiceStub(service1, device1, object);
|
||||
std::string localBusName = "localBusName";
|
||||
int ret = dbinderServiceStub.SaveDBinderData(localBusName);
|
||||
ASSERT_EQ(ret, DBINDER_SERVICE_FILL_DATA_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveDBinderData002
|
||||
* @tc.desc: Verify the SaveDBinderData function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DBinderServiceStubUnitTest, SaveDBinderData002, TestSize.Level1)
|
||||
{
|
||||
const std::string service1 = "serviceTest1";
|
||||
const std::string device1 = "deviceTest1";
|
||||
binder_uintptr_t object = BINDER_OBJECT;
|
||||
DBinderServiceStub dbinderServiceStub(service1, device1, object);
|
||||
std::string localBusName = "localBusName";
|
||||
dbinderServiceStub.dbinderData_ = std::make_unique<uint8_t[]>(sizeof(DBinderNegotiationData));
|
||||
ASSERT_NE(dbinderServiceStub.dbinderData_, nullptr);
|
||||
int ret = dbinderServiceStub.SaveDBinderData(localBusName);
|
||||
ASSERT_EQ(ret, DBINDER_SERVICE_FILL_DATA_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveDBinderData003
|
||||
* @tc.desc: Verify the SaveDBinderData function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DBinderServiceStubUnitTest, SaveDBinderData003, TestSize.Level1)
|
||||
{
|
||||
const std::string service1 = "serviceTest1";
|
||||
const std::string device1 = "deviceTest1";
|
||||
binder_uintptr_t object = BINDER_OBJECT;
|
||||
DBinderServiceStub dbinderServiceStub(service1, device1, object);
|
||||
binder_uintptr_t objectAddress = reinterpret_cast<binder_uintptr_t>(&dbinderServiceStub);
|
||||
std::string localBusName = "localBusName";
|
||||
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
|
||||
std::shared_ptr<SessionInfo> sessionInfo = std::make_shared<SessionInfo>();
|
||||
EXPECT_TRUE(sessionInfo != nullptr);
|
||||
sessionInfo->type = SESSION_TYPE_UNKNOWN;
|
||||
bool isInitialized = dBinderService->AttachSessionObject(sessionInfo, objectAddress);
|
||||
ASSERT_TRUE(isInitialized);
|
||||
dbinderServiceStub.dbinderData_ = nullptr;
|
||||
int ret = dbinderServiceStub.SaveDBinderData(localBusName);
|
||||
ASSERT_EQ(ret, DBINDER_SERVICE_MALLOC_ERR);
|
||||
bool result = dBinderService->DetachSessionObject(objectAddress);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveDBinderData004
|
||||
* @tc.desc: Verify the SaveDBinderData function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DBinderServiceStubUnitTest, SaveDBinderData004, TestSize.Level1)
|
||||
{
|
||||
const std::string service1 = "serviceTest1";
|
||||
const std::string device1 = "deviceTest1";
|
||||
binder_uintptr_t object = BINDER_OBJECT;
|
||||
DBinderServiceStub dbinderServiceStub(service1, device1, object);
|
||||
std::string localBusName = "localBusName";
|
||||
dbinderServiceStub.dbinderData_ = std::make_unique<uint8_t[]>(sizeof(DBinderNegotiationData));
|
||||
ASSERT_NE(dbinderServiceStub.dbinderData_, nullptr);
|
||||
DBinderNegotiationData data;
|
||||
data.stubIndex = 1;
|
||||
data.peerTokenId = 1;
|
||||
data.peerServiceName = "target_name";
|
||||
data.peerDeviceId = "target_device";
|
||||
data.localDeviceId = "local_device";
|
||||
data.localServiceName = "local_name";
|
||||
memcpy_s(dbinderServiceStub.dbinderData_.get(), sizeof(DBinderNegotiationData),
|
||||
&data, sizeof(DBinderNegotiationData));
|
||||
int ret = dbinderServiceStub.SaveDBinderData(localBusName);
|
||||
ASSERT_EQ(ret, DBINDER_SERVICE_FILL_DATA_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveDBinderData005
|
||||
* @tc.desc: Verify the SaveDBinderData function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DBinderServiceStubUnitTest, SaveDBinderData005, TestSize.Level1)
|
||||
{
|
||||
const std::string service1 = "serviceTest1";
|
||||
const std::string device1 = "deviceTest1";
|
||||
binder_uintptr_t object = BINDER_OBJECT;
|
||||
DBinderServiceStub dbinderServiceStub(service1, device1, object);
|
||||
binder_uintptr_t objectAddress = reinterpret_cast<binder_uintptr_t>(&dbinderServiceStub);
|
||||
std::string localBusName = "localBusName";
|
||||
dbinderServiceStub.dbinderData_ = std::make_unique<uint8_t[]>(sizeof(DBinderNegotiationData));
|
||||
ASSERT_NE(dbinderServiceStub.dbinderData_, nullptr);
|
||||
DBinderNegotiationData data;
|
||||
data.stubIndex = 1;
|
||||
data.peerTokenId = 1;
|
||||
data.peerServiceName = "target_name";
|
||||
data.peerDeviceId = "target_device";
|
||||
data.localDeviceId = "local_device";
|
||||
data.localServiceName = "local_name";
|
||||
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
|
||||
std::shared_ptr<SessionInfo> sessionInfo = std::make_shared<SessionInfo>();
|
||||
EXPECT_TRUE(sessionInfo != nullptr);
|
||||
sessionInfo->type = SESSION_TYPE_UNKNOWN;
|
||||
bool isInitialized = dBinderService->AttachSessionObject(sessionInfo, objectAddress);
|
||||
ASSERT_TRUE(isInitialized);
|
||||
memcpy_s(dbinderServiceStub.dbinderData_.get(), sizeof(DBinderNegotiationData),
|
||||
&data, sizeof(DBinderNegotiationData));
|
||||
int ret = dbinderServiceStub.SaveDBinderData(localBusName);
|
||||
ASSERT_EQ(ret, ERR_NONE);
|
||||
bool result = dBinderService->DetachSessionObject(objectAddress);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
Loading…
Reference in New Issue
Block a user