• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_common.h"
17 
18 using namespace OHOS::Global::Resource;
19 using namespace testing::ext;
20 
ResourceManagerTestCommon(ResourceManager * rm)21 ResourceManagerTestCommon::ResourceManagerTestCommon(ResourceManager *rm) : rm(rm)
22 {}
23 
ResourceManagerTestCommon(std::shared_ptr<ResourceManager> rm)24 ResourceManagerTestCommon::ResourceManagerTestCommon(std::shared_ptr<ResourceManager> rm)
25 {
26     this->rm = rm.get();
27 }
28 
~ResourceManagerTestCommon()29 ResourceManagerTestCommon::~ResourceManagerTestCommon()
30 {}
31 
SetUpTestCase(void)32 void ResourceManagerTestCommon::SetUpTestCase(void)
33 {
34     // step 1: input testsuit setup step
35     g_logLevel = LOG_DEBUG;
36 }
37 
TearDownTestCase(void)38 void ResourceManagerTestCommon::TearDownTestCase(void)
39 {
40     // step 2: input testsuit teardown step
41 }
42 
SetUp(void)43 void ResourceManagerTestCommon::SetUp(void)
44 {
45     this->rm = CreateResourceManager();
46 }
47 
TearDown(void)48 void ResourceManagerTestCommon::TearDown(void)
49 {
50     delete this->rm;
51 }
52 
GetResId(const std::string & name,ResType resType)53 int ResourceManagerTestCommon::GetResId(const std::string &name, ResType resType)
54 {
55     auto idValues = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType);
56     if (idValues.size() == 0) {
57         return -1;
58     }
59 
60     PrintIdValues(idValues[0]);
61     for (auto &idValue : idValues) {
62         if (idValue->GetLimitPathsConst().size() > 0 && !idValue->GetLimitPathsConst()[0]->IsSystemResource()) {
63             return idValue->GetLimitPathsConst()[0]->GetIdItem()->id_;
64         }
65     }
66     return OBJ_NOT_FOUND;
67 }
68 
TestStringByName(const char * name,const char * cmp)69 void ResourceManagerTestCommon::TestStringByName(const char *name, const char *cmp)
70 {
71     std::string outValue;
72     RState rState = rm->GetStringByName(name, outValue);
73     ASSERT_EQ(SUCCESS, rState);
74     RESMGR_HILOGD(RESMGR_TAG, "%s : %s", name, outValue.c_str());
75     ASSERT_EQ(std::string(cmp), outValue);
76 }
77 
TestStringById(const char * name,const char * cmp)78 void ResourceManagerTestCommon::TestStringById(const char *name, const char *cmp)
79 {
80     std::string outValue;
81     int id = GetResId(name, ResType::STRING);
82     ASSERT_TRUE(id > 0);
83     RState rState = rm->GetStringById(id, outValue);
84     ASSERT_EQ(SUCCESS, rState);
85     ASSERT_EQ(std::string(cmp), outValue);
86 }
87 
AddResource(const char * language,const char * script,const char * region)88 void ResourceManagerTestCommon::AddResource(const char *language, const char *script, const char *region)
89 {
90     if (language != nullptr || region != nullptr) {
91         auto rc = CreateResConfig();
92         if (rc == nullptr) {
93             EXPECT_TRUE(false);
94             return;
95         }
96         rc->SetLocaleInfo(language, script, region);
97         rm->UpdateResConfig(*rc);
98         delete rc;
99     }
100     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
101     ASSERT_TRUE(ret);
102 }
103 
AddHapResource(const char * language,const char * script,const char * region)104 void ResourceManagerTestCommon::AddHapResource(const char *language, const char *script, const char *region)
105 {
106     if (language != nullptr || region != nullptr) {
107         auto rc = CreateResConfig();
108         if (rc == nullptr) {
109             EXPECT_TRUE(false);
110             return;
111         }
112         rc->SetLocaleInfo(language, script, region);
113         rm->UpdateResConfig(*rc);
114         delete rc;
115     }
116     bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
117     ASSERT_TRUE(ret);
118 }
119 
AddColorModeResource(DeviceType deviceType,ColorMode colorMode,float screenDensity)120 void ResourceManagerTestCommon::AddColorModeResource(DeviceType deviceType, ColorMode colorMode,
121     float screenDensity)
122 {
123     auto rc = CreateResConfig();
124     if (rc == nullptr) {
125         EXPECT_TRUE(false);
126         return;
127     }
128     rc->SetLocaleInfo("zh", nullptr, nullptr);
129     rc->SetDeviceType(deviceType);
130     rc->SetColorMode(colorMode);
131     rc->SetScreenDensity(screenDensity);
132     rm->UpdateResConfig(*rc);
133     delete rc;
134     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
135     ASSERT_TRUE(ret);
136 }
137 
TestPluralStringById(int quantity,const char * cmp,bool format)138 void ResourceManagerTestCommon::TestPluralStringById(int quantity, const char *cmp, bool format)
139 {
140     RState ret;
141     std::string outValue;
142     int id = GetResId("eat_apple", ResType::PLURALS);
143     ASSERT_TRUE(id > 0);
144     if (format) {
145         ret = rm->GetPluralStringByIdFormat(outValue, id, quantity, quantity);
146     } else {
147         ret = rm->GetPluralStringById(id, quantity, outValue);
148     }
149 
150     ASSERT_EQ(SUCCESS, ret);
151     ASSERT_EQ(std::string(cmp), outValue);
152 }
153 
TestPluralStringByName(int quantity,const char * cmp,bool format)154 void ResourceManagerTestCommon::TestPluralStringByName(int quantity, const char *cmp, bool format)
155 {
156     RState ret;
157     std::string outValue;
158     const char *name = "eat_apple";
159     if (format) {
160         ret = rm->GetPluralStringByNameFormat(outValue, name, quantity, quantity);
161     } else {
162         ret = rm->GetPluralStringByName(name, quantity, outValue);
163     }
164 
165     ASSERT_EQ(SUCCESS, ret);
166     ASSERT_EQ(std::string(cmp), outValue);
167 }
168 
TestGetRawFilePathByName(const std::string & name,const std::string & cmp)169 void ResourceManagerTestCommon::TestGetRawFilePathByName(const std::string &name, const std::string &cmp)
170 {
171     std::string outValue;
172     rm->GetRawFilePathByName(name, outValue);
173     RESMGR_HILOGD(RESMGR_TAG, "%s : %s", name.c_str(), outValue.c_str());
174     ASSERT_EQ(cmp, outValue);
175 }
176 
TestGetProfileById(HapResource * tmp)177 void ResourceManagerTestCommon::TestGetProfileById(HapResource *tmp)
178 {
179     tmp->Init(this->defaultResConfig);
180     std::string res = tmp->GetResourcePath();
181     res.append("entry/resources/base/profile/test_profile.json");
182 
183     std::string outValue;
184     RState state;
185     int id = GetResId("test_profile", ResType::PROF);
186     EXPECT_TRUE(id > 0);
187     state = rm->GetProfileById(id, outValue);
188     EXPECT_TRUE(state == SUCCESS);
189     EXPECT_EQ(res, outValue);
190 }
191 
TestGetProfileByName(HapResource * tmp)192 void ResourceManagerTestCommon::TestGetProfileByName(HapResource *tmp)
193 {
194     tmp->Init(this->defaultResConfig);
195     std::string res = tmp->GetResourcePath();
196     res.append("entry/resources/base/profile/test_profile.json");
197 
198     std::string outValue;
199     RState state = rm->GetProfileByName("test_profile", outValue);
200     EXPECT_TRUE(state == SUCCESS);
201     EXPECT_EQ(res, outValue);
202 }
203 
TestGetMediaById(HapResource * tmp)204 void ResourceManagerTestCommon::TestGetMediaById(HapResource *tmp)
205 {
206     tmp->Init(this->defaultResConfig);
207     std::string res = tmp->GetResourcePath();
208     res.append("entry/resources/base/media/icon1.png");
209 
210     std::string outValue;
211     int id = GetResId("icon1", ResType::MEDIA);
212     EXPECT_TRUE(id > 0);
213     RState state = rm->GetMediaById(id, outValue);
214     EXPECT_TRUE(state == SUCCESS);
215     EXPECT_EQ(res, outValue);
216 }
217 
TestGetMediaWithDensityById(HapResource * tmp)218 void ResourceManagerTestCommon::TestGetMediaWithDensityById(HapResource *tmp)
219 {
220     tmp->Init(this->defaultResConfig);
221     std::string res = tmp->GetResourcePath();
222     res.append("entry/resources/sdpi/media/icon.png");
223 
224     auto rc = CreateResConfig();
225     if (rc == nullptr) {
226         EXPECT_TRUE(false);
227         return;
228     }
229     rc->SetDeviceType(DEVICE_TV);
230     rc->SetColorMode(COLOR_MODE_NOT_SET);
231     rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
232     rm->UpdateResConfig(*rc);
233     delete rc;
234 
235     int density = 120;
236     std::string outValue;
237     int id = GetResId("icon", ResType::MEDIA);
238     EXPECT_TRUE(id > 0);
239     RState state = rm->GetMediaById(id, outValue, density);
240     EXPECT_TRUE(state == SUCCESS);
241     EXPECT_EQ(res, outValue);
242 }
243 
TestGetMediaByName(HapResource * tmp)244 void ResourceManagerTestCommon::TestGetMediaByName(HapResource *tmp)
245 {
246     tmp->Init(this->defaultResConfig);
247     std::string res = tmp->GetResourcePath();
248     res.append("entry/resources/base/media/icon1.png");
249 
250     std::string outValue;
251     RState state = rm->GetMediaByName("icon1", outValue);
252     EXPECT_TRUE(state == SUCCESS);
253     EXPECT_EQ(res, outValue);
254 }
255 
TestGetMediaWithDensityByName(HapResource * tmp)256 void ResourceManagerTestCommon::TestGetMediaWithDensityByName(HapResource *tmp)
257 {
258     tmp->Init(this->defaultResConfig);
259     std::string res = tmp->GetResourcePath();
260     res.append("entry/resources/sdpi/media/icon.png");
261 
262     auto rc = CreateResConfig();
263     if (rc == nullptr) {
264         EXPECT_TRUE(false);
265         return;
266     }
267     rc->SetDeviceType(DEVICE_PHONE);
268     rc->SetColorMode(COLOR_MODE_NOT_SET);
269     rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
270     rm->UpdateResConfig(*rc);
271     delete rc;
272 
273     uint32_t density = 120;
274     std::string outValue;
275     RState state = rm->GetMediaByName("icon", outValue, density);
276     EXPECT_TRUE(state == SUCCESS);
277     EXPECT_EQ(res, outValue);
278 }
279 
TestGetDrawableInfoById(HapResource * tmp)280 void ResourceManagerTestCommon::TestGetDrawableInfoById(HapResource *tmp)
281 {
282     tmp->Init(this->defaultResConfig);
283     int id = GetResId("icon1", ResType::MEDIA);
284     EXPECT_TRUE(id > 0);
285     std::string type;
286     size_t len;
287     std::unique_ptr<uint8_t[]> jsonBuf;
288     RState state = rm->GetDrawableInfoById(id, type, len, jsonBuf);
289     EXPECT_TRUE(state == SUCCESS);
290     EXPECT_TRUE(jsonBuf != nullptr);
291 }
292 
TestGetDrawableInfoWithDensityById(HapResource * tmp)293 void ResourceManagerTestCommon::TestGetDrawableInfoWithDensityById(HapResource *tmp)
294 {
295     tmp->Init(this->defaultResConfig);
296     auto rc = CreateResConfig();
297     if (rc == nullptr) {
298         EXPECT_TRUE(false);
299         return;
300     }
301     rc->SetDeviceType(DEVICE_TV);
302     rc->SetColorMode(COLOR_MODE_NOT_SET);
303     rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
304     rm->UpdateResConfig(*rc);
305     delete rc;
306 
307     int density = 120;
308     int id = GetResId("icon", ResType::MEDIA);
309     EXPECT_TRUE(id > 0);
310     std::string type;
311     size_t len;
312     std::unique_ptr<uint8_t[]> jsonBuf;
313     RState state = rm->GetDrawableInfoById(id, type, len, jsonBuf, density);
314     EXPECT_TRUE(state == SUCCESS);
315     EXPECT_TRUE(jsonBuf != nullptr);
316 
317     // invalid density
318     int invalidDensity = 1000;
319     state = rm->GetDrawableInfoById(id, type, len, jsonBuf, invalidDensity);
320     EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
321 }
322 
TestGetDrawableInfoByName(HapResource * tmp)323 void ResourceManagerTestCommon::TestGetDrawableInfoByName(HapResource *tmp)
324 {
325     tmp->Init(this->defaultResConfig);
326     std::string type;
327     size_t len;
328     std::unique_ptr<uint8_t[]> jsonBuf;
329     RState state = rm->GetDrawableInfoByName("icon1", type, len, jsonBuf);
330     EXPECT_TRUE(state == SUCCESS);
331     EXPECT_TRUE(jsonBuf != nullptr);
332 }
333 
TestGetDrawableInfoWithDensityByName(HapResource * tmp)334 void ResourceManagerTestCommon::TestGetDrawableInfoWithDensityByName(HapResource *tmp)
335 {
336     tmp->Init(this->defaultResConfig);
337     auto rc = CreateResConfig();
338     if (rc == nullptr) {
339         EXPECT_TRUE(false);
340         return;
341     }
342     rc->SetDeviceType(DEVICE_PHONE);
343     rc->SetColorMode(COLOR_MODE_NOT_SET);
344     rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
345     rm->UpdateResConfig(*rc);
346     delete rc;
347 
348     uint32_t density = 120;
349     std::string type;
350     size_t len;
351     std::unique_ptr<uint8_t[]> jsonBuf;
352     RState state = rm->GetDrawableInfoByName("icon1", type, len, jsonBuf, density);
353     EXPECT_TRUE(state == SUCCESS);
354     EXPECT_TRUE(jsonBuf != nullptr);
355 
356     // invalid density
357     int invalidDensity = 1000;
358     state = rm->GetDrawableInfoByName("icon1", type, len, jsonBuf, invalidDensity);
359     EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
360 }
361 
TestGetStringFormatById(const char * name,const char * cmp)362 void ResourceManagerTestCommon::TestGetStringFormatById(const char *name, const char *cmp)
363 {
364     int id = GetResId(name, ResType::STRING);
365     ASSERT_TRUE(id > 0);
366     std::string outValue;
367     RState state = rm->GetStringFormatById(outValue, id, 101); // 101 means the format number
368     ASSERT_EQ(SUCCESS, state);
369     ASSERT_EQ(cmp, outValue);
370 }
371 
TestGetStringFormatByName(const char * name,const char * cmp)372 void ResourceManagerTestCommon::TestGetStringFormatByName(const char *name, const char *cmp)
373 {
374     std::string outValue;
375     RState state = rm->GetStringFormatByName(outValue, name, 101); // 101 means the format number
376     ASSERT_EQ(SUCCESS, state);
377     ASSERT_EQ(cmp, outValue);
378 }
379 
TestGetStringArrayById(const char * name)380 void ResourceManagerTestCommon::TestGetStringArrayById(const char *name)
381 {
382     std::vector<std::string> outValue;
383     int id = GetResId(name, ResType::STRINGARRAY);
384     RState state = rm->GetStringArrayById(id, outValue);
385     ASSERT_EQ(SUCCESS, state);
386     ASSERT_EQ(static_cast<size_t>(4), outValue.size()); // 4 means the size of string array resource
387     PrintVectorString(outValue);
388 }
389 
TestGetStringFormatById(const char * name,std::vector<std::tuple<ResourceManager::NapiValueType,std::string>> & jsParams,const char * cmp)390 void ResourceManagerTestCommon::TestGetStringFormatById(const char *name,
391     std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp)
392 {
393     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
394     ASSERT_TRUE(ret);
395     uint32_t id = GetResId(name, ResType::STRING);
396     ASSERT_TRUE(id > 0);
397     std::string outValue;
398     RState state = rm->GetStringFormatById(id, outValue, jsParams);
399     ASSERT_EQ(SUCCESS, state);
400     ASSERT_EQ(cmp, outValue);
401 }
402 
TestGetStringFormatByIdWithVaArgs(const char * name,const char * cmp,...)403 void ResourceManagerTestCommon::TestGetStringFormatByIdWithVaArgs(const char *name, const char *cmp, ...)
404 {
405     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
406     ASSERT_TRUE(ret);
407     uint32_t id = GetResId(name, ResType::STRING);
408     ASSERT_TRUE(id > 0);
409     std::string outValue;
410     va_list args;
411     va_start(args, cmp);
412     RState state = rm->GetStringFormatById(outValue, id, args);
413     va_end(args);
414     ASSERT_EQ(SUCCESS, state);
415     ASSERT_EQ(cmp, outValue);
416 }
417 
TestGetStringFormatByName(const char * name,std::vector<std::tuple<ResourceManager::NapiValueType,std::string>> & jsParams,const char * cmp)418 void ResourceManagerTestCommon::TestGetStringFormatByName(const char *name,
419     std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp)
420 {
421     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
422     ASSERT_TRUE(ret);
423     std::string outValue;
424     RState state = rm->GetStringFormatByName(name, outValue, jsParams);
425     ASSERT_EQ(SUCCESS, state);
426     ASSERT_EQ(cmp, outValue);
427 }
428 
TestGetStringFormatByNameWithVaArgs(const char * name,const char * cmp,...)429 void ResourceManagerTestCommon::TestGetStringFormatByNameWithVaArgs(const char *name, const char *cmp, ...)
430 {
431     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
432     ASSERT_TRUE(ret);
433     std::string outValue;
434     va_list args;
435     va_start(args, cmp);
436     RState state = rm->GetStringFormatByName(outValue, name, args);
437     va_end(args);
438     ASSERT_EQ(SUCCESS, state);
439     ASSERT_EQ(cmp, outValue);
440 }
441 
TestGetStringArrayByName(const char * name)442 void ResourceManagerTestCommon::TestGetStringArrayByName(const char *name)
443 {
444     std::vector<std::string> outValue;
445     RState state = rm->GetStringArrayByName(name, outValue);
446     ASSERT_EQ(SUCCESS, state);
447     ASSERT_EQ(static_cast<size_t>(4), outValue.size()); // 4 means the size of string array resource
448     PrintVectorString(outValue);
449 }
450 
TestGetPatternById(const char * name)451 void ResourceManagerTestCommon::TestGetPatternById(const char *name)
452 {
453     std::map<std::string, std::string> outValue;
454     int id = GetResId(name, ResType::PATTERN);
455     RState state = rm->GetPatternById(id, outValue);
456     ASSERT_EQ(SUCCESS, state);
457     ASSERT_EQ(static_cast<size_t>(3), outValue.size()); // 3 means the size of pattern resource
458     PrintMapString(outValue);
459 }
460 
TestGetPatternByName(const char * name)461 void ResourceManagerTestCommon::TestGetPatternByName(const char *name)
462 {
463     std::map<std::string, std::string> outValue;
464     RState state = rm->GetPatternByName(name, outValue);
465     ASSERT_EQ(SUCCESS, state);
466     ASSERT_EQ(static_cast<size_t>(3), outValue.size()); // 3 means the size of pattern resource
467     PrintMapString(outValue);
468 }
469 
TestGetThemeById(const char * name)470 void ResourceManagerTestCommon::TestGetThemeById(const char *name)
471 {
472     std::map<std::string, std::string> outValue;
473     int id = GetResId(name, ResType::THEME);
474     ASSERT_TRUE(id > 0);
475     RState state = rm->GetThemeById(id, outValue);
476     ASSERT_EQ(SUCCESS, state);
477 }
478 
TestGetThemeByName(const char * appTheme,const char * testTheme)479 void ResourceManagerTestCommon::TestGetThemeByName(const char *appTheme, const char *testTheme)
480 {
481     std::map<std::string, std::string> outValue;
482     RState state = rm->GetThemeByName(appTheme, outValue);
483     ASSERT_EQ(SUCCESS, state);
484     PrintMapString(outValue);
485 
486     state = rm->GetThemeByName(testTheme, outValue);
487     ASSERT_EQ(SUCCESS, state);
488 }
489 
TestGetBooleanById(const char * boolean1,const char * booleanRef)490 void ResourceManagerTestCommon::TestGetBooleanById(const char* boolean1, const char* booleanRef)
491 {
492     bool outValue = true;
493     int id = GetResId(boolean1, ResType::BOOLEAN);
494     ASSERT_TRUE(id > 0);
495     RState state = rm->GetBooleanById(id, outValue);
496     ASSERT_EQ(SUCCESS, state);
497     EXPECT_TRUE(outValue);
498 
499     id = GetResId(booleanRef, ResType::BOOLEAN);
500     ASSERT_TRUE(id > 0);
501     state = rm->GetBooleanById(id, outValue);
502     ASSERT_EQ(SUCCESS, state);
503     EXPECT_TRUE(outValue);
504 }
505 
TestGetBooleanByName(const char * boolean1,const char * booleanRef)506 void ResourceManagerTestCommon::TestGetBooleanByName(const char* boolean1, const char* booleanRef)
507 {
508     bool outValue = true;
509     RState state = rm->GetBooleanByName(boolean1, outValue);
510     ASSERT_EQ(SUCCESS, state);
511     EXPECT_TRUE(outValue);
512 
513     state = rm->GetBooleanByName(booleanRef, outValue);
514     ASSERT_EQ(SUCCESS, state);
515     EXPECT_TRUE(outValue);
516 }
517 
TestGetIntegerById(const char * integer1,const char * integerRef)518 void ResourceManagerTestCommon::TestGetIntegerById(const char* integer1, const char* integerRef)
519 {
520     int outValue;
521     int id = GetResId(integer1, ResType::INTEGER);
522     ASSERT_TRUE(id > 0);
523     RState state = rm->GetIntegerById(id, outValue);
524     ASSERT_EQ(SUCCESS, state);
525     EXPECT_EQ(101, outValue); // 101 means the result of int resource
526 
527     id = GetResId(integerRef, ResType::INTEGER);
528     ASSERT_TRUE(id > 0);
529     state = rm->GetIntegerById(id, outValue);
530     ASSERT_EQ(SUCCESS, state);
531     EXPECT_EQ(101, outValue); // 101 means the result of int resource
532 }
533 
TestGetIntegerByName(const char * integer1,const char * integerRef)534 void ResourceManagerTestCommon::TestGetIntegerByName(const char* integer1, const char* integerRef)
535 {
536     int outValue;
537     RState state = rm->GetIntegerByName(integer1, outValue);
538     ASSERT_EQ(SUCCESS, state);
539     EXPECT_EQ(101, outValue); // 101 means the result of int resource
540 
541     state = rm->GetIntegerByName(integerRef, outValue);
542     ASSERT_EQ(SUCCESS, state);
543     EXPECT_EQ(101, outValue); // 101 means the result of int resource
544 }
545 
TestGetFloatById(const char * touchTarget,const char * floatRef)546 void ResourceManagerTestCommon::TestGetFloatById(const char* touchTarget, const char* floatRef)
547 {
548     float outValue;
549     int id = GetResId(touchTarget, ResType::FLOAT);
550     ASSERT_TRUE(id > 0);
551     RState state = rm->GetFloatById(id, outValue);
552     ASSERT_EQ(SUCCESS, state);
553     EXPECT_EQ(48, outValue); // 48vp
554 
555     std::string unit;
556     state = rm->GetFloatById(id, outValue, unit);
557     ASSERT_EQ(SUCCESS, state);
558     EXPECT_EQ(48, outValue); // 48vp
559     EXPECT_EQ("vp", unit);
560 
561     id = GetResId(floatRef, ResType::FLOAT);
562     ASSERT_TRUE(id > 0);
563     state = rm->GetFloatById(id, outValue);
564     ASSERT_EQ(SUCCESS, state);
565     EXPECT_EQ(707, outValue); // 707vp
566 }
567 
TestGetFloatByName(const char * touchTarget,const char * floatRef)568 void ResourceManagerTestCommon::TestGetFloatByName(const char* touchTarget, const char* floatRef)
569 {
570     float outValue;
571     RState state = rm->GetFloatByName(touchTarget, outValue);
572     ASSERT_EQ(SUCCESS, state);
573     EXPECT_EQ(48, outValue); // 48vp
574 
575     std::string unit;
576     state = rm->GetFloatByName(touchTarget, outValue, unit);
577     ASSERT_EQ(SUCCESS, state);
578     EXPECT_EQ(48, outValue); // 48vp
579     EXPECT_EQ("vp", unit);
580 
581     state = rm->GetFloatByName(floatRef, outValue);
582     ASSERT_EQ(SUCCESS, state);
583     EXPECT_EQ(707, outValue); // 707vp
584 }
585 
TestGetIntArrayById(const char * intarray1)586 void ResourceManagerTestCommon::TestGetIntArrayById(const char* intarray1)
587 {
588     std::vector<int> outValue;
589     int id = GetResId(intarray1, ResType::INTARRAY);
590     EXPECT_TRUE(id > 0);
591     RState state = rm->GetIntArrayById(id, outValue);
592     EXPECT_TRUE(state == SUCCESS);
593     EXPECT_EQ(static_cast<uint32_t>(3), outValue.size()); // 3 means the size of int array resource
594     EXPECT_EQ(100, outValue[0]); // 100 means the first value of int array
595     EXPECT_EQ(200, outValue[1]); // 200 means the second value of int array
596     EXPECT_EQ(101, outValue[2]); // 101 means the third value of int array
597 }
598 
TestGetIntArrayByName(const char * intarray1)599 void ResourceManagerTestCommon::TestGetIntArrayByName(const char* intarray1)
600 {
601     std::vector<int> outValue;
602     RState state = rm->GetIntArrayByName(intarray1, outValue);
603     EXPECT_TRUE(state == SUCCESS);
604     EXPECT_EQ(static_cast<uint32_t>(3), outValue.size()); // 3 means the size of int array resource
605     EXPECT_EQ(100, outValue[0]); // 100 means the first value of int array
606     EXPECT_EQ(200, outValue[1]); // 200 means the second value of int array
607     EXPECT_EQ(101, outValue[2]); // 101 means the third value of int array
608 }
609 
TestGetResourceLimitKeys(uint32_t expectedLimitKeys)610 void ResourceManagerTestCommon::TestGetResourceLimitKeys(uint32_t expectedLimitKeys)
611 {
612     uint32_t limitKeys = rm->GetResourceLimitKeys();
613     limitKeys &= expectedLimitKeys;
614     EXPECT_EQ(limitKeys, expectedLimitKeys);
615 }
616