1 /*
2 * Copyright (c) 2023 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 "resource_manager_test_hap.h"
17
18 #include "resource_manager_test_common.h"
19
20 using namespace OHOS::Global::Resource;
21 using namespace testing::ext;
22 namespace {
23 static constexpr uint32_t DATA_ALL_HAP_LIMIT_KEYS = 1503;
24 static constexpr uint32_t SYSTEM_RES_LIMIT_KEYS = 1503;
25 class ResourceManagerTestHap : public testing::Test {
26 public:
27 static void SetUpTestCase(void);
28
29 static void TearDownTestCase(void);
30
31 void SetUp();
32
33 void TearDown();
34
ResourceManagerTestHap()35 ResourceManagerTestHap() : rm(nullptr)
36 {}
37
~ResourceManagerTestHap()38 ~ResourceManagerTestHap()
39 {}
40 public:
41 ResourceManager *rm;
42 ResourceManagerTestCommon *rmc;
43 };
44
SetUpTestCase(void)45 void ResourceManagerTestHap::SetUpTestCase(void)
46 {
47 // step 1: input testsuit setup step
48 g_logLevel = LOG_DEBUG;
49 }
50
TearDownTestCase(void)51 void ResourceManagerTestHap::TearDownTestCase(void)
52 {
53 // step 2: input testsuit teardown step
54 }
55
SetUp(void)56 void ResourceManagerTestHap::SetUp(void)
57 {
58 this->rm = CreateResourceManager();
59 this->rmc = new ResourceManagerTestCommon(rm);
60 }
61
TearDown(void)62 void ResourceManagerTestHap::TearDown(void)
63 {
64 delete this->rm;
65 delete this->rmc;
66 }
67
68 /*
69 * @tc.name: ResourceManagerAddResourceFromHapTest001
70 * @tc.desc: Test AddResource function
71 * @tc.type: FUNC
72 * @tc.require: issueI5LHLP
73 */
74 HWTEST_F(ResourceManagerTestHap, ResourceManagerAddResourceFromHapTest001, TestSize.Level1)
75 {
76 // error cases
77 // file not exist
78 bool ret = rm->AddResource("/data/test/do_not_exist.hap");
79 ASSERT_TRUE(!ret);
80 }
81
82 /*
83 * @tc.name: ResourceManagerGetStringByIdFromHapTest002
84 * @tc.desc: Test GetStringById function
85 * @tc.type: FUNC
86 * @tc.require: issueI5LHLP
87 */
88 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringByIdFromHapTest002, TestSize.Level1)
89 {
90 rmc->AddHapResource("en", nullptr, "US");
91
92 rmc->TestStringById("app_name", "App Name");
93 rmc->TestStringById("copyright_text", "XXXXXX All rights reserved. ©2011-2019");
94 }
95
96 /*
97 * @tc.name: ResourceManagerGetStringByIdFromHapTest003
98 * @tc.desc: Test GetStringById function
99 * @tc.type: FUNC
100 * @tc.require: issueI5LHLP
101 */
102 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringByIdFromHapTest003, TestSize.Level1)
103 {
104 rmc->AddHapResource("zh", nullptr, nullptr);
105
106 rmc->TestStringById("app_name", "应用名称");
107 rmc->TestStringById("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利");
108 }
109
110 /*
111 * @tc.name: ResourceManagerGetStringByNameFromHapTest004
112 * @tc.desc: Test GetStringByName function
113 * @tc.type: FUNC
114 * @tc.require: issueI5LHLP
115 */
116 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringByNameFromHapTest004, TestSize.Level1)
117 {
118 rmc->AddHapResource("en", nullptr, nullptr);
119
120 rmc->TestStringByName("app_name", "App Name");
121 rmc->TestStringByName("copyright_text", "XXXXXX All rights reserved. ©2011-2019");
122 }
123
124 /*
125 * @tc.name: ResourceManagerGetStringByNameFromHapTest005
126 * @tc.desc: Test GetStringByName function
127 * @tc.type: FUNC
128 * @tc.require: issueI5LHLP
129 */
130 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringByNameFromHapTest005, TestSize.Level1)
131 {
132 rmc->AddHapResource("zh", nullptr, nullptr);
133
134 rmc->TestStringByName("app_name", "应用名称");
135 rmc->TestStringByName("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利");
136 }
137
138 /*
139 * @tc.name: ResourceManagerGetStringFormatByIdFromHapTest006
140 * @tc.desc: Test GetStringFormatById function
141 * @tc.type: FUNC
142 * @tc.require: issueI5LHLP
143 */
144 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringFormatByIdFromHapTest006, TestSize.Level1)
145 {
146 rmc->AddHapResource("zh", nullptr, nullptr);
147
148 rmc->TestGetStringFormatById("app_name", "应用名称");
149 }
150
151
152 /*
153 * @tc.name: ResourceManagerGetStringFormatByNameFromHapTest007
154 * @tc.desc: Test GetStringFormatByName function
155 * @tc.type: FUNC
156 * @tc.require: issueI5LHLP
157 */
158 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringFormatByNameFromHapTest007, TestSize.Level1)
159 {
160 rmc->AddHapResource("zh", nullptr, nullptr);
161
162 rmc->TestGetStringFormatByName("app_name", "应用名称");
163 }
164
165 /*
166 * @tc.name: ResourceManagerGetStringArrayByIdFromHapTest008
167 * @tc.desc: Test GetStringArrayById function
168 * @tc.type: FUNC
169 * @tc.require: issueI5LHLP
170 */
171 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringArrayByIdFromHapTest008, TestSize.Level1)
172 {
173 rmc->AddHapResource("zh", nullptr, nullptr);
174
175 rmc->TestGetStringArrayById("size");
176 }
177
178 /*
179 * @tc.name: ResourceManagerGetStringArrayByNameFromHapTest009
180 * @tc.desc: Test GetStringArrayByName function
181 * @tc.type: FUNC
182 * @tc.require: issueI5LHLP
183 */
184 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetStringArrayByNameFromHapTest009, TestSize.Level1)
185 {
186 rmc->AddHapResource("zh", nullptr, nullptr);
187
188 rmc->TestGetStringArrayByName("size");
189 }
190
191 /*
192 * @tc.name: ResourceManagerGetPatternByIdFromHapTest0010
193 * @tc.desc: Test GetPatternById function
194 * @tc.type: FUNC
195 * @tc.require: issueI5LHLP
196 */
197 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPatternByIdFromHapTest0010, TestSize.Level1)
198 {
199 rmc->AddHapResource("zh", nullptr, nullptr);
200 rmc->TestGetPatternById("base");
201 }
202
203 /*
204 * @tc.name: ResourceManagerGetPatternByNameFromHapTest0011
205 * @tc.desc: Test GetPatternByName function
206 * @tc.type: FUNC
207 * @tc.require: issueI5LHLP
208 */
209 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPatternByNameFromHapTest0011, TestSize.Level1)
210 {
211 rmc->AddHapResource("zh", nullptr, nullptr);
212 rmc->TestGetPatternByName("base");
213 }
214
215 /*
216 * @tc.name: ResourceManagerGetPluralStringByIdFromHapTest0012
217 * @tc.desc: Test GetPluralStringById function
218 * @tc.type: FUNC
219 * @tc.require: issueI5LHLP
220 */
221 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPluralStringByIdFromHapTest0012, TestSize.Level1)
222 {
223 rmc->AddHapResource("en", nullptr, "US");
224
225 int quantity = 1;
226 rmc->TestPluralStringById(quantity, "%d apple", false);
227 quantity = 101;
228 rmc->TestPluralStringById(quantity, "%d apples", false);
229 }
230
231 /*
232 * @tc.name: ResourceManagerGetPluralStringByIdFromHapTest0013
233 * @tc.desc: Test GetPluralStringById function
234 * @tc.type: FUNC
235 * @tc.require: issueI5LHLP
236 */
237 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPluralStringByIdFromHapTest0013, TestSize.Level1)
238 {
239 rmc->AddHapResource("zh", nullptr, "CN");
240
241 int quantity = 1;
242 rmc->TestPluralStringById(quantity, "%d apples", false);
243 quantity = 101;
244 rmc->TestPluralStringById(quantity, "%d apples", false);
245 }
246
247 /*
248 * @tc.name: ResourceManagerGetPluralStringByIdFromHapTest0014
249 * @tc.desc: Test GetPluralStringById function
250 * @tc.type: FUNC
251 * @tc.require: issueI5LHLP
252 */
253 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPluralStringByIdFromHapTest0014, TestSize.Level1)
254 {
255 rmc->AddHapResource("ar", nullptr, "SA");
256
257 int quantity = 0;
258 rmc->TestPluralStringById(quantity, "zero-0");
259 quantity = 1;
260 rmc->TestPluralStringById(quantity, "one-1");
261 quantity = 5;
262 rmc->TestPluralStringById(quantity, "few-%d");
263 quantity = 500;
264 rmc->TestPluralStringById(quantity, "other-%d");
265 }
266
267 /*
268 * @tc.name: ResourceManagerGetPluralStringByIdFromHapTest0015
269 * @tc.desc: Test GetPluralStringById function
270 * @tc.type: FUNC
271 * @tc.require: issueI5LHLP
272 */
273 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPluralStringByIdFromHapTest0015, TestSize.Level1)
274 {
275 rmc->AddHapResource("pl", nullptr, "PL");
276
277 int quantity = 1;
278 rmc->TestPluralStringById(quantity, "1 jabłko");
279 quantity = 2;
280 rmc->TestPluralStringById(quantity, "%d jabłka");
281 }
282
283 /*
284 * @tc.name: ResourceManagerGetPluralStringByNameFromHapTest0016
285 * @tc.desc: Test GetPluralStringByName function
286 * @tc.type: FUNC
287 * @tc.require: issueI5LHLP
288 */
289 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPluralStringByNameFromHapTest0016, TestSize.Level1)
290 {
291 rmc->AddHapResource("en", nullptr, "US");
292
293 int quantity = 1;
294 rmc->TestPluralStringByName(quantity, "%d apple", false);
295 quantity = 101;
296 rmc->TestPluralStringByName(quantity, "%d apples", false);
297 }
298
299 /*
300 * @tc.name: ResourceManagerGetPluralStringByIdFormatFromHapTest0017
301 * @tc.desc: Test GetPluralStringById function
302 * @tc.type: FUNC
303 * @tc.require: issueI5LHLP
304 */
305 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPluralStringByIdFormatFromHapTest0017, TestSize.Level1)
306 {
307 rmc->AddHapResource("zh", nullptr, "CN");
308
309 int quantity = 1;
310 rmc->TestPluralStringById(quantity, "1 apples", true);
311 quantity = 101;
312 rmc->TestPluralStringById(quantity, "101 apples", true);
313 }
314
315 /*
316 * @tc.name: ResourceManagerGetPluralStringByNameFormatFromHapTest0018
317 * @tc.desc: Test GetPluralStringByName function
318 * @tc.type: FUNC
319 * @tc.require: issueI5LHLP
320 */
321 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetPluralStringByNameFormatFromHapTest0018, TestSize.Level1)
322 {
323 rmc->AddHapResource("zh", nullptr, "CN");
324
325 int quantity = 1;
326 rmc->TestPluralStringByName(quantity, "1 apples", true);
327 quantity = 101;
328 rmc->TestPluralStringByName(quantity, "101 apples", true);
329 }
330
331 /*
332 * @tc.name: ResourceManagerGetThemeByIdFromHapTest0019
333 * @tc.desc: Test GetThemeById
334 * @tc.type: FUNC
335 * @tc.require: issueI5LHLP
336 */
337 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetThemeByIdFromHapTest0019, TestSize.Level1)
338 {
339 rmc->AddHapResource("zh", nullptr, "CN");
340
341 rmc->TestGetThemeById("app_theme");
342 }
343
344 /*
345 * @tc.name: ResourceManagerGetThemeByNameFromHapTest0020
346 * @tc.desc: Test GetThemeByName
347 * @tc.type: FUNC
348 * @tc.require: issueI5LHLP
349 */
350 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetThemeByNameFromHapTest0020, TestSize.Level1)
351 {
352 rmc->AddHapResource("zh", nullptr, "CN");
353
354 rmc->TestGetThemeByName("app_theme", "test_theme");
355 }
356
357 /*
358 * @tc.name: ResourceManagerGetBooleanByIdFromHapTest0021
359 * @tc.desc: Test GetBooleanById
360 * @tc.type: FUNC
361 * @tc.require: issueI5LHLP
362 */
363 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetBooleanByIdFromHapTest0021, TestSize.Level1)
364 {
365 rmc->AddHapResource("zh", nullptr, "CN");
366
367 rmc->TestGetBooleanById("boolean_1", "boolean_ref");
368 }
369
370 /*
371 * @tc.name: ResourceManagerGetBooleanByNameFromHapTest0022
372 * @tc.desc: Test GetBooleanByName
373 * @tc.type: FUNC
374 * @tc.require: issueI5LHLP
375 */
376 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetBooleanByNameFromHapTest0022, TestSize.Level1)
377 {
378 rmc->AddHapResource("zh", nullptr, "CN");
379
380 rmc->TestGetBooleanByName("boolean_1", "boolean_ref");
381 }
382
383 /*
384 * @tc.name: ResourceManagerGetIntegerByIdFromHapTest0023
385 * @tc.desc: Test GetIntegerById
386 * @tc.type: FUNC
387 * @tc.require: issueI5LHLP
388 */
389 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetIntegerByIdFromHapTest0023, TestSize.Level1)
390 {
391 rmc->AddHapResource("zh", nullptr, "CN");
392
393 rmc->TestGetIntegerById("integer_1", "integer_ref");
394 }
395
396 /*
397 * @tc.name: ResourceManagerGetIntegerByNameFromHapTest0024
398 * @tc.desc: Test GetIntegerByName
399 * @tc.type: FUNC
400 * @tc.require: issueI5LHLP
401 */
402 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetIntegerByNameFromHapTest0024, TestSize.Level1)
403 {
404 rmc->AddHapResource("zh", nullptr, "CN");
405
406 rmc->TestGetIntegerByName("integer_1", "integer_ref");
407 }
408
409 /*
410 * @tc.name: ResourceManagerGetFloatByIdFromHapTest0025
411 * @tc.desc: Test GetFloatById
412 * @tc.type: FUNC
413 * @tc.require: issueI5LHLP
414 */
415 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetFloatByIdFromHapTest0025, TestSize.Level1)
416 {
417 rmc->AddHapResource("zh", nullptr, "CN");
418
419 rmc->TestGetFloatById("width_appBar_backButton_touchTarget", "float_ref");
420 }
421
422 /*
423 * @tc.name: ResourceManagerGetFloatByNameFromHapTest0026
424 * @tc.desc: Test GetFloatByName
425 * @tc.type: FUNC
426 * @tc.require: issueI5LHLP
427 */
428 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetFloatByNameFromHapTest0026, TestSize.Level1)
429 {
430 rmc->AddHapResource("zh", nullptr, "CN");
431
432 rmc->TestGetFloatByName("width_appBar_backButton_touchTarget", "float_ref");
433 }
434
435 /*
436 * @tc.name: ResourceManagerGetIntArrayByIdFromHapTest0027
437 * @tc.desc: Test GetIntArrayById
438 * @tc.type: FUNC
439 * @tc.require: issueI5LHLP
440 */
441 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetIntArrayByIdFromHapTest0027, TestSize.Level1)
442 {
443 rmc->AddHapResource("zh", nullptr, "CN");
444
445 rmc->TestGetIntArrayById("intarray_1");
446 }
447
448 /*
449 * @tc.name: ResourceManagerGetIntArrayByNameFromHapTest0028
450 * @tc.desc: Test GetIntArrayByName
451 * @tc.type: FUNC
452 * @tc.require: issueI5LHLP
453 */
454 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetIntArrayByNameFromHapTest0028, TestSize.Level1)
455 {
456 rmc->AddHapResource("zh", nullptr, "CN");
457
458 rmc->TestGetIntArrayByName("intarray_1");
459 }
460
461 /*
462 * @tc.name: ResourceManagerGetProfileByIdFromHapTest0029
463 * @tc.desc: Test GetProfileById
464 * @tc.type: FUNC
465 * @tc.require: issueI5LHLP
466 */
467 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetProfileByIdFromHapTest0029, TestSize.Level1)
468 {
469 rmc->AddHapResource("zh", nullptr, "CN");
470
471 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
472 rmc->TestGetProfileById(tmp);
473 delete tmp;
474 }
475
476 /*
477 * @tc.name: ResourceManagerGetProfileByNameFromHapTest0030
478 * @tc.desc: Test GetProfileByName
479 * @tc.type: FUNC
480 * @tc.require: issueI5LHLP
481 */
482 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetProfileByNameFromHapTest0030, TestSize.Level1)
483 {
484 rmc->AddHapResource("zh", nullptr, "CN");
485
486 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
487 rmc->TestGetProfileByName(tmp);
488 delete tmp;
489 }
490
491 /*
492 * @tc.name: ResourceManagerGetMediaByIdFromHapTest0031
493 * @tc.desc: Test GetMediaById
494 * @tc.type: FUNC
495 * @tc.require: issueI5LHLP
496 */
497 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaByIdFromHapTest0031, TestSize.Level1)
498 {
499 rmc->AddHapResource("zh", nullptr, "CN");
500
501 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
502 rmc->TestGetMediaById(tmp);
503 delete tmp;
504 }
505
506 /*
507 * @tc.name: ResourceManagerGetMediaByIdFromHapTest0032
508 * @tc.desc: Test GetMediaById, to match sdpi determinder
509 * @tc.type: FUNC
510 * @tc.require: issueI5LHLP
511 */
512 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaByIdFromHapTest0032, TestSize.Level1)
513 {
514 rmc->AddHapResource("en", nullptr, "US");
515
516 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
517 rmc->TestGetMediaWithDensityById(tmp);
518 delete tmp;
519 }
520
521 /*
522 * @tc.name: ResourceManagerGetMediaByNameFromHapTest0033
523 * @tc.desc: Test GetMediaByName
524 * @tc.type: FUNC
525 * @tc.require: issueI5LHLP
526 */
527 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaByNameFromHapTest0033, TestSize.Level1)
528 {
529 rmc->AddHapResource("zh", nullptr, "CN");
530
531 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
532 rmc->TestGetMediaByName(tmp);
533 delete tmp;
534 }
535
536 /*
537 * @tc.name: ResourceManagerGetMediaByNameFromHapTest0034
538 * @tc.desc: Test GetMediaByName, to match sdpi determinder
539 * @tc.type: FUNC
540 * @tc.require: issueI5LHLP
541 */
542 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaByNameFromHapTest0034, TestSize.Level1)
543 {
544 rmc->AddHapResource("en", nullptr, "US");
545
546 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
547 rmc->TestGetMediaWithDensityByName(tmp);
548 delete tmp;
549 }
550
551 /*
552 * @tc.name: ResourceManagerGetProfileDataByIdFromHapTest0035
553 * @tc.desc: Test GetProfileDataByName
554 * @tc.type: FUNC
555 * @tc.require: issueI5LHLP
556 */
557 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetProfileDataByIdFromHapTest0035, TestSize.Level1)
558 {
559 rmc->AddHapResource("zh", nullptr, "CN");
560
561 std::unique_ptr<uint8_t[]> outValue;
562 int id = rmc->GetResId("test_profile", ResType::PROF);
563 EXPECT_TRUE(id > 0);
564 size_t len;
565 RState state = rm->GetProfileDataById(id, len, outValue);
566 EXPECT_TRUE(state == SUCCESS);
567 }
568
569 /*
570 * @tc.name: ResourceManagerGetProfileDataByNameFromHapTest0036
571 * @tc.desc: Test GetProfileDataByName
572 * @tc.type: FUNC
573 * @tc.require: issueI5LHLP
574 */
575 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetProfileDataByNameFromHapTest0036, TestSize.Level1)
576 {
577 rmc->AddHapResource("zh", nullptr, "CN");
578
579 std::unique_ptr<uint8_t[]> outValue;
580 size_t len;
581 RState state = rm->GetProfileDataByName("test_profile", len, outValue);
582 EXPECT_TRUE(state == SUCCESS);
583 }
584
585 /*
586 * @tc.name: ResourceManagerGetMediaDataByNameFromHapTest0037
587 * @tc.desc: Test GetMediaDataByName
588 * @tc.type: FUNC
589 * @tc.require: issueI5LHLP
590 */
591 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaDataByNameFromHapTest0037, TestSize.Level1)
592 {
593 rmc->AddHapResource("zh", nullptr, "CN");
594
595 std::unique_ptr<uint8_t[]> outValue;
596 RState state;
597 size_t len;
598 state = rm->GetMediaDataByName("icon1", len, outValue);
599 EXPECT_EQ(len, static_cast<size_t>(5997)); // the length of icon1
600 EXPECT_TRUE(state == SUCCESS);
601 }
602
603 /*
604 * @tc.name: ResourceManagerGetMediaDataByIdFromHapTest0038
605 * @tc.desc: Test GetMediaDataById
606 * @tc.type: FUNC
607 * @tc.require: issueI5LHLP
608 */
609 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaDataByIdFromHapTest0038, TestSize.Level1)
610 {
611 rmc->AddHapResource("zh", nullptr, "CN");
612
613 std::unique_ptr<uint8_t[]> outValue;
614 RState state;
615 int id = rmc->GetResId("icon1", ResType::MEDIA);
616 EXPECT_TRUE(id > 0);
617 size_t len;
618 state = rm->GetMediaDataById(id, len, outValue);
619 EXPECT_EQ(len, static_cast<size_t>(5997)); // the length of icon1
620 EXPECT_TRUE(state == SUCCESS);
621 }
622
623 /*
624 * @tc.name: ResourceManagerGetMediaDataBase64ByNameFromHapTest0039
625 * @tc.desc: Test GetMediaBase64DataByName
626 * @tc.type: FUNC
627 * @tc.require: issueI5LHLP
628 */
629 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaDataBase64ByNameFromHapTest0039, TestSize.Level1)
630 {
631 rmc->AddHapResource("zh", nullptr, "CN");
632
633 std::string outValue;
634 RState state;
635 state = rm->GetMediaBase64DataByName("icon1", outValue);
636 EXPECT_TRUE(state == SUCCESS);
637 }
638
639 /*
640 * @tc.name: ResourceManagerGetMediaDataBase64ByIdFromHapTest0040
641 * @tc.desc: Test GetMediaDataBase64ById
642 * @tc.type: FUNC
643 * @tc.require: issueI5LHLP
644 */
645 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaDataBase64ByIdFromHapTest0040, TestSize.Level1)
646 {
647 rmc->AddHapResource("zh", nullptr, "CN");
648
649 std::string outValue;
650 int id = rmc->GetResId("icon1", ResType::MEDIA);
651 EXPECT_TRUE(id > 0);
652 RState state;
653 state = rm->GetMediaBase64DataById(id, outValue);
654 EXPECT_TRUE(state == SUCCESS);
655 }
656
657 /*
658 * @tc.name: ResourceManagerGetMediaDataByIdFromHapTest0041
659 * @tc.desc: Test GetMediaDataById, to match sdpi determinder
660 * @tc.type: FUNC
661 * @tc.require: issueI5LHLP
662 */
663 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaDataByIdFromHapTest0041, TestSize.Level1)
664 {
665 rmc->AddHapResource("zh", nullptr, "CN");
666
667 auto rc = CreateResConfig();
668 if (rc == nullptr) {
669 EXPECT_TRUE(false);
670 return;
671 }
672 rc->SetDeviceType(DEVICE_TV);
673 rc->SetColorMode(COLOR_MODE_NOT_SET);
674 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
675 rm->UpdateResConfig(*rc);
676 delete rc;
677
678 int density = 120;
679 std::unique_ptr<uint8_t[]> outValue;
680 RState state;
681 int id = rmc->GetResId("icon", ResType::MEDIA);
682 EXPECT_TRUE(id > 0);
683 size_t len;
684 state = rm->GetMediaDataById(id, len, outValue, density);
685 EXPECT_EQ(static_cast<int>(len), 6790); // the length of icon
686 EXPECT_TRUE(state == SUCCESS);
687
688 density = 1; // invalid density
689 size_t len2;
690 state = rm->GetMediaDataById(id, len2, outValue, density);
691 EXPECT_EQ(static_cast<int>(len2), 0);
692 EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
693 }
694
695 /*
696 * @tc.name: ResourceManagerGetMediaDataByNameFromHapTest0042
697 * @tc.desc: Test GetMediaBase64DataByName, to match sdpi determinder
698 * @tc.type: FUNC
699 * @tc.require: issueI5LHLP
700 */
701 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaDataByNameFromHapTest0042, TestSize.Level1)
702 {
703 rmc->AddHapResource("zh", nullptr, "CN");
704
705 auto rc = CreateResConfig();
706 if (rc == nullptr) {
707 EXPECT_TRUE(false);
708 return;
709 }
710 rc->SetDeviceType(DEVICE_TV);
711 rc->SetColorMode(COLOR_MODE_NOT_SET);
712 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
713 rm->UpdateResConfig(*rc);
714 delete rc;
715
716 int density = 120;
717 std::unique_ptr<uint8_t[]> outValue;
718 RState state;
719 size_t len;
720 state = rm->GetMediaDataByName("icon", len, outValue, density);
721 EXPECT_EQ(static_cast<int>(len), 6790); // the length of icon
722 EXPECT_TRUE(state == SUCCESS);
723
724 density = 1; // invalid density
725 size_t len2;
726 state = rm->GetMediaDataByName("icon", len2, outValue, density);
727 EXPECT_EQ(static_cast<int>(len2), 0);
728 EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
729 }
730
731 /*
732 * @tc.name: ResourceManagerGetMediaBase64DataByIdFromHapTest0043
733 * @tc.desc: Test GetMediaBase64DataById, to match sdpi determinder
734 * @tc.type: FUNC
735 * @tc.require: issueI5LHLP
736 */
737 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaBase64DataByIdFromHapTest0043, TestSize.Level1)
738 {
739 rmc->AddHapResource("zh", nullptr, "CN");
740
741 auto rc = CreateResConfig();
742 if (rc == nullptr) {
743 EXPECT_TRUE(false);
744 return;
745 }
746 rc->SetDeviceType(DEVICE_TV);
747 rc->SetColorMode(COLOR_MODE_NOT_SET);
748 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
749 rm->UpdateResConfig(*rc);
750 delete rc;
751
752 int density = 120;
753 std::string outValue;
754 RState state;
755 int id = rmc->GetResId("icon", ResType::MEDIA);
756 EXPECT_TRUE(id > 0);
757 state = rm->GetMediaBase64DataById(id, outValue, density);
758 EXPECT_TRUE(state == SUCCESS);
759
760 density = 1; // invalid density
761 state = rm->GetMediaBase64DataById(id, outValue, density);
762 EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
763 }
764
765 /*
766 * @tc.name: ResourceManagerGetMediaBase64DataByNameFromHapTest0044
767 * @tc.desc: Test GetMediaDataById, to match sdpi determinder
768 * @tc.type: FUNC
769 * @tc.require: issueI5LHLP
770 */
771 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetMediaBase64DataByNameFromHapTest0044, TestSize.Level1)
772 {
773 rmc->AddHapResource("zh", nullptr, "CN");
774
775 auto rc = CreateResConfig();
776 if (rc == nullptr) {
777 EXPECT_TRUE(false);
778 return;
779 }
780 rc->SetDeviceType(DEVICE_TV);
781 rc->SetColorMode(COLOR_MODE_NOT_SET);
782 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
783 rm->UpdateResConfig(*rc);
784 delete rc;
785
786 int density = 120;
787 std::string outValue;
788 RState state;
789 state = rm->GetMediaBase64DataByName("icon", outValue, density);
790 EXPECT_TRUE(state == SUCCESS);
791
792 density = 1; // invalid density
793 state = rm->GetMediaBase64DataByName("icon", outValue, density);
794 EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
795 }
796
797 /*
798 * test get raw file path interface
799 * @tc.name: RawFileTestFromHap0045
800 * @tc.desc: Test GetRawFileFromHap & AddResource function, file case.
801 * @tc.type: FUNC
802 * @tc.require: issueI5LHLP
803 */
804 HWTEST_F(ResourceManagerTestHap, RawFileTestFromHap0045, TestSize.Level1)
805 {
806 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
807 EXPECT_TRUE(ret);
808 RState state;
809 size_t len;
810 std::unique_ptr<uint8_t[]> outValue;
811 state = rm->GetRawFileFromHap("test_rawfile.txt", len, outValue);
812 ASSERT_EQ(static_cast<int>(len), 17); // 17 means the length of "for raw file test" in "test_rawfile.txt"
813 EXPECT_TRUE(state == SUCCESS);
814
815 size_t len2;
816 std::unique_ptr<uint8_t[]> outValue2;
817 state = rm->GetRawFileFromHap("rawfile/test_rawfile.txt", len2, outValue2);
818 ASSERT_EQ(static_cast<int>(len2), 17); // 17 means the length of "for raw file test" in "test_rawfile.txt"
819 EXPECT_TRUE(state == SUCCESS);
820 }
821
822 /*
823 * test get raw file path interface
824 * @tc.name: RawFileTestFromHap0046
825 * @tc.desc: Test GetRawFileFromHap & AddResource function, file case.
826 * @tc.type: FUNC
827 * @tc.require: issueI5LHLP
828 */
829 HWTEST_F(ResourceManagerTestHap, RawFileTestFromHap0046, TestSize.Level1)
830 {
831 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
832 EXPECT_TRUE(ret);
833 ResourceManager::RawFileDescriptor descriptor;
834 RState state;
835 state = rm->GetRawFileDescriptorFromHap("test_rawfile.txt", descriptor);
836 EXPECT_TRUE(state == SUCCESS);
837 ASSERT_EQ(descriptor.length, 17); // 17 means the length of test_rawfile.txt after compressed
838 state = rm->CloseRawFileDescriptor("test_rawfile.txt");
839 EXPECT_TRUE(state == SUCCESS);
840
841 state = rm->GetRawFileDescriptorFromHap("rawfile/test_rawfile.txt", descriptor);
842 EXPECT_TRUE(state == SUCCESS);
843 ASSERT_EQ(descriptor.length, 17); // 17 means the length of test_rawfile.txt after compressed
844 state = rm->CloseRawFileDescriptor("rawfile/test_rawfile.txt");
845 EXPECT_TRUE(state == SUCCESS);
846
847 state = rm->CloseRawFileDescriptor("noexist.txt");
848 EXPECT_EQ(state, ERROR_CODE_RES_PATH_INVALID);
849 }
850
851 /*
852 * test get raw file path interface
853 * @tc.name: RawFileTestFromHap0047
854 * @tc.desc: Test GetRawFileFromHap & AddResource function, file case.
855 * @tc.type: FUNC
856 * @tc.require: issueI5LHLP
857 */
858 HWTEST_F(ResourceManagerTestHap, RawFileTestFromHap0047, TestSize.Level1)
859 {
860 rm->AddResource(FormatFullPath(g_resFilePath).c_str());
861 size_t len;
862 std::unique_ptr<uint8_t[]> outValue;
863 RState state = rm->GetRawFileFromHap("test_rawfile.txt", len, outValue);
864 ASSERT_EQ(static_cast<int>(len), 17); // 17 means the length of "for raw file test" in "test_rawfile.txt"
865 EXPECT_TRUE(state == SUCCESS);
866 }
867
868 /*
869 * test get raw file path interface
870 * @tc.name: RawFileTestFromHap0048
871 * @tc.desc: Test GetRawFileDescriptorFromHap & AddResource function, file case.
872 * @tc.type: FUNC
873 * @tc.require: issueI5LHLP
874 */
875 HWTEST_F(ResourceManagerTestHap, RawFileTestFromHap0048, TestSize.Level1)
876 {
877 rm->AddResource(FormatFullPath(g_resFilePath).c_str());
878 std::unique_ptr<uint8_t[]> outValue;
879 ResourceManager::RawFileDescriptor descriptor;
880 RState state;
881 state = rm->GetRawFileDescriptorFromHap("test_rawfile.txt", descriptor);
882 ASSERT_EQ(descriptor.length, 17);
883 EXPECT_TRUE(state == SUCCESS);
884 }
885
886 /*
887 * @tc.name: ResourceManagerOverlayTest001
888 * @tc.desc: Test overlay AddResource & UpdateResConfig function, file case.
889 * @tc.type: FUNC
890 * @tc.require: issueI5LHLP
891 */
892 HWTEST_F(ResourceManagerTestHap, ResourceManagerOverlayTest001, TestSize.Level1)
893 {
894 std::vector<std::string> overlayPaths;
895 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
896 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
897 ASSERT_TRUE(ret);
898
899 auto rc = CreateResConfig();
900 if (rc == nullptr) {
901 EXPECT_TRUE(false);
902 return;
903 }
904 rc->SetLocaleInfo("en", nullptr, "US");
905 rm->UpdateResConfig(*rc);
906 delete rc;
907 }
908
909 /*
910 * @tc.name: ResourceManagerOverlayTest002
911 * @tc.desc: Test overlay function
912 * @tc.type: FUNC
913 */
914 HWTEST_F(ResourceManagerTestHap, ResourceManagerOverlayTest002, TestSize.Level1)
915 {
916 rmc->AddResource("en", nullptr, nullptr);
917
918 std::vector<std::string> overlayPaths;
919 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
920 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
921 ASSERT_TRUE(ret);
922 ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
923 // repeat add the same overlayPaths
924 ASSERT_TRUE(ret);
925 rmc->TestStringById("ohos_app_name", "SystemOverlay");
926
927 std::vector<std::string> removePaths;
928 removePaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
929 ret = ((ResourceManagerImpl*)rm)->RemoveResource(FormatFullPath(g_resFilePath).c_str(), removePaths);
930 ASSERT_TRUE(ret);
931 rmc->TestStringById("ohos_app_name", "System");
932
933 ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
934 ASSERT_TRUE(ret);
935 rmc->TestStringById("ohos_app_name", "SystemOverlay");
936 }
937
938 /*
939 * @tc.name: ResourceManagerOverlayTest003
940 * @tc.desc: Test overlay function
941 * @tc.type: FUNC
942 */
943 HWTEST_F(ResourceManagerTestHap, ResourceManagerOverlayTest003, TestSize.Level1)
944 {
945 rmc->AddResource("en", nullptr, nullptr);
946
947 std::vector<std::string> overlayPaths;
948 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
949 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
950 ASSERT_TRUE(ret);
951 rmc->TestStringById("ohos_app_name", "SystemOverlay");
952
953 std::vector<std::string> removePaths;
954 removePaths.push_back("notexist.index");
955 removePaths.push_back("notexist2.index");
956 removePaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
957 ret = ((ResourceManagerImpl*)rm)->RemoveResource(FormatFullPath(g_resFilePath).c_str(), removePaths);
958 ASSERT_TRUE(ret);
959 rmc->TestStringById("ohos_app_name", "System");
960 }
961
962 /*
963 * @tc.name: ResourceManagerOverlayTest004
964 * @tc.desc: Test overlay function
965 * @tc.type: FUNC
966 */
967 HWTEST_F(ResourceManagerTestHap, ResourceManagerOverlayTest004, TestSize.Level1)
968 {
969 rmc->AddResource("zh", nullptr, nullptr);
970
971 std::vector<std::string> overlayPaths;
972 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
973 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
974 ASSERT_TRUE(ret);
975 rmc->TestStringById("ohos_lab_answer_call", "overlay接听电话");
976
977 std::vector<std::string> removePaths;
978 removePaths.push_back("notexist.index");
979 removePaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
980 ret = ((ResourceManagerImpl*)rm)->RemoveResource(FormatFullPath(g_resFilePath).c_str(), removePaths);
981 ASSERT_TRUE(ret);
982 rmc->TestStringById("ohos_lab_answer_call", "接听电话");
983
984 ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
985 ASSERT_TRUE(ret);
986 rmc->TestStringById("ohos_lab_answer_call", "overlay接听电话");
987 }
988
989 /*
990 * @tc.name: ResourceManagerUtilsTest001
991 * @tc.desc: Test endWithTail;
992 * @tc.type: FUNC
993 * @tc.require: issueI5LHLP
994 */
995 HWTEST_F(ResourceManagerTestHap, ResourceManagerUtilsTest001, TestSize.Level1)
996 {
997 std::string path = "";
998 std::string tail = ".hap";
999 bool ret = Utils::endWithTail(path, tail);
1000 ASSERT_FALSE(ret);
1001 }
1002
1003 /*
1004 * @tc.name: ResourceManagerGetResourceLimitKeysTest001
1005 * @tc.desc: Test GetResourceLimitKeys function
1006 * @tc.type: FUNC
1007 * @tc.require: issueI73ZQ8
1008 */
1009 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResourceLimitKeysTest001, TestSize.Level1)
1010 {
1011 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1012 ASSERT_TRUE(ret);
1013 // all/assets/entry/resources.index contains limit keys for LANGUAGE/REGION/
1014 // SCREEN_DENSITY/DEVICETYPE/COLORMODE/MCC/MNC/INPUTDEVICE
1015 rmc->TestGetResourceLimitKeys(DATA_ALL_HAP_LIMIT_KEYS);
1016 }
1017
1018 /*
1019 * @tc.name: ResourceManagerGetResourceLimitKeysTest002
1020 * @tc.desc: Test GetResourceLimitKeys function
1021 * @tc.type: FUNC
1022 * @tc.require: issueI73ZQ8
1023 */
1024 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResourceLimitKeysTest002, TestSize.Level1)
1025 {
1026 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1027 ASSERT_TRUE(ret);
1028 // all.hap contains limit keys for LANGUAGE/REGION/
1029 // SCREEN_DENSITY/DEVICETYPE/COLORMODE/MCC/MNC/INPUTDEVICE
1030 rmc->TestGetResourceLimitKeys(DATA_ALL_HAP_LIMIT_KEYS);
1031 }
1032
1033 /*
1034 * @tc.name: ResourceManagerGetResourceLimitKeysTest003
1035 * @tc.desc: Test GetResourceLimitKeys function
1036 * @tc.type: FUNC
1037 * @tc.require: issueI73ZQ8
1038 */
1039 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResourceLimitKeysTest003, TestSize.Level1)
1040 {
1041 std::vector<std::string> overlayPaths;
1042 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
1043 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
1044 ASSERT_TRUE(ret);
1045 // all/assets/entry/resources.index and overlay/assets/entry/resources.index contains
1046 // LANGUAGE/REGION/DIRECTION/COLORMODE
1047 rmc->TestGetResourceLimitKeys(SYSTEM_RES_LIMIT_KEYS);
1048 }
1049
1050 /*
1051 * @tc.name: ResourceManagerOverlayTest005
1052 * @tc.desc: Test overlay function
1053 * @tc.type: FUNC
1054 */
1055 HWTEST_F(ResourceManagerTestHap, ResourceManagerOverlayTest005, TestSize.Level1)
1056 {
1057 rmc->AddResource("zh", nullptr, nullptr);
1058 // test add invalid overlay path
1059 bool ret = ((ResourceManagerImpl*)rm)->AddAppOverlay("noexist.hap");
1060 ASSERT_FALSE(ret);
1061
1062 ret = ((ResourceManagerImpl*)rm)->AddAppOverlay(FormatFullPath(g_overlayResFilePath).c_str());
1063 ASSERT_TRUE(ret);
1064 rmc->TestStringById("ohos_lab_answer_call", "overlay接听电话");
1065 }
1066
1067 /*
1068 * @tc.name: ResourceManagerOverlayTest006
1069 * @tc.desc: Test overlay function
1070 * @tc.type: FUNC
1071 */
1072 HWTEST_F(ResourceManagerTestHap, ResourceManagerOverlayTest006, TestSize.Level1)
1073 {
1074 rmc->AddResource("zh", nullptr, nullptr);
1075 // test remove invalid overlay path
1076 bool ret = ((ResourceManagerImpl*)rm)->RemoveAppOverlay("noexist.hap");
1077 ASSERT_FALSE(ret);
1078
1079 ret = ((ResourceManagerImpl*)rm)->AddAppOverlay(FormatFullPath(g_overlayResFilePath).c_str());
1080 ASSERT_TRUE(ret);
1081 ret = ((ResourceManagerImpl*)rm)->RemoveAppOverlay(FormatFullPath(g_overlayResFilePath).c_str());
1082 ASSERT_TRUE(ret);
1083 rmc->TestStringById("ohos_lab_answer_call", "接听电话");
1084 }
1085
1086 /*
1087 * @tc.name: ResourceManagerGetResIdTest001
1088 * @tc.desc: Test GetResId function
1089 * @tc.type: FUNC
1090 */
1091 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResIdTest001, TestSize.Level1)
1092 {
1093 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1094 EXPECT_TRUE(ret);
1095 const std::string resTypeName = "app.string.entry_MainAbility";
1096 uint32_t id = 0;
1097 RState state = rm->GetResId(resTypeName, id);
1098 EXPECT_TRUE(state == SUCCESS);
1099 EXPECT_EQ(id, 16777226);
1100 }
1101
1102 /*
1103 * @tc.name: ResourceManagerGetResIdTest002
1104 * @tc.desc: Test GetResId function
1105 * @tc.type: FUNC
1106 */
1107 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResIdTest002, TestSize.Level1)
1108 {
1109 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1110 EXPECT_TRUE(ret);
1111 const std::string resTypeName = "app.media.icon";
1112 uint32_t id = 0;
1113 RState state = rm->GetResId(resTypeName, id);
1114 EXPECT_TRUE(state == SUCCESS);
1115 EXPECT_EQ(id, 16777321);
1116 }
1117
1118 /*
1119 * @tc.name: ResourceManagerGetResIdTest003
1120 * @tc.desc: Test GetResId function
1121 * @tc.type: FUNC
1122 */
1123 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResIdTest003, TestSize.Level1)
1124 {
1125 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1126 EXPECT_TRUE(ret);
1127 const std::string resTypeName = "app.color.color_aboutPage_title_primary";
1128 uint32_t id = 0;
1129 RState state = rm->GetResId(resTypeName, id);
1130 EXPECT_TRUE(state == SUCCESS);
1131 EXPECT_EQ(id, 16777273);
1132 }
1133
1134 /*
1135 * @tc.name: ResourceManagerGetResIdTest004
1136 * @tc.desc: Test GetResId function
1137 * @tc.type: FUNC
1138 */
1139 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResIdTest004, TestSize.Level1)
1140 {
1141 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1142 EXPECT_TRUE(ret);
1143 const std::string resTypeName = "app.string.xxx";
1144 uint32_t id = 0;
1145 RState state = rm->GetResId(resTypeName, id);
1146 EXPECT_TRUE(state == NOT_FOUND);
1147 EXPECT_EQ(id, 0);
1148 }
1149
1150 /*
1151 * @tc.name: ResourceManagerGetResIdTest005
1152 * @tc.desc: Test GetResId function
1153 * @tc.type: FUNC
1154 */
1155 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResIdTest005, TestSize.Level1)
1156 {
1157 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1158 EXPECT_TRUE(ret);
1159 const std::string resTypeName = "xxx.string.entry_MainAbility";
1160 uint32_t id = 0;
1161 RState state = rm->GetResId(resTypeName, id);
1162 EXPECT_TRUE(state == NOT_FOUND);
1163 EXPECT_EQ(id, 0);
1164 }
1165
1166 /*
1167 * @tc.name: ResourceManagerGetResIdTest006
1168 * @tc.desc: Test GetResId function
1169 * @tc.type: FUNC
1170 */
1171 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetResIdTest006, TestSize.Level1)
1172 {
1173 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1174 EXPECT_TRUE(ret);
1175 const std::string resTypeName = "app.xxx.entry_MainAbility";
1176 uint32_t id = 0;
1177 RState state = rm->GetResId(resTypeName, id);
1178 EXPECT_TRUE(state == NOT_FOUND);
1179 EXPECT_EQ(id, 0);
1180 }
1181
1182 /*
1183 * @tc.name: ResourceManagerGetLocalesTest001
1184 * @tc.desc: Test GetLocales function
1185 * @tc.type: FUNC
1186 */
1187 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetLocalesTest001, TestSize.Level1)
1188 {
1189 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1190 EXPECT_TRUE(ret);
1191 std::vector<std::string> outValue;
1192 rm->GetLocales(outValue);
1193 EXPECT_EQ(static_cast<size_t>(4), outValue.size());
1194 }
1195
1196 /*
1197 * @tc.name: ResourceManagerGetLocalesTest002
1198 * @tc.desc: Test GetLocales function
1199 * @tc.type: FUNC
1200 */
1201 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetLocalesTest002, TestSize.Level1)
1202 {
1203 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1204 EXPECT_TRUE(ret);
1205 std::vector<std::string> outValue;
1206 rm->GetLocales(outValue, false);
1207 EXPECT_EQ(static_cast<size_t>(4), outValue.size());
1208 }
1209
1210 /*
1211 * @tc.name: ResourceManagerGetLocalesTest003
1212 * @tc.desc: Test GetLocales function
1213 * @tc.type: FUNC
1214 */
1215 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetLocalesTest003, TestSize.Level1)
1216 {
1217 bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
1218 EXPECT_TRUE(ret);
1219 std::vector<std::string> outValue;
1220 rm->GetLocales(outValue, true);
1221 EXPECT_EQ(static_cast<size_t>(4), outValue.size());
1222 }
1223
1224 /*
1225 * @tc.name: ResourceManagerGetDrawableInfoByIdFromHapTest001
1226 * @tc.desc: Test GetDrawableInfo
1227 * @tc.type: FUNC
1228 * @tc.require: issueI5LHLP
1229 */
1230 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetDrawableInfoByIdFromHapTest001, TestSize.Level1)
1231 {
1232 rmc->AddHapResource("zh", nullptr, "CN");
1233
1234 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
1235 rmc->TestGetDrawableInfoById(tmp);
1236 delete tmp;
1237 }
1238
1239 /*
1240 * @tc.name: ResourceManagerGetDrawableInfoByIdFromHapTest002
1241 * @tc.desc: Test GetDrawableInfo, to match sdpi determinder
1242 * @tc.type: FUNC
1243 * @tc.require: issueI5LHLP
1244 */
1245 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetDrawableInfoByIdFromHapTest002, TestSize.Level1)
1246 {
1247 rmc->AddHapResource("en", nullptr, "US");
1248
1249 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
1250 rmc->TestGetDrawableInfoWithDensityById(tmp);
1251 delete tmp;
1252 }
1253
1254 /*
1255 * @tc.name: ResourceManagerGetDrawableInfoByNameFromHapTest001
1256 * @tc.desc: Test GetDrawableInfo
1257 * @tc.type: FUNC
1258 * @tc.require: issueI5LHLP
1259 */
1260 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetDrawableInfoByNameFromHapTest001, TestSize.Level1)
1261 {
1262 rmc->AddHapResource("zh", nullptr, "CN");
1263
1264 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
1265 rmc->TestGetDrawableInfoByName(tmp);
1266 delete tmp;
1267 }
1268
1269 /*
1270 * @tc.name: ResourceManagerGetDrawableInfoByNameFromHapTest002
1271 * @tc.desc: Test GetDrawableInfo, to match sdpi determinder
1272 * @tc.type: FUNC
1273 * @tc.require: issueI5LHLP
1274 */
1275 HWTEST_F(ResourceManagerTestHap, ResourceManagerGetDrawableInfoByNameFromHapTest002, TestSize.Level1)
1276 {
1277 rmc->AddHapResource("en", nullptr, "US");
1278
1279 HapResource *tmp = new HapResource(FormatFullPath(g_hapPath).c_str(), 0, nullptr);
1280 rmc->TestGetDrawableInfoWithDensityByName(tmp);
1281 delete tmp;
1282 }
1283 }
1284