1 /*
2  * Copyright (c) 2024 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 <cmath>
17 #include <cstdio>
18 #include <gtest/gtest.h>
19 #include <securec.h>
20 #include "hdf_base.h"
21 #include "hdf_log.h"
22 #include "osal_time.h"
23 #include "v1_0/ilight_interface.h"
24 #include "light_type.h"
25 
26 #define HDF_LOG_TAG "hdi_unittest_light"
27 #define TEST_FUNC_IN HDF_LOGI("%{public}s in", testing::UnitTest::GetInstance()->current_test_info()->name())
28 
29 using namespace OHOS::HDI::Light::V1_0;
30 using namespace testing::ext;
31 
32 namespace {
33     constexpr uint32_t g_sleepTime = 3;
34     constexpr int32_t ON_TIME = 500;
35     constexpr int32_t OFF_TIME = 100;
36     std::vector<HdfLightInfo> g_info;
37     sptr<ILightInterface> g_lightInterface = nullptr;
38 }
39 
40 class HdiUnitTestLight : public testing::Test {
41 public:
42     static void SetUpTestSuite();
43     static void TearDownTestSuite();
44     void SetUp();
45     void TearDown();
46 };
47 
SetUpTestSuite()48 void HdiUnitTestLight::SetUpTestSuite()
49 {
50     g_lightInterface = ILightInterface::Get();
51 }
52 
TearDownTestSuite()53 void HdiUnitTestLight::TearDownTestSuite()
54 {
55 }
56 
SetUp()57 void HdiUnitTestLight::SetUp()
58 {
59 }
60 
TearDown()61 void HdiUnitTestLight::TearDown()
62 {
63 }
64 
IsSupportedLightId(int32_t lightId)65 static int32_t IsSupportedLightId(int32_t lightId)
66 {
67     TEST_FUNC_IN;
68     EXPECT_GT(g_info.size(), 0);
69 
70     bool result = std::any_of(g_info.begin(), g_info.end(),
71         [lightId](const HdfLightInfo &info) {return info.lightId == lightId;});
72     if (result) {
73         return HDF_SUCCESS;
74     }
75 
76     return HDF_ERR_NOT_SUPPORT;
77 }
78 
LightTest(int32_t lightId, int32_t lightFlashMode, HdfLightEffect &effect)79 static void LightTest(int32_t lightId, int32_t lightFlashMode, HdfLightEffect &effect)
80 {
81     TEST_FUNC_IN;
82     if (lightFlashMode != HDF_LIGHT_FLASH_NONE) {
83         effect.flashEffect.onTime = ON_TIME;
84         effect.flashEffect.offTime = OFF_TIME;
85     }
86     effect.flashEffect.flashMode = lightFlashMode;
87 
88     int32_t ans = IsSupportedLightId(lightId);
89     int32_t ret = g_lightInterface->TurnOnLight(lightId, effect);
90     EXPECT_EQ(ans, ret);
91 
92     OsalSleep(g_sleepTime);
93 
94     ret = g_lightInterface->TurnOffLight(lightId);
95     EXPECT_EQ(ans, ret);
96 }
97 
98 /**
99   * @tc.name: CheckLightInstanceIsEmpty
100   * @tc.desc: Create a light instance. The instance is not empty.
101   * @tc.type: FUNC
102   * @tc.require: #IAU5KS
103   */
HWTEST_F(HdiUnitTestLight, CheckLightInstanceIsEmpty001, TestSize.Level1)104 HWTEST_F(HdiUnitTestLight, CheckLightInstanceIsEmpty001, TestSize.Level1)
105 {
106     TEST_FUNC_IN;
107     ASSERT_NE(nullptr, g_lightInterface);
108 }
109 
110 /**
111   * @tc.name: GetLightInfo001
112   * @tc.desc: Get light info.
113   * @tc.type: FUNC
114   * @tc.require: #IAU5KS
115   */
HWTEST_F(HdiUnitTestLight, GetLightInfo001, TestSize.Level1)116 HWTEST_F(HdiUnitTestLight, GetLightInfo001, TestSize.Level1)
117 {
118     TEST_FUNC_IN;
119     ASSERT_NE(nullptr, g_lightInterface);
120 
121     int32_t ret = g_lightInterface->GetLightInfo(g_info);
122     EXPECT_EQ(HDF_SUCCESS, ret);
123     EXPECT_GT(g_info.size(), 0);
124 
125     printf("get light list num[%zu]\n\r", g_info.size());
126     for (auto iter : g_info) {
127         printf("lightId[%d], name[%s], number[%d], type[%d]\n\r", iter.lightId, iter.lightName.c_str(),
128             iter.lightNumber, iter.lightType);
129     }
130 }
131 
132 /**
133   * @tc.name: TurnOnLightBatteryAlwaysOnRed001
134   * @tc.desc: The power indicator is steady red.
135   * @tc.type: FUNC
136   * @tc.require: #IAU5KS
137   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnRed001, TestSize.Level1)138 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnRed001, TestSize.Level1)
139 {
140     TEST_FUNC_IN;
141     ASSERT_NE(nullptr, g_lightInterface);
142 
143     HdfLightEffect effect = {
144         .lightColor.colorValue.rgbColor.r = 255,
145         .lightColor.colorValue.rgbColor.g = 0,
146         .lightColor.colorValue.rgbColor.b = 0,
147     };
148 
149     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_NONE, effect);
150 }
151 
152 /**
153   * @tc.name: TurnOnLightBatteryAlwaysOnGreen001
154   * @tc.desc: The power indicator is steady green.
155   * @tc.type: FUNC
156   * @tc.require: #IAU5KS
157   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnGreen001, TestSize.Level1)158 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnGreen001, TestSize.Level1)
159 {
160     TEST_FUNC_IN;
161     ASSERT_NE(nullptr, g_lightInterface);
162 
163     HdfLightEffect effect = {
164         .lightColor.colorValue.rgbColor.r = 0,
165         .lightColor.colorValue.rgbColor.g = 255,
166         .lightColor.colorValue.rgbColor.b = 0,
167     };
168 
169     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_NONE, effect);
170 }
171 
172 /**
173   * @tc.name: TurnOnLightBatteryAlwaysOnBlue001
174   * @tc.desc: The power indicator is steady blue.
175   * @tc.type: FUNC
176   * @tc.require: #IAU5KS
177   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnBlue001, TestSize.Level1)178 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnBlue001, TestSize.Level1)
179 {
180     TEST_FUNC_IN;
181     ASSERT_NE(nullptr, g_lightInterface);
182 
183     HdfLightEffect effect = {
184         .lightColor.colorValue.rgbColor.r = 0,
185         .lightColor.colorValue.rgbColor.g = 0,
186         .lightColor.colorValue.rgbColor.b = 255,
187     };
188 
189     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_NONE, effect);
190 }
191 
192 /**
193   * @tc.name: TurnOnLightBatteryAlwaysOnWhite001
194   * @tc.desc: The power indicator is steady white.
195   * @tc.type: FUNC
196   * @tc.require: #IAU5KS
197   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnWhite001, TestSize.Level1)198 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryAlwaysOnWhite001, TestSize.Level1)
199 {
200     TEST_FUNC_IN;
201     ASSERT_NE(nullptr, g_lightInterface);
202 
203     HdfLightEffect effect = {
204         .lightColor.colorValue.rgbColor.r = 255,
205         .lightColor.colorValue.rgbColor.g = 255,
206         .lightColor.colorValue.rgbColor.b = 255,
207     };
208 
209     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_NONE, effect);
210 }
211 
212 /**
213   * @tc.name: TurnOnLightBatteryBlinkRed001
214   * @tc.desc: The power indicator is blinking red.
215   * @tc.type: FUNC
216   * @tc.require: #IAU5KS
217   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkRed001, TestSize.Level1)218 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkRed001, TestSize.Level1)
219 {
220     TEST_FUNC_IN;
221     ASSERT_NE(nullptr, g_lightInterface);
222 
223     HdfLightEffect effect = {
224         .lightColor.colorValue.rgbColor.r = 255,
225         .lightColor.colorValue.rgbColor.g = 0,
226         .lightColor.colorValue.rgbColor.b = 0,
227     };
228 
229     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_BLINK, effect);
230 }
231 
232 /**
233   * @tc.name: TurnOnLightBatteryBlinkGreen001
234   * @tc.desc: The power indicator is blinking green.
235   * @tc.type: FUNC
236   * @tc.require: #IAU5KS
237   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkGreen001, TestSize.Level1)238 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkGreen001, TestSize.Level1)
239 {
240     TEST_FUNC_IN;
241     ASSERT_NE(nullptr, g_lightInterface);
242 
243     HdfLightEffect effect = {
244         .lightColor.colorValue.rgbColor.r = 0,
245         .lightColor.colorValue.rgbColor.g = 255,
246         .lightColor.colorValue.rgbColor.b = 0,
247     };
248 
249     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_BLINK, effect);
250 }
251 
252 /**
253   * @tc.name: TurnOnLightBatteryBlinkBlue001
254   * @tc.desc: The power indicator is blinking blue.
255   * @tc.type: FUNC
256   * @tc.require: #IAU5KS
257   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkBlue001, TestSize.Level1)258 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkBlue001, TestSize.Level1)
259 {
260     HDF_LOGI("%{public}s in", testing::UnitTest::GetInstance()->current_test_info()->name());
261     ASSERT_NE(nullptr, g_lightInterface);
262 
263     HdfLightEffect effect = {
264         .lightColor.colorValue.rgbColor.r = 0,
265         .lightColor.colorValue.rgbColor.g = 0,
266         .lightColor.colorValue.rgbColor.b = 255,
267     };
268 
269     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_BLINK, effect);
270 }
271 
272 /**
273   * @tc.name: TurnOnLightBatteryBlinkWhite001
274   * @tc.desc: The power indicator is blinking white.
275   * @tc.type: FUNC
276   * @tc.require: #IAU5KS
277   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkWhite001, TestSize.Level1)278 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryBlinkWhite001, TestSize.Level1)
279 {
280     TEST_FUNC_IN;
281     ASSERT_NE(nullptr, g_lightInterface);
282 
283     HdfLightEffect effect = {
284         .lightColor.colorValue.rgbColor.r = 255,
285         .lightColor.colorValue.rgbColor.g = 255,
286         .lightColor.colorValue.rgbColor.b = 255,
287     };
288 
289     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_BLINK, effect);
290 }
291 
292 /**
293   * @tc.name: TurnOnLightBatteryGradientRed001
294   * @tc.desc: The power indicator red light gradients.
295   * @tc.type: FUNC
296   * @tc.require: #IAU5KS
297   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientRed001, TestSize.Level1)298 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientRed001, TestSize.Level1)
299 {
300     TEST_FUNC_IN;
301     ASSERT_NE(nullptr, g_lightInterface);
302 
303     HdfLightEffect effect = {
304         .lightColor.colorValue.rgbColor.r = 255,
305         .lightColor.colorValue.rgbColor.g = 0,
306         .lightColor.colorValue.rgbColor.b = 0,
307     };
308 
309     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_GRADIENT, effect);
310 }
311 
312 /**
313   * @tc.name: TurnOnLightBatteryGradientGreen001
314   * @tc.desc: The power indicator green light gradients.
315   * @tc.type: FUNC
316   * @tc.require: #IAU5KS
317   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientGreen001, TestSize.Level1)318 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientGreen001, TestSize.Level1)
319 {
320     TEST_FUNC_IN;
321     ASSERT_NE(nullptr, g_lightInterface);
322 
323     HdfLightEffect effect = {
324         .lightColor.colorValue.rgbColor.r = 0,
325         .lightColor.colorValue.rgbColor.g = 255,
326         .lightColor.colorValue.rgbColor.b = 0,
327     };
328 
329     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_GRADIENT, effect);
330 }
331 
332 /**
333   * @tc.name: TurnOnLightBatteryGradientBlue001
334   * @tc.desc: The power indicator blue light gradients.
335   * @tc.type: FUNC
336   * @tc.require: #IAU5KS
337   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientBlue001, TestSize.Level1)338 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientBlue001, TestSize.Level1)
339 {
340     TEST_FUNC_IN;
341     ASSERT_NE(nullptr, g_lightInterface);
342 
343     HdfLightEffect effect = {
344         .lightColor.colorValue.rgbColor.r = 0,
345         .lightColor.colorValue.rgbColor.g = 0,
346         .lightColor.colorValue.rgbColor.b = 255,
347     };
348 
349     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_GRADIENT, effect);
350 }
351 
352 /**
353   * @tc.name: TurnOnLightBatteryGradientWhite001
354   * @tc.desc: The power indicator white light gradients.
355   * @tc.type: FUNC
356   * @tc.require: #IAU5KS
357   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientWhite001, TestSize.Level1)358 HWTEST_F(HdiUnitTestLight, TurnOnLightBatteryGradientWhite001, TestSize.Level1)
359 {
360     TEST_FUNC_IN;
361     ASSERT_NE(nullptr, g_lightInterface);
362 
363     HdfLightEffect effect = {
364         .lightColor.colorValue.rgbColor.r = 255,
365         .lightColor.colorValue.rgbColor.g = 255,
366         .lightColor.colorValue.rgbColor.b = 255,
367     };
368 
369     LightTest(HDF_LIGHT_ID_BATTERY, HDF_LIGHT_FLASH_GRADIENT, effect);
370 }
371 
372 /**
373   * @tc.name: TurnOnLightNotificationsAlwaysOnRed001
374   * @tc.desc: The notification light is steady red.
375   * @tc.type: FUNC
376   * @tc.require: #IAU5KS
377   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnRed001, TestSize.Level1)378 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnRed001, TestSize.Level1)
379 {
380     TEST_FUNC_IN;
381     ASSERT_NE(nullptr, g_lightInterface);
382 
383     HdfLightEffect effect = {
384         .lightColor.colorValue.rgbColor.r = 255,
385         .lightColor.colorValue.rgbColor.g = 0,
386         .lightColor.colorValue.rgbColor.b = 0,
387     };
388 
389     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_NONE, effect);
390 }
391 
392 /**
393   * @tc.name: TurnOnLightNotificationsAlwaysOnGreen001
394   * @tc.desc: The notification light is steady green.
395   * @tc.type: FUNC
396   * @tc.require: #IAU5KS
397   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnGreen001, TestSize.Level1)398 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnGreen001, TestSize.Level1)
399 {
400     TEST_FUNC_IN;
401     ASSERT_NE(nullptr, g_lightInterface);
402 
403     HdfLightEffect effect = {
404         .lightColor.colorValue.rgbColor.r = 0,
405         .lightColor.colorValue.rgbColor.g = 255,
406         .lightColor.colorValue.rgbColor.b = 0,
407     };
408 
409     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_NONE, effect);
410 }
411 
412 /**
413   * @tc.name: TurnOnLightNotificationsAlwaysOnBlue001
414   * @tc.desc: The notification light is steady blue.
415   * @tc.type: FUNC
416   * @tc.require: #IAU5KS
417   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnBlue001, TestSize.Level1)418 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnBlue001, TestSize.Level1)
419 {
420     TEST_FUNC_IN;
421     ASSERT_NE(nullptr, g_lightInterface);
422 
423     HdfLightEffect effect = {
424         .lightColor.colorValue.rgbColor.r = 0,
425         .lightColor.colorValue.rgbColor.g = 0,
426         .lightColor.colorValue.rgbColor.b = 255,
427     };
428 
429     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_NONE, effect);
430 }
431 
432 /**
433   * @tc.name: TurnOnLightNotificationsAlwaysOnWhite001
434   * @tc.desc: The notification light is steady white.
435   * @tc.type: FUNC
436   * @tc.require: #IAU5KS
437   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnWhite001, TestSize.Level1)438 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsAlwaysOnWhite001, TestSize.Level1)
439 {
440     TEST_FUNC_IN;
441     ASSERT_NE(nullptr, g_lightInterface);
442 
443     HdfLightEffect effect = {
444         .lightColor.colorValue.rgbColor.r = 255,
445         .lightColor.colorValue.rgbColor.g = 255,
446         .lightColor.colorValue.rgbColor.b = 255,
447     };
448 
449     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_NONE, effect);
450 }
451 
452 /**
453   * @tc.name: TurnOnLightNotificationsBlinkRed001
454   * @tc.desc: Notification light blinking red.
455   * @tc.type: FUNC
456   * @tc.require: #IAU5KS
457   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkRed001, TestSize.Level1)458 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkRed001, TestSize.Level1)
459 {
460     TEST_FUNC_IN;
461     ASSERT_NE(nullptr, g_lightInterface);
462 
463     HdfLightEffect effect = {
464         .lightColor.colorValue.rgbColor.r = 255,
465         .lightColor.colorValue.rgbColor.g = 0,
466         .lightColor.colorValue.rgbColor.b = 0,
467     };
468 
469     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_BLINK, effect);
470 }
471 
472 /**
473   * @tc.name: TurnOnLightNotificationsBlinkGreen001
474   * @tc.desc: Notification light blinking green.
475   * @tc.type: FUNC
476   * @tc.require: #IAU5KS
477   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkGreen001, TestSize.Level1)478 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkGreen001, TestSize.Level1)
479 {
480     TEST_FUNC_IN;
481     ASSERT_NE(nullptr, g_lightInterface);
482 
483     HdfLightEffect effect = {
484         .lightColor.colorValue.rgbColor.r = 0,
485         .lightColor.colorValue.rgbColor.g = 255,
486         .lightColor.colorValue.rgbColor.b = 0,
487     };
488 
489     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_BLINK, effect);
490 }
491 
492 /**
493   * @tc.name: TurnOnLightNotificationsBlinkBlue001
494   * @tc.desc: Notification light blinking blue.
495   * @tc.type: FUNC
496   * @tc.require: #IAU5KS
497   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkBlue001, TestSize.Level1)498 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkBlue001, TestSize.Level1)
499 {
500     TEST_FUNC_IN;
501     ASSERT_NE(nullptr, g_lightInterface);
502 
503     HdfLightEffect effect = {
504         .lightColor.colorValue.rgbColor.r = 0,
505         .lightColor.colorValue.rgbColor.g = 0,
506         .lightColor.colorValue.rgbColor.b = 255,
507     };
508 
509     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_BLINK, effect);
510 }
511 
512 /**
513   * @tc.name: TurnOnLightNotificationsBlinkWhite001
514   * @tc.desc: Notification light blinking white.
515   * @tc.type: FUNC
516   * @tc.require: #IAU5KS
517   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkWhite001, TestSize.Level1)518 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsBlinkWhite001, TestSize.Level1)
519 {
520     TEST_FUNC_IN;
521     ASSERT_NE(nullptr, g_lightInterface);
522 
523     HdfLightEffect effect = {
524         .lightColor.colorValue.rgbColor.r = 255,
525         .lightColor.colorValue.rgbColor.g = 255,
526         .lightColor.colorValue.rgbColor.b = 255,
527     };
528 
529     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_BLINK, effect);
530 }
531 
532 /**
533   * @tc.name: TurnOnLightNotificationsGradientRed001
534   * @tc.desc: Notification light gradient red.
535   * @tc.type: FUNC
536   * @tc.require: #IAU5KS
537   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientRed001, TestSize.Level1)538 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientRed001, TestSize.Level1)
539 {
540     TEST_FUNC_IN;
541     ASSERT_NE(nullptr, g_lightInterface);
542 
543     HdfLightEffect effect = {
544         .lightColor.colorValue.rgbColor.r = 255,
545         .lightColor.colorValue.rgbColor.g = 0,
546         .lightColor.colorValue.rgbColor.b = 0,
547     };
548 
549     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_GRADIENT, effect);
550 }
551 
552 /**
553   * @tc.name: TurnOnLightNotificationsGradientGreen001
554   * @tc.desc: Notification light gradient green.
555   * @tc.type: FUNC
556   * @tc.require: #IAU5KS
557   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientGreen001, TestSize.Level1)558 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientGreen001, TestSize.Level1)
559 {
560     TEST_FUNC_IN;
561     ASSERT_NE(nullptr, g_lightInterface);
562 
563     HdfLightEffect effect = {
564         .lightColor.colorValue.rgbColor.r = 0,
565         .lightColor.colorValue.rgbColor.g = 255,
566         .lightColor.colorValue.rgbColor.b = 0,
567     };
568 
569     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_GRADIENT, effect);
570 }
571 
572 /**
573   * @tc.name: TurnOnLightNotificationsGradientBlue001
574   * @tc.desc: Notification light gradient blue.
575   * @tc.type: FUNC
576   * @tc.require: #IAU5KS
577   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientBlue001, TestSize.Level1)578 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientBlue001, TestSize.Level1)
579 {
580     TEST_FUNC_IN;
581     ASSERT_NE(nullptr, g_lightInterface);
582 
583     HdfLightEffect effect = {
584         .lightColor.colorValue.rgbColor.r = 0,
585         .lightColor.colorValue.rgbColor.g = 0,
586         .lightColor.colorValue.rgbColor.b = 255,
587     };
588 
589     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_GRADIENT, effect);
590 }
591 
592 /**
593   * @tc.name: TurnOnLightNotificationsGradientWhite001
594   * @tc.desc: Notification light gradient white.
595   * @tc.type: FUNC
596   * @tc.require: #IAU5KS
597   */
HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientWhite001, TestSize.Level1)598 HWTEST_F(HdiUnitTestLight, TurnOnLightNotificationsGradientWhite001, TestSize.Level1)
599 {
600     TEST_FUNC_IN;
601     ASSERT_NE(nullptr, g_lightInterface);
602 
603     HdfLightEffect effect = {
604         .lightColor.colorValue.rgbColor.r = 255,
605         .lightColor.colorValue.rgbColor.g = 255,
606         .lightColor.colorValue.rgbColor.b = 255,
607     };
608 
609     LightTest(HDF_LIGHT_ID_NOTIFICATIONS, HDF_LIGHT_FLASH_GRADIENT, effect);
610 }
611 
612 /**
613   * @tc.name: TurnOnLightAttention001
614   * @tc.desc: The reserved indicator is not supported currently.
615   * @tc.type: FUNC
616   * @tc.require: #IAU5KS
617   */
HWTEST_F(HdiUnitTestLight, TurnOnLightAttention001, TestSize.Level1)618 HWTEST_F(HdiUnitTestLight, TurnOnLightAttention001, TestSize.Level1)
619 {
620     TEST_FUNC_IN;
621     ASSERT_NE(nullptr, g_lightInterface);
622 
623     HdfLightEffect effect = {
624         .lightColor.colorValue.rgbColor.r = 255,
625         .lightColor.colorValue.rgbColor.g = 0,
626         .lightColor.colorValue.rgbColor.b = 0,
627     };
628 
629     LightTest(HDF_LIGHT_ID_ATTENTION, HDF_LIGHT_FLASH_NONE, effect);
630 }
631 
632 /**
633   * @tc.name: TurnOnMultiLights001
634   * @tc.desc: Turn on multiple lights.
635   * @tc.type: FUNC
636   * @tc.require: #IAU5KS
637   */
HWTEST_F(HdiUnitTestLight, TurnOnMultiLights001, TestSize.Level1)638 HWTEST_F(HdiUnitTestLight, TurnOnMultiLights001, TestSize.Level1)
639 {
640     TEST_FUNC_IN;
641     ASSERT_NE(nullptr, g_lightInterface);
642 
643     int32_t lightId = HDF_LIGHT_ID_NOTIFICATIONS;
644     struct HdfLightColor color = {
645         .colorValue.rgbColor.r = 255,
646         .colorValue.rgbColor.g = 255,
647         .colorValue.rgbColor.b = 255,
648     };
649     std::vector<HdfLightColor> lightColor;
650     lightColor.push_back(color);
651 
652     int32_t ret = IsSupportedLightId(lightId);
653     EXPECT_EQ(HDF_SUCCESS, ret);
654 
655     ret = g_lightInterface->TurnOnMultiLights(lightId, lightColor);
656     EXPECT_EQ(HDF_SUCCESS, ret);
657 
658     OsalSleep(g_sleepTime);
659 
660     ret = g_lightInterface->TurnOffLight(lightId);
661     EXPECT_EQ(HDF_SUCCESS, ret);
662 }
663 
664 /**
665   * @tc.name: TurnOnMultiLights002
666   * @tc.desc: Turn on multiple lights.
667   * @tc.type: FUNC
668   * @tc.require: #IAU5KS
669   */
HWTEST_F(HdiUnitTestLight, TurnOnMultiLights002, TestSize.Level1)670 HWTEST_F(HdiUnitTestLight, TurnOnMultiLights002, TestSize.Level1)
671 {
672     TEST_FUNC_IN;
673     ASSERT_NE(nullptr, g_lightInterface);
674 
675     int32_t lightId = HDF_LIGHT_ID_BATTERY;
676     struct HdfLightColor color1 = {
677         .colorValue.rgbColor.r = 255,
678         .colorValue.rgbColor.g = 255,
679         .colorValue.rgbColor.b = 255,
680     };
681     struct HdfLightColor color2 = {
682         .colorValue.rgbColor.r = 255,
683         .colorValue.rgbColor.g = 255,
684         .colorValue.rgbColor.b = 0,
685     };
686     std::vector<HdfLightColor> lightColor;
687     lightColor.push_back(color1);
688     lightColor.push_back(color2);
689 
690     int32_t ret = IsSupportedLightId(lightId);
691     EXPECT_EQ(HDF_SUCCESS, ret);
692 
693     ret = g_lightInterface->TurnOnMultiLights(lightId, lightColor);
694     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
695 
696     OsalSleep(g_sleepTime);
697 
698     ret = g_lightInterface->TurnOffLight(lightId);
699     EXPECT_EQ(HDF_SUCCESS, ret);
700 }
701 
702 /**
703   * @tc.name: TurnOnLightBlinkException001
704   * @tc.desc: The ontime setting is abnormal in blinking mode.
705   * @tc.type: FUNC
706   * @tc.require: #IAU5KS
707   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBlinkException001, TestSize.Level1)708 HWTEST_F(HdiUnitTestLight, TurnOnLightBlinkException001, TestSize.Level1)
709 {
710     TEST_FUNC_IN;
711     ASSERT_NE(nullptr, g_lightInterface);
712 
713     int32_t lightId = HDF_LIGHT_ID_NOTIFICATIONS;
714     HdfLightEffect effect = {
715         .lightColor.colorValue.rgbColor.r = 255,
716         .lightColor.colorValue.rgbColor.g = 255,
717         .lightColor.colorValue.rgbColor.b = 255,
718         .flashEffect.onTime = -1,
719         .flashEffect.offTime = OFF_TIME,
720         .flashEffect.flashMode = HDF_LIGHT_FLASH_BLINK,
721     };
722 
723     int32_t ret = IsSupportedLightId(lightId);
724     EXPECT_EQ(HDF_SUCCESS, ret);
725 
726     ret = g_lightInterface->TurnOnLight(lightId, effect);
727     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
728 
729     OsalSleep(g_sleepTime);
730 
731     ret = g_lightInterface->TurnOffLight(lightId);
732     EXPECT_EQ(HDF_SUCCESS, ret);
733 }
734 
735 /**
736   * @tc.name: TurnOnLightBlinkException002
737   * @tc.desc: The offtime setting is abnormal in blinking mode.
738   * @tc.type: FUNC
739   * @tc.require: #IAU5KS
740   */
HWTEST_F(HdiUnitTestLight, TurnOnLightBlinkException002, TestSize.Level1)741 HWTEST_F(HdiUnitTestLight, TurnOnLightBlinkException002, TestSize.Level1)
742 {
743     TEST_FUNC_IN;
744     ASSERT_NE(nullptr, g_lightInterface);
745 
746     int32_t lightId = HDF_LIGHT_ID_NOTIFICATIONS;
747     HdfLightEffect effect = {
748         .lightColor.colorValue.rgbColor.r = 255,
749         .lightColor.colorValue.rgbColor.g = 255,
750         .lightColor.colorValue.rgbColor.b = 255,
751         .flashEffect.onTime = ON_TIME,
752         .flashEffect.offTime = -1,
753         .flashEffect.flashMode = HDF_LIGHT_FLASH_BLINK,
754     };
755 
756     int32_t ret = IsSupportedLightId(lightId);
757     EXPECT_EQ(HDF_SUCCESS, ret);
758 
759     ret = g_lightInterface->TurnOnLight(lightId, effect);
760     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
761 
762     OsalSleep(g_sleepTime);
763 
764     ret = g_lightInterface->TurnOffLight(lightId);
765     EXPECT_EQ(HDF_SUCCESS, ret);
766 }
767 
768 /**
769   * @tc.name: TurnOnLightGradientException001
770   * @tc.desc: The ontime setting is abnormal in gradient mode.
771   * @tc.type: FUNC
772   * @tc.require: #IAU5KS
773   */
HWTEST_F(HdiUnitTestLight, TurnOnLightGradientException001, TestSize.Level1)774 HWTEST_F(HdiUnitTestLight, TurnOnLightGradientException001, TestSize.Level1)
775 {
776     TEST_FUNC_IN;
777     ASSERT_NE(nullptr, g_lightInterface);
778 
779     int32_t lightId = HDF_LIGHT_ID_NOTIFICATIONS;
780     HdfLightEffect effect = {
781         .lightColor.colorValue.rgbColor.r = 255,
782         .lightColor.colorValue.rgbColor.g = 255,
783         .lightColor.colorValue.rgbColor.b = 255,
784         .flashEffect.onTime = -1,
785         .flashEffect.offTime = OFF_TIME,
786         .flashEffect.flashMode = HDF_LIGHT_FLASH_GRADIENT,
787     };
788 
789     int32_t ret = IsSupportedLightId(lightId);
790     EXPECT_EQ(HDF_SUCCESS, ret);
791 
792     ret = g_lightInterface->TurnOnLight(lightId, effect);
793     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
794 
795     OsalSleep(g_sleepTime);
796 
797     ret = g_lightInterface->TurnOffLight(lightId);
798     EXPECT_EQ(HDF_SUCCESS, ret);
799 }
800 
801 /**
802   * @tc.name: TurnOnLightGradientException002
803   * @tc.desc: The offtime setting is abnormal in gradient mode.
804   * @tc.type: FUNC
805   * @tc.require: #IAU5KS
806   */
HWTEST_F(HdiUnitTestLight, TurnOnLightGradientException002, TestSize.Level1)807 HWTEST_F(HdiUnitTestLight, TurnOnLightGradientException002, TestSize.Level1)
808 {
809     TEST_FUNC_IN;
810     ASSERT_NE(nullptr, g_lightInterface);
811 
812     int32_t lightId = HDF_LIGHT_ID_NOTIFICATIONS;
813     HdfLightEffect effect = {
814         .lightColor.colorValue.rgbColor.r = 255,
815         .lightColor.colorValue.rgbColor.g = 255,
816         .lightColor.colorValue.rgbColor.b = 255,
817         .flashEffect.onTime = ON_TIME,
818         .flashEffect.offTime = -1,
819         .flashEffect.flashMode = HDF_LIGHT_FLASH_GRADIENT,
820     };
821 
822     int32_t ret = IsSupportedLightId(lightId);
823     EXPECT_EQ(HDF_SUCCESS, ret);
824 
825     ret = g_lightInterface->TurnOnLight(lightId, effect);
826     EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
827 
828     OsalSleep(g_sleepTime);
829 
830     ret = g_lightInterface->TurnOffLight(lightId);
831     EXPECT_EQ(HDF_SUCCESS, ret);
832 }
833