1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include <gmock/gmock.h> 18 19 #include "device_config_file_parser.h" 20 21 namespace OHOS { 22 namespace MMI { 23 namespace { 24 using namespace testing::ext; 25 } // namespace 26 27 class DeviceConfigFileParserTest : public testing::Test { 28 public: SetUpTestCase(void)29 static void SetUpTestCase(void) {} TearDownTestCase(void)30 static void TearDownTestCase(void) {} 31 }; 32 33 class MockLibinputDevice { 34 public: libinput_device_get_id_vendor() const35 virtual uint32_t libinput_device_get_id_vendor() const { return 123; } libinput_device_get_id_product() const36 virtual uint32_t libinput_device_get_id_product() const { return 456; } libinput_device_get_id_version() const37 virtual uint32_t libinput_device_get_id_version() const { return 789; } LibinputDeviceGetName() const38 virtual const char* LibinputDeviceGetName() const { return "MockDevice"; } 39 }; 40 41 /** 42 * @tc.name: DeviceConfigFileParserTest_CombDeviceFileName_001 43 * @tc.desc: Test the function CombDeviceFileName 44 * @tc.type: FUNC 45 * @tc.require: 46 */ 47 HWTEST_F(DeviceConfigFileParserTest, DeviceConfigFileParserTest_CombDeviceFileName_001, TestSize.Level1) 48 { 49 DeviceConfigManagement configManager; 50 struct libinput_device *device = nullptr; 51 std::string fileName = configManager.CombDeviceFileName(device); 52 EXPECT_NE(fileName, "63373_13888_63373_x"); 53 } 54 55 /** 56 * @tc.name: DeviceConfigFileParserTest_ConfigItemName2Id_001 57 * @tc.desc: Test the function ConfigItemName2Id 58 * @tc.type: FUNC 59 * @tc.require: 60 */ 61 HWTEST_F(DeviceConfigFileParserTest, DeviceConfigFileParserTest_ConfigItemName2Id_001, TestSize.Level1) 62 { 63 DeviceConfigManagement configManager; 64 ConfigFileItem ret = configManager.ConfigItemName2Id("speed"); 65 EXPECT_EQ(ret, ConfigFileItem::POINTER_SPEED); 66 ret = configManager.ConfigItemName2Id("invalid_name"); 67 EXPECT_EQ(ret, ConfigFileItem::INVALID); 68 } 69 70 /** 71 * @tc.name: DeviceConfigFileParserTest_ReadConfigFile_001 72 * @tc.desc: Test the function ReadConfigFile 73 * @tc.type: FUNC 74 * @tc.require: 75 */ 76 HWTEST_F(DeviceConfigFileParserTest, DeviceConfigFileParserTest_ReadConfigFile_001, TestSize.Level1) 77 { 78 DeviceConfigManagement configManager; 79 std::map<ConfigFileItem, int32_t> configList = configManager.ReadConfigFile("empty.txt"); 80 EXPECT_TRUE(configList.empty()); 81 configList = configManager.ReadConfigFile("comment.cfg"); 82 EXPECT_TRUE(configList.empty()); 83 configList = configManager.ReadConfigFile("no_valid_line.txt"); 84 EXPECT_TRUE(configList.empty()); 85 configList = configManager.ReadConfigFile("valid.cfg"); 86 EXPECT_TRUE(configList.empty()); 87 } 88 89 /** 90 * @tc.name: DeviceConfigFileParserTest_GetVendorConfig_002 91 * @tc.desc: Test the function GetVendorConfig 92 * @tc.type: FUNC 93 * @tc.require: 94 */ 95 HWTEST_F(DeviceConfigFileParserTest, DeviceConfigFileParserTest_GetVendorConfig_002, TestSize.Level1) 96 { 97 DeviceConfigManagement configManager; 98 struct libinput_device *device = nullptr; 99 VendorConfig vendorconfig = configManager.GetVendorConfig(device); 100 EXPECT_EQ(vendorconfig.pointerSpeed, -1); 101 } 102 } // namespace MMI 103 } // namespace OHOS