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_media.h"
17
18 #include "resource_manager_test_common.h"
19
20 using namespace OHOS::Global::Resource;
21 using namespace testing::ext;
22 namespace {
23 class ResourceManagerTestString : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26
27 static void TearDownTestCase(void);
28
29 void SetUp();
30
31 void TearDown();
32
ResourceManagerTestString()33 ResourceManagerTestString() : rm(nullptr)
34 {}
35
~ResourceManagerTestString()36 ~ResourceManagerTestString()
37 {}
38 public:
39 ResourceManager *rm;
40 ResourceManagerTestCommon *rmc;
41 };
42
SetUpTestCase(void)43 void ResourceManagerTestString::SetUpTestCase(void)
44 {
45 // step 1: input testsuit setup step
46 g_logLevel = LOG_DEBUG;
47 }
48
TearDownTestCase(void)49 void ResourceManagerTestString::TearDownTestCase(void)
50 {
51 // step 2: input testsuit teardown step
52 }
53
SetUp(void)54 void ResourceManagerTestString::SetUp(void)
55 {
56 this->rm = CreateResourceManager();
57 this->rmc = new ResourceManagerTestCommon(rm);
58 }
59
TearDown(void)60 void ResourceManagerTestString::TearDown(void)
61 {
62 delete this->rm;
63 delete this->rmc;
64 }
65
66 /*
67 * @tc.name: ResourceManagerGetStringByIdTest001
68 * @tc.desc: Test GetStringById function
69 * @tc.type: FUNC
70 */
71 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest001, TestSize.Level1)
72 {
73 rmc->AddResource("en", nullptr, nullptr);
74
75 rmc->TestStringById("app_name", "App Name");
76
77 rmc->TestStringById("copyright_text", "XXXXXX All rights reserved. ©2011-2019");
78
79 rmc->TestStringById("string_ref", "XXXXXX All rights reserved. ©2011-2019");
80
81 rmc->TestStringById("string_ref2", "XXXXXX All rights reserved. ©2011-2019");
82 }
83
84 /*
85 * @tc.name: ResourceManagerGetStringByIdTest002
86 * @tc.desc: Test GetStringById function
87 * @tc.type: FUNC
88 */
89 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest002, TestSize.Level1)
90 {
91 rmc->AddResource("zh", nullptr, nullptr);
92
93 rmc->TestStringById("app_name", "应用名称");
94
95 rmc->TestStringById("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利");
96
97 rmc->TestStringById("string_ref", "$aaaaa");
98
99 rmc->TestStringById("string_ref2", "$aaaaa");
100 }
101
102 /*
103 * @tc.name: ResourceManagerGetStringByIdTest003
104 * @tc.desc: Test GetStringById function
105 * @tc.type: FUNC
106 */
107 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest003, TestSize.Level1)
108 {
109 rmc->AddResource("zh", nullptr, nullptr);
110
111 std::string outValue;
112 RState state = rm->GetStringById(NON_EXIST_ID, outValue);
113 ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
114 }
115
116 /*
117 * @tc.name: ResourceManagerGetStringByIdTest004
118 * @tc.desc: Test GetStringById function
119 * @tc.type: FUNC
120 */
121 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest004, TestSize.Level1)
122 {
123 rmc->AddResource("en", nullptr, nullptr);
124
125 std::vector<std::string> overlayPaths;
126 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
127 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
128 ASSERT_TRUE(ret);
129 rmc->TestStringById("ohos_app_name", "SystemOverlay");
130 }
131
132 /*
133 * @tc.name: ResourceManagerGetStringByIdTest005
134 * @tc.desc: Test GetStringById function
135 * @tc.type: FUNC
136 */
137 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest005, TestSize.Level1)
138 {
139 rmc->AddResource("zh", nullptr, nullptr);
140
141 std::vector<std::string> overlayPaths;
142 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
143 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
144 ASSERT_TRUE(ret);
145 rmc->TestStringById("ohos_lab_answer_call", "overlay接听电话");
146 }
147
148 /*
149 * @tc.name: ResourceManagerGetStringByNameTest001
150 * @tc.desc: Test GetStringByName function
151 * @tc.type: FUNC
152 */
153 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest001, TestSize.Level1)
154 {
155 rmc->AddResource("en", nullptr, nullptr);
156
157 rmc->TestStringByName("app_name", "App Name");
158
159 rmc->TestStringByName("copyright_text", "XXXXXX All rights reserved. ©2011-2019");
160
161 rmc->TestStringByName("string_ref", "XXXXXX All rights reserved. ©2011-2019");
162
163 rmc->TestStringByName("string_ref2", "XXXXXX All rights reserved. ©2011-2019");
164 }
165
166 /*
167 * @tc.name: ResourceManagerGetStringByNameTest002
168 * @tc.desc: Test GetStringByName function
169 * @tc.type: FUNC
170 */
171 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest002, TestSize.Level1)
172 {
173 rmc->AddResource("zh", nullptr, nullptr);
174
175 rmc->TestStringByName("app_name", "应用名称");
176
177 rmc->TestStringByName("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利");
178
179 rmc->TestStringByName("string_ref", "$aaaaa");
180
181 rmc->TestStringByName("string_ref2", "$aaaaa");
182 }
183
184 /*
185 * @tc.name: ResourceManagerGetStringByNameTest003
186 * @tc.desc: Test GetStringByName function
187 * @tc.type: FUNC
188 */
189 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest003, TestSize.Level1)
190 {
191 rmc->AddResource("zh", nullptr, nullptr);
192
193 std::string outValue;
194 RState state = rm->GetStringByName(g_nonExistName, outValue);
195 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
196 }
197
198 /*
199 * @tc.name: ResourceManagerGetStringByNameTest004
200 * @tc.desc: Test GetStringByName function
201 * @tc.type: FUNC
202 */
203 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest004, TestSize.Level1)
204 {
205 auto rc = CreateResConfig();
206 if (rc == nullptr) {
207 EXPECT_TRUE(false);
208 return;
209 }
210 rc->SetLocaleInfo("zh", nullptr, "CN");
211 rc->SetDirection(DIRECTION_VERTICAL);
212 rm->UpdateResConfig(*rc);
213 delete rc;
214 std::vector<std::string> overlayPaths;
215 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
216 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
217 ASSERT_TRUE(ret);
218 std::string outValue;
219 ((ResourceManagerImpl *)rm)->GetStringByName("ohos_desc_camera", outValue);
220 ASSERT_EQ(outValue, "允许应用拍摄照片和视频。");
221 }
222
223 /*
224 * @tc.name: ResourceManagerGetStringByNameTest005
225 * @tc.desc: Test GetStringByName function
226 * @tc.type: FUNC
227 */
228 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest005, TestSize.Level1)
229 {
230 rmc->AddResource("en", nullptr, nullptr);
231 std::vector<std::string> overlayPaths;
232 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
233 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
234 ASSERT_TRUE(ret);
235 std::string outValue;
236 ((ResourceManagerImpl *)rm)->GetStringByName("hello", outValue);
237 ASSERT_EQ(outValue, "Helloooo");
238 }
239
240 /*
241 * @tc.name: ResourceManagerGetStringFormatByIdTest001
242 * @tc.desc: Test GetStringFormatById function
243 * @tc.type: FUNC
244 */
245 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest001, TestSize.Level1)
246 {
247 rmc->AddResource("zh", nullptr, nullptr);
248
249 const char *name = "app_name";
250 int id = rmc->GetResId(name, ResType::STRING);
251 ASSERT_TRUE(id > 0);
252 std::string outValue;
253 RState state = rm->GetStringFormatById(outValue, id, 101);
254 ASSERT_EQ(SUCCESS, state);
255 ASSERT_EQ("应用名称", outValue);
256 }
257
258 /*
259 * @tc.name: ResourceManagerGetStringFormatByIdTest002
260 * @tc.desc: Test GetStringFormatById function
261 * @tc.type: FUNC
262 */
263 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest002, TestSize.Level1)
264 {
265 rmc->AddResource("zh", nullptr, nullptr);
266
267 std::string outValue;
268 RState state = rm->GetStringFormatById(outValue, NON_EXIST_ID, 101);
269 ASSERT_EQ(NOT_FOUND, state);
270 }
271
272 /*
273 * @tc.name: ResourceManagerGetStringFormatByIdTest003
274 * @tc.desc: Test GetStringFormatById function
275 * @tc.type: FUNC
276 */
277 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest003, TestSize.Level1)
278 {
279 const char *name = "test_string0";
280 const char *cmp = "向前兼容";
281 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
282 rmc->TestGetStringFormatById(name, jsParams, cmp);
283 }
284
285 /*
286 * @tc.name: ResourceManagerGetStringFormatByIdTest004
287 * @tc.desc: Test GetStringFormatById function
288 * @tc.type: FUNC
289 */
290 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest004, TestSize.Level1)
291 {
292 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
293 std::string outValue;
294 RState state = rm->GetStringFormatById(NON_EXIST_ID, outValue, jsParams);
295 ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
296 }
297
298 /*
299 * @tc.name: ResourceManagerGetStringFormatByIdTest005
300 * @tc.desc: Test GetStringFormatById function
301 * @tc.type: FUNC
302 */
303 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest005, TestSize.Level1)
304 {
305 const char *name = "test_string1";
306 const char *cmp = "%10%d%%d%%";
307 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
308 {{ResourceManager::NapiValueType::NAPI_NUMBER, "10"}};
309 rmc->TestGetStringFormatByName(name, jsParams, cmp);
310 }
311
312 /*
313 * @tc.name: ResourceManagerGetStringFormatByIdTest006
314 * @tc.desc: Test GetStringFormatById function
315 * @tc.type: FUNC
316 */
317 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest006, TestSize.Level1)
318 {
319 const char *name = "test_string2";
320 const char *cmp = "-9.999 你好";
321 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
322 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"},
323 {ResourceManager::NapiValueType::NAPI_STRING, " 你好"}};
324 rmc->TestGetStringFormatByName(name, jsParams, cmp);
325 }
326
327 /*
328 * @tc.name: ResourceManagerGetStringFormatByIdTest007
329 * @tc.desc: Test GetStringFormatById function
330 * @tc.type: FUNC
331 */
332 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest007, TestSize.Level1)
333 {
334 const char *name = "test_string2";
335 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
336 ASSERT_TRUE(ret);
337 int id = rmc->GetResId(name, ResType::STRING);
338 ASSERT_TRUE(id > 0);
339 std::string outValue;
340 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
341 {{ResourceManager::NapiValueType::NAPI_STRING, " 你好"},
342 {ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
343 RState state = rm->GetStringFormatById(id, outValue, jsParams);
344 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
345 }
346
347 /*
348 * @tc.name: ResourceManagerGetStringFormatByIdTest008
349 * @tc.desc: Test GetStringFormatById function
350 * @tc.type: FUNC
351 */
352 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest008, TestSize.Level1)
353 {
354 const char *name = "test_string2";
355 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
356 ASSERT_TRUE(ret);
357 int id = rmc->GetResId(name, ResType::STRING);
358 ASSERT_TRUE(id > 0);
359 std::string outValue;
360 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
361 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
362 RState state = rm->GetStringFormatById(id, outValue, jsParams);
363 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
364 }
365
366 /*
367 * @tc.name: ResourceManagerGetStringFormatByIdTest009
368 * @tc.desc: Test GetStringFormatById function
369 * @tc.type: FUNC
370 */
371 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest009, TestSize.Level1)
372 {
373 const char *name = "test_string9";
374 const char *cmp = "%d-%d1$d";
375 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
376 rmc->TestGetStringFormatById(name, jsParams, cmp);
377 }
378
379 /*
380 * @tc.name: ResourceManagerGetStringFormatByIdTest010
381 * @tc.desc: Test GetStringFormatById function
382 * @tc.type: FUNC
383 */
384 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest010, TestSize.Level1)
385 {
386 const char *name = "test_string10";
387 const char *cmp = "%d%%%";
388 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
389 rmc->TestGetStringFormatById(name, jsParams, cmp);
390 }
391
392 /*
393 * @tc.name: ResourceManagerGetStringFormatByIdTest011
394 * @tc.desc: Test GetStringFormatById function
395 * @tc.type: FUNC
396 */
397 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest011, TestSize.Level1)
398 {
399 const char *name = "test_string11";
400 const char *cmp = "-7";
401 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
402 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-7.5"}};
403 rmc->TestGetStringFormatById(name, jsParams, cmp);
404 }
405
406 /*
407 * @tc.name: ResourceManagerGetStringFormatByIdTest012
408 * @tc.desc: Test GetStringFormatById function
409 * @tc.type: FUNC
410 */
411 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest012, TestSize.Level1)
412 {
413 const char *name = "test_string12";
414 const char *cmp = "2-1===6.100000-5.000000===你好,world===%hh%%%";
415 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
416 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1.000000"},
417 {ResourceManager::NapiValueType::NAPI_NUMBER, "2.100000"},
418 {ResourceManager::NapiValueType::NAPI_NUMBER, "5.000000"},
419 {ResourceManager::NapiValueType::NAPI_NUMBER, "6.100000"},
420 {ResourceManager::NapiValueType::NAPI_STRING, "world"},
421 {ResourceManager::NapiValueType::NAPI_STRING, "你好,"}};
422 rmc->TestGetStringFormatById(name, jsParams, cmp);
423 }
424
425 /*
426 * @tc.name: ResourceManagerGetStringFormatByIdTest013
427 * @tc.desc: Test GetStringFormatById function
428 * @tc.type: FUNC
429 */
430 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest013, TestSize.Level1)
431 {
432 const char *name = "test_string13";
433 const char *cmp = "11";
434 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
435 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
436 rmc->TestGetStringFormatById(name, jsParams, cmp);
437 }
438
439 /*
440 * @tc.name: ResourceManagerGetStringFormatByIdTest014
441 * @tc.desc: Test GetStringFormatById function
442 * @tc.type: FUNC
443 */
444 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest014, TestSize.Level1)
445 {
446 const char *name = "test_string14";
447 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
448 ASSERT_TRUE(ret);
449 int id = rmc->GetResId(name, ResType::STRING);
450 ASSERT_TRUE(id > 0);
451 std::string outValue;
452 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
453 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
454 RState state = rm->GetStringFormatById(id, outValue, jsParams);
455 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
456 }
457
458 /*
459 * @tc.name: ResourceManagerGetStringFormatByIdTest015
460 * @tc.desc: Test GetStringFormatById function
461 * @tc.type: FUNC
462 */
463 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest015, TestSize.Level1)
464 {
465 const char *name = "test_string15";
466 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
467 ASSERT_TRUE(ret);
468 int id = rmc->GetResId(name, ResType::STRING);
469 ASSERT_TRUE(id > 0);
470 std::string outValue;
471 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
472 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
473 RState state = rm->GetStringFormatById(id, outValue, jsParams);
474 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
475 }
476
477 /*
478 * @tc.name: ResourceManagerGetStringFormatByIdTest016
479 * @tc.desc: Test GetStringFormatById function
480 * @tc.type: FUNC
481 */
482 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest016, TestSize.Level1)
483 {
484 const char *name = "test_string16";
485 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
486 ASSERT_TRUE(ret);
487 int id = rmc->GetResId(name, ResType::STRING);
488 ASSERT_TRUE(id > 0);
489 std::string outValue;
490 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
491 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
492 RState state = rm->GetStringFormatById(id, outValue, jsParams);
493 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
494 }
495
496 /*
497 * @tc.name: ResourceManagerGetStringFormatByIdTest017
498 * @tc.desc: Test GetStringFormatById function
499 * @tc.type: FUNC
500 */
501 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest017, TestSize.Level1)
502 {
503 const char *name = "test_string17";
504 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
505 ASSERT_TRUE(ret);
506 int id = rmc->GetResId(name, ResType::STRING);
507 ASSERT_TRUE(id > 0);
508 std::string outValue;
509 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
510 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
511 RState state = rm->GetStringFormatById(id, outValue, jsParams);
512 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
513 }
514
515 /*
516 * @tc.name: ResourceManagerGetStringFormatByIdTest018
517 * @tc.desc: Test GetStringFormatById function
518 * @tc.type: FUNC
519 */
520 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest018, TestSize.Level1)
521 {
522 const char *name = "test_string18";
523 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
524 ASSERT_TRUE(ret);
525 int id = rmc->GetResId(name, ResType::STRING);
526 ASSERT_TRUE(id > 0);
527 std::string outValue;
528 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
529 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
530 RState state = rm->GetStringFormatById(id, outValue, jsParams);
531 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
532 }
533
534 /*
535 * @tc.name: ResourceManagerGetStringFormatByIdTest019
536 * @tc.desc: Test GetStringFormatById function
537 * @tc.type: FUNC
538 */
539 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest019, TestSize.Level1)
540 {
541 const char *name = "test_string19";
542 const char *cmp = "11";
543 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
544 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
545 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"}};
546 rmc->TestGetStringFormatById(name, jsParams, cmp);
547 }
548
549 /*
550 * @tc.name: ResourceManagerGetStringFormatByIdTest020
551 * @tc.desc: Test GetStringFormatById function
552 * @tc.type: FUNC
553 */
554 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest020, TestSize.Level1)
555 {
556 const char *name = "test_string20";
557 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
558 ASSERT_TRUE(ret);
559 int id = rmc->GetResId(name, ResType::STRING);
560 ASSERT_TRUE(id > 0);
561 std::string outValue;
562 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
563 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
564 RState state = rm->GetStringFormatById(id, outValue, jsParams);
565 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
566 }
567
568 /*
569 * @tc.name: ResourceManagerGetStringFormatByIdTest021
570 * @tc.desc: Test GetStringFormatById function
571 * @tc.type: FUNC
572 */
573 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest021, TestSize.Level1)
574 {
575 const char *name = "test_string21";
576 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
577 ASSERT_TRUE(ret);
578 int id = rmc->GetResId(name, ResType::STRING);
579 ASSERT_TRUE(id > 0);
580 std::string outValue;
581 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
582 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
583 RState state = rm->GetStringFormatById(id, outValue, jsParams);
584 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
585 }
586
587 /*
588 * @tc.name: ResourceManagerGetStringFormatByIdTest022
589 * @tc.desc: Test GetStringFormatById function
590 * @tc.type: FUNC
591 */
592 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest022, TestSize.Level1)
593 {
594 const char *name = "test_string22";
595 const char *cmp = "112";
596 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
597 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
598 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"},
599 {ResourceManager::NapiValueType::NAPI_NUMBER, "3"}};
600 rmc->TestGetStringFormatById(name, jsParams, cmp);
601 }
602
603 /*
604 * @tc.name: ResourceManagerGetStringFormatByIdTest023
605 * @tc.desc: Test GetStringFormatById function
606 * @tc.type: FUNC
607 */
608 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest023, TestSize.Level1)
609 {
610 const char *name = "test_string22";
611 const char *cmp = "112";
612 rmc->TestGetStringFormatByIdWithVaArgs(name, cmp, 1, 2, 3);
613 }
614
615 /*
616 * @tc.name: ResourceManagerGetStringFormatByNameTest001
617 * @tc.desc: Test GetStringFormatByName function
618 * @tc.type: FUNC
619 */
620 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest001, TestSize.Level1)
621 {
622 rmc->AddResource("zh", nullptr, nullptr);
623
624 const char *name = "app_name";
625 std::string outValue;
626 RState state = rm->GetStringFormatByName(outValue, name, 101);
627 ASSERT_EQ(SUCCESS, state);
628 ASSERT_EQ("应用名称", outValue);
629 }
630
631 /*
632 * @tc.name: ResourceManagerGetStringFormatByNameTest002
633 * @tc.desc: Test GetStringFormatByName function
634 * @tc.type: FUNC
635 */
636 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest002, TestSize.Level1)
637 {
638 rmc->AddResource("zh", nullptr, nullptr);
639
640 std::string outValue;
641 RState state = rm->GetStringFormatByName(outValue, g_nonExistName, 101);
642 ASSERT_EQ(NOT_FOUND, state);
643 }
644
645 /*
646 * @tc.name: ResourceManagerGetStringFormatByNameTest003
647 * @tc.desc: Test GetStringFormatByName function
648 * @tc.type: FUNC
649 */
650 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest003, TestSize.Level1)
651 {
652 const char *name = "test_string0";
653 const char *cmp = "向前兼容";
654 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
655 rmc->TestGetStringFormatByName(name, jsParams, cmp);
656 }
657
658 /*
659 * @tc.name: ResourceManagerGetStringFormatByNameTest004
660 * @tc.desc: Test GetStringFormatByName function
661 * @tc.type: FUNC
662 */
663 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest004, TestSize.Level1)
664 {
665 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
666 std::string outValue;
667 RState state = rm->GetStringFormatByName("NON_EXIST_NAME", outValue, jsParams);
668 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
669 }
670
671 /*
672 * @tc.name: ResourceManagerGetStringFormatByNameTest005
673 * @tc.desc: Test GetStringFormatByName function
674 * @tc.type: FUNC
675 */
676 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest005, TestSize.Level1)
677 {
678 const char *name = "test_string3";
679 const char *cmp = "abc12.3abc%%\"abc\"abc";
680 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
681 {{ResourceManager::NapiValueType::NAPI_NUMBER, "12.3"},
682 {ResourceManager::NapiValueType::NAPI_STRING, "\"abc\""}};
683 rmc->TestGetStringFormatByName(name, jsParams, cmp);
684 }
685
686 /*
687 * @tc.name: ResourceManagerGetStringFormatByNameTest006
688 * @tc.desc: Test GetStringFormatByName function
689 * @tc.type: FUNC
690 */
691 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest006, TestSize.Level1)
692 {
693 const char *name = "test_string4";
694 const char *cmp = "%a-320a%%";
695 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
696 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-320"}};
697 rmc->TestGetStringFormatByName(name, jsParams, cmp);
698 }
699
700 /*
701 * @tc.name: ResourceManagerGetStringFormatByNameTest007
702 * @tc.desc: Test GetStringFormatByName function
703 * @tc.type: FUNC
704 */
705 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest007, TestSize.Level1)
706 {
707 const char *name = "test_string2";
708 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
709 ASSERT_TRUE(ret);
710 std::string outValue;
711 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
712 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"},
713 {ResourceManager::NapiValueType::NAPI_NUMBER, "abc"}};
714 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
715 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
716 }
717
718 /*
719 * @tc.name: ResourceManagerGetStringFormatByNameTest008
720 * @tc.desc: Test GetStringFormatByName function
721 * @tc.type: FUNC
722 */
723 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest008, TestSize.Level1)
724 {
725 const char *name = "test_string2";
726 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
727 ASSERT_TRUE(ret);
728 std::string outValue;
729 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
730 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
731 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
732 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
733 }
734
735 /*
736 * @tc.name: ResourceManagerGetStringFormatByNameTest009
737 * @tc.desc: Test GetStringFormatById function
738 * @tc.type: FUNC
739 */
740 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest009, TestSize.Level1)
741 {
742 const char *name = "test_string9";
743 const char *cmp = "%d-%d1$d";
744 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
745 rmc->TestGetStringFormatByName(name, jsParams, cmp);
746 }
747
748 /*
749 * @tc.name: ResourceManagerGetStringFormatByNameTest010
750 * @tc.desc: Test GetStringFormatById function
751 * @tc.type: FUNC
752 */
753 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest010, TestSize.Level1)
754 {
755 const char *name = "test_string10";
756 const char *cmp = "%d%%%";
757 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
758 rmc->TestGetStringFormatByName(name, jsParams, cmp);
759 }
760
761 /*
762 * @tc.name: ResourceManagerGetStringFormatByNameTest011
763 * @tc.desc: Test GetStringFormatById function
764 * @tc.type: FUNC
765 */
766 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest011, TestSize.Level1)
767 {
768 const char *name = "test_string11";
769 const char *cmp = "-7";
770 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
771 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-7.5"}};
772 rmc->TestGetStringFormatByName(name, jsParams, cmp);
773 }
774
775 /*
776 * @tc.name: ResourceManagerGetStringFormatByNameTest012
777 * @tc.desc: Test GetStringFormatById function
778 * @tc.type: FUNC
779 */
780 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest012, TestSize.Level1)
781 {
782 const char *name = "test_string12";
783 const char *cmp = "2-1===4.100000-3.000000===你好,world===%hh%%%";
784 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
785 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1.000000"},
786 {ResourceManager::NapiValueType::NAPI_NUMBER, "2.100000"},
787 {ResourceManager::NapiValueType::NAPI_NUMBER, "3.000000"},
788 {ResourceManager::NapiValueType::NAPI_NUMBER, "4.100000"},
789 {ResourceManager::NapiValueType::NAPI_STRING, "world"},
790 {ResourceManager::NapiValueType::NAPI_STRING, "你好,"}};
791 rmc->TestGetStringFormatByName(name, jsParams, cmp);
792 }
793
794 /*
795 * @tc.name: ResourceManagerGetStringFormatByNameTest013
796 * @tc.desc: Test GetStringFormatById function
797 * @tc.type: FUNC
798 */
799 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest013, TestSize.Level1)
800 {
801 const char *name = "test_string13";
802 const char *cmp = "11";
803 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
804 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
805 rmc->TestGetStringFormatByName(name, jsParams, cmp);
806 }
807
808 /*
809 * @tc.name: ResourceManagerGetStringFormatByNameTest014
810 * @tc.desc: Test GetStringFormatById function
811 * @tc.type: FUNC
812 */
813 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest014, TestSize.Level1)
814 {
815 const char *name = "test_string14";
816 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
817 ASSERT_TRUE(ret);
818 std::string outValue;
819 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
820 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
821 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
822 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
823 }
824
825 /*
826 * @tc.name: ResourceManagerGetStringFormatByNameTest015
827 * @tc.desc: Test GetStringFormatById function
828 * @tc.type: FUNC
829 */
830 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest015, TestSize.Level1)
831 {
832 const char *name = "test_string15";
833 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
834 ASSERT_TRUE(ret);
835 std::string outValue;
836 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
837 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
838 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
839 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
840 }
841
842 /*
843 * @tc.name: ResourceManagerGetStringFormatByNameTest016
844 * @tc.desc: Test GetStringFormatById function
845 * @tc.type: FUNC
846 */
847 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest016, TestSize.Level1)
848 {
849 const char *name = "test_string16";
850 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
851 ASSERT_TRUE(ret);
852 std::string outValue;
853 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
854 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
855 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
856 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
857 }
858
859 /*
860 * @tc.name: ResourceManagerGetStringFormatByNameTest017
861 * @tc.desc: Test GetStringFormatById function
862 * @tc.type: FUNC
863 */
864 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest017, TestSize.Level1)
865 {
866 const char *name = "test_string17";
867 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
868 ASSERT_TRUE(ret);
869 std::string outValue;
870 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
871 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
872 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
873 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
874 }
875
876 /*
877 * @tc.name: ResourceManagerGetStringFormatByNameTest018
878 * @tc.desc: Test GetStringFormatById function
879 * @tc.type: FUNC
880 */
881 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest018, TestSize.Level1)
882 {
883 const char *name = "test_string18";
884 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
885 ASSERT_TRUE(ret);
886 std::string outValue;
887 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
888 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
889 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
890 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
891 }
892
893 /*
894 * @tc.name: ResourceManagerGetStringFormatByNameTest019
895 * @tc.desc: Test GetStringFormatById function
896 * @tc.type: FUNC
897 */
898 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest019, TestSize.Level1)
899 {
900 const char *name = "test_string19";
901 const char *cmp = "11";
902 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
903 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
904 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"}};
905 rmc->TestGetStringFormatByName(name, jsParams, cmp);
906 }
907
908 /*
909 * @tc.name: ResourceManagerGetStringFormatByNameTest020
910 * @tc.desc: Test GetStringFormatById function
911 * @tc.type: FUNC
912 */
913 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest020, TestSize.Level1)
914 {
915 const char *name = "test_string20";
916 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
917 ASSERT_TRUE(ret);
918 std::string outValue;
919 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
920 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
921 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
922 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
923 }
924
925 /*
926 * @tc.name: ResourceManagerGetStringFormatByNameTest021
927 * @tc.desc: Test GetStringFormatById function
928 * @tc.type: FUNC
929 */
930 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest021, TestSize.Level1)
931 {
932 const char *name = "test_string21";
933 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
934 ASSERT_TRUE(ret);
935 std::string outValue;
936 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
937 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
938 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
939 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
940 }
941
942 /*
943 * @tc.name: ResourceManagerGetStringFormatByNameTest022
944 * @tc.desc: Test GetStringFormatById function
945 * @tc.type: FUNC
946 */
947 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest022, TestSize.Level1)
948 {
949 const char *name = "test_string22";
950 const char *cmp = "112";
951 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
952 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
953 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"},
954 {ResourceManager::NapiValueType::NAPI_NUMBER, "3"}};
955 rmc->TestGetStringFormatByName(name, jsParams, cmp);
956 }
957
958 /*
959 * @tc.name: ResourceManagerGetStringFormatByNameTest023
960 * @tc.desc: Test GetStringFormatById function
961 * @tc.type: FUNC
962 */
963 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest023, TestSize.Level1)
964 {
965 const char *name = "test_string22";
966 const char *cmp = "112";
967 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, 1, 2, 3);
968 }
969
970 /*
971 * @tc.name: ResourceManagerGetStringArrayByIdTest001
972 * @tc.desc: Test GetStringArrayById function, file case.
973 * @tc.type: FUNC
974 */
975 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByIdTest001, TestSize.Level1)
976 {
977 rmc->AddResource("zh", nullptr, nullptr);
978
979 rmc->TestGetStringArrayById("size");
980 }
981
982 /*
983 * @tc.name: ResourceManagerGetStringArrayByIdTest002
984 * @tc.desc: Test GetStringArrayById function, file case.
985 * @tc.type: FUNC
986 */
987 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByIdTest002, TestSize.Level1)
988 {
989 rmc->AddResource("zh", nullptr, nullptr);
990
991 RState state;
992 // error case
993 // not found case
994 std::vector<std::string> outValue;
995 state = rm->GetStringArrayById(NON_EXIST_ID, outValue);
996 ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
997 }
998
999 /*
1000 * @tc.name: ResourceManagerGetStringArrayByNameTest001
1001 * @tc.desc: Test GetStringArrayByName function, file case.
1002 * @tc.type: FUNC
1003 */
1004 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByNameTest001, TestSize.Level1)
1005 {
1006 rmc->AddResource("zh", nullptr, nullptr);
1007
1008 rmc->TestGetStringArrayByName("size");
1009 }
1010
1011 /*
1012 * @tc.name: ResourceManagerGetStringArrayByNameTest002
1013 * @tc.desc: Test GetStringArrayByName function, file case.
1014 * @tc.type: FUNC
1015 */
1016 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByNameTest002, TestSize.Level1)
1017 {
1018 rmc->AddResource("zh", nullptr, nullptr);
1019
1020 RState state;
1021 // error case
1022 // not found case
1023 std::vector<std::string> outValue;
1024 state = rm->GetStringArrayByName(g_nonExistName, outValue);
1025 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
1026 }
1027
1028
1029 /*
1030 * @tc.name: ResourceManagerGetPluralStringByIdTest001
1031 * @tc.desc: Test GetPluralStringById function, file case.
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest001, TestSize.Level1)
1035 {
1036 rmc->AddResource("en", nullptr, "US");
1037
1038 int quantity = 1;
1039 rmc->TestPluralStringById(quantity, "%d apple", false);
1040
1041 quantity = 101;
1042 rmc->TestPluralStringById(quantity, "%d apples", false);
1043 }
1044
1045 /*
1046 * @tc.name: ResourceManagerGetPluralStringByIdTest002
1047 * @tc.desc: Test GetPluralStringById function, file case.
1048 * @tc.type: FUNC
1049 */
1050 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest002, TestSize.Level1)
1051 {
1052 rmc->AddResource("zh", nullptr, "CN");
1053
1054 int quantity = 1;
1055 rmc->TestPluralStringById(quantity, "%d apples", false);
1056
1057 quantity = 101;
1058 rmc->TestPluralStringById(quantity, "%d apples", false);
1059 }
1060
1061 /*
1062 * @tc.name: ResourceManagerGetPluralStringByIdTest003
1063 * @tc.desc: Test GetPluralStringById function, file case.
1064 * @tc.type: FUNC
1065 */
1066 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest003, TestSize.Level1)
1067 {
1068 rmc->AddResource("pl", nullptr, "PL");
1069
1070 int quantity = 1;
1071 rmc->TestPluralStringById(quantity, "1 jabłko");
1072
1073 quantity = 2;
1074 rmc->TestPluralStringById(quantity, "%d jabłka");
1075
1076 quantity = 23;
1077 rmc->TestPluralStringById(quantity, "%d jabłka");
1078
1079 quantity = 12;
1080 rmc->TestPluralStringById(quantity, "%d jabłek");
1081 }
1082
1083 /*
1084 * @tc.name: ResourceManagerGetPluralStringByIdTest004
1085 * @tc.desc: Test GetPluralStringById function, file case.
1086 * @tc.type: FUNC
1087 */
1088 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest004, TestSize.Level1)
1089 {
1090 rmc->AddResource("ar", nullptr, "SA");
1091
1092 int quantity = 0;
1093 rmc->TestPluralStringById(quantity, "zero-0");
1094 quantity = 1;
1095 rmc->TestPluralStringById(quantity, "one-1");
1096 quantity = 2;
1097 rmc->TestPluralStringById(quantity, "two-2");
1098 quantity = 5;
1099 rmc->TestPluralStringById(quantity, "few-%d");
1100 quantity = 12;
1101 rmc->TestPluralStringById(quantity, "many-%d");
1102 quantity = 500;
1103 rmc->TestPluralStringById(quantity, "other-%d");
1104 }
1105
1106 /*
1107 * @tc.name: ResourceManagerGetPluralStringByIdTest005
1108 * @tc.desc: Test GetPluralStringById function, file case.
1109 * @tc.type: FUNC
1110 */
1111 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest005, TestSize.Level1)
1112 {
1113 rmc->AddResource("ar", nullptr, "SA");
1114
1115 RState state;
1116 std::string outValue;
1117 state = rm->GetPluralStringById(NON_EXIST_ID, 1, outValue);
1118 ASSERT_EQ(NOT_FOUND, state);
1119 }
1120
1121 /*
1122 * @tc.name: ResourceManagerGetPluralStringByNameTest001
1123 * @tc.desc: Test GetPluralStringByName function, file case.
1124 * @tc.type: FUNC
1125 */
1126 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameTest001, TestSize.Level1)
1127 {
1128 rmc->AddResource("en", nullptr, "US");
1129
1130 int quantity = 1;
1131 rmc->TestPluralStringByName(quantity, "%d apple", false);
1132
1133 quantity = 101;
1134 rmc->TestPluralStringByName(quantity, "%d apples", false);
1135 }
1136
1137 /*
1138 * @tc.name: ResourceManagerGetPluralStringByNameTest002
1139 * @tc.desc: Test GetPluralStringByName function, file case.
1140 * @tc.type: FUNC
1141 */
1142 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameTest002, TestSize.Level1)
1143 {
1144 rmc->AddResource("ar", nullptr, "SA");
1145
1146 RState state;
1147 std::string outValue;
1148 state = rm->GetPluralStringByName(g_nonExistName, 1, outValue);
1149 ASSERT_EQ(NOT_FOUND, state);
1150 }
1151
1152 /*
1153 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest001
1154 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1155 * @tc.type: FUNC
1156 */
1157 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest001, TestSize.Level1)
1158 {
1159 rmc->AddResource("zh", nullptr, "CN");
1160
1161 int quantity = 1;
1162 rmc->TestPluralStringById(quantity, "1 apples", true);
1163
1164 quantity = 101;
1165 rmc->TestPluralStringById(quantity, "101 apples", true);
1166 }
1167
1168 /*
1169 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest002
1170 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1171 * @tc.type: FUNC
1172 */
1173 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest002, TestSize.Level1)
1174 {
1175 rmc->AddResource("ar", nullptr, "SA");
1176
1177 RState state;
1178 std::string outValue;
1179 state = rm->GetPluralStringByIdFormat(outValue, NON_EXIST_ID, 1, 1);
1180 ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
1181 }
1182
1183 /*
1184 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest003
1185 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1186 * @tc.type: FUNC
1187 */
1188 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest003, TestSize.Level1)
1189 {
1190 rmc->AddResource("ar", nullptr, "SA");
1191
1192 RState state;
1193 std::string outValue;
1194 int id = rmc->GetResId("app_name", ResType::STRING);
1195 state = rm->GetPluralStringByIdFormat(outValue, id, 1, 1);
1196 ASSERT_EQ(ERROR_CODE_RES_NOT_FOUND_BY_ID, state);
1197 }
1198
1199 /*
1200 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest004
1201 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1202 * @tc.type: FUNC
1203 */
1204 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest004, TestSize.Level1)
1205 {
1206 rmc->AddColorModeResource(DEVICE_PHONE, LIGHT, SCREEN_DENSITY_LDPI / BASE_DPI);
1207
1208 RState state;
1209 std::string outValue;
1210 int quantity = 1;
1211 int id = rmc->GetResId("eat_apple1", ResType::PLURALS);
1212 state = rm->GetPluralStringByIdFormat(outValue, id, quantity);
1213 ASSERT_EQ(ERROR_CODE_RES_REF_TOO_MUCH, state);
1214 }
1215
1216 /*
1217 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest001
1218 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
1219 * @tc.type: FUNC
1220 */
1221 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest001, TestSize.Level1)
1222 {
1223 rmc->AddResource("zh", nullptr, "CN");
1224
1225 int quantity = 1;
1226 rmc->TestPluralStringByName(quantity, "1 apples", true);
1227
1228 quantity = 101;
1229 rmc->TestPluralStringByName(quantity, "101 apples", true);
1230 }
1231
1232 /*
1233 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest002
1234 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
1235 * @tc.type: FUNC
1236 */
1237 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest002, TestSize.Level1)
1238 {
1239 rmc->AddResource("ar", nullptr, "SA");
1240
1241 RState state;
1242 std::string outValue;
1243 state = rm->GetPluralStringByNameFormat(outValue, g_nonExistName, 1, 1);
1244 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
1245 }
1246
1247 /*
1248 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest003
1249 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
1250 * @tc.type: FUNC
1251 */
1252 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest003, TestSize.Level1)
1253 {
1254 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_overlayResFilePath).c_str());
1255 ASSERT_TRUE(ret);
1256 std::string outValue;
1257 const char* eatApple = "eat_apple";
1258 RState state = rm->GetPluralStringByNameFormat(outValue, eatApple, 1, 1);
1259 ASSERT_EQ(ERROR_CODE_RES_NOT_FOUND_BY_NAME, state);
1260 }
1261
1262 /*
1263 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest004
1264 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
1265 * @tc.type: FUNC
1266 */
1267 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest004, TestSize.Level1)
1268 {
1269 rmc->AddColorModeResource(DEVICE_PHONE, LIGHT, SCREEN_DENSITY_LDPI / BASE_DPI);
1270
1271 std::string outValue;
1272 const char* eatApple = "eat_apple1";
1273 int quantity = 1;
1274 RState state = rm->GetPluralStringByNameFormat(outValue, eatApple, quantity);
1275 ASSERT_EQ(ERROR_CODE_RES_REF_TOO_MUCH, state);
1276 }
1277
1278 /*
1279 * @tc.name: ResourceManagerGetStringByNameForMccMncTest001
1280 * @tc.desc: Test GetStringByName
1281 * @tc.type: FUNC
1282 */
1283 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest001, TestSize.Level1)
1284 {
1285 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1286 ASSERT_TRUE(ret);
1287 auto rc = CreateResConfig();
1288 if (rc == nullptr) {
1289 EXPECT_TRUE(false);
1290 return;
1291 }
1292 rc->SetLocaleInfo("en", nullptr, nullptr);
1293 rc->SetDeviceType(DEVICE_TV);
1294 rc->SetColorMode(LIGHT);
1295 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1296 rm->UpdateResConfig(*rc);
1297 delete rc;
1298
1299 RState rState;
1300 std::string outValue;
1301 rState = rm->GetStringByName("mccmnc_str", outValue);
1302 ASSERT_EQ(SUCCESS, rState);
1303 ASSERT_EQ("str_en_us_light", outValue);
1304 }
1305
1306 /*
1307 * @tc.name: ResourceManagerGetStringByNameForMccMncTest002
1308 * @tc.desc: Test GetStringByName
1309 * @tc.type: FUNC
1310 */
1311 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest002, TestSize.Level1)
1312 {
1313 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1314 ASSERT_TRUE(ret);
1315 auto rc = CreateResConfig();
1316 if (rc == nullptr) {
1317 EXPECT_TRUE(false);
1318 return;
1319 }
1320 rc->SetLocaleInfo("zh", nullptr, nullptr);
1321 rc->SetDeviceType(DEVICE_TV);
1322 rc->SetColorMode(LIGHT);
1323 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1324 rm->UpdateResConfig(*rc);
1325 delete rc;
1326
1327 RState rState;
1328 std::string outValue;
1329 rState = rm->GetStringByName("mccmnc_str", outValue);
1330 ASSERT_EQ(SUCCESS, rState);
1331 ASSERT_EQ("str_zh_cn", outValue);
1332 }
1333
1334 /*
1335 * @tc.name: ResourceManagerGetStringByNameForMccMncTest003
1336 * @tc.desc: Test GetStringByName
1337 * @tc.type: FUNC
1338 */
1339 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest003, TestSize.Level1)
1340 {
1341 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1342 ASSERT_TRUE(ret);
1343 auto rc = CreateResConfig();
1344 if (rc == nullptr) {
1345 EXPECT_TRUE(false);
1346 return;
1347 }
1348 rc->SetLocaleInfo("en", nullptr, nullptr);
1349 rc->SetMcc(460);
1350 rc->SetMnc(101);
1351 rc->SetDeviceType(DEVICE_TV);
1352 rc->SetColorMode(LIGHT);
1353 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1354
1355 rm->UpdateResConfig(*rc);
1356 delete rc;
1357
1358 RState rState;
1359 std::string outValue;
1360 rState = rm->GetStringByName("mccmnc_str", outValue);
1361 ASSERT_EQ(SUCCESS, rState);
1362 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
1363 }
1364
1365 /*
1366 * @tc.name: ResourceManagerGetStringByNameForMccMncTest004
1367 * @tc.desc: Test GetStringByName
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest004, TestSize.Level1)
1371 {
1372 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1373 ASSERT_TRUE(ret);
1374
1375 auto rc = CreateResConfig();
1376 if (rc == nullptr) {
1377 EXPECT_TRUE(false);
1378 return;
1379 }
1380 rc->SetLocaleInfo("en", nullptr, nullptr);
1381 rc->SetMcc(460);
1382 rc->SetMnc(1);
1383 rc->SetDeviceType(DEVICE_TV);
1384 rc->SetColorMode(LIGHT);
1385 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1386 rm->UpdateResConfig(*rc);
1387 delete rc;
1388
1389 RState rState;
1390 std::string outValue;
1391 rState = rm->GetStringByName("mccmnc_str", outValue);
1392 ASSERT_EQ(SUCCESS, rState);
1393 ASSERT_EQ("str_mcc460_mnc001_en", outValue);
1394 }
1395
1396 /*
1397 * @tc.name: ResourceManagerGetStringByNameForMccMncTest005
1398 * @tc.desc: Test GetStringByName
1399 * @tc.type: FUNC
1400 */
1401 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest005, TestSize.Level1)
1402 {
1403 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1404 ASSERT_TRUE(ret);
1405
1406 auto rc = CreateResConfig();
1407 if (rc == nullptr) {
1408 EXPECT_TRUE(false);
1409 return;
1410 }
1411 rc->SetLocaleInfo("en", nullptr, nullptr);
1412 rc->SetMcc(460);
1413 rc->SetMnc(10);
1414 rc->SetDeviceType(DEVICE_TV);
1415 rc->SetColorMode(LIGHT);
1416 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1417 rm->UpdateResConfig(*rc);
1418 delete rc;
1419
1420 RState rState;
1421 std::string outValue;
1422 rState = rm->GetStringByName("mccmnc_str", outValue);
1423 ASSERT_EQ(SUCCESS, rState);
1424 ASSERT_EQ("str_mcc460_mnc010_en", outValue);
1425 }
1426
1427 /*
1428 * @tc.name: ResourceManagerGetStringByNameForMccMncTest006
1429 * @tc.desc: Test GetStringByName
1430 * @tc.type: FUNC
1431 */
1432 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest006, TestSize.Level1)
1433 {
1434 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1435 ASSERT_TRUE(ret);
1436
1437 auto rc = CreateResConfig();
1438 if (rc == nullptr) {
1439 EXPECT_TRUE(false);
1440 return;
1441 }
1442 rc->SetLocaleInfo("en", nullptr, nullptr);
1443 rc->SetMcc(460);
1444 rc->SetMnc(101);
1445 rc->SetDeviceType(DEVICE_TV);
1446 rc->SetColorMode(LIGHT);
1447 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1448 rm->UpdateResConfig(*rc);
1449 delete rc;
1450
1451 RState rState;
1452 std::string outValue;
1453 rState = rm->GetStringByName("mccmnc_str", outValue);
1454 ASSERT_EQ(SUCCESS, rState);
1455 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
1456 }
1457
1458 /*
1459 * @tc.name: ResourceManagerGetStringByNameForMccMncTest007
1460 * @tc.desc: Test GetStringByName
1461 * @tc.type: FUNC
1462 */
1463 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest007, TestSize.Level1)
1464 {
1465 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1466 ASSERT_TRUE(ret);
1467
1468 auto rc = CreateResConfig();
1469 if (rc == nullptr) {
1470 EXPECT_TRUE(false);
1471 return;
1472 }
1473 rc->SetLocaleInfo("zh", nullptr, nullptr);
1474 rc->SetMcc(460);
1475 rc->SetMnc(101);
1476 rc->SetDeviceType(DEVICE_TV);
1477 rc->SetColorMode(LIGHT);
1478 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1479 rm->UpdateResConfig(*rc);
1480 delete rc;
1481
1482 RState rState;
1483 std::string outValue;
1484 rState = rm->GetStringByName("mccmnc_str", outValue);
1485 ASSERT_EQ(SUCCESS, rState);
1486 ASSERT_EQ("str_mcc460_mnc101_zh", outValue);
1487 }
1488
1489 /*
1490 * @tc.name: ResourceManagerGetStringByNameForMccMncTest008
1491 * @tc.desc: Test GetStringByName
1492 * @tc.type: FUNC
1493 */
1494 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest008, TestSize.Level1)
1495 {
1496 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1497 ASSERT_TRUE(ret);
1498 auto rc = CreateResConfig();
1499 if (rc == nullptr) {
1500 EXPECT_TRUE(false);
1501 return;
1502 }
1503 rc->SetLocaleInfo("en", nullptr, nullptr);
1504 rc->SetDeviceType(DEVICE_PHONE);
1505 rc->SetColorMode(LIGHT);
1506 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1507 rm->UpdateResConfig(*rc);
1508 delete rc;
1509
1510 RState rState;
1511 std::string outValue;
1512 rState = rm->GetStringByName("mccmnc_str", outValue);
1513 ASSERT_EQ(SUCCESS, rState);
1514 ASSERT_EQ("str_en_us_phone", outValue);
1515 }
1516
1517 /*
1518 * @tc.name: ResourceManagerGetStringByNameForMccMncTest009
1519 * @tc.desc: Test GetStringByName
1520 * @tc.type: FUNC
1521 */
1522 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest009, TestSize.Level1)
1523 {
1524 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1525 ASSERT_TRUE(ret);
1526 auto rc = CreateResConfig();
1527 if (rc == nullptr) {
1528 EXPECT_TRUE(false);
1529 return;
1530 }
1531 rc->SetLocaleInfo("en", nullptr, nullptr);
1532 rc->SetColorMode(LIGHT);
1533 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1534 rm->UpdateResConfig(*rc);
1535 delete rc;
1536
1537 RState rState;
1538 std::string outValue;
1539 rState = rm->GetStringByName("mccmnc_str", outValue);
1540 ASSERT_EQ(SUCCESS, rState);
1541 ASSERT_EQ("str_en_us_light", outValue);
1542 }
1543
1544 /*
1545 * @tc.name: ResourceManagerGetStringByNameForMccMncTest010
1546 * @tc.desc: Test GetStringByName
1547 * @tc.type: FUNC
1548 */
1549 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest010, TestSize.Level1)
1550 {
1551 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1552 ASSERT_TRUE(ret);
1553 auto rc = CreateResConfig();
1554 if (rc == nullptr) {
1555 EXPECT_TRUE(false);
1556 return;
1557 }
1558 rc->SetLocaleInfo("en", nullptr, nullptr);
1559 rc->SetMcc(460);
1560 rc->SetMnc(101);
1561 rc->SetDeviceType(DEVICE_PHONE);
1562 rc->SetColorMode(LIGHT);
1563 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1564 rm->UpdateResConfig(*rc);
1565 delete rc;
1566
1567 RState rState;
1568 std::string outValue;
1569 rState = rm->GetStringByName("mccmnc_str", outValue);
1570 ASSERT_EQ(SUCCESS, rState);
1571 ASSERT_EQ("str_mcc460_mnc101_en_phone", outValue);
1572 }
1573
1574 /*
1575 * @tc.name: ResourceManagerGetStringByNameForMccMncTest011
1576 * @tc.desc: Test GetStringByName
1577 * @tc.type: FUNC
1578 */
1579 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest011, TestSize.Level1)
1580 {
1581 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1582 ASSERT_TRUE(ret);
1583 auto rc = CreateResConfig();
1584 if (rc == nullptr) {
1585 EXPECT_TRUE(false);
1586 return;
1587 }
1588 rc->SetLocaleInfo("en", nullptr, nullptr);
1589 rc->SetMcc(460);
1590 rc->SetMnc(101);
1591 rc->SetColorMode(LIGHT);
1592 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1593 rm->UpdateResConfig(*rc);
1594 delete rc;
1595
1596 RState rState;
1597 std::string outValue;
1598 rState = rm->GetStringByName("mccmnc_str", outValue);
1599 ASSERT_EQ(SUCCESS, rState);
1600 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
1601 }
1602
1603 /*
1604 * @tc.name: ResourceManagerGetStringByNameForMccMncTest012
1605 * @tc.desc: Test GetStringByName
1606 * @tc.type: FUNC
1607 */
1608 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest012, TestSize.Level1)
1609 {
1610 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1611 ASSERT_TRUE(ret);
1612 auto rc = CreateResConfig();
1613 if (rc == nullptr) {
1614 EXPECT_TRUE(false);
1615 return;
1616 }
1617 rc->SetLocaleInfo("en", nullptr, nullptr);
1618 rc->SetDeviceType(DEVICE_TV);
1619 rc->SetColorMode(DARK);
1620 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1621 rm->UpdateResConfig(*rc);
1622 delete rc;
1623
1624 RState rState;
1625 std::string outValue;
1626 rState = rm->GetStringByName("mccmnc_str", outValue);
1627 ASSERT_EQ(SUCCESS, rState);
1628 ASSERT_EQ("str_en_us_dark", outValue);
1629 }
1630
1631 /*
1632 * @tc.name: ResourceManagerGetStringByNameForMccMncTest013
1633 * @tc.desc: Test GetStringByName
1634 * @tc.type: FUNC
1635 */
1636 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest013, TestSize.Level1)
1637 {
1638 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1639 ASSERT_TRUE(ret);
1640 auto rc = CreateResConfig();
1641 if (rc == nullptr) {
1642 EXPECT_TRUE(false);
1643 return;
1644 }
1645 rc->SetLocaleInfo("en", nullptr, nullptr);
1646 rc->SetDeviceType(DEVICE_TV);
1647 rc->SetColorMode(LIGHT);
1648 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1649 rm->UpdateResConfig(*rc);
1650 delete rc;
1651
1652 RState rState;
1653 std::string outValue;
1654 rState = rm->GetStringByName("mccmnc_str", outValue);
1655 ASSERT_EQ(SUCCESS, rState);
1656 ASSERT_EQ("str_en_us_light", outValue);
1657 }
1658
1659 /*
1660 * @tc.name: ResourceManagerGetStringByNameForMccMncTest014
1661 * @tc.desc: Test GetStringByName
1662 * @tc.type: FUNC
1663 */
1664 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest014, TestSize.Level1)
1665 {
1666 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1667 ASSERT_TRUE(ret);
1668 auto rc = CreateResConfig();
1669 if (rc == nullptr) {
1670 EXPECT_TRUE(false);
1671 return;
1672 }
1673 rc->SetLocaleInfo("en", nullptr, nullptr);
1674 rc->SetMcc(460);
1675 rc->SetMnc(101);
1676 rc->SetDeviceType(DEVICE_TV);
1677 rc->SetColorMode(DARK);
1678 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1679 rm->UpdateResConfig(*rc);
1680 delete rc;
1681
1682 RState rState;
1683 std::string outValue;
1684 rState = rm->GetStringByName("mccmnc_str", outValue);
1685 ASSERT_EQ(SUCCESS, rState);
1686 ASSERT_EQ("str_mcc460_mnc101_en_dark", outValue);
1687 }
1688
1689 /*
1690 * @tc.name: ResourceManagerGetStringByNameForMccMncTest015
1691 * @tc.desc: Test GetStringByName
1692 * @tc.type: FUNC
1693 */
1694 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest015, TestSize.Level1)
1695 {
1696 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1697 ASSERT_TRUE(ret);
1698 auto rc = CreateResConfig();
1699 if (rc == nullptr) {
1700 EXPECT_TRUE(false);
1701 return;
1702 }
1703 rc->SetLocaleInfo("en", nullptr, nullptr);
1704 rc->SetMcc(460);
1705 rc->SetMnc(101);
1706 rc->SetDeviceType(DEVICE_TV);
1707 rc->SetColorMode(LIGHT);
1708 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
1709 rm->UpdateResConfig(*rc);
1710 delete rc;
1711
1712 RState rState;
1713 std::string outValue;
1714 rState = rm->GetStringByName("mccmnc_str", outValue);
1715 ASSERT_EQ(SUCCESS, rState);
1716 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
1717 }
1718
1719 /*
1720 * @tc.name: ResourceManagerGetStringByNameForMccMncTest016
1721 * @tc.desc: Test GetStringByName
1722 * @tc.type: FUNC
1723 */
1724 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest016, TestSize.Level1)
1725 {
1726 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1727 ASSERT_TRUE(ret);
1728 auto rc = CreateResConfig();
1729 if (rc == nullptr) {
1730 EXPECT_TRUE(false);
1731 return;
1732 }
1733 rc->SetLocaleInfo("en", nullptr, nullptr);
1734 rc->SetDeviceType(DEVICE_TV);
1735 rc->SetColorMode(LIGHT);
1736 rc->SetScreenDensity(SCREEN_DENSITY_LDPI / BASE_DPI);
1737 rm->UpdateResConfig(*rc);
1738 delete rc;
1739
1740 RState rState;
1741 std::string outValue;
1742 rState = rm->GetStringByName("mccmnc_str", outValue);
1743 ASSERT_EQ(SUCCESS, rState);
1744 ASSERT_EQ("str_en_us_light", outValue);
1745 }
1746
1747 /*
1748 * @tc.name: ResourceManagerGetStringByNameForMccMncTest017
1749 * @tc.desc: Test GetStringByName
1750 * @tc.type: FUNC
1751 */
1752 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest017, TestSize.Level1)
1753 {
1754 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1755 ASSERT_TRUE(ret);
1756 auto rc = CreateResConfig();
1757 if (rc == nullptr) {
1758 EXPECT_TRUE(false);
1759 return;
1760 }
1761 rc->SetLocaleInfo("en", nullptr, nullptr);
1762 rc->SetDeviceType(DEVICE_TV);
1763 rc->SetColorMode(LIGHT);
1764 rc->SetScreenDensity(SCREEN_DENSITY_XLDPI / BASE_DPI);
1765 rm->UpdateResConfig(*rc);
1766 delete rc;
1767
1768 RState rState;
1769 std::string outValue;
1770 rState = rm->GetStringByName("mccmnc_str", outValue);
1771 ASSERT_EQ(SUCCESS, rState);
1772 ASSERT_EQ("str_en_us_light", outValue);
1773 }
1774
1775 /*
1776 * @tc.name: ResourceManagerGetStringByNameForMccMncTest018
1777 * @tc.desc: Test GetStringByName
1778 * @tc.type: FUNC
1779 */
1780 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest018, TestSize.Level1)
1781 {
1782 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1783 ASSERT_TRUE(ret);
1784 auto rc = CreateResConfig();
1785 if (rc == nullptr) {
1786 EXPECT_TRUE(false);
1787 return;
1788 }
1789 rc->SetLocaleInfo("en", nullptr, nullptr);
1790 rc->SetMcc(460);
1791 rc->SetMnc(101);
1792 rc->SetDeviceType(DEVICE_TV);
1793 rc->SetColorMode(LIGHT);
1794 rc->SetScreenDensity(SCREEN_DENSITY_LDPI / BASE_DPI);
1795 rm->UpdateResConfig(*rc);
1796 delete rc;
1797
1798 RState rState;
1799 std::string outValue;
1800 rState = rm->GetStringByName("mccmnc_str", outValue);
1801 ASSERT_EQ(SUCCESS, rState);
1802 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
1803 }
1804
1805 /*
1806 * @tc.name: ResourceManagerGetStringByNameForMccMncTest019
1807 * @tc.desc: Test GetStringByName
1808 * @tc.type: FUNC
1809 */
1810 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest019, TestSize.Level1)
1811 {
1812 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1813 ASSERT_TRUE(ret);
1814 auto rc = CreateResConfig();
1815 if (rc == nullptr) {
1816 EXPECT_TRUE(false);
1817 return;
1818 }
1819 rc->SetLocaleInfo("en", nullptr, nullptr);
1820 rc->SetMcc(460);
1821 rc->SetMnc(101);
1822 rc->SetDeviceType(DEVICE_TV);
1823 rc->SetColorMode(LIGHT);
1824 rc->SetScreenDensity(SCREEN_DENSITY_XLDPI / BASE_DPI);
1825 rm->UpdateResConfig(*rc);
1826 delete rc;
1827
1828 RState rState;
1829 std::string outValue;
1830 rState = rm->GetStringByName("mccmnc_str", outValue);
1831 ASSERT_EQ(SUCCESS, rState);
1832 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
1833 }
1834
1835 /*
1836 * @tc.name: ResourceManagerGetStringByNameForMccMncTest020
1837 * @tc.desc: Test GetStringByName
1838 * @tc.type: FUNC
1839 */
1840 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest020, TestSize.Level1)
1841 {
1842 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1843 ASSERT_TRUE(ret);
1844 auto rc = CreateResConfig();
1845 if (rc == nullptr) {
1846 EXPECT_TRUE(false);
1847 return;
1848 }
1849 rc->SetLocaleInfo("en", nullptr, nullptr);
1850 rc->SetMcc(460);
1851 rc->SetMnc(101);
1852 rc->SetDeviceType(DEVICE_PHONE);
1853 rc->SetColorMode(DARK);
1854 rc->SetScreenDensity(SCREEN_DENSITY_XLDPI / BASE_DPI);
1855 rm->UpdateResConfig(*rc);
1856 delete rc;
1857
1858 RState rState;
1859 std::string outValue;
1860 rState = rm->GetStringByName("mccmnc_str", outValue);
1861 ASSERT_EQ(SUCCESS, rState);
1862 ASSERT_EQ("str_mcc460_mnc101_en_phone_dark_xldpi", outValue);
1863 }
1864 }
1865