• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 "delete_context.h"
17 
18 #include "mock_context.h"
19 #include "mock_credential_info.h"
20 #include "mock_deletion.h"
21 #include "mock_schedule_node.h"
22 #include "mock_update_pin_param_info.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 namespace OHOS {
27 namespace UserIam {
28 namespace UserAuth {
29 class DeleteContextTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32 
33     static void TearDownTestCase();
34 
35     void SetUp() override;
36 
37     void TearDown() override;
38 };
39 
SetUpTestCase()40 void DeleteContextTest::SetUpTestCase()
41 {
42 }
43 
TearDownTestCase()44 void DeleteContextTest::TearDownTestCase()
45 {
46 }
47 
SetUp()48 void DeleteContextTest::SetUp()
49 {
50 }
51 
TearDown()52 void DeleteContextTest::TearDown()
53 {
54 }
55 
56 HWTEST_F(DeleteContextTest, DeleteContextTest_NullHdi, TestSize.Level0)
57 {
58     const uint64_t testContestId = 2;
59     const int32_t testResultCode = 7;
60     const auto finalResult = Common::MakeShared<Attributes>();
61     ASSERT_NE(finalResult, nullptr);
62     std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
63     ASSERT_NE(contextCallback, nullptr);
64     EXPECT_CALL(*contextCallback, OnResult(_, _)).Times(Exactly(1));
65     std::shared_ptr<Deletion> deletion = nullptr;
66 
67     auto oriContext = Common::MakeShared<DeleteContext>(testContestId, deletion, contextCallback);
68     ASSERT_NE(oriContext, nullptr);
69     std::shared_ptr<Context> context = oriContext;
70     std::shared_ptr<ScheduleNodeCallback> nodeCallback = oriContext;
71 
72     ASSERT_EQ(context->Start(), false);
73     ASSERT_EQ(context->Stop(), false);
74     nodeCallback->OnScheduleStoped(testResultCode, finalResult);
75 }
76 
77 HWTEST_F(DeleteContextTest, DeleteContextTest_NullCallback, TestSize.Level0)
78 {
79     const uint64_t testContestId = 2;
80     const ExecutorRole testRole = static_cast<ExecutorRole>(3);
81     const int32_t testModuleType = 4;
82     const std::vector<uint8_t> testAcquireMsg = {4, 5, 6};
83     const int32_t testResultCode = 7;
84     const auto finalResult = Common::MakeShared<Attributes>();
85     ASSERT_NE(finalResult, nullptr);
86 
87     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
88     ASSERT_NE(mockDeletion, nullptr);
89     std::shared_ptr<ContextCallback> contextCallback = nullptr;
90 
91     auto oriContext = Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
92     ASSERT_NE(oriContext, nullptr);
93     std::shared_ptr<ScheduleNodeCallback> nodeCallback = oriContext;
94 
95     nodeCallback->OnScheduleStarted();
96     nodeCallback->OnScheduleProcessed(testRole, testModuleType, testAcquireMsg);
97     nodeCallback->OnScheduleStoped(testResultCode, finalResult);
98 }
99 
100 HWTEST_F(DeleteContextTest, DeleteContextTest_BasicInfo, TestSize.Level0)
101 {
102     const uint64_t testContestId = 2;
103 
104     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
105     ASSERT_NE(mockDeletion, nullptr);
106     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
107     ASSERT_NE(contextCallback, nullptr);
108 
109     auto oriContext = Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
110     ASSERT_NE(oriContext, nullptr);
111     std::shared_ptr<Context> context = oriContext;
112 
113     ASSERT_EQ(context->GetContextId(), testContestId);
114     ASSERT_EQ(context->GetContextType(), CONTEXT_DELETE);
115 }
116 
117 HWTEST_F(DeleteContextTest, DeleteContextTest_Start_001, TestSize.Level0)
118 {
119     static const uint64_t testContestId = 2;
120 
121     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
122     ASSERT_NE(mockDeletion, nullptr);
123     EXPECT_CALL(*mockDeletion, GetLatestError()).Times(1);
124     EXPECT_CALL(*mockDeletion, Start(_, _, _))
125         .Times(Exactly(1))
126         .WillOnce([](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
__anon0d857a950102(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList, std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) 127                       std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) {
128             isCredentialDelete = false;
129             return false;
130         });
131     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
132     ASSERT_NE(contextCallback, nullptr);
133     std::shared_ptr<Context> context =
134         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
135     ASSERT_NE(context, nullptr);
136     ASSERT_EQ(context->Start(), false);
137 }
138 
139 HWTEST_F(DeleteContextTest, DeleteContextTest_Start_002, TestSize.Level0)
140 {
141     static const uint64_t testContestId = 2;
142 
143     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
144     ASSERT_NE(mockDeletion, nullptr);
145     EXPECT_CALL(*mockDeletion, Start(_, _, _))
146         .Times(Exactly(1))
147         .WillOnce([](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
__anon0d857a950202(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList, std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) 148                       std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) {
149             isCredentialDelete = false;
150             return true;
151         });
152     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
153     ASSERT_NE(contextCallback, nullptr);
154     std::shared_ptr<Context> context =
155         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
156     ASSERT_NE(context, nullptr);
157     ASSERT_EQ(context->Start(), false);
158 }
159 
160 HWTEST_F(DeleteContextTest, DeleteContextTest_Start_003, TestSize.Level0)
161 {
162     static const uint64_t testContestId = 2;
163 
164     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
165     ASSERT_NE(mockDeletion, nullptr);
166     EXPECT_CALL(*mockDeletion, Start(_, _, _))
167         .Times(Exactly(1))
168         .WillOnce([](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
__anon0d857a950302(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList, std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) 169                       std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) {
170             scheduleList.push_back(Common::MakeShared<MockScheduleNode>());
171             scheduleList.push_back(Common::MakeShared<MockScheduleNode>());
172             return true;
173         });
174     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
175     ASSERT_NE(contextCallback, nullptr);
176     std::shared_ptr<Context> context =
177         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
178     ASSERT_NE(context, nullptr);
179     ASSERT_EQ(context->Start(), false);
180 }
181 
182 HWTEST_F(DeleteContextTest, DeleteContextTest_Start_004, TestSize.Level0)
183 {
184     static const uint64_t testContestId = 2;
185 
186     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
187     ASSERT_NE(mockDeletion, nullptr);
188     EXPECT_CALL(*mockDeletion, Start(_, _, _))
189         .Times(Exactly(1))
190         .WillOnce([](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
__anon0d857a950402(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList, std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) 191                       std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) {
192             auto scheduleNode = Common::MakeShared<MockScheduleNode>();
193             EXPECT_NE(scheduleNode, nullptr);
194 
195             EXPECT_CALL(*scheduleNode, StartSchedule()).Times(Exactly(1)).WillOnce(Return(false));
196             scheduleList.push_back(scheduleNode);
197             return true;
198         });
199     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
200     ASSERT_NE(contextCallback, nullptr);
201     std::shared_ptr<Context> context =
202         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
203     ASSERT_NE(context, nullptr);
204     ASSERT_EQ(context->Start(), false);
205 }
206 
207 HWTEST_F(DeleteContextTest, DeleteContextTest_Start_005, TestSize.Level0)
208 {
209     static const uint64_t testContestId = 2;
210     static const uint64_t testScheduleId = 3;
211 
212     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
213     ASSERT_NE(mockDeletion, nullptr);
214     EXPECT_CALL(*mockDeletion, Start(_, _, _))
215         .Times(Exactly(1))
216         .WillOnce([](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
__anon0d857a950502(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList, std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) 217             std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) {
218             EXPECT_EQ(scheduleList.size(), 0U);
219             auto scheduleNode = Common::MakeShared<MockScheduleNode>();
220             EXPECT_NE(scheduleNode, nullptr);
221             EXPECT_CALL(*scheduleNode, StartSchedule()).Times(Exactly(1)).WillOnce(Return(true));
222             EXPECT_CALL(*scheduleNode, GetScheduleId()).WillRepeatedly(Return(testScheduleId));
223             scheduleList.push_back(scheduleNode);
224             return true;
225         });
226     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
227     ASSERT_NE(contextCallback, nullptr);
228     std::shared_ptr<Context> context =
229         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
230     ASSERT_NE(context, nullptr);
231     ASSERT_EQ(context->Start(), true);
232     ASSERT_EQ(context->Start(), false);
233     auto node = context->GetScheduleNode(testScheduleId);
234     ASSERT_NE(node, nullptr);
235     node = context->GetScheduleNode(testScheduleId + 1);
236     ASSERT_EQ(node, nullptr);
237 }
238 
239 HWTEST_F(DeleteContextTest, DeleteContextTest_Stop_001, TestSize.Level0)
240 {
241     static const uint64_t testContestId = 2;
242 
243     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
244     ASSERT_NE(mockDeletion, nullptr);
245     EXPECT_CALL(*mockDeletion, GetLatestError()).Times(1);
__anon0d857a950602() 246     EXPECT_CALL(*mockDeletion, Cancel()).Times(Exactly(1)).WillOnce([]() {
247         return false;
248     });
249     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
250     ASSERT_NE(contextCallback, nullptr);
251     std::shared_ptr<Context> context =
252         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
253     ASSERT_NE(context, nullptr);
254     ASSERT_EQ(context->Stop(), false);
255 }
256 
257 HWTEST_F(DeleteContextTest, DeleteContextTest_Stop_002, TestSize.Level0)
258 {
259     static const uint64_t testContestId = 2;
260     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
261     ASSERT_NE(mockDeletion, nullptr);
__anon0d857a950702() 262     EXPECT_CALL(*mockDeletion, Cancel()).Times(Exactly(1)).WillOnce([]() { return true; });
263     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
264     ASSERT_NE(contextCallback, nullptr);
265     std::shared_ptr<Context> context =
266         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
267     ASSERT_NE(context, nullptr);
268     ASSERT_EQ(context->Stop(), true);
269 }
270 
271 HWTEST_F(DeleteContextTest, DeleteContextTest_Stop_003, TestSize.Level0)
272 {
273     static const uint64_t testContestId = 2;
274 
275     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
276     ASSERT_NE(mockDeletion, nullptr);
277     EXPECT_CALL(*mockDeletion, Start(_, _, _)).Times(1);
278     ON_CALL(*mockDeletion, Start)
279         .WillByDefault(
280             [](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
__anon0d857a950802(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList, std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) 281                 std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) {
282                 scheduleList.push_back(nullptr);
283                 return true;
284             }
285         );
__anon0d857a950902() 286     EXPECT_CALL(*mockDeletion, Cancel()).Times(Exactly(1)).WillOnce([]() {
287         return true;
288     });
289     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
290     ASSERT_NE(contextCallback, nullptr);
291     std::shared_ptr<Context> context =
292         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
293     ASSERT_NE(context, nullptr);
294     ASSERT_EQ(context->Start(), false);
295     ASSERT_EQ(context->Stop(), true);
296 }
297 
298 HWTEST_F(DeleteContextTest, DeleteContextTest_Stop_004, TestSize.Level0)
299 {
300     static const uint64_t testContestId = 2;
301 
302     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
303     ASSERT_NE(mockDeletion, nullptr);
304     EXPECT_CALL(*mockDeletion, Start(_, _, _)).Times(1);
305     ON_CALL(*mockDeletion, Start)
306         .WillByDefault(
307             [](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
__anon0d857a950a02(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList, std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) 308                 std::shared_ptr<ScheduleNodeCallback> callback, bool &isCredentialDelete) {
309                 auto scheduleNode = Common::MakeShared<MockScheduleNode>();
310                 EXPECT_NE(scheduleNode, nullptr);
311                 EXPECT_CALL(*scheduleNode, StartSchedule()).Times(1);
312                 EXPECT_CALL(*scheduleNode, StopSchedule()).Times(1);
313                 scheduleList.push_back(scheduleNode);
314                 return true;
315             }
316         );
317     EXPECT_CALL(*mockDeletion, GetLatestError()).Times(1);
__anon0d857a950b02() 318     EXPECT_CALL(*mockDeletion, Cancel()).Times(Exactly(1)).WillOnce([]() {
319         return false;
320     });
321     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
322     ASSERT_NE(contextCallback, nullptr);
323     std::shared_ptr<Context> context =
324         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
325     ASSERT_NE(context, nullptr);
326     ASSERT_EQ(context->Start(), false);
327     ASSERT_EQ(context->Stop(), false);
328 }
329 
330 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleStarted, TestSize.Level0)
331 {
332     static const uint64_t testContestId = 2;
333 
334     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
335     ASSERT_NE(mockDeletion, nullptr);
336     std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
337     ASSERT_NE(contextCallback, nullptr);
338 
339     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
340         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
341     ASSERT_NE(nodeCallback, nullptr);
342     nodeCallback->OnScheduleStarted();
343 }
344 
345 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleProcessed, TestSize.Level0)
346 {
347     static const uint64_t testContestId = 2;
348     const ExecutorRole testRole = static_cast<ExecutorRole>(3);
349     const int32_t testModuleType = 4;
350     const std::vector<uint8_t> testAcquireMsg = {4, 5, 6};
351 
352     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
353     ASSERT_NE(mockDeletion, nullptr);
354     auto contextCallback = Common::MakeShared<MockContextCallback>();
355     ASSERT_NE(contextCallback, nullptr);
356     EXPECT_CALL(*contextCallback, OnAcquireInfo(_, _, _))
357         .WillOnce(
__anon0d857a950c02(ExecutorRole src, int32_t moduleType, const std::vector<uint8_t> &acquireMsg) 358             [](ExecutorRole src, int32_t moduleType, const std::vector<uint8_t> &acquireMsg) {
359                 EXPECT_EQ(moduleType, 4);
360             }
361         );
362 
363     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
364         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
365     ASSERT_NE(nodeCallback, nullptr);
366     nodeCallback->OnScheduleProcessed(testRole, testModuleType, testAcquireMsg);
367 }
368 
369 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleStoped_001, TestSize.Level0)
370 {
371     static const uint64_t testContestId = 2;
372     static const int32_t testResultCode = 7;
373 
374     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
375     ASSERT_NE(mockDeletion, nullptr);
376     std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
377     ASSERT_NE(contextCallback, nullptr);
378     EXPECT_CALL(*contextCallback, OnResult(_, _))
379         .Times(Exactly(1))
__anon0d857a950d02(int32_t resultCode, const Attributes &finalResult) 380         .WillOnce([](int32_t resultCode, const Attributes &finalResult) {
381             EXPECT_EQ(resultCode, testResultCode);
382         });
383 
384     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
385         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
386     ASSERT_NE(nodeCallback, nullptr);
387     // Error: result is null when testResultCode is not success
388     std::shared_ptr<Attributes> result = nullptr;
389     nodeCallback->OnScheduleStoped(testResultCode, result);
390 }
391 
392 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleStoped_002, TestSize.Level0)
393 {
394     static const uint64_t testContestId = 2;
395     static const int32_t testResultCode = ResultCode::SUCCESS;
396 
397     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
398     ASSERT_NE(mockDeletion, nullptr);
399     std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
400     ASSERT_NE(contextCallback, nullptr);
401     EXPECT_CALL(*contextCallback, OnResult(_, _))
402         .Times(Exactly(1))
__anon0d857a950e02(int32_t resultCode, const Attributes &finalResult) 403         .WillOnce([](int32_t resultCode, const Attributes &finalResult) {
404             EXPECT_EQ(resultCode, ResultCode::GENERAL_ERROR);
405         });
406 
407     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
408         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
409     ASSERT_NE(nodeCallback, nullptr);
410     // Error: result is null when testResultCode is success
411     std::shared_ptr<Attributes> result = nullptr;
412     nodeCallback->OnScheduleStoped(testResultCode, result);
413 }
414 
415 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleStoped_003, TestSize.Level0)
416 {
417     static const uint64_t testContestId = 2;
418     static const int32_t testResultCode = ResultCode::SUCCESS;
419 
420     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
421     ASSERT_NE(mockDeletion, nullptr);
422     std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
423     ASSERT_NE(contextCallback, nullptr);
424     EXPECT_CALL(*contextCallback, OnResult(_, _))
425         .Times(Exactly(1))
__anon0d857a950f02(int32_t resultCode, const Attributes &finalResult) 426         .WillOnce([](int32_t resultCode, const Attributes &finalResult) {
427             EXPECT_EQ(resultCode, ResultCode::GENERAL_ERROR);
428         });
429 
430     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
431         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
432     ASSERT_NE(nodeCallback, nullptr);
433     std::shared_ptr<Attributes> result = Common::MakeShared<Attributes>();
434     ASSERT_NE(result, nullptr);
435     nodeCallback->OnScheduleStoped(testResultCode, result);
436 }
437 
438 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleStoped_004, TestSize.Level0)
439 {
440     static const uint64_t testContestId = 2;
441     static const int32_t testResultCode = ResultCode::SUCCESS;
442     static const std::vector<uint8_t> testScheduleResult = {3, 4, 5, 6};
443 
444     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
445     ASSERT_NE(mockDeletion, nullptr);
446     EXPECT_CALL(*mockDeletion, GetLatestError()).Times(1);
447     EXPECT_CALL(*mockDeletion, Update(_, _))
448         .Times(Exactly(1))
__anon0d857a951002(const std::vector<uint8_t> &scheduleResult, std::shared_ptr<CredentialInfoInterface> &info) 449         .WillOnce([](const std::vector<uint8_t> &scheduleResult, std::shared_ptr<CredentialInfoInterface> &info) {
450             EXPECT_EQ(scheduleResult, testScheduleResult);
451             return false;
452         });
453     std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
454     ASSERT_NE(contextCallback, nullptr);
455     EXPECT_CALL(*contextCallback, OnResult(_, _))
456         .Times(Exactly(1))
__anon0d857a951102(int32_t resultCode, const Attributes &finalResult) 457         .WillOnce([](int32_t resultCode, const Attributes &finalResult) {
458             EXPECT_EQ(resultCode, ResultCode::GENERAL_ERROR);
459         });
460 
461     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
462         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
463     ASSERT_NE(nodeCallback, nullptr);
464     std::shared_ptr<Attributes> result = Common::MakeShared<Attributes>();
465     ASSERT_NE(result, nullptr);
466     bool ret1 = result->SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, testScheduleResult);
467     ASSERT_EQ(ret1, true);
468 
469     bool ret2 = result->SetUint8ArrayValue(Attributes::ATTR_RESULT, testScheduleResult);
470     ASSERT_EQ(ret2, true);
471     nodeCallback->OnScheduleStoped(testResultCode, result);
472 }
473 
474 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleStoped_005, TestSize.Level0)
475 {
476     static const uint64_t testContestId = 2;
477     static const std::vector<uint8_t> testScheduleResult = {3, 4, 5, 6};
478 
479     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
480     ASSERT_NE(mockDeletion, nullptr);
481     EXPECT_CALL(*mockDeletion, Update(_, _))
482         .Times(Exactly(1))
__anon0d857a951202(const std::vector<uint8_t> &scheduleResult, std::shared_ptr<CredentialInfoInterface> &info) 483         .WillOnce([](const std::vector<uint8_t> &scheduleResult, std::shared_ptr<CredentialInfoInterface> &info) {
484             EXPECT_EQ(scheduleResult, testScheduleResult);
485             return true;
486         });
487     std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
488     ASSERT_NE(contextCallback, nullptr);
489     EXPECT_CALL(*contextCallback, OnResult(_, _))
490         .Times(Exactly(1))
__anon0d857a951302(int32_t resultCode, const Attributes &finalResult) 491         .WillOnce([](int32_t resultCode, const Attributes &finalResult) {
492             EXPECT_EQ(resultCode, ResultCode::SUCCESS);
493         });
494 
495     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
496         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
497     ASSERT_NE(nodeCallback, nullptr);
498     std::shared_ptr<Attributes> result = Common::MakeShared<Attributes>();
499     ASSERT_NE(result, nullptr);
500     bool ret1 = result->SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, testScheduleResult);
501     ASSERT_EQ(ret1, true);
502 
503     bool ret2 = result->SetUint8ArrayValue(Attributes::ATTR_RESULT, testScheduleResult);
504     ASSERT_EQ(ret2, true);
505     nodeCallback->OnScheduleStoped(ResultCode::SUCCESS, result);
506 }
507 
508 HWTEST_F(DeleteContextTest, DeleteContextTest_OnScheduleStoped_006, TestSize.Level0)
509 {
510     static const uint64_t testContestId = 2;
511     static const std::vector<uint8_t> testScheduleResult = {3, 4, 5, 6};
512 
513     std::shared_ptr<MockDeletion> mockDeletion = Common::MakeShared<MockDeletion>();
514     ASSERT_NE(mockDeletion, nullptr);
515     EXPECT_CALL(*mockDeletion, Update(_, _))
516         .Times(Exactly(1))
__anon0d857a951402(const std::vector<uint8_t> &scheduleResult, std::shared_ptr<CredentialInfoInterface> &info) 517         .WillOnce([](const std::vector<uint8_t> &scheduleResult, std::shared_ptr<CredentialInfoInterface> &info) {
518             EXPECT_EQ(scheduleResult, testScheduleResult);
519             return true;
520         });
521     std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
522     ASSERT_NE(contextCallback, nullptr);
523     EXPECT_CALL(*contextCallback, OnResult(_, _)).Times(1);
524 
525     std::shared_ptr<ScheduleNodeCallback> nodeCallback =
526         Common::MakeShared<DeleteContext>(testContestId, mockDeletion, contextCallback);
527     ASSERT_NE(nodeCallback, nullptr);
528     std::shared_ptr<Attributes> result = Common::MakeShared<Attributes>();
529     ASSERT_NE(result, nullptr);
530     bool ret1 = result->SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, testScheduleResult);
531     ASSERT_EQ(ret1, true);
532 
533     bool ret2 = result->SetUint8ArrayValue(Attributes::ATTR_RESULT, testScheduleResult);
534     ASSERT_EQ(ret2, true);
535     nodeCallback->OnScheduleStoped(ResultCode::SUCCESS, result);
536 }
537 } // namespace UserAuth
538 } // namespace UserIam
539 } // namespace OHOS
540