• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "edm_errors.h"
17 #include "event_config.h"
18 #include "hilog_wrapper.h"
19 #include "notification_locale.h"
20 #include "notification_peripheral.h"
21 #include <gtest/gtest.h>
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace ExternalDeviceManager {
27 class DeviceNotificationTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase(void)35 void DeviceNotificationTest::SetUpTestCase(void) {}
TearDownTestCase(void)36 void DeviceNotificationTest::TearDownTestCase(void) {}
SetUp(void)37 void DeviceNotificationTest::SetUp(void) {}
TearDown(void)38 void DeviceNotificationTest::TearDown(void) {}
39 
40 /**
41  * @tc.name: HandleNotification001
42  * @tc.desc: Test HandleNotification
43  * @tc.type: FUNC
44  */
45 HWTEST_F(DeviceNotificationTest, HandleNotification001, TestSize.Level1)
46 {
47     DeviceNotification &perNotification = DeviceNotification::GetInstance();
48     FaultInfo faultInfo;
49     EXPECT_FALSE(perNotification.HandleNotification(faultInfo));
50 }
51 
52 /**
53  * @tc.name: PeripheralDeviceNotification001
54  * @tc.desc: Test PeripheralDeviceNotification
55  * @tc.type: FUNC
56  */
57 HWTEST_F(DeviceNotificationTest, PeripheralDeviceNotification001, TestSize.Level1)
58 {
59     DeviceNotification &perNotification = DeviceNotification::GetInstance();
60     FaultInfo faultInfo;
61     EXPECT_FALSE(perNotification.PeripheralDeviceNotification(faultInfo));
62 }
63 
64 /**
65  * @tc.name: GetPixelMap001
66  * @tc.desc: Test GetPixelMap
67  * @tc.type: FUNC
68  */
69 HWTEST_F(DeviceNotificationTest, GetPixelMap001, TestSize.Level1)
70 {
71     DeviceNotification &perNotification = DeviceNotification::GetInstance();
72     std::string path = "";
73     perNotification.GetPixelMap(path);
74     EXPECT_FALSE(std::filesystem::exists(path)) << "Test file does not exist: " << path;
75 }
76 
77 /**
78  * @tc.name: GetPixelMap002
79  * @tc.desc: Test GetPixelMap
80  * @tc.type: FUNC
81  */
82 HWTEST_F(DeviceNotificationTest, GetPixelMap002, TestSize.Level1)
83 {
84     DeviceNotification &perNotification = DeviceNotification::GetInstance();
85     perNotification.iconPixelMap_ = std::make_unique<Media::PixelMap>();
86     std::string path = "/system/etc/peripheral/resources/peripheral_fault_icon.png";
87     perNotification.GetPixelMap(path);
88     EXPECT_TRUE(std::filesystem::exists(path)) << "Test file exist: " << path;
89 }
90 
91 /**
92  * @tc.name: FillNotificationCfg001
93  * @tc.desc: Test FillNotificationCfg
94  * @tc.type: FUNC
95  */
96 HWTEST_F(DeviceNotificationTest, FillNotificationCfg001, TestSize.Level1)
97 {
98     DeviceNotification &perNotification = DeviceNotification::GetInstance();
99     FaultInfo faultInfo;
100     faultInfo.title = "";
101     faultInfo.msg = "";
102     faultInfo.uri = "";
103     FaultInfo result = perNotification.FillNotificationCfg(faultInfo);
104     EXPECT_TRUE(result.title.empty());
105     EXPECT_TRUE(result.msg.empty());
106     EXPECT_TRUE(result.uri.empty());
107 }
108 
109 /**
110  * @tc.name: FillNotificationCfg002
111  * @tc.desc: Test FillNotificationCfg
112  * @tc.type: FUNC
113  */
114 HWTEST_F(DeviceNotificationTest, FillNotificationCfg002, TestSize.Level1)
115 {
116     DeviceNotification &perNotification = DeviceNotification::GetInstance();
117     FaultInfo faultInfo;
118     faultInfo.title = "usb_transmission_error_title";
119     faultInfo.msg = "usb_troubleshoot_message";
120     faultInfo.uri = "www.gitee.com";
121     NotificationLocale &perLocale = NotificationLocale::GetInstance();
122     perLocale.stringMap_["usb_transmission_error_title"] = faultInfo.title;
123     perLocale.stringMap_["usb_troubleshoot_message"] = faultInfo.msg;
124     perLocale.stringMap_["www.gitee.com"] = faultInfo.uri;
125     perLocale.stringMap_["usb_transmission_error_title"] = faultInfo.title;
126 
127     FaultInfo result = perNotification.FillNotificationCfg(faultInfo);
128     EXPECT_EQ(result.title, "usb_transmission_error_title");
129     EXPECT_EQ(result.msg, "usb_troubleshoot_message");
130     EXPECT_EQ(result.uri, "www.gitee.com");
131 }
132 } // namespace ExternalDeviceManager
133 } // namespace OHOS
134