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 <cstdio>
17 #include <gtest/gtest.h>
18 #include <securec.h>
19 #include <string>
20 #include "hdf_base.h"
21 #include "hdf_log.h"
22 #include "osal_time.h"
23 #include "parameters.h"
24 #include "v1_3/ivibrator_interface.h"
25 
26 #define HDF_LOG_TAG "hdi_unittest_vibrator"
27 #define TEST_FUNC_IN HDF_LOGI("%{public}s in", testing::UnitTest::GetInstance()->current_test_info()->name())
28 
29 using namespace std;
30 using namespace testing::ext;
31 using namespace OHOS::HDI::Vibrator;
32 using namespace OHOS::HDI::Vibrator::V1_3;
33 
34 namespace {
35     uint32_t g_duration = 2000;
36     std::string g_effect1 = "haptic.long_press.light";
37     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     V1_2::HapticPaket g_pkg1 = {434, 1, {{V1_2::TRANSIENT, 0, 149, 100, 50, 0, 4,
40         {{0, 0, 0}, {1, 1, 0}, {32, 1, -39}, {149, 0, -39}}}}};
41     int32_t g_vibratorId = 0;
42     int32_t g_intensity = 60;
43     std::vector<HdfWaveInformation> g_info;
44     const std::vector<std::string> g_effect{"haptic.long_press.light", "haptic.slide.light", \
45         "haptic.threshold", "haptic.long_press.medium", "haptic.fail", "haptic.common.notice1", \
46         "haptic.common.success", "haptic.charging", "haptic.long_press.heavy"};
47     HapticCapacity g_hapticCapacity;-
48     sptr<V1_3::IVibratorInterface> g_vibratorInterface = nullptr;
49 } // namespace
50 
51 class HdiUnitTestVibrator : public testing::Test {
52 public:
53     static void SetUpTestSuite();
54     static void TearDownTestSuite();
55     void SetUp();
56     void TearDown();
57 };
58 
SetUpTestSuite()59 void HdiUnitTestVibrator::SetUpTestSuite()
60 {
61     g_vibratorInterface = V1_3::IVibratorInterface::Get();
62 }
63 
TearDownTestSuite()64 void HdiUnitTestVibrator::TearDownTestSuite()
65 {
66 }
67 
SetUp()68 void HdiUnitTestVibrator::SetUp()
69 {
70 }
71 
TearDown()72 void HdiUnitTestVibrator::TearDown()
73 {
74 }
75 
76 /**
77   * @tc.name: CheckVibratorInstanceIsEmpty
78   * @tc.desc: Create a Vibrator instance. The instance is not empty.
79   * @tc.type: FUNC
80   * @tc.require: #IAU5KS
81   */
HWTEST_F(HdiUnitTestVibrator, CheckVibratorInstanceIsEmpty001, TestSize.Level1)82 HWTEST_F(HdiUnitTestVibrator, CheckVibratorInstanceIsEmpty001, TestSize.Level1)
83 {
84     TEST_FUNC_IN;
85     ASSERT_NE(nullptr, g_vibratorInterface);
86 }
87 
88 /**
89   * @tc.name: VibratorStartOnceTest001
90   * @tc.desc: Start one-shot vibration with given duration.
91   * @tc.type: FUNC
92   * @tc.require: #IAU5KS
93   */
HWTEST_F(HdiUnitTestVibrator, VibratorStartOnceTest001, TestSize.Level1)94 HWTEST_F(HdiUnitTestVibrator, VibratorStartOnceTest001, TestSize.Level1)
95 {
96     TEST_FUNC_IN;
97     ASSERT_NE(nullptr, g_vibratorInterface);
98 
99     int32_t ret = g_vibratorInterface->StartOnce(2000);
100     HDF_LOGD("ret:%{public}d", ret);
101     EXPECT_EQ(HDF_SUCCESS, ret);
102     OsalMSleep(2000);
103 }
104 
105 /**
106   * @tc.name: VibratorStartTest001
107   * @tc.desc: Start periodic vibration with preset effect.
108   * @tc.type: FUNC
109   * @tc.require: #IAU5KS
110   */
HWTEST_F(HdiUnitTestVibrator, VibratorStartTest001, TestSize.Level1)111 HWTEST_F(HdiUnitTestVibrator, VibratorStartTest001, TestSize.Level1)
112 {
113     TEST_FUNC_IN;
114     ASSERT_NE(nullptr, g_vibratorInterface);
115 
116     int32_t ret = g_vibratorInterface->Start("haptic.pattern.type1");
117     HDF_LOGD("ret:%{public}d", ret);
118     EXPECT_EQ(HDF_SUCCESS, ret);
119     OsalMSleep(2000);
120 }
121 
122 /**
123   * @tc.name: GetHapticCapacity
124   * @tc.desc: Obtains the vibration capability of the motor.
125   * @tc.type: FUNC
126   * @tc.require: #IAU5KS
127   */
HWTEST_F(HdiUnitTestVibrator, GetHapticCapacity, TestSize.Level1)128 HWTEST_F(HdiUnitTestVibrator, GetHapticCapacity, TestSize.Level1)
129 {
130     TEST_FUNC_IN;
131     ASSERT_NE(nullptr, g_vibratorInterface);
132 
133     int32_t startRet = g_vibratorInterface->GetHapticCapacity(g_hapticCapacity);
134     EXPECT_EQ(startRet, HDF_SUCCESS);
135     printf("g_hapticCapacity.isSupportHdHaptic = %d\n", g_hapticCapacity.isSupportHdHaptic);
136     printf("g_hapticCapacity.isSupportPresetMapping = %d\n", g_hapticCapacity.isSupportPresetMapping);
137     printf("g_hapticCapacity.isSupportTimeDelay = %d\n", g_hapticCapacity.isSupportTimeDelay);
138 }
139 
140 /**
141   * @tc.name: EnableCompositeEffectTest001
142   * @tc.desc: Start periodic vibration with custom composite effect.
143   * @tc.type: FUNC
144   * @tc.require: #IAU5KS
145   */
HWTEST_F(HdiUnitTestVibrator, EnableCompositeEffectTest001, TestSize.Level1)146 HWTEST_F(HdiUnitTestVibrator, EnableCompositeEffectTest001, TestSize.Level1)
147 {
148     TEST_FUNC_IN;
149     ASSERT_NE(nullptr, g_vibratorInterface);
150 
151     if (g_hapticCapacity.isSupportPresetMapping) {
152         HDF_LOGI("EnableCompositeEffectTest001 phone in");
153         PrimitiveEffect primitiveEffect1 { 0, 60007, 0 };
154         PrimitiveEffect primitiveEffect2 { 1000, 60007, 0 };
155         PrimitiveEffect primitiveEffect3 { 1000, 60007, 0 };
156         CompositeEffect effect1 = {
157             .primitiveEffect = primitiveEffect1,
158         };
159         CompositeEffect effect2 = {
160             .primitiveEffect = primitiveEffect2,
161         };
162         CompositeEffect effect3 = {
163             .primitiveEffect = primitiveEffect3,
164         };
165         std::vector<CompositeEffect> vec;
166         vec.push_back(effect1);
167         vec.push_back(effect2);
168         vec.push_back(effect3);
169         HdfCompositeEffect effect;
170         effect.type = HDF_EFFECT_TYPE_PRIMITIVE;
171         effect.compositeEffects = vec;
172         int32_t ret = g_vibratorInterface->EnableCompositeEffect(effect);
173         HDF_LOGD("ret:%{public}d", ret);
174         EXPECT_EQ(HDF_SUCCESS, ret);
175         OsalMSleep(2000);
176     }
177 }
178 
179 /**
180   * @tc.name: EnableCompositeEffectTest002
181   * @tc.desc: Start periodic vibration with custom composite effect.
182   * @tc.type: FUNC
183   * @tc.require: #IAU5KS
184   */
HWTEST_F(HdiUnitTestVibrator, EnableCompositeEffectTest002, TestSize.Level1)185 HWTEST_F(HdiUnitTestVibrator, EnableCompositeEffectTest002, TestSize.Level1)
186 {
187     TEST_FUNC_IN;
188     ASSERT_NE(nullptr, g_vibratorInterface);
189 
190     if (g_hapticCapacity.isSupportPresetMapping) {
191         HDF_LOGI("EnableCompositeEffectTest002 phone in");
192         PrimitiveEffect primitiveEffect1 { 0, 60007, 0 };
193         PrimitiveEffect primitiveEffect2 { 1000, 60007, 0 };
194         PrimitiveEffect primitiveEffect3 { 1000, 60007, 0 };
195         CompositeEffect effect1 = {
196             .primitiveEffect = primitiveEffect1,
197         };
198         CompositeEffect effect2 = {
199             .primitiveEffect = primitiveEffect2,
200         };
201         CompositeEffect effect3 = {
202             .primitiveEffect = primitiveEffect3,
203         };
204         std::vector<CompositeEffect> vec;
205         vec.push_back(effect1);
206         vec.push_back(effect2);
207         vec.push_back(effect3);
208         HdfCompositeEffect effect;
209         effect.type = HDF_EFFECT_TYPE_PRIMITIVE;
210         effect.compositeEffects = vec;
211         int32_t ret = g_vibratorInterface->EnableCompositeEffect(effect);
212         HDF_LOGD("ret:%{public}d", ret);
213         EXPECT_EQ(HDF_SUCCESS, ret);
214 
215         OsalMSleep(1000);
216         ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
217         HDF_LOGD("ret:%{public}d", ret);
218         EXPECT_EQ(HDF_SUCCESS, ret);
219     }
220 }
221 
222 /**
223   * @tc.name: GetEffectInfoTest001
224   * @tc.desc: Get effect information with the given effect type.
225   * @tc.type: FUNC
226   * @tc.require: #IAU5KS
227   */
HWTEST_F(HdiUnitTestVibrator, GetEffectInfoTest001, TestSize.Level1)228 HWTEST_F(HdiUnitTestVibrator, GetEffectInfoTest001, TestSize.Level1)
229 {
230     TEST_FUNC_IN;
231     ASSERT_NE(nullptr, g_vibratorInterface);
232 
233     HdfEffectInfo effectInfo;
234     int32_t ret = g_vibratorInterface->GetEffectInfo("haptic.pattern.type1", effectInfo);
235     HDF_LOGD("ret:%{public}d", ret);
236     EXPECT_EQ(effectInfo.duration, 1900);
237     EXPECT_EQ(effectInfo.isSupportEffect, true);
238     EXPECT_EQ(HDF_SUCCESS, ret);
239 }
240 
241 /**
242   * @tc.name: GetEffectInfoTest002
243   * @tc.desc: Get effect information with the given effect type.
244   * @tc.type: FUNC
245   * @tc.require: #IAU5KS
246   */
HWTEST_F(HdiUnitTestVibrator, GetEffectInfoTest002, TestSize.Level1)247 HWTEST_F(HdiUnitTestVibrator, GetEffectInfoTest002, TestSize.Level1)
248 {
249     TEST_FUNC_IN;
250     ASSERT_NE(nullptr, g_vibratorInterface);
251 
252     HdfEffectInfo effectInfo;
253     int32_t ret = g_vibratorInterface->GetEffectInfo("invalid.effect.id", effectInfo);
254     HDF_LOGD("ret:%{public}d", ret);
255     EXPECT_EQ(HDF_SUCCESS, ret);
256     EXPECT_EQ(effectInfo.duration, 0);
257     EXPECT_EQ(effectInfo.isSupportEffect, false);
258 }
259 
260 /**
261   * @tc.name: VibratorStopTest001
262   * @tc.desc: Stop vibration.
263   * @tc.type: FUNC
264   * @tc.require: #IAU5KS
265   */
HWTEST_F(HdiUnitTestVibrator, VibratorStopTest001, TestSize.Level1)266 HWTEST_F(HdiUnitTestVibrator, VibratorStopTest001, TestSize.Level1)
267 {
268     TEST_FUNC_IN;
269     ASSERT_NE(nullptr, g_vibratorInterface);
270 
271     int32_t ret = g_vibratorInterface->StartOnce(2000);
272     HDF_LOGD("ret:%{public}d", ret);
273     EXPECT_EQ(HDF_SUCCESS, ret);
274 
275     OsalMSleep(1000);
276     ret = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
277     HDF_LOGD("ret:%{public}d", ret);
278     EXPECT_EQ(HDF_SUCCESS, ret);
279 }
280 
281 /**
282   * @tc.name: IsVibratorRunningTest001
283   * @tc.desc: Get vibration status.
284   * @tc.type: FUNC
285   * @tc.require: #IAU5KS
286   */
HWTEST_F(HdiUnitTestVibrator, IsVibratorRunningTest001, TestSize.Level1)287 HWTEST_F(HdiUnitTestVibrator, IsVibratorRunningTest001, TestSize.Level1)
288 {
289     TEST_FUNC_IN;
290     ASSERT_NE(nullptr, g_vibratorInterface);
291 
292     PrimitiveEffect primitiveEffect1 { 0, 60007, 0 };
293     PrimitiveEffect primitiveEffect2 { 1000, 60007, 0 };
294     PrimitiveEffect primitiveEffect3 { 1000, 60007, 0 };
295     CompositeEffect effect1 = {
296         .primitiveEffect = primitiveEffect1,
297     };
298     CompositeEffect effect2 = {
299         .primitiveEffect = primitiveEffect2,
300     };
301     CompositeEffect effect3 = {
302         .primitiveEffect = primitiveEffect3,
303     };
304     std::vector<CompositeEffect> vec;
305     vec.push_back(effect1);
306     vec.push_back(effect2);
307     vec.push_back(effect3);
308     HdfCompositeEffect effect;
309     effect.type = HDF_EFFECT_TYPE_PRIMITIVE;
310     effect.compositeEffects = vec;
311     int32_t ret = g_vibratorInterface->EnableCompositeEffect(effect);
312     HDF_LOGD("ret:%{public}d", ret);
313     if (g_hapticCapacity.isSupportPresetMapping) {
314         EXPECT_EQ(HDF_SUCCESS, ret);
315         bool state {false};
316         g_vibratorInterface->IsVibratorRunning(state);
317         HDF_LOGD("Vibrating state:%{public}s", state ? "is vibrating ..." : "vibrate stopped");
318         EXPECT_EQ(state, true);
319 
320         OsalMSleep(3000);
321         g_vibratorInterface->IsVibratorRunning(state);
322         HDF_LOGD("Stoped state:%{public}s", state ? "is vibrating ..." : "vibrate stopped");
323         EXPECT_EQ(state, false);
324     } else {
325         OsalMSleep(3000);
326     }
327 }
328 
329 /**
330   * @tc.name: IsVibratorRunningTest002
331   * @tc.desc: Get vibration status.
332   * @tc.type: FUNC
333   * @tc.require: #IAU5KS
334   */
HWTEST_F(HdiUnitTestVibrator, IsVibratorRunningTest002, TestSize.Level1)335 HWTEST_F(HdiUnitTestVibrator, IsVibratorRunningTest002, TestSize.Level1)
336 {
337     TEST_FUNC_IN;
338     bool state {false};
339     g_vibratorInterface->IsVibratorRunning(state);
340     HDF_LOGD("No vibrate state:%{public}s", state ? "is vibrating ..." : "vibrate stopped");
341     EXPECT_EQ(state, false);
342 }
343 
344 /**
345   * @tc.name: GetVibratorInfo001
346   * @tc.desc: Get vibrator information.
347   * @tc.type: FUNC
348   * @tc.require: #IAU5KS
349   */
HWTEST_F(HdiUnitTestVibrator, GetVibratorInfo001, TestSize.Level1)350 HWTEST_F(HdiUnitTestVibrator, GetVibratorInfo001, TestSize.Level1)
351 {
352     TEST_FUNC_IN;
353     ASSERT_NE(nullptr, g_vibratorInterface);
354     std::vector<HdfVibratorInfo> info;
355     int32_t ret = g_vibratorInterface->GetVibratorInfo(info);
356     EXPECT_EQ(HDF_SUCCESS, ret);
357     EXPECT_GT(info.size(), 0);
358 
359     printf("isSupportIntensity = %d, intensityMaxValue = %d, intensityMinValue = %d\n\t",
360         info[0].isSupportIntensity, info[0].intensityMaxValue, info[0].intensityMinValue);
361     printf("isSupportFrequency = %d, intensityMaxValue = %d, intensityMinValue = %d\n\t",
362         info[0].isSupportFrequency, info[0].frequencyMaxValue, info[0].frequencyMinValue);
363 }
364 
365 /**
366   * @tc.name: EnableVibratorModulation_001
367   * @tc.desc: Start vibrator based on the setting vibration effect.
368   * @tc.type: FUNC
369   * @tc.require: #IAU5KS
370   */
HWTEST_F(HdiUnitTestVibrator, EnableVibratorModulation_001, TestSize.Level1)371 HWTEST_F(HdiUnitTestVibrator, EnableVibratorModulation_001, TestSize.Level1)
372 {
373     TEST_FUNC_IN;
374     ASSERT_NE(nullptr, g_vibratorInterface);
375     std::vector<HdfVibratorInfo> info;
376 
377     int32_t startRet = g_vibratorInterface->GetVibratorInfo(info);
378     EXPECT_EQ(startRet, HDF_SUCCESS);
379 
380     if ((info[0].isSupportIntensity == 1) || (info[0].isSupportFrequency == 1)) {
381         uint32_t duration = 2000;
382         int32_t intensity = 30;
383         int32_t frequency = 200;
384         uint32_t sleepTime = 2000;
385         startRet = g_vibratorInterface->EnableVibratorModulation(duration, intensity, frequency);
386         EXPECT_EQ(startRet, HDF_SUCCESS);
387         OsalMSleep(sleepTime);
388         startRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
389         EXPECT_EQ(startRet, HDF_SUCCESS);
390     }
391 }
392 
393 /**
394   * @tc.name: EnableVibratorModulation_002
395   * @tc.desc: Start vibrator based on the setting vibration effect.
396   * Validity check of input parameters.
397   * @tc.type: FUNC
398   * @tc.require: #IAU5KS
399   */
HWTEST_F(HdiUnitTestVibrator, EnableVibratorModulation_002, TestSize.Level1)400 HWTEST_F(HdiUnitTestVibrator, EnableVibratorModulation_002, TestSize.Level1)
401 {
402     TEST_FUNC_IN;
403     ASSERT_NE(nullptr, g_vibratorInterface);
404     std::vector<HdfVibratorInfo> info;
405 
406     int32_t startRet = g_vibratorInterface->GetVibratorInfo(info);
407     EXPECT_EQ(startRet, HDF_SUCCESS);
408 
409     if ((info[0].isSupportIntensity == 1) || (info[0].isSupportFrequency == 1)) {
410         uint32_t noDuration = 0;
411         int32_t intensity = 30;
412         int32_t frequency = 200;
413         startRet = g_vibratorInterface->EnableVibratorModulation(noDuration, intensity, frequency);
414         EXPECT_EQ(startRet, -1);
415     }
416 }
417 
418 /**
419   * @tc.name: VibratorStartTest011
420   * @tc.desc: Start periodic vibration with preset effect.
421   * @tc.type: FUNC
422   * @tc.require: #IAU5KS
423   */
HWTEST_F(HdiUnitTestVibrator, VibratorStartTest011, TestSize.Level1)424 HWTEST_F(HdiUnitTestVibrator, VibratorStartTest011, TestSize.Level1)
425 {
426     TEST_FUNC_IN;
427     ASSERT_NE(nullptr, g_vibratorInterface);
428 
429     HdfEffectInfo effectInfo;
430     for (auto iter : g_effect) {
431         g_vibratorInterface->GetEffectInfo(iter, effectInfo);
432         if (effectInfo.isSupportEffect == true) {
433             printf("VibratorStart : %s\n", iter.c_str());
434             int32_t ret = g_vibratorInterface->Start(iter);
435             HDF_LOGD("ret:%{public}d", ret);
436             EXPECT_EQ(HDF_SUCCESS, ret);
437             OsalMSleep(2000);
438         }
439     }
440 }
441 
442 /**
443   * @tc.name: PlayHapticPattern
444   * @tc.desc: HD vibration data packet delivery.
445   * @tc.type: FUNC
446   * @tc.require: #IAU5KS
447   */
HWTEST_F(HdiUnitTestVibrator, PlayHapticPattern, TestSize.Level1)448 HWTEST_F(HdiUnitTestVibrator, PlayHapticPattern, TestSize.Level1)
449 {
450     TEST_FUNC_IN;
451     ASSERT_NE(nullptr, g_vibratorInterface);
452 
453     int32_t startRet = g_vibratorInterface->PlayHapticPattern(g_pkg);
454     EXPECT_EQ(startRet, HDF_SUCCESS);
455 
456     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
457     EXPECT_EQ(endRet, HDF_SUCCESS);
458 }
459 
460 /**
461   * @tc.name: PlayHapticPattern_001
462   * @tc.desc: HD vibration data packet delivery.
463   * @tc.type: FUNC
464   * @tc.require: #IAU5KS
465   */
HWTEST_F(HdiUnitTestVibrator, PlayHapticPattern_001, TestSize.Level1)466 HWTEST_F(HdiUnitTestVibrator, PlayHapticPattern_001, TestSize.Level1)
467 {
468     TEST_FUNC_IN;
469     ASSERT_NE(nullptr, g_vibratorInterface);
470 
471     int32_t startRet = g_vibratorInterface->PlayHapticPattern(g_pkg1);
472     EXPECT_EQ(startRet, HDF_SUCCESS);
473 
474     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
475     EXPECT_EQ(endRet, HDF_SUCCESS);
476 }
477 
478 /**
479   * @tc.name: GetHapticStartUpTime
480   * @tc.desc: Indicates the time from command is issued to the time the motor starts.
481   * @tc.type: FUNC
482   * @tc.require: #IAU5KS
483   */
HWTEST_F(HdiUnitTestVibrator, GetHapticStartUpTime, TestSize.Level1)484 HWTEST_F(HdiUnitTestVibrator, GetHapticStartUpTime, TestSize.Level1)
485 {
486     TEST_FUNC_IN;
487     ASSERT_NE(nullptr, g_vibratorInterface);
488 
489     int32_t startUpTime = 0;
490     int32_t mode = 0;
491     int32_t startRet = g_vibratorInterface->GetHapticStartUpTime(mode, startUpTime);
492     EXPECT_EQ(startRet, HDF_SUCCESS);
493     printf("startUpTime = %d\n", startUpTime);
494 
495     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
496     EXPECT_EQ(endRet, HDF_SUCCESS);
497 }
498 
499 /**
500   * @tc.name: StopV1_2Test_001
501   * @tc.desc: Controls this vibrator to stop the vibrator.
502   * @tc.type: FUNC
503   * @tc.require: #IAU5KS
504   */
HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_001, TestSize.Level1)505 HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_001, TestSize.Level1)
506 {
507     TEST_FUNC_IN;
508     ASSERT_NE(nullptr, g_vibratorInterface);
509 
510     int32_t startRet = g_vibratorInterface->StartOnce(g_duration);
511     EXPECT_EQ(startRet, HDF_SUCCESS);
512 
513     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_ONCE);
514     EXPECT_EQ(endRet, HDF_SUCCESS);
515 }
516 
517 /**
518   * @tc.name: StopV1_2Test_002
519   * @tc.desc: Controls this vibrator to stop the vibrator.
520   * @tc.type: FUNC
521   * @tc.require: #IAU5KS
522   */
HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_002, TestSize.Level1)523 HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_002, TestSize.Level1)
524 {
525     TEST_FUNC_IN;
526     ASSERT_NE(nullptr, g_vibratorInterface);
527 
528     int32_t startRet = g_vibratorInterface->Start(g_effect1);
529     EXPECT_EQ(startRet, HDF_SUCCESS);
530 
531     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
532     EXPECT_EQ(endRet, HDF_SUCCESS);
533 }
534 
535 /**
536   * @tc.name: StopV1_2Test_003
537   * @tc.desc: Controls this vibrator to stop the vibrator.
538   * @tc.type: FUNC
539   * @tc.require: #IAU5KS
540   */
HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_003, TestSize.Level1)541 HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_003, TestSize.Level1)
542 {
543     TEST_FUNC_IN;
544     ASSERT_NE(nullptr, g_vibratorInterface);
545 
546     int32_t startRet = g_vibratorInterface->PlayHapticPattern(g_pkg);
547     EXPECT_EQ(startRet, HDF_SUCCESS);
548 
549     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_HDHAPTIC);
550     EXPECT_EQ(endRet, HDF_SUCCESS);
551 }
552 
553 /**
554   * @tc.name: StopV1_2Test_004
555   * @tc.desc: Controls this vibrator to stop the vibrator.
556   * @tc.type: FUNC
557   * @tc.require: #IAU5KS
558   */
HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_004, TestSize.Level1)559 HWTEST_F(HdiUnitTestVibrator, StopV1_2Test_004, TestSize.Level1)
560 {
561     TEST_FUNC_IN;
562     ASSERT_NE(nullptr, g_vibratorInterface);
563 
564     int32_t startRet = g_vibratorInterface->Start(g_effect1);
565     EXPECT_EQ(startRet, HDF_SUCCESS);
566 
567     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_BUTT);
568     EXPECT_EQ(endRet, HDF_ERR_INVALID_PARAM);
569 }
570 
571 /**
572   * @tc.name: StartByIntensityTest
573   * @tc.desc: Controls this Performing Time Series Vibrator Effects.
574   * Controls this vibrator to stop the vibrator
575   * @tc.type: FUNC
576   * @tc.require: #IAU5KS
577   */
HWTEST_F(HdiUnitTestVibrator, StartByIntensityTest, TestSize.Level1)578 HWTEST_F(HdiUnitTestVibrator, StartByIntensityTest, TestSize.Level1)
579 {
580     TEST_FUNC_IN;
581     ASSERT_NE(nullptr, g_vibratorInterface);
582 
583     int32_t startRet = g_vibratorInterface->StartByIntensity(g_effect1, g_intensity);
584     EXPECT_EQ(startRet, HDF_SUCCESS);
585 
586     int32_t endRet = g_vibratorInterface->StopV1_2(HdfVibratorModeV1_2::HDF_VIBRATOR_MODE_PRESET);
587     EXPECT_EQ(endRet, HDF_SUCCESS);
588 }
589 
590 /**
591   * @tc.name: StopTest
592   * @tc.desc: Controls this Performing Time Series Vibrator Effects.
593   * Controls this vibrator to stop the vibrator
594   * @tc.type: FUNC
595   * @tc.require: #IAU5KS
596   */
HWTEST_F(HdiUnitTestVibrator, StopTest, TestSize.Level1)597 HWTEST_F(HdiUnitTestVibrator, StopTest, TestSize.Level1)
598 {
599     TEST_FUNC_IN;
600     ASSERT_NE(nullptr, g_vibratorInterface);
601 
602     int32_t startRet = g_vibratorInterface->StartOnce(g_duration);
603     EXPECT_EQ(startRet, HDF_SUCCESS);
604     int32_t endRet = g_vibratorInterface->Stop(HdfVibratorMode::HDF_VIBRATOR_MODE_ONCE);
605     EXPECT_EQ(endRet, HDF_SUCCESS);
606     OsalMSleep(g_duration);
607 
608     startRet = g_vibratorInterface->StartByIntensity(g_effect1, g_intensity);
609     EXPECT_EQ(startRet, HDF_SUCCESS);
610     endRet = g_vibratorInterface->StopV1_2(HdfVibratorMode::HDF_VIBRATOR_MODE_PRESET);
611     EXPECT_EQ(endRet, HDF_SUCCESS);
612     OsalMSleep(g_duration);
613 
614 
615     startRet = g_vibratorInterface->Start(g_effect1);
616     EXPECT_EQ(startRet, HDF_SUCCESS);
617     endRet = g_vibratorInterface->Stop(HdfVibratorMode::HDF_VIBRATOR_MODE_BUTT);
618     EXPECT_EQ(endRet, HDF_ERR_INVALID_PARAM);
619     OsalMSleep(g_duration);
620 }
621 
622 /**
623   * @tc.name: GetAllWaveInfoTest
624   * @tc.desc: Controls this Performing Time Series Vibrator Effects.
625   * Controls this vibrator to stop the vibrator
626   * @tc.type: FUNC
627   * @tc.require: #IAU5KS
628   */
HWTEST_F(HdiUnitTestVibrator, GetAllWaveInfoTest, TestSize.Level1)629 HWTEST_F(HdiUnitTestVibrator, GetAllWaveInfoTest, TestSize.Level1)
630 {
631     TEST_FUNC_IN;
632     ASSERT_NE(nullptr, g_vibratorInterface);
633 
634     int32_t startRet = g_vibratorInterface->GetAllWaveInfo(g_vibratorId, g_info);
635 
636     if (g_hapticCapacity.isSupportPresetMapping) {
637         EXPECT_EQ(startRet, HDF_SUCCESS);
638     } else {
639         HDF_LOGI("device is not support preset mapping");
640     }
641 }