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_ConfigItemName2Id_001
43  * @tc.desc: Test the function ConfigItemName2Id
44  * @tc.type: FUNC
45  * @tc.require:
46  */
47 HWTEST_F(DeviceConfigFileParserTest, DeviceConfigFileParserTest_ConfigItemName2Id_001, TestSize.Level1)
48 {
49     DeviceConfigManagement configManager;
50     ConfigFileItem ret = configManager.ConfigItemName2Id("speed");
51     EXPECT_EQ(ret, ConfigFileItem::POINTER_SPEED);
52     ret = configManager.ConfigItemName2Id("invalid_name");
53     EXPECT_EQ(ret, ConfigFileItem::INVALID);
54 }
55 
56 /**
57  * @tc.name: DeviceConfigFileParserTest_ReadConfigFile_001
58  * @tc.desc: Test the function ReadConfigFile
59  * @tc.type: FUNC
60  * @tc.require:
61  */
62 HWTEST_F(DeviceConfigFileParserTest, DeviceConfigFileParserTest_ReadConfigFile_001, TestSize.Level1)
63 {
64     DeviceConfigManagement configManager;
65     std::map<ConfigFileItem, int32_t> configList = configManager.ReadConfigFile("empty.txt");
66     EXPECT_TRUE(configList.empty());
67     configList = configManager.ReadConfigFile("comment.cfg");
68     EXPECT_TRUE(configList.empty());
69     configList = configManager.ReadConfigFile("no_valid_line.txt");
70     EXPECT_TRUE(configList.empty());
71     configList = configManager.ReadConfigFile("valid.cfg");
72     EXPECT_TRUE(configList.empty());
73 }
74 
75 /**
76  * @tc.name: DeviceConfigFileParserTest_GetVendorConfig_002
77  * @tc.desc: Test the function GetVendorConfig
78  * @tc.type: FUNC
79  * @tc.require:
80  */
81 HWTEST_F(DeviceConfigFileParserTest, DeviceConfigFileParserTest_GetVendorConfig_002, TestSize.Level1)
82 {
83     DeviceConfigManagement configManager;
84     struct libinput_device *device = nullptr;
85     VendorConfig vendorconfig = configManager.GetVendorConfig(device);
86     EXPECT_EQ(vendorconfig.pointerSpeed, -1);
87 }
88 } // namespace MMI
89 } // namespace OHOS