1 /*
2 * Copyright (c) 2022-2023 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 "gtest/gtest.h"
17
18 #include "iam_logger.h"
19 #include "iam_ptr.h"
20
21 #include "sensor_illumination_manager.h"
22 #include "service_ex_manager.h"
23
24 #define LOG_LABEL UserIam::Common::LABEL_FINGERPRINT_AUTH_SA
25
26 using namespace testing;
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace UserIam {
30 namespace FingerprintAuth {
31 constexpr uint32_t WHITE = 0xFFFFFFFF;
32 class FingerprintAuthSensorIllumination : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp();
37 void TearDown();
38 };
39
SetUpTestCase()40 void FingerprintAuthSensorIllumination::SetUpTestCase()
41 {
42 }
43
TearDownTestCase()44 void FingerprintAuthSensorIllumination::TearDownTestCase()
45 {
46 }
47
SetUp()48 void FingerprintAuthSensorIllumination::SetUp()
49 {
50 }
51
TearDown()52 void FingerprintAuthSensorIllumination::TearDown()
53 {
54 }
55
56 HWTEST_F(FingerprintAuthSensorIllumination, FingerprintAuthSensorIllumination_001, TestSize.Level0)
57 {
58 auto acquireRet = ServiceExManager::GetInstance().Acquire();
59 EXPECT_TRUE(acquireRet == UserAuth::SUCCESS);
60
61 auto task = ServiceExManager::GetInstance().GetSensorIlluminationTask();
62 EXPECT_TRUE(task != nullptr);
63
__anon8e5bdfb40102() 64 task->RegisterDestructCallback([]() {
65 IAM_LOGI("task destruct");
66 ServiceExManager::GetInstance().Release();
67 });
68
69 IAM_LOGI("Begin EnableSensorIllumination");
70 task->EnableSensorIllumination(500, 500, 200, WHITE);
71 IAM_LOGI("End EnableSensorIllumination");
72
73 IAM_LOGI("Begin TurnOnSensorIllumination 1");
74 task->TurnOnSensorIllumination();
75 IAM_LOGI("End TurnOnSensorIllumination 1");
76 IAM_LOGI("Begin TurnOffSensorIllumination 1");
77 task->TurnOffSensorIllumination();
78 IAM_LOGI("End TurnOffSensorIllumination 1");
79
80 IAM_LOGI("Begin TurnOnSensorIllumination 2");
81 task->TurnOnSensorIllumination();
82 IAM_LOGI("End TurnOnSensorIllumination 2");
83 IAM_LOGI("Begin TurnOffSensorIllumination 2");
84 task->TurnOffSensorIllumination();
85 IAM_LOGI("End TurnOffSensorIllumination 2");
86
87 IAM_LOGI("Begin DisableSensorIllumination");
88 task->DisableSensorIllumination();
89 IAM_LOGI("End DisableSensorIllumination");
90 task = nullptr;
91 }
92
93 HWTEST_F(FingerprintAuthSensorIllumination, FingerprintAuthSensorIllumination_002, TestSize.Level0)
94 {
95 SaCommand enableCommand = {
96 .id = SaCommandId::ENABLE_SENSOR_ILLUMINATION,
97 .param = { .enableSensorIllumination = { 500, 500, 200, 0, WHITE } }
98 };
99 SaCommand disableCommand = { SaCommandId::DISABLE_SENSOR_ILLUMINATION };
100 SaCommand turnOnCommand = { SaCommandId::TURN_ON_SENSOR_ILLUMINATION };
101 SaCommand turnOffCommand = { SaCommandId::TURN_OFF_SENSOR_ILLUMINATION };
102
103 auto manager = SensorIlluminationManager::GetInstance();
104 EXPECT_TRUE(manager != nullptr);
105 auto executor = Common::MakeShared<FingerprintAuthExecutorHdi>(nullptr);
106 EXPECT_TRUE(executor != nullptr);
107
108 IAM_LOGI("Begin EnableSensorIllumination");
109 manager->ProcessSaCommand(executor, enableCommand);
110 IAM_LOGI("End EnableSensorIllumination");
111
112 IAM_LOGI("Begin TurnOnSensorIllumination 1");
113 manager->ProcessSaCommand(executor, turnOnCommand);
114 IAM_LOGI("End TurnOnSensorIllumination 1");
115 IAM_LOGI("Begin TurnOffSensorIllumination 1");
116 manager->ProcessSaCommand(executor, turnOffCommand);
117 IAM_LOGI("End TurnOffSensorIllumination 1");
118
119 IAM_LOGI("Begin TurnOnSensorIllumination 2");
120 manager->ProcessSaCommand(executor, turnOnCommand);
121 IAM_LOGI("End TurnOnSensorIllumination 2");
122 IAM_LOGI("Begin TurnOffSensorIllumination 2");
123 manager->ProcessSaCommand(executor, turnOffCommand);
124 IAM_LOGI("End TurnOffSensorIllumination 2");
125
126 IAM_LOGI("Begin DisableSensorIllumination");
127 manager->ProcessSaCommand(executor, disableCommand);
128 IAM_LOGI("End DisableSensorIllumination");
129 }
130 } // namespace FingerprintAuth
131 } // namespace UserIam
132 } // namespace OHOS
133