fix: fix: ut coverage

Signed-off-by: 居凯 <shun0304@126.com>
Change-Id: Iae667d334b8f76ae8d59c2ea38513050f43247ba
This commit is contained in:
居凯 2024-11-07 20:12:08 +08:00
parent 3d4a0cc14d
commit 3082f64488
12 changed files with 1270 additions and 8 deletions

View File

@ -24,6 +24,10 @@ ohos_unittest("iam_executors_test") {
blocklist = "../../../cfi_blocklist.txt"
}
branch_protector_ret = "pac_ret"
cflags = [
"-Dprivate=public",
"-Dprotected=public",
]
include_dirs = [
"mock",
"../../../frameworks/native/executors/include",

View File

@ -89,6 +89,57 @@ HWTEST_F(DriverManagerUnitTest, DriverManagerTest_002, TestSize.Level0)
config.driver = Common::MakeShared<MockIAuthDriverHdi>();
EXPECT_EQ(IDriverManager::Start(hdiName2Config), USERAUTH_ERROR);
}
HWTEST_F(DriverManagerUnitTest, DriverManagerTest_003, TestSize.Level0)
{
std::string serviceName1 = "mockDriver1";
std::string serviceName2 = "mockDriver2";
HdiConfig config = {};
config.id = 10;
config.driver = Common::MakeShared<MockIAuthDriverHdi>();
std::map<std::string, HdiConfig> hdiName2Config;
hdiName2Config.emplace(serviceName1, config);
EXPECT_EQ(DriverManager::GetInstance().HdiConfigIsValid(hdiName2Config), true);
hdiName2Config.emplace(serviceName2, config);
EXPECT_EQ(DriverManager::GetInstance().HdiConfigIsValid(hdiName2Config), false);
EXPECT_EQ(IDriverManager::Start(hdiName2Config), USERAUTH_ERROR);
}
HWTEST_F(DriverManagerUnitTest, DriverManagerTest_004, TestSize.Level0)
{
std::string serviceName = "mockDriver";
HdiConfig config = {};
config.id = 10;
config.driver = Common::MakeShared<MockIAuthDriverHdi>();
std::map<std::string, HdiConfig> hdiName2Config;
hdiName2Config.emplace(serviceName, config);
EXPECT_EQ(DriverManager::GetInstance().HdiConfigIsValid(hdiName2Config), true);
std::shared_ptr<Driver> mockDriver = Common::MakeShared<Driver>(serviceName, config);
DriverManager::GetInstance().serviceName2Driver_.emplace(serviceName, mockDriver);
EXPECT_EQ(DriverManager::GetInstance().Start(hdiName2Config), USERAUTH_SUCCESS);
EXPECT_NE(DriverManager::GetInstance().GetDriverByServiceName(serviceName), nullptr);
DriverManager::GetInstance().OnFrameworkReady();
DriverManager::GetInstance().SubscribeHdiDriverStatus();
DriverManager::GetInstance().OnAllHdiDisconnect();
}
HWTEST_F(DriverManagerUnitTest, DriverManagerTest_005, TestSize.Level0)
{
std::string serviceName = "mockDriver";
HdiConfig config = {};
config.id = 10;
config.driver = Common::MakeShared<MockIAuthDriverHdi>();
std::map<std::string, HdiConfig> hdiName2Config;
hdiName2Config.emplace(serviceName, config);
EXPECT_EQ(DriverManager::GetInstance().HdiConfigIsValid(hdiName2Config), true);
DriverManager::GetInstance().serviceName2Driver_.emplace(serviceName, nullptr);
EXPECT_EQ(DriverManager::GetInstance().Start(hdiName2Config), USERAUTH_SUCCESS);
EXPECT_NE(DriverManager::GetInstance().GetDriverByServiceName(serviceName), nullptr);
DriverManager::GetInstance().OnFrameworkReady();
DriverManager::GetInstance().SubscribeHdiDriverStatus();
DriverManager::GetInstance().OnAllHdiDisconnect();
DriverManager::GetInstance().OnAllHdiDisconnect();
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -145,6 +145,9 @@ ohos_unittest("iam_services_test") {
"src/schedule_node_test.cpp",
"src/secure_user_info_test.cpp",
"src/simple_auth_context_test.cpp",
"src/soft_bus_base_socket_test.cpp",
"src/soft_bus_manager_test.cpp",
"src/soft_bus_server_socket_test.cpp",
"src/state_machine_test.cpp",
"src/template_cache_manager_test.cpp",
"src/ui_extension_ability_connection_test.cpp",

View File

@ -0,0 +1,37 @@
/*
* 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 SOFT_BUS_SERVER_SOCKET_TEST_H
#define SOFT_BUS_SERVER_SOCKET_TEST_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class SoftBusBaseSocketTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // SOFT_BUS_SERVER_SOCKET_TEST_H

View File

@ -0,0 +1,37 @@
/*
* 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 SOFT_BUS_MANAGER_TEST_H
#define SOFT_BUS_MANAGER_TEST_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class SoftBusManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // SOFT_BUS_MANAGER_TEST_H

View File

@ -0,0 +1,37 @@
/*
* 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 SOFT_BUS_BASE_SOCKET_TEST_H
#define SOFT_BUS_BASE_SOCKET_TEST_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class SoftBusServerSocketTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // SOFT_BUS_BASE_SOCKET_TEST_H

View File

@ -56,7 +56,7 @@ HWTEST_F(AttributesTest, AttributesSerialize, TestSize.Level0)
{
const std::vector<Attributes::AttributeKey> desired = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE,
Attributes::ATTR_TEMPLATE_ID_LIST, Attributes::ATTR_REMAIN_TIMES, Attributes::ATTR_FREEZING_TIME,
Attributes::ATTR_SCHEDULE_ID, Attributes::ATTR_SCHEDULE_MODE};
Attributes::ATTR_SCHEDULE_ID, Attributes::ATTR_SCHEDULE_MODE, Attributes::ATTR_CREDENTIAL_DIGEST};
Attributes attrs;
@ -65,6 +65,7 @@ HWTEST_F(AttributesTest, AttributesSerialize, TestSize.Level0)
EXPECT_TRUE(attrs.SetUint64Value(Attributes::ATTR_SCHEDULE_ID, UINT64_MAX));
EXPECT_TRUE(attrs.SetUint32ArrayValue(Attributes::ATTR_REMAIN_TIMES, {1, 3, 5, 7, 9}));
EXPECT_TRUE(attrs.SetUint32Value(Attributes::ATTR_SCHEDULE_MODE, UINT32_MAX));
EXPECT_TRUE(attrs.SetUint16Value(Attributes::ATTR_CREDENTIAL_DIGEST, UINT16_MAX));
EXPECT_TRUE(attrs.SetUint64ArrayValue(Attributes::ATTR_FREEZING_TIME, {2, 4, 6, 8, 10}));
EXPECT_TRUE(attrs.SetStringValue(Attributes::ATTR_TEMPLATE_ID_LIST, "iam"));
@ -92,6 +93,10 @@ HWTEST_F(AttributesTest, AttributesSerialize, TestSize.Level0)
EXPECT_TRUE(attrs2.GetUint32Value(Attributes::ATTR_SCHEDULE_MODE, u32Value));
EXPECT_EQ(u32Value, UINT32_MAX);
uint16_t u16Value;
EXPECT_TRUE(attrs2.GetUint16Value(Attributes::ATTR_CREDENTIAL_DIGEST, u16Value));
EXPECT_EQ(u16Value, UINT16_MAX);
std::vector<uint64_t> u64Vector;
EXPECT_TRUE(attrs2.GetUint64ArrayValue(Attributes::ATTR_FREEZING_TIME, u64Vector));
EXPECT_THAT(u64Vector, ElementsAre(2, 4, 6, 8, 10));
@ -118,11 +123,14 @@ HWTEST_F(AttributesTest, AttributesBoolValue, TestSize.Level0)
HWTEST_F(AttributesTest, AttributesUint64Value, TestSize.Level0)
{
Attributes attrs;
uint64_t value1;
uint64_t value2;
EXPECT_FALSE(attrs.GetUint64Value(Attributes::ATTR_RESULT_CODE, value1));
EXPECT_FALSE(attrs.GetUint64Value(Attributes::ATTR_SIGNATURE, value2));
EXPECT_TRUE(attrs.SetUint64Value(Attributes::ATTR_RESULT_CODE, UINT32_MAX));
EXPECT_TRUE(attrs.SetUint64Value(Attributes::ATTR_SIGNATURE, UINT64_MAX));
uint64_t value1;
uint64_t value2;
EXPECT_TRUE(attrs.GetUint64Value(Attributes::ATTR_RESULT_CODE, value1));
EXPECT_TRUE(attrs.GetUint64Value(Attributes::ATTR_SIGNATURE, value2));
EXPECT_EQ(value1, UINT32_MAX);
@ -160,11 +168,14 @@ HWTEST_F(AttributesTest, AttributesUint16Value, TestSize.Level0)
HWTEST_F(AttributesTest, AttributesUint8Value, TestSize.Level0)
{
Attributes attrs;
EXPECT_TRUE(attrs.SetUint8Value(Attributes::ATTR_RESULT_CODE, 0));
EXPECT_TRUE(attrs.SetUint8Value(Attributes::ATTR_SIGNATURE, UINT8_MAX));
uint8_t value1;
uint8_t value2;
EXPECT_FALSE(attrs.GetUint8Value(Attributes::ATTR_RESULT_CODE, value1));
EXPECT_FALSE(attrs.GetUint8Value(Attributes::ATTR_SIGNATURE, value2));
EXPECT_TRUE(attrs.SetUint8Value(Attributes::ATTR_RESULT_CODE, 0));
EXPECT_TRUE(attrs.SetUint8Value(Attributes::ATTR_SIGNATURE, UINT8_MAX));
EXPECT_TRUE(attrs.GetUint8Value(Attributes::ATTR_RESULT_CODE, value1));
EXPECT_TRUE(attrs.GetUint8Value(Attributes::ATTR_SIGNATURE, value2));
EXPECT_EQ(value1, 0);
@ -223,9 +234,11 @@ HWTEST_F(AttributesTest, AttributesUint32ByteArray, TestSize.Level0)
for (int i = 0; i < SIZE; i++) {
array.push_back(UINT32_MAX - i);
}
EXPECT_TRUE(attrs.SetUint32ArrayValue(Attributes::ATTR_FREEZING_TIME, array));
std::vector<uint32_t> out;
EXPECT_FALSE(attrs.GetUint32ArrayValue(Attributes::ATTR_FREEZING_TIME, out));
EXPECT_TRUE(attrs.SetUint32ArrayValue(Attributes::ATTR_FREEZING_TIME, array));
EXPECT_TRUE(attrs.GetUint32ArrayValue(Attributes::ATTR_FREEZING_TIME, out));
EXPECT_THAT(out, ElementsAreArray(array));
}
@ -325,6 +338,7 @@ HWTEST_F(AttributesTest, AttributesEmptyArrays, TestSize.Level0)
EXPECT_TRUE(attrs1.SetUint32ArrayValue(Attributes::ATTR_REMAIN_TIMES, u32Vector));
std::vector<uint16_t> u16Vector;
EXPECT_FALSE(attrs1.GetUint16ArrayValue(Attributes::ATTR_TEMPLATE_ID_LIST, u16Vector));
EXPECT_TRUE(attrs1.SetUint16ArrayValue(Attributes::ATTR_TEMPLATE_ID_LIST, u16Vector));
std::vector<uint8_t> u8Vector;
@ -412,14 +426,16 @@ HWTEST_F(AttributesTest, AttributesSetAndGetAttributesArray01, TestSize.Level0)
EXPECT_EQ(value1, 1);
Attributes setAttrs;
EXPECT_EQ(setAttrs.SetAttributesValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, attrs1), true);
Attributes attrs2;
std::vector<int32_t> array2;
EXPECT_EQ(setAttrs.GetInt32ArrayValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, array2), false);
EXPECT_EQ(setAttrs.GetAttributesValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, attrs2), false);
EXPECT_EQ(setAttrs.SetAttributesValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, attrs1), true);
EXPECT_EQ(setAttrs.GetAttributesValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, attrs2), true);
std::vector<int32_t> array1;
array1.push_back(1);
EXPECT_EQ(setAttrs.SetInt32ArrayValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, array1), true);
std::vector<int32_t> array2;
EXPECT_EQ(setAttrs.GetInt32ArrayValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, array2), true);
}
} // namespace UserAuth

View File

@ -0,0 +1,346 @@
/*
* 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 "soft_bus_base_socket_test.h"
#include "soft_bus_base_socket.h"
#include "soft_bus_manager.h"
#include "remote_connect_listener_manager.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
using namespace testing;
using namespace testing::ext;
void SoftBusBaseSocketTest::SetUpTestCase()
{
}
void SoftBusBaseSocketTest::TearDownTestCase()
{
}
void SoftBusBaseSocketTest::SetUp()
{
}
void SoftBusBaseSocketTest::TearDown()
{
}
class BaseSocketTest : public BaseSocket {
public:
explicit BaseSocketTest(const int32_t socketId);
~BaseSocketTest();
ResultCode SendMessage(const std::string &connectionName, const std::string &srcEndPoint,
const std::string &destEndPoint, const std::shared_ptr<Attributes> &attributes, MsgCallback &callback);
void OnBind(int32_t socketId, PeerSocketInfo info);
void OnShutdown(int32_t socketId, ShutdownReason reason);
void OnBytes(int32_t socketId, const void *data, uint32_t dataLen);
void OnQos(int32_t socketId, QoSEvent eventId, const QosTV *qos, uint32_t qosCount);
std::string GetConnectionName() override;
std::string GetNetworkId();
};
BaseSocketTest::BaseSocketTest(const int32_t socketId)
: BaseSocket(socketId)
{
}
BaseSocketTest::~BaseSocketTest()
{
}
ResultCode BaseSocketTest::SendMessage(const std::string &connectionName, const std::string &srcEndPoint,
const std::string &destEndPoint, const std::shared_ptr<Attributes> &attributes, MsgCallback &callback)
{
return SUCCESS;
}
void BaseSocketTest::OnBind(int32_t socketId, PeerSocketInfo info)
{
return;
}
void BaseSocketTest::OnShutdown(int32_t socketId, ShutdownReason reason)
{
return;
}
void BaseSocketTest::OnBytes(int32_t socketId, const void *data, uint32_t dataLen)
{
return;
}
void BaseSocketTest::OnQos(int32_t socketId, QoSEvent eventId, const QosTV *qos, uint32_t qosCount)
{
return;
}
std::string BaseSocketTest::GetConnectionName()
{
return "connectionName";
}
std::string BaseSocketTest::GetNetworkId()
{
return "networkId";
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestInsertMsgCallback, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
const std::string connectionName = "connectionName";
MsgCallback callback;
uint32_t timerId = 456;
EXPECT_NO_THROW(baseSocket->InsertMsgCallback(messageSeq, connectionName, callback, timerId));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestRemoveMsgCallback, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetMsgCallback, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
EXPECT_NO_THROW(baseSocket->GetMsgCallback(messageSeq));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestPrintTransferDuration, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
EXPECT_NO_THROW(baseSocket->PrintTransferDuration(messageSeq));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetReplyTimer, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
EXPECT_NO_THROW(baseSocket->GetReplyTimer(messageSeq));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStartReplyTimer, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
EXPECT_NO_THROW(baseSocket->StartReplyTimer(messageSeq));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStopReplyTimer, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
EXPECT_NO_THROW(baseSocket->StopReplyTimer(messageSeq));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestReplyTimerTimeOut, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
uint32_t messageSeq = 123;
EXPECT_NO_THROW(baseSocket->ReplyTimerTimeOut(messageSeq));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestSetDeviceNetworkId, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::string networkId = "456";
std::shared_ptr<Attributes> attributes = Common::MakeShared<Attributes>();
ASSERT_NE(attributes, nullptr);
EXPECT_NO_THROW(baseSocket->SetDeviceNetworkId(networkId, attributes));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestSendRequest, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::string connectionName = "connectionName";
std::string srcEndPoint = "123";
std::string destEndPoint = "456";
std::shared_ptr<Attributes> attributes = Common::MakeShared<Attributes>();
ASSERT_NE(attributes, nullptr);
MsgCallback callback;
EXPECT_EQ(baseSocket->SendRequest(socketId, connectionName, srcEndPoint, destEndPoint, attributes,
callback), GENERAL_ERROR);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestSendResponse, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::string connectionName = "connectionName";
std::string srcEndPoint = "123";
std::string destEndPoint = "456";
std::shared_ptr<Attributes> attributes = Common::MakeShared<Attributes>();
ASSERT_NE(attributes, nullptr);
uint32_t messageSeq = 123;
EXPECT_EQ(baseSocket->SendResponse(socketId, connectionName, srcEndPoint, destEndPoint, attributes,
messageSeq), GENERAL_ERROR);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestParseMessage_001, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::string networkId = "networkId";
void *message = nullptr;
uint32_t messageLen = 0;
std::shared_ptr<SoftBusMessage> result = baseSocket->ParseMessage(networkId, message, messageLen);
ASSERT_EQ(result, nullptr);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestParseMessage_002, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::string networkId = "networkId";
void *message = new char[10];
uint32_t messageLen = 0;
std::shared_ptr<SoftBusMessage> result = baseSocket->ParseMessage(networkId, message, messageLen);
ASSERT_EQ(result, nullptr);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestParseMessage_003, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::string networkId = "networkId";
void *message = new char[10];
uint32_t messageLen = 10;
std::shared_ptr<SoftBusMessage> result = baseSocket->ParseMessage(networkId, message, messageLen);
ASSERT_EQ(result, nullptr);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcessMessage_001, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::shared_ptr<SoftBusMessage> softBusMessage = Common::MakeShared<SoftBusMessage>(0, "", "", "", nullptr);
std::shared_ptr<Attributes> attributes = Common::MakeShared<Attributes>();
ASSERT_NE(attributes, nullptr);
EXPECT_NO_THROW(baseSocket->ProcessMessage(softBusMessage, attributes));
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_001, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::shared_ptr<SoftBusMessage> softBusMessage = nullptr;
ResultCode result = baseSocket->ProcDataReceive(socketId, softBusMessage);
ASSERT_EQ(result, INVALID_PARAMETERS);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_002, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::shared_ptr<SoftBusMessage> softBusMessage = Common::MakeShared<SoftBusMessage>(0, "", "", "", nullptr);
ResultCode result = baseSocket->ProcDataReceive(socketId, softBusMessage);
ASSERT_EQ(result, 2);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_003, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::shared_ptr<SoftBusMessage> softBusMessage = Common::MakeShared<SoftBusMessage>(0, "", "", "", nullptr);
softBusMessage->isAck_ = true;
ResultCode result = baseSocket->ProcDataReceive(socketId, softBusMessage);
ASSERT_EQ(result, 2);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_004, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::shared_ptr<SoftBusMessage> softBusMessage = Common::MakeShared<SoftBusMessage>(0, "", "", "", nullptr);
softBusMessage->isAck_ = true;
softBusMessage->CreateMessage(true);
ResultCode result = baseSocket->ProcDataReceive(socketId, softBusMessage);
ASSERT_EQ(result, 2);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_005, TestSize.Level0)
{
int32_t socketId = 1;
BaseSocketTest *baseSocket = new BaseSocketTest(socketId);
std::shared_ptr<SoftBusMessage> softBusMessage = Common::MakeShared<SoftBusMessage>(0, "", "", "", nullptr);
softBusMessage->isAck_ = true;
softBusMessage->CreateMessage(true);
ResultCode result = baseSocket->ProcDataReceive(socketId, softBusMessage);
ASSERT_EQ(result, 2);
delete baseSocket;
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestParseMessage_004, TestSize.Level0)
{
std::shared_ptr<SoftBusMessage> softBusMessage = Common::MakeShared<SoftBusMessage>(0, "", "", "", nullptr);
void *message = new char[10];
uint32_t messageLen = 0;
std::shared_ptr<Attributes> attributes = softBusMessage->ParseMessage(message, messageLen);
ASSERT_EQ(attributes, nullptr);
}
HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestParseMessage_005, TestSize.Level0)
{
std::shared_ptr<SoftBusMessage> softBusMessage = Common::MakeShared<SoftBusMessage>(0, "", "", "", nullptr);
void *message = new char[10];
uint32_t messageLen = 10;
std::shared_ptr<Attributes> attributes = softBusMessage->ParseMessage(message, messageLen);
ASSERT_EQ(attributes, nullptr);
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -0,0 +1,54 @@
/*
* 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 "soft_bus_manager_test.h"
#include "soft_bus_manager.h"
#include "socket_factory.h"
#include "socket.h"
#include "gtest/gtest.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
using namespace testing;
using namespace testing::ext;
void SoftBusManagerTest::SetUpTestCase()
{
}
void SoftBusManagerTest::TearDownTestCase()
{
}
void SoftBusManagerTest::SetUp()
{
}
void SoftBusManagerTest::TearDown()
{
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestCheckAndCopyStr, TestSize.Level0)
{
char dest[1];
uint32_t destLen = 2;
const std::string src = "123123123";
EXPECT_EQ(SoftBusManager::GetInstance().CheckAndCopyStr(dest, destLen, src), false);
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -0,0 +1,192 @@
/*
* 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 "soft_bus_server_socket_test.h"
#include "soft_bus_server_socket.h"
#include "soft_bus_manager.h"
#include "remote_connect_listener_manager.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
using namespace testing;
using namespace testing::ext;
void SoftBusServerSocketTest::SetUpTestCase()
{
}
void SoftBusServerSocketTest::TearDownTestCase()
{
}
void SoftBusServerSocketTest::SetUp()
{
}
void SoftBusServerSocketTest::TearDown()
{
}
class ServerSocketTest : public ServerSocket {
public:
explicit ServerSocketTest(const int32_t socketId);
~ServerSocketTest();
ResultCode SendMessage(const std::string &connectionName, const std::string &srcEndPoint,
const std::string &destEndPoint, const std::shared_ptr<Attributes> &attributes, MsgCallback &callback);
void OnBind(int32_t socketId, PeerSocketInfo info) override;
};
ServerSocketTest::ServerSocketTest(const int32_t socketId)
: ServerSocket(socketId)
{
}
ServerSocketTest::~ServerSocketTest()
{
}
void ServerSocketTest::OnBind(int32_t socketId, PeerSocketInfo info)
{
return;
}
ResultCode ServerSocketTest::SendMessage(const std::string &connectionName, const std::string &srcEndPoint,
const std::string &destEndPoint, const std::shared_ptr<Attributes> &attributes, MsgCallback &callback)
{
return SUCCESS;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestOnBind, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
PeerSocketInfo info;
EXPECT_NO_THROW(serverSocket->OnBind(-2, info));
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestOnShutdown, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
const std::string connectionName = "connectionName";
ShutdownReason reason = SHUTDOWN_REASON_LOCAL;
serverSocket->AddClientConnection(socketId, connectionName);
EXPECT_NO_THROW(serverSocket->OnShutdown(socketId, reason));
EXPECT_NO_THROW(serverSocket->OnShutdown(socketId, reason));
serverSocket->clientConnectionMap_ = {};
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestOnBytes, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
const std::string networkId = "connectionName";
void *data = new char[10];
uint32_t dataLen = 10;
EXPECT_NO_THROW(serverSocket->OnBytes(socketId, data, dataLen));
EXPECT_NO_THROW(serverSocket->AddServerSocket(socketId, networkId));
EXPECT_NO_THROW(serverSocket->OnBytes(socketId, data, dataLen));
serverSocket->serverSocketBindMap_ = {};
serverSocket->clientConnectionMap_ = {};
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestAddServerSocket, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
const std::string networkId = "connectionName";
EXPECT_NO_THROW(serverSocket->AddServerSocket(socketId, networkId));
EXPECT_NO_THROW(serverSocket->AddServerSocket(socketId, networkId));
serverSocket->serverSocketBindMap_ = {};
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestDeleteServerSocket, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
const std::string networkId = "connectionName";
EXPECT_NO_THROW(serverSocket->DeleteServerSocket(socketId));
EXPECT_NO_THROW(serverSocket->AddServerSocket(socketId, networkId));
EXPECT_NO_THROW(serverSocket->DeleteServerSocket(socketId));
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestGetNetworkIdBySocketId, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
std::string result = serverSocket->GetNetworkIdBySocketId(socketId);
EXPECT_EQ(result, "");
const std::string networkId = "connectionName";
EXPECT_NO_THROW(serverSocket->AddServerSocket(socketId, networkId));
result = serverSocket->GetNetworkIdBySocketId(socketId);
EXPECT_EQ(result, networkId);
serverSocket->serverSocketBindMap_ = {};
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestAddClientConnection, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
const std::string connectionName = "connectionName";
std::string clientConnectionName = serverSocket->GetClientConnectionName(socketId);
EXPECT_EQ(clientConnectionName, "");
EXPECT_NO_THROW(serverSocket->AddClientConnection(socketId, connectionName));
clientConnectionName = serverSocket->GetClientConnectionName(socketId);
EXPECT_EQ(clientConnectionName, connectionName);
EXPECT_NO_THROW(serverSocket->AddClientConnection(socketId, connectionName));
serverSocket->clientConnectionMap_ = {};
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestDeleteClientConnection, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
const std::string connectionName = "connectionName";
EXPECT_NO_THROW(serverSocket->DeleteClientConnection(socketId));
EXPECT_NO_THROW(serverSocket->AddClientConnection(socketId, connectionName));
EXPECT_NO_THROW(serverSocket->DeleteClientConnection(socketId));
serverSocket->clientConnectionMap_ = {};
delete serverSocket;
}
HWTEST_F(SoftBusServerSocketTest, SoftBusServerSocketTestGetSocketIdByClientConnectionName, TestSize.Level0)
{
int32_t socketId = 1;
ServerSocketTest *serverSocket = new ServerSocketTest(socketId);
const std::string connectionName = "connectionName";
EXPECT_NO_THROW(serverSocket->AddClientConnection(socketId, connectionName));
int32_t result = serverSocket->GetSocketIdByClientConnectionName(connectionName);
ASSERT_EQ(result, socketId);
const std::string connectionName1 = "connectionName1";
result = serverSocket->GetSocketIdByClientConnectionName(connectionName1);
ASSERT_EQ(result, -1);
serverSocket->clientConnectionMap_ = {};
delete serverSocket;
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -17,6 +17,9 @@
#include "iam_common_defines.h"
#include "template_cache_manager.h"
#include "os_account_manager.h"
#include "system_ability_definition.h"
#include "system_ability_status_change_stub.h"
namespace OHOS {
namespace UserIam {
@ -40,6 +43,34 @@ void TemplateCacheManagerTest::TearDown()
{
}
using OsAccountSubscriber = AccountSA::OsAccountSubscriber;
using OsAccountSubscribeInfo = AccountSA::OsAccountSubscribeInfo;
using OS_ACCOUNT_SUBSCRIBE_TYPE = AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE;
class ServiceStatusListener : public OHOS::SystemAbilityStatusChangeStub, public NoCopyable {
public:
static sptr<ServiceStatusListener> GetInstance();
static void Subscribe();
void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
private:
ServiceStatusListener() {};
~ServiceStatusListener() override {};
};
class OsAccountIdSubscriber : public OsAccountSubscriber, public NoCopyable {
public:
explicit OsAccountIdSubscriber(const OsAccountSubscribeInfo &subscribeInfo);
~OsAccountIdSubscriber() = default;
static std::shared_ptr<OsAccountIdSubscriber> GetInstance();
static void Subscribe();
static void Unsubscribe();
void OnAccountsChanged(const int& id) override;
};
HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTest_001, TestSize.Level0)
{
EXPECT_NO_THROW({
@ -49,6 +80,48 @@ HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTest_001, TestSize.Level0
TemplateCacheManager::GetInstance().UpdateTemplateCache(PIN);
});
}
HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnAddSystemAbility, TestSize.Level0)
{
int32_t systemAbilityId = 1;
const std::string deviceId = "123";
EXPECT_NO_THROW({
ServiceStatusListener::GetInstance()->OnAddSystemAbility(systemAbilityId, deviceId);
});
}
HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnRemoveSystemAbility_001, TestSize.Level0)
{
int32_t systemAbilityId = 1;
const std::string deviceId = "123";
EXPECT_NO_THROW({
ServiceStatusListener::GetInstance()->OnRemoveSystemAbility(systemAbilityId, deviceId);
});
}
HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnRemoveSystemAbility_002, TestSize.Level0)
{
int32_t systemAbilityId = 200;
const std::string deviceId = "123";
EXPECT_NO_THROW({
ServiceStatusListener::GetInstance()->OnAddSystemAbility(systemAbilityId, deviceId);
});
}
HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestUnsubscribe, TestSize.Level0)
{
EXPECT_NO_THROW({
OsAccountIdSubscriber::GetInstance()->Unsubscribe();
});
}
HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnAccountsChanged, TestSize.Level0)
{
const int id = 1;
EXPECT_NO_THROW({
OsAccountIdSubscriber::GetInstance()->OnAccountsChanged(id);
});
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -42,6 +42,19 @@ void UserAuthStubTest::TearDown()
{
}
HWTEST_F(UserAuthStubTest, UserAuthStubDefault, TestSize.Level0)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
MockUserAuthService service;
EXPECT_EQ(305, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubGetEnrolledStateStub001, TestSize.Level0)
{
MessageParcel data;
@ -388,6 +401,318 @@ HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub002, TestSize.Level0)
EXPECT_EQ(contextId, testContextId);
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub003, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub004, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
uint64_t testContextId = 2346728;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
EXPECT_CALL(service, AuthUser(_, _, _)).Times(1);
ON_CALL(service, AuthUser)
.WillByDefault(
[&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](AuthParamInner &authParam,
std::optional<RemoteAuthParam> &remoteAuthParam, sptr<UserAuthCallbackInterface> &callback) {
EXPECT_THAT(authParam.challenge, ElementsAreArray(testChallenge));
if (callback != nullptr) {
Attributes attr;
callback->OnResult(SUCCESS, attr);
}
return testContextId;
}
);
EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
uint32_t collectorTokenId = 123;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("verifierNetworkId"));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteUint32(collectorTokenId));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub005, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
uint32_t collectorTokenId = 123;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("verifierNetworkId"));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_TRUE(data.WriteBool(false));
EXPECT_TRUE(data.WriteUint32(collectorTokenId));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub006, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("verifierNetworkId"));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_TRUE(data.WriteBool(false));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub007, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("verifierNetworkId"));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub008, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("verifierNetworkId"));
EXPECT_TRUE(data.WriteBool(false));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub009, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("verifierNetworkId"));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub010, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub011, TestSize.Level0)
{
int32_t testUserId = 3467;
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
AuthType testAuthType = FACE;
AuthTrustLevel testAtl = ATL2;
sptr<MockAuthEventListenerService> callback(new (std::nothrow) MockAuthEventListenerService());
EXPECT_NE(callback, nullptr);
MockUserAuthService service;
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER;
std::vector<int32_t> testAuthTypeInts;
testAuthTypeInts.push_back(static_cast<AuthType>(1));
uint32_t authIntent = 0;
uint32_t collectorTokenId = 123;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteInt32(testUserId));
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
EXPECT_TRUE(data.WriteInt32(testAuthType));
EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts));
EXPECT_TRUE(data.WriteUint32(testAtl));
EXPECT_TRUE(data.WriteUint32(authIntent));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("verifierNetworkId"));
EXPECT_TRUE(data.WriteBool(true));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_TRUE(data.WriteBool(false));
EXPECT_TRUE(data.WriteUint32(collectorTokenId));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(GENERAL_ERROR, service.OnRemoteRequest(code, data, reply, option));
}
HWTEST_F(UserAuthStubTest, UserAuthStubIdentifyStub001, TestSize.Level0)
{
MessageParcel data;
@ -484,6 +809,34 @@ HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub002, TestSize.Lev
EXPECT_EQ(result, SUCCESS);
}
HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub003, TestSize.Level0)
{
uint64_t testContextId = 9346248;
MockUserAuthService service;
EXPECT_CALL(service, CancelAuthOrIdentify(_)).Times(1);
ON_CALL(service, CancelAuthOrIdentify)
.WillByDefault(
[&testContextId](uint64_t contextId) {
EXPECT_EQ(contextId, testContextId);
return SUCCESS;
}
);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_CANCEL_IDENTIFY;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteUint64(testContextId));
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
int32_t result = FAIL;
EXPECT_TRUE(reply.ReadInt32(result));
EXPECT_EQ(result, SUCCESS);
}
HWTEST_F(UserAuthStubTest, UserAuthStubGetVersionStub, TestSize.Level0)
{
int32_t testVersion = 1000;
@ -633,6 +986,65 @@ HWTEST_F(UserAuthStubTest, UserAuthStubSetGlobalConfigParamStub002, TestSize.Lev
EXPECT_TRUE(reply.ReadInt32(result));
EXPECT_EQ(result, GENERAL_ERROR);
}
HWTEST_F(UserAuthStubTest, UserAuthStubPrepareRemoteAuthStub_001, TestSize.Level0)
{
MockUserAuthService service;
sptr<MockAuthEventListenerService> callback(new (std::nothrow) MockAuthEventListenerService());
EXPECT_NE(callback, nullptr);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
int32_t result;
EXPECT_FALSE(reply.ReadInt32(result));
EXPECT_EQ(result, SUCCESS);
}
HWTEST_F(UserAuthStubTest, UserAuthStubPrepareRemoteAuthStub_002, TestSize.Level0)
{
MockUserAuthService service;
sptr<MockAuthEventListenerService> callback(new (std::nothrow) MockAuthEventListenerService());
EXPECT_NE(callback, nullptr);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
int32_t result;
EXPECT_FALSE(reply.ReadInt32(result));
EXPECT_EQ(result, SUCCESS);
}
HWTEST_F(UserAuthStubTest, UserAuthStubPrepareRemoteAuthStub_003, TestSize.Level0)
{
MockUserAuthService service;
sptr<MockUserAuthCallback> callback(new (std::nothrow) MockUserAuthCallback());
EXPECT_NE(callback, nullptr);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
uint32_t code = UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH;
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteString("collectorNetworkId"));
EXPECT_NE(callback->AsObject(), nullptr);
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
int32_t result;
EXPECT_FALSE(reply.ReadInt32(result));
EXPECT_EQ(result, SUCCESS);
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS