1 /*
2 * Copyright (c) 2022-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 #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
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace DistributedHardware {
SetUpTestCase(void)27 void ScreenCommonTest::SetUpTestCase(void) {}
28
TearDownTestCase(void)29 void ScreenCommonTest::TearDownTestCase(void) {}
30
SetUp()31 void ScreenCommonTest::SetUp() {}
32
TearDown()33 void ScreenCommonTest::TearDown() {}
34
35 /**
36 * @tc.name: common_001
37 * @tc.desc: Verify the common function.
38 * @tc.type: FUNC
39 * @tc.require: Issue Number
40 */
41 HWTEST_F(ScreenCommonTest, common_001, TestSize.Level1)
42 {
43 DHLOGW("common_001.");
44 std::string networkId = "networkId";
45 int32_t ret = GetLocalDeviceNetworkId(networkId);
46 EXPECT_NE(DH_SUCCESS, ret);
47 }
48
49 /**
50 * @tc.name: common_002
51 * @tc.desc: Verify the common function.
52 * @tc.type: FUNC
53 * @tc.require: Issue Number
54 */
55 HWTEST_F(ScreenCommonTest, common_002, TestSize.Level1)
56 {
57 DHLOGW("common_002.");
58 ReportSaFail(eventName, errCode, saId, errMsg);
59 ReportSaFail(eventName, errCode, saId, errMsg);
60 ReportRegisterFail(eventName, errCode, devId, dhId, errMsg);
61 ReportUnRegisterFail(eventName, errCode, devId, dhId, errMsg);
62 ReportOptFail(eventName, errCode, errMsg);
63 ReportSaEvent(eventName, saId, errMsg);
64 ReportRegisterScreenEvent(eventName, devId, dhId, errMsg);
65 ReportUnRegisterScreenEvent(eventName, devId, dhId, errMsg);
66 ReportScreenMirrorEvent(eventName, devId, dhId, errMsg);
67 ReportSaFail(longEventName, errCode, saId, errMsg);
68 ReportSaFail(longEventName, errCode, saId, errMsg);
69 ReportRegisterFail(longEventName, errCode, devId, dhId, errMsg);
70 ReportUnRegisterFail(longEventName, errCode, devId, dhId, errMsg);
71 ReportOptFail(longEventName, errCode, errMsg);
72 ReportSaEvent(longEventName, saId, errMsg);
73 ReportRegisterScreenEvent(longEventName, devId, dhId, errMsg);
74 ReportUnRegisterScreenEvent(longEventName, devId, dhId, errMsg);
75 ReportScreenMirrorEvent(longEventName, devId, dhId, errMsg);
76 std::string value = "Id";
77 std::string ret = GetAnonyString(value);
78 EXPECT_EQ("******", ret);
79 }
80
81 /**
82 * @tc.name: common_003
83 * @tc.desc: Verify the common function.
84 * @tc.type: FUNC
85 * @tc.require: Issue Number
86 */
87 HWTEST_F(ScreenCommonTest, common_003, TestSize.Level1)
88 {
89 DHLOGW("common_003.");
90 std::string value = "Id";
91 std::string ret = GetInterruptString(value);
92 EXPECT_EQ(value, ret);
93 }
94
95 /**
96 * @tc.name: common_004
97 * @tc.desc: Verify the common function.
98 * @tc.type: FUNC
99 * @tc.require: Issue Number
100 */
101 HWTEST_F(ScreenCommonTest, common_004, TestSize.Level1)
102 {
103 DHLOGW("common_004.");
104 std::string value = "Idvalues";
105 std::string ret = GetInterruptString(value);
106 EXPECT_EQ("Idva", ret);
107 }
108
109 /**
110 * @tc.name: IsInt64_001
111 * @tc.desc: Verify the IsInt64 function.
112 * @tc.type: FUNC
113 * @tc.require: Issue Number
114 */
115 HWTEST_F(ScreenCommonTest, IsInt64_001, TestSize.Level1)
116 {
117 nlohmann::json testJson;
118 std::string key = "test";
119 EXPECT_FALSE(IsInt64(testJson, key));
120
121 testJson[key] = "test";
122 EXPECT_FALSE(IsInt64(testJson, key));
123
124 testJson[key] = 1;
125 EXPECT_TRUE(IsInt64(testJson, key));
126 }
127
128 /**
129 * @tc.name: IsArray_001
130 * @tc.desc: Verify the IsArray function.
131 * @tc.type: FUNC
132 * @tc.require: Issue Number
133 */
134 HWTEST_F(ScreenCommonTest, IsArray_001, TestSize.Level1)
135 {
136 nlohmann::json testJson;
137 std::string key = "test";
138 EXPECT_FALSE(IsArray(testJson, key));
139
140 testJson[key] = "test";
141 EXPECT_FALSE(IsArray(testJson, key));
142
143 testJson[key] = {1, 2, 3};
144 EXPECT_TRUE(IsArray(testJson, key));
145 }
146 } // namespace DistributedHardware
147 } // namespace OHOS