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