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 #define private public
16 #define protected public
17 #include "full_ime_info_manager.h"
18 #undef private
19 #include <gtest/gtest.h>
20 #include <sys/time.h>
21 #include <unistd.h>
22
23 #include <string>
24 #include <vector>
25
26 #include "global.h"
27 #include "ime_info_inquirer.h"
28
29 using namespace testing::ext;
30 namespace OHOS {
31 namespace MiscServices {
32 class FullImeInfoManagerTest : public testing::Test {
33 public:
34 static void SetUpTestCase(void);
35 static void TearDownTestCase(void);
36 void SetUp();
37 void TearDown();
38 };
39
SetUpTestCase(void)40 void FullImeInfoManagerTest::SetUpTestCase(void)
41 {
42 IMSA_HILOGI("FullImeInfoManagerTest::SetUpTestCase");
43 }
44
TearDownTestCase(void)45 void FullImeInfoManagerTest::TearDownTestCase(void)
46 {
47 IMSA_HILOGI("FullImeInfoManagerTest::TearDownTestCase");
48 FullImeInfoManager::GetInstance().fullImeInfos_.clear();
49 }
50
SetUp(void)51 void FullImeInfoManagerTest::SetUp(void)
52 {
53 IMSA_HILOGI("FullImeInfoManagerTest::SetUp");
54 FullImeInfoManager::GetInstance().fullImeInfos_.clear();
55 }
56
TearDown(void)57 void FullImeInfoManagerTest::TearDown(void)
58 {
59 IMSA_HILOGI("FullImeInfoManagerTest::TearDown");
60 }
61
62 /**
63 * @tc.name: test_Init_001
64 * @tc.desc: test Init that QueryFullImeInfo failed.
65 * @tc.type: FUNC
66 */
67 HWTEST_F(FullImeInfoManagerTest, test_Init_001, TestSize.Level0)
68 {
69 IMSA_HILOGI("test_Init_001 start");
70 // QueryFullImeInfo failed
71 std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> fullImeInfos;
72 ImeInfoInquirer::GetInstance().SetFullImeInfo(false, fullImeInfos);
73 auto ret = FullImeInfoManager::GetInstance().Init();
74 EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
75 }
76
77 /**
78 * @tc.name: test_Init_002
79 * @tc.desc: test Init succeed.
80 * @tc.type: FUNC
81 */
82 HWTEST_F(FullImeInfoManagerTest, test_Init_002, TestSize.Level0)
83 {
84 Property prop;
85 prop.name = "bundleName";
86 IMSA_HILOGI("test_Init_002 start");
87 int32_t userId = 100;
88 bool isNewIme = false;
89 uint32_t tokenId = 2;
90 std::string appId = "appId";
91 uint32_t versionCode = 11;
92 std::vector<FullImeInfo> imeInfos;
93 imeInfos.push_back({ isNewIme, tokenId, appId, versionCode, prop });
94 std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> fullImeInfos;
95 fullImeInfos.emplace_back(std::make_pair(userId, imeInfos));
96 ImeInfoInquirer::GetInstance().SetFullImeInfo(true, fullImeInfos);
97 auto ret = FullImeInfoManager::GetInstance().Init();
98 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
99 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
100 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
101 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
102 ASSERT_EQ(it->second.size(), 1);
103 auto imeInfo = it->second[0];
104 EXPECT_EQ(imeInfo.isNewIme, isNewIme);
105 EXPECT_EQ(imeInfo.tokenId, tokenId);
106 EXPECT_EQ(imeInfo.appId, appId);
107 EXPECT_EQ(imeInfo.versionCode, versionCode);
108 EXPECT_EQ(imeInfo.prop.name, prop.name);
109 }
110
111 /**
112 * @tc.name: test_Switch_001
113 * @tc.desc: test user switched that the userId exists
114 * @tc.type: FUNC
115 */
116 HWTEST_F(FullImeInfoManagerTest, test_Switch_001, TestSize.Level0)
117 {
118 IMSA_HILOGI("test_Switch_001 start");
119 int32_t userId = 100;
120 std::vector<FullImeInfo> imeInfos;
121 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
122 auto ret = FullImeInfoManager::GetInstance().Switch(userId);
123 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
124 }
125
126 /**
127 * @tc.name: test_Switch_002
128 * @tc.desc: test user Switched that QueryFullImeInfo failed
129 * @tc.type: FUNC
130 */
131 HWTEST_F(FullImeInfoManagerTest, test_Switch_002, TestSize.Level0)
132 {
133 IMSA_HILOGI("test_Switch_002 start");
134 int32_t userId = 100;
135 std::vector<FullImeInfo> imeInfos;
136 ImeInfoInquirer::GetInstance().SetFullImeInfo(false, imeInfos);
137 auto ret = FullImeInfoManager::GetInstance().Switch(userId);
138 EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
139 }
140
141 /**
142 * @tc.name: test_Switch_003
143 * @tc.desc: test user Switched succeed
144 * @tc.type: FUNC
145 */
146 HWTEST_F(FullImeInfoManagerTest, test_Switch_003, TestSize.Level0)
147 {
148 Property prop;
149 Property prop1;
150 IMSA_HILOGI("test_Switch_003 start");
151 int32_t userId = 100;
152 std::vector<FullImeInfo> imeInfos;
153 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
154
155 bool isNewIme = false;
156 uint32_t tokenId = 2;
157 std::string appId = "appId";
158 uint32_t versionCode = 11;
159 prop.name = "bundleName";
160
161 FullImeInfo imeInfo { isNewIme, tokenId, appId, versionCode, prop };
162 uint32_t tokenId1 = 2;
163 std::string appId1 = "appId1";
164 prop1.name = "bundleName1";
165 FullImeInfo imeInfo1 { isNewIme, tokenId1, appId1, versionCode, prop1 };
166 imeInfos.push_back(imeInfo);
167 imeInfos.push_back(imeInfo1);
168 ImeInfoInquirer::GetInstance().SetFullImeInfo(true, imeInfos);
169
170 int32_t userId1 = 101;
171 auto ret = FullImeInfoManager::GetInstance().Switch(userId1);
172 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
173 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 2);
174 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId1);
175 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
176 ASSERT_EQ(it->second.size(), 2);
177 EXPECT_EQ(it->second[0].isNewIme, isNewIme);
178 EXPECT_EQ(it->second[0].tokenId, tokenId);
179 EXPECT_EQ(it->second[0].appId, appId);
180 EXPECT_EQ(it->second[0].versionCode, versionCode);
181 EXPECT_EQ(it->second[0].prop.name, prop.name);
182 EXPECT_EQ(it->second[1].isNewIme, isNewIme);
183 EXPECT_EQ(it->second[1].tokenId, tokenId1);
184 EXPECT_EQ(it->second[1].appId, appId1);
185 EXPECT_EQ(it->second[1].versionCode, versionCode);
186 EXPECT_EQ(it->second[1].prop.name, prop1.name);
187 }
188
189 /**
190 * @tc.name: test_Add_001
191 * @tc.desc: test package added that GetFullImeInfo failed
192 * @tc.type: FUNC
193 */
194 HWTEST_F(FullImeInfoManagerTest, test_Add_001, TestSize.Level0)
195 {
196 IMSA_HILOGI("test_Add_001 start");
197 FullImeInfo imeInfo;
198 ImeInfoInquirer::GetInstance().SetFullImeInfo(false, imeInfo);
199 int32_t userId = 100;
200 std::string bundleName = "bundleName";
201 auto ret = FullImeInfoManager::GetInstance().Add(userId, bundleName);
202 EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
203 }
204
205 /**
206 * @tc.name: test_Add_002
207 * @tc.desc: test package added that userId does not exist;
208 * @tc.type: FUNC
209 */
210 HWTEST_F(FullImeInfoManagerTest, test_Add_002, TestSize.Level0)
211 {
212 IMSA_HILOGI("test_Add_002 start");
213 FullImeInfo imeInfo;
214 ImeInfoInquirer::GetInstance().SetFullImeInfo(true, imeInfo);
215 int32_t userId = 100;
216 std::string bundleName = "bundleName";
217 auto ret = FullImeInfoManager::GetInstance().Add(userId, bundleName);
218 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
219 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
220 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
221 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
222 EXPECT_EQ(it->second.size(), 1);
223 }
224
225 /**
226 * @tc.name: test_Add_003
227 * @tc.desc: test package added that bundleName does not exist;
228 * @tc.type: FUNC
229 */
230 HWTEST_F(FullImeInfoManagerTest, test_Add_003, TestSize.Level0)
231 {
232 IMSA_HILOGI("test_Add_003 start");
233 int32_t userId = 100;
234 std::vector<FullImeInfo> imeInfos;
235 FullImeInfo imeInfo;
236 imeInfo.prop.name = "bundleName";
237 imeInfos.push_back(imeInfo);
238 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
239
240 FullImeInfo imeInfo1;
241 imeInfo1.prop.name = "bundleName1";
242 ImeInfoInquirer::GetInstance().SetFullImeInfo(true, imeInfo1);
243
244 std::string bundleName = "bundleName1";
245 auto ret = FullImeInfoManager::GetInstance().Add(userId, bundleName);
246 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
247 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
248 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
249 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
250 ASSERT_EQ(it->second.size(), 2);
251 EXPECT_EQ(it->second[0].prop.name, imeInfo.prop.name);
252 EXPECT_EQ(it->second[1].prop.name, imeInfo1.prop.name);
253 }
254
255 /**
256 * @tc.name: test_Add_004
257 * @tc.desc: test package added that bundleName exists;
258 * @tc.type: FUNC
259 */
260 HWTEST_F(FullImeInfoManagerTest, test_Add_004, TestSize.Level0)
261 {
262 IMSA_HILOGI("test_Add_004 start");
263 int32_t userId = 100;
264 std::vector<FullImeInfo> imeInfos;
265 FullImeInfo imeInfo;
266 imeInfo.isNewIme = true;
267 imeInfo.prop.name = "bundleName";
268 imeInfos.push_back(imeInfo);
269 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
270
271 FullImeInfo imeInfo1;
272 imeInfo1.isNewIme = false;
273 imeInfo1.prop.name = "bundleName";
274 ImeInfoInquirer::GetInstance().SetFullImeInfo(true, imeInfo1);
275
276 std::string bundleName = "bundleName";
277 auto ret = FullImeInfoManager::GetInstance().Add(userId, bundleName);
278 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
279 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
280 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
281 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
282 ASSERT_EQ(it->second.size(), 1);
283 EXPECT_FALSE(it->second[0].isNewIme);
284 }
285
286 /**
287 * @tc.name: test_Update_001
288 * @tc.desc: test Update in language change that Init failed
289 * @tc.type: FUNC
290 */
291 HWTEST_F(FullImeInfoManagerTest, test_Update_001, TestSize.Level0)
292 {
293 IMSA_HILOGI("test_Update_001 start");
294 int32_t userId = 100;
295 std::vector<FullImeInfo> imeInfos;
296 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
297
298 std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> fullImeInfos;
299 ImeInfoInquirer::GetInstance().SetFullImeInfo(false, fullImeInfos);
300 auto ret = FullImeInfoManager::GetInstance().Update();
301 EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
302 EXPECT_TRUE(FullImeInfoManager::GetInstance().fullImeInfos_.empty());
303 }
304
305 /**
306 * @tc.name: test_Update_002
307 * @tc.desc: test Update in language change succeed
308 * @tc.type: FUNC
309 */
310 HWTEST_F(FullImeInfoManagerTest, test_Update_002, TestSize.Level0)
311 {
312 IMSA_HILOGI("test_Update_002 start");
313 int32_t userId = 100;
314 std::vector<FullImeInfo> imeInfos;
315 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
316
317 int32_t userId1 = 101;
318 std::vector<FullImeInfo> imeInfos1;
319 int32_t userId2 = 102;
320 std::vector<FullImeInfo> imeInfos2;
321 std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> fullImeInfos;
322 fullImeInfos.emplace_back(std::make_pair(userId1, imeInfos1));
323 fullImeInfos.emplace_back(std::make_pair(userId2, imeInfos2));
324 ImeInfoInquirer::GetInstance().SetFullImeInfo(true, fullImeInfos);
325
326 auto ret = FullImeInfoManager::GetInstance().Update();
327 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
328 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 2);
329 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
330 ASSERT_EQ(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
331 auto it1 = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId1);
332 ASSERT_NE(it1, FullImeInfoManager::GetInstance().fullImeInfos_.end());
333 auto it2 = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId2);
334 ASSERT_NE(it2, FullImeInfoManager::GetInstance().fullImeInfos_.end());
335 }
336
337 /**
338 * @tc.name: test_Delete_001
339 * @tc.desc: test Delete in user removed that userId does not exist
340 * @tc.type: FUNC
341 */
342 HWTEST_F(FullImeInfoManagerTest, test_Delete_001, TestSize.Level0)
343 {
344 IMSA_HILOGI("test_Delete_001 start");
345 int32_t userId = 100;
346 std::vector<FullImeInfo> imeInfos;
347 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
348
349 int32_t userId1 = 101;
350 auto ret = FullImeInfoManager::GetInstance().Delete(userId1);
351 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
352 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
353 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
354 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
355 }
356
357 /**
358 * @tc.name: test_Delete_002
359 * @tc.desc: test Delete in user removed that userId exists
360 * @tc.type: FUNC
361 */
362 HWTEST_F(FullImeInfoManagerTest, test_Delete_002, TestSize.Level0)
363 {
364 IMSA_HILOGI("test_Delete_002 start");
365 int32_t userId = 100;
366 std::vector<FullImeInfo> imeInfos;
367 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
368
369 auto ret = FullImeInfoManager::GetInstance().Delete(userId);
370 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
371 ASSERT_TRUE(FullImeInfoManager::GetInstance().fullImeInfos_.empty());
372
373 int32_t userId1 = 101;
374 std::vector<FullImeInfo> imeInfos1;
375 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId1, imeInfos1);
376 int32_t userId2 = 102;
377 std::vector<FullImeInfo> imeInfos2;
378 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId2, imeInfos2);
379 ret = FullImeInfoManager::GetInstance().Delete(userId2);
380 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
381 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
382 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId2);
383 ASSERT_EQ(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
384 }
385
386 /**
387 * @tc.name: test_Delete_003
388 * @tc.desc: test Delete in package removed that userId does not exist
389 * @tc.type: FUNC
390 */
391 HWTEST_F(FullImeInfoManagerTest, test_Delete_003, TestSize.Level0)
392 {
393 IMSA_HILOGI("test_Delete_003 start");
394 int32_t userId = 100;
395 std::vector<FullImeInfo> imeInfos;
396 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
397
398 int32_t userId1 = 101;
399 std::string bundleName = "bundleName";
400 auto ret = FullImeInfoManager::GetInstance().Delete(userId1, bundleName);
401 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
402 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
403 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
404 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
405 }
406
407 /**
408 * @tc.name: test_Delete_004
409 * @tc.desc: test Delete in package removed that bundleName does not exist
410 * @tc.type: FUNC
411 */
412 HWTEST_F(FullImeInfoManagerTest, test_Delete_004, TestSize.Level0)
413 {
414 IMSA_HILOGI("test_Delete_004 start");
415 int32_t userId = 100;
416 std::vector<FullImeInfo> imeInfos;
417 FullImeInfo imeInfo;
418 imeInfo.prop.name = "bundleName";
419 imeInfos.push_back(imeInfo);
420 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
421
422 std::string bundleName = "bundleName1";
423 auto ret = FullImeInfoManager::GetInstance().Delete(userId, bundleName);
424 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
425 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
426 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
427 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
428 ASSERT_EQ(it->second.size(), 1);
429 EXPECT_EQ(it->second[0].prop.name, imeInfo.prop.name);
430 }
431
432 /**
433 * @tc.name: test_Delete_005
434 * @tc.desc: test Delete in package removed that bundleName exist
435 * @tc.type: FUNC
436 */
437 HWTEST_F(FullImeInfoManagerTest, test_Delete_005, TestSize.Level0)
438 {
439 IMSA_HILOGI("test_Delete_005 start");
440 int32_t userId = 100;
441 std::vector<FullImeInfo> imeInfos;
442 FullImeInfo imeInfo;
443 imeInfo.prop.name = "bundleName";
444 imeInfos.push_back(imeInfo);
445 FullImeInfo imeInfo1;
446 imeInfo1.prop.name = "bundleName1";
447 imeInfos.push_back(imeInfo1);
448 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
449
450 std::string bundleName1 = "bundleName1";
451 auto ret = FullImeInfoManager::GetInstance().Delete(userId, bundleName1);
452 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
453 EXPECT_EQ(FullImeInfoManager::GetInstance().fullImeInfos_.size(), 1);
454 auto it = FullImeInfoManager::GetInstance().fullImeInfos_.find(userId);
455 ASSERT_NE(it, FullImeInfoManager::GetInstance().fullImeInfos_.end());
456 ASSERT_EQ(it->second.size(), 1);
457 EXPECT_EQ(it->second[0].prop.name, imeInfo.prop.name);
458
459 std::string bundleName = "bundleName";
460 ret = FullImeInfoManager::GetInstance().Delete(userId, bundleName);
461 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
462 EXPECT_TRUE(FullImeInfoManager::GetInstance().fullImeInfos_.empty());
463 }
464
465 /**
466 * @tc.name: test_Get_001
467 * @tc.desc: test Get that by userId that userId does not exist
468 * @tc.type: FUNC
469 */
470 HWTEST_F(FullImeInfoManagerTest, test_Get_001, TestSize.Level0)
471 {
472 IMSA_HILOGI("test_Get_001 start");
473 int32_t userId = 100;
474 std::vector<FullImeInfo> imeInfos;
475 FullImeInfo info;
476 imeInfos.push_back(info);
477 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
478
479 int32_t userId1 = 101;
480 std::vector<Property> props;
481 auto ret = FullImeInfoManager::GetInstance().Get(userId1, props);
482 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
483 EXPECT_TRUE(props.empty());
484 }
485
486 /**
487 * @tc.name: test_Get_002
488 * @tc.desc: test Get that by userId that userId exist
489 * @tc.type: FUNC
490 */
491 HWTEST_F(FullImeInfoManagerTest, test_Get_002, TestSize.Level0)
492 {
493 IMSA_HILOGI("test_Get_002 start");
494 int32_t userId = 100;
495 std::vector<FullImeInfo> imeInfos;
496 FullImeInfo info;
497 imeInfos.push_back(info);
498 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
499 std::vector<Property> props;
500 auto ret = FullImeInfoManager::GetInstance().Get(userId, props);
501 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
502 EXPECT_EQ(props.size(), 1);
503 }
504
505 /**
506 * @tc.name: test_Get_003
507 * @tc.desc: test Get that by userId and bundleName that userId does not exist
508 * @tc.type: FUNC
509 */
510 HWTEST_F(FullImeInfoManagerTest, test_Get_003, TestSize.Level0)
511 {
512 IMSA_HILOGI("test_Get_003 start");
513 int32_t userId = 100;
514 std::vector<FullImeInfo> imeInfos;
515 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
516
517 int32_t userId1 = 101;
518 std::string bundleName = "bundleName";
519 FullImeInfo info;
520 auto ret = FullImeInfoManager::GetInstance().Get(userId1, bundleName, info);
521 EXPECT_FALSE(ret);
522 }
523
524 /**
525 * @tc.name: test_Get_004
526 * @tc.desc: test Get that by userId and bundleName that bundleName does not exist
527 * @tc.type: FUNC
528 */
529 HWTEST_F(FullImeInfoManagerTest, test_Get_004, TestSize.Level0)
530 {
531 IMSA_HILOGI("test_Get_004 start");
532 int32_t userId = 100;
533 std::vector<FullImeInfo> imeInfos;
534 FullImeInfo info;
535 info.prop.name = "bundleName1";
536 imeInfos.push_back(info);
537 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
538
539 int32_t userId1 = 100;
540 std::string bundleName = "bundleName";
541 FullImeInfo infoRet;
542 auto ret = FullImeInfoManager::GetInstance().Get(userId1, bundleName, infoRet);
543 EXPECT_FALSE(ret);
544 }
545
546 /**
547 * @tc.name: test_Get_005
548 * @tc.desc: test Get that by userId and bundleName succeed
549 * @tc.type: FUNC
550 */
551 HWTEST_F(FullImeInfoManagerTest, test_Get_005, TestSize.Level0)
552 {
553 IMSA_HILOGI("test_Get_005 start");
554 int32_t userId = 100;
555 std::vector<FullImeInfo> imeInfos;
556 FullImeInfo info;
557 info.prop.name = "bundleName1";
558 imeInfos.push_back(info);
559 FullImeInfoManager::GetInstance().fullImeInfos_.insert_or_assign(userId, imeInfos);
560
561 int32_t userId1 = 100;
562 std::string bundleName = "bundleName1";
563 FullImeInfo infoRet;
564 auto ret = FullImeInfoManager::GetInstance().Get(userId1, bundleName, infoRet);
565 EXPECT_TRUE(ret);
566 EXPECT_EQ(infoRet.prop.name, info.prop.name);
567 }
568 } // namespace MiscServices
569 } // namespace OHOS