• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "schedule_node_helper_test.h"
17 
18 #include "iam_ptr.h"
19 
20 #include "mock_schedule_node_callback.h"
21 #include "mock_resource_node.h"
22 #include "resource_node_pool.h"
23 #include "schedule_node_helper.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using namespace testing;
29 using namespace testing::ext;
30 
31 using HdiAuthResultInfo = OHOS::HDI::UserAuth::V1_0::AuthResultInfo;
32 using HdiAuthSolution = OHOS::HDI::UserAuth::V1_0::AuthSolution;
33 using HdiExecutorSendMsg = OHOS::HDI::UserAuth::V1_0::ExecutorSendMsg;
34 using HdiAuthType = OHOS::HDI::UserAuth::V1_0::AuthType;
35 using HdiEnrollParam = OHOS::HDI::UserAuth::V1_0::EnrollParam;
36 using HdiExecutorInfo = OHOS::HDI::UserAuth::V1_0::ExecutorInfo;
37 using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_0::ScheduleInfo;
38 using HdiExecutorRole = OHOS::HDI::UserAuth::V1_0::ExecutorRole;
39 using HdiScheduleMode = OHOS::HDI::UserAuth::V1_0::ScheduleMode;
40 using HdiExecutorSecureLevel = OHOS::HDI::UserAuth::V1_0::ExecutorSecureLevel;
41 
SetUpTestCase()42 void ScheduleNodeHelperTest::SetUpTestCase()
43 {
44 }
45 
TearDownTestCase()46 void ScheduleNodeHelperTest::TearDownTestCase()
47 {
48 }
49 
SetUp()50 void ScheduleNodeHelperTest::SetUp()
51 {
52 }
53 
TearDown()54 void ScheduleNodeHelperTest::TearDown()
55 {
56 }
57 
58 HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTest_001, TestSize.Level0)
59 {
60     std::vector<HdiScheduleInfo> scheduleInfoList;
61     auto callback = Common::MakeShared<MockScheduleNodeCallback>();
62     EXPECT_NE(callback, nullptr);
63     std::vector<std::shared_ptr<ScheduleNode>> scheduleNodeList;
64     ScheduleNodeHelper::NodeOptionalPara para = {};
65     EXPECT_TRUE(ScheduleNodeHelper::BuildFromHdi(scheduleInfoList, callback, scheduleNodeList, para));
66 }
67 
68 HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTest_002, TestSize.Level0)
69 {
70     std::vector<HdiScheduleInfo> scheduleInfoList;
71     HdiScheduleInfo scheduleInfo = {};
72     scheduleInfo.authType = HdiAuthType::FACE;
73     scheduleInfo.executorMatcher = 10;
74     HdiExecutorInfo executorInfo1 = {};
75     executorInfo1.executorIndex = 60;
76     scheduleInfo.executors.push_back(executorInfo1);
77 
78     HdiExecutorInfo executorInfo2 = {};
79     executorInfo2.executorIndex = 90;
80     scheduleInfo.executors.push_back(executorInfo2);
81 
82     scheduleInfo.scheduleId = 20;
83     scheduleInfo.scheduleMode = HdiScheduleMode::AUTH;
84     scheduleInfo.templateIds.push_back(30);
85     scheduleInfoList.push_back(scheduleInfo);
86 
87     std::vector<std::vector<ExecutorRole>> executorRoles = {
88         {COLLECTOR, COLLECTOR},
89         {VERIFIER, VERIFIER},
90         {ALL_IN_ONE, ALL_IN_ONE},
91         {COLLECTOR, VERIFIER},
92         {COLLECTOR, ALL_IN_ONE},
93         {VERIFIER, COLLECTOR},
94         {VERIFIER, ALL_IN_ONE},
95         {ALL_IN_ONE, COLLECTOR},
96         {ALL_IN_ONE, VERIFIER},
97     };
98 
99     for (const auto &executorRole : executorRoles) {
100         auto resourceNode1 = MockResourceNode::CreateWithExecuteIndex(60, FACE, executorRole[0]);
101         EXPECT_NE(resourceNode1, nullptr);
102         auto resourceNode2 = MockResourceNode::CreateWithExecuteIndex(90, FACE, executorRole[1]);
103         EXPECT_NE(resourceNode2, nullptr);
104         EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode1));
105         EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode2));
106 
107         auto callback = Common::MakeShared<MockScheduleNodeCallback>();
108         EXPECT_NE(callback, nullptr);
109         std::vector<std::shared_ptr<ScheduleNode>> scheduleNodeList;
110         ScheduleNodeHelper::NodeOptionalPara para = {};
111         ScheduleNodeHelper::BuildFromHdi(scheduleInfoList, callback, scheduleNodeList, para);
112         ResourceNodePool::Instance().DeleteAll();
113     }
114 }
115 } // namespace UserAuth
116 } // namespace UserIam
117 } // namespace OHOS
118