1 /*
2  * Copyright (c) 2021-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 #include <cmath>
16 #include <cstdio>
17 #include <gtest/gtest.h>
18 #include <securec.h>
19 #include "hdf_base.h"
20 #include "osal_time.h"
21 #include "v1_2/ivibrator_interface.h"
22 #include "vibrator_type.h"
23 
24 using namespace OHOS::HDI::Vibrator;
25 using namespace OHOS::HDI::Vibrator::V1_2;
26 using namespace testing::ext;
27 
28 namespace {
29     uint32_t g_duration = 1000;
30     uint32_t g_noDuration = 0;
31     uint32_t g_sleepTime1 = 2000;
32     uint32_t g_sleepTime2 = 5000;
33     int32_t g_intensity1 = 30;
34     int32_t g_intensity2 = -30;
35     int32_t g_frequency1 = 200;
36     int32_t g_frequency2 = -200;
37     V1_2::HapticPaket g_pkg = {434, 1, {{V1_2::CONTINUOUS, 0, 149, 100, 50, 0, 4,
38         {{0, 0, 0}, {1, 1, 0}, {32, 1, -39}, {149, 0, -39}}}}};
39     constexpr int32_t MIN_DURATION = 0;
40     constexpr int32_t MAX_DURATION = 3600000;
41     std::vector<std::string> g_effect_list = {"haptic.clock.timer", "haptic.long_press.light", \
42         "haptic.long_press.medium", "haptic.long_press.light", "haptic.fail", "haptic.charging", \
43         "haptic.slide.light", "haptic.threshold"};
44     std::string g_builtIn = "haptic.default.effect";
45     std::string g_effect1 = "haptic.long_press.light";
46     std::string g_arbitraryStr = "arbitraryString";
47     sptr<OHOS::HDI::Vibrator::V1_2::IVibratorInterface> g_vibratorInterface = nullptr;
48 }
49 
50 class HdfVibratorHdiServiceTest : public testing::Test {
51 public:
52     static void SetUpTestCase();
53     static void TearDownTestCase();
54     void SetUp();
55     void TearDown();
56 };
57 
SetUpTestCase()58 void HdfVibratorHdiServiceTest::SetUpTestCase()
59 {
60     g_vibratorInterface = OHOS::HDI::Vibrator::V1_2::IVibratorInterface::Get();
61 }
62 
TearDownTestCase()63 void HdfVibratorHdiServiceTest::TearDownTestCase()
64 {
65 }
66 
SetUp()67 void HdfVibratorHdiServiceTest::SetUp()
68 {
69 }
70 
TearDown()71 void HdfVibratorHdiServiceTest::TearDown()
72 {
73 }
74 
75 /**
76   * @tc.name: CheckVibratorInstanceIsEmpty
77   * @tc.desc: Creat a vibrator instance. The instance is not empty.
78   * @tc.type: FUNC
79   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0100, Function | MediumTest | Level1)80 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0100, Function | MediumTest | Level1)
81 {
82     ASSERT_NE(nullptr, g_vibratorInterface);
83 }
84 
85 /**
86   * @tc.name: PerformOneShotVibratorDuration001
87   * @tc.desc: Controls this vibrator to perform a one-shot vibrator at a given duration.
88   * Controls this vibrator to stop the vibrator
89   * @tc.type: FUNC
90   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0200, Function | MediumTest | Level1)91 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0200, Function | MediumTest | Level1)
92 {
93     ASSERT_NE(nullptr, g_vibratorInterface);
94 
95     int32_t startRet = g_vibratorInterface->StartOnce(g_duration);
96     EXPECT_EQ(startRet, HDF_SUCCESS);
97 
98     OsalMSleep(g_sleepTime1);
99 
100     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
101     EXPECT_EQ(endRet, HDF_SUCCESS);
102 }
103 
104 /**
105   * @tc.name: PerformOneShotVibratorDuration002
106   * @tc.desc: Controls this vibrator to perform a one-shot vibrator at 0 millisecond.
107   * Controls this vibrator to stop the vibrator
108   * @tc.type: FUNC
109   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0300, Function | MediumTest | Level1)110 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0300, Function | MediumTest | Level1)
111 {
112     ASSERT_NE(nullptr, g_vibratorInterface);
113 
114     int32_t startRet = g_vibratorInterface->StartOnce(g_noDuration);
115     EXPECT_EQ(startRet, HDF_SUCCESS);
116 
117     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
118     EXPECT_EQ(endRet, HDF_SUCCESS);
119 }
120 
121 /**
122   * @tc.name: ExecuteVibratorEffect001
123   * @tc.desc: Controls this Performing Time Series Vibrator Effects.
124   * Controls this vibrator to stop the vibrator
125   * @tc.type: FUNC
126   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0400, Function | MediumTest | Level1)127 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0400, Function | MediumTest | Level1)
128 {
129     ASSERT_NE(nullptr, g_vibratorInterface);
130 
131     int32_t ret;
132     for (auto iter : g_effect_list) {
133         printf("VibratorEffect : %s\n", iter.c_str());
134         ret = g_vibratorInterface->Start(iter);
135         EXPECT_EQ(ret, HDF_SUCCESS);
136 
137     OsalMSleep(g_sleepTime2);
138 
139         ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
140         EXPECT_EQ(ret, HDF_SUCCESS);
141     }
142 }
143 
144 /**
145   * @tc.name: ExecuteVibratorEffect002
146   * @tc.desc: Controls this Performing built-in Vibrator Effects.
147   * Controls this vibrator to stop the vibrator.
148   * @tc.type: FUNC
149   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0500, Function | MediumTest | Level1)150 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0500, Function | MediumTest | Level1)
151 {
152     ASSERT_NE(nullptr, g_vibratorInterface);
153 
154     int32_t ret;
155     for (auto iter : g_effect_list) {
156         printf("VibratorEffect : %s\n", iter.c_str());
157         ret = g_vibratorInterface->Start(iter);
158         EXPECT_EQ(ret, HDF_SUCCESS);
159 
160     OsalMSleep(g_sleepTime1);
161 
162         ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
163         EXPECT_EQ(ret, HDF_SUCCESS);
164     }
165 }
166 
167 /**
168   * @tc.name: ExecuteVibratorEffect004
169   * @tc.desc: Controls this Performing Time Series Vibrator Effects.
170   * Controls this vibrator to stop the vibrator.
171   * @tc.type: FUNC
172   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0600, Function | MediumTest | Level1)173 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0600, Function | MediumTest | Level1)
174 {
175     ASSERT_NE(nullptr, g_vibratorInterface);
176 
177     int32_t ret;
178     for (auto iter : g_effect_list) {
179         printf("VibratorEffect : %s\n", iter.c_str());
180         ret = g_vibratorInterface->Start(iter);
181         EXPECT_EQ(ret, HDF_SUCCESS);
182 
183     OsalMSleep(g_sleepTime2);
184 
185         ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_BUTT);
186         EXPECT_EQ(ret, HDF_ERR_INVALID_PARAM);
187 
188         ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
189         EXPECT_EQ(ret, HDF_SUCCESS);
190     }
191 }
192 
193 /**
194   * @tc.name: ExecuteVibratorEffect005
195   * @tc.desc: Controls this vibrator to stop the vibrator.
196   * Controls this Performing Time Series Vibrator Effects.
197   * Controls this vibrator to stop the vibrator.
198   * @tc.type: FUNC
199   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0700, Function | MediumTest | Level1)200 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0700, Function | MediumTest | Level1)
201 {
202     ASSERT_NE(nullptr, g_vibratorInterface);
203 
204     int32_t ret;
205     for (auto iter : g_effect_list) {
206         printf("VibratorEffect : %s\n", iter.c_str());
207         ret = g_vibratorInterface->Start(iter);
208         EXPECT_EQ(ret, HDF_SUCCESS);
209 
210     OsalMSleep(g_sleepTime2);
211 
212         ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
213         EXPECT_EQ(ret, HDF_SUCCESS);
214     }
215 }
216 
217 /**
218   * @tc.name: ExecuteVibratorEffect006
219   * @tc.desc: Controls this vibrator to stop the vibrator.
220   * Controls this Perform built-in Vibrator Effects.
221   * Controls this vibrator to stop the vibrator.
222   * @tc.type: FUNC
223   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0800, Function | MediumTest | Level1)224 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0800, Function | MediumTest | Level1)
225 {
226     ASSERT_NE(nullptr, g_vibratorInterface);
227 
228     int32_t ret;
229     for (auto iter : g_effect_list) {
230         printf("VibratorEffect : %s\n", iter.c_str());
231         ret = g_vibratorInterface->Start(iter);
232         EXPECT_EQ(ret, HDF_SUCCESS);
233 
234     OsalMSleep(g_sleepTime2);
235 
236         ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
237         EXPECT_EQ(ret, HDF_SUCCESS);
238     }
239 }
240 
241 /**
242   * @tc.name: ExecuteVibratorEffect007
243   * @tc.desc: Controls this Perform a one-shot vibrator with a arbitrary string.
244   * Controls this vibrator to stop the vibrator.
245   * @tc.type: FUNC
246   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0900, Function | MediumTest | Level1)247 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_0900, Function | MediumTest | Level1)
248 {
249     ASSERT_NE(nullptr, g_vibratorInterface);
250 
251     int32_t startRet = g_vibratorInterface->Start(g_arbitraryStr);
252     EXPECT_EQ(startRet, HDF_ERR_INVALID_PARAM);
253 
254     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
255     EXPECT_EQ(endRet, HDF_SUCCESS);
256 }
257 
258 /**
259   * @tc.name: GetVibratorInfo_001
260   * @tc.desc: Obtain the vibrator setting strength, frequency capability and range in the system.
261   * Validity check of input parameters.
262   * @tc.type: FUNC
263   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1000, Function | MediumTest | Level1)264 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1000, Function | MediumTest | Level1)
265 {
266     uint32_t majorVer;
267     uint32_t minorVer;
268     if (g_vibratorInterface->GetVersion(majorVer, minorVer) != HDF_SUCCESS) {
269         printf("get version failed!\n\t");
270         return;
271     }
272 
273     if (majorVer > 0 && minorVer <= 0) {
274         printf("version not support!\n\t");
275         return;
276     }
277     ASSERT_NE(nullptr, g_vibratorInterface);
278 
279     std::vector<HdfVibratorInfo> info;
280 
281     int32_t startRet = g_vibratorInterface->GetVibratorInfo(info);
282     EXPECT_EQ(startRet, HDF_SUCCESS);
283 
284     printf("intensity = %d, intensityMaxValue = %d, intensityMinValue = %d\n\t",
285         info[0].isSupportIntensity, info[0].intensityMaxValue, info[0].intensityMinValue);
286     printf("frequency = %d, intensityMaxValue = %d, intensityMinValue = %d\n\t",
287         info[0].isSupportFrequency, info[0].frequencyMaxValue, info[0].frequencyMinValue);
288 }
289 
290 /**
291   * @tc.name: EnableVibratorModulation_001
292   * @tc.desc: Start vibrator based on the setting vibration effect.
293   * @tc.type: FUNC
294   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1100, Function | MediumTest | Level1)295 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1100, Function | MediumTest | Level1)
296 {
297     uint32_t majorVer;
298     uint32_t minorVer;
299     if (g_vibratorInterface->GetVersion(majorVer, minorVer) != HDF_SUCCESS) {
300         printf("get version failed!\n\t");
301         return;
302     }
303 
304     if (majorVer > 0 && minorVer <= 0) {
305         printf("version not support!\n\t");
306         return;
307     }
308     ASSERT_NE(nullptr, g_vibratorInterface);
309 
310     std::vector<HdfVibratorInfo> info;
311 
312     int32_t startRet = g_vibratorInterface->GetVibratorInfo(info);
313     EXPECT_EQ(startRet, HDF_SUCCESS);
314 
315     if ((info[0].isSupportIntensity == 1) || (info[0].isSupportFrequency == 1)) {
316         EXPECT_GT(g_duration, 0);
317         EXPECT_GE(g_intensity1, info[0].intensityMinValue);
318         EXPECT_LE(g_intensity1, info[0].intensityMaxValue);
319         EXPECT_GE(g_frequency1, info[0].frequencyMinValue);
320         EXPECT_LE(g_frequency1, info[0].frequencyMaxValue);
321 
322         startRet = g_vibratorInterface->EnableVibratorModulation(g_duration, g_intensity1, g_frequency1);
323         EXPECT_EQ(startRet, HDF_SUCCESS);
324         OsalMSleep(g_sleepTime1);
325         startRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
326         EXPECT_EQ(startRet, HDF_SUCCESS);
327     }
328 }
329 
330 /**
331   * @tc.name: EnableVibratorModulation_002
332   * @tc.desc: Start vibrator based on the setting vibration effect.
333   * Validity check of input parameters.
334   * @tc.type: FUNC
335   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1200, Function | MediumTest | Level1)336 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1200, Function | MediumTest | Level1)
337 {
338     uint32_t majorVer;
339     uint32_t minorVer;
340     if (g_vibratorInterface->GetVersion(majorVer, minorVer) != HDF_SUCCESS) {
341         printf("get version failed!\n\t");
342         return;
343     }
344 
345     if (majorVer > 0 && minorVer <= 0) {
346         printf("version not support!\n\t");
347         return;
348     }
349     ASSERT_NE(nullptr, g_vibratorInterface);
350 
351     std::vector<HdfVibratorInfo> info;
352 
353     int32_t startRet = g_vibratorInterface->GetVibratorInfo(info);
354     EXPECT_EQ(startRet, HDF_SUCCESS);
355 
356     if ((info[0].isSupportIntensity == 1) || (info[0].isSupportFrequency == 1)) {
357         startRet = g_vibratorInterface->EnableVibratorModulation(g_noDuration, g_intensity1, g_frequency1);
358         EXPECT_EQ(startRet, VIBRATOR_NOT_PERIOD);
359     }
360 }
361 
362 /**
363   * @tc.name: EnableVibratorModulation_003
364   * @tc.desc: Start vibrator based on the setting vibration effect.
365   * Validity check of input parameters.
366   * @tc.type: FUNC
367   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1300, Function | MediumTest | Level1)368 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1300, Function | MediumTest | Level1)
369 {
370     uint32_t majorVer;
371     uint32_t minorVer;
372     if (g_vibratorInterface->GetVersion(majorVer, minorVer) != HDF_SUCCESS) {
373         printf("get version failed!\n\t");
374         return;
375     }
376 
377     if (majorVer > 0 && minorVer <= 0) {
378         printf("version not support!\n\t");
379         return;
380     }
381     ASSERT_NE(nullptr, g_vibratorInterface);
382 
383     std::vector<HdfVibratorInfo> info;
384 
385     int32_t startRet = g_vibratorInterface->GetVibratorInfo(info);
386     EXPECT_EQ(startRet, HDF_SUCCESS);
387 
388     if ((info[0].isSupportIntensity == 1) || (info[0].isSupportFrequency == 1)) {
389         startRet = g_vibratorInterface->EnableVibratorModulation(g_duration, g_intensity2, g_frequency1);
390         EXPECT_EQ(startRet, VIBRATOR_NOT_INTENSITY);
391     }
392 }
393 
394 /**
395   * @tc.name: EnableVibratorModulation_004
396   * @tc.desc: Start vibrator based on the setting vibration effect.
397   * Validity check of input parameters.
398   * @tc.type: FUNC
399   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1400, Function | MediumTest | Level1)400 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1400, Function | MediumTest | Level1)
401 {
402     uint32_t majorVer;
403     uint32_t minorVer;
404     if (g_vibratorInterface->GetVersion(majorVer, minorVer) != HDF_SUCCESS) {
405         printf("get version failed!\n\t");
406         return;
407     }
408 
409     if (majorVer > 0 && minorVer <= 0) {
410         printf("version not support!\n\t");
411         return;
412     }
413     ASSERT_NE(nullptr, g_vibratorInterface);
414 
415     std::vector<HdfVibratorInfo> info;
416 
417     int32_t startRet = g_vibratorInterface->GetVibratorInfo(info);
418     EXPECT_EQ(startRet, HDF_SUCCESS);
419 
420     if ((info[0].isSupportIntensity == 1) || (info[0].isSupportFrequency == 1)) {
421         startRet = g_vibratorInterface->EnableVibratorModulation(g_duration, g_intensity1, g_frequency2);
422         EXPECT_EQ(startRet, VIBRATOR_NOT_FREQUENCY);
423     }
424 }
425 
426 /**
427   * @tc.name: GetEffectInfo_001
428   * @tc.desc: Get effect information with the given effect type.
429   * @tc.type: FUNC
430   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1500, Function | MediumTest | Level1)431 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1500, Function | MediumTest | Level1)
432 {
433     ASSERT_NE(nullptr, g_vibratorInterface);
434 
435     HdfEffectInfo effectInfo;
436     int32_t ret;
437     for (auto iter : g_effect_list) {
438         printf("VibratorEffect : %s\n", iter.c_str());
439         ret = g_vibratorInterface->GetEffectInfo(iter, effectInfo);
440         printf("isSupportEffect = [%d]\n\r", effectInfo.isSupportEffect);
441         printf("duration = [%d]\n\r", effectInfo.duration);
442         EXPECT_EQ(ret, HDF_SUCCESS);
443         if (effectInfo.isSupportEffect) {
444             EXPECT_GT(effectInfo.duration, MIN_DURATION);
445             EXPECT_LE(effectInfo.duration, MAX_DURATION);
446         }
447     }
448 }
449 
450 /**
451   * @tc.name: GetEffectInfo_002
452   * @tc.desc: Get effect information with the given effect type.
453   * @tc.type: FUNC
454   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1600, Function | MediumTest | Level1)455 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1600, Function | MediumTest | Level1)
456 {
457     ASSERT_NE(nullptr, g_vibratorInterface);
458 
459     HdfEffectInfo effectInfo;
460     int32_t ret = g_vibratorInterface->GetEffectInfo("invaild effect id", effectInfo);
461     printf("isSupportEffect = [%d]\n\r", effectInfo.isSupportEffect);
462     printf("duration = [%d]\n\r", effectInfo.duration);
463     EXPECT_EQ(ret, HDF_SUCCESS);
464     EXPECT_EQ(effectInfo.isSupportEffect, false);
465     EXPECT_EQ(effectInfo.duration, 0);
466 }
467 
468 /**
469   * @tc.name: PlayHapticPattern
470   * @tc.desc: HD vibration data packet delivery.
471   * @tc.type: FUNC
472   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1700, Function | MediumTest | Level1)473 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1700, Function | MediumTest | Level1)
474 {
475     ASSERT_NE(nullptr, g_vibratorInterface);
476 
477     int32_t startRet = g_vibratorInterface->PlayHapticPattern(g_pkg);
478     EXPECT_EQ(startRet, HDF_SUCCESS);
479 
480     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
481     EXPECT_EQ(endRet, HDF_SUCCESS);
482 }
483 
484 /**
485   * @tc.name: GetHapticCapacity
486   * @tc.desc: Obtains the vibration capability of the motor.
487   * @tc.type: FUNC
488   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1800, Function | MediumTest | Level1)489 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1800, Function | MediumTest | Level1)
490 {
491     ASSERT_NE(nullptr, g_vibratorInterface);
492 
493     OHOS::HDI::Vibrator::V1_2::HapticCapacity hapticCapacity;
494     int32_t startRet = g_vibratorInterface->GetHapticCapacity(hapticCapacity);
495     EXPECT_EQ(startRet, HDF_SUCCESS);
496     printf("hapticCapacity.isSupportHdHaptic = %d\n", hapticCapacity.isSupportHdHaptic);
497     printf("hapticCapacity.isSupportPresetMapping = %d\n", hapticCapacity.isSupportPresetMapping);
498     printf("hapticCapacity.isSupportTimeDelay = %d\n", hapticCapacity.isSupportTimeDelay);
499 
500     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
501     EXPECT_EQ(endRet, HDF_SUCCESS);
502 }
503 
504 /**
505   * @tc.name: GetHapticStartUpTime
506   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
507   * @tc.type: FUNC
508   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1900, Function | MediumTest | Level1)509 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_1900, Function | MediumTest | Level1)
510 {
511     ASSERT_NE(nullptr, g_vibratorInterface);
512 
513     int32_t startUpTime;
514     int32_t mode = 0;
515     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
516     EXPECT_EQ(startRet, HDF_SUCCESS);
517     printf("startUpTime = %d\n", startUpTime);
518 
519     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
520     EXPECT_EQ(endRet, HDF_SUCCESS);
521 }
522 
523 /**
524   * @tc.name: StopV1_2Test_001
525   * @tc.desc: Controls this vibrator to stop the vibrator.
526   * @tc.type: FUNC
527   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2000, Function | MediumTest | Level1)528 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2000, Function | MediumTest | Level1)
529 {
530     ASSERT_NE(nullptr, g_vibratorInterface);
531 
532     int32_t startRet = g_vibratorInterface->StartOnce(g_duration);
533     EXPECT_EQ(startRet, HDF_SUCCESS);
534 
535     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
536     EXPECT_EQ(endRet, HDF_SUCCESS);
537 }
538 
539 /**
540   * @tc.name: StopV1_2Test_002
541   * @tc.desc: Controls this vibrator to stop the vibrator.
542   * @tc.type: FUNC
543   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2100, Function | MediumTest | Level1)544 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2100, Function | MediumTest | Level1)
545 {
546     ASSERT_NE(nullptr, g_vibratorInterface);
547 
548     int32_t startRet = g_vibratorInterface->Start(g_effect1);
549     EXPECT_EQ(startRet, HDF_SUCCESS);
550 
551     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
552     EXPECT_EQ(endRet, HDF_SUCCESS);
553 }
554 
555 /**
556   * @tc.name: StopV1_2Test_003
557   * @tc.desc: Controls this vibrator to stop the vibrator.
558   * @tc.type: FUNC
559   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2200, Function | MediumTest | Level1)560 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2200, Function | MediumTest | Level1)
561 {
562     ASSERT_NE(nullptr, g_vibratorInterface);
563 
564     int32_t startRet = g_vibratorInterface->PlayHapticPattern(g_pkg);
565     EXPECT_EQ(startRet, HDF_SUCCESS);
566 
567     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_HDHAPTIC);
568     EXPECT_EQ(endRet, HDF_ERR_NOT_SUPPORT);
569 }
570 
571 /**
572   * @tc.name: StopV1_2Test_004
573   * @tc.desc: Controls this vibrator to stop the vibrator.
574   * @tc.type: FUNC
575   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2300, Function | MediumTest | Level1)576 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2300, Function | MediumTest | Level1)
577 {
578     ASSERT_NE(nullptr, g_vibratorInterface);
579 
580     int32_t startRet = g_vibratorInterface->Start(g_effect1);
581     EXPECT_EQ(startRet, HDF_SUCCESS);
582 
583     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_BUTT);
584     EXPECT_EQ(endRet, HDF_ERR_INVALID_PARAM);
585 }
586 
587 /**
588   * @tc.name: GetHapticStartUpTime1
589   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
590   * @tc.type: FUNC
591   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2700, Function | MediumTest | Level1)592 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2700, Function | MediumTest | Level1)
593 {
594     ASSERT_NE(nullptr, g_vibratorInterface);
595 
596     int32_t startUpTime;
597     int32_t mode = 1;
598     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
599     EXPECT_EQ(startRet, HDF_SUCCESS);
600     printf("startUpTime = %d\n", startUpTime);
601 
602     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
603     EXPECT_EQ(endRet, HDF_SUCCESS);
604 }
605 
606 /**
607   * @tc.name: GetHapticStartUpTime2
608   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
609   * @tc.type: FUNC
610   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2800, Function | MediumTest | Level1)611 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2800, Function | MediumTest | Level1)
612 {
613     ASSERT_NE(nullptr, g_vibratorInterface);
614 
615     int32_t startUpTime;
616     int32_t mode = 2;
617     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
618     EXPECT_EQ(startRet, HDF_SUCCESS);
619     printf("startUpTime = %d\n", startUpTime);
620 
621     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
622     EXPECT_EQ(endRet, HDF_SUCCESS);
623 }
624 
625 /**
626   * @tc.name: GetHapticStartUpTime3
627   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
628   * @tc.type: FUNC
629   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2900, Function | MediumTest | Level1)630 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_2900, Function | MediumTest | Level1)
631 {
632     ASSERT_NE(nullptr, g_vibratorInterface);
633 
634     int32_t startUpTime;
635     int32_t mode = 3;
636     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
637     EXPECT_EQ(startRet, HDF_SUCCESS);
638     printf("startUpTime = %d\n", startUpTime);
639 
640     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
641     EXPECT_EQ(endRet, HDF_SUCCESS);
642 }
643 
644 /**
645   * @tc.name: GetHapticStartUpTime4
646   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
647   * @tc.type: FUNC
648   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_3000, Function | MediumTest | Level1)649 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_3000, Function | MediumTest | Level1)
650 {
651     ASSERT_NE(nullptr, g_vibratorInterface);
652 
653     int32_t startUpTime;
654     int32_t mode = -1;
655     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
656     EXPECT_EQ(startRet, HDF_SUCCESS);
657     printf("startUpTime = %d\n", startUpTime);
658 
659     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
660     EXPECT_EQ(endRet, HDF_SUCCESS);
661 }
662 
663 /**
664   * @tc.name: GetHapticStartUpTime5
665   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
666   * @tc.type: FUNC
667   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_3100, Function | MediumTest | Level1)668 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_3100, Function | MediumTest | Level1)
669 {
670     ASSERT_NE(nullptr, g_vibratorInterface);
671 
672     int32_t startUpTime = 0;
673     int32_t mode = 0;
674     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
675     EXPECT_EQ(startRet, HDF_SUCCESS);
676     printf("startUpTime = %d\n", startUpTime);
677 
678     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
679     EXPECT_EQ(endRet, HDF_SUCCESS);
680 }
681 
682 /**
683   * @tc.name: GetHapticStartUpTime6
684   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
685   * @tc.type: FUNC
686   */
HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_3200, Function | MediumTest | Level1)687 HWTEST_F(HdfVibratorHdiServiceTest, SUB_Driver_Sensor_HdiVibrator_3200, Function | MediumTest | Level1)
688 {
689     ASSERT_NE(nullptr, g_vibratorInterface);
690 
691     int32_t startUpTime = -1;
692     int32_t mode = 0;
693     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
694     EXPECT_EQ(startRet, HDF_SUCCESS);
695     printf("startUpTime = %d\n", startUpTime);
696 
697     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
698     EXPECT_EQ(endRet, HDF_SUCCESS);
699 }
700 
701