• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <fcntl.h>
17 #include <gtest/gtest.h>
18 #include <string>
19 #include <thread>
20 
21 #include "accesstoken_kit.h"
22 #include "nativetoken_kit.h"
23 #include "parameters.h"
24 #include "parcel.h"
25 #include "token_setproc.h"
26 
27 #include "sensors_errors.h"
28 #include "vibrator_agent.h"
29 #include "vibrator_infos.h"
30 
31 #undef LOG_TAG
32 #define LOG_TAG "VibratorAgentTest"
33 
34 namespace OHOS {
35 namespace Sensors {
36 using namespace testing::ext;
37 using namespace Security::AccessToken;
38 using Security::AccessToken::AccessTokenID;
39 
40 namespace {
41 constexpr int32_t TIME_WAIT_FOR_OP = 500;
42 constexpr int32_t TIME_WAIT_FOR_OP_EACH_CASE = 200;
43 constexpr int32_t INTENSITY_HIGH = 100;
44 constexpr int32_t INTENSITY_MEDIUM = 50;
45 constexpr int32_t INTENSITY_LOW = 20;
46 constexpr int32_t INTENSITY_INVALID = -1;
47 constexpr int32_t SESSION_ID_ONE = 1;
48 constexpr int32_t SESSION_ID_TWO = 2;
49 constexpr int32_t SESSION_ID_THREE = 3;
50 constexpr int32_t SESSION_ID_FOUR = 4;
51 constexpr int32_t SESSION_ID_FIVE = 5;
52 constexpr int32_t LOOP_TIMES = 5;
53 
54 PermissionStateFull g_infoManagerTestState = {
55     .grantFlags = {1},
56     .grantStatus = {PermissionState::PERMISSION_GRANTED},
57     .isGeneral = true,
58     .permissionName = "ohos.permission.VIBRATE",
59     .resDeviceID = {"local"}
60 };
61 
62 HapPolicyParams g_infoManagerTestPolicyPrams = {
63     .apl = APL_NORMAL,
64     .domain = "test.domain",
65     .permList = {},
66     .permStateList = {g_infoManagerTestState}
67 };
68 
69 HapInfoParams g_infoManagerTestInfoParms = {
70     .bundleName = "vibratoragent_test",
71     .userID = 1,
72     .instIndex = 0,
73     .appIDDesc = "vibratorAgentTest"
74 };
75 
TestCallBack(VibratorStatusEvent * deviceInfo)76 void TestCallBack(VibratorStatusEvent *deviceInfo)
77 {
78     return;
79 }
80 
81 constexpr VibratorUser testUser = {
82     .callback = TestCallBack,
83 };
84 } // namespace
85 
86 class VibratorAgentTest : public testing::Test {
87 public:
88     static void SetUpTestCase();
89     static void TearDownTestCase();
90     void SetUp();
91     void TearDown();
92 
93 private:
94     static AccessTokenID tokenID_;
95 };
96 
97 struct FileDescriptor {
FileDescriptorOHOS::Sensors::FileDescriptor98     explicit FileDescriptor(const std::string &path)
99     {
100         fd = open(path.c_str(), O_RDONLY);
101     }
~FileDescriptorOHOS::Sensors::FileDescriptor102     ~FileDescriptor()
103     {
104         close(fd);
105     }
106     int32_t fd;
107 };
108 
109 AccessTokenID VibratorAgentTest::tokenID_ = 0;
110 
SetUpTestCase()111 void VibratorAgentTest::SetUpTestCase()
112 {
113     AccessTokenIDEx tokenIdEx = {0};
114     tokenIdEx = AccessTokenKit::AllocHapToken(g_infoManagerTestInfoParms, g_infoManagerTestPolicyPrams);
115     tokenID_ = tokenIdEx.tokenIdExStruct.tokenID;
116     ASSERT_NE(0, tokenID_);
117     ASSERT_EQ(0, SetSelfTokenID(tokenID_));
118 }
119 
TearDownTestCase()120 void VibratorAgentTest::TearDownTestCase()
121 {
122     int32_t ret = AccessTokenKit::DeleteToken(tokenID_);
123     if (tokenID_ != 0) {
124         ASSERT_EQ(RET_SUCCESS, ret);
125     }
126 }
127 
SetUp()128 void VibratorAgentTest::SetUp()
129 {}
130 
TearDown()131 void VibratorAgentTest::TearDown()
132 {
133     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_EACH_CASE));
134 }
135 
IsSupportVibratorEffect(const char * effectId)136 bool IsSupportVibratorEffect(const char* effectId)
137 {
138     bool state { false };
139     IsSupportEffect(effectId, &state);
140     return state;
141 }
142 
143 HWTEST_F(VibratorAgentTest, StartVibratorTest_001, TestSize.Level1)
144 {
145     MISC_HILOGI("StartVibratorTest_001 in");
146     bool isSupport = IsSupportVibratorEffect(VIBRATOR_TYPE_CLOCK_TIMER);
147     if (isSupport) {
148         int32_t ret = StartVibrator(VIBRATOR_TYPE_CLOCK_TIMER);
149         ASSERT_EQ(ret, 0);
150     } else {
151         ASSERT_EQ(isSupport, false);
152     }
153 }
154 
155 HWTEST_F(VibratorAgentTest, StartVibratorTest_002, TestSize.Level1)
156 {
157     MISC_HILOGI("StartVibratorTest_002 in");
158     int32_t ret = StartVibrator("");
159     ASSERT_NE(ret, 0);
160 }
161 
162 HWTEST_F(VibratorAgentTest, StartVibratorTest_003, TestSize.Level1)
163 {
164     MISC_HILOGI("StartVibratorTest_003 in");
165     int32_t ret = StartVibrator(nullptr);
166     ASSERT_NE(ret, 0);
167 }
168 
169 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_001, TestSize.Level0)
170 {
171     MISC_HILOGI("StartVibratorOnceTest_001 in");
172     int32_t ret = StartVibratorOnce(300);
173     ASSERT_EQ(ret, 0);
174 }
175 
176 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_002, TestSize.Level1)
177 {
178     MISC_HILOGI("StartVibratorOnceTest_002 in");
179     int32_t ret = StartVibratorOnce(0);
180     ASSERT_NE(ret, 0);
181 }
182 
183 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_003, TestSize.Level1)
184 {
185     MISC_HILOGI("StartVibratorOnceTest_003 in");
186     int32_t ret = StartVibratorOnce(1800000);
187     ASSERT_EQ(ret, 0);
188 }
189 
190 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_004, TestSize.Level1)
191 {
192     MISC_HILOGI("StartVibratorOnceTest_004 in");
193     int32_t ret = StartVibratorOnce(1800001);
194     ASSERT_NE(ret, 0);
195 }
196 
197 HWTEST_F(VibratorAgentTest, StopVibratorTest_001, TestSize.Level1)
198 {
199     MISC_HILOGI("StopVibratorTest_001 in");
200     int32_t ret = StopVibrator("time");
201     ASSERT_EQ(ret, 0);
202 }
203 
204 HWTEST_F(VibratorAgentTest, StopVibratorTest_002, TestSize.Level1)
205 {
206     MISC_HILOGI("StopVibratorTest_002 in");
207     int32_t ret = StopVibrator("preset");
208     ASSERT_EQ(ret, 0);
209 }
210 
211 HWTEST_F(VibratorAgentTest, StopVibratorTest_003, TestSize.Level1)
212 {
213     MISC_HILOGI("StopVibratorTest_003 in");
214     int32_t ret = StopVibrator("");
215     ASSERT_NE(ret, 0);
216 }
217 
218 HWTEST_F(VibratorAgentTest, StopVibratorTest_004, TestSize.Level1)
219 {
220     MISC_HILOGI("StopVibratorTest_004 in");
221     int32_t ret = StopVibrator(nullptr);
222     ASSERT_NE(ret, 0);
223 }
224 
225 HWTEST_F(VibratorAgentTest, StopVibratorTest_005, TestSize.Level1)
226 {
227     MISC_HILOGI("StopVibratorTest_005 in");
228     int32_t ret = StartVibratorOnce(300);
229     ASSERT_EQ(ret, 0);
230     ret = StopVibrator("time");
231     ASSERT_EQ(ret, 0);
232 }
233 
234 HWTEST_F(VibratorAgentTest, SetLoopCount_001, TestSize.Level1)
235 {
236     MISC_HILOGI("SetLoopCount_001 in");
237     bool ret = SetLoopCount(300);
238     ASSERT_TRUE(ret);
239 }
240 
241 HWTEST_F(VibratorAgentTest, SetLoopCount_002, TestSize.Level1)
242 {
243     MISC_HILOGI("SetLoopCount_002 in");
244     bool ret = SetLoopCount(-1);
245     ASSERT_FALSE(ret);
246 }
247 
248 HWTEST_F(VibratorAgentTest, SetLoopCount_003, TestSize.Level1)
249 {
250     MISC_HILOGI("SetLoopCount_003 in");
251     bool ret = SetLoopCount(0);
252     ASSERT_FALSE(ret);
253 }
254 
255 HWTEST_F(VibratorAgentTest, SetUsage_001, TestSize.Level1)
256 {
257     MISC_HILOGI("SetUsage_001 in");
258     bool ret = SetUsage(0);
259     ASSERT_TRUE(ret);
260 }
261 
262 HWTEST_F(VibratorAgentTest, SetUsage_002, TestSize.Level1)
263 {
264     MISC_HILOGI("SetUsage_002 in");
265     bool ret = SetUsage(-1);
266     ASSERT_FALSE(ret);
267 }
268 
269 HWTEST_F(VibratorAgentTest, SetUsage_003, TestSize.Level1)
270 {
271     MISC_HILOGI("SetUsage_003 in");
272     bool ret = SetUsage(USAGE_MAX);
273     ASSERT_FALSE(ret);
274 }
275 
276 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_001, TestSize.Level0)
277 {
278     MISC_HILOGI("PlayVibratorCustom_001 in");
279     bool isSupport = IsSupportVibratorCustom();
280     if (isSupport) {
281         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
282         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
283         struct stat64 statbuf = { 0 };
284         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
285             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
286             ASSERT_EQ(ret, 0);
287         }
288         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
289     } else {
290         ASSERT_EQ(isSupport, false);
291     }
292     Cancel();
293 }
294 
295 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_002, TestSize.Level1)
296 {
297     MISC_HILOGI("PlayVibratorCustom_002 in");
298     bool isSupport = IsSupportVibratorCustom();
299     if (isSupport) {
300         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
301         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
302         struct stat64 statbuf = { 0 };
303         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
304             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
305             ASSERT_EQ(ret, 0);
306         }
307         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
308     } else {
309         ASSERT_EQ(isSupport, false);
310     }
311     Cancel();
312 }
313 
314 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_003, TestSize.Level1)
315 {
316     MISC_HILOGI("PlayVibratorCustom_003 in");
317     bool isSupport = (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL));
318     if (isSupport) {
319         bool flag = SetLoopCount(2);
320         ASSERT_TRUE(flag);
321         int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
322         ASSERT_EQ(ret, 0);
323         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
324         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
325         struct stat64 statbuf = { 0 };
326         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
327             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
328             ASSERT_NE(ret, 0);
329         }
330         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
331     } else {
332         ASSERT_EQ(isSupport, false);
333     }
334     Cancel();
335 }
336 
337 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_004, TestSize.Level1)
338 {
339     MISC_HILOGI("PlayVibratorCustom_004 in");
340     bool isSupport = (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL));
341     if (isSupport) {
342         bool flag = SetUsage(USAGE_ALARM);
343         ASSERT_TRUE(flag);
344         int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
345         ASSERT_EQ(ret, 0);
346         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
347         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
348         struct stat64 statbuf = { 0 };
349         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
350             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
351             ASSERT_NE(ret, 0);
352         }
353         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
354     } else {
355         ASSERT_EQ(isSupport, false);
356     }
357     Cancel();
358 }
359 
360 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_005, TestSize.Level1)
361 {
362     MISC_HILOGI("PlayVibratorCustom_005 in");
363     bool isSupport = (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL));
364     if (isSupport) {
365         bool flag = SetUsage(USAGE_UNKNOWN);
366         ASSERT_TRUE(flag);
367         int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
368         ASSERT_EQ(ret, 0);
369         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
370         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
371         struct stat64 statbuf = { 0 };
372         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
373             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
374             ASSERT_EQ(ret, 0);
375         }
376         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
377     } else {
378         ASSERT_EQ(isSupport, false);
379     }
380     Cancel();
381 }
382 
383 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_006, TestSize.Level1)
384 {
385     MISC_HILOGI("PlayVibratorCustom_006 in");
386     bool isSupport = (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL));
387     if (isSupport) {
388         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
389         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
390         struct stat64 statbuf = { 0 };
391         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
392             bool flag = SetUsage(USAGE_ALARM);
393             ASSERT_TRUE(flag);
394             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
395             ASSERT_EQ(ret, 0);
396             ret = StartVibrator(VIBRATOR_TYPE_FAIL);
397             ASSERT_NE(ret, 0);
398         }
399         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
400     } else {
401         ASSERT_EQ(isSupport, false);
402     }
403     Cancel();
404 }
405 
406 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_007, TestSize.Level1)
407 {
408     MISC_HILOGI("PlayVibratorCustom_007 in");
409     bool isSupport = (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL));
410     if (isSupport) {
411         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
412         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
413         struct stat64 statbuf = { 0 };
414         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
415             bool flag = SetUsage(USAGE_UNKNOWN);
416             ASSERT_TRUE(flag);
417             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
418             ASSERT_EQ(ret, 0);
419             ret = StartVibrator(VIBRATOR_TYPE_FAIL);
420             ASSERT_EQ(ret, 0);
421         }
422         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
423     } else {
424         ASSERT_EQ(isSupport, false);
425     }
426     Cancel();
427 }
428 
429 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_008, TestSize.Level1)
430 {
431     MISC_HILOGI("PlayVibratorCustom_008 in");
432     bool isSupport = IsSupportVibratorCustom();
433     if (isSupport) {
434         bool flag = SetUsage(USAGE_ALARM);
435         ASSERT_TRUE(flag);
436         int32_t ret = StartVibratorOnce(500);
437         ASSERT_EQ(ret, 0);
438         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
439         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
440         struct stat64 statbuf = { 0 };
441         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
442             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
443             ASSERT_NE(ret, 0);
444         }
445         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
446     } else {
447         ASSERT_EQ(isSupport, false);
448     }
449     Cancel();
450 }
451 
452 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_009, TestSize.Level1)
453 {
454     MISC_HILOGI("PlayVibratorCustom_009 in");
455     bool isSupport = IsSupportVibratorCustom();
456     if (isSupport) {
457         bool flag = SetUsage(USAGE_UNKNOWN);
458         ASSERT_TRUE(flag);
459         int32_t ret = StartVibratorOnce(500);
460         ASSERT_EQ(ret, 0);
461         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
462         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
463         struct stat64 statbuf = { 0 };
464         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
465             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
466             ASSERT_EQ(ret, 0);
467         }
468         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
469     } else {
470         ASSERT_EQ(isSupport, false);
471     }
472     Cancel();
473 }
474 
475 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_010, TestSize.Level1)
476 {
477     MISC_HILOGI("PlayVibratorCustom_010 in");
478     bool isSupport = IsSupportVibratorCustom();
479     if (isSupport) {
480         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
481         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
482         struct stat64 statbuf = { 0 };
483         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
484             bool flag = SetUsage(USAGE_ALARM);
485             ASSERT_TRUE(flag);
486             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
487             ASSERT_EQ(ret, 0);
488             ret = StartVibratorOnce(500);
489             ASSERT_NE(ret, 0);
490         }
491         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
492     } else {
493         ASSERT_EQ(isSupport, false);
494     }
495     Cancel();
496 }
497 
498 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_011, TestSize.Level1)
499 {
500     MISC_HILOGI("PlayVibratorCustom_011 in");
501     bool isSupport = IsSupportVibratorCustom();
502     if (isSupport) {
503         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
504         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
505         struct stat64 statbuf = { 0 };
506         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
507             bool flag = SetUsage(USAGE_UNKNOWN);
508             ASSERT_TRUE(flag);
509             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
510             ASSERT_EQ(ret, 0);
511             ret = StartVibratorOnce(500);
512             ASSERT_EQ(ret, 0);
513         }
514         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
515     } else {
516         ASSERT_EQ(isSupport, false);
517     }
518     Cancel();
519 }
520 
521 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_012, TestSize.Level1)
522 {
523     MISC_HILOGI("PlayVibratorCustom_012 in");
524     bool isSupport = IsSupportVibratorCustom();
525     if (isSupport) {
526         FileDescriptor fileDescriptor("/data/test/vibrator/test_128_event.json");
527         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
528         struct stat64 statbuf = { 0 };
529         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
530             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
531             ASSERT_EQ(ret, 0);
532         }
533         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
534     } else {
535         ASSERT_EQ(isSupport, false);
536     }
537     Cancel();
538 }
539 
540 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_013, TestSize.Level1)
541 {
542     MISC_HILOGI("PlayVibratorCustom_013 in");
543     bool isSupport = IsSupportVibratorCustom();
544     if (isSupport) {
545         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_type.json");
546         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
547         struct stat64 statbuf = { 0 };
548         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
549             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
550             ASSERT_NE(ret, 0);
551         }
552     } else {
553         ASSERT_EQ(isSupport, false);
554     }
555 }
556 
557 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_014, TestSize.Level1)
558 {
559     MISC_HILOGI("PlayVibratorCustom_014 in");
560     bool isSupport = IsSupportVibratorCustom();
561     if (isSupport) {
562         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_startTime.json");
563         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
564         struct stat64 statbuf = { 0 };
565         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
566             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
567             ASSERT_NE(ret, 0);
568         }
569     } else {
570         ASSERT_EQ(isSupport, false);
571     }
572 }
573 
574 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_015, TestSize.Level1)
575 {
576     MISC_HILOGI("PlayVibratorCustom_015 in");
577     bool isSupport = IsSupportVibratorCustom();
578     if (isSupport) {
579         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_duration.json");
580         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
581         struct stat64 statbuf = { 0 };
582         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
583             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
584             ASSERT_NE(ret, 0);
585         }
586     } else {
587         ASSERT_EQ(isSupport, false);
588     }
589 }
590 
591 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_016, TestSize.Level1)
592 {
593     MISC_HILOGI("PlayVibratorCustom_016 in");
594     bool isSupport = IsSupportVibratorCustom();
595     if (isSupport) {
596         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_intensity.json");
597         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
598         struct stat64 statbuf = { 0 };
599         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
600             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
601             ASSERT_NE(ret, 0);
602         }
603     } else {
604         ASSERT_EQ(isSupport, false);
605     }
606 }
607 
608 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_017, TestSize.Level1)
609 {
610     MISC_HILOGI("PlayVibratorCustom_017 in");
611     bool isSupport = IsSupportVibratorCustom();
612     if (isSupport) {
613         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_frequency.json");
614         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
615         struct stat64 statbuf = { 0 };
616         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
617             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
618             ASSERT_NE(ret, 0);
619         }
620     } else {
621         ASSERT_EQ(isSupport, false);
622     }
623 }
624 
625 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_018, TestSize.Level1)
626 {
627     MISC_HILOGI("PlayVibratorCustom_018 in");
628     bool isSupport = IsSupportVibratorCustom();
629     if (isSupport) {
630         FileDescriptor fileDescriptor("/data/test/vibrator/test_129_event.json");
631         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
632         struct stat64 statbuf = { 0 };
633         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
634             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
635             ASSERT_NE(ret, 0);
636         }
637     } else {
638         ASSERT_EQ(isSupport, false);
639     }
640 }
641 
642 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_019, TestSize.Level1)
643 {
644     MISC_HILOGI("PlayVibratorCustom_019 in");
645     bool isSupport = IsSupportVibratorCustom();
646     if (isSupport) {
647         FileDescriptor fileDescriptor("/data/test/vibrator/test_big_file_size.json");
648         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
649         struct stat64 statbuf = { 0 };
650         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
651             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
652             ASSERT_NE(ret, 0);
653         }
654     } else {
655         ASSERT_EQ(isSupport, false);
656     }
657 }
658 
659 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_020, TestSize.Level1)
660 {
661     MISC_HILOGI("PlayVibratorCustom_020 in");
662     bool isSupport = IsSupportVibratorCustom();
663     if (isSupport) {
664         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_1.json");
665         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
666         struct stat64 statbuf = { 0 };
667         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
668             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
669             ASSERT_EQ(ret, 0);
670         }
671     } else {
672         ASSERT_EQ(isSupport, false);
673     }
674     Cancel();
675 }
676 
677 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_021, TestSize.Level1)
678 {
679     MISC_HILOGI("PlayVibratorCustom_021 in");
680     bool isSupport = IsSupportVibratorCustom();
681     if (isSupport) {
682         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_2.json");
683         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
684         struct stat64 statbuf = { 0 };
685         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
686             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
687             ASSERT_EQ(ret, 0);
688         }
689     } else {
690         ASSERT_EQ(isSupport, false);
691     }
692     Cancel();
693 }
694 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_022, TestSize.Level1)
695 {
696     MISC_HILOGI("PlayVibratorCustom_022 in");
697     bool isSupport = IsSupportVibratorCustom();
698     if (isSupport) {
699         FileDescriptor fileDescriptor("/data/test/vibrator/Jet_N2O.he");
700         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
701         struct stat64 statbuf = { 0 };
702         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
703             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
704             ASSERT_EQ(ret, 0);
705         }
706         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
707     } else {
708         ASSERT_EQ(isSupport, false);
709     }
710     Cancel();
711 }
712 
713 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_023, TestSize.Level1)
714 {
715     MISC_HILOGI("PlayVibratorCustom_023 in");
716     bool isSupport = IsSupportVibratorCustom();
717     if (isSupport) {
718         FileDescriptor fileDescriptor("/data/test/vibrator/Racing_Start.he");
719         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
720         struct stat64 statbuf = { 0 };
721         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
722             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
723             ASSERT_EQ(ret, 0);
724         }
725         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
726     } else {
727         ASSERT_EQ(isSupport, false);
728     }
729     Cancel();
730 }
731 
732 HWTEST_F(VibratorAgentTest, SetParameters_001, TestSize.Level1)
733 {
734     MISC_HILOGI("SetParameters_001 in");
735     VibratorParameter parameter = {
736         .intensity = -1,
737         .frequency = -15
738     };
739     bool ret = SetParameters(parameter);
740     ASSERT_FALSE(ret);
741 }
742 
743 HWTEST_F(VibratorAgentTest, SetParameters_002, TestSize.Level1)
744 {
745     MISC_HILOGI("SetParameters_002 in");
746     VibratorParameter parameter = {
747         .intensity = 70,
748         .frequency = 150
749     };
750     bool ret = SetParameters(parameter);
751     ASSERT_FALSE(ret);
752 }
753 
754 HWTEST_F(VibratorAgentTest, SetParameters_003, TestSize.Level1)
755 {
756     MISC_HILOGI("SetParameters_003 in");
757     bool isSupport = IsSupportVibratorCustom();
758     if (isSupport) {
759         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
760         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
761         struct stat64 statbuf = { 0 };
762         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
763             VibratorParameter parameter = {
764                 .intensity = 50,
765                 .frequency = -15
766             };
767             bool flag = SetParameters(parameter);
768             ASSERT_TRUE(flag);
769             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
770             ASSERT_EQ(ret, 0);
771         }
772         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
773     } else {
774         ASSERT_EQ(isSupport, false);
775     }
776     Cancel();
777 }
778 
779 HWTEST_F(VibratorAgentTest, SetParameters_004, TestSize.Level1)
780 {
781     MISC_HILOGI("SetParameters_004 in");
782     bool isSupport = IsSupportVibratorCustom();
783     if (isSupport) {
784         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
785         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
786         struct stat64 statbuf = { 0 };
787         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
788             VibratorParameter parameter = {
789                 .intensity = 33,
790                 .frequency = 55
791             };
792             bool flag = SetParameters(parameter);
793             ASSERT_TRUE(flag);
794             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
795             ASSERT_EQ(ret, 0);
796         }
797         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
798     } else {
799         ASSERT_EQ(isSupport, false);
800     }
801     Cancel();
802 }
803 
804 HWTEST_F(VibratorAgentTest, Cancel_001, TestSize.Level1)
805 {
806     MISC_HILOGI("Cancel_001 in");
807     int32_t ret = Cancel();
808     ASSERT_EQ(ret, 0);
809 }
810 
811 HWTEST_F(VibratorAgentTest, Cancel_002, TestSize.Level1)
812 {
813     MISC_HILOGI("Cancel_002 in");
814     bool isSupport = IsSupportVibratorCustom();
815     if (isSupport) {
816         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
817         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
818         struct stat64 statbuf = { 0 };
819         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
820             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
821             ASSERT_EQ(ret, 0);
822             ret = Cancel();
823             ASSERT_EQ(ret, 0);
824         }
825     } else {
826         ASSERT_EQ(isSupport, false);
827     }
828 }
829 
830 HWTEST_F(VibratorAgentTest, Cancel_003, TestSize.Level1)
831 {
832     MISC_HILOGI("Cancel_003 in");
833     int32_t ret = StartVibratorOnce(500);
834     ASSERT_EQ(ret, 0);
835     ret = Cancel();
836     ASSERT_EQ(ret, 0);
837 }
838 
839 HWTEST_F(VibratorAgentTest, Cancel_004, TestSize.Level1)
840 {
841     MISC_HILOGI("Cancel_004 in");
842     if (IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL)) {
843         int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
844         ASSERT_EQ(ret, 0);
845         ret = Cancel();
846         ASSERT_EQ(ret, 0);
847     }
848     ASSERT_TRUE(true);
849 }
850 
851 HWTEST_F(VibratorAgentTest, IsSupportEffect_001, TestSize.Level1)
852 {
853     MISC_HILOGI("IsSupportEffect_001 in");
854     bool state { false };
855     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_CLOCK_TIMER, &state);
856     ASSERT_EQ(ret, 0);
857     if (state) {
858         ret = StartVibrator(VIBRATOR_TYPE_CLOCK_TIMER);
859         ASSERT_EQ(ret, 0);
860         Cancel();
861     } else {
862         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_CLOCK_TIMER);
863     }
864 }
865 
866 HWTEST_F(VibratorAgentTest, IsSupportEffect_002, TestSize.Level1)
867 {
868     MISC_HILOGI("IsSupportEffect_002 in");
869     bool state { false };
870     int32_t ret = IsSupportEffect("haptic.xxx.yyy", &state);
871     ASSERT_EQ(ret, 0);
872     ASSERT_FALSE(state);
873 }
874 
875 HWTEST_F(VibratorAgentTest, IsSupportEffect_003, TestSize.Level1)
876 {
877     MISC_HILOGI("IsSupportEffect_003 in");
878     bool state { false };
879     int32_t ret = IsSupportEffect(nullptr, &state);
880     ASSERT_NE(ret, 0);
881     ASSERT_FALSE(state);
882 }
883 
884 HWTEST_F(VibratorAgentTest, IsSupportEffect_004, TestSize.Level1)
885 {
886     MISC_HILOGI("IsSupportEffect_004 in");
887     bool state { false };
888     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_FAIL, &state);
889     ASSERT_EQ(ret, 0);
890     if (state) {
891         ret = StartVibrator(VIBRATOR_TYPE_FAIL);
892         ASSERT_EQ(ret, 0);
893         Cancel();
894     } else {
895         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_FAIL);
896     }
897 }
898 
899 HWTEST_F(VibratorAgentTest, IsSupportEffect_005, TestSize.Level1)
900 {
901     MISC_HILOGI("IsSupportEffect_005 in");
902     bool state { false };
903     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_CHARGING, &state);
904     ASSERT_EQ(ret, 0);
905     if (state) {
906         ret = StartVibrator(VIBRATOR_TYPE_CHARGING);
907         ASSERT_EQ(ret, 0);
908         Cancel();
909     } else {
910         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_CHARGING);
911     }
912 }
913 
914 HWTEST_F(VibratorAgentTest, IsSupportEffect_006, TestSize.Level1)
915 {
916     MISC_HILOGI("IsSupportEffect_006 in");
917     bool state { false };
918     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_LONG_PRESS_HEAVY, &state);
919     ASSERT_EQ(ret, 0);
920     if (state) {
921         ret = StartVibrator(VIBRATOR_TYPE_LONG_PRESS_HEAVY);
922         ASSERT_EQ(ret, 0);
923         Cancel();
924     } else {
925         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_HEAVY);
926     }
927 }
928 
929 HWTEST_F(VibratorAgentTest, IsSupportEffect_007, TestSize.Level1)
930 {
931     MISC_HILOGI("IsSupportEffect_007 in");
932     bool state { false };
933     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_LONG_PRESS_LIGHT, &state);
934     ASSERT_EQ(ret, 0);
935     if (state) {
936         ret = StartVibrator(VIBRATOR_TYPE_LONG_PRESS_LIGHT);
937         ASSERT_EQ(ret, 0);
938         Cancel();
939     } else {
940         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_LIGHT);
941     }
942 }
943 
944 HWTEST_F(VibratorAgentTest, IsSupportEffect_008, TestSize.Level1)
945 {
946     MISC_HILOGI("IsSupportEffect_008 in");
947     bool state { false };
948     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_LONG_PRESS_MEDIUM, &state);
949     ASSERT_EQ(ret, 0);
950     if (state) {
951         ret = StartVibrator(VIBRATOR_TYPE_LONG_PRESS_MEDIUM);
952         ASSERT_EQ(ret, 0);
953         Cancel();
954     } else {
955         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_MEDIUM);
956     }
957 }
958 
959 HWTEST_F(VibratorAgentTest, IsSupportEffect_009, TestSize.Level1)
960 {
961     MISC_HILOGI("IsSupportEffect_009 in");
962     bool state { false };
963     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE_LIGHT, &state);
964     ASSERT_EQ(ret, 0);
965     if (state) {
966         ret = StartVibrator(VIBRATOR_TYPE_SLIDE_LIGHT);
967         ASSERT_EQ(ret, 0);
968         Cancel();
969     } else {
970         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE_LIGHT);
971     }
972 }
973 
974 HWTEST_F(VibratorAgentTest, IsSupportEffect_010, TestSize.Level1)
975 {
976     MISC_HILOGI("IsSupportEffect_010 in");
977     bool state { false };
978     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_THRESHOID, &state);
979     ASSERT_EQ(ret, 0);
980     if (state) {
981         ret = StartVibrator(VIBRATOR_TYPE_THRESHOID);
982         ASSERT_EQ(ret, 0);
983         Cancel();
984     } else {
985         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_THRESHOID);
986     }
987 }
988 
989 HWTEST_F(VibratorAgentTest, GetDelayTime_001, TestSize.Level1)
990 {
991     MISC_HILOGI("GetDelayTime_001 in");
992     bool isSupport = IsSupportVibratorCustom();
993     if (isSupport) {
994         int32_t delayTime { -1 };
995         int32_t ret = GetDelayTime(delayTime);
996         ASSERT_EQ(ret, 0);
997     } else {
998         ASSERT_EQ(isSupport, false);
999     }
1000 }
1001 
1002 HWTEST_F(VibratorAgentTest, PreProcess_001, TestSize.Level1)
1003 {
1004     MISC_HILOGI("PreProcess_001 in");
1005     bool isSupport = IsSupportVibratorCustom();
1006     if (isSupport) {
1007         FileDescriptor fileDescriptor("invalid_file_name");
1008         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1009         VibratorFileDescription vfd;
1010         VibratorPackage package;
1011         struct stat64 statbuf = { 0 };
1012         bool ret = fstat64(fileDescriptor.fd, &statbuf);
1013         if (ret) {
1014             vfd.fd = fileDescriptor.fd;
1015             vfd.offset = 0;
1016             vfd.length = statbuf.st_size;
1017             ret = PreProcess(vfd, package);
1018             ASSERT_NE(ret, 0);
1019             ret = FreeVibratorPackage(package);
1020             ASSERT_NE(ret, 0);
1021         } else {
1022             ASSERT_EQ(isSupport, false);
1023         }
1024     } else {
1025         ASSERT_EQ(isSupport, false);
1026     }
1027 }
1028 
1029 HWTEST_F(VibratorAgentTest, PreProcess_002, TestSize.Level1)
1030 {
1031     MISC_HILOGI("PreProcess_002 in");
1032     bool isSupport = IsSupportVibratorCustom();
1033     if (isSupport) {
1034         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_duration.json");
1035         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1036         VibratorFileDescription vfd;
1037         VibratorPackage package;
1038         struct stat64 statbuf = { 0 };
1039         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1040             vfd.fd = fileDescriptor.fd;
1041             vfd.offset = 0;
1042             vfd.length = statbuf.st_size;
1043             int32_t ret = PreProcess(vfd, package);
1044             ASSERT_NE(ret, 0);
1045             ret = FreeVibratorPackage(package);
1046             ASSERT_NE(ret, 0);
1047         } else {
1048             ASSERT_FALSE(true);
1049         }
1050     } else {
1051         ASSERT_EQ(isSupport, false);
1052     }
1053 }
1054 
1055 HWTEST_F(VibratorAgentTest, PreProcess_003, TestSize.Level1)
1056 {
1057     MISC_HILOGI("PreProcess_003 in");
1058     bool isSupport = IsSupportVibratorCustom();
1059     if (isSupport) {
1060         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_frequency.json");
1061         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1062         VibratorFileDescription vfd;
1063         VibratorPackage package;
1064         struct stat64 statbuf = { 0 };
1065         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1066             vfd.fd = fileDescriptor.fd;
1067             vfd.offset = 0;
1068             vfd.length = statbuf.st_size;
1069             int32_t ret = PreProcess(vfd, package);
1070             ASSERT_NE(ret, 0);
1071             ret = FreeVibratorPackage(package);
1072             ASSERT_NE(ret, 0);
1073         } else {
1074             ASSERT_FALSE(true);
1075         }
1076     } else {
1077         ASSERT_EQ(isSupport, false);
1078     }
1079 }
1080 
1081 HWTEST_F(VibratorAgentTest, PreProcess_004, TestSize.Level1)
1082 {
1083     MISC_HILOGI("PreProcess_004 in");
1084     bool isSupport = IsSupportVibratorCustom();
1085     if (isSupport) {
1086         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_intensity.json");
1087         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1088         VibratorFileDescription vfd;
1089         VibratorPackage package;
1090         struct stat64 statbuf = { 0 };
1091         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1092             vfd.fd = fileDescriptor.fd;
1093             vfd.offset = 0;
1094             vfd.length = statbuf.st_size;
1095             int32_t ret = PreProcess(vfd, package);
1096             ASSERT_NE(ret, 0);
1097             ret = FreeVibratorPackage(package);
1098             ASSERT_NE(ret, 0);
1099         } else {
1100             ASSERT_FALSE(true);
1101         }
1102     } else {
1103         ASSERT_EQ(isSupport, false);
1104     }
1105 }
1106 
1107 HWTEST_F(VibratorAgentTest, PreProcess_005, TestSize.Level1)
1108 {
1109     MISC_HILOGI("PreProcess_005 in");
1110     bool isSupport = IsSupportVibratorCustom();
1111     if (isSupport) {
1112         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_startTime.json");
1113         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1114         VibratorFileDescription vfd;
1115         VibratorPackage package;
1116         struct stat64 statbuf = { 0 };
1117         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1118             vfd.fd = fileDescriptor.fd;
1119             vfd.offset = 0;
1120             vfd.length = statbuf.st_size;
1121             int32_t ret = PreProcess(vfd, package);
1122             ASSERT_NE(ret, 0);
1123             ret = FreeVibratorPackage(package);
1124             ASSERT_NE(ret, 0);
1125         } else {
1126             ASSERT_FALSE(true);
1127         }
1128     } else {
1129         ASSERT_EQ(isSupport, false);
1130     }
1131 }
1132 
1133 HWTEST_F(VibratorAgentTest, PreProcess_006, TestSize.Level1)
1134 {
1135     MISC_HILOGI("PreProcess_006 in");
1136     bool isSupport = IsSupportVibratorCustom();
1137     if (isSupport) {
1138         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_type.json");
1139         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1140         VibratorFileDescription vfd;
1141         VibratorPackage package;
1142         struct stat64 statbuf = { 0 };
1143         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1144             vfd.fd = fileDescriptor.fd;
1145             vfd.offset = 0;
1146             vfd.length = statbuf.st_size;
1147             int32_t ret = PreProcess(vfd, package);
1148             ASSERT_NE(ret, 0);
1149             ret = FreeVibratorPackage(package);
1150             ASSERT_NE(ret, 0);
1151         } else {
1152             ASSERT_FALSE(true);
1153         }
1154     } else {
1155         ASSERT_EQ(isSupport, false);
1156     }
1157 }
1158 
1159 HWTEST_F(VibratorAgentTest, PreProcess_007, TestSize.Level1)
1160 {
1161     MISC_HILOGI("PreProcess_007 in");
1162     bool isSupport = IsSupportVibratorCustom();
1163     if (isSupport) {
1164         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_1.json");
1165         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1166         VibratorFileDescription vfd;
1167         VibratorPackage package;
1168         struct stat64 statbuf = { 0 };
1169         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1170             vfd.fd = fileDescriptor.fd;
1171             vfd.offset = 0;
1172             vfd.length = statbuf.st_size;
1173             int32_t ret = PreProcess(vfd, package);
1174             ASSERT_EQ(ret, 0);
1175             ret = FreeVibratorPackage(package);
1176             ASSERT_EQ(ret, 0);
1177         } else {
1178             ASSERT_FALSE(true);
1179         }
1180     } else {
1181         ASSERT_EQ(isSupport, false);
1182     }
1183 }
1184 
1185 HWTEST_F(VibratorAgentTest, PreProcess_008, TestSize.Level1)
1186 {
1187     MISC_HILOGI("PreProcess_008 in");
1188     bool isSupport = IsSupportVibratorCustom();
1189     if (isSupport) {
1190         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_2.json");
1191         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1192         VibratorFileDescription vfd;
1193         VibratorPackage package;
1194         struct stat64 statbuf = { 0 };
1195         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1196             vfd.fd = fileDescriptor.fd;
1197             vfd.offset = 0;
1198             vfd.length = statbuf.st_size;
1199             int32_t ret = PreProcess(vfd, package);
1200             ASSERT_EQ(ret, 0);
1201             ret = FreeVibratorPackage(package);
1202             ASSERT_EQ(ret, 0);
1203         } else {
1204             ASSERT_FALSE(true);
1205         }
1206     } else {
1207         ASSERT_EQ(isSupport, false);
1208     }
1209 }
1210 
1211 HWTEST_F(VibratorAgentTest, PreProcess_009, TestSize.Level1)
1212 {
1213     MISC_HILOGI("PreProcess_009 in");
1214     bool isSupport = IsSupportVibratorCustom();
1215     if (isSupport) {
1216         FileDescriptor fileDescriptor("/data/test/vibrator/test_129_event.json");
1217         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1218         VibratorFileDescription vfd;
1219         VibratorPackage package;
1220         struct stat64 statbuf = { 0 };
1221         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1222             vfd.fd = fileDescriptor.fd;
1223             vfd.offset = 0;
1224             vfd.length = statbuf.st_size;
1225             int32_t ret = PreProcess(vfd, package);
1226             ASSERT_NE(ret, 0);
1227             ret = FreeVibratorPackage(package);
1228             ASSERT_NE(ret, 0);
1229         } else {
1230             ASSERT_FALSE(true);
1231         }
1232     } else {
1233         ASSERT_EQ(isSupport, false);
1234     }
1235 }
1236 
1237 HWTEST_F(VibratorAgentTest, PlayPattern_001, TestSize.Level1)
1238 {
1239     MISC_HILOGI("PlayPattern_001 in");
1240     bool isSupport = IsSupportVibratorCustom();
1241     if (isSupport) {
1242         int32_t delayTime { -1 };
1243         int32_t ret = GetDelayTime(delayTime);
1244         ASSERT_EQ(ret, 0);
1245         MISC_HILOGD("delayTime:%{public}d", delayTime);
1246         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
1247         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1248         VibratorFileDescription vfd;
1249         VibratorPackage package;
1250         struct stat64 statbuf = { 0 };
1251         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1252             vfd.fd = fileDescriptor.fd;
1253             vfd.offset = 0;
1254             vfd.length = statbuf.st_size;
1255             ret = PreProcess(vfd, package);
1256             ASSERT_EQ(ret, 0);
1257             for (int32_t i = 0; i < package.patternNum; ++i) {
1258                 if (i == 0) {
1259                     std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time));
1260                 } else {
1261                     std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time) -
1262                         std::chrono::milliseconds(package.patterns[i - 1].time));
1263                 }
1264                 ASSERT_EQ(SetUsage(USAGE_UNKNOWN), true);
1265                 MISC_HILOGD("pointNum:%{public}d", package.patterns[i].events[i].pointNum);
1266                 ret = PlayPattern(package.patterns[i]);
1267                 ASSERT_EQ(ret, 0);
1268             }
1269         }
1270         ret = FreeVibratorPackage(package);
1271         ASSERT_EQ(ret, 0);
1272         Cancel();
1273     } else {
1274         ASSERT_EQ(isSupport, false);
1275     }
1276 }
1277 
1278 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_001, TestSize.Level1)
1279 {
1280     MISC_HILOGI("PlayPrimitiveEffect_001 in");
1281     int32_t ret = PlayPrimitiveEffect(nullptr, INTENSITY_HIGH);
1282     ASSERT_EQ(ret, PARAMETER_ERROR);
1283 }
1284 
1285 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_002, TestSize.Level1)
1286 {
1287     MISC_HILOGI("PlayPrimitiveEffect_002 in");
1288     bool state { false };
1289     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1290     ASSERT_EQ(ret, 0);
1291     if (state) {
1292         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_INVALID);
1293         ASSERT_EQ(ret, PARAMETER_ERROR);
1294     } else {
1295         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1296     }
1297 }
1298 
1299 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_003, TestSize.Level1)
1300 {
1301     MISC_HILOGI("PlayPrimitiveEffect_003 in");
1302     bool state { false };
1303     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1304     ASSERT_EQ(ret, 0);
1305     if (state) {
1306         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_LOW);
1307         ASSERT_EQ(ret, 0);
1308         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1309         Cancel();
1310     } else {
1311         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1312     }
1313 }
1314 
1315 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_004, TestSize.Level1)
1316 {
1317     MISC_HILOGI("PlayPrimitiveEffect_004 in");
1318     bool state { false };
1319     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1320     ASSERT_EQ(ret, 0);
1321     if (state) {
1322         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_MEDIUM);
1323         ASSERT_EQ(ret, 0);
1324         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1325         Cancel();
1326     } else {
1327         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1328     }
1329 }
1330 
1331 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_005, TestSize.Level1)
1332 {
1333     MISC_HILOGI("PlayPrimitiveEffect_005 in");
1334     bool state { false };
1335     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1336     ASSERT_EQ(ret, 0);
1337     if (state) {
1338         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_HIGH);
1339         ASSERT_EQ(ret, 0);
1340         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1341         Cancel();
1342     } else {
1343         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1344     }
1345 }
1346 
1347 HWTEST_F(VibratorAgentTest, IsHdHapticSupported_001, TestSize.Level1)
1348 {
1349     MISC_HILOGI("IsHdHapticSupported_001 in");
1350     bool isSupport = (IsSupportVibratorCustom() && IsHdHapticSupported());
1351     if (isSupport) {
1352         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
1353         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1354         struct stat64 statbuf = { 0 };
1355         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1356             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
1357             ASSERT_EQ(ret, 0);
1358         }
1359         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1360     } else {
1361         ASSERT_EQ(isSupport, false);
1362     }
1363     Cancel();
1364 }
1365 
1366 HWTEST_F(VibratorAgentTest, StartVibratorUseNotifactionTest, TestSize.Level1)
1367 {
1368     MISC_HILOGI("StartVibratorUseNotifactionTest in");
1369     bool flag = SetUsage(USAGE_UNKNOWN);
1370     ASSERT_TRUE(flag);
1371     bool isSupport = false;
1372     ASSERT_EQ(IsSupportEffect(VIBRATOR_TYPE_FAIL, &isSupport), 0);
1373     if (!isSupport) {
1374         MISC_HILOGW("effect %{public}s is not supported, skip test case StartVibratorUseNotifactionTest",
1375             VIBRATOR_TYPE_FAIL);
1376         return;
1377     }
1378     int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
1379     ASSERT_EQ(ret, SUCCESS);
1380     flag = SetUsage(USAGE_NOTIFICATION);
1381     ASSERT_TRUE(flag);
1382     ret = StartVibrator(VIBRATOR_TYPE_FAIL);
1383     ASSERT_TRUE(ret == SUCCESS || ret == DEVICE_OPERATION_FAILED);
1384     Cancel();
1385 }
1386 
1387 HWTEST_F(VibratorAgentTest, StartVibratorUseRingTest, TestSize.Level1)
1388 {
1389     MISC_HILOGI("StartVibratorUseRingTest in");
1390     bool flag = SetUsage(USAGE_UNKNOWN);
1391     ASSERT_TRUE(flag);
1392     bool isSupport = false;
1393     ASSERT_EQ(IsSupportEffect(VIBRATOR_TYPE_FAIL, &isSupport), 0);
1394     if (!isSupport) {
1395         MISC_HILOGW("effect %{public}s is not supported, skip test case StartVibratorUseRingTest",
1396             VIBRATOR_TYPE_FAIL);
1397         return;
1398     }
1399     int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
1400     ASSERT_EQ(ret, SUCCESS);
1401     flag = SetUsage(USAGE_RING);
1402     ASSERT_TRUE(flag);
1403     ret = StartVibrator(VIBRATOR_TYPE_FAIL);
1404     ASSERT_TRUE(ret == SUCCESS || ret == DEVICE_OPERATION_FAILED);
1405     Cancel();
1406 }
1407 
1408 HWTEST_F(VibratorAgentTest, GetVibrateModeTest, TestSize.Level1)
1409 {
1410     MISC_HILOGI("GetVibrateModeTest in");
1411     VibratorCapacity vibrateCapacity;
1412     int32_t mode = vibrateCapacity.GetVibrateMode();
1413     ASSERT_EQ(mode, ERROR);
1414     vibrateCapacity.isSupportHdHaptic = true;
1415     mode = vibrateCapacity.GetVibrateMode();
1416     ASSERT_EQ(mode, VIBRATE_MODE_HD);
1417     vibrateCapacity.isSupportHdHaptic = false;
1418     vibrateCapacity.isSupportPresetMapping = true;
1419     mode = vibrateCapacity.GetVibrateMode();
1420     ASSERT_EQ(mode, VIBRATE_MODE_MAPPING);
1421     vibrateCapacity.isSupportHdHaptic = false;
1422     vibrateCapacity.isSupportPresetMapping = false;
1423     vibrateCapacity.isSupportTimeDelay = true;
1424     mode = vibrateCapacity.GetVibrateMode();
1425     ASSERT_EQ(mode, VIBRATE_MODE_TIMES);
1426 }
1427 
1428 HWTEST_F(VibratorAgentTest, VibratePatternTest, TestSize.Level1)
1429 {
1430     MISC_HILOGI("VibratePatternTest in");
1431     VibratePattern vibratePattern;
1432     vibratePattern.startTime = 10;
1433     vibratePattern.patternDuration = 1000;
1434     VibrateEvent vibrateEvent;
1435     vibrateEvent.time = 1;
1436     vibrateEvent.duration = 50;
1437     vibrateEvent.intensity = 98;
1438     vibrateEvent.frequency = 78;
1439     vibrateEvent.index = 0;
1440     vibrateEvent.tag = EVENT_TAG_CONTINUOUS;
1441     VibrateCurvePoint vibrateCurvePoint;
1442     vibrateCurvePoint.time = 1;
1443     vibrateCurvePoint.intensity = 1;
1444     vibrateCurvePoint.frequency = 1;
1445     vibrateEvent.points.push_back(vibrateCurvePoint);
1446     vibratePattern.events.push_back(vibrateEvent);
1447     Parcel data;
1448     bool flag = vibratePattern.Marshalling(data);
1449     ASSERT_EQ(flag, true);
1450     VibratePattern *ret = vibratePattern.Unmarshalling(data);
1451     ASSERT_EQ(ret->startTime, 10);
1452     ASSERT_EQ(ret->patternDuration, 1000);
1453     ret = nullptr;
1454 }
1455 
IsSupportVibratorEffectEnhanced(const VibratorIdentifier identifier,const char * effectId)1456 bool IsSupportVibratorEffectEnhanced(const VibratorIdentifier identifier, const char* effectId)
1457 {
1458     bool state { false };
1459     IsSupportEffectEnhanced(identifier, effectId, &state);
1460     return state;
1461 }
1462 
1463 HWTEST_F(VibratorAgentTest, StartVibratorEnhancedTest_001, TestSize.Level1)
1464 {
1465     MISC_HILOGI("StartVibratorEnhancedTest_001 in");
1466     VibratorIdentifier identifier = {
1467         .deviceId = -1,
1468         .vibratorId = -1,
1469     };
1470     bool isSupport = IsSupportVibratorEffectEnhanced(identifier, VIBRATOR_TYPE_CLOCK_TIMER);
1471     if (isSupport) {
1472         int32_t ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_CLOCK_TIMER);
1473         ASSERT_EQ(ret, 0);
1474     } else {
1475         ASSERT_EQ(isSupport, false);
1476     }
1477 }
1478 
1479 HWTEST_F(VibratorAgentTest, StartVibratorEnhancedTest_002, TestSize.Level1)
1480 {
1481     MISC_HILOGI("StartVibratorEnhancedTest_002 in");
1482     VibratorIdentifier identifier = {
1483         .deviceId = -1,
1484         .vibratorId = -1,
1485     };
1486     int32_t ret = StartVibratorEnhanced(identifier, "");
1487     ASSERT_NE(ret, 0);
1488 }
1489 
1490 HWTEST_F(VibratorAgentTest, StartVibratorEnhancedTest_003, TestSize.Level1)
1491 {
1492     MISC_HILOGI("StartVibratorTest_003 in");
1493     VibratorIdentifier identifier = {
1494         .deviceId = -1,
1495         .vibratorId = -1,
1496     };
1497     int32_t ret = StartVibratorEnhanced(identifier, nullptr);
1498     ASSERT_NE(ret, 0);
1499 }
1500 
1501 HWTEST_F(VibratorAgentTest, StartVibratorOnceEnhancedTest_001, TestSize.Level0)
1502 {
1503     MISC_HILOGI("StartVibratorOnceEnhancedTest_001 in");
1504     VibratorIdentifier identifier = {
1505         .deviceId = -1,
1506         .vibratorId = -1,
1507     };
1508     int32_t ret = StartVibratorOnceEnhanced(identifier, 300);
1509     ASSERT_EQ(ret, 0);
1510 }
1511 
1512 HWTEST_F(VibratorAgentTest, StartVibratorOnceEnhancedTest_002, TestSize.Level1)
1513 {
1514     MISC_HILOGI("StartVibratorOnceEnhancedTest_002 in");
1515     VibratorIdentifier identifier = {
1516         .deviceId = -1,
1517         .vibratorId = -1,
1518     };
1519     int32_t ret = StartVibratorOnceEnhanced(identifier, 0);
1520     ASSERT_NE(ret, 0);
1521 }
1522 
1523 HWTEST_F(VibratorAgentTest, StartVibratorOnceEnhancedTest_003, TestSize.Level1)
1524 {
1525     MISC_HILOGI("StartVibratorOnceEnhancedTest_003 in");
1526     VibratorIdentifier identifier = {
1527         .deviceId = -1,
1528         .vibratorId = -1,
1529     };
1530     int32_t ret = StartVibratorOnceEnhanced(identifier, 1800000);
1531     ASSERT_EQ(ret, 0);
1532 }
1533 
1534 HWTEST_F(VibratorAgentTest, StartVibratorOnceEnhancedTest_004, TestSize.Level1)
1535 {
1536     MISC_HILOGI("StartVibratorOnceEnhancedTest_004 in");
1537     VibratorIdentifier identifier = {
1538         .deviceId = -1,
1539         .vibratorId = -1,
1540     };
1541     int32_t ret = StartVibratorOnceEnhanced(identifier, 1800001);
1542     ASSERT_NE(ret, 0);
1543 }
1544 
1545 HWTEST_F(VibratorAgentTest, StopVibratorEnhancedTest_001, TestSize.Level1)
1546 {
1547     MISC_HILOGI("StopVibratorEnhancedTest_001 in");
1548     VibratorIdentifier identifier = {
1549         .deviceId = -1,
1550         .vibratorId = -1,
1551     };
1552     int32_t ret = StopVibratorEnhanced(identifier, "time");
1553     ASSERT_EQ(ret, 0);
1554 }
1555 
1556 HWTEST_F(VibratorAgentTest, StopVibratorEnhancedTest_002, TestSize.Level1)
1557 {
1558     MISC_HILOGI("StopVibratorEnhancedTest_002 in");
1559     VibratorIdentifier identifier = {
1560         .deviceId = -1,
1561         .vibratorId = -1,
1562     };
1563     int32_t ret = StopVibratorEnhanced(identifier, "preset");
1564     ASSERT_EQ(ret, 0);
1565 }
1566 
1567 HWTEST_F(VibratorAgentTest, StopVibratorEnhancedTest_003, TestSize.Level1)
1568 {
1569     MISC_HILOGI("StopVibratorEnhancedTest_003 in");
1570     VibratorIdentifier identifier = {
1571         .deviceId = -1,
1572         .vibratorId = -1,
1573     };
1574     int32_t ret = StopVibratorEnhanced(identifier, "");
1575     ASSERT_NE(ret, 0);
1576 }
1577 
1578 HWTEST_F(VibratorAgentTest, StopVibratorEnhancedTest_004, TestSize.Level1)
1579 {
1580     MISC_HILOGI("StopVibratorEnhancedTest_004 in");
1581     VibratorIdentifier identifier = {
1582         .deviceId = -1,
1583         .vibratorId = -1,
1584     };
1585     int32_t ret = StopVibratorEnhanced(identifier, nullptr);
1586     ASSERT_NE(ret, 0);
1587 }
1588 
1589 HWTEST_F(VibratorAgentTest, StopVibratorEnhancedTest_005, TestSize.Level1)
1590 {
1591     MISC_HILOGI("StopVibratorEnhancedTest_005 in");
1592     VibratorIdentifier identifier = {
1593         .deviceId = -1,
1594         .vibratorId = -1,
1595     };
1596     int32_t ret = StartVibratorOnceEnhanced(identifier, 300);
1597     ASSERT_EQ(ret, 0);
1598     ret = StopVibratorEnhanced(identifier, "time");
1599     ASSERT_EQ(ret, 0);
1600 }
1601 
1602 HWTEST_F(VibratorAgentTest, SetLoopCountEnhanced_001, TestSize.Level1)
1603 {
1604     MISC_HILOGI("SetLoopCountEnhanced_001 in");
1605     VibratorIdentifier identifier = {
1606         .deviceId = -1,
1607         .vibratorId = -1,
1608     };
1609     bool ret = SetLoopCountEnhanced(identifier, 300);
1610     ASSERT_TRUE(ret);
1611 }
1612 
1613 HWTEST_F(VibratorAgentTest, SetLoopCountEnhanced_002, TestSize.Level1)
1614 {
1615     MISC_HILOGI("SetLoopCount_002 in");
1616     VibratorIdentifier identifier = {
1617         .deviceId = -1,
1618         .vibratorId = -1,
1619     };
1620     bool ret = SetLoopCountEnhanced(identifier, -1);
1621     ASSERT_FALSE(ret);
1622 }
1623 
1624 HWTEST_F(VibratorAgentTest, SetLoopCountEnhanced_003, TestSize.Level1)
1625 {
1626     MISC_HILOGI("SetLoopCountEnhanced_003 in");
1627     VibratorIdentifier identifier = {
1628         .deviceId = -1,
1629         .vibratorId = -1,
1630     };
1631     bool ret = SetLoopCountEnhanced(identifier, 0);
1632     ASSERT_FALSE(ret);
1633 }
1634 
1635 HWTEST_F(VibratorAgentTest, SetUsageEnhanced_001, TestSize.Level1)
1636 {
1637     MISC_HILOGI("SetUsageEnhanced_001 in");
1638     VibratorIdentifier identifier = {
1639         .deviceId = -1,
1640         .vibratorId = -1,
1641     };
1642     bool ret = SetUsageEnhanced(identifier, 0);
1643     ASSERT_TRUE(ret);
1644 }
1645 
1646 HWTEST_F(VibratorAgentTest, SetUsageEnhanced_002, TestSize.Level1)
1647 {
1648     MISC_HILOGI("SetUsageEnhanced_002 in");
1649     VibratorIdentifier identifier = {
1650         .deviceId = -1,
1651         .vibratorId = -1,
1652     };
1653     bool ret = SetUsageEnhanced(identifier, -1);
1654     ASSERT_FALSE(ret);
1655 }
1656 
1657 HWTEST_F(VibratorAgentTest, SetUsageEnhanced_003, TestSize.Level1)
1658 {
1659     MISC_HILOGI("SetUsage_003 in");
1660     VibratorIdentifier identifier = {
1661         .deviceId = -1,
1662         .vibratorId = -1,
1663     };
1664     bool ret = SetUsageEnhanced(identifier, USAGE_MAX);
1665     ASSERT_FALSE(ret);
1666 }
1667 
1668 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_001, TestSize.Level0)
1669 {
1670     MISC_HILOGI("PlayVibratorCustomEnhanced_001 in");
1671     VibratorIdentifier identifier = {
1672         .deviceId = -1,
1673         .vibratorId = -1,
1674     };
1675     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1676     if (isSupport) {
1677         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
1678         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1679         struct stat64 statbuf = { 0 };
1680         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1681             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1682             ASSERT_EQ(ret, 0);
1683         }
1684         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1685     } else {
1686         ASSERT_EQ(isSupport, false);
1687     }
1688     CancelEnhanced(identifier);
1689 }
1690 
1691 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_002, TestSize.Level1)
1692 {
1693     MISC_HILOGI("PlayVibratorCustomEnhanced_002 in");
1694     VibratorIdentifier identifier = {
1695         .deviceId = -1,
1696         .vibratorId = -1,
1697     };
1698     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1699     if (isSupport) {
1700         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1701         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1702         struct stat64 statbuf = { 0 };
1703         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1704             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1705             ASSERT_EQ(ret, 0);
1706         }
1707         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1708     } else {
1709         ASSERT_EQ(isSupport, false);
1710     }
1711     CancelEnhanced(identifier);
1712 }
1713 
1714 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_003, TestSize.Level1)
1715 {
1716     MISC_HILOGI("PlayVibratorCustomEnhanced_003 in");
1717     VibratorIdentifier identifier = {
1718         .deviceId = -1,
1719         .vibratorId = -1,
1720     };
1721     bool isSupport = (IsSupportVibratorCustomEnhanced(identifier) &&
1722         IsSupportVibratorEffectEnhanced(identifier, VIBRATOR_TYPE_FAIL));
1723     if (isSupport) {
1724         bool flag = SetLoopCountEnhanced(identifier, 2);
1725         ASSERT_TRUE(flag);
1726         int32_t ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_FAIL);
1727         ASSERT_EQ(ret, 0);
1728         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1729         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1730         struct stat64 statbuf = { 0 };
1731         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1732             ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1733             ASSERT_NE(ret, 0);
1734         }
1735         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1736     } else {
1737         ASSERT_EQ(isSupport, false);
1738     }
1739     CancelEnhanced(identifier);
1740 }
1741 
1742 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_004, TestSize.Level1)
1743 {
1744     MISC_HILOGI("PlayVibratorCustomEnhanced_004 in");
1745     VibratorIdentifier identifier = {
1746         .deviceId = -1,
1747         .vibratorId = -1,
1748     };
1749     bool isSupport = (IsSupportVibratorCustomEnhanced(identifier) &&
1750         IsSupportVibratorEffectEnhanced(identifier, VIBRATOR_TYPE_FAIL));
1751     if (isSupport) {
1752         bool flag = SetUsageEnhanced(identifier, USAGE_ALARM);
1753         ASSERT_TRUE(flag);
1754         int32_t ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_FAIL);
1755         ASSERT_EQ(ret, 0);
1756         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1757         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1758         struct stat64 statbuf = { 0 };
1759         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1760             ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1761             ASSERT_NE(ret, 0);
1762         }
1763         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1764     } else {
1765         ASSERT_EQ(isSupport, false);
1766     }
1767     CancelEnhanced(identifier);
1768 }
1769 
1770 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_005, TestSize.Level1)
1771 {
1772     MISC_HILOGI("PlayVibratorCustomEnhanced_005 in");
1773     VibratorIdentifier identifier = {
1774         .deviceId = -1,
1775         .vibratorId = -1,
1776     };
1777     bool isSupport = (IsSupportVibratorCustomEnhanced(identifier) &&
1778         IsSupportVibratorEffectEnhanced(identifier, VIBRATOR_TYPE_FAIL));
1779     if (isSupport) {
1780         bool flag = SetUsageEnhanced(identifier, USAGE_UNKNOWN);
1781         ASSERT_TRUE(flag);
1782         int32_t ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_FAIL);
1783         ASSERT_EQ(ret, 0);
1784         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1785         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1786         struct stat64 statbuf = { 0 };
1787         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1788             ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1789             ASSERT_EQ(ret, 0);
1790         }
1791         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1792     } else {
1793         ASSERT_EQ(isSupport, false);
1794     }
1795     CancelEnhanced(identifier);
1796 }
1797 
1798 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_006, TestSize.Level1)
1799 {
1800     MISC_HILOGI("PlayVibratorCustomEnhanced_006 in");
1801     VibratorIdentifier identifier = {
1802         .deviceId = -1,
1803         .vibratorId = -1,
1804     };
1805     bool isSupport = (IsSupportVibratorCustomEnhanced(identifier) &&
1806         IsSupportVibratorEffectEnhanced(identifier, VIBRATOR_TYPE_FAIL));
1807     if (isSupport) {
1808         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1809         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1810         struct stat64 statbuf = { 0 };
1811         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1812             bool flag = SetUsageEnhanced(identifier, USAGE_ALARM);
1813             ASSERT_TRUE(flag);
1814             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1815             ASSERT_EQ(ret, 0);
1816             ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_FAIL);
1817             ASSERT_NE(ret, 0);
1818         }
1819         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1820     } else {
1821         ASSERT_EQ(isSupport, false);
1822     }
1823     CancelEnhanced(identifier);
1824 }
1825 
1826 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_007, TestSize.Level1)
1827 {
1828     MISC_HILOGI("PlayVibratorCustomEnhanced_007 in");
1829     VibratorIdentifier identifier = {
1830         .deviceId = -1,
1831         .vibratorId = -1,
1832     };
1833     bool isSupport = (IsSupportVibratorCustomEnhanced(identifier) &&
1834         IsSupportVibratorEffectEnhanced(identifier, VIBRATOR_TYPE_FAIL));
1835     if (isSupport) {
1836         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1837         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1838         struct stat64 statbuf = { 0 };
1839         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1840             bool flag = SetUsageEnhanced(identifier, USAGE_UNKNOWN);
1841             ASSERT_TRUE(flag);
1842             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1843             ASSERT_EQ(ret, 0);
1844             ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_FAIL);
1845             ASSERT_EQ(ret, 0);
1846         }
1847         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1848     } else {
1849         ASSERT_EQ(isSupport, false);
1850     }
1851     CancelEnhanced(identifier);
1852 }
1853 
1854 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_008, TestSize.Level1)
1855 {
1856     MISC_HILOGI("PlayVibratorCustomEnhanced_008 in");
1857     VibratorIdentifier identifier = {
1858         .deviceId = -1,
1859         .vibratorId = -1,
1860     };
1861     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1862     if (isSupport) {
1863         bool flag = SetUsageEnhanced(identifier, USAGE_ALARM);
1864         ASSERT_TRUE(flag);
1865         int32_t ret = StartVibratorOnceEnhanced(identifier, 500);
1866         ASSERT_EQ(ret, 0);
1867         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1868         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1869         struct stat64 statbuf = { 0 };
1870         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1871             ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1872             ASSERT_NE(ret, 0);
1873         }
1874         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1875     } else {
1876         ASSERT_EQ(isSupport, false);
1877     }
1878     CancelEnhanced(identifier);
1879 }
1880 
1881 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_009, TestSize.Level1)
1882 {
1883     MISC_HILOGI("PlayVibratorCustomEnhanced_009 in");
1884     VibratorIdentifier identifier = {
1885         .deviceId = -1,
1886         .vibratorId = -1,
1887     };
1888     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1889     if (isSupport) {
1890         bool flag = SetUsage(USAGE_UNKNOWN);
1891         ASSERT_TRUE(flag);
1892         int32_t ret = StartVibratorOnceEnhanced(identifier, 500);
1893         ASSERT_EQ(ret, 0);
1894         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1895         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1896         struct stat64 statbuf = { 0 };
1897         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1898             ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1899             ASSERT_EQ(ret, 0);
1900         }
1901         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1902     } else {
1903         ASSERT_EQ(isSupport, false);
1904     }
1905     CancelEnhanced(identifier);
1906 }
1907 
1908 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_010, TestSize.Level1)
1909 {
1910     MISC_HILOGI("PlayVibratorCustomEnhanced_010 in");
1911     VibratorIdentifier identifier = {
1912         .deviceId = -1,
1913         .vibratorId = -1,
1914     };
1915     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1916     if (isSupport) {
1917         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1918         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1919         struct stat64 statbuf = { 0 };
1920         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1921             bool flag = SetUsageEnhanced(identifier, USAGE_ALARM);
1922             ASSERT_TRUE(flag);
1923             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1924             ASSERT_EQ(ret, 0);
1925             ret = StartVibratorOnceEnhanced(identifier, 500);
1926             ASSERT_NE(ret, 0);
1927         }
1928         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1929     } else {
1930         ASSERT_EQ(isSupport, false);
1931     }
1932     CancelEnhanced(identifier);
1933 }
1934 
1935 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_011, TestSize.Level1)
1936 {
1937     MISC_HILOGI("PlayVibratorCustomEnhanced_011 in");
1938     VibratorIdentifier identifier = {
1939         .deviceId = -1,
1940         .vibratorId = -1,
1941     };
1942     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1943     if (isSupport) {
1944         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
1945         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1946         struct stat64 statbuf = { 0 };
1947         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1948             bool flag = SetUsageEnhanced(identifier, USAGE_UNKNOWN);
1949             ASSERT_TRUE(flag);
1950             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1951             ASSERT_EQ(ret, 0);
1952             ret = StartVibratorOnceEnhanced(identifier, 500);
1953             ASSERT_EQ(ret, 0);
1954         }
1955         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1956     } else {
1957         ASSERT_EQ(isSupport, false);
1958     }
1959     CancelEnhanced(identifier);
1960 }
1961 
1962 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_012, TestSize.Level1)
1963 {
1964     MISC_HILOGI("PlayVibratorCustomEnhanced_012 in");
1965     VibratorIdentifier identifier = {
1966         .deviceId = -1,
1967         .vibratorId = -1,
1968     };
1969     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1970     if (isSupport) {
1971         FileDescriptor fileDescriptor("/data/test/vibrator/test_128_event.json");
1972         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1973         struct stat64 statbuf = { 0 };
1974         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1975             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1976             ASSERT_EQ(ret, 0);
1977         }
1978         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1979     } else {
1980         ASSERT_EQ(isSupport, false);
1981     }
1982     CancelEnhanced(identifier);
1983 }
1984 
1985 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_013, TestSize.Level1)
1986 {
1987     MISC_HILOGI("PlayVibratorCustomEnhanced_013 in");
1988     VibratorIdentifier identifier = {
1989         .deviceId = -1,
1990         .vibratorId = -1,
1991     };
1992     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
1993     if (isSupport) {
1994         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_type.json");
1995         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1996         struct stat64 statbuf = { 0 };
1997         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1998             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
1999             ASSERT_NE(ret, 0);
2000         }
2001     } else {
2002         ASSERT_EQ(isSupport, false);
2003     }
2004 }
2005 
2006 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_014, TestSize.Level1)
2007 {
2008     MISC_HILOGI("PlayVibratorCustomEnhanced_014 in");
2009     VibratorIdentifier identifier = {
2010         .deviceId = -1,
2011         .vibratorId = -1,
2012     };
2013     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2014     if (isSupport) {
2015         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_startTime.json");
2016         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2017         struct stat64 statbuf = { 0 };
2018         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2019             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2020             ASSERT_NE(ret, 0);
2021         }
2022     } else {
2023         ASSERT_EQ(isSupport, false);
2024     }
2025 }
2026 
2027 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_015, TestSize.Level1)
2028 {
2029     MISC_HILOGI("PlayVibratorCustomEnhanced_015 in");
2030     VibratorIdentifier identifier = {
2031         .deviceId = -1,
2032         .vibratorId = -1,
2033     };
2034     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2035     if (isSupport) {
2036         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_duration.json");
2037         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2038         struct stat64 statbuf = { 0 };
2039         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2040             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2041             ASSERT_NE(ret, 0);
2042         }
2043     } else {
2044         ASSERT_EQ(isSupport, false);
2045     }
2046 }
2047 
2048 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_016, TestSize.Level1)
2049 {
2050     MISC_HILOGI("PlayVibratorCustomEnhanced_016 in");
2051     VibratorIdentifier identifier = {
2052         .deviceId = -1,
2053         .vibratorId = -1,
2054     };
2055     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2056     if (isSupport) {
2057         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_intensity.json");
2058         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2059         struct stat64 statbuf = { 0 };
2060         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2061             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2062             ASSERT_NE(ret, 0);
2063         }
2064     } else {
2065         ASSERT_EQ(isSupport, false);
2066     }
2067 }
2068 
2069 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_017, TestSize.Level1)
2070 {
2071     MISC_HILOGI("PlayVibratorCustomEnhanced_017 in");
2072     VibratorIdentifier identifier = {
2073         .deviceId = -1,
2074         .vibratorId = -1,
2075     };
2076     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2077     if (isSupport) {
2078         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_frequency.json");
2079         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2080         struct stat64 statbuf = { 0 };
2081         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2082             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2083             ASSERT_NE(ret, 0);
2084         }
2085     } else {
2086         ASSERT_EQ(isSupport, false);
2087     }
2088 }
2089 
2090 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_018, TestSize.Level1)
2091 {
2092     MISC_HILOGI("PlayVibratorCustomEnhanced_018 in");
2093     VibratorIdentifier identifier = {
2094         .deviceId = -1,
2095         .vibratorId = -1,
2096     };
2097     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2098     if (isSupport) {
2099         FileDescriptor fileDescriptor("/data/test/vibrator/test_129_event.json");
2100         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2101         struct stat64 statbuf = { 0 };
2102         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2103             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2104             ASSERT_NE(ret, 0);
2105         }
2106     } else {
2107         ASSERT_EQ(isSupport, false);
2108     }
2109 }
2110 
2111 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_019, TestSize.Level1)
2112 {
2113     MISC_HILOGI("PlayVibratorCustomEnhanced_019 in");
2114     VibratorIdentifier identifier = {
2115         .deviceId = -1,
2116         .vibratorId = -1,
2117     };
2118     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2119     if (isSupport) {
2120         FileDescriptor fileDescriptor("/data/test/vibrator/test_big_file_size.json");
2121         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2122         struct stat64 statbuf = { 0 };
2123         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2124             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2125             ASSERT_NE(ret, 0);
2126         }
2127     } else {
2128         ASSERT_EQ(isSupport, false);
2129     }
2130 }
2131 
2132 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_020, TestSize.Level1)
2133 {
2134     MISC_HILOGI("PlayVibratorCustomEnhanced_020 in");
2135     VibratorIdentifier identifier = {
2136         .deviceId = -1,
2137         .vibratorId = -1,
2138     };
2139     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2140     if (isSupport) {
2141         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_1.json");
2142         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2143         struct stat64 statbuf = { 0 };
2144         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2145             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2146             ASSERT_EQ(ret, 0);
2147         }
2148     } else {
2149         ASSERT_EQ(isSupport, false);
2150     }
2151     CancelEnhanced(identifier);
2152 }
2153 
2154 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_021, TestSize.Level1)
2155 {
2156     MISC_HILOGI("PlayVibratorCustomEnhanced_021 in");
2157     VibratorIdentifier identifier = {
2158         .deviceId = -1,
2159         .vibratorId = -1,
2160     };
2161     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2162     if (isSupport) {
2163         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_2.json");
2164         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2165         struct stat64 statbuf = { 0 };
2166         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2167             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2168             ASSERT_EQ(ret, 0);
2169         }
2170     } else {
2171         ASSERT_EQ(isSupport, false);
2172     }
2173     CancelEnhanced(identifier);
2174 }
2175 
2176 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_022, TestSize.Level1)
2177 {
2178     MISC_HILOGI("PlayVibratorCustomEnhanced_022 in");
2179     VibratorIdentifier identifier = {
2180         .deviceId = -1,
2181         .vibratorId = -1,
2182     };
2183     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2184     if (isSupport) {
2185         FileDescriptor fileDescriptor("/data/test/vibrator/Jet_N2O.he");
2186         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2187         struct stat64 statbuf = { 0 };
2188         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2189             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2190             ASSERT_EQ(ret, 0);
2191         }
2192         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2193     } else {
2194         ASSERT_EQ(isSupport, false);
2195     }
2196     CancelEnhanced(identifier);
2197 }
2198 
2199 HWTEST_F(VibratorAgentTest, PlayVibratorCustomEnhanced_023, TestSize.Level1)
2200 {
2201     MISC_HILOGI("PlayVibratorCustomEnhanced_023 in");
2202     VibratorIdentifier identifier = {
2203         .deviceId = -1,
2204         .vibratorId = -1,
2205     };
2206     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2207     if (isSupport) {
2208         FileDescriptor fileDescriptor("/data/test/vibrator/Racing_Start.he");
2209         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2210         struct stat64 statbuf = { 0 };
2211         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2212             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2213             ASSERT_EQ(ret, 0);
2214         }
2215         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2216     } else {
2217         ASSERT_EQ(isSupport, false);
2218     }
2219     CancelEnhanced(identifier);
2220 }
2221 
2222 HWTEST_F(VibratorAgentTest, SetParametersEnhanced_001, TestSize.Level1)
2223 {
2224     MISC_HILOGI("SetParametersEnhanced_001 in");
2225     VibratorIdentifier identifier = {
2226         .deviceId = -1,
2227         .vibratorId = -1,
2228     };
2229     VibratorParameter parameter = {
2230         .intensity = -1,
2231         .frequency = -15
2232     };
2233     bool ret = SetParametersEnhanced(identifier, parameter);
2234     ASSERT_FALSE(ret);
2235 }
2236 
2237 HWTEST_F(VibratorAgentTest, SetParametersEnhanced_002, TestSize.Level1)
2238 {
2239     MISC_HILOGI("SetParametersEnhanced_002 in");
2240     VibratorIdentifier identifier = {
2241         .deviceId = -1,
2242         .vibratorId = -1,
2243     };
2244     VibratorParameter parameter = {
2245         .intensity = 70,
2246         .frequency = 150
2247     };
2248     bool ret = SetParametersEnhanced(identifier, parameter);
2249     ASSERT_FALSE(ret);
2250 }
2251 
2252 HWTEST_F(VibratorAgentTest, SetParametersEnhanced_003, TestSize.Level1)
2253 {
2254     MISC_HILOGI("SetParametersEnhanced_003 in");
2255     VibratorIdentifier identifier = {
2256         .deviceId = -1,
2257         .vibratorId = -1,
2258     };
2259     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2260     if (isSupport) {
2261         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
2262         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2263         struct stat64 statbuf = { 0 };
2264         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2265             VibratorParameter parameter = {
2266                 .intensity = 50,
2267                 .frequency = -15
2268             };
2269             bool flag = SetParametersEnhanced(identifier, parameter);
2270             ASSERT_TRUE(flag);
2271             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2272             ASSERT_EQ(ret, 0);
2273         }
2274         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2275     } else {
2276         ASSERT_EQ(isSupport, false);
2277     }
2278     CancelEnhanced(identifier);
2279 }
2280 
2281 HWTEST_F(VibratorAgentTest, SetParametersEnhanced_004, TestSize.Level1)
2282 {
2283     MISC_HILOGI("SetParametersEnhanced_004 in");
2284     VibratorIdentifier identifier = {
2285         .deviceId = -1,
2286         .vibratorId = -1,
2287     };
2288     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2289     if (isSupport) {
2290         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
2291         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2292         struct stat64 statbuf = { 0 };
2293         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2294             VibratorParameter parameter = {
2295                 .intensity = 33,
2296                 .frequency = 55
2297             };
2298             bool flag = SetParametersEnhanced(identifier, parameter);
2299             ASSERT_TRUE(flag);
2300             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2301             ASSERT_EQ(ret, 0);
2302         }
2303         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2304     } else {
2305         ASSERT_EQ(isSupport, false);
2306     }
2307     CancelEnhanced(identifier);
2308 }
2309 
2310 HWTEST_F(VibratorAgentTest, CancelEnhanced_001, TestSize.Level1)
2311 {
2312     MISC_HILOGI("CancelEnhanced_001 in");
2313     VibratorIdentifier identifier = {
2314         .deviceId = -1,
2315         .vibratorId = -1,
2316     };
2317     int32_t ret = CancelEnhanced(identifier);
2318     ASSERT_EQ(ret, 0);
2319 }
2320 
2321 HWTEST_F(VibratorAgentTest, CancelEnhanced_002, TestSize.Level1)
2322 {
2323     MISC_HILOGI("CancelEnhanced_002 in");
2324     VibratorIdentifier identifier = {
2325         .deviceId = -1,
2326         .vibratorId = -1,
2327     };
2328     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2329     if (isSupport) {
2330         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
2331         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2332         struct stat64 statbuf = { 0 };
2333         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2334             int32_t ret = PlayVibratorCustomEnhanced(identifier, fileDescriptor.fd, 0, statbuf.st_size);
2335             ASSERT_EQ(ret, 0);
2336             ret = CancelEnhanced(identifier);
2337             ASSERT_EQ(ret, 0);
2338         }
2339     } else {
2340         ASSERT_EQ(isSupport, false);
2341     }
2342 }
2343 
2344 HWTEST_F(VibratorAgentTest, CancelEnhanced_003, TestSize.Level1)
2345 {
2346     MISC_HILOGI("CancelEnhanced_003 in");
2347     VibratorIdentifier identifier = {
2348         .deviceId = -1,
2349         .vibratorId = -1,
2350     };
2351     int32_t ret = StartVibratorOnceEnhanced(identifier, 500);
2352     ASSERT_EQ(ret, 0);
2353     ret = CancelEnhanced(identifier);
2354     ASSERT_EQ(ret, 0);
2355 }
2356 
2357 HWTEST_F(VibratorAgentTest, CancelEnhanced_004, TestSize.Level1)
2358 {
2359     MISC_HILOGI("CancelEnhanced_004 in");
2360     VibratorIdentifier identifier = {
2361         .deviceId = -1,
2362         .vibratorId = -1,
2363     };
2364     if (IsSupportVibratorEffectEnhanced(identifier, VIBRATOR_TYPE_FAIL)) {
2365         int32_t ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_FAIL);
2366         ASSERT_EQ(ret, 0);
2367         ret = CancelEnhanced(identifier);
2368         ASSERT_EQ(ret, 0);
2369     }
2370     ASSERT_TRUE(true);
2371 }
2372 
2373 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_001, TestSize.Level1)
2374 {
2375     MISC_HILOGI("IsSupportEffectEnhanced_001 in");
2376     VibratorIdentifier identifier = {
2377         .deviceId = -1,
2378         .vibratorId = -1,
2379     };
2380     bool state { false };
2381     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_CLOCK_TIMER, &state);
2382     ASSERT_EQ(ret, 0);
2383     if (state) {
2384         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_CLOCK_TIMER);
2385         ASSERT_EQ(ret, 0);
2386         CancelEnhanced(identifier);
2387     } else {
2388         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_CLOCK_TIMER);
2389     }
2390 }
2391 
2392 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_002, TestSize.Level1)
2393 {
2394     MISC_HILOGI("IsSupportEffectEnhanced_002 in");
2395     VibratorIdentifier identifier = {
2396         .deviceId = -1,
2397         .vibratorId = -1,
2398     };
2399     bool state { false };
2400     int32_t ret = IsSupportEffectEnhanced(identifier, "haptic.xxx.yyy", &state);
2401     ASSERT_EQ(ret, 0);
2402     ASSERT_FALSE(state);
2403 }
2404 
2405 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_003, TestSize.Level1)
2406 {
2407     MISC_HILOGI("IsSupportEffectEnhanced_003 in");
2408     VibratorIdentifier identifier = {
2409         .deviceId = -1,
2410         .vibratorId = -1,
2411     };
2412     bool state { false };
2413     int32_t ret = IsSupportEffectEnhanced(identifier, nullptr, &state);
2414     ASSERT_NE(ret, 0);
2415     ASSERT_FALSE(state);
2416 }
2417 
2418 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_004, TestSize.Level1)
2419 {
2420     MISC_HILOGI("IsSupportEffectEnhanced_004 in");
2421     VibratorIdentifier identifier = {
2422         .deviceId = -1,
2423         .vibratorId = -1,
2424     };
2425     bool state { false };
2426     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_FAIL, &state);
2427     ASSERT_EQ(ret, 0);
2428     if (state) {
2429         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_FAIL);
2430         ASSERT_EQ(ret, 0);
2431         CancelEnhanced(identifier);
2432     } else {
2433         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_FAIL);
2434     }
2435 }
2436 
2437 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_005, TestSize.Level1)
2438 {
2439     MISC_HILOGI("IsSupportEffectEnhanced_005 in");
2440     VibratorIdentifier identifier = {
2441         .deviceId = -1,
2442         .vibratorId = -1,
2443     };
2444     bool state { false };
2445     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_CHARGING, &state);
2446     ASSERT_EQ(ret, 0);
2447     if (state) {
2448         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_CHARGING);
2449         ASSERT_EQ(ret, 0);
2450         CancelEnhanced(identifier);
2451     } else {
2452         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_CHARGING);
2453     }
2454 }
2455 
2456 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_006, TestSize.Level1)
2457 {
2458     MISC_HILOGI("IsSupportEffectEnhanced_006 in");
2459     VibratorIdentifier identifier = {
2460         .deviceId = -1,
2461         .vibratorId = -1,
2462     };
2463     bool state { false };
2464     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_LONG_PRESS_HEAVY, &state);
2465     ASSERT_EQ(ret, 0);
2466     if (state) {
2467         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_LONG_PRESS_HEAVY);
2468         ASSERT_EQ(ret, 0);
2469         CancelEnhanced(identifier);
2470     } else {
2471         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_HEAVY);
2472     }
2473 }
2474 
2475 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_007, TestSize.Level1)
2476 {
2477     MISC_HILOGI("IsSupportEffectEnhanced_007 in");
2478     VibratorIdentifier identifier = {
2479         .deviceId = -1,
2480         .vibratorId = -1,
2481     };
2482     bool state { false };
2483     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_LONG_PRESS_LIGHT, &state);
2484     ASSERT_EQ(ret, 0);
2485     if (state) {
2486         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_LONG_PRESS_LIGHT);
2487         ASSERT_EQ(ret, 0);
2488         CancelEnhanced(identifier);
2489     } else {
2490         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_LIGHT);
2491     }
2492 }
2493 
2494 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_008, TestSize.Level1)
2495 {
2496     MISC_HILOGI("IsSupportEffectEnhanced_008 in");
2497     VibratorIdentifier identifier = {
2498         .deviceId = -1,
2499         .vibratorId = -1,
2500     };
2501     bool state { false };
2502     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_LONG_PRESS_MEDIUM, &state);
2503     ASSERT_EQ(ret, 0);
2504     if (state) {
2505         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_LONG_PRESS_MEDIUM);
2506         ASSERT_EQ(ret, 0);
2507         CancelEnhanced(identifier);
2508     } else {
2509         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_MEDIUM);
2510     }
2511 }
2512 
2513 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_009, TestSize.Level1)
2514 {
2515     MISC_HILOGI("IsSupportEffectEnhanced_009 in");
2516     VibratorIdentifier identifier = {
2517         .deviceId = -1,
2518         .vibratorId = -1,
2519     };
2520     bool state { false };
2521     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE_LIGHT, &state);
2522     ASSERT_EQ(ret, 0);
2523     if (state) {
2524         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_SLIDE_LIGHT);
2525         ASSERT_EQ(ret, 0);
2526         CancelEnhanced(identifier);
2527     } else {
2528         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE_LIGHT);
2529     }
2530 }
2531 
2532 HWTEST_F(VibratorAgentTest, IsSupportEffectEnhanced_010, TestSize.Level1)
2533 {
2534     MISC_HILOGI("IsSupportEffectEnhanced_010 in");
2535     VibratorIdentifier identifier = {
2536         .deviceId = -1,
2537         .vibratorId = -1,
2538     };
2539     bool state { false };
2540     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_THRESHOID, &state);
2541     ASSERT_EQ(ret, 0);
2542     if (state) {
2543         ret = StartVibratorEnhanced(identifier, VIBRATOR_TYPE_THRESHOID);
2544         ASSERT_EQ(ret, 0);
2545         CancelEnhanced(identifier);
2546     } else {
2547         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_THRESHOID);
2548     }
2549 }
2550 
2551 HWTEST_F(VibratorAgentTest, GetDelayTimeEnhanced_001, TestSize.Level1)
2552 {
2553     MISC_HILOGI("GetDelayTimeEnhanced_001 in");
2554     VibratorIdentifier identifier = {
2555         .deviceId = -1,
2556         .vibratorId = -1,
2557     };
2558     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2559     if (isSupport) {
2560         int32_t delayTime { -1 };
2561         int32_t ret = GetDelayTimeEnhanced(identifier, delayTime);
2562         ASSERT_EQ(ret, 0);
2563     } else {
2564         ASSERT_EQ(isSupport, false);
2565     }
2566 }
2567 
2568 HWTEST_F(VibratorAgentTest, PlayPatternEnhanced_001, TestSize.Level1)
2569 {
2570     MISC_HILOGI("PlayPatternEnhanced_001 in");
2571     VibratorIdentifier identifier = {
2572         .deviceId = -1,
2573         .vibratorId = -1,
2574     };
2575     bool isSupport = IsSupportVibratorCustomEnhanced(identifier);
2576 
2577     if (!isSupport) {
2578         ASSERT_EQ(isSupport, false);
2579     }
2580     int32_t delayTime { -1 };
2581     int32_t ret = GetDelayTimeEnhanced(identifier, delayTime);
2582     ASSERT_EQ(ret, 0);
2583     MISC_HILOGD("delayTime:%{public}d", delayTime);
2584     FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
2585     MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
2586     VibratorFileDescription vfd;
2587     VibratorPackage package;
2588     struct stat64 statbuf = { 0 };
2589     if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2590         vfd.fd = fileDescriptor.fd;
2591         vfd.offset = 0;
2592         vfd.length = statbuf.st_size;
2593         ret = PreProcess(vfd, package);
2594         ASSERT_EQ(ret, 0);
2595         for (int32_t i = 0; i < package.patternNum; ++i) {
2596             if (i == 0) {
2597                 std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time));
2598             } else {
2599                 std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time) -
2600                     std::chrono::milliseconds(package.patterns[i - 1].time));
2601             }
2602             ASSERT_EQ(SetUsageEnhanced(identifier, USAGE_UNKNOWN), true);
2603             MISC_HILOGD("pointNum:%{public}d", package.patterns[i].events[i].pointNum);
2604             ret = PlayPatternEnhanced(identifier, package.patterns[i]);
2605             ASSERT_EQ(ret, 0);
2606         }
2607     }
2608     ret = FreeVibratorPackage(package);
2609     ASSERT_EQ(ret, 0);
2610     CancelEnhanced(identifier);
2611 }
2612 
2613 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffectEnhanced_001, TestSize.Level1)
2614 {
2615     MISC_HILOGI("PlayPrimitiveEffectEnhanced_001 in");
2616     VibratorIdentifier identifier = {
2617         .deviceId = -1,
2618         .vibratorId = -1,
2619     };
2620     int32_t ret = PlayPrimitiveEffectEnhanced(identifier, nullptr, INTENSITY_HIGH);
2621     ASSERT_EQ(ret, PARAMETER_ERROR);
2622 }
2623 
2624 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffectEnhanced_002, TestSize.Level1)
2625 {
2626     MISC_HILOGI("PlayPrimitiveEffectEnhanced_002 in");
2627     VibratorIdentifier identifier = {
2628         .deviceId = -1,
2629         .vibratorId = -1,
2630     };
2631     bool state { false };
2632     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, &state);
2633     ASSERT_EQ(ret, 0);
2634     if (state) {
2635         ret = PlayPrimitiveEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, INTENSITY_INVALID);
2636         ASSERT_EQ(ret, PARAMETER_ERROR);
2637     } else {
2638         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
2639     }
2640 }
2641 
2642 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffectEnhanced_003, TestSize.Level1)
2643 {
2644     MISC_HILOGI("PlayPrimitiveEffectEnhanced_003 in");
2645     VibratorIdentifier identifier = {
2646         .deviceId = -1,
2647         .vibratorId = -1,
2648     };
2649     bool state { false };
2650     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, &state);
2651     ASSERT_EQ(ret, 0);
2652     if (state) {
2653         ret = PlayPrimitiveEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, INTENSITY_LOW);
2654         ASSERT_EQ(ret, 0);
2655         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2656         CancelEnhanced(identifier);
2657     } else {
2658         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
2659     }
2660 }
2661 
2662 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffectEnhanced_004, TestSize.Level1)
2663 {
2664     MISC_HILOGI("PlayPrimitiveEffectEnhanced_004 in");
2665     VibratorIdentifier identifier = {
2666         .deviceId = -1,
2667         .vibratorId = -1,
2668     };
2669     bool state { false };
2670     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, &state);
2671     ASSERT_EQ(ret, 0);
2672     if (state) {
2673         ret = PlayPrimitiveEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, INTENSITY_MEDIUM);
2674         ASSERT_EQ(ret, 0);
2675         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2676         CancelEnhanced(identifier);
2677     } else {
2678         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
2679     }
2680 }
2681 
2682 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffectEnhanced_005, TestSize.Level1)
2683 {
2684     MISC_HILOGI("PlayPrimitiveEffectEnhanced_005 in");
2685     VibratorIdentifier identifier = {
2686         .deviceId = -1,
2687         .vibratorId = -1,
2688     };
2689     bool state { false };
2690     int32_t ret = IsSupportEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, &state);
2691     ASSERT_EQ(ret, 0);
2692     if (state) {
2693         ret = PlayPrimitiveEffectEnhanced(identifier, VIBRATOR_TYPE_SLIDE, INTENSITY_HIGH);
2694         ASSERT_EQ(ret, 0);
2695         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2696         CancelEnhanced(identifier);
2697     } else {
2698         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
2699     }
2700 }
2701 
2702 HWTEST_F(VibratorAgentTest, IsHdHapticSupportedEnhanced_001, TestSize.Level1)
2703 {
2704     MISC_HILOGI("IsHdHapticSupportedEnhanced_001 in");
2705     VibratorIdentifier identifier = {
2706         .deviceId = -1,
2707         .vibratorId = -1,
2708     };
2709     bool isSupport = (IsSupportVibratorCustomEnhanced(identifier) && IsHdHapticSupportedEnhanced(identifier));
2710     if (isSupport) {
2711         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
2712         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
2713         struct stat64 statbuf = { 0 };
2714         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2715             int32_t ret = PlayVibratorCustomEnhanced(identifier,  fileDescriptor.fd, 0, statbuf.st_size);
2716             ASSERT_EQ(ret, 0);
2717         }
2718         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2719     } else {
2720         ASSERT_EQ(isSupport, false);
2721     }
2722     CancelEnhanced(identifier);
2723 }
2724 
2725 HWTEST_F(VibratorAgentTest, GetVibratorIdList_001, TestSize.Level1)
2726 {
2727     MISC_HILOGI("GetVibratorIdList_001 in");
2728     VibratorIdentifier identifier = {
2729         .deviceId = -1,
2730         .vibratorId = -1,
2731     };
2732     std::vector<VibratorInfos> result;
2733     int32_t ret = GetVibratorList(identifier, result);
2734     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2735 }
2736 
2737 HWTEST_F(VibratorAgentTest, GetVibratorIdList_002, TestSize.Level1)
2738 {
2739     MISC_HILOGI("GetVibratorIdList_002 in");
2740     VibratorIdentifier identifier = {
2741         .deviceId = -1,
2742         .vibratorId = 1,
2743     };
2744     std::vector<VibratorInfos> result;
2745     int32_t ret = GetVibratorList(identifier, result);
2746     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2747 }
2748 
2749 HWTEST_F(VibratorAgentTest, GetVibratorIdList_003, TestSize.Level1)
2750 {
2751     MISC_HILOGI("GetVibratorIdList_003 in");
2752     VibratorIdentifier identifier = {
2753         .deviceId = 1,
2754         .vibratorId = -1,
2755     };
2756     std::vector<VibratorInfos> result;
2757     int32_t ret = GetVibratorList(identifier, result);
2758     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2759 }
2760 
2761 HWTEST_F(VibratorAgentTest, GetVibratorIdList_004, TestSize.Level1)
2762 {
2763     MISC_HILOGI("GetVibratorIdList_004 in");
2764     VibratorIdentifier identifier = {
2765         .deviceId = 1,
2766         .vibratorId = 1,
2767     };
2768     std::vector<VibratorInfos> result;
2769     int32_t ret = GetVibratorList(identifier, result);
2770     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2771 }
2772 
2773 HWTEST_F(VibratorAgentTest, GetVibratorIdList_005, TestSize.Level1)
2774 {
2775     MISC_HILOGI("GetVibratorIdList_005 in");
2776     VibratorIdentifier identifier = {
2777         .deviceId = -9999,
2778         .vibratorId = 1,
2779     };
2780     std::vector<VibratorInfos> result;
2781     int32_t ret = GetVibratorList(identifier, result);
2782     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2783 }
2784 
2785 HWTEST_F(VibratorAgentTest, GetEffectInfo_001, TestSize.Level1)
2786 {
2787     MISC_HILOGI("GetEffectInfo_001 in");
2788     VibratorIdentifier identifier = {
2789         .deviceId = 1,
2790         .vibratorId = -1,
2791     };
2792     std::string effectType = "";
2793     EffectInfo result;
2794     int32_t ret = GetEffectInfo(identifier, effectType, result);
2795     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2796 }
2797 
2798 HWTEST_F(VibratorAgentTest, GetEffectInfo_002, TestSize.Level1)
2799 {
2800     MISC_HILOGI("GetEffectInfo_002 in");
2801     VibratorIdentifier identifier = {
2802         .deviceId = -1,
2803         .vibratorId = -1,
2804     };
2805     std::string effectType = "";
2806     EffectInfo result;
2807     int32_t ret = GetEffectInfo(identifier, effectType, result);
2808     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2809 }
2810 
2811 HWTEST_F(VibratorAgentTest, SubscribeVibrator_001, TestSize.Level1)
2812 {
2813     MISC_HILOGI("SubscribeVibrator_001 in");
2814     int32_t ret = SubscribeVibratorPlug(testUser);
2815     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2816 }
2817 
2818 HWTEST_F(VibratorAgentTest, SubscribeVibrator_002, TestSize.Level1)
2819 {
2820     VibratorUser invalidUser = {
2821         .callback = nullptr,
2822     };
2823     MISC_HILOGI("SubscribeVibrator_002 in");
2824     int32_t ret = SubscribeVibratorPlug(invalidUser);
2825     ASSERT_NE(ret, OHOS::Sensors::SUCCESS);
2826 }
2827 
2828 HWTEST_F(VibratorAgentTest, UnSubscribeVibrator_001, TestSize.Level1)
2829 {
2830     MISC_HILOGI("UnSubscribeVibrator_001 in");
2831     int32_t ret = UnSubscribeVibratorPlug(testUser);
2832     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
2833     ret = UnSubscribeVibratorPlug(testUser);
2834     ASSERT_NE(ret, OHOS::Sensors::SUCCESS);
2835 }
2836 
2837 HWTEST_F(VibratorAgentTest, operator_001, TestSize.Level1)
2838 {
2839     MISC_HILOGI("operator_001 in");
2840     VibratorIdentifier id1{1, 1};
2841     VibratorIdentifier id2{2, 1};
2842     ASSERT_TRUE(id1 < id2);
2843 }
2844 
2845 HWTEST_F(VibratorAgentTest, PlayPatternBySessionId_001, TestSize.Level1)
2846 {
2847     MISC_HILOGI("PlayPatternBySessionId_001 in");
2848     VibratorPattern pattern;
2849     int32_t ret = PlayPatternBySessionId(0, pattern);
2850     ASSERT_EQ(ret, PARAMETER_ERROR);
2851 }
2852 
2853 HWTEST_F(VibratorAgentTest, PlayPatternBySessionId_002, TestSize.Level1)
2854 {
2855     MISC_HILOGI("PlayPatternBySessionId_002 in");
2856     bool isSupport = IsSupportVibratorCustom();
2857     if (isSupport) {
2858         int32_t delayTime { -1 };
2859         int32_t ret = GetDelayTime(delayTime);
2860         ASSERT_EQ(ret, 0);
2861         MISC_HILOGD("delayTime:%{public}d", delayTime);
2862         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
2863         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
2864         VibratorFileDescription vfd;
2865         VibratorPackage package;
2866         struct stat64 statbuf = { 0 };
2867         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2868             vfd.fd = fileDescriptor.fd;
2869             vfd.offset = 0;
2870             vfd.length = statbuf.st_size;
2871             ret = PreProcess(vfd, package);
2872             ASSERT_EQ(ret, 0);
2873             for (int32_t i = 0; i < package.patternNum; ++i) {
2874                 if (i == 0) {
2875                     std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time));
2876                 } else {
2877                     std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time) -
2878                         std::chrono::milliseconds(package.patterns[i - 1].time));
2879                 }
2880                 ASSERT_EQ(SetUsage(USAGE_UNKNOWN), true);
2881                 MISC_HILOGD("pointNum:%{public}d", package.patterns[i].events[i].pointNum);
2882                 ret = PlayPatternBySessionId(SESSION_ID_ONE, package.patterns[i]);
2883                 ASSERT_EQ(ret, 0);
2884             }
2885         }
2886         ret = FreeVibratorPackage(package);
2887         ASSERT_EQ(ret, 0);
2888         StopVibrateBySessionId(SESSION_ID_ONE);
2889     } else {
2890         ASSERT_EQ(isSupport, false);
2891     }
2892 }
2893 
2894 HWTEST_F(VibratorAgentTest, PlayPatternBySessionId_003, TestSize.Level1)
2895 {
2896     MISC_HILOGI("PlayPatternBySessionId_003 in");
2897     bool isSupport = IsSupportVibratorCustom();
2898     if (isSupport) {
2899         VibratorCurvePoint point = {
2900             .time = 10,
2901             .intensity = 5,
2902             .frequency = 5,
2903         };
2904         VibratorEvent event = {
2905             .type = EVENT_TYPE_CONTINUOUS,
2906             .time = 10,
2907             .duration = 5,
2908             .pointNum = 1,
2909             .points = &point,
2910         };
2911         VibratorPattern pattern = {
2912             .time = 10,
2913             .eventNum = 1,
2914             .patternDuration = 2,
2915             .events = &event,
2916         };
2917         int32_t ret = PlayPatternBySessionId(SESSION_ID_ONE, pattern);
2918         ASSERT_EQ(ret, 0);
2919         ret = PlayPatternBySessionId(SESSION_ID_TWO, pattern);
2920         ASSERT_EQ(ret, 0);
2921         ret = PlayPatternBySessionId(SESSION_ID_THREE, pattern);
2922         ASSERT_EQ(ret, 0);
2923         ret = PlayPatternBySessionId(SESSION_ID_FOUR, pattern);
2924         ASSERT_EQ(ret, 0);
2925         ret = PlayPatternBySessionId(SESSION_ID_FIVE, pattern);
2926         ASSERT_EQ(ret, 0);
2927     } else {
2928         ASSERT_EQ(isSupport, false);
2929     }
2930 }
2931 
2932 HWTEST_F(VibratorAgentTest, PlayPackageBySessionId_001, TestSize.Level1)
2933 {
2934     MISC_HILOGI("PlayPackageBySessionId_001 in");
2935     VibratorPackage package;
2936     int32_t ret = PlayPackageBySessionId(0, package);
2937     ASSERT_EQ(ret, PARAMETER_ERROR);
2938 }
2939 
2940 HWTEST_F(VibratorAgentTest, PlayPackageBySessionId_002, TestSize.Level1)
2941 {
2942     MISC_HILOGI("PlayPackageBySessionId_002 in");
2943     bool isSupport = IsSupportVibratorCustom();
2944     if (isSupport) {
2945         int32_t delayTime { -1 };
2946         int32_t ret = GetDelayTime(delayTime);
2947         ASSERT_EQ(ret, 0);
2948         MISC_HILOGD("delayTime:%{public}d", delayTime);
2949         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
2950         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
2951         VibratorFileDescription vfd;
2952         VibratorPackage package;
2953         struct stat64 statbuf = { 0 };
2954         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2955             vfd.fd = fileDescriptor.fd;
2956             vfd.offset = 0;
2957             vfd.length = statbuf.st_size;
2958             ret = PreProcess(vfd, package);
2959             ASSERT_EQ(ret, 0);
2960             ASSERT_EQ(SetUsage(USAGE_UNKNOWN), true);
2961             MISC_HILOGD("patternNum:%{public}d", package.patternNum);
2962             ret = PlayPackageBySessionId(SESSION_ID_ONE, package);
2963             ASSERT_EQ(ret, 0);
2964         }
2965         ret = FreeVibratorPackage(package);
2966         ASSERT_EQ(ret, 0);
2967         StopVibrateBySessionId(SESSION_ID_ONE);
2968     } else {
2969         ASSERT_EQ(isSupport, false);
2970     }
2971 }
2972 
2973 HWTEST_F(VibratorAgentTest, PlayPackageBySessionId_003, TestSize.Level1)
2974 {
2975     MISC_HILOGI("PlayPackageBySessionId_003 in");
2976     bool isSupport = IsSupportVibratorCustom();
2977     if (isSupport) {
2978         int32_t delayTime { -1 };
2979         int32_t ret = GetDelayTime(delayTime);
2980         ASSERT_EQ(ret, 0);
2981         MISC_HILOGD("delayTime:%{public}d", delayTime);
2982         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
2983         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
2984         VibratorFileDescription vfd;
2985         VibratorPackage package;
2986         struct stat64 statbuf = { 0 };
2987         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
2988             vfd.fd = fileDescriptor.fd;
2989             vfd.offset = 0;
2990             vfd.length = statbuf.st_size;
2991             ret = PreProcess(vfd, package);
2992             ASSERT_EQ(ret, 0);
2993             ASSERT_EQ(SetUsage(USAGE_UNKNOWN), true);
2994             MISC_HILOGD("patternNum:%{public}d", package.patternNum);
2995             for (int32_t i = 0; i < LOOP_TIMES; ++i) {
2996                 ret = PlayPackageBySessionId((i + 1), package);
2997                 ASSERT_EQ(ret, 0);
2998             }
2999         }
3000         ret = FreeVibratorPackage(package);
3001         ASSERT_EQ(ret, 0);
3002         StopVibrateBySessionId(SESSION_ID_ONE);
3003     } else {
3004         ASSERT_EQ(isSupport, false);
3005     }
3006 }
3007 
3008 HWTEST_F(VibratorAgentTest, StopVibrateBySessionId_001, TestSize.Level1)
3009 {
3010     MISC_HILOGI("StopVibrateBySessionId_001 in");
3011     int32_t ret = StopVibrateBySessionId(0);
3012     ASSERT_EQ(ret, PARAMETER_ERROR);
3013 }
3014 
3015 HWTEST_F(VibratorAgentTest, StopVibrateBySessionId_002, TestSize.Level1)
3016 {
3017     MISC_HILOGI("StopVibrateBySessionId_002 in");
3018     int32_t ret = StopVibrateBySessionId(SESSION_ID_ONE);
3019     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3020 }
3021 
3022 HWTEST_F(VibratorAgentTest, StopVibrateBySessionId_003, TestSize.Level1)
3023 {
3024     MISC_HILOGI("StopVibrateBySessionId_003 in");
3025     int32_t ret = StopVibrateBySessionId(SESSION_ID_ONE);
3026     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3027     ret = StopVibrateBySessionId(SESSION_ID_ONE);
3028     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3029     ret = StopVibrateBySessionId(SESSION_ID_ONE);
3030     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3031     ret = StopVibrateBySessionId(SESSION_ID_ONE);
3032     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3033     ret = StopVibrateBySessionId(SESSION_ID_ONE);
3034     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3035 }
3036 
3037 HWTEST_F(VibratorAgentTest, StopVibrateBySessionId_004, TestSize.Level1)
3038 {
3039     MISC_HILOGI("StopVibrateBySessionId_004 in");
3040     int32_t ret = StopVibrateBySessionId(SESSION_ID_ONE);
3041     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3042     ret = StopVibrateBySessionId(SESSION_ID_TWO);
3043     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3044     ret = StopVibrateBySessionId(SESSION_ID_THREE);
3045     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3046     ret = StopVibrateBySessionId(SESSION_ID_FOUR);
3047     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3048     ret = StopVibrateBySessionId(SESSION_ID_FIVE);
3049     ASSERT_EQ(ret, OHOS::Sensors::SUCCESS);
3050 }
3051 } // namespace Sensors
3052 } // namespace OHOS