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
TestFormatPluralStringById(const int id,double quantity,const char * cmp)169 void ResourceManagerTestCommon::TestFormatPluralStringById(const int id, double quantity, const char *cmp)
170 {
171 RState ret;
172 std::string outValue;
173 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
174 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, std::to_string(quantity)));
175 ret = rm->GetFormatPluralStringById(outValue, id, quantity, params);
176 ASSERT_EQ(SUCCESS, ret);
177 ASSERT_EQ(std::string(cmp), outValue);
178 }
179
TestFormatPluralStringByName(const std::string name,double quantity,const char * cmp)180 void ResourceManagerTestCommon::TestFormatPluralStringByName(const std::string name, double quantity, const char *cmp)
181 {
182 RState ret;
183 std::string outValue;
184 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
185 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, std::to_string(quantity)));
186 ret = rm->GetFormatPluralStringByName(outValue, name.c_str(), quantity, params);
187 ASSERT_EQ(SUCCESS, ret);
188 ASSERT_EQ(std::string(cmp), outValue);
189 }
190
TestGetFormatPluralStringById(std::string outValue,const int id,ResourceManager::Quantity quantity,...)191 RState ResourceManagerTestCommon::TestGetFormatPluralStringById(std::string outValue, const int id,
192 ResourceManager::Quantity quantity, ...)
193 {
194 RState state;
195 va_list args;
196 va_start(args, quantity);
197 state = rm->GetFormatPluralStringById(outValue, id, quantity, args);
198 va_end(args);
199 return state;
200 }
201
TestGetFormatPluralStringByName(std::string outValue,const char * name,ResourceManager::Quantity quantity,...)202 RState ResourceManagerTestCommon::TestGetFormatPluralStringByName(std::string outValue, const char *name,
203 ResourceManager::Quantity quantity, ...)
204 {
205 RState state;
206 va_list args;
207 va_start(args, quantity);
208 state = rm->GetFormatPluralStringByName(outValue, name, quantity, args);
209 va_end(args);
210 return state;
211 }
212
TestGetRawFilePathByName(const std::string & name,const std::string & cmp)213 void ResourceManagerTestCommon::TestGetRawFilePathByName(const std::string &name, const std::string &cmp)
214 {
215 std::string outValue;
216 rm->GetRawFilePathByName(name, outValue);
217 RESMGR_HILOGD(RESMGR_TAG, "%s : %s", name.c_str(), outValue.c_str());
218 ASSERT_EQ(cmp, outValue);
219 }
220
TestGetProfileById(HapResource * tmp)221 void ResourceManagerTestCommon::TestGetProfileById(HapResource *tmp)
222 {
223 tmp->Init(this->defaultResConfig);
224 std::string res = tmp->GetResourcePath();
225 res.append("entry/resources/base/profile/test_profile.json");
226
227 std::string outValue;
228 RState state;
229 int id = GetResId("test_profile", ResType::PROF);
230 EXPECT_TRUE(id > 0);
231 state = rm->GetProfileById(id, outValue);
232 EXPECT_TRUE(state == SUCCESS);
233 EXPECT_EQ(res, outValue);
234 }
235
TestGetProfileByName(HapResource * tmp)236 void ResourceManagerTestCommon::TestGetProfileByName(HapResource *tmp)
237 {
238 tmp->Init(this->defaultResConfig);
239 std::string res = tmp->GetResourcePath();
240 res.append("entry/resources/base/profile/test_profile.json");
241
242 std::string outValue;
243 RState state = rm->GetProfileByName("test_profile", outValue);
244 EXPECT_TRUE(state == SUCCESS);
245 EXPECT_EQ(res, outValue);
246 }
247
TestGetMediaById(HapResource * tmp)248 void ResourceManagerTestCommon::TestGetMediaById(HapResource *tmp)
249 {
250 tmp->Init(this->defaultResConfig);
251 std::string res = tmp->GetResourcePath();
252 res.append("entry/resources/base/media/icon1.png");
253
254 std::string outValue;
255 int id = GetResId("icon1", ResType::MEDIA);
256 EXPECT_TRUE(id > 0);
257 RState state = rm->GetMediaById(id, outValue);
258 EXPECT_TRUE(state == SUCCESS);
259 EXPECT_EQ(res, outValue);
260 }
261
TestGetMediaWithDensityById(HapResource * tmp)262 void ResourceManagerTestCommon::TestGetMediaWithDensityById(HapResource *tmp)
263 {
264 tmp->Init(this->defaultResConfig);
265 std::string res = tmp->GetResourcePath();
266 res.append("entry/resources/sdpi/media/icon.png");
267
268 auto rc = CreateResConfig();
269 if (rc == nullptr) {
270 EXPECT_TRUE(false);
271 return;
272 }
273 rc->SetDeviceType(DEVICE_TV);
274 rc->SetColorMode(COLOR_MODE_NOT_SET);
275 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
276 rm->UpdateResConfig(*rc);
277 delete rc;
278
279 int density = 120;
280 std::string outValue;
281 int id = GetResId("icon", ResType::MEDIA);
282 EXPECT_TRUE(id > 0);
283 RState state = rm->GetMediaById(id, outValue, density);
284 EXPECT_TRUE(state == SUCCESS);
285 EXPECT_EQ(res, outValue);
286 }
287
TestGetMediaByName(HapResource * tmp)288 void ResourceManagerTestCommon::TestGetMediaByName(HapResource *tmp)
289 {
290 tmp->Init(this->defaultResConfig);
291 std::string res = tmp->GetResourcePath();
292 res.append("entry/resources/base/media/icon1.png");
293
294 std::string outValue;
295 RState state = rm->GetMediaByName("icon1", outValue);
296 EXPECT_TRUE(state == SUCCESS);
297 EXPECT_EQ(res, outValue);
298 }
299
TestGetMediaWithDensityByName(HapResource * tmp)300 void ResourceManagerTestCommon::TestGetMediaWithDensityByName(HapResource *tmp)
301 {
302 tmp->Init(this->defaultResConfig);
303 std::string res = tmp->GetResourcePath();
304 res.append("entry/resources/sdpi/media/icon.png");
305
306 auto rc = CreateResConfig();
307 if (rc == nullptr) {
308 EXPECT_TRUE(false);
309 return;
310 }
311 rc->SetDeviceType(DEVICE_PHONE);
312 rc->SetColorMode(COLOR_MODE_NOT_SET);
313 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
314 rm->UpdateResConfig(*rc);
315 delete rc;
316
317 uint32_t density = 120;
318 std::string outValue;
319 RState state = rm->GetMediaByName("icon", outValue, density);
320 EXPECT_TRUE(state == SUCCESS);
321 EXPECT_EQ(res, outValue);
322 }
323
TestGetDrawableInfoById(HapResource * tmp)324 void ResourceManagerTestCommon::TestGetDrawableInfoById(HapResource *tmp)
325 {
326 tmp->Init(this->defaultResConfig);
327 int id = GetResId("icon1", ResType::MEDIA);
328 EXPECT_TRUE(id > 0);
329 std::string type;
330 size_t len;
331 std::unique_ptr<uint8_t[]> jsonBuf;
332 RState state = rm->GetDrawableInfoById(id, type, len, jsonBuf);
333 EXPECT_TRUE(state == SUCCESS);
334 EXPECT_TRUE(jsonBuf != nullptr);
335 }
336
TestGetDrawableInfoWithDensityById(HapResource * tmp)337 void ResourceManagerTestCommon::TestGetDrawableInfoWithDensityById(HapResource *tmp)
338 {
339 tmp->Init(this->defaultResConfig);
340 auto rc = CreateResConfig();
341 if (rc == nullptr) {
342 EXPECT_TRUE(false);
343 return;
344 }
345 rc->SetDeviceType(DEVICE_TV);
346 rc->SetColorMode(COLOR_MODE_NOT_SET);
347 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
348 rm->UpdateResConfig(*rc);
349 delete rc;
350
351 int density = 120;
352 int id = GetResId("icon", ResType::MEDIA);
353 EXPECT_TRUE(id > 0);
354 std::string type;
355 size_t len;
356 std::unique_ptr<uint8_t[]> jsonBuf;
357 RState state = rm->GetDrawableInfoById(id, type, len, jsonBuf, density);
358 EXPECT_TRUE(state == SUCCESS);
359 EXPECT_TRUE(jsonBuf != nullptr);
360
361 // invalid density
362 int invalidDensity = 1000;
363 state = rm->GetDrawableInfoById(id, type, len, jsonBuf, invalidDensity);
364 EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
365 }
366
TestGetDrawableInfoByName(HapResource * tmp)367 void ResourceManagerTestCommon::TestGetDrawableInfoByName(HapResource *tmp)
368 {
369 tmp->Init(this->defaultResConfig);
370 std::string type;
371 size_t len;
372 std::unique_ptr<uint8_t[]> jsonBuf;
373 RState state = rm->GetDrawableInfoByName("icon1", type, len, jsonBuf);
374 EXPECT_TRUE(state == SUCCESS);
375 EXPECT_TRUE(jsonBuf != nullptr);
376 }
377
TestGetDrawableInfoWithDensityByName(HapResource * tmp)378 void ResourceManagerTestCommon::TestGetDrawableInfoWithDensityByName(HapResource *tmp)
379 {
380 tmp->Init(this->defaultResConfig);
381 auto rc = CreateResConfig();
382 if (rc == nullptr) {
383 EXPECT_TRUE(false);
384 return;
385 }
386 rc->SetDeviceType(DEVICE_PHONE);
387 rc->SetColorMode(COLOR_MODE_NOT_SET);
388 rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
389 rm->UpdateResConfig(*rc);
390 delete rc;
391
392 uint32_t density = 120;
393 std::string type;
394 size_t len;
395 std::unique_ptr<uint8_t[]> jsonBuf;
396 RState state = rm->GetDrawableInfoByName("icon1", type, len, jsonBuf, density);
397 EXPECT_TRUE(state == SUCCESS);
398 EXPECT_TRUE(jsonBuf != nullptr);
399
400 // invalid density
401 int invalidDensity = 1000;
402 state = rm->GetDrawableInfoByName("icon1", type, len, jsonBuf, invalidDensity);
403 EXPECT_TRUE(state == ERROR_CODE_INVALID_INPUT_PARAMETER);
404 }
405
TestGetStringFormatById(const char * name,const char * cmp)406 void ResourceManagerTestCommon::TestGetStringFormatById(const char *name, const char *cmp)
407 {
408 int id = GetResId(name, ResType::STRING);
409 ASSERT_TRUE(id > 0);
410 std::string outValue;
411 RState state = rm->GetStringFormatById(outValue, id, 101); // 101 means the format number
412 ASSERT_EQ(SUCCESS, state);
413 ASSERT_EQ(cmp, outValue);
414 }
415
TestGetStringFormatByName(const char * name,const char * cmp)416 void ResourceManagerTestCommon::TestGetStringFormatByName(const char *name, const char *cmp)
417 {
418 std::string outValue;
419 RState state = rm->GetStringFormatByName(outValue, name, 101); // 101 means the format number
420 ASSERT_EQ(SUCCESS, state);
421 ASSERT_EQ(cmp, outValue);
422 }
423
TestGetStringArrayById(const char * name)424 void ResourceManagerTestCommon::TestGetStringArrayById(const char *name)
425 {
426 std::vector<std::string> outValue;
427 int id = GetResId(name, ResType::STRINGARRAY);
428 RState state = rm->GetStringArrayById(id, outValue);
429 ASSERT_EQ(SUCCESS, state);
430 ASSERT_EQ(static_cast<size_t>(4), outValue.size()); // 4 means the size of string array resource
431 PrintVectorString(outValue);
432 }
433
TestGetStringFormatById(const char * name,std::vector<std::tuple<ResourceManager::NapiValueType,std::string>> & jsParams,const char * cmp)434 void ResourceManagerTestCommon::TestGetStringFormatById(const char *name,
435 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams, const char *cmp)
436 {
437 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
438 ASSERT_TRUE(ret);
439 uint32_t id = GetResId(name, ResType::STRING);
440 ASSERT_TRUE(id > 0);
441 std::string outValue;
442 RState state = rm->GetStringFormatById(id, outValue, jsParams);
443 ASSERT_EQ(SUCCESS, state);
444 ASSERT_EQ(cmp, outValue);
445 }
446
TestGetStringFormatByIdWithVaArgs(const char * name,const char * cmp,...)447 void ResourceManagerTestCommon::TestGetStringFormatByIdWithVaArgs(const char *name, const char *cmp, ...)
448 {
449 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
450 ASSERT_TRUE(ret);
451 uint32_t id = GetResId(name, ResType::STRING);
452 ASSERT_TRUE(id > 0);
453 std::string outValue;
454 va_list args;
455 va_start(args, cmp);
456 RState state = rm->GetStringFormatById(outValue, id, args);
457 va_end(args);
458 ASSERT_EQ(SUCCESS, state);
459 ASSERT_EQ(cmp, outValue);
460 }
461
TestGetStringFormatByName(const char * name,std::vector<std::tuple<ResourceManager::NapiValueType,std::string>> & jsParams,const char * cmp)462 void ResourceManagerTestCommon::TestGetStringFormatByName(const char *name,
463 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams, const char *cmp)
464 {
465 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
466 ASSERT_TRUE(ret);
467 std::string outValue;
468 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
469 ASSERT_EQ(SUCCESS, state);
470 ASSERT_EQ(cmp, outValue);
471 }
472
TestGetStringFormatByNameWithVaArgs(const char * name,const char * cmp,...)473 void ResourceManagerTestCommon::TestGetStringFormatByNameWithVaArgs(const char *name, const char *cmp, ...)
474 {
475 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
476 ASSERT_TRUE(ret);
477 std::string outValue;
478 va_list args;
479 va_start(args, cmp);
480 RState state = rm->GetStringFormatByName(outValue, name, args);
481 va_end(args);
482 ASSERT_EQ(SUCCESS, state);
483 ASSERT_EQ(cmp, outValue);
484 }
485
TestGetStringArrayByName(const char * name)486 void ResourceManagerTestCommon::TestGetStringArrayByName(const char *name)
487 {
488 std::vector<std::string> outValue;
489 RState state = rm->GetStringArrayByName(name, outValue);
490 ASSERT_EQ(SUCCESS, state);
491 ASSERT_EQ(static_cast<size_t>(4), outValue.size()); // 4 means the size of string array resource
492 PrintVectorString(outValue);
493 }
494
TestGetPatternById(const char * name)495 void ResourceManagerTestCommon::TestGetPatternById(const char *name)
496 {
497 std::map<std::string, std::string> outValue;
498 int id = GetResId(name, ResType::PATTERN);
499 RState state = rm->GetPatternById(id, outValue);
500 ASSERT_EQ(SUCCESS, state);
501 ASSERT_EQ(static_cast<size_t>(3), outValue.size()); // 3 means the size of pattern resource
502 PrintMapString(outValue);
503 }
504
TestGetPatternByName(const char * name)505 void ResourceManagerTestCommon::TestGetPatternByName(const char *name)
506 {
507 std::map<std::string, std::string> outValue;
508 RState state = rm->GetPatternByName(name, outValue);
509 ASSERT_EQ(SUCCESS, state);
510 ASSERT_EQ(static_cast<size_t>(3), outValue.size()); // 3 means the size of pattern resource
511 PrintMapString(outValue);
512 }
513
TestGetThemeById(const char * name)514 void ResourceManagerTestCommon::TestGetThemeById(const char *name)
515 {
516 std::map<std::string, std::string> outValue;
517 int id = GetResId(name, ResType::THEME);
518 ASSERT_TRUE(id > 0);
519 RState state = rm->GetThemeById(id, outValue);
520 ASSERT_EQ(SUCCESS, state);
521 }
522
TestGetThemeByName(const char * appTheme,const char * testTheme)523 void ResourceManagerTestCommon::TestGetThemeByName(const char *appTheme, const char *testTheme)
524 {
525 std::map<std::string, std::string> outValue;
526 RState state = rm->GetThemeByName(appTheme, outValue);
527 ASSERT_EQ(SUCCESS, state);
528 PrintMapString(outValue);
529
530 state = rm->GetThemeByName(testTheme, outValue);
531 ASSERT_EQ(SUCCESS, state);
532 }
533
TestGetBooleanById(const char * boolean1,const char * booleanRef)534 void ResourceManagerTestCommon::TestGetBooleanById(const char* boolean1, const char* booleanRef)
535 {
536 bool outValue = true;
537 int id = GetResId(boolean1, ResType::BOOLEAN);
538 ASSERT_TRUE(id > 0);
539 RState state = rm->GetBooleanById(id, outValue);
540 ASSERT_EQ(SUCCESS, state);
541 EXPECT_TRUE(outValue);
542
543 id = GetResId(booleanRef, ResType::BOOLEAN);
544 ASSERT_TRUE(id > 0);
545 state = rm->GetBooleanById(id, outValue);
546 ASSERT_EQ(SUCCESS, state);
547 EXPECT_TRUE(outValue);
548 }
549
TestGetBooleanByName(const char * boolean1,const char * booleanRef)550 void ResourceManagerTestCommon::TestGetBooleanByName(const char* boolean1, const char* booleanRef)
551 {
552 bool outValue = true;
553 RState state = rm->GetBooleanByName(boolean1, outValue);
554 ASSERT_EQ(SUCCESS, state);
555 EXPECT_TRUE(outValue);
556
557 state = rm->GetBooleanByName(booleanRef, outValue);
558 ASSERT_EQ(SUCCESS, state);
559 EXPECT_TRUE(outValue);
560 }
561
TestGetIntegerById(const char * integer1,const char * integerRef)562 void ResourceManagerTestCommon::TestGetIntegerById(const char* integer1, const char* integerRef)
563 {
564 int outValue;
565 int id = GetResId(integer1, ResType::INTEGER);
566 ASSERT_TRUE(id > 0);
567 RState state = rm->GetIntegerById(id, outValue);
568 ASSERT_EQ(SUCCESS, state);
569 EXPECT_EQ(101, outValue); // 101 means the result of int resource
570
571 id = GetResId(integerRef, ResType::INTEGER);
572 ASSERT_TRUE(id > 0);
573 state = rm->GetIntegerById(id, outValue);
574 ASSERT_EQ(SUCCESS, state);
575 EXPECT_EQ(101, outValue); // 101 means the result of int resource
576 }
577
TestGetIntegerByName(const char * integer1,const char * integerRef)578 void ResourceManagerTestCommon::TestGetIntegerByName(const char* integer1, const char* integerRef)
579 {
580 int outValue;
581 RState state = rm->GetIntegerByName(integer1, outValue);
582 ASSERT_EQ(SUCCESS, state);
583 EXPECT_EQ(101, outValue); // 101 means the result of int resource
584
585
586 state = rm->GetIntegerByName(integerRef, outValue);
587 ASSERT_EQ(SUCCESS, state);
588 EXPECT_EQ(101, outValue); // 101 means the result of int resource
589 }
590
TestGetFloatById(const char * touchTarget,const char * floatRef)591 void ResourceManagerTestCommon::TestGetFloatById(const char* touchTarget, const char* floatRef)
592 {
593 float outValue;
594 int id = GetResId(touchTarget, ResType::FLOAT);
595 ASSERT_TRUE(id > 0);
596 RState state = rm->GetFloatById(id, outValue);
597 ASSERT_EQ(SUCCESS, state);
598 EXPECT_EQ(48, outValue); // 48vp
599
600 std::string unit;
601 state = rm->GetFloatById(id, outValue, unit);
602 ASSERT_EQ(SUCCESS, state);
603 EXPECT_EQ(48, outValue); // 48vp
604 EXPECT_EQ("vp", unit);
605
606 id = GetResId(floatRef, ResType::FLOAT);
607 ASSERT_TRUE(id > 0);
608 state = rm->GetFloatById(id, outValue);
609 ASSERT_EQ(SUCCESS, state);
610 EXPECT_EQ(707, outValue); // 707vp
611 }
612
TestGetFloatByName(const char * touchTarget,const char * floatRef)613 void ResourceManagerTestCommon::TestGetFloatByName(const char* touchTarget, const char* floatRef)
614 {
615 float outValue;
616 RState state = rm->GetFloatByName(touchTarget, outValue);
617 ASSERT_EQ(SUCCESS, state);
618 EXPECT_EQ(48, outValue); // 48vp
619
620 std::string unit;
621 state = rm->GetFloatByName(touchTarget, outValue, unit);
622 ASSERT_EQ(SUCCESS, state);
623 EXPECT_EQ(48, outValue); // 48vp
624 EXPECT_EQ("vp", unit);
625
626 state = rm->GetFloatByName(floatRef, outValue);
627 ASSERT_EQ(SUCCESS, state);
628 EXPECT_EQ(707, outValue); // 707vp
629 }
630
TestGetIntArrayById(const char * intarray1)631 void ResourceManagerTestCommon::TestGetIntArrayById(const char* intarray1)
632 {
633 std::vector<int> outValue;
634 int id = GetResId(intarray1, ResType::INTARRAY);
635 EXPECT_TRUE(id > 0);
636 RState state = rm->GetIntArrayById(id, outValue);
637 EXPECT_TRUE(state == SUCCESS);
638 EXPECT_EQ(static_cast<uint32_t>(3), outValue.size()); // 3 means the size of int array resource
639 EXPECT_EQ(100, outValue[0]); // 100 means the first value of int array
640 EXPECT_EQ(200, outValue[1]); // 200 means the second value of int array
641 EXPECT_EQ(101, outValue[2]); // 101 means the third value of int array
642 }
643
TestGetIntArrayByName(const char * intarray1)644 void ResourceManagerTestCommon::TestGetIntArrayByName(const char* intarray1)
645 {
646 std::vector<int> outValue;
647 RState state = rm->GetIntArrayByName(intarray1, outValue);
648 EXPECT_TRUE(state == SUCCESS);
649 EXPECT_EQ(static_cast<uint32_t>(3), outValue.size()); // 3 means the size of int array resource
650 EXPECT_EQ(100, outValue[0]); // 100 means the first value of int array
651 EXPECT_EQ(200, outValue[1]); // 200 means the second value of int array
652 EXPECT_EQ(101, outValue[2]); // 101 means the third value of int array
653 }
654
TestGetResourceLimitKeys(uint32_t expectedLimitKeys)655 void ResourceManagerTestCommon::TestGetResourceLimitKeys(uint32_t expectedLimitKeys)
656 {
657 uint32_t limitKeys = rm->GetResourceLimitKeys();
658 limitKeys &= expectedLimitKeys;
659 EXPECT_EQ(limitKeys, expectedLimitKeys);
660 }
661