1 /* 2 * Copyright (c) 2022-2023 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<map> 17 #include <gtest/gtest.h> 18 #include "hdf_base.h" 19 #include "vibrator_common.h" 20 #include "vibrator_parse.h" 21 22 #define HDF_LOG_TAG "hdi_vibrator_parse_test" 23 24 using namespace OHOS::HDI::Vibrator::V1_1; 25 using namespace testing::ext; 26 27 namespace { 28 const std::string DEVICETYPE_KEY = "const.product.devicetype"; 29 const std::string DEVICETYPE_TYPE = "phone"; 30 sptr<IVibratorInterface> g_vibratorInterface = nullptr; 31 } 32 33 class HatsHdfVibratorParseTest : public testing::Test { 34 public: 35 SetUp()36 virtual void SetUp() {} TearDown()37 virtual void TearDown() {} 38 }; 39 static const std::map<int32_t, int32_t> EFFECT_TIMES = { 40 {32, 14}, {33, 14}, {34, 14}, {35, 14}, 41 {36, 17}, {37, 17}, {38, 17}, {39, 17}, 42 {40, 11}, {41, 11}, {42, 11}, {43, 11}, 43 {44, 7}, {45, 7}, {46, 7}, {47, 7}, 44 {48, 22}, {49, 22}, {50, 22}, {51, 22}, 45 {52, 15}, {53, 15}, {54, 15}, {55, 15}, 46 {56, 27}, {57, 27}, {58, 27}, {59, 27}, 47 {60, 10}, {61, 10}, {62, 10}, {63, 10}, 48 {64, 10}, {65, 10}, {66, 10}, {67, 10}, 49 {68, 50}, {69, 50}, {70, 50}, {71, 50}, 50 {72, 10}, {73, 10}, {74, 10}, {75, 10}, 51 {76, 15}, {77, 15}, {78, 15}, {79, 15}, 52 {80, 20}, {81, 20}, {82, 20}, {83, 20}, 53 {84, 28}, {85, 28}, {86, 28}, {87, 28}, 54 {88, 15}, {89, 15}, {90, 15}, {91, 15}, 55 {92, 19}, {93, 19}, {94, 19}, {95, 19}, 56 {96, 10}, {97, 10}, {98, 10}, {99, 10}, 57 {100, 20}, {101, 20}, {102, 20}, {103, 20}, 58 {107, 1500}, {108, 25}, {109, 30}, {110, 35}, 59 {111, 40}, {112, 45}, {113, 50}, {114, 55}, 60 {115, 60}, {116, 65}, {117, 70}, {118, 75}, 61 {119, 80}, {120, 85}, {121, 90}, {122, 95}, 62 {123, 100}, {124, 105}, {125, 110}, {126, 115}, 63 {127, 120}, {128, 1500}, {129, 1500}, {130, 1500}, 64 {131, 1500}, {132, 1500}, {133, 1500}, {134, 1500}, {135, 1500} 65 }; 66 67 /** 68 * @tc.name: VibratorParseTest001 69 * @tc.desc: Parse and verify all haptic effects. 70 * @tc.type: FUNC 71 */ 72 HWTEST_F(HatsHdfVibratorParseTest, SUB_Vibrator_HDI_VibratorParseTest_0010, Function | MediumTest | Level1) 73 { 74 HapticMap haptics; 75 int ret = ParserHapticsXml(haptics); 76 EXPECT_EQ(ret, HDF_SUCCESS); 77 if (!haptics.effectContainer.empty()) 78 { 79 EffectMap::iterator iter = haptics.effectContainer.begin(); 80 for (;iter != haptic.effectContainer.end();iter++) { 81 for (unsigned long i = 0;i<iter->second.EffectSeq.size();i++) { 82 } 83 } 84 } 85 if (!haptic.parContainer.empty()) { 86 ParaMap::iterator iter = haptics.paraContainer.begin(); 87 for (;iter != haptic.paraContainer.end();iter++) { 88 } 89 } 90 } 91 92 /** 93 * @tc.name: VibratorParseTest002 94 * @tc.desc: Parse and verify all haptic effects. 95 * @tc.type: FUNC 96 */ 97 HWTEST_F(HatsHdfVibratorParseTest, SUB_Vibrator_HDI_VibratorParseTest_0020, Function | MediumTest | Level1) 98 { 99 HapticMap haptics; 100 int ret = ParserHapticsXml(haptics); 101 EXPECT_EQ(ret, HDF_SUCCESS); 102 if (!haptics.effectContainer.empty()) 103 { 104 EffectMap::iterator iter = haptics.effectContainer.begin(); 105 for (;iter != haptic.effectContainer.end();iter++) { 106 int32_t seqType = iter -> second.SeqType; 107 int32_t duration = iter -> second.duration; 108 int32_t sum {0}; 109 size_t count = iter -> second.EffectSeq.size(); 110 for (size_t i = 0;i<count;i++) { 111 } 112 EXPECT_EQ(duration, sum); 113 } 114 } 115 } 116 117