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