1 /*
2 * Copyright (c) 2022 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
18 #include "profile_event_handler_factory.h"
19 #include "subscribe_info.h"
20 #include "subscribe_info_checker.h"
21 #include "utils.h"
22
23 namespace OHOS {
24 namespace DeviceProfile {
25 using namespace testing;
26 using namespace testing::ext;
27
28 class SubscribeInfoCheckerTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp();
33 void TearDown();
34 };
35
SetUpTestCase()36 void SubscribeInfoCheckerTest::SetUpTestCase()
37 {
38 DTEST_LOG << "SetUpTestCase" << std::endl;
39 }
40
TearDownTestCase()41 void SubscribeInfoCheckerTest::TearDownTestCase()
42 {
43 DTEST_LOG << "TearDownTestCase" << std::endl;
44 }
45
SetUp()46 void SubscribeInfoCheckerTest::SetUp()
47 {
48 DTEST_LOG << "SetUp" << std::endl;
49 }
50
TearDown()51 void SubscribeInfoCheckerTest::TearDown()
52 {
53 DTEST_LOG << "TearDown" << std::endl;
54 }
55
56 /**
57 * @tc.name: Check_001
58 * @tc.desc: Check
59 * @tc.type: FUNC
60 * @tc.require: I4NY1T
61 */
62 HWTEST_F(SubscribeInfoCheckerTest, Check_001, TestSize.Level3)
63 {
64 SubscribeInfo subInfo;
65 subInfo.extraInfo = {
66 {"deviceId", ""},
67 {"serviceIds", "1111"}
68 };
69 subInfo.profileEvent = ProfileEvent::EVENT_UNKNOWN;
70 std::list<SubscribeInfo> infos(1, subInfo);
71 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
72 ASSERT_FALSE(ret);
73 }
74
75 /**
76 * @tc.name: Check_002
77 * @tc.desc: Check
78 * @tc.type: FUNC
79 * @tc.require: I4NY1T
80 */
81 HWTEST_F(SubscribeInfoCheckerTest, Check_002, TestSize.Level3)
82 {
83 SubscribeInfo subInfo;
84 subInfo.extraInfo = {
85 {"deviceId", ""},
86 {"serviceIds", "1111"}
87 };
88 subInfo.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED;
89 std::list<SubscribeInfo> infos(1, subInfo);
90 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
91 ASSERT_TRUE(ret);
92 }
93
94 /**
95 * @tc.name: Check_004
96 * @tc.desc: Check
97 * @tc.type: FUNC
98 * @tc.require: I4NY1T
99 */
100 HWTEST_F(SubscribeInfoCheckerTest, Check_004, TestSize.Level3)
101 {
102 SubscribeInfo subInfo;
103 subInfo.extraInfo = {
104 {"deviceId", "1"},
105 {"serviceIds", "1111"}
106 };
107 subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED;
108 std::list<SubscribeInfo> infos(1, subInfo);
109 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
110 ASSERT_FALSE(ret);
111 }
112
113 /**
114 * @tc.name: Check_005
115 * @tc.desc: Check
116 * @tc.type: FUNC
117 * @tc.require: I4NY1T
118 */
119 HWTEST_F(SubscribeInfoCheckerTest, Check_005, TestSize.Level3)
120 {
121 SubscribeInfo subInfo;
122 subInfo.extraInfo = {
123 {"deviceId", 1},
124 {"serviceIds", "1111"}
125 };
126 subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED;
127 std::list<SubscribeInfo> infos(1, subInfo);
128 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
129 ASSERT_FALSE(ret);
130 }
131
132 /**
133 * @tc.name: Check_006
134 * @tc.desc: Check
135 * @tc.type: FUNC
136 * @tc.require: I4NY1T
137 */
138 HWTEST_F(SubscribeInfoCheckerTest, Check_006, TestSize.Level3)
139 {
140 SubscribeInfo subInfo;
141 subInfo.extraInfo = {
142 {"deviceId", "deviceId"}
143 };
144 subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED;
145 std::list<SubscribeInfo> infos(1, subInfo);
146 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
147 ASSERT_FALSE(ret);
148 }
149
150 /**
151 * @tc.name: Check_007
152 * @tc.desc: Check
153 * @tc.type: FUNC
154 * @tc.require: I4NY1T
155 */
156 HWTEST_F(SubscribeInfoCheckerTest, Check_007, TestSize.Level3)
157 {
158 SubscribeInfo subInfo;
159 subInfo.extraInfo = {
160 {"deviceId", "deviceId"}
161 };
162 std::list<std::string> serviceIds = {"fakeStorage", "fakeSystem"};
163 subInfo.extraInfo["serviceIds"] = serviceIds;
164 subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED;
165 std::list<SubscribeInfo> infos(1, subInfo);
166 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
167 ASSERT_TRUE(ret);
168 }
169
170 /**
171 * @tc.name: Check_007
172 * @tc.desc: Check
173 * @tc.type: FUNC
174 * @tc.require: I4NY1T
175 */
176 HWTEST_F(SubscribeInfoCheckerTest, Check_008, TestSize.Level3)
177 {
178 SubscribeInfo subInfo;
179 subInfo.extraInfo["serviceIds"] = nullptr;
180 subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED;
181 std::list<SubscribeInfo> infos(1, subInfo);
182 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
183 ASSERT_FALSE(ret);
184 }
185
186 /**
187 * @tc.name: Check_007
188 * @tc.desc: Check
189 * @tc.type: FUNC
190 * @tc.require: I4NY1T
191 */
192 HWTEST_F(SubscribeInfoCheckerTest, Check_009, TestSize.Level3)
193 {
194 SubscribeInfo subInfo;
195 subInfo.extraInfo["deviceId"] = nullptr;
196 subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED;
197 std::list<SubscribeInfo> infos(1, subInfo);
198 bool ret = SubscribeInfoChecker::GetInstance().Check(infos);
199 ASSERT_FALSE(ret);
200 }
201
202 /**
203 * @tc.name: GetHandler_001
204 * @tc.desc: GetHandler
205 * @tc.type: FUNC
206 * @tc.require: I4NY1T
207 */
208 HWTEST_F(SubscribeInfoCheckerTest, GetHandler_001, TestSize.Level3)
209 {
210 auto result = ProfileEventHandlerFactory::GetInstance().GetHandler(ProfileEvent::EVENT_PROFILE_END);
211 DTEST_LOG << "result: " << result << std::endl;
212 EXPECT_EQ(nullptr, result);
213 }
214 }
215 }