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 "osal_time.h"
22 #include "light_if.h"
23 #include "light_type.h"
24 #include "v1_0/ilight_interface.h"
25
26 using namespace testing::ext;
27 using namespace OHOS::HDI::Light::V1_0;
28
29 namespace {
30 constexpr int32_t MAX_VALUE = 255;
31 constexpr int32_t MIN_VALUE = 0;
32 constexpr uint32_t SLEEP_TIME = 3;
33 const struct LightInterface *g_lightPerformanceDev = nullptr;
34 }
35
36 class HdfLightPerformanceTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp();
41 void TearDown();
42 };
43
SetUpTestCase()44 void HdfLightPerformanceTest::SetUpTestCase()
45 {
46 g_lightPerformanceDev = NewLightInterfaceInstance();
47 if (g_lightPerformanceDev == nullptr) {
48 printf("test lightHdi get Module insttace failed\n\r");
49 }
50 }
51
TearDownTestCase()52 void HdfLightPerformanceTest::TearDownTestCase()
53 {
54 if (g_lightPerformanceDev != nullptr) {
55 FreeLightInterfaceInstance();
56 g_lightPerformanceDev = nullptr;
57 }
58 }
59
SetUp()60 void HdfLightPerformanceTest::SetUp()
61 {
62 }
63
TearDown()64 void HdfLightPerformanceTest::TearDown()
65 {
66 }
67
InitConfig(LightEffect & effect)68 static void InitConfig(LightEffect &effect)
69 {
70 effect.lightColor.colorValue.rgbColor.r = MIN_VALUE;
71 effect.lightColor.colorValue.rgbColor.g = MIN_VALUE;
72 effect.lightColor.colorValue.rgbColor.b = MIN_VALUE;
73 effect.flashEffect.flashMode = LIGHT_FLASH_NONE;
74 }
75
76 /**
77 * @tc.name: TurnOnLightRed001
78 * @tc.desc: Turn on the light always on red.
79 * @tc.type: FUNC
80 * @tc.require: #I9EKU9
81 */
82 HWTEST_F(HdfLightPerformanceTest, TurnOnLightRed_001, TestSize.Level1)
83 {
84 ASSERT_NE(nullptr, g_lightPerformanceDev);
85
86 LightEffect effect;
87 InitConfig(effect);
88 effect.lightColor.colorValue.rgbColor.r = MAX_VALUE;
89
90 int32_t ret = g_lightPerformanceDev->TurnOnLight(LIGHT_ID_BATTERY, &effect);
91 EXPECT_EQ(HDF_SUCCESS, ret);
92
93 OsalSleep(SLEEP_TIME);
94
95 ret = g_lightPerformanceDev->TurnOffLight(LIGHT_ID_BATTERY);
96 EXPECT_EQ(HDF_SUCCESS, ret);
97 }
98
99 /**
100 * @tc.name: Interface_coverage
101 * @tc.desc: Turn on the light always on red.
102 * @tc.type: FUNC
103 * @tc.require: #I9EKU9
104 */
105 HWTEST_F(HdfLightPerformanceTest, Interface_coverage, TestSize.Level1)
106 {
107 ASSERT_NE(nullptr, g_lightPerformanceDev);
108 int32_t ret = FreeLightInterfaceInstance();
109 EXPECT_EQ(ret, HDF_SUCCESS);
110 }