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