• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "resource_manager_test.h"
17 
18 #include <climits>
19 #include <cstring>
20 #include <gtest/gtest.h>
21 #define private public
22 
23 #include "res_config.h"
24 #include "resource_manager.h"
25 #include "resource_manager_impl.h"
26 #include "test_common.h"
27 #include "utils/errors.h"
28 #include "utils/string_utils.h"
29 
30 using namespace OHOS::Global::Resource;
31 using namespace testing::ext;
32 namespace {
33 static const int NON_EXIST_ID = 1111;
34 
35 static const char *g_nonExistName = "non_existent_name";
36 class ResourceManagerTest : public testing::Test {
37 public:
38     static void SetUpTestCase(void);
39 
40     static void TearDownTestCase(void);
41 
42     void SetUp();
43 
44     void TearDown();
45 
ResourceManagerTest()46     ResourceManagerTest() : rm(nullptr)
47     {}
48 
~ResourceManagerTest()49     ~ResourceManagerTest()
50     {}
51 
52 public:
53     ResourceManager *rm;
54 
55     int GetResId(std::string name, ResType resType) const;
56 
57     void TestStringByName(const char *name, const char *cmp) const;
58 
59     void TestStringById(const char *name, const char *cmp) const;
60 
61     void TestPluralStringById(int quantity, const char *cmp, bool format = false) const;
62 
63     void TestPluralStringByName(int quantity, const char *cmp, bool format = false) const;
64 
65     void AddResource(const char *language, const char *script, const char *region);
66 };
67 
GetResId(std::string name,ResType resType) const68 int ResourceManagerTest::GetResId(std::string name, ResType resType) const
69 {
70     auto idv = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType);
71     if (idv == nullptr) {
72         return -1;
73     }
74 
75     PrintIdValues(idv);
76     if (idv->GetLimitPathsConst().size() > 0) {
77         return idv->GetLimitPathsConst()[0]->GetIdItem()->id_;
78     }
79     return OBJ_NOT_FOUND;
80 }
81 
TestStringByName(const char * name,const char * cmp) const82 void ResourceManagerTest::TestStringByName(const char *name, const char *cmp) const
83 {
84     RState rState;
85     std::string outValue;
86     rState = rm->GetStringByName(name, outValue);
87     ASSERT_EQ(SUCCESS, rState);
88     HILOG_DEBUG("%s : %s", name, outValue.c_str());
89     ASSERT_EQ(std::string(cmp), outValue);
90 }
91 
TestStringById(const char * name,const char * cmp) const92 void ResourceManagerTest::TestStringById(const char *name, const char *cmp) const
93 {
94     RState rState;
95     std::string outValue;
96     int id = GetResId(name, ResType::STRING);
97     ASSERT_TRUE(id > 0);
98     rState = rm->GetStringById(id, outValue);
99     ASSERT_EQ(SUCCESS, rState);
100     ASSERT_EQ(std::string(cmp), outValue);
101 }
102 
AddResource(const char * language,const char * script,const char * region)103 void ResourceManagerTest::AddResource(const char *language, const char *script, const char *region)
104 {
105     if (language != nullptr || region != nullptr) {
106         auto rc = CreateResConfig();
107         if (rc == nullptr) {
108             EXPECT_TRUE(false);
109             return;
110         }
111         rc->SetLocaleInfo(language, script, region);
112         rm->UpdateResConfig(*rc);
113         delete rc;
114     }
115     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
116     ASSERT_TRUE(ret);
117 }
118 
TestPluralStringById(int quantity,const char * cmp,bool format) const119 void ResourceManagerTest::TestPluralStringById(int quantity, const char *cmp, bool format) const
120 {
121     RState ret;
122     std::string outValue;
123     int id = GetResId("eat_apple", ResType::PLURALS);
124     if (format) {
125         ret = rm->GetPluralStringByIdFormat(outValue, id, quantity, quantity);
126     } else {
127         ret = rm->GetPluralStringById(id, quantity, outValue);
128     }
129 
130     ASSERT_EQ(SUCCESS, ret);
131     ASSERT_EQ(std::string(cmp), outValue);
132 }
133 
TestPluralStringByName(int quantity,const char * cmp,bool format) const134 void ResourceManagerTest::TestPluralStringByName(int quantity, const char *cmp, bool format) const
135 {
136     RState ret;
137     std::string outValue;
138     const char *name = "eat_apple";
139     if (format) {
140         ret = rm->GetPluralStringByNameFormat(outValue, name, quantity, quantity);
141     } else {
142         ret = rm->GetPluralStringByName(name, quantity, outValue);
143     }
144 
145     ASSERT_EQ(SUCCESS, ret);
146     ASSERT_EQ(std::string(cmp), outValue);
147 }
148 
SetUpTestCase(void)149 void ResourceManagerTest::SetUpTestCase(void)
150 {
151     // step 1: input testsuit setup step
152     g_logLevel = LOG_DEBUG;
153 }
154 
TearDownTestCase(void)155 void ResourceManagerTest::TearDownTestCase(void)
156 {
157     // step 2: input testsuit teardown step
158 }
159 
SetUp(void)160 void ResourceManagerTest::SetUp(void)
161 {
162     this->rm = CreateResourceManager();
163 }
164 
TearDown(void)165 void ResourceManagerTest::TearDown(void)
166 {
167     delete this->rm;
168 }
169 
170 /*
171  * @tc.name: ResourceManagerAddResourceTest001
172  * @tc.desc: Test AddResource function, file case.
173  * @tc.type: FUNC
174  */
175 HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest001, TestSize.Level1)
176 {
177     // success cases
178     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
179     ASSERT_TRUE(ret);
180 };
181 
182 /*
183  * @tc.name: ResourceManagerAddResourceTest002
184  * @tc.desc: Test AddResource function, file case.
185  * @tc.type: FUNC
186  */
187 HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest002, TestSize.Level1)
188 {
189     // error cases
190     // file not exist
191     bool ret = rm->AddResource("/data/test/do_not_exist.resources");
192     ASSERT_TRUE(!ret);
193 }
194 
195 /*
196  * @tc.name: ResourceManagerAddResourceTest003
197  * @tc.desc: Test AddResource function, file case.
198  * @tc.type: FUNC
199  */
200 HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest003, TestSize.Level1)
201 {
202     // error cases
203     // reload the same path
204     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
205     ASSERT_TRUE(ret);
206     ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
207     ASSERT_TRUE(!ret);
208 }
209 
210 /*
211  * @tc.name: ResourceManagerUpdateResConfigTest001
212  * @tc.desc: Test UpdateResConfig function
213  * @tc.type: FUNC
214  */
215 HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest001, TestSize.Level1)
216 {
217     // success cases
218     RState state;
219     ResConfig *rc = CreateResConfig();
220     if (rc == nullptr) {
221         EXPECT_TRUE(false);
222         return;
223     }
224     rc->SetLocaleInfo("en", nullptr, "US");
225     rc->SetDeviceType(DeviceType::DEVICE_CAR);
226     state = rm->UpdateResConfig(*rc);
227     delete rc;
228     EXPECT_EQ(SUCCESS, state);
229 }
230 
231 /*
232  * @tc.name: ResourceManagerUpdateResConfigTest002
233  * @tc.desc: Test UpdateResConfig function
234  * @tc.type: FUNC
235  */
236 HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest002, TestSize.Level1)
237 {
238     // error cases
239     RState state;
240     ResConfig *rc = CreateResConfig();
241     if (rc == nullptr) {
242         EXPECT_TRUE(false);
243         return;
244     }
245     state = rm->UpdateResConfig(*rc);
246     delete rc;
247     EXPECT_EQ(LOCALEINFO_IS_NULL, state);
248 }
249 
250 /*
251  * @tc.name: ResourceManagerUpdateResConfigTest003
252  * @tc.desc: Test UpdateResConfig function
253  * @tc.type: FUNC
254  */
255 HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest003, TestSize.Level1)
256 {
257     // error cases
258     RState state;
259     ResConfig *rc = CreateResConfig();
260     if (rc == nullptr) {
261         EXPECT_TRUE(false);
262         return;
263     }
264     rc->SetLocaleInfo(nullptr, nullptr, "US");
265     state = rm->UpdateResConfig(*rc);
266     delete rc;
267     EXPECT_EQ(LOCALEINFO_IS_NULL, state);
268 }
269 
270 /*
271  * load a hap, defaultConfig set to en, then switch to zh
272  * @tc.name: ResourceManagerUpdateResConfigTest004
273  * @tc.desc: Test UpdateResConfig function
274  * @tc.type: FUNC
275  */
276 HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest004, TestSize.Level1)
277 {
278     // success case
279     bool ret = true;
280     RState state;
281     ResConfig *rc = CreateResConfig();
282     if (rc == nullptr) {
283         EXPECT_TRUE(false);
284         return;
285     }
286     rc->SetLocaleInfo("en", nullptr, nullptr);
287     state = rm->UpdateResConfig(*rc);
288     EXPECT_EQ(SUCCESS, state);
289     ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
290     if (!ret) {
291         EXPECT_TRUE(false);
292         delete rc;
293         return;
294     }
295     // update to another language, will trigger reload
296     // before reload:
297     TestStringByName("app_name", "App Name");
298 
299     rc->SetLocaleInfo("zh", nullptr, nullptr);
300     state = rm->UpdateResConfig(*rc);
301     delete rc;
302     EXPECT_EQ(SUCCESS, state);
303     // after reload:
304     TestStringByName("app_name", "应用名称");
305 }
306 
307 /*
308  * @tc.name: ResourceManagerUpdateResConfigTest005
309  * @tc.desc: Test UpdateResConfig function
310  * @tc.type: FUNC
311  */
312 HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest005, TestSize.Level1)
313 {
314     // error case
315     AddResource("zh", nullptr, nullptr);
316 
317     // make a fake hapResource, then reload will fail
318     HapResource *hapResource = new HapResource("/data/test/non_exist", 0, nullptr, nullptr);
319     ((ResourceManagerImpl *)rm)->hapManager_->hapResources_.push_back(hapResource);
320     RState state;
321     ResConfig *rc = CreateResConfig();
322     if (rc == nullptr) {
323         EXPECT_TRUE(false);
324         return;
325     }
326     rc->SetLocaleInfo("en", nullptr, "US");
327     state = rm->UpdateResConfig(*rc);
328     delete rc;
329     EXPECT_EQ(HAP_INIT_FAILED, state);
330 }
331 
332 /*
333  * @tc.name: ResourceManagerGetResConfigTest001
334  * @tc.desc: Test GetResConfig function
335  * @tc.type: FUNC
336  */
337 HWTEST_F(ResourceManagerTest, ResourceManagerGetResConfigTest001, TestSize.Level1)
338 {
339     // success cases
340     ResConfigImpl rc;
341     rm->GetResConfig(rc);
342     EXPECT_EQ(nullptr, rc.GetLocaleInfo());
343     EXPECT_EQ(DIRECTION_NOT_SET, rc.GetDirection());
344     EXPECT_EQ(SCREEN_DENSITY_NOT_SET, rc.GetScreenDensity());
345     EXPECT_EQ(DEVICE_NOT_SET, rc.GetDeviceType());
346 }
347 
348 /*
349  * @tc.name: ResourceManagerGetResConfigTest002
350  * @tc.desc: Test GetResConfig function
351  * @tc.type: FUNC
352  */
353 HWTEST_F(ResourceManagerTest, ResourceManagerGetResConfigTest002, TestSize.Level1)
354 {
355     // success cases
356     RState state;
357     {
358         ResConfig *rc = CreateResConfig();
359         if (rc == nullptr) {
360             EXPECT_TRUE(false);
361             return;
362         }
363         rc->SetLocaleInfo("en", nullptr, "US");
364         rc->SetDeviceType(DeviceType::DEVICE_CAR);
365         state = rm->UpdateResConfig(*rc);
366         delete rc;
367         EXPECT_EQ(SUCCESS, state);
368     }
369 
370     ResConfigImpl rc;
371     rm->GetResConfig(rc);
372     EXPECT_EQ("en", std::string(rc.GetLocaleInfo()->GetLanguage()));
373     EXPECT_EQ(DEVICE_CAR, rc.GetDeviceType());
374 }
375 
376 /*
377  * @tc.name: ResourceManagerGetStringByIdTest001
378  * @tc.desc: Test GetStringById function
379  * @tc.type: FUNC
380  */
381 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest001, TestSize.Level1)
382 {
383     AddResource("en", nullptr, nullptr);
384 
385     TestStringById("app_name", "App Name");
386 
387     TestStringById("copyright_text", "XXXXXX All rights reserved. ©2011-2019");
388 
389     TestStringById("string_ref", "XXXXXX All rights reserved. ©2011-2019");
390 
391     TestStringById("string_ref2", "XXXXXX All rights reserved. ©2011-2019");
392 }
393 
394 /*
395  * @tc.name: ResourceManagerGetStringByIdTest002
396  * @tc.desc: Test GetStringById function
397  * @tc.type: FUNC
398  */
399 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest002, TestSize.Level1)
400 {
401     AddResource("zh", nullptr, nullptr);
402 
403     TestStringById("app_name", "应用名称");
404 
405     TestStringById("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利");
406 
407     TestStringById("string_ref", "$aaaaa");
408 
409     TestStringById("string_ref2", "$aaaaa");
410 }
411 
412 /*
413  * @tc.name: ResourceManagerGetStringByIdTest003
414  * @tc.desc: Test GetStringById function
415  * @tc.type: FUNC
416  */
417 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest003, TestSize.Level1)
418 {
419     AddResource("zh", nullptr, nullptr);
420 
421     std::string outValue;
422     RState state = rm->GetStringById(NON_EXIST_ID, outValue);
423     ASSERT_EQ(NOT_FOUND, state);
424 }
425 
426 /*
427  * @tc.name: ResourceManagerGetStringByNameTest001
428  * @tc.desc: Test GetStringByName function
429  * @tc.type: FUNC
430  */
431 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByNameTest001, TestSize.Level1)
432 {
433     AddResource("en", nullptr, nullptr);
434 
435     TestStringByName("app_name", "App Name");
436 
437     TestStringByName("copyright_text", "XXXXXX All rights reserved. ©2011-2019");
438 
439     TestStringByName("string_ref", "XXXXXX All rights reserved. ©2011-2019");
440 
441     TestStringByName("string_ref2", "XXXXXX All rights reserved. ©2011-2019");
442 }
443 
444 /*
445  * @tc.name: ResourceManagerGetStringByNameTest002
446  * @tc.desc: Test GetStringByName function
447  * @tc.type: FUNC
448  */
449 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByNameTest002, TestSize.Level1)
450 {
451     AddResource("zh", nullptr, nullptr);
452 
453     TestStringByName("app_name", "应用名称");
454 
455     TestStringByName("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利");
456 
457     TestStringByName("string_ref", "$aaaaa");
458 
459     TestStringByName("string_ref2", "$aaaaa");
460 }
461 
462 /*
463  * @tc.name: ResourceManagerGetStringByNameTest003
464  * @tc.desc: Test GetStringByName function
465  * @tc.type: FUNC
466  */
467 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByNameTest003, TestSize.Level1)
468 {
469     AddResource("zh", nullptr, nullptr);
470 
471     std::string outValue;
472     RState state = rm->GetStringByName(g_nonExistName, outValue);
473     ASSERT_EQ(NOT_FOUND, state);
474 }
475 
476 /*
477  * @tc.name: ResourceManagerGetStringFormatByIdTest001
478  * @tc.desc: Test GetStringFormatById function
479  * @tc.type: FUNC
480  */
481 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByIdTest001, TestSize.Level1)
482 {
483     AddResource("zh", nullptr, nullptr);
484 
485     const char *name = "app_name";
486     int id = GetResId(name, ResType::STRING);
487     ASSERT_TRUE(id > 0);
488     std::string outValue;
489     RState state = rm->GetStringFormatById(outValue, id, 101);
490     ASSERT_EQ(SUCCESS, state);
491     ASSERT_EQ("应用名称", outValue);
492 }
493 
494 /*
495  * @tc.name: ResourceManagerGetStringFormatByIdTest002
496  * @tc.desc: Test GetStringFormatById function
497  * @tc.type: FUNC
498  */
499 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByIdTest002, TestSize.Level1)
500 {
501     AddResource("zh", nullptr, nullptr);
502 
503     std::string outValue;
504     RState state = rm->GetStringFormatById(outValue, NON_EXIST_ID, 101);
505     ASSERT_EQ(NOT_FOUND, state);
506 }
507 
508 /*
509  * @tc.name: ResourceManagerGetStringFormatByNameTest001
510  * @tc.desc: Test GetStringFormatByName function
511  * @tc.type: FUNC
512  */
513 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByNameTest001, TestSize.Level1)
514 {
515     AddResource("zh", nullptr, nullptr);
516 
517     const char *name = "app_name";
518     std::string outValue;
519     RState state = rm->GetStringFormatByName(outValue, name, 101);
520     ASSERT_EQ(SUCCESS, state);
521     ASSERT_EQ("应用名称", outValue);
522 }
523 
524 /*
525  * @tc.name: ResourceManagerGetStringFormatByNameTest002
526  * @tc.desc: Test GetStringFormatByName function
527  * @tc.type: FUNC
528  */
529 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByNameTest002, TestSize.Level1)
530 {
531     AddResource("zh", nullptr, nullptr);
532 
533     std::string outValue;
534     RState state = rm->GetStringFormatByName(outValue, g_nonExistName, 101);
535     ASSERT_EQ(NOT_FOUND, state);
536 }
537 
538 /*
539  * @tc.name: ResourceManagerGetStringArrayByIdTest001
540  * @tc.desc: Test GetStringArrayById function, file case.
541  * @tc.type: FUNC
542  */
543 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByIdTest001, TestSize.Level1)
544 {
545     AddResource("zh", nullptr, nullptr);
546 
547     int id;
548     std::vector<std::string> outValue;
549     RState state;
550 
551     id = GetResId("size", ResType::STRINGARRAY);
552     state = rm->GetStringArrayById(id, outValue);
553     ASSERT_EQ(SUCCESS, state);
554     ASSERT_EQ(static_cast<size_t>(4), outValue.size());
555     PrintVectorString(outValue);
556 
557     // by name
558     state = rm->GetStringArrayByName("size", outValue);
559     ASSERT_EQ(SUCCESS, state);
560     ASSERT_EQ(static_cast<size_t>(4), outValue.size());
561     PrintVectorString(outValue);
562 }
563 
564 /*
565  * @tc.name: ResourceManagerGetStringArrayByIdTest002
566  * @tc.desc: Test GetStringArrayById function, file case.
567  * @tc.type: FUNC
568  */
569 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByIdTest002, TestSize.Level1)
570 {
571     AddResource("zh", nullptr, nullptr);
572 
573     RState state;
574     // error case
575     // not found case
576     std::vector<std::string> outValue;
577     state = rm->GetStringArrayById(NON_EXIST_ID, outValue);
578     ASSERT_EQ(NOT_FOUND, state);
579 }
580 
581 /*
582  * @tc.name: ResourceManagerGetStringArrayByNameTest001
583  * @tc.desc: Test GetStringArrayByName function, file case.
584  * @tc.type: FUNC
585  */
586 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByNameTest001, TestSize.Level1)
587 {
588     AddResource("zh", nullptr, nullptr);
589 
590     std::vector<std::string> outValue;
591     RState state;
592 
593     // by name
594     state = rm->GetStringArrayByName("size", outValue);
595     ASSERT_EQ(SUCCESS, state);
596     ASSERT_EQ(static_cast<size_t>(4), outValue.size());
597     PrintVectorString(outValue);
598 }
599 
600 /*
601  * @tc.name: ResourceManagerGetStringArrayByNameTest002
602  * @tc.desc: Test GetStringArrayByName function, file case.
603  * @tc.type: FUNC
604  */
605 HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByNameTest002, TestSize.Level1)
606 {
607     AddResource("zh", nullptr, nullptr);
608 
609     RState state;
610     // error case
611     // not found case
612     std::vector<std::string> outValue;
613     state = rm->GetStringArrayByName(g_nonExistName, outValue);
614     ASSERT_EQ(NOT_FOUND, state);
615 }
616 
617 /*
618  * @tc.name: ResourceManagerGetPatternByIdTest001
619  * @tc.desc: Test GetPatternById function, file case.
620  * @tc.type: FUNC
621  */
622 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest001, TestSize.Level1)
623 {
624     AddResource("zh", nullptr, nullptr);
625 
626     int id;
627     std::map<std::string, std::string> outValue;
628     RState state;
629 
630     id = GetResId("base", ResType::PATTERN);
631     ASSERT_TRUE(id > 0);
632     state = rm->GetPatternById(id, outValue);
633     ASSERT_EQ(SUCCESS, state);
634     ASSERT_EQ(static_cast<size_t>(3), outValue.size());
635     PrintMapString(outValue);
636 }
637 
638 /*
639  * @tc.name: ResourceManagerGetPatternByIdTest002
640  * @tc.desc: Test GetPatternById function, file case.
641  * @tc.type: FUNC
642  */
643 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest002, TestSize.Level1)
644 {
645     AddResource("zh", nullptr, nullptr);
646 
647     int id;
648     std::map<std::string, std::string> outValue;
649     RState state;
650 
651     id = GetResId("child", ResType::PATTERN);
652     ASSERT_TRUE(id > 0);
653     state = rm->GetPatternById(id, outValue);
654     ASSERT_EQ(SUCCESS, state);
655     ASSERT_EQ(static_cast<size_t>(4), outValue.size());
656     PrintMapString(outValue);
657 }
658 
659 /*
660  * @tc.name: ResourceManagerGetPatternByIdTest003
661  * @tc.desc: Test GetPatternById function, file case.
662  * @tc.type: FUNC
663  */
664 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest003, TestSize.Level1)
665 {
666     AddResource("zh", nullptr, nullptr);
667 
668     int id;
669     std::map<std::string, std::string> outValue;
670     RState state;
671 
672     id = GetResId("ccchild", ResType::PATTERN);
673     ASSERT_TRUE(id > 0);
674     state = rm->GetPatternById(id, outValue);
675     ASSERT_EQ(SUCCESS, state);
676     ASSERT_EQ(static_cast<size_t>(5), outValue.size());
677     PrintMapString(outValue);
678 }
679 
680 /*
681  * @tc.name: ResourceManagerGetPatternByIdTest004
682  * @tc.desc: Test GetPatternById function, file case.
683  * @tc.type: FUNC
684  */
685 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest004, TestSize.Level1)
686 {
687     AddResource("zh", nullptr, nullptr);
688 
689     std::map<std::string, std::string> outValue;
690     RState state;
691 
692     // not found case
693     state = rm->GetPatternById(NON_EXIST_ID, outValue);
694     ASSERT_EQ(NOT_FOUND, state);
695 }
696 
697 /*
698  * @tc.name: ResourceManagerGetPatternByNameTest001
699  * @tc.desc: Test GetPatternByName function, file case.
700  * @tc.type: FUNC
701  */
702 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest001, TestSize.Level1)
703 {
704     AddResource("zh", nullptr, nullptr);
705 
706     std::map<std::string, std::string> outValue;
707     RState state;
708 
709     state = rm->GetPatternByName("base", outValue);
710     ASSERT_EQ(SUCCESS, state);
711     ASSERT_EQ(static_cast<size_t>(3), outValue.size());
712     PrintMapString(outValue);
713 }
714 
715 /*
716  * @tc.name: ResourceManagerGetPatternByNameTest002
717  * @tc.desc: Test GetPatternByName function, file case.
718  * @tc.type: FUNC
719  */
720 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest002, TestSize.Level1)
721 {
722     AddResource("zh", nullptr, nullptr);
723 
724     std::map<std::string, std::string> outValue;
725     RState state;
726 
727     state = rm->GetPatternByName("child", outValue);
728     ASSERT_EQ(SUCCESS, state);
729     ASSERT_EQ(static_cast<size_t>(4), outValue.size());
730     PrintMapString(outValue);
731 }
732 
733 /*
734  * @tc.name: ResourceManagerGetPatternByNameTest003
735  * @tc.desc: Test GetPatternByName function, file case.
736  * @tc.type: FUNC
737  */
738 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest003, TestSize.Level1)
739 {
740     AddResource("zh", nullptr, nullptr);
741 
742     std::map<std::string, std::string> outValue;
743     RState state;
744 
745     state = rm->GetPatternByName("ccchild", outValue);
746     ASSERT_EQ(SUCCESS, state);
747     ASSERT_EQ(static_cast<size_t>(5), outValue.size());
748     PrintMapString(outValue);
749 }
750 
751 /*
752  * @tc.name: ResourceManagerGetPatternByNameTest004
753  * @tc.desc: Test GetPatternByName function, file case.
754  * @tc.type: FUNC
755  */
756 HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest004, TestSize.Level1)
757 {
758     AddResource("zh", nullptr, nullptr);
759 
760     std::map<std::string, std::string> outValue;
761     RState state;
762 
763     // not found case
764     state = rm->GetPatternByName(g_nonExistName, outValue);
765     ASSERT_EQ(NOT_FOUND, state);
766 }
767 
768 /*
769  * @tc.name: ResourceManagerGetPluralStringByIdTest001
770  * @tc.desc: Test GetPluralStringById function, file case.
771  * @tc.type: FUNC
772  */
773 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest001, TestSize.Level1)
774 {
775     AddResource("en", nullptr, "US");
776 
777     int quantity = 1;
778     TestPluralStringById(quantity, "%d apple", false);
779 
780     quantity = 101;
781     TestPluralStringById(quantity, "%d apples", false);
782 }
783 
784 /*
785  * @tc.name: ResourceManagerGetPluralStringByIdTest002
786  * @tc.desc: Test GetPluralStringById function, file case.
787  * @tc.type: FUNC
788  */
789 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest002, TestSize.Level1)
790 {
791     AddResource("zh", nullptr, "CN");
792 
793     int quantity = 1;
794     TestPluralStringById(quantity, "%d apples", false);
795 
796     quantity = 101;
797     TestPluralStringById(quantity, "%d apples", false);
798 }
799 
800 /*
801  * @tc.name: ResourceManagerGetPluralStringByIdTest003
802  * @tc.desc: Test GetPluralStringById function, file case.
803  * @tc.type: FUNC
804  */
805 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest003, TestSize.Level1)
806 {
807     AddResource("pl", nullptr, "PL");
808 
809     int quantity = 1;
810     TestPluralStringById(quantity, "1 jabłko");
811 
812     quantity = 2;
813     TestPluralStringById(quantity, "%d jabłka");
814 
815     quantity = 23;
816     TestPluralStringById(quantity, "%d jabłka");
817 
818     quantity = 12;
819     TestPluralStringById(quantity, "%d jabłek");
820 }
821 
822 /*
823  * @tc.name: ResourceManagerGetPluralStringByIdTest004
824  * @tc.desc: Test GetPluralStringById function, file case.
825  * @tc.type: FUNC
826  */
827 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest004, TestSize.Level1)
828 {
829     AddResource("ar", nullptr, "SA");
830 
831     int quantity = 0;
832     TestPluralStringById(quantity, "zero-0");
833     quantity = 1;
834     TestPluralStringById(quantity, "one-1");
835     quantity = 2;
836     TestPluralStringById(quantity, "two-2");
837     quantity = 5;
838     TestPluralStringById(quantity, "few-%d");
839     quantity = 12;
840     TestPluralStringById(quantity, "many-%d");
841     quantity = 500;
842     TestPluralStringById(quantity, "other-%d");
843 }
844 
845 /*
846  * @tc.name: ResourceManagerGetPluralStringByIdTest005
847  * @tc.desc: Test GetPluralStringById function, file case.
848  * @tc.type: FUNC
849  */
850 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest005, TestSize.Level1)
851 {
852     AddResource("ar", nullptr, "SA");
853 
854     RState state;
855     std::string outValue;
856     state = rm->GetPluralStringById(NON_EXIST_ID, 1, outValue);
857     ASSERT_EQ(NOT_FOUND, state);
858 }
859 
860 /*
861  * @tc.name: ResourceManagerGetPluralStringByNameTest001
862  * @tc.desc: Test GetPluralStringByName function, file case.
863  * @tc.type: FUNC
864  */
865 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameTest001, TestSize.Level1)
866 {
867     AddResource("en", nullptr, "US");
868 
869     int quantity = 1;
870     TestPluralStringByName(quantity, "%d apple", false);
871 
872     quantity = 101;
873     TestPluralStringByName(quantity, "%d apples", false);
874 }
875 
876 /*
877  * @tc.name: ResourceManagerGetPluralStringByNameTest002
878  * @tc.desc: Test GetPluralStringByName function, file case.
879  * @tc.type: FUNC
880  */
881 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameTest002, TestSize.Level1)
882 {
883     AddResource("ar", nullptr, "SA");
884 
885     RState state;
886     std::string outValue;
887     state = rm->GetPluralStringByName(g_nonExistName, 1, outValue);
888     ASSERT_EQ(NOT_FOUND, state);
889 }
890 
891 /*
892  * @tc.name: ResourceManagerGetPluralStringByIdFormatTest001
893  * @tc.desc: Test GetPluralStringByIdFormat function, file case.
894  * @tc.type: FUNC
895  */
896 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdFormatTest001, TestSize.Level1)
897 {
898     AddResource("zh", nullptr, "CN");
899 
900     int quantity = 1;
901     TestPluralStringById(quantity, "1 apples", true);
902 
903     quantity = 101;
904     TestPluralStringById(quantity, "101 apples", true);
905 }
906 
907 /*
908  * @tc.name: ResourceManagerGetPluralStringByIdFormatTest002
909  * @tc.desc: Test GetPluralStringByIdFormat function, file case.
910  * @tc.type: FUNC
911  */
912 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdFormatTest002, TestSize.Level1)
913 {
914     AddResource("ar", nullptr, "SA");
915 
916     RState state;
917     std::string outValue;
918     state = rm->GetPluralStringByIdFormat(outValue, NON_EXIST_ID, 1, 1);
919     ASSERT_EQ(NOT_FOUND, state);
920 }
921 
922 /*
923  * @tc.name: ResourceManagerGetPluralStringByNameFormatTest001
924  * @tc.desc: Test GetPluralStringByNameFormat function, file case.
925  * @tc.type: FUNC
926  */
927 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameFormatTest001, TestSize.Level1)
928 {
929     AddResource("zh", nullptr, "CN");
930 
931     int quantity = 1;
932     TestPluralStringByName(quantity, "1 apples", true);
933 
934     quantity = 101;
935     TestPluralStringByName(quantity, "101 apples", true);
936 }
937 
938 /*
939  * @tc.name: ResourceManagerGetPluralStringByNameFormatTest002
940  * @tc.desc: Test GetPluralStringByNameFormat function, file case.
941  * @tc.type: FUNC
942  */
943 HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameFormatTest002, TestSize.Level1)
944 {
945     AddResource("ar", nullptr, "SA");
946 
947     RState state;
948     std::string outValue;
949     state = rm->GetPluralStringByNameFormat(outValue, g_nonExistName, 1, 1);
950     ASSERT_EQ(NOT_FOUND, state);
951 }
952 
953 /*
954  * @tc.name: ResourceManagerGetThemeByIdTest001
955  * @tc.desc: Test GetThemeById
956  * @tc.type: FUNC
957  */
958 HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByIdTest001, TestSize.Level1)
959 {
960     AddResource("zh", nullptr, "CN");
961 
962     std::map<std::string, std::string> outValue;
963     RState state;
964     int id = GetResId("app_theme", ResType::THEME);
965     ASSERT_TRUE(id > 0);
966     state = rm->GetThemeById(id, outValue);
967     ASSERT_EQ(SUCCESS, state);
968     PrintMapString(outValue);
969 }
970 
971 /*
972  * @tc.name: ResourceManagerGetThemeByIdTest002
973  * @tc.desc: Test GetThemeById
974  * @tc.type: FUNC
975  */
976 HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByIdTest002, TestSize.Level1)
977 {
978     AddResource("zh", nullptr, "CN");
979 
980     std::map<std::string, std::string> outValue;
981     RState state;
982     state = rm->GetThemeById(NON_EXIST_ID, outValue);
983     ASSERT_EQ(NOT_FOUND, state);
984 }
985 
986 /*
987  * @tc.name: ResourceManagerGetThemeByNameTest001
988  * @tc.desc: Test GetThemeByName
989  * @tc.type: FUNC
990  */
991 HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByNameTest001, TestSize.Level1)
992 {
993     AddResource("zh", nullptr, "CN");
994 
995     std::map<std::string, std::string> outValue;
996     RState state;
997     state = rm->GetThemeByName("app_theme", outValue);
998     ASSERT_EQ(SUCCESS, state);
999     PrintMapString(outValue);
1000 
1001     state = rm->GetThemeByName("test_theme", outValue);
1002     ASSERT_EQ(SUCCESS, state);
1003     PrintMapString(outValue);
1004 }
1005 
1006 /*
1007  * @tc.name: ResourceManagerGetThemeByNameTest002
1008  * @tc.desc: Test GetThemeByName
1009  * @tc.type: FUNC
1010  */
1011 HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByNameTest002, TestSize.Level1)
1012 {
1013     AddResource("zh", nullptr, "CN");
1014 
1015     std::map<std::string, std::string> outValue;
1016     RState state;
1017     state = rm->GetThemeByName(g_nonExistName, outValue);
1018     ASSERT_EQ(NOT_FOUND, state);
1019 }
1020 
1021 /*
1022  * @tc.name: ResourceManagerGetBooleanByIdTest001
1023  * @tc.desc: Test GetBooleanById
1024  * @tc.type: FUNC
1025  */
1026 HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByIdTest001, TestSize.Level1)
1027 {
1028     AddResource("zh", nullptr, "CN");
1029 
1030     bool outValue = true;
1031     RState state;
1032     int id = GetResId("boolean_1", ResType::BOOLEAN);
1033     ASSERT_TRUE(id > 0);
1034     state = rm->GetBooleanById(id, outValue);
1035     ASSERT_EQ(SUCCESS, state);
1036     EXPECT_TRUE(outValue);
1037 
1038     id = GetResId("boolean_ref", ResType::BOOLEAN);
1039     ASSERT_TRUE(id > 0);
1040     state = rm->GetBooleanById(id, outValue);
1041     ASSERT_EQ(SUCCESS, state);
1042     EXPECT_TRUE(outValue);
1043 }
1044 
1045 /*
1046  * @tc.name: ResourceManagerGetBooleanByIdTest002
1047  * @tc.desc: Test GetBooleanById
1048  * @tc.type: FUNC
1049  */
1050 HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByIdTest002, TestSize.Level1)
1051 {
1052     AddResource("zh", nullptr, "CN");
1053 
1054     bool outValue = true;
1055     RState state;
1056     state = rm->GetBooleanById(NON_EXIST_ID, outValue);
1057     ASSERT_EQ(NOT_FOUND, state);
1058 }
1059 
1060 /*
1061  * @tc.name: ResourceManagerGetBooleanByNameTest001
1062  * @tc.desc: Test GetBooleanByName
1063  * @tc.type: FUNC
1064  */
1065 HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByNameTest001, TestSize.Level1)
1066 {
1067     AddResource("zh", nullptr, "CN");
1068 
1069     bool outValue = true;
1070     RState state;
1071     state = rm->GetBooleanByName("boolean_1", outValue);
1072     ASSERT_EQ(SUCCESS, state);
1073     EXPECT_TRUE(outValue);
1074 
1075     state = rm->GetBooleanByName("boolean_ref", outValue);
1076     ASSERT_EQ(SUCCESS, state);
1077     EXPECT_TRUE(outValue);
1078 }
1079 
1080 /*
1081  * @tc.name: ResourceManagerGetBooleanByNameTest002
1082  * @tc.desc: Test GetBooleanByName
1083  * @tc.type: FUNC
1084  */
1085 HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByNameTest002, TestSize.Level1)
1086 {
1087     AddResource("zh", nullptr, "CN");
1088 
1089     bool outValue = true;
1090     RState state;
1091     state = rm->GetBooleanByName(g_nonExistName, outValue);
1092     ASSERT_EQ(NOT_FOUND, state);
1093 }
1094 
1095 /*
1096  * @tc.name: ResourceManagerGetIntegerByIdTest001
1097  * @tc.desc: Test GetIntegerById
1098  * @tc.type: FUNC
1099  */
1100 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByIdTest001, TestSize.Level1)
1101 {
1102     AddResource("zh", nullptr, "CN");
1103 
1104     int outValue;
1105     RState state;
1106     int id = GetResId("integer_1", ResType::INTEGER);
1107     ASSERT_TRUE(id > 0);
1108     state = rm->GetIntegerById(id, outValue);
1109     ASSERT_EQ(SUCCESS, state);
1110     EXPECT_EQ(101, outValue);
1111 
1112     id = GetResId("integer_ref", ResType::INTEGER);
1113     ASSERT_TRUE(id > 0);
1114     state = rm->GetIntegerById(id, outValue);
1115     ASSERT_EQ(SUCCESS, state);
1116     EXPECT_EQ(101, outValue);
1117 }
1118 
1119 /*
1120  * @tc.name: ResourceManagerGetIntegerByIdTest002
1121  * @tc.desc: Test GetIntegerById
1122  * @tc.type: FUNC
1123  */
1124 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByIdTest002, TestSize.Level1)
1125 {
1126     AddResource("zh", nullptr, "CN");
1127 
1128     int outValue;
1129     RState state;
1130     state = rm->GetIntegerById(NON_EXIST_ID, outValue);
1131     ASSERT_EQ(NOT_FOUND, state);
1132 }
1133 
1134 /*
1135  * @tc.name: ResourceManagerGetIntegerByNameTest001
1136  * @tc.desc: Test GetIntegerByName
1137  * @tc.type: FUNC
1138  */
1139 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByNameTest001, TestSize.Level1)
1140 {
1141     AddResource("zh", nullptr, "CN");
1142 
1143     int outValue;
1144     RState state;
1145     state = rm->GetIntegerByName("integer_1", outValue);
1146     ASSERT_EQ(SUCCESS, state);
1147     EXPECT_EQ(101, outValue);
1148 
1149     state = rm->GetIntegerByName("integer_ref", outValue);
1150     ASSERT_EQ(SUCCESS, state);
1151     EXPECT_EQ(101, outValue);
1152 }
1153 
1154 /*
1155  * @tc.name: ResourceManagerGetIntegerByNameTest002
1156  * @tc.desc: Test GetIntegerByName
1157  * @tc.type: FUNC
1158  */
1159 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByNameTest002, TestSize.Level1)
1160 {
1161     AddResource("zh", nullptr, "CN");
1162 
1163     int outValue;
1164     RState state;
1165     state = rm->GetIntegerByName(g_nonExistName, outValue);
1166     ASSERT_EQ(NOT_FOUND, state);
1167 }
1168 
1169 /*
1170  * @tc.name: ResourceManagerGetFloatByIdTest001
1171  * @tc.desc: Test GetFloatById
1172  * @tc.type: FUNC
1173  */
1174 HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByIdTest001, TestSize.Level1)
1175 {
1176     AddResource("zh", nullptr, "CN");
1177 
1178     float outValue;
1179     RState state;
1180     int id = GetResId("width_appBar_backButton_touchTarget", ResType::FLOAT);
1181     ASSERT_TRUE(id > 0);
1182     state = rm->GetFloatById(id, outValue);
1183     ASSERT_EQ(SUCCESS, state);
1184     EXPECT_EQ(48, outValue); // 50vp
1185 
1186     id = GetResId("float_ref", ResType::FLOAT);
1187     ASSERT_TRUE(id > 0);
1188     state = rm->GetFloatById(id, outValue);
1189     ASSERT_EQ(SUCCESS, state);
1190     EXPECT_EQ(707, outValue); // 48vp
1191 }
1192 
1193 /*
1194  * @tc.name: ResourceManagerGetFloatByIdTest002
1195  * @tc.desc: Test GetFloatById
1196  * @tc.type: FUNC
1197  */
1198 HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByIdTest002, TestSize.Level1)
1199 {
1200     AddResource("zh", nullptr, "CN");
1201 
1202     float outValue;
1203     RState state;
1204     state = rm->GetFloatById(NON_EXIST_ID, outValue);
1205     ASSERT_EQ(NOT_FOUND, state);
1206 }
1207 
1208 /*
1209  * @tc.name: ResourceManagerGetFloatByNameTest001
1210  * @tc.desc: Test GetFloatByName
1211  * @tc.type: FUNC
1212  */
1213 HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByNameTest001, TestSize.Level1)
1214 {
1215     AddResource("zh", nullptr, "CN");
1216 
1217     float outValue;
1218     RState state;
1219     state = rm->GetFloatByName("width_appBar_backButton_touchTarget", outValue);
1220     ASSERT_EQ(SUCCESS, state);
1221     EXPECT_EQ(48, outValue); // 50vp
1222 
1223     state = rm->GetFloatByName("float_ref", outValue);
1224     ASSERT_EQ(SUCCESS, state);
1225     EXPECT_EQ(707, outValue); // 48vp
1226 }
1227 
1228 /*
1229  * @tc.name: ResourceManagerGetFloatByNameTest002
1230  * @tc.desc: Test GetFloatByName
1231  * @tc.type: FUNC
1232  */
1233 HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByNameTest002, TestSize.Level1)
1234 {
1235     AddResource("zh", nullptr, "CN");
1236 
1237     float outValue;
1238     RState state;
1239     state = rm->GetFloatByName(g_nonExistName, outValue);
1240     ASSERT_EQ(NOT_FOUND, state);
1241 }
1242 
1243 /*
1244  * @tc.name: ResourceManagerGetIntArrayByIdTest001
1245  * @tc.desc: Test GetIntArrayById
1246  * @tc.type: FUNC
1247  */
1248 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByIdTest001, TestSize.Level1)
1249 {
1250     AddResource("zh", nullptr, "CN");
1251 
1252     std::vector<int> outValue;
1253     RState state;
1254     int id = GetResId("intarray_1", ResType::INTARRAY);
1255     EXPECT_TRUE(id > 0);
1256     state = rm->GetIntArrayById(id, outValue);
1257     EXPECT_TRUE(state == SUCCESS);
1258     EXPECT_EQ(static_cast<uint32_t>(3), outValue.size());
1259     EXPECT_EQ(100, outValue[0]);
1260     EXPECT_EQ(200, outValue[1]);
1261     EXPECT_EQ(101, outValue[2]);
1262 }
1263 
1264 /*
1265  * @tc.name: ResourceManagerGetIntArrayByIdTest002
1266  * @tc.desc: Test GetIntArrayById
1267  * @tc.type: FUNC
1268  */
1269 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByIdTest002, TestSize.Level1)
1270 {
1271     AddResource("zh", nullptr, "CN");
1272 
1273     std::vector<int> outValue;
1274     RState state;
1275     state = rm->GetIntArrayById(NON_EXIST_ID, outValue);
1276     ASSERT_EQ(NOT_FOUND, state);
1277 }
1278 
1279 /*
1280  * @tc.name: ResourceManagerGetIntArrayByNameTest001
1281  * @tc.desc: Test GetIntArrayByName
1282  * @tc.type: FUNC
1283  */
1284 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByNameTest001, TestSize.Level1)
1285 {
1286     AddResource("zh", nullptr, "CN");
1287 
1288     std::vector<int> outValue;
1289     RState state;
1290     state = rm->GetIntArrayByName("intarray_1", outValue);
1291     EXPECT_TRUE(state == SUCCESS);
1292     EXPECT_EQ(static_cast<uint32_t>(3), outValue.size());
1293     EXPECT_EQ(100, outValue[0]);
1294     EXPECT_EQ(200, outValue[1]);
1295     EXPECT_EQ(101, outValue[2]);
1296 }
1297 
1298 /*
1299  * @tc.name: ResourceManagerGetIntArrayByNameTest002
1300  * @tc.desc: Test GetIntArrayByName
1301  * @tc.type: FUNC
1302  */
1303 HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByNameTest002, TestSize.Level1)
1304 {
1305     AddResource("zh", nullptr, "CN");
1306 
1307     std::vector<int> outValue;
1308     RState state;
1309     state = rm->GetIntArrayByName(g_nonExistName, outValue);
1310     ASSERT_EQ(NOT_FOUND, state);
1311 }
1312 
1313 /*
1314  * @tc.name: ResourceManagerGetColorByIdTest001
1315  * @tc.desc: Test GetColorById
1316  * @tc.type: FUNC
1317  */
1318 HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByIdTest001, TestSize.Level1)
1319 {
1320     AddResource("zh", nullptr, "CN");
1321 
1322     uint32_t outValue;
1323     RState state;
1324     int id = GetResId("divider_color", ResType::COLOR);
1325     EXPECT_TRUE(id > 0);
1326     state = rm->GetColorById(id, outValue);
1327     EXPECT_TRUE(state == SUCCESS);
1328     EXPECT_EQ(static_cast<uint32_t>(268435456), outValue); // #10000000
1329 
1330     id = GetResId("color_aboutPage_title_primary", ResType::COLOR);
1331     EXPECT_TRUE(id > 0);
1332     state = rm->GetColorById(id, outValue);
1333     EXPECT_TRUE(state == SUCCESS);
1334     EXPECT_EQ(4279834905, outValue); // #191919
1335 }
1336 
1337 /*
1338  * @tc.name: ResourceManagerGetColorByIdTest002
1339  * @tc.desc: Test GetColorById
1340  * @tc.type: FUNC
1341  */
1342 HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByIdTest002, TestSize.Level1)
1343 {
1344     AddResource("zh", nullptr, "CN");
1345 
1346     uint32_t outValue;
1347     RState state;
1348     state = rm->GetColorById(NON_EXIST_ID, outValue);
1349     ASSERT_EQ(NOT_FOUND, state);
1350 }
1351 
1352 /*
1353  * @tc.name: ResourceManagerGetColorByNameTest001
1354  * @tc.desc: Test GetColorByName
1355  * @tc.type: FUNC
1356  */
1357 HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByNameTest001, TestSize.Level1)
1358 {
1359     AddResource("zh", nullptr, "CN");
1360 
1361     uint32_t outValue;
1362     RState state;
1363     state = rm->GetColorByName("divider_color", outValue);
1364     EXPECT_TRUE(state == SUCCESS);
1365     EXPECT_EQ(static_cast<uint32_t>(268435456), outValue); // #10000000
1366 
1367     state = rm->GetColorByName("color_aboutPage_title_primary", outValue);
1368     EXPECT_TRUE(state == SUCCESS);
1369     EXPECT_EQ(4279834905, outValue); // #191919
1370 }
1371 
1372 /*
1373  * @tc.name: ResourceManagerGetColorByNameTest002
1374  * @tc.desc: Test GetColorByName
1375  * @tc.type: FUNC
1376  */
1377 HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByNameTest002, TestSize.Level1)
1378 {
1379     AddResource("zh", nullptr, "CN");
1380 
1381     uint32_t outValue;
1382     RState state;
1383     state = rm->GetColorByName(g_nonExistName, outValue);
1384     ASSERT_EQ(NOT_FOUND, state);
1385 }
1386 
1387 /*
1388  * @tc.name: ResourceManagerGetProfileByIdTest001
1389  * @tc.desc: Test GetProfileById
1390  * @tc.type: FUNC
1391  */
1392 HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByIdTest001, TestSize.Level1)
1393 {
1394     AddResource("zh", nullptr, "CN");
1395 
1396     HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr);
1397     tmp->Init();
1398     std::string res = tmp->GetResourcePath();
1399     res.append("entry/resources/base/profile/test_common.h");
1400 
1401     std::string outValue;
1402     RState state;
1403     int id = GetResId("test_common", ResType::PROF);
1404     EXPECT_TRUE(id > 0);
1405     state = rm->GetProfileById(id, outValue);
1406     EXPECT_TRUE(state == SUCCESS);
1407     EXPECT_EQ(res, outValue);
1408     delete tmp;
1409 }
1410 
1411 /*
1412  * @tc.name: ResourceManagerGetProfileByIdTest002
1413  * @tc.desc: Test GetProfileById
1414  * @tc.type: FUNC
1415  */
1416 HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByIdTest002, TestSize.Level1)
1417 {
1418     AddResource("zh", nullptr, "CN");
1419 
1420     std::string outValue;
1421     RState state;
1422     state = rm->GetProfileById(NON_EXIST_ID, outValue);
1423     ASSERT_EQ(NOT_FOUND, state);
1424 }
1425 
1426 /*
1427  * @tc.name: ResourceManagerGetProfileByNameTest001
1428  * @tc.desc: Test GetProfileByName
1429  * @tc.type: FUNC
1430  */
1431 HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByNameTest001, TestSize.Level1)
1432 {
1433     AddResource("zh", nullptr, "CN");
1434 
1435     HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr);
1436     tmp->Init();
1437     std::string res = tmp->GetResourcePath();
1438     res.append("entry/resources/base/profile/test_common.h");
1439 
1440     std::string outValue;
1441     RState state;
1442     state = rm->GetProfileByName("test_common", outValue);
1443     EXPECT_TRUE(state == SUCCESS);
1444     EXPECT_EQ(res, outValue);
1445     delete tmp;
1446 }
1447 
1448 /*
1449  * @tc.name: ResourceManagerGetProfileByNameTest002
1450  * @tc.desc: Test GetProfileByName
1451  * @tc.type: FUNC
1452  */
1453 HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByNameTest002, TestSize.Level1)
1454 {
1455     AddResource("zh", nullptr, "CN");
1456 
1457     std::string outValue;
1458     RState state;
1459     state = rm->GetProfileByName(g_nonExistName, outValue);
1460     ASSERT_EQ(NOT_FOUND, state);
1461 }
1462 
1463 /*
1464  * @tc.name: ResourceManagerGetMediaByIdTest001
1465  * @tc.desc: Test GetMediaById
1466  * @tc.type: FUNC
1467  */
1468 HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByIdTest001, TestSize.Level1)
1469 {
1470     AddResource("zh", nullptr, "CN");
1471 
1472     HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr);
1473     tmp->Init();
1474     std::string res = tmp->GetResourcePath();
1475     res.append("entry/resources/base/media/icon.png");
1476 
1477     std::string outValue;
1478     RState state;
1479     int id = GetResId("icon", ResType::MEDIA);
1480     EXPECT_TRUE(id > 0);
1481     state = rm->GetMediaById(id, outValue);
1482     EXPECT_TRUE(state == SUCCESS);
1483     EXPECT_EQ(res, outValue);
1484     delete tmp;
1485 }
1486 
1487 /*
1488  * @tc.name: ResourceManagerGetMediaByIdTest002
1489  * @tc.desc: Test GetMediaById
1490  * @tc.type: FUNC
1491  */
1492 HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByIdTest002, TestSize.Level1)
1493 {
1494     AddResource("zh", nullptr, "CN");
1495 
1496     std::string outValue;
1497     RState state;
1498     state = rm->GetMediaById(NON_EXIST_ID, outValue);
1499     ASSERT_EQ(NOT_FOUND, state);
1500 }
1501 
1502 /*
1503  * @tc.name: ResourceManagerGetMediaByNameTest001
1504  * @tc.desc: Test GetMediaByName
1505  * @tc.type: FUNC
1506  */
1507 HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByNameTest001, TestSize.Level1)
1508 {
1509     AddResource("zh", nullptr, "CN");
1510 
1511     HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr);
1512     tmp->Init();
1513     std::string res = tmp->GetResourcePath();
1514     res.append("entry/resources/base/media/icon.png");
1515 
1516     std::string outValue;
1517     RState state;
1518     state = rm->GetMediaByName("icon", outValue);
1519     EXPECT_TRUE(state == SUCCESS);
1520     EXPECT_EQ(res, outValue);
1521     delete tmp;
1522 }
1523 
1524 /*
1525  * @tc.name: ResourceManagerGetMediaByNameTest002
1526  * @tc.desc: Test GetMediaByName
1527  * @tc.type: FUNC
1528  */
1529 HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByNameTest002, TestSize.Level1)
1530 {
1531     AddResource("zh", nullptr, "CN");
1532 
1533     std::string outValue;
1534     RState state;
1535     state = rm->GetMediaByName(g_nonExistName, outValue);
1536     ASSERT_EQ(NOT_FOUND, state);
1537 }
1538 
1539 /*
1540  * @tc.name: ResourceManagerResolveReferenceTest001
1541  * @tc.desc: Test ResolveReference function, file case.
1542  * @tc.type: FUNC
1543  */
1544 HWTEST_F(ResourceManagerTest, ResourceManagerResolveReferenceTest001, TestSize.Level1)
1545 {
1546     ResConfig *rc = CreateResConfig();
1547     if (rc == nullptr) {
1548         EXPECT_TRUE(false);
1549         return;
1550     }
1551     rc->SetLocaleInfo("en", nullptr, "US");
1552     rm->UpdateResConfig(*rc);
1553 
1554     rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1555 
1556     int id = GetResId("integer_1", ResType::INTEGER);
1557     std::string value(FormatString("$integer:%d", id));
1558     std::string outValue;
1559     RState ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1560     EXPECT_EQ(SUCCESS, ret);
1561     EXPECT_EQ(std::string("101"), outValue);
1562 
1563     std::string copyright("XXXXXX All rights reserved. ©2011-2019");
1564     id = GetResId("copyright_text", ResType::STRING);
1565     value.assign(FormatString("$string:%d", id));
1566     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1567     EXPECT_EQ(SUCCESS, ret);
1568     EXPECT_EQ(copyright, outValue);
1569 
1570     id = GetResId("string_ref", ResType::STRING);
1571     value.assign(FormatString("$string:%d", id));
1572     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1573     EXPECT_EQ(SUCCESS, ret);
1574     EXPECT_EQ(copyright, outValue);
1575 
1576     id = GetResId("boolean_1", ResType::BOOLEAN);
1577     value.assign(FormatString("$boolean:%d", id));
1578     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1579     EXPECT_EQ(SUCCESS, ret);
1580     EXPECT_EQ(std::string("true"), outValue);
1581 
1582     id = GetResId("grey_background", ResType::COLOR);
1583     value.assign(FormatString("$color:%d", id));
1584     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1585     EXPECT_EQ(SUCCESS, ret);
1586     EXPECT_EQ(std::string("#F5F5F5"), outValue);
1587 
1588     id = GetResId("aboutPage_minHeight", ResType::FLOAT);
1589     value.assign(FormatString("$float:%d", id));
1590     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1591     EXPECT_EQ(SUCCESS, ret);
1592     EXPECT_EQ(std::string("707vp"), outValue);
1593 
1594     id = GetResId("base", ResType::PATTERN);
1595     value.assign(FormatString("$pattern:%d", id));
1596     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1597     EXPECT_EQ(ERROR, ret);
1598 
1599     // reload
1600     rc->SetLocaleInfo("zh", nullptr, "CN");
1601     rm->UpdateResConfig(*rc);
1602     delete rc;
1603 
1604     id = GetResId("copyright_text", ResType::STRING);
1605     value.assign(FormatString("$string:%d", id));
1606     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1607     ASSERT_EQ(SUCCESS, ret);
1608     ASSERT_EQ(std::string("版权所有 ©2011-2019 XXXX有限公司保留一切权利"), outValue.c_str());
1609 
1610     id = GetResId("string_ref", ResType::STRING);
1611     value.assign(FormatString("$string:%d", id));
1612     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1613     ASSERT_EQ(SUCCESS, ret);
1614     ASSERT_EQ(std::string("$aaaaa"), outValue.c_str());
1615 
1616     // error case
1617     // wrong id
1618     value.assign(FormatString("$boolean:%d", NON_EXIST_ID));
1619     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1620     ASSERT_EQ(ERROR, ret);
1621     // wrong type
1622     id = GetResId("copyright_text", ResType::STRING);
1623     value.assign(FormatString("$boolean:%d", id));
1624     ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue);
1625     ASSERT_EQ(ERROR, ret);
1626 }
1627 
1628 /*
1629  * @tc.name: ResourceManagerResolveParentReferenceTest001
1630  * @tc.desc: Test ResolveParentReference function, file case.
1631  * @tc.type: FUNC
1632  */
1633 HWTEST_F(ResourceManagerTest, ResourceManagerResolveParentReferenceTest001, TestSize.Level1)
1634 {
1635     rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1636     int id;
1637     std::map<std::string, std::string> outValue;
1638     const IdItem *idItem;
1639     RState ret;
1640 
1641     id = GetResId("base", ResType::PATTERN);
1642     ASSERT_TRUE(id > 0);
1643     idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id);
1644     ASSERT_TRUE(idItem != nullptr);
1645     ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue);
1646     ASSERT_EQ(SUCCESS, ret);
1647     PrintMapString(outValue);
1648 
1649     HILOG_DEBUG("=====");
1650     id = GetResId("child", ResType::PATTERN);
1651     ASSERT_TRUE(id > 0);
1652     idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id);
1653     ASSERT_TRUE(idItem != nullptr);
1654     ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue);
1655     ASSERT_EQ(SUCCESS, ret);
1656     PrintMapString(outValue);
1657 
1658     HILOG_DEBUG("=====");
1659     id = GetResId("ccchild", ResType::PATTERN);
1660     ASSERT_TRUE(id > 0);
1661     idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id);
1662     ASSERT_TRUE(idItem != nullptr);
1663     ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue);
1664     ASSERT_EQ(SUCCESS, ret);
1665     PrintMapString(outValue);
1666 
1667     // error case
1668     ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(nullptr, outValue);
1669     ASSERT_EQ(ERROR, ret);
1670     // wrong resType
1671     IdItem *item = new IdItem;
1672     for (int i = 0; i < ResType::MAX_RES_TYPE; ++i) {
1673         if (i == ResType::THEME || i == ResType::PATTERN) {
1674             continue;
1675         }
1676         item->resType_ = (ResType) i;
1677         ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(item, outValue);
1678         EXPECT_EQ(ERROR, ret);
1679     }
1680     delete item;
1681 }
1682 
1683 /*
1684  * test res with same name in different resType
1685  * @tc.name: ResourceManagerSameNameTest001
1686  * @tc.desc: Test GetStringByName & GetBooleanByName & GetIntegerByName function, file case.
1687  * @tc.type: FUNC
1688  */
1689 HWTEST_F(ResourceManagerTest, ResourceManagerSameNameTest001, TestSize.Level1)
1690 {
1691     rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1692     std::string outValue;
1693     std::string name;
1694     RState state;
1695 
1696     state = rm->GetStringByName("same_name", outValue);
1697     EXPECT_TRUE(state == SUCCESS);
1698     EXPECT_EQ(std::string("StringSameName"), outValue);
1699 
1700     bool outValueB = true;
1701     state = rm->GetBooleanByName("same_name", outValueB);
1702     EXPECT_TRUE(state == SUCCESS);
1703     EXPECT_EQ(false, outValueB);
1704 
1705     int outValueI;
1706     state = rm->GetIntegerByName("same_name", outValueI);
1707     EXPECT_TRUE(state == SUCCESS);
1708     EXPECT_EQ(999, outValueI);
1709 }
1710 }
1711