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