• 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 "token_setproc.h"
25 
26 #include "sensors_errors.h"
27 #include "vibrator_agent.h"
28 
29 #undef LOG_TAG
30 #define LOG_TAG "VibratorAgentTest"
31 
32 namespace OHOS {
33 namespace Sensors {
34 using namespace testing::ext;
35 using namespace Security::AccessToken;
36 using Security::AccessToken::AccessTokenID;
37 
38 namespace {
39 constexpr int32_t TIME_WAIT_FOR_OP = 500;
40 constexpr int32_t TIME_WAIT_FOR_OP_TWO_HUNDRED = 200;
41 constexpr int32_t INTENSITY_HIGH = 100;
42 constexpr int32_t INTENSITY_MEDIUM = 50;
43 constexpr int32_t INTENSITY_LOW = 20;
44 constexpr int32_t INTENSITY_INVALID = -1;
45 
46 PermissionStateFull g_infoManagerTestState = {
47     .grantFlags = {1},
48     .grantStatus = {PermissionState::PERMISSION_GRANTED},
49     .isGeneral = true,
50     .permissionName = "ohos.permission.VIBRATE",
51     .resDeviceID = {"local"}
52 };
53 
54 HapPolicyParams g_infoManagerTestPolicyPrams = {
55     .apl = APL_NORMAL,
56     .domain = "test.domain",
57     .permList = {},
58     .permStateList = {g_infoManagerTestState}
59 };
60 
61 HapInfoParams g_infoManagerTestInfoParms = {
62     .bundleName = "vibratoragent_test",
63     .userID = 1,
64     .instIndex = 0,
65     .appIDDesc = "vibratorAgentTest"
66 };
67 } // namespace
68 
69 class VibratorAgentTest : public testing::Test {
70 public:
71     static void SetUpTestCase();
72     static void TearDownTestCase();
73     void SetUp();
74     void TearDown();
75 
76 private:
77     static AccessTokenID tokenID_;
78 };
79 
80 struct FileDescriptor {
FileDescriptorOHOS::Sensors::FileDescriptor81     explicit FileDescriptor(const std::string &path)
82     {
83         fd = open(path.c_str(), O_RDONLY);
84     }
~FileDescriptorOHOS::Sensors::FileDescriptor85     ~FileDescriptor()
86     {
87         close(fd);
88     }
89     int32_t fd;
90 };
91 
92 AccessTokenID VibratorAgentTest::tokenID_ = 0;
93 
SetUpTestCase()94 void VibratorAgentTest::SetUpTestCase()
95 {
96     AccessTokenIDEx tokenIdEx = {0};
97     tokenIdEx = AccessTokenKit::AllocHapToken(g_infoManagerTestInfoParms, g_infoManagerTestPolicyPrams);
98     tokenID_ = tokenIdEx.tokenIdExStruct.tokenID;
99     ASSERT_NE(0, tokenID_);
100     ASSERT_EQ(0, SetSelfTokenID(tokenID_));
101 }
102 
TearDownTestCase()103 void VibratorAgentTest::TearDownTestCase()
104 {
105     int32_t ret = AccessTokenKit::DeleteToken(tokenID_);
106     if (tokenID_ != 0) {
107         ASSERT_EQ(RET_SUCCESS, ret);
108     }
109 }
110 
SetUp()111 void VibratorAgentTest::SetUp()
112 {}
113 
TearDown()114 void VibratorAgentTest::TearDown()
115 {
116     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_TWO_HUNDRED));
117 }
118 
IsSupportVibratorEffect(const char * effectId)119 bool IsSupportVibratorEffect(const char* effectId)
120 {
121     bool state { false };
122     IsSupportEffect(effectId, &state);
123     return state;
124 }
125 
126 HWTEST_F(VibratorAgentTest, StartVibratorTest_001, TestSize.Level1)
127 {
128     MISC_HILOGI("StartVibratorTest_001 in");
129     if (IsSupportVibratorEffect(VIBRATOR_TYPE_CLOCK_TIMER)) {
130         int32_t ret = StartVibrator(VIBRATOR_TYPE_CLOCK_TIMER);
131         ASSERT_EQ(ret, 0);
132     } else {
133         ASSERT_EQ(0, 0);
134     }
135 }
136 
137 HWTEST_F(VibratorAgentTest, StartVibratorTest_002, TestSize.Level1)
138 {
139     MISC_HILOGI("StartVibratorTest_002 in");
140     int32_t ret = StartVibrator("");
141     ASSERT_NE(ret, 0);
142 }
143 
144 HWTEST_F(VibratorAgentTest, StartVibratorTest_003, TestSize.Level1)
145 {
146     MISC_HILOGI("StartVibratorTest_003 in");
147     int32_t ret = StartVibrator(nullptr);
148     ASSERT_NE(ret, 0);
149 }
150 
151 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_001, TestSize.Level1)
152 {
153     MISC_HILOGI("StartVibratorOnceTest_001 in");
154     int32_t ret = StartVibratorOnce(300);
155     ASSERT_EQ(ret, 0);
156 }
157 
158 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_002, TestSize.Level1)
159 {
160     MISC_HILOGI("StartVibratorOnceTest_002 in");
161     int32_t ret = StartVibratorOnce(0);
162     ASSERT_NE(ret, 0);
163 }
164 
165 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_003, TestSize.Level1)
166 {
167     MISC_HILOGI("StartVibratorOnceTest_003 in");
168     int32_t ret = StartVibratorOnce(1800000);
169     ASSERT_EQ(ret, 0);
170 }
171 
172 HWTEST_F(VibratorAgentTest, StartVibratorOnceTest_004, TestSize.Level1)
173 {
174     MISC_HILOGI("StartVibratorOnceTest_004 in");
175     int32_t ret = StartVibratorOnce(1800001);
176     ASSERT_NE(ret, 0);
177 }
178 
179 HWTEST_F(VibratorAgentTest, StopVibratorTest_001, TestSize.Level1)
180 {
181     MISC_HILOGI("StopVibratorTest_001 in");
182     int32_t ret = StopVibrator("time");
183     ASSERT_EQ(ret, 0);
184 }
185 
186 HWTEST_F(VibratorAgentTest, StopVibratorTest_002, TestSize.Level1)
187 {
188     MISC_HILOGI("StopVibratorTest_002 in");
189     int32_t ret = StopVibrator("preset");
190     ASSERT_NE(ret, 0);
191 }
192 
193 HWTEST_F(VibratorAgentTest, StopVibratorTest_003, TestSize.Level1)
194 {
195     MISC_HILOGI("StopVibratorTest_003 in");
196     int32_t ret = StopVibrator("");
197     ASSERT_NE(ret, 0);
198 }
199 
200 HWTEST_F(VibratorAgentTest, StopVibratorTest_004, TestSize.Level1)
201 {
202     MISC_HILOGI("StopVibratorTest_004 in");
203     int32_t ret = StopVibrator(nullptr);
204     ASSERT_NE(ret, 0);
205 }
206 
207 HWTEST_F(VibratorAgentTest, StopVibratorTest_005, TestSize.Level1)
208 {
209     MISC_HILOGI("StopVibratorTest_005 in");
210     int32_t ret = StartVibratorOnce(300);
211     ASSERT_EQ(ret, 0);
212     ret = StopVibrator("time");
213     ASSERT_EQ(ret, 0);
214 }
215 
216 HWTEST_F(VibratorAgentTest, SetLoopCount_001, TestSize.Level1)
217 {
218     MISC_HILOGI("SetLoopCount_001 in");
219     bool ret = SetLoopCount(300);
220     ASSERT_TRUE(ret);
221 }
222 
223 HWTEST_F(VibratorAgentTest, SetLoopCount_002, TestSize.Level1)
224 {
225     MISC_HILOGI("SetLoopCount_002 in");
226     bool ret = SetLoopCount(-1);
227     ASSERT_FALSE(ret);
228 }
229 
230 HWTEST_F(VibratorAgentTest, SetLoopCount_003, TestSize.Level1)
231 {
232     MISC_HILOGI("SetLoopCount_003 in");
233     bool ret = SetLoopCount(0);
234     ASSERT_FALSE(ret);
235 }
236 
237 HWTEST_F(VibratorAgentTest, SetUsage_001, TestSize.Level1)
238 {
239     MISC_HILOGI("SetUsage_001 in");
240     bool ret = SetUsage(0);
241     ASSERT_TRUE(ret);
242 }
243 
244 HWTEST_F(VibratorAgentTest, SetUsage_002, TestSize.Level1)
245 {
246     MISC_HILOGI("SetUsage_002 in");
247     bool ret = SetUsage(-1);
248     ASSERT_FALSE(ret);
249 }
250 
251 HWTEST_F(VibratorAgentTest, SetUsage_003, TestSize.Level1)
252 {
253     MISC_HILOGI("SetUsage_003 in");
254     bool ret = SetUsage(USAGE_MAX);
255     ASSERT_FALSE(ret);
256 }
257 
258 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_001, TestSize.Level1)
259 {
260     MISC_HILOGI("PlayVibratorCustom_001 in");
261     if (IsSupportVibratorCustom()) {
262         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
263         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
264         struct stat64 statbuf = { 0 };
265         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
266             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
267             ASSERT_EQ(ret, 0);
268         }
269         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
270     } else {
271         ASSERT_EQ(0, 0);
272     }
273     Cancel();
274 }
275 
276 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_002, TestSize.Level1)
277 {
278     MISC_HILOGI("PlayVibratorCustom_002 in");
279     if (IsSupportVibratorCustom()) {
280         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
281         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
282         struct stat64 statbuf = { 0 };
283         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
284             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
285             ASSERT_EQ(ret, 0);
286         }
287         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
288     } else {
289         ASSERT_EQ(0, 0);
290     }
291     Cancel();
292 }
293 
294 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_003, TestSize.Level1)
295 {
296     MISC_HILOGI("PlayVibratorCustom_003 in");
297     if (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL)) {
298         bool flag = SetLoopCount(2);
299         ASSERT_TRUE(flag);
300         int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
301         ASSERT_EQ(ret, 0);
302         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
303         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
304         struct stat64 statbuf = { 0 };
305         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
306             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
307             ASSERT_NE(ret, 0);
308         }
309         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
310     } else {
311         ASSERT_EQ(0, 0);
312     }
313     Cancel();
314 }
315 
316 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_004, TestSize.Level1)
317 {
318     MISC_HILOGI("PlayVibratorCustom_004 in");
319     if (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL)) {
320         bool flag = SetUsage(USAGE_ALARM);
321         ASSERT_TRUE(flag);
322         int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
323         ASSERT_EQ(ret, 0);
324         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
325         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
326         struct stat64 statbuf = { 0 };
327         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
328             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
329             ASSERT_NE(ret, 0);
330         }
331         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
332     } else {
333         ASSERT_EQ(0, 0);
334     }
335     Cancel();
336 }
337 
338 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_005, TestSize.Level1)
339 {
340     MISC_HILOGI("PlayVibratorCustom_005 in");
341     if (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL)) {
342         bool flag = SetUsage(USAGE_UNKNOWN);
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_EQ(ret, 0);
352         }
353         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
354     } else {
355         ASSERT_EQ(0, 0);
356     }
357     Cancel();
358 }
359 
360 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_006, TestSize.Level1)
361 {
362     MISC_HILOGI("PlayVibratorCustom_006 in");
363     if (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL)) {
364         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
365         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
366         struct stat64 statbuf = { 0 };
367         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
368             bool flag = SetUsage(USAGE_ALARM);
369             ASSERT_TRUE(flag);
370             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
371             ASSERT_EQ(ret, 0);
372             ret = StartVibrator(VIBRATOR_TYPE_FAIL);
373             ASSERT_NE(ret, 0);
374         }
375         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
376     } else {
377         ASSERT_EQ(0, 0);
378     }
379     Cancel();
380 }
381 
382 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_007, TestSize.Level1)
383 {
384     MISC_HILOGI("PlayVibratorCustom_007 in");
385     if (IsSupportVibratorCustom() && IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL)) {
386         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
387         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
388         struct stat64 statbuf = { 0 };
389         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
390             bool flag = SetUsage(USAGE_UNKNOWN);
391             ASSERT_TRUE(flag);
392             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
393             ASSERT_EQ(ret, 0);
394             ret = StartVibrator(VIBRATOR_TYPE_FAIL);
395             ASSERT_EQ(ret, 0);
396         }
397         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
398     } else {
399         ASSERT_EQ(0, 0);
400     }
401     Cancel();
402 }
403 
404 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_008, TestSize.Level1)
405 {
406     MISC_HILOGI("PlayVibratorCustom_008 in");
407     if (IsSupportVibratorCustom()) {
408         bool flag = SetUsage(USAGE_ALARM);
409         ASSERT_TRUE(flag);
410         int32_t ret = StartVibratorOnce(500);
411         ASSERT_EQ(ret, 0);
412         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
413         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
414         struct stat64 statbuf = { 0 };
415         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
416             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
417             ASSERT_NE(ret, 0);
418         }
419         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
420     } else {
421         ASSERT_EQ(0, 0);
422     }
423     Cancel();
424 }
425 
426 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_009, TestSize.Level1)
427 {
428     MISC_HILOGI("PlayVibratorCustom_009 in");
429     if (IsSupportVibratorCustom()) {
430         bool flag = SetUsage(USAGE_UNKNOWN);
431         ASSERT_TRUE(flag);
432         int32_t ret = StartVibratorOnce(500);
433         ASSERT_EQ(ret, 0);
434         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
435         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
436         struct stat64 statbuf = { 0 };
437         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
438             ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
439             ASSERT_EQ(ret, 0);
440         }
441         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
442     } else {
443         ASSERT_EQ(0, 0);
444     }
445     Cancel();
446 }
447 
448 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_010, TestSize.Level1)
449 {
450     MISC_HILOGI("PlayVibratorCustom_010 in");
451     if (IsSupportVibratorCustom()) {
452         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
453         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
454         struct stat64 statbuf = { 0 };
455         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
456             bool flag = SetUsage(USAGE_ALARM);
457             ASSERT_TRUE(flag);
458             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
459             ASSERT_EQ(ret, 0);
460             ret = StartVibratorOnce(500);
461             ASSERT_NE(ret, 0);
462         }
463         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
464     } else {
465         ASSERT_EQ(0, 0);
466     }
467     Cancel();
468 }
469 
470 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_011, TestSize.Level1)
471 {
472     MISC_HILOGI("PlayVibratorCustom_011 in");
473     if (IsSupportVibratorCustom()) {
474         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
475         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
476         struct stat64 statbuf = { 0 };
477         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
478             bool flag = SetUsage(USAGE_UNKNOWN);
479             ASSERT_TRUE(flag);
480             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
481             ASSERT_EQ(ret, 0);
482             ret = StartVibratorOnce(500);
483             ASSERT_EQ(ret, 0);
484         }
485         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
486     } else {
487         ASSERT_EQ(0, 0);
488     }
489     Cancel();
490 }
491 
492 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_012, TestSize.Level1)
493 {
494     MISC_HILOGI("PlayVibratorCustom_012 in");
495     if (IsSupportVibratorCustom()) {
496         FileDescriptor fileDescriptor("/data/test/vibrator/test_128_event.json");
497         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
498         struct stat64 statbuf = { 0 };
499         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
500             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
501             ASSERT_EQ(ret, 0);
502         }
503         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
504     } else {
505         ASSERT_EQ(0, 0);
506     }
507     Cancel();
508 }
509 
510 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_013, TestSize.Level1)
511 {
512     MISC_HILOGI("PlayVibratorCustom_013 in");
513     if (IsSupportVibratorCustom()) {
514         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_type.json");
515         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
516         struct stat64 statbuf = { 0 };
517         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
518             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
519             ASSERT_NE(ret, 0);
520         }
521     } else {
522         ASSERT_EQ(0, 0);
523     }
524 }
525 
526 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_014, TestSize.Level1)
527 {
528     MISC_HILOGI("PlayVibratorCustom_014 in");
529     if (IsSupportVibratorCustom()) {
530         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_startTime.json");
531         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
532         struct stat64 statbuf = { 0 };
533         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
534             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
535             ASSERT_NE(ret, 0);
536         }
537     } else {
538         ASSERT_EQ(0, 0);
539     }
540 }
541 
542 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_015, TestSize.Level1)
543 {
544     MISC_HILOGI("PlayVibratorCustom_015 in");
545     if (IsSupportVibratorCustom()) {
546         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_duration.json");
547         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
548         struct stat64 statbuf = { 0 };
549         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
550             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
551             ASSERT_NE(ret, 0);
552         }
553     } else {
554         ASSERT_EQ(0, 0);
555     }
556 }
557 
558 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_016, TestSize.Level1)
559 {
560     MISC_HILOGI("PlayVibratorCustom_016 in");
561     if (IsSupportVibratorCustom()) {
562         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_intensity.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(0, 0);
571     }
572 }
573 
574 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_017, TestSize.Level1)
575 {
576     MISC_HILOGI("PlayVibratorCustom_017 in");
577     if (IsSupportVibratorCustom()) {
578         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_frequency.json");
579         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
580         struct stat64 statbuf = { 0 };
581         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
582             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
583             ASSERT_NE(ret, 0);
584         }
585     } else {
586         ASSERT_EQ(0, 0);
587     }
588 }
589 
590 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_018, TestSize.Level1)
591 {
592     MISC_HILOGI("PlayVibratorCustom_018 in");
593     if (IsSupportVibratorCustom()) {
594         FileDescriptor fileDescriptor("/data/test/vibrator/test_129_event.json");
595         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
596         struct stat64 statbuf = { 0 };
597         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
598             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
599             ASSERT_NE(ret, 0);
600         }
601     } else {
602         ASSERT_EQ(0, 0);
603     }
604 }
605 
606 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_019, TestSize.Level1)
607 {
608     MISC_HILOGI("PlayVibratorCustom_019 in");
609     if (IsSupportVibratorCustom()) {
610         FileDescriptor fileDescriptor("/data/test/vibrator/test_big_file_size.json");
611         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
612         struct stat64 statbuf = { 0 };
613         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
614             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
615             ASSERT_NE(ret, 0);
616         }
617     } else {
618         ASSERT_EQ(0, 0);
619     }
620 }
621 
622 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_020, TestSize.Level1)
623 {
624     MISC_HILOGI("PlayVibratorCustom_020 in");
625     if (IsSupportVibratorCustom()) {
626         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_1.json");
627         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
628         struct stat64 statbuf = { 0 };
629         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
630             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
631             ASSERT_EQ(ret, 0);
632         }
633     } else {
634         ASSERT_EQ(0, 0);
635     }
636     Cancel();
637 }
638 
639 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_021, TestSize.Level1)
640 {
641     MISC_HILOGI("PlayVibratorCustom_021 in");
642     if (IsSupportVibratorCustom()) {
643         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_2.json");
644         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
645         struct stat64 statbuf = { 0 };
646         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
647             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
648             ASSERT_EQ(ret, 0);
649         }
650     } else {
651         ASSERT_EQ(0, 0);
652     }
653     Cancel();
654 }
655 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_022, TestSize.Level1)
656 {
657     MISC_HILOGI("PlayVibratorCustom_022 in");
658     if (IsSupportVibratorCustom()) {
659         FileDescriptor fileDescriptor("/data/test/vibrator/Jet_N2O.he");
660         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
661         struct stat64 statbuf = { 0 };
662         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
663             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
664             ASSERT_EQ(ret, 0);
665         }
666         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
667     } else {
668         ASSERT_EQ(0, 0);
669     }
670     Cancel();
671 }
672 
673 HWTEST_F(VibratorAgentTest, PlayVibratorCustom_023, TestSize.Level1)
674 {
675     MISC_HILOGI("PlayVibratorCustom_023 in");
676     if (IsSupportVibratorCustom()) {
677         FileDescriptor fileDescriptor("/data/test/vibrator/Racing_Start.he");
678         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
679         struct stat64 statbuf = { 0 };
680         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
681             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
682             ASSERT_EQ(ret, 0);
683         }
684         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
685     } else {
686         ASSERT_EQ(0, 0);
687     }
688     Cancel();
689 }
690 
691 HWTEST_F(VibratorAgentTest, SetParameters_001, TestSize.Level1)
692 {
693     MISC_HILOGI("SetParameters_001 in");
694     VibratorParameter parameter = {
695         .intensity = -1,
696         .frequency = -15
697     };
698     bool ret = SetParameters(parameter);
699     ASSERT_FALSE(ret);
700 }
701 
702 HWTEST_F(VibratorAgentTest, SetParameters_002, TestSize.Level1)
703 {
704     MISC_HILOGI("SetParameters_002 in");
705     VibratorParameter parameter = {
706         .intensity = 70,
707         .frequency = 150
708     };
709     bool ret = SetParameters(parameter);
710     ASSERT_FALSE(ret);
711 }
712 
713 HWTEST_F(VibratorAgentTest, SetParameters_003, TestSize.Level1)
714 {
715     MISC_HILOGI("SetParameters_003 in");
716     if (IsSupportVibratorCustom()) {
717         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
718         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
719         struct stat64 statbuf = { 0 };
720         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
721             VibratorParameter parameter = {
722                 .intensity = 50,
723                 .frequency = -15
724             };
725             bool flag = SetParameters(parameter);
726             ASSERT_TRUE(flag);
727             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
728             ASSERT_EQ(ret, 0);
729         }
730         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
731     } else {
732         ASSERT_EQ(0, 0);
733     }
734     Cancel();
735 }
736 
737 HWTEST_F(VibratorAgentTest, SetParameters_004, TestSize.Level1)
738 {
739     MISC_HILOGI("SetParameters_004 in");
740     if (IsSupportVibratorCustom()) {
741         FileDescriptor fileDescriptor("/data/test/vibrator/on_carpet.json");
742         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
743         struct stat64 statbuf = { 0 };
744         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
745             VibratorParameter parameter = {
746                 .intensity = 33,
747                 .frequency = 55
748             };
749             bool flag = SetParameters(parameter);
750             ASSERT_TRUE(flag);
751             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
752             ASSERT_EQ(ret, 0);
753         }
754         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
755     } else {
756         ASSERT_EQ(0, 0);
757     }
758     Cancel();
759 }
760 
761 HWTEST_F(VibratorAgentTest, Cancel_001, TestSize.Level1)
762 {
763     MISC_HILOGI("Cancel_001 in");
764     int32_t ret = Cancel();
765     ASSERT_NE(ret, 0);
766 }
767 
768 HWTEST_F(VibratorAgentTest, Cancel_002, TestSize.Level1)
769 {
770     MISC_HILOGI("Cancel_002 in");
771     if (IsSupportVibratorCustom()) {
772         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
773         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
774         struct stat64 statbuf = { 0 };
775         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
776             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
777             ASSERT_EQ(ret, 0);
778             ret = Cancel();
779             ASSERT_EQ(ret, 0);
780         }
781     } else {
782         ASSERT_EQ(0, 0);
783     }
784 }
785 
786 HWTEST_F(VibratorAgentTest, Cancel_003, TestSize.Level1)
787 {
788     MISC_HILOGI("Cancel_003 in");
789     int32_t ret = StartVibratorOnce(500);
790     ASSERT_EQ(ret, 0);
791     ret = Cancel();
792     ASSERT_EQ(ret, 0);
793 }
794 
795 HWTEST_F(VibratorAgentTest, Cancel_004, TestSize.Level1)
796 {
797     MISC_HILOGI("Cancel_004 in");
798     if (IsSupportVibratorEffect(VIBRATOR_TYPE_FAIL)) {
799         int32_t ret = StartVibrator(VIBRATOR_TYPE_FAIL);
800         ASSERT_EQ(ret, 0);
801         ret = Cancel();
802         ASSERT_EQ(ret, 0);
803     }
804     ASSERT_TRUE(true);
805 }
806 
807 HWTEST_F(VibratorAgentTest, IsSupportEffect_001, TestSize.Level1)
808 {
809     MISC_HILOGI("IsSupportEffect_001 in");
810     bool state { false };
811     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_CLOCK_TIMER, &state);
812     ASSERT_EQ(ret, 0);
813     if (state) {
814         ret = StartVibrator(VIBRATOR_TYPE_CLOCK_TIMER);
815         ASSERT_EQ(ret, 0);
816         Cancel();
817     } else {
818         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_CLOCK_TIMER);
819     }
820 }
821 
822 HWTEST_F(VibratorAgentTest, IsSupportEffect_002, TestSize.Level1)
823 {
824     MISC_HILOGI("IsSupportEffect_002 in");
825     bool state { false };
826     int32_t ret = IsSupportEffect("haptic.xxx.yyy", &state);
827     ASSERT_EQ(ret, 0);
828     ASSERT_FALSE(state);
829 }
830 
831 HWTEST_F(VibratorAgentTest, IsSupportEffect_003, TestSize.Level1)
832 {
833     MISC_HILOGI("IsSupportEffect_003 in");
834     bool state { false };
835     int32_t ret = IsSupportEffect(nullptr, &state);
836     ASSERT_NE(ret, 0);
837     ASSERT_FALSE(state);
838 }
839 
840 HWTEST_F(VibratorAgentTest, IsSupportEffect_004, TestSize.Level1)
841 {
842     MISC_HILOGI("IsSupportEffect_004 in");
843     bool state { false };
844     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_FAIL, &state);
845     ASSERT_EQ(ret, 0);
846     if (state) {
847         ret = StartVibrator(VIBRATOR_TYPE_FAIL);
848         ASSERT_EQ(ret, 0);
849         Cancel();
850     } else {
851         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_FAIL);
852     }
853 }
854 
855 HWTEST_F(VibratorAgentTest, IsSupportEffect_005, TestSize.Level1)
856 {
857     MISC_HILOGI("IsSupportEffect_005 in");
858     bool state { false };
859     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_CHARGING, &state);
860     ASSERT_EQ(ret, 0);
861     if (state) {
862         ret = StartVibrator(VIBRATOR_TYPE_CHARGING);
863         ASSERT_EQ(ret, 0);
864         Cancel();
865     } else {
866         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_CHARGING);
867     }
868 }
869 
870 HWTEST_F(VibratorAgentTest, IsSupportEffect_006, TestSize.Level1)
871 {
872     MISC_HILOGI("IsSupportEffect_006 in");
873     bool state { false };
874     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_LONG_PRESS_HEAVY, &state);
875     ASSERT_EQ(ret, 0);
876     if (state) {
877         ret = StartVibrator(VIBRATOR_TYPE_LONG_PRESS_HEAVY);
878         ASSERT_EQ(ret, 0);
879         Cancel();
880     } else {
881         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_HEAVY);
882     }
883 }
884 
885 HWTEST_F(VibratorAgentTest, IsSupportEffect_007, TestSize.Level1)
886 {
887     MISC_HILOGI("IsSupportEffect_007 in");
888     bool state { false };
889     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_LONG_PRESS_LIGHT, &state);
890     ASSERT_EQ(ret, 0);
891     if (state) {
892         ret = StartVibrator(VIBRATOR_TYPE_LONG_PRESS_LIGHT);
893         ASSERT_EQ(ret, 0);
894         Cancel();
895     } else {
896         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_LIGHT);
897     }
898 }
899 
900 HWTEST_F(VibratorAgentTest, IsSupportEffect_008, TestSize.Level1)
901 {
902     MISC_HILOGI("IsSupportEffect_008 in");
903     bool state { false };
904     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_LONG_PRESS_MEDIUM, &state);
905     ASSERT_EQ(ret, 0);
906     if (state) {
907         ret = StartVibrator(VIBRATOR_TYPE_LONG_PRESS_MEDIUM);
908         ASSERT_EQ(ret, 0);
909         Cancel();
910     } else {
911         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_LONG_PRESS_MEDIUM);
912     }
913 }
914 
915 HWTEST_F(VibratorAgentTest, IsSupportEffect_009, TestSize.Level1)
916 {
917     MISC_HILOGI("IsSupportEffect_009 in");
918     bool state { false };
919     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE_LIGHT, &state);
920     ASSERT_EQ(ret, 0);
921     if (state) {
922         ret = StartVibrator(VIBRATOR_TYPE_SLIDE_LIGHT);
923         ASSERT_EQ(ret, 0);
924         Cancel();
925     } else {
926         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE_LIGHT);
927     }
928 }
929 
930 HWTEST_F(VibratorAgentTest, IsSupportEffect_010, TestSize.Level1)
931 {
932     MISC_HILOGI("IsSupportEffect_010 in");
933     bool state { false };
934     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_THRESHOID, &state);
935     ASSERT_EQ(ret, 0);
936     if (state) {
937         ret = StartVibrator(VIBRATOR_TYPE_THRESHOID);
938         ASSERT_EQ(ret, 0);
939         Cancel();
940     } else {
941         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_THRESHOID);
942     }
943 }
944 
945 HWTEST_F(VibratorAgentTest, GetDelayTime_001, TestSize.Level1)
946 {
947     MISC_HILOGI("GetDelayTime_001 in");
948     if (IsSupportVibratorCustom()) {
949         int32_t delayTime { -1 };
950         int32_t ret = GetDelayTime(delayTime);
951         ASSERT_EQ(ret, 0);
952     } else {
953         ASSERT_EQ(0, 0);
954     }
955 }
956 
957 HWTEST_F(VibratorAgentTest, PreProcess_001, TestSize.Level1)
958 {
959     MISC_HILOGI("PreProcess_001 in");
960     if (IsSupportVibratorCustom()) {
961         FileDescriptor fileDescriptor("invalid_file_name");
962         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
963         VibratorFileDescription vfd;
964         VibratorPackage package;
965         struct stat64 statbuf = { 0 };
966         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
967             vfd.fd = fileDescriptor.fd;
968             vfd.offset = 0;
969             vfd.length = statbuf.st_size;
970             int32_t ret = PreProcess(vfd, package);
971             ASSERT_NE(ret, 0);
972             ret = FreeVibratorPackage(package);
973             ASSERT_NE(ret, 0);
974         } else {
975             ASSERT_EQ(0, 0);
976         }
977     } else {
978         ASSERT_EQ(0, 0);
979     }
980 }
981 
982 HWTEST_F(VibratorAgentTest, PreProcess_002, TestSize.Level1)
983 {
984     MISC_HILOGI("PreProcess_002 in");
985     if (IsSupportVibratorCustom()) {
986         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_duration.json");
987         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
988         VibratorFileDescription vfd;
989         VibratorPackage package;
990         struct stat64 statbuf = { 0 };
991         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
992             vfd.fd = fileDescriptor.fd;
993             vfd.offset = 0;
994             vfd.length = statbuf.st_size;
995             int32_t ret = PreProcess(vfd, package);
996             ASSERT_NE(ret, 0);
997             ret = FreeVibratorPackage(package);
998             ASSERT_NE(ret, 0);
999         } else {
1000             ASSERT_FALSE(true);
1001         }
1002     } else {
1003         ASSERT_EQ(0, 0);
1004     }
1005 }
1006 
1007 HWTEST_F(VibratorAgentTest, PreProcess_003, TestSize.Level1)
1008 {
1009     MISC_HILOGI("PreProcess_003 in");
1010     if (IsSupportVibratorCustom()) {
1011         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_frequency.json");
1012         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1013         VibratorFileDescription vfd;
1014         VibratorPackage package;
1015         struct stat64 statbuf = { 0 };
1016         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1017             vfd.fd = fileDescriptor.fd;
1018             vfd.offset = 0;
1019             vfd.length = statbuf.st_size;
1020             int32_t ret = PreProcess(vfd, package);
1021             ASSERT_NE(ret, 0);
1022             ret = FreeVibratorPackage(package);
1023             ASSERT_NE(ret, 0);
1024         } else {
1025             ASSERT_FALSE(true);
1026         }
1027     } else {
1028         ASSERT_EQ(0, 0);
1029     }
1030 }
1031 
1032 HWTEST_F(VibratorAgentTest, PreProcess_004, TestSize.Level1)
1033 {
1034     MISC_HILOGI("PreProcess_004 in");
1035     if (IsSupportVibratorCustom()) {
1036         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_intensity.json");
1037         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1038         VibratorFileDescription vfd;
1039         VibratorPackage package;
1040         struct stat64 statbuf = { 0 };
1041         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1042             vfd.fd = fileDescriptor.fd;
1043             vfd.offset = 0;
1044             vfd.length = statbuf.st_size;
1045             int32_t ret = PreProcess(vfd, package);
1046             ASSERT_NE(ret, 0);
1047             ret = FreeVibratorPackage(package);
1048             ASSERT_NE(ret, 0);
1049         } else {
1050             ASSERT_FALSE(true);
1051         }
1052     } else {
1053         ASSERT_EQ(0, 0);
1054     }
1055 }
1056 
1057 HWTEST_F(VibratorAgentTest, PreProcess_005, TestSize.Level1)
1058 {
1059     MISC_HILOGI("PreProcess_005 in");
1060     if (IsSupportVibratorCustom()) {
1061         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_startTime.json");
1062         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1063         VibratorFileDescription vfd;
1064         VibratorPackage package;
1065         struct stat64 statbuf = { 0 };
1066         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1067             vfd.fd = fileDescriptor.fd;
1068             vfd.offset = 0;
1069             vfd.length = statbuf.st_size;
1070             int32_t ret = PreProcess(vfd, package);
1071             ASSERT_NE(ret, 0);
1072             ret = FreeVibratorPackage(package);
1073             ASSERT_NE(ret, 0);
1074         } else {
1075             ASSERT_FALSE(true);
1076         }
1077     } else {
1078         ASSERT_EQ(0, 0);
1079     }
1080 }
1081 
1082 HWTEST_F(VibratorAgentTest, PreProcess_006, TestSize.Level1)
1083 {
1084     MISC_HILOGI("PreProcess_006 in");
1085     if (IsSupportVibratorCustom()) {
1086         FileDescriptor fileDescriptor("/data/test/vibrator/test_invalid_type.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(0, 0);
1104     }
1105 }
1106 
1107 HWTEST_F(VibratorAgentTest, PreProcess_007, TestSize.Level1)
1108 {
1109     MISC_HILOGI("PreProcess_007 in");
1110     if (IsSupportVibratorCustom()) {
1111         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_1.json");
1112         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1113         VibratorFileDescription vfd;
1114         VibratorPackage package;
1115         struct stat64 statbuf = { 0 };
1116         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1117             vfd.fd = fileDescriptor.fd;
1118             vfd.offset = 0;
1119             vfd.length = statbuf.st_size;
1120             int32_t ret = PreProcess(vfd, package);
1121             ASSERT_EQ(ret, 0);
1122             ret = FreeVibratorPackage(package);
1123             ASSERT_EQ(ret, 0);
1124         } else {
1125             ASSERT_FALSE(true);
1126         }
1127     } else {
1128         ASSERT_EQ(0, 0);
1129     }
1130 }
1131 
1132 HWTEST_F(VibratorAgentTest, PreProcess_008, TestSize.Level1)
1133 {
1134     MISC_HILOGI("PreProcess_008 in");
1135     if (IsSupportVibratorCustom()) {
1136         FileDescriptor fileDescriptor("/data/test/vibrator/test_event_overlap_2.json");
1137         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1138         VibratorFileDescription vfd;
1139         VibratorPackage package;
1140         struct stat64 statbuf = { 0 };
1141         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1142             vfd.fd = fileDescriptor.fd;
1143             vfd.offset = 0;
1144             vfd.length = statbuf.st_size;
1145             int32_t ret = PreProcess(vfd, package);
1146             ASSERT_EQ(ret, 0);
1147             ret = FreeVibratorPackage(package);
1148             ASSERT_EQ(ret, 0);
1149         } else {
1150             ASSERT_FALSE(true);
1151         }
1152     } else {
1153         ASSERT_EQ(0, 0);
1154     }
1155 }
1156 
1157 HWTEST_F(VibratorAgentTest, PreProcess_009, TestSize.Level1)
1158 {
1159     MISC_HILOGI("PreProcess_009 in");
1160     if (IsSupportVibratorCustom()) {
1161         FileDescriptor fileDescriptor("/data/test/vibrator/test_129_event.json");
1162         MISC_HILOGD("fd:%{public}d", fileDescriptor.fd);
1163         VibratorFileDescription vfd;
1164         VibratorPackage package;
1165         struct stat64 statbuf = { 0 };
1166         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1167             vfd.fd = fileDescriptor.fd;
1168             vfd.offset = 0;
1169             vfd.length = statbuf.st_size;
1170             int32_t ret = PreProcess(vfd, package);
1171             ASSERT_NE(ret, 0);
1172             ret = FreeVibratorPackage(package);
1173             ASSERT_NE(ret, 0);
1174         } else {
1175             ASSERT_FALSE(true);
1176         }
1177     } else {
1178         ASSERT_EQ(0, 0);
1179     }
1180 }
1181 
1182 HWTEST_F(VibratorAgentTest, PlayPattern_001, TestSize.Level1)
1183 {
1184     MISC_HILOGI("PlayPattern_001 in");
1185     if (IsSupportVibratorCustom()) {
1186         int32_t delayTime { -1 };
1187         int32_t ret = GetDelayTime(delayTime);
1188         ASSERT_EQ(ret, 0);
1189         MISC_HILOGD("delayTime:%{public}d", delayTime);
1190         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.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             ret = PreProcess(vfd, package);
1200             ASSERT_EQ(ret, 0);
1201             for (int32_t i = 0; i < package.patternNum; ++i) {
1202                 if (i == 0) {
1203                     std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time));
1204                 } else {
1205                     std::this_thread::sleep_for(std::chrono::milliseconds(package.patterns[i].time) -
1206                         std::chrono::milliseconds(package.patterns[i - 1].time));
1207                 }
1208                 ASSERT_EQ(SetUsage(USAGE_UNKNOWN), true);
1209                 MISC_HILOGD("pointNum:%{public}d", package.patterns[i].events[i].pointNum);
1210                 ret = PlayPattern(package.patterns[i]);
1211                 ASSERT_EQ(ret, 0);
1212             }
1213         }
1214         ret = FreeVibratorPackage(package);
1215         ASSERT_EQ(ret, 0);
1216         Cancel();
1217     } else {
1218         ASSERT_EQ(0, 0);
1219     }
1220 }
1221 
1222 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_001, TestSize.Level1)
1223 {
1224     MISC_HILOGI("PlayPrimitiveEffect_001 in");
1225     int32_t ret = PlayPrimitiveEffect(nullptr, INTENSITY_HIGH);
1226     ASSERT_EQ(ret, PARAMETER_ERROR);
1227 }
1228 
1229 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_002, TestSize.Level1)
1230 {
1231     MISC_HILOGI("PlayPrimitiveEffect_002 in");
1232     bool state { false };
1233     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1234     ASSERT_EQ(ret, 0);
1235     if (state) {
1236         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_INVALID);
1237         ASSERT_EQ(ret, PARAMETER_ERROR);
1238     } else {
1239         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1240     }
1241 }
1242 
1243 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_003, TestSize.Level1)
1244 {
1245     MISC_HILOGI("PlayPrimitiveEffect_003 in");
1246     bool state { false };
1247     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1248     ASSERT_EQ(ret, 0);
1249     if (state) {
1250         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_LOW);
1251         ASSERT_EQ(ret, 0);
1252         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1253         Cancel();
1254     } else {
1255         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1256     }
1257 }
1258 
1259 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_004, TestSize.Level1)
1260 {
1261     MISC_HILOGI("PlayPrimitiveEffect_004 in");
1262     bool state { false };
1263     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1264     ASSERT_EQ(ret, 0);
1265     if (state) {
1266         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_MEDIUM);
1267         ASSERT_EQ(ret, 0);
1268         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1269         Cancel();
1270     } else {
1271         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1272     }
1273 }
1274 
1275 HWTEST_F(VibratorAgentTest, PlayPrimitiveEffect_005, TestSize.Level1)
1276 {
1277     MISC_HILOGI("PlayPrimitiveEffect_005 in");
1278     bool state { false };
1279     int32_t ret = IsSupportEffect(VIBRATOR_TYPE_SLIDE, &state);
1280     ASSERT_EQ(ret, 0);
1281     if (state) {
1282         ret = PlayPrimitiveEffect(VIBRATOR_TYPE_SLIDE, INTENSITY_HIGH);
1283         ASSERT_EQ(ret, 0);
1284         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1285         Cancel();
1286     } else {
1287         MISC_HILOGI("Do not support %{public}s", VIBRATOR_TYPE_SLIDE);
1288     }
1289 }
1290 
1291 HWTEST_F(VibratorAgentTest, IsHdHapticSupported_001, TestSize.Level1)
1292 {
1293     MISC_HILOGI("IsHdHapticSupported_001 in");
1294     if (IsSupportVibratorCustom() && IsHdHapticSupported()) {
1295         FileDescriptor fileDescriptor("/data/test/vibrator/coin_drop.json");
1296         MISC_HILOGD("Test fd:%{public}d", fileDescriptor.fd);
1297         struct stat64 statbuf = { 0 };
1298         if (fstat64(fileDescriptor.fd, &statbuf) == 0) {
1299             int32_t ret = PlayVibratorCustom(fileDescriptor.fd, 0, statbuf.st_size);
1300             ASSERT_EQ(ret, 0);
1301         }
1302         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1303     } else {
1304         ASSERT_EQ(0, 0);
1305     }
1306     Cancel();
1307 }
1308 } // namespace Sensors
1309 } // namespace OHOS
1310