• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #include "screen_common_test.h"
16 
17 #include "dscreen_errcode.h"
18 #include "dscreen_hisysevent.h"
19 #include "dscreen_json_util.h"
20 #include "dscreen_log.h"
21 #include "dscreen_util.h"
22 #include "parameter.h"
23 #include "softbus_bus_center.h"
24 
25 using namespace testing::ext;
26 static int g_mockGetLocalNodeDeviceInfoReturnInt32Value = -1;
27 static int g_mockGetParameterReturnIntValue = -1;
28 
29 namespace OHOS {
30 namespace DistributedHardware {
SetUpTestCase(void)31 void ScreenCommonTest::SetUpTestCase(void) {}
32 
TearDownTestCase(void)33 void ScreenCommonTest::TearDownTestCase(void) {}
34 
SetUp()35 void ScreenCommonTest::SetUp() {}
36 
TearDown()37 void ScreenCommonTest::TearDown() {}
38 
39 /**
40  * @tc.name: common_001
41  * @tc.desc: Verify the common function.
42  * @tc.type: FUNC
43  * @tc.require: Issue Number
44  */
45 HWTEST_F(ScreenCommonTest, common_001, TestSize.Level1)
46 {
47     DHLOGW("common_001.");
48     std::string networkId = "networkId";
49     g_mockGetLocalNodeDeviceInfoReturnInt32Value = -1;
50     int32_t ret = GetLocalDeviceNetworkId(networkId);
51     EXPECT_NE(DH_SUCCESS, ret);
52 }
53 
54 /**
55  * @tc.name: common_002
56  * @tc.desc: Verify the common function.
57  * @tc.type: FUNC
58  * @tc.require: Issue Number
59  */
60 HWTEST_F(ScreenCommonTest, common_002, TestSize.Level1)
61 {
62     DHLOGW("common_002.");
63     std::string networkId = "networkId";
64     g_mockGetLocalNodeDeviceInfoReturnInt32Value = DH_SUCCESS;
65     int32_t ret = GetLocalDeviceNetworkId(networkId);
66     EXPECT_EQ(DH_SUCCESS, ret);
67 }
68 
69 /**
70  * @tc.name: common_003
71  * @tc.desc: Verify the common function.
72  * @tc.type: FUNC
73  * @tc.require: Issue Number
74  */
75 HWTEST_F(ScreenCommonTest, common_003, TestSize.Level1)
76 {
77     DHLOGW("common_003.");
78     ReportSaFail(eventName, errCode, saId, errMsg);
79     ReportSaFail(eventName, errCode, saId, errMsg);
80     ReportRegisterFail(eventName, errCode, devId, dhId, errMsg);
81     ReportUnRegisterFail(eventName, errCode, devId, dhId, errMsg);
82     ReportOptFail(eventName, errCode, errMsg);
83     ReportSaEvent(eventName, saId, errMsg);
84     ReportRegisterScreenEvent(eventName, devId, dhId, errMsg);
85     ReportUnRegisterScreenEvent(eventName, devId, dhId, errMsg);
86     ReportScreenMirrorEvent(eventName, devId, dhId, errMsg);
87     ReportSaFail(longEventName, errCode, saId, errMsg);
88     ReportSaFail(longEventName, errCode, saId, errMsg);
89     ReportRegisterFail(longEventName, errCode, devId, dhId, errMsg);
90     ReportUnRegisterFail(longEventName, errCode, devId, dhId, errMsg);
91     ReportOptFail(longEventName, errCode, errMsg);
92     ReportSaEvent(longEventName, saId, errMsg);
93     ReportRegisterScreenEvent(longEventName, devId, dhId, errMsg);
94     ReportUnRegisterScreenEvent(longEventName, devId, dhId, errMsg);
95     ReportScreenMirrorEvent(longEventName, devId, dhId, errMsg);
96     std::string value = "Id";
97     std::string ret = GetAnonyString(value);
98     EXPECT_EQ("******", ret);
99 }
100 
101 /**
102  * @tc.name: common_004
103  * @tc.desc: Verify the common function.
104  * @tc.type: FUNC
105  * @tc.require: Issue Number
106  */
107 HWTEST_F(ScreenCommonTest, common_004, TestSize.Level1)
108 {
109     DHLOGW("common_004.");
110     std::string value = "Id";
111     std::string ret = GetInterruptString(value);
112     EXPECT_EQ(value, ret);
113 }
114 
115 /**
116  * @tc.name: common_005
117  * @tc.desc: Verify the common function.
118  * @tc.type: FUNC
119  * @tc.require: Issue Number
120  */
121 HWTEST_F(ScreenCommonTest, common_005, TestSize.Level1)
122 {
123     DHLOGW("common_005.");
124     std::string value = "Idvalues";
125     std::string ret = GetInterruptString(value);
126     EXPECT_EQ("Idva", ret);
127 }
128 
129 /**
130  * @tc.name: IsInt64_001
131  * @tc.desc: Verify the IsInt64 function.
132  * @tc.type: FUNC
133  * @tc.require: Issue Number
134  */
135 HWTEST_F(ScreenCommonTest, IsInt64_001, TestSize.Level1)
136 {
137     nlohmann::json testJson;
138     std::string key = "test";
139     EXPECT_FALSE(IsInt64(testJson, key));
140 
141     testJson[key] = "test";
142     EXPECT_FALSE(IsInt64(testJson, key));
143 
144     testJson[key] = 1;
145     EXPECT_TRUE(IsInt64(testJson, key));
146 }
147 
148 /**
149  * @tc.name: IsArray_001
150  * @tc.desc: Verify the IsArray function.
151  * @tc.type: FUNC
152  * @tc.require: Issue Number
153  */
154 HWTEST_F(ScreenCommonTest, IsArray_001, TestSize.Level1)
155 {
156     nlohmann::json testJson;
157     std::string key = "test";
158     EXPECT_FALSE(IsArray(testJson, key));
159 
160     testJson[key] = "test";
161     EXPECT_FALSE(IsArray(testJson, key));
162 
163     testJson[key] = {1, 2, 3};
164     EXPECT_TRUE(IsArray(testJson, key));
165 }
166 
167 /**
168  * @tc.name: IsPartialRefreshEnabled_001
169  * @tc.desc: Verify the IsPartialRefreshEnabled function.
170  * @tc.type: FUNC
171  * @tc.require: Issue Number
172  */
173 HWTEST_F(ScreenCommonTest, IsPartialRefreshEnabled_001, TestSize.Level1)
174 {
175     g_mockGetParameterReturnIntValue = 1;
176     EXPECT_FALSE(IsPartialRefreshEnabled());
177     g_mockGetParameterReturnIntValue = -1;
178     EXPECT_FALSE(IsPartialRefreshEnabled());
179 }
180 
181 /**
182  * @tc.name: IsSupportAVTransEngine_001
183  * @tc.desc: Verify the IsSupportAVTransEngine function.
184  * @tc.type: FUNC
185  * @tc.require: Issue Number
186  */
187 HWTEST_F(ScreenCommonTest, IsSupportAVTransEngine_001, TestSize.Level1)
188 {
189     std::string version = "2";
190     EXPECT_FALSE(IsSupportAVTransEngine(version));
191 
192     version = "3";
193     g_mockGetParameterReturnIntValue = 1;
194     EXPECT_TRUE(IsSupportAVTransEngine(version));
195 
196     g_mockGetParameterReturnIntValue = -1;
197     EXPECT_TRUE(IsSupportAVTransEngine(version));
198 }
199 } // namespace DistributedHardware
200 } // namespace OHOS
201 
GetLocalNodeDeviceInfo(const char * pkgName,NodeBasicInfo * info)202 extern "C" __attribute__((constructor)) int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info)
203 {
204     return g_mockGetLocalNodeDeviceInfoReturnInt32Value;
205 }
206 
GetParameter(const char * key,const char * def,char * value,unsigned int len)207 extern "C" __attribute__((constructor)) int GetParameter(const char *key, const char *def,
208     char *value, unsigned int len)
209 {
210     return g_mockGetParameterReturnIntValue;
211 }
212