1 /*
2 * Copyright (c) 2023-2025 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: ResourceManagerGetStringByIdTest006
150 * @tc.desc: Test GetStringById function
151 * @tc.type: FUNC
152 */
153 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest006, TestSize.Level1)
154 {
155 rmc->AddHapResource("zh", nullptr, "CN");
156 int id = rmc->GetResId("icon1", ResType::MEDIA);
157 EXPECT_TRUE(id > 0);
158 std::string outValue;
159 RState state = rm->GetStringById(id, outValue);
160 EXPECT_EQ(state, ERROR_CODE_RES_NOT_FOUND_BY_ID);
161 }
162
163 /*
164 * @tc.name: ResourceManagerGetStringByIdTest007
165 * @tc.desc: Test GetStringById function
166 * @tc.type: FUNC
167 */
168 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest007, TestSize.Level1)
169 {
170 rmc->AddResource("en", nullptr, nullptr);
171
172 std::vector<std::string> overlayPaths;
173 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
174 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
175 ASSERT_TRUE(ret);
176 rmc->TestStringById("ohos_app_name", "SystemOverlay");
177 }
178
179 /*
180 * @tc.name: ResourceManagerGetStringByIdTest008
181 * @tc.desc: Test GetStringById function
182 * @tc.type: FUNC
183 */
184 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest008, TestSize.Level1)
185 {
186 rmc->AddResource("zh", nullptr, nullptr);
187
188 std::vector<std::string> overlayPaths;
189 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
190 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
191 ASSERT_TRUE(ret);
192 rmc->TestStringById("ohos_lab_answer_call", "overlay接听电话");
193 }
194
195 /*
196 * @tc.name: ResourceManagerGetStringByIdTest009
197 * @tc.desc: Test GetStringById function
198 * @tc.type: FUNC
199 */
200 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest009, TestSize.Level1)
201 {
202 rmc->AddResource("en", nullptr, nullptr);
203
204 std::vector<std::string> overlayPaths;
205 overlayPaths.push_back(FormatFullPath(g_newOverlayResFilePath).c_str());
206 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
207 ASSERT_TRUE(ret);
208 rmc->TestStringById("ohos_app_name", "SystemOverlay");
209 }
210
211 /*
212 * @tc.name: ResourceManagerGetStringByIdTest010
213 * @tc.desc: Test GetStringById function
214 * @tc.type: FUNC
215 */
216 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByIdTest010, TestSize.Level1)
217 {
218 rmc->AddResource("zh", nullptr, nullptr);
219
220 std::vector<std::string> overlayPaths;
221 overlayPaths.push_back(FormatFullPath(g_newOverlayResFilePath).c_str());
222 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
223 ASSERT_TRUE(ret);
224 rmc->TestStringById("ohos_lab_answer_call", "overlay接听电话");
225 }
226
227 /*
228 * @tc.name: ResourceManagerGetStringByNameTest001
229 * @tc.desc: Test GetStringByName function
230 * @tc.type: FUNC
231 */
232 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest001, TestSize.Level1)
233 {
234 rmc->AddResource("en", nullptr, nullptr);
235
236 rmc->TestStringByName("app_name", "App Name");
237
238 rmc->TestStringByName("copyright_text", "XXXXXX All rights reserved. ©2011-2019");
239
240 rmc->TestStringByName("string_ref", "XXXXXX All rights reserved. ©2011-2019");
241
242 rmc->TestStringByName("string_ref2", "XXXXXX All rights reserved. ©2011-2019");
243 }
244
245 /*
246 * @tc.name: ResourceManagerGetStringByNameTest002
247 * @tc.desc: Test GetStringByName function
248 * @tc.type: FUNC
249 */
250 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest002, TestSize.Level1)
251 {
252 rmc->AddResource("zh", nullptr, nullptr);
253
254 rmc->TestStringByName("app_name", "应用名称");
255
256 rmc->TestStringByName("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利");
257
258 rmc->TestStringByName("string_ref", "$aaaaa");
259
260 rmc->TestStringByName("string_ref2", "$aaaaa");
261 }
262
263 /*
264 * @tc.name: ResourceManagerGetStringByNameTest003
265 * @tc.desc: Test GetStringByName function
266 * @tc.type: FUNC
267 */
268 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest003, TestSize.Level1)
269 {
270 rmc->AddResource("zh", nullptr, nullptr);
271
272 std::string outValue;
273 RState state = rm->GetStringByName(g_nonExistName, outValue);
274 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
275 }
276
277 /*
278 * @tc.name: ResourceManagerGetStringByNameTest004
279 * @tc.desc: Test GetStringByName function
280 * @tc.type: FUNC
281 */
282 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest004, TestSize.Level1)
283 {
284 auto rc = CreateResConfig();
285 if (rc == nullptr) {
286 ASSERT_TRUE(false);
287 }
288 rc->SetLocaleInfo("zh", nullptr, "CN");
289 rc->SetDirection(DIRECTION_VERTICAL);
290 rm->UpdateResConfig(*rc);
291 delete rc;
292 std::vector<std::string> overlayPaths;
293 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
294 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
295 ASSERT_TRUE(ret);
296 std::string outValue;
297 ((ResourceManagerImpl *)rm)->GetStringByName("ohos_desc_camera", outValue);
298 ASSERT_EQ(outValue, "允许应用拍摄照片和视频。");
299 }
300
301 /*
302 * @tc.name: ResourceManagerGetStringByNameTest005
303 * @tc.desc: Test GetStringByName function
304 * @tc.type: FUNC
305 */
306 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest005, TestSize.Level1)
307 {
308 rmc->AddResource("en", nullptr, nullptr);
309 std::vector<std::string> overlayPaths;
310 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
311 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_resFilePath).c_str(), overlayPaths);
312 ASSERT_TRUE(ret);
313 std::string outValue;
314 ((ResourceManagerImpl *)rm)->GetStringByName("hello", outValue);
315 ASSERT_EQ(outValue, "Helloooo");
316 }
317
318 /*
319 * @tc.name: ResourceManagerGetStringByNameTest006
320 * @tc.desc: Test GetStringByName function
321 * @tc.type: FUNC
322 */
323 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest006, TestSize.Level1)
324 {
325 auto rc = CreateResConfig();
326 if (rc == nullptr) {
327 ASSERT_TRUE(false);
328 }
329 rc->SetLocaleInfo("zh", nullptr, "CN");
330 rc->SetDirection(DIRECTION_VERTICAL);
331 rm->UpdateResConfig(*rc);
332 delete rc;
333 std::vector<std::string> overlayPaths;
334 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
335 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
336 ASSERT_TRUE(ret);
337 std::string outValue;
338 ((ResourceManagerImpl *)rm)->GetStringByName("ohos_desc_camera", outValue);
339 ASSERT_EQ(outValue, "允许应用拍摄照片和视频。");
340 }
341
342 /*
343 * @tc.name: ResourceManagerGetStringByNameTest007
344 * @tc.desc: Test GetStringByName function
345 * @tc.type: FUNC
346 */
347 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest007, TestSize.Level1)
348 {
349 rmc->AddResource("en", nullptr, nullptr);
350 std::vector<std::string> overlayPaths;
351 overlayPaths.push_back(FormatFullPath(g_overlayResFilePath).c_str());
352 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
353 ASSERT_TRUE(ret);
354 std::string outValue;
355 ((ResourceManagerImpl *)rm)->GetStringByName("hello", outValue);
356 ASSERT_EQ(outValue, "Helloooo");
357 }
358
359 /*
360 * @tc.name: ResourceManagerGetStringByNameTest008
361 * @tc.desc: Test GetStringByName function
362 * @tc.type: FUNC
363 */
364 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest008, TestSize.Level1)
365 {
366 auto rc = CreateResConfig();
367 if (rc == nullptr) {
368 ASSERT_TRUE(false);
369 }
370 rc->SetLocaleInfo("zh", nullptr, "CN");
371 rc->SetDirection(DIRECTION_VERTICAL);
372 rm->UpdateResConfig(*rc);
373 delete rc;
374 std::vector<std::string> overlayPaths;
375 overlayPaths.push_back(FormatFullPath(g_newOverlayResFilePath).c_str());
376 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
377 ASSERT_TRUE(ret);
378 std::string outValue;
379 ((ResourceManagerImpl *)rm)->GetStringByName("ohos_desc_camera", outValue);
380 ASSERT_EQ(outValue, "允许应用拍摄照片和视频。");
381 }
382
383 /*
384 * @tc.name: ResourceManagerGetStringByNameTest009
385 * @tc.desc: Test GetStringByName function
386 * @tc.type: FUNC
387 */
388 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameTest009, TestSize.Level1)
389 {
390 rmc->AddResource("en", nullptr, nullptr);
391 std::vector<std::string> overlayPaths;
392 overlayPaths.push_back(FormatFullPath(g_newOverlayResFilePath).c_str());
393 bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_newResFilePath).c_str(), overlayPaths);
394 ASSERT_TRUE(ret);
395 std::string outValue;
396 ((ResourceManagerImpl *)rm)->GetStringByName("hello", outValue);
397 ASSERT_EQ(outValue, "Helloooo");
398 }
399
400 /*
401 * @tc.name: ResourceManagerGetStringFormatByIdTest001
402 * @tc.desc: Test GetStringFormatById function
403 * @tc.type: FUNC
404 */
405 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest001, TestSize.Level1)
406 {
407 rmc->AddResource("zh", nullptr, nullptr);
408
409 const char *name = "app_name";
410 int id = rmc->GetResId(name, ResType::STRING);
411 ASSERT_TRUE(id > 0);
412 std::string outValue;
413 RState state = rm->GetStringFormatById(outValue, id, 101);
414 ASSERT_EQ(SUCCESS, state);
415 ASSERT_EQ("应用名称", outValue);
416 }
417
418 /*
419 * @tc.name: ResourceManagerGetStringFormatByIdTest002
420 * @tc.desc: Test GetStringFormatById function
421 * @tc.type: FUNC
422 */
423 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest002, TestSize.Level1)
424 {
425 rmc->AddResource("zh", nullptr, nullptr);
426
427 std::string outValue;
428 RState state = rm->GetStringFormatById(outValue, NON_EXIST_ID, 101);
429 ASSERT_EQ(NOT_FOUND, state);
430 }
431
432 /*
433 * @tc.name: ResourceManagerGetStringFormatByIdTest003
434 * @tc.desc: Test GetStringFormatById function
435 * @tc.type: FUNC
436 */
437 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest003, TestSize.Level1)
438 {
439 const char *name = "test_string0";
440 const char *cmp = "向前兼容";
441 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
442 rmc->TestGetStringFormatById(name, jsParams, cmp);
443 }
444
445 /*
446 * @tc.name: ResourceManagerGetStringFormatByIdTest004
447 * @tc.desc: Test GetStringFormatById function
448 * @tc.type: FUNC
449 */
450 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest004, TestSize.Level1)
451 {
452 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
453 std::string outValue;
454 RState state = rm->GetStringFormatById(NON_EXIST_ID, outValue, jsParams);
455 ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
456 }
457
458 /*
459 * @tc.name: ResourceManagerGetStringFormatByIdTest005
460 * @tc.desc: Test GetStringFormatById function
461 * @tc.type: FUNC
462 */
463 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest005, TestSize.Level1)
464 {
465 const char *name = "test_string1";
466 const char *cmp = "%10%d%%d%%";
467 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
468 {{ResourceManager::NapiValueType::NAPI_NUMBER, "10"}};
469 rmc->TestGetStringFormatByName(name, jsParams, cmp);
470 }
471
472 /*
473 * @tc.name: ResourceManagerGetStringFormatByIdTest006
474 * @tc.desc: Test GetStringFormatById function
475 * @tc.type: FUNC
476 */
477 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest006, TestSize.Level1)
478 {
479 const char *name = "test_string2";
480 const char *cmp = "-9.999 你好";
481 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
482 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"},
483 {ResourceManager::NapiValueType::NAPI_STRING, " 你好"}};
484 rmc->TestGetStringFormatByName(name, jsParams, cmp);
485 }
486
487 /*
488 * @tc.name: ResourceManagerGetStringFormatByIdTest007
489 * @tc.desc: Test GetStringFormatById function
490 * @tc.type: FUNC
491 */
492 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest007, TestSize.Level1)
493 {
494 const char *name = "test_string2";
495 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
496 ASSERT_TRUE(ret);
497 int id = rmc->GetResId(name, ResType::STRING);
498 ASSERT_TRUE(id > 0);
499 std::string outValue;
500 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
501 {{ResourceManager::NapiValueType::NAPI_STRING, " 你好"},
502 {ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
503 RState state = rm->GetStringFormatById(id, outValue, jsParams);
504 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
505 }
506
507 /*
508 * @tc.name: ResourceManagerGetStringFormatByIdTest008
509 * @tc.desc: Test GetStringFormatById function
510 * @tc.type: FUNC
511 */
512 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest008, TestSize.Level1)
513 {
514 const char *name = "test_string2";
515 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
516 ASSERT_TRUE(ret);
517 int id = rmc->GetResId(name, ResType::STRING);
518 ASSERT_TRUE(id > 0);
519 std::string outValue;
520 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
521 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
522 RState state = rm->GetStringFormatById(id, outValue, jsParams);
523 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
524 }
525
526 /*
527 * @tc.name: ResourceManagerGetStringFormatByIdTest009
528 * @tc.desc: Test GetStringFormatById function
529 * @tc.type: FUNC
530 */
531 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest009, TestSize.Level1)
532 {
533 const char *name = "test_string9";
534 const char *cmp = "%d-%d1$d";
535 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
536 rmc->TestGetStringFormatById(name, jsParams, cmp);
537 }
538
539 /*
540 * @tc.name: ResourceManagerGetStringFormatByIdTest010
541 * @tc.desc: Test GetStringFormatById function
542 * @tc.type: FUNC
543 */
544 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest010, TestSize.Level1)
545 {
546 const char *name = "test_string10";
547 const char *cmp = "%d%%%";
548 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
549 rmc->TestGetStringFormatById(name, jsParams, cmp);
550 }
551
552 /*
553 * @tc.name: ResourceManagerGetStringFormatByIdTest011
554 * @tc.desc: Test GetStringFormatById function
555 * @tc.type: FUNC
556 */
557 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest011, TestSize.Level1)
558 {
559 const char *name = "test_string11";
560 const char *cmp = "-7";
561 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
562 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-7.5"}};
563 rmc->TestGetStringFormatById(name, jsParams, cmp);
564 }
565
566 /*
567 * @tc.name: ResourceManagerGetStringFormatByIdTest012
568 * @tc.desc: Test GetStringFormatById function
569 * @tc.type: FUNC
570 */
571 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest012, TestSize.Level1)
572 {
573 const char *name = "test_string12";
574 const char *cmp = "2-1===6.100000-5.000000===你好,world===%hh%%%";
575 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
576 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1.000000"},
577 {ResourceManager::NapiValueType::NAPI_NUMBER, "2.100000"},
578 {ResourceManager::NapiValueType::NAPI_NUMBER, "5.000000"},
579 {ResourceManager::NapiValueType::NAPI_NUMBER, "6.100000"},
580 {ResourceManager::NapiValueType::NAPI_STRING, "world"},
581 {ResourceManager::NapiValueType::NAPI_STRING, "你好,"}};
582 rmc->TestGetStringFormatById(name, jsParams, cmp);
583 }
584
585 /*
586 * @tc.name: ResourceManagerGetStringFormatByIdTest013
587 * @tc.desc: Test GetStringFormatById function
588 * @tc.type: FUNC
589 */
590 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest013, TestSize.Level1)
591 {
592 const char *name = "test_string13";
593 const char *cmp = "11";
594 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
595 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
596 rmc->TestGetStringFormatById(name, jsParams, cmp);
597 }
598
599 /*
600 * @tc.name: ResourceManagerGetStringFormatByIdTest014
601 * @tc.desc: Test GetStringFormatById function
602 * @tc.type: FUNC
603 */
604 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest014, TestSize.Level1)
605 {
606 const char *name = "test_string14";
607 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
608 ASSERT_TRUE(ret);
609 int id = rmc->GetResId(name, ResType::STRING);
610 ASSERT_TRUE(id > 0);
611 std::string outValue;
612 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
613 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
614 RState state = rm->GetStringFormatById(id, outValue, jsParams);
615 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
616 }
617
618 /*
619 * @tc.name: ResourceManagerGetStringFormatByIdTest015
620 * @tc.desc: Test GetStringFormatById function
621 * @tc.type: FUNC
622 */
623 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest015, TestSize.Level1)
624 {
625 const char *name = "test_string15";
626 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
627 ASSERT_TRUE(ret);
628 int id = rmc->GetResId(name, ResType::STRING);
629 ASSERT_TRUE(id > 0);
630 std::string outValue;
631 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
632 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
633 RState state = rm->GetStringFormatById(id, outValue, jsParams);
634 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
635 }
636
637 /*
638 * @tc.name: ResourceManagerGetStringFormatByIdTest016
639 * @tc.desc: Test GetStringFormatById function
640 * @tc.type: FUNC
641 */
642 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest016, TestSize.Level1)
643 {
644 const char *name = "test_string16";
645 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
646 ASSERT_TRUE(ret);
647 int id = rmc->GetResId(name, ResType::STRING);
648 ASSERT_TRUE(id > 0);
649 std::string outValue;
650 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
651 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
652 RState state = rm->GetStringFormatById(id, outValue, jsParams);
653 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
654 }
655
656 /*
657 * @tc.name: ResourceManagerGetStringFormatByIdTest017
658 * @tc.desc: Test GetStringFormatById function
659 * @tc.type: FUNC
660 */
661 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest017, TestSize.Level1)
662 {
663 const char *name = "test_string17";
664 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
665 ASSERT_TRUE(ret);
666 int id = rmc->GetResId(name, ResType::STRING);
667 ASSERT_TRUE(id > 0);
668 std::string outValue;
669 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
670 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
671 RState state = rm->GetStringFormatById(id, outValue, jsParams);
672 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
673 }
674
675 /*
676 * @tc.name: ResourceManagerGetStringFormatByIdTest018
677 * @tc.desc: Test GetStringFormatById function
678 * @tc.type: FUNC
679 */
680 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest018, TestSize.Level1)
681 {
682 const char *name = "test_string18";
683 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
684 ASSERT_TRUE(ret);
685 int id = rmc->GetResId(name, ResType::STRING);
686 ASSERT_TRUE(id > 0);
687 std::string outValue;
688 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
689 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
690 RState state = rm->GetStringFormatById(id, outValue, jsParams);
691 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
692 }
693
694 /*
695 * @tc.name: ResourceManagerGetStringFormatByIdTest019
696 * @tc.desc: Test GetStringFormatById function
697 * @tc.type: FUNC
698 */
699 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest019, TestSize.Level1)
700 {
701 const char *name = "test_string19";
702 const char *cmp = "11";
703 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
704 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
705 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"}};
706 rmc->TestGetStringFormatById(name, jsParams, cmp);
707 }
708
709 /*
710 * @tc.name: ResourceManagerGetStringFormatByIdTest020
711 * @tc.desc: Test GetStringFormatById function
712 * @tc.type: FUNC
713 */
714 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest020, TestSize.Level1)
715 {
716 const char *name = "test_string20";
717 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
718 ASSERT_TRUE(ret);
719 int id = rmc->GetResId(name, ResType::STRING);
720 ASSERT_TRUE(id > 0);
721 std::string outValue;
722 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
723 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
724 RState state = rm->GetStringFormatById(id, outValue, jsParams);
725 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
726 }
727
728 /*
729 * @tc.name: ResourceManagerGetStringFormatByIdTest021
730 * @tc.desc: Test GetStringFormatById function
731 * @tc.type: FUNC
732 */
733 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest021, TestSize.Level1)
734 {
735 const char *name = "test_string21";
736 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
737 ASSERT_TRUE(ret);
738 int id = rmc->GetResId(name, ResType::STRING);
739 ASSERT_TRUE(id > 0);
740 std::string outValue;
741 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
742 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
743 RState state = rm->GetStringFormatById(id, outValue, jsParams);
744 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
745 }
746
747 /*
748 * @tc.name: ResourceManagerGetStringFormatByIdTest022
749 * @tc.desc: Test GetStringFormatById function
750 * @tc.type: FUNC
751 */
752 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest022, TestSize.Level1)
753 {
754 const char *name = "test_string22";
755 const char *cmp = "112";
756 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
757 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
758 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"},
759 {ResourceManager::NapiValueType::NAPI_NUMBER, "3"}};
760 rmc->TestGetStringFormatById(name, jsParams, cmp);
761 }
762
763 /*
764 * @tc.name: ResourceManagerGetStringFormatByIdTest023
765 * @tc.desc: Test GetStringFormatById function
766 * @tc.type: FUNC
767 */
768 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest023, TestSize.Level1)
769 {
770 const char *name = "test_string22";
771 const char *cmp = "112";
772 rmc->TestGetStringFormatByIdWithVaArgs(name, cmp, 1, 2, 3);
773 }
774
775 /*
776 * @tc.name: ResourceManagerGetStringFormatByIdTest024
777 * @tc.desc: Test GetStringFormatById function
778 * @tc.type: FUNC
779 */
780 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest024, TestSize.Level1)
781 {
782 const char *name = "test_string2";
783 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
784 ASSERT_TRUE(ret);
785 int id = rmc->GetResId(name, ResType::STRING);
786 ASSERT_TRUE(id > 0);
787 std::string outValue;
788 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
789 {{ResourceManager::NapiValueType::NAPI_STRING, " 你好"},
790 {ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
791 RState state = rm->GetStringFormatById(id, outValue, jsParams);
792 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
793 }
794
795 /*
796 * @tc.name: ResourceManagerGetStringFormatByIdTest025
797 * @tc.desc: Test GetStringFormatById function
798 * @tc.type: FUNC
799 */
800 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest025, TestSize.Level1)
801 {
802 const char *name = "test_string2";
803 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
804 ASSERT_TRUE(ret);
805 int id = rmc->GetResId(name, ResType::STRING);
806 ASSERT_TRUE(id > 0);
807 std::string outValue;
808 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
809 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
810 RState state = rm->GetStringFormatById(id, outValue, jsParams);
811 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
812 }
813
814 /*
815 * @tc.name: ResourceManagerGetStringFormatByIdTest026
816 * @tc.desc: Test GetStringFormatById function
817 * @tc.type: FUNC
818 */
819 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest026, TestSize.Level1)
820 {
821 const char *name = "test_string14";
822 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
823 ASSERT_TRUE(ret);
824 int id = rmc->GetResId(name, ResType::STRING);
825 ASSERT_TRUE(id > 0);
826 std::string outValue;
827 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
828 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
829 RState state = rm->GetStringFormatById(id, outValue, jsParams);
830 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
831 }
832
833 /*
834 * @tc.name: ResourceManagerGetStringFormatByIdTest027
835 * @tc.desc: Test GetStringFormatById function
836 * @tc.type: FUNC
837 */
838 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest027, TestSize.Level1)
839 {
840 const char *name = "test_string15";
841 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
842 ASSERT_TRUE(ret);
843 int id = rmc->GetResId(name, ResType::STRING);
844 ASSERT_TRUE(id > 0);
845 std::string outValue;
846 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
847 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
848 RState state = rm->GetStringFormatById(id, outValue, jsParams);
849 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
850 }
851
852 /*
853 * @tc.name: ResourceManagerGetStringFormatByIdTest028
854 * @tc.desc: Test GetStringFormatById function
855 * @tc.type: FUNC
856 */
857 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest028, TestSize.Level1)
858 {
859 const char *name = "test_string16";
860 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
861 ASSERT_TRUE(ret);
862 int id = rmc->GetResId(name, ResType::STRING);
863 ASSERT_TRUE(id > 0);
864 std::string outValue;
865 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
866 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
867 RState state = rm->GetStringFormatById(id, outValue, jsParams);
868 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
869 }
870
871 /*
872 * @tc.name: ResourceManagerGetStringFormatByIdTest029
873 * @tc.desc: Test GetStringFormatById function
874 * @tc.type: FUNC
875 */
876 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest029, TestSize.Level1)
877 {
878 const char *name = "test_string17";
879 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
880 ASSERT_TRUE(ret);
881 int id = rmc->GetResId(name, ResType::STRING);
882 ASSERT_TRUE(id > 0);
883 std::string outValue;
884 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
885 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
886 RState state = rm->GetStringFormatById(id, outValue, jsParams);
887 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
888 }
889
890 /*
891 * @tc.name: ResourceManagerGetStringFormatByIdTest030
892 * @tc.desc: Test GetStringFormatById function
893 * @tc.type: FUNC
894 */
895 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest030, TestSize.Level1)
896 {
897 const char *name = "test_string18";
898 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
899 ASSERT_TRUE(ret);
900 int id = rmc->GetResId(name, ResType::STRING);
901 ASSERT_TRUE(id > 0);
902 std::string outValue;
903 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
904 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
905 RState state = rm->GetStringFormatById(id, outValue, jsParams);
906 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
907 }
908
909 /*
910 * @tc.name: ResourceManagerGetStringFormatByIdTest031
911 * @tc.desc: Test GetStringFormatById function
912 * @tc.type: FUNC
913 */
914 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest031, TestSize.Level1)
915 {
916 const char *name = "test_string20";
917 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
918 ASSERT_TRUE(ret);
919 int id = rmc->GetResId(name, ResType::STRING);
920 ASSERT_TRUE(id > 0);
921 std::string outValue;
922 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
923 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
924 RState state = rm->GetStringFormatById(id, outValue, jsParams);
925 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
926 }
927
928 /*
929 * @tc.name: ResourceManagerGetStringFormatByIdTest032
930 * @tc.desc: Test GetStringFormatById function
931 * @tc.type: FUNC
932 */
933 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByIdTest032, TestSize.Level1)
934 {
935 const char *name = "test_string21";
936 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
937 ASSERT_TRUE(ret);
938 int id = rmc->GetResId(name, ResType::STRING);
939 ASSERT_TRUE(id > 0);
940 std::string outValue;
941 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
942 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
943 RState state = rm->GetStringFormatById(id, outValue, jsParams);
944 ASSERT_EQ(ERROR_CODE_RES_ID_FORMAT_ERROR, state);
945 }
946
947 /*
948 * @tc.name: ResourceManagerGetStringFormatByNameTest001
949 * @tc.desc: Test GetStringFormatByName function
950 * @tc.type: FUNC
951 */
952 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest001, TestSize.Level1)
953 {
954 rmc->AddResource("zh", nullptr, nullptr);
955
956 const char *name = "app_name";
957 std::string outValue;
958 RState state = rm->GetStringFormatByName(outValue, name, 101);
959 ASSERT_EQ(SUCCESS, state);
960 ASSERT_EQ("应用名称", outValue);
961 }
962
963 /*
964 * @tc.name: ResourceManagerGetStringFormatByNameTest002
965 * @tc.desc: Test GetStringFormatByName function
966 * @tc.type: FUNC
967 */
968 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest002, TestSize.Level1)
969 {
970 rmc->AddResource("zh", nullptr, nullptr);
971
972 std::string outValue;
973 RState state = rm->GetStringFormatByName(outValue, g_nonExistName, 101);
974 ASSERT_EQ(NOT_FOUND, state);
975 }
976
977 /*
978 * @tc.name: ResourceManagerGetStringFormatByNameTest003
979 * @tc.desc: Test GetStringFormatByName function
980 * @tc.type: FUNC
981 */
982 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest003, TestSize.Level1)
983 {
984 const char *name = "test_string0";
985 const char *cmp = "向前兼容";
986 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
987 rmc->TestGetStringFormatByName(name, jsParams, cmp);
988 }
989
990 /*
991 * @tc.name: ResourceManagerGetStringFormatByNameTest004
992 * @tc.desc: Test GetStringFormatByName function
993 * @tc.type: FUNC
994 */
995 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest004, TestSize.Level1)
996 {
997 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
998 std::string outValue;
999 RState state = rm->GetStringFormatByName("NON_EXIST_NAME", outValue, jsParams);
1000 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
1001 }
1002
1003 /*
1004 * @tc.name: ResourceManagerGetStringFormatByNameTest005
1005 * @tc.desc: Test GetStringFormatByName function
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest005, TestSize.Level1)
1009 {
1010 const char *name = "test_string3";
1011 const char *cmp = "abc12.3abc%%\"abc\"abc";
1012 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1013 {{ResourceManager::NapiValueType::NAPI_NUMBER, "12.3"},
1014 {ResourceManager::NapiValueType::NAPI_STRING, "\"abc\""}};
1015 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1016 }
1017
1018 /*
1019 * @tc.name: ResourceManagerGetStringFormatByNameTest006
1020 * @tc.desc: Test GetStringFormatByName function
1021 * @tc.type: FUNC
1022 */
1023 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest006, TestSize.Level1)
1024 {
1025 const char *name = "test_string4";
1026 const char *cmp = "%a-320a%%";
1027 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1028 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-320"}};
1029 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1030 }
1031
1032 /*
1033 * @tc.name: ResourceManagerGetStringFormatByNameTest007
1034 * @tc.desc: Test GetStringFormatByName function
1035 * @tc.type: FUNC
1036 */
1037 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest007, TestSize.Level1)
1038 {
1039 const char *name = "test_string2";
1040 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1041 ASSERT_TRUE(ret);
1042 std::string outValue;
1043 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1044 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"},
1045 {ResourceManager::NapiValueType::NAPI_NUMBER, "abc"}};
1046 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1047 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1048 }
1049
1050 /*
1051 * @tc.name: ResourceManagerGetStringFormatByNameTest008
1052 * @tc.desc: Test GetStringFormatByName function
1053 * @tc.type: FUNC
1054 */
1055 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest008, TestSize.Level1)
1056 {
1057 const char *name = "test_string2";
1058 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1059 ASSERT_TRUE(ret);
1060 std::string outValue;
1061 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1062 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
1063 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1064 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1065 }
1066
1067 /*
1068 * @tc.name: ResourceManagerGetStringFormatByNameTest009
1069 * @tc.desc: Test GetStringFormatById function
1070 * @tc.type: FUNC
1071 */
1072 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest009, TestSize.Level1)
1073 {
1074 const char *name = "test_string9";
1075 const char *cmp = "%d-%d1$d";
1076 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
1077 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1078 }
1079
1080 /*
1081 * @tc.name: ResourceManagerGetStringFormatByNameTest010
1082 * @tc.desc: Test GetStringFormatById function
1083 * @tc.type: FUNC
1084 */
1085 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest010, TestSize.Level1)
1086 {
1087 const char *name = "test_string10";
1088 const char *cmp = "%d%%%";
1089 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
1090 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1091 }
1092
1093 /*
1094 * @tc.name: ResourceManagerGetStringFormatByNameTest011
1095 * @tc.desc: Test GetStringFormatById function
1096 * @tc.type: FUNC
1097 */
1098 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest011, TestSize.Level1)
1099 {
1100 const char *name = "test_string11";
1101 const char *cmp = "-7";
1102 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1103 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-7.5"}};
1104 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1105 }
1106
1107 /*
1108 * @tc.name: ResourceManagerGetStringFormatByNameTest012
1109 * @tc.desc: Test GetStringFormatById function
1110 * @tc.type: FUNC
1111 */
1112 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest012, TestSize.Level1)
1113 {
1114 const char *name = "test_string12";
1115 const char *cmp = "2-1===4.100000-3.000000===你好,world===%hh%%%";
1116 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1117 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1.000000"},
1118 {ResourceManager::NapiValueType::NAPI_NUMBER, "2.100000"},
1119 {ResourceManager::NapiValueType::NAPI_NUMBER, "3.000000"},
1120 {ResourceManager::NapiValueType::NAPI_NUMBER, "4.100000"},
1121 {ResourceManager::NapiValueType::NAPI_STRING, "world"},
1122 {ResourceManager::NapiValueType::NAPI_STRING, "你好,"}};
1123 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1124 }
1125
1126 /*
1127 * @tc.name: ResourceManagerGetStringFormatByNameTest013
1128 * @tc.desc: Test GetStringFormatById function
1129 * @tc.type: FUNC
1130 */
1131 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest013, TestSize.Level1)
1132 {
1133 const char *name = "test_string13";
1134 const char *cmp = "11";
1135 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1136 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1137 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1138 }
1139
1140 /*
1141 * @tc.name: ResourceManagerGetStringFormatByNameTest014
1142 * @tc.desc: Test GetStringFormatById function
1143 * @tc.type: FUNC
1144 */
1145 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest014, TestSize.Level1)
1146 {
1147 const char *name = "test_string14";
1148 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1149 ASSERT_TRUE(ret);
1150 std::string outValue;
1151 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1152 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1153 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1154 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1155 }
1156
1157 /*
1158 * @tc.name: ResourceManagerGetStringFormatByNameTest015
1159 * @tc.desc: Test GetStringFormatById function
1160 * @tc.type: FUNC
1161 */
1162 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest015, TestSize.Level1)
1163 {
1164 const char *name = "test_string15";
1165 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1166 ASSERT_TRUE(ret);
1167 std::string outValue;
1168 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1169 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
1170 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1171 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1172 }
1173
1174 /*
1175 * @tc.name: ResourceManagerGetStringFormatByNameTest016
1176 * @tc.desc: Test GetStringFormatById function
1177 * @tc.type: FUNC
1178 */
1179 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest016, TestSize.Level1)
1180 {
1181 const char *name = "test_string16";
1182 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1183 ASSERT_TRUE(ret);
1184 std::string outValue;
1185 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1186 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
1187 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1188 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1189 }
1190
1191 /*
1192 * @tc.name: ResourceManagerGetStringFormatByNameTest017
1193 * @tc.desc: Test GetStringFormatById function
1194 * @tc.type: FUNC
1195 */
1196 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest017, TestSize.Level1)
1197 {
1198 const char *name = "test_string17";
1199 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1200 ASSERT_TRUE(ret);
1201 std::string outValue;
1202 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1203 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1204 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1205 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1206 }
1207
1208 /*
1209 * @tc.name: ResourceManagerGetStringFormatByNameTest018
1210 * @tc.desc: Test GetStringFormatById function
1211 * @tc.type: FUNC
1212 */
1213 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest018, TestSize.Level1)
1214 {
1215 const char *name = "test_string18";
1216 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1217 ASSERT_TRUE(ret);
1218 std::string outValue;
1219 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1220 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1221 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1222 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1223 }
1224
1225 /*
1226 * @tc.name: ResourceManagerGetStringFormatByNameTest019
1227 * @tc.desc: Test GetStringFormatById function
1228 * @tc.type: FUNC
1229 */
1230 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest019, TestSize.Level1)
1231 {
1232 const char *name = "test_string19";
1233 const char *cmp = "11";
1234 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1235 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
1236 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"}};
1237 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1238 }
1239
1240 /*
1241 * @tc.name: ResourceManagerGetStringFormatByNameTest020
1242 * @tc.desc: Test GetStringFormatById function
1243 * @tc.type: FUNC
1244 */
1245 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest020, TestSize.Level1)
1246 {
1247 const char *name = "test_string20";
1248 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1249 ASSERT_TRUE(ret);
1250 std::string outValue;
1251 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1252 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1253 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1254 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1255 }
1256
1257 /*
1258 * @tc.name: ResourceManagerGetStringFormatByNameTest021
1259 * @tc.desc: Test GetStringFormatById function
1260 * @tc.type: FUNC
1261 */
1262 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest021, TestSize.Level1)
1263 {
1264 const char *name = "test_string21";
1265 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
1266 ASSERT_TRUE(ret);
1267 std::string outValue;
1268 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1269 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1270 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1271 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1272 }
1273
1274 /*
1275 * @tc.name: ResourceManagerGetStringFormatByNameTest022
1276 * @tc.desc: Test GetStringFormatById function
1277 * @tc.type: FUNC
1278 */
1279 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest022, TestSize.Level1)
1280 {
1281 const char *name = "test_string22";
1282 const char *cmp = "112";
1283 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1284 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"},
1285 {ResourceManager::NapiValueType::NAPI_NUMBER, "2"},
1286 {ResourceManager::NapiValueType::NAPI_NUMBER, "3"}};
1287 rmc->TestGetStringFormatByName(name, jsParams, cmp);
1288 }
1289
1290 /*
1291 * @tc.name: ResourceManagerGetStringFormatByNameTest023
1292 * @tc.desc: Test GetStringFormatByName with va_list function
1293 * @tc.type: FUNC
1294 */
1295 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest023, TestSize.Level1)
1296 {
1297 const char *name = "test_string22";
1298 const char *cmp = "112";
1299 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, 1, 2, 3);
1300 }
1301
1302 /*
1303 * @tc.name: ResourceManagerGetStringFormatByNameTest024
1304 * @tc.desc: Test GetStringFormatByName with va_list function
1305 * @tc.type: FUNC
1306 */
1307 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest024, TestSize.Level1)
1308 {
1309 const char *name = "test_string1";
1310 const char *cmp = "%10%d%%d%%";
1311 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, 10);
1312 }
1313
1314 /*
1315 * @tc.name: ResourceManagerGetStringFormatByNameTest025
1316 * @tc.desc: Test GetStringFormatByName with va_list function
1317 * @tc.type: FUNC
1318 */
1319 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest025, TestSize.Level1)
1320 {
1321 const char *name = "test_string2";
1322 const char *cmp = "-9.999000 你好";
1323 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, -9.999, " 你好");
1324 }
1325
1326 /*
1327 * @tc.name: ResourceManagerGetStringFormatByNameTest026
1328 * @tc.desc: Test GetStringFormatByName with va_list function
1329 * @tc.type: FUNC
1330 */
1331 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest026, TestSize.Level1)
1332 {
1333 const char *name = "test_string13";
1334 const char *cmp = "11";
1335 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, 1);
1336 }
1337
1338 /*
1339 * @tc.name: ResourceManagerGetStringFormatByNameTest027
1340 * @tc.desc: Test GetStringFormatByName with va_list function
1341 * @tc.type: FUNC
1342 */
1343 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest027, TestSize.Level1)
1344 {
1345 const char *name = "test_string15";
1346 const char *cmp = "100";
1347 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, 100);
1348 }
1349
1350 /*
1351 * @tc.name: ResourceManagerGetStringFormatByNameTest028
1352 * @tc.desc: Test GetStringFormatByName with va_list function
1353 * @tc.type: FUNC
1354 */
1355 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest028, TestSize.Level1)
1356 {
1357 const char *name = "test_string16";
1358 const char *cmp = "1.230000";
1359 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, 1.23);
1360 }
1361
1362 /*
1363 * @tc.name: ResourceManagerGetStringFormatByNameTest029
1364 * @tc.desc: Test GetStringFormatByName with va_list function
1365 * @tc.type: FUNC
1366 */
1367 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest029, TestSize.Level1)
1368 {
1369 const char *name = "test_string17";
1370 const char *cmp = "Hello World";
1371 rmc->TestGetStringFormatByNameWithVaArgs(name, cmp, "Hello World");
1372 }
1373
1374 /*
1375 * @tc.name: ResourceManagerGetStringFormatByNameTest030
1376 * @tc.desc: Test GetStringFormatByName function
1377 * @tc.type: FUNC
1378 */
1379 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest030, TestSize.Level1)
1380 {
1381 const char *name = "test_string2";
1382 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1383 ASSERT_TRUE(ret);
1384 std::string outValue;
1385 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1386 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"},
1387 {ResourceManager::NapiValueType::NAPI_NUMBER, "abc"}};
1388 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1389 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1390 }
1391
1392 /*
1393 * @tc.name: ResourceManagerGetStringFormatByNameTest031
1394 * @tc.desc: Test GetStringFormatByName function
1395 * @tc.type: FUNC
1396 */
1397 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest031, TestSize.Level1)
1398 {
1399 const char *name = "test_string2";
1400 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1401 ASSERT_TRUE(ret);
1402 std::string outValue;
1403 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1404 {{ResourceManager::NapiValueType::NAPI_NUMBER, "-9.999"}};
1405 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1406 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1407 }
1408
1409 /*
1410 * @tc.name: ResourceManagerGetStringFormatByNameTest032
1411 * @tc.desc: Test GetStringFormatById function
1412 * @tc.type: FUNC
1413 */
1414 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest032, TestSize.Level1)
1415 {
1416 const char *name = "test_string14";
1417 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1418 ASSERT_TRUE(ret);
1419 std::string outValue;
1420 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1421 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1422 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1423 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1424 }
1425
1426 /*
1427 * @tc.name: ResourceManagerGetStringFormatByNameTest033
1428 * @tc.desc: Test GetStringFormatById function
1429 * @tc.type: FUNC
1430 */
1431 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest033, TestSize.Level1)
1432 {
1433 const char *name = "test_string15";
1434 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1435 ASSERT_TRUE(ret);
1436 std::string outValue;
1437 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1438 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
1439 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1440 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1441 }
1442
1443 /*
1444 * @tc.name: ResourceManagerGetStringFormatByNameTest034
1445 * @tc.desc: Test GetStringFormatById function
1446 * @tc.type: FUNC
1447 */
1448 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest034, TestSize.Level1)
1449 {
1450 const char *name = "test_string16";
1451 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1452 ASSERT_TRUE(ret);
1453 std::string outValue;
1454 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1455 {{ResourceManager::NapiValueType::NAPI_STRING, "hhh"}};
1456 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1457 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1458 }
1459
1460 /*
1461 * @tc.name: ResourceManagerGetStringFormatByNameTest035
1462 * @tc.desc: Test GetStringFormatById function
1463 * @tc.type: FUNC
1464 */
1465 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest035, TestSize.Level1)
1466 {
1467 const char *name = "test_string17";
1468 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1469 ASSERT_TRUE(ret);
1470 std::string outValue;
1471 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1472 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1473 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1474 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1475 }
1476
1477 /*
1478 * @tc.name: ResourceManagerGetStringFormatByNameTest036
1479 * @tc.desc: Test GetStringFormatById function
1480 * @tc.type: FUNC
1481 */
1482 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest036, TestSize.Level1)
1483 {
1484 const char *name = "test_string18";
1485 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1486 ASSERT_TRUE(ret);
1487 std::string outValue;
1488 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1489 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1490 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1491 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1492 }
1493
1494 /*
1495 * @tc.name: ResourceManagerGetStringFormatByNameTest037
1496 * @tc.desc: Test GetStringFormatById function
1497 * @tc.type: FUNC
1498 */
1499 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest037, TestSize.Level1)
1500 {
1501 const char *name = "test_string20";
1502 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1503 ASSERT_TRUE(ret);
1504 std::string outValue;
1505 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1506 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1507 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1508 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1509 }
1510
1511 /*
1512 * @tc.name: ResourceManagerGetStringFormatByNameTest038
1513 * @tc.desc: Test GetStringFormatById function
1514 * @tc.type: FUNC
1515 */
1516 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringFormatByNameTest038, TestSize.Level1)
1517 {
1518 const char *name = "test_string21";
1519 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
1520 ASSERT_TRUE(ret);
1521 std::string outValue;
1522 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams =
1523 {{ResourceManager::NapiValueType::NAPI_NUMBER, "1"}};
1524 RState state = rm->GetStringFormatByName(name, outValue, jsParams);
1525 ASSERT_EQ(ERROR_CODE_RES_NAME_FORMAT_ERROR, state);
1526 }
1527
1528 /*
1529 * @tc.name: ResourceManagerGetStringArrayByIdTest001
1530 * @tc.desc: Test GetStringArrayById function, file case.
1531 * @tc.type: FUNC
1532 */
1533 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByIdTest001, TestSize.Level1)
1534 {
1535 rmc->AddResource("zh", nullptr, nullptr);
1536
1537 rmc->TestGetStringArrayById("size");
1538 }
1539
1540 /*
1541 * @tc.name: ResourceManagerGetStringArrayByIdTest002
1542 * @tc.desc: Test GetStringArrayById function, file case.
1543 * @tc.type: FUNC
1544 */
1545 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByIdTest002, TestSize.Level1)
1546 {
1547 rmc->AddResource("zh", nullptr, nullptr);
1548
1549 RState state;
1550 // error case
1551 // not found case
1552 std::vector<std::string> outValue;
1553 state = rm->GetStringArrayById(NON_EXIST_ID, outValue);
1554 ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
1555 }
1556
1557 /*
1558 * @tc.name: ResourceManagerGetStringArrayByIdTest003
1559 * @tc.desc: Test GetStringArrayById function, file case.
1560 * @tc.type: FUNC
1561 */
1562 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByIdTest003, TestSize.Level1)
1563 {
1564 rmc->AddResource("zh", nullptr, "CN");
1565 int id = rmc->GetResId("app_name", ResType::STRING);
1566 ASSERT_TRUE(id > 0);
1567 std::vector<std::string> outValue;
1568 RState state = rm->GetStringArrayById(id, outValue);
1569 ASSERT_EQ(ERROR_CODE_RES_NOT_FOUND_BY_ID, state);
1570 }
1571
1572 /*
1573 * @tc.name: ResourceManagerGetStringArrayByNameTest001
1574 * @tc.desc: Test GetStringArrayByName function, file case.
1575 * @tc.type: FUNC
1576 */
1577 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByNameTest001, TestSize.Level1)
1578 {
1579 rmc->AddResource("zh", nullptr, nullptr);
1580
1581 rmc->TestGetStringArrayByName("size");
1582 }
1583
1584 /*
1585 * @tc.name: ResourceManagerGetStringArrayByNameTest002
1586 * @tc.desc: Test GetStringArrayByName function, file case.
1587 * @tc.type: FUNC
1588 */
1589 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringArrayByNameTest002, TestSize.Level1)
1590 {
1591 rmc->AddResource("zh", nullptr, nullptr);
1592
1593 RState state;
1594 // error case
1595 // not found case
1596 std::vector<std::string> outValue;
1597 state = rm->GetStringArrayByName(g_nonExistName, outValue);
1598 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
1599 }
1600
1601
1602 /*
1603 * @tc.name: ResourceManagerGetPluralStringByIdTest001
1604 * @tc.desc: Test GetPluralStringById function, file case.
1605 * @tc.type: FUNC
1606 */
1607 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest001, TestSize.Level1)
1608 {
1609 rmc->AddResource("en", nullptr, "US");
1610
1611 int quantity = 1;
1612 rmc->TestPluralStringById(quantity, "%d apple", false);
1613
1614 quantity = 101;
1615 rmc->TestPluralStringById(quantity, "%d apples", false);
1616 }
1617
1618 /*
1619 * @tc.name: ResourceManagerGetPluralStringByIdTest002
1620 * @tc.desc: Test GetPluralStringById function, file case.
1621 * @tc.type: FUNC
1622 */
1623 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest002, TestSize.Level1)
1624 {
1625 rmc->AddResource("zh", nullptr, "CN");
1626
1627 int quantity = 1;
1628 rmc->TestPluralStringById(quantity, "%d apples", false);
1629
1630 quantity = 101;
1631 rmc->TestPluralStringById(quantity, "%d apples", false);
1632 }
1633
1634 /*
1635 * @tc.name: ResourceManagerGetPluralStringByIdTest003
1636 * @tc.desc: Test GetPluralStringById function, file case.
1637 * @tc.type: FUNC
1638 */
1639 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest003, TestSize.Level1)
1640 {
1641 rmc->AddResource("pl", nullptr, "PL");
1642
1643 int quantity = 1;
1644 rmc->TestPluralStringById(quantity, "1 jabłko");
1645
1646 quantity = 2;
1647 rmc->TestPluralStringById(quantity, "%d jabłka");
1648
1649 quantity = 23;
1650 rmc->TestPluralStringById(quantity, "%d jabłka");
1651
1652 quantity = 12;
1653 rmc->TestPluralStringById(quantity, "%d jabłek");
1654 }
1655
1656 /*
1657 * @tc.name: ResourceManagerGetPluralStringByIdTest004
1658 * @tc.desc: Test GetPluralStringById function, file case.
1659 * @tc.type: FUNC
1660 */
1661 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest004, TestSize.Level1)
1662 {
1663 rmc->AddResource("ar", nullptr, "SA");
1664
1665 int quantity = 0;
1666 rmc->TestPluralStringById(quantity, "zero-0");
1667 quantity = 1;
1668 rmc->TestPluralStringById(quantity, "one-1");
1669 quantity = 2;
1670 rmc->TestPluralStringById(quantity, "two-2");
1671 quantity = 5;
1672 rmc->TestPluralStringById(quantity, "few-%d");
1673 quantity = 12;
1674 rmc->TestPluralStringById(quantity, "many-%d");
1675 quantity = 500;
1676 rmc->TestPluralStringById(quantity, "other-%d");
1677 }
1678
1679 /*
1680 * @tc.name: ResourceManagerGetPluralStringByIdTest005
1681 * @tc.desc: Test GetPluralStringById function, file case.
1682 * @tc.type: FUNC
1683 */
1684 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdTest005, TestSize.Level1)
1685 {
1686 rmc->AddResource("ar", nullptr, "SA");
1687
1688 RState state;
1689 std::string outValue;
1690 state = rm->GetPluralStringById(NON_EXIST_ID, 1, outValue);
1691 ASSERT_EQ(NOT_FOUND, state);
1692 }
1693
1694 /*
1695 * @tc.name: ResourceManagerGetPluralStringByNameTest001
1696 * @tc.desc: Test GetPluralStringByName function, file case.
1697 * @tc.type: FUNC
1698 */
1699 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameTest001, TestSize.Level1)
1700 {
1701 rmc->AddResource("en", nullptr, "US");
1702
1703 int quantity = 1;
1704 rmc->TestPluralStringByName(quantity, "%d apple", false);
1705
1706 quantity = 101;
1707 rmc->TestPluralStringByName(quantity, "%d apples", false);
1708 }
1709
1710 /*
1711 * @tc.name: ResourceManagerGetPluralStringByNameTest002
1712 * @tc.desc: Test GetPluralStringByName function, file case.
1713 * @tc.type: FUNC
1714 */
1715 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameTest002, TestSize.Level1)
1716 {
1717 rmc->AddResource("ar", nullptr, "SA");
1718
1719 RState state;
1720 std::string outValue;
1721 state = rm->GetPluralStringByName(g_nonExistName, 1, outValue);
1722 ASSERT_EQ(NOT_FOUND, state);
1723 }
1724
1725 /*
1726 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest001
1727 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1728 * @tc.type: FUNC
1729 */
1730 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest001, TestSize.Level1)
1731 {
1732 rmc->AddResource("zh", nullptr, "CN");
1733
1734 int quantity = 1;
1735 rmc->TestPluralStringById(quantity, "1 apples", true);
1736
1737 quantity = 101;
1738 rmc->TestPluralStringById(quantity, "101 apples", true);
1739 }
1740
1741 /*
1742 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest002
1743 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1744 * @tc.type: FUNC
1745 */
1746 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest002, TestSize.Level1)
1747 {
1748 rmc->AddResource("ar", nullptr, "SA");
1749
1750 RState state;
1751 std::string outValue;
1752 state = rm->GetPluralStringByIdFormat(outValue, NON_EXIST_ID, 1, 1);
1753 ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
1754 }
1755
1756 /*
1757 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest003
1758 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1759 * @tc.type: FUNC
1760 */
1761 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest003, TestSize.Level1)
1762 {
1763 rmc->AddResource("ar", nullptr, "SA");
1764
1765 RState state;
1766 std::string outValue;
1767 int id = rmc->GetResId("app_name", ResType::STRING);
1768 state = rm->GetPluralStringByIdFormat(outValue, id, 1, 1);
1769 ASSERT_EQ(ERROR_CODE_RES_NOT_FOUND_BY_ID, state);
1770 }
1771
1772 /*
1773 * @tc.name: ResourceManagerGetPluralStringByIdFormatTest004
1774 * @tc.desc: Test GetPluralStringByIdFormat function, file case.
1775 * @tc.type: FUNC
1776 */
1777 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByIdFormatTest004, TestSize.Level1)
1778 {
1779 rmc->AddColorModeResource(DEVICE_PHONE, LIGHT, SCREEN_DENSITY_LDPI / BASE_DPI);
1780
1781 RState state;
1782 std::string outValue;
1783 int quantity = 1;
1784 int id = rmc->GetResId("eat_apple1", ResType::PLURALS);
1785 state = rm->GetPluralStringByIdFormat(outValue, id, quantity);
1786 ASSERT_EQ(ERROR_CODE_RES_REF_TOO_MUCH, state);
1787 }
1788
1789 /*
1790 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest001
1791 * @tc.desc: Test GetFormatPluralStringById function
1792 * @tc.type: FUNC
1793 */
1794 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest001, TestSize.Level1)
1795 {
1796 rmc->AddResource("zh", nullptr, "CN");
1797 double quantity = 1;
1798 int id = rmc->GetResId("eat_apple", ResType::PLURALS);
1799 ASSERT_TRUE(id > 0);
1800 rmc->TestFormatPluralStringById(id, quantity, "1 apples");
1801 }
1802
1803 /*
1804 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest002
1805 * @tc.desc: Test GetFormatPluralStringById function
1806 * @tc.type: FUNC
1807 */
1808 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest002, TestSize.Level1)
1809 {
1810 rmc->AddResource("en", nullptr, "US");
1811 double quantity = 1;
1812 int id = rmc->GetResId("eat_apple", ResType::PLURALS);
1813 ASSERT_TRUE(id > 0);
1814 rmc->TestFormatPluralStringById(id, quantity, "1 apple");
1815
1816 quantity = 10;
1817 rmc->TestFormatPluralStringById(id, quantity, "10 apples");
1818 }
1819
1820 /*
1821 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest003
1822 * @tc.desc: Test GetFormatPluralStringById function
1823 * @tc.type: FUNC
1824 */
1825 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest003, TestSize.Level1)
1826 {
1827 rmc->AddResource("zh", nullptr, "CN");
1828 double quantity = 1;
1829 int id = 0;
1830 RState state;
1831 std::string outValue;
1832 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
1833 state = rm->GetFormatPluralStringById(outValue, id, quantity, jsParams);
1834 EXPECT_EQ(state, ERROR_CODE_RES_ID_NOT_FOUND);
1835 }
1836
1837 /*
1838 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest004
1839 * @tc.desc: Test GetFormatPluralStringById function
1840 * @tc.type: FUNC
1841 */
1842 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest004, TestSize.Level1)
1843 {
1844 rmc->AddResource("zh", nullptr, "CN");
1845 double quantity = 1;
1846 int id = rmc->GetResId("app_name", ResType::STRING);
1847 ASSERT_TRUE(id > 0);
1848 RState state;
1849 std::string outValue;
1850 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
1851 state = rm->GetFormatPluralStringById(outValue, id, quantity, jsParams);
1852 EXPECT_EQ(state, ERROR_CODE_RES_NOT_FOUND_BY_ID);
1853 }
1854
1855 /*
1856 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest005
1857 * @tc.desc: Test GetFormatPluralStringById function
1858 * @tc.type: FUNC
1859 */
1860 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest005, TestSize.Level1)
1861 {
1862 rmc->AddResource("zh", nullptr, "CN");
1863 double quantity = 1;
1864 int id = rmc->GetResId("eat_apple", ResType::PLURALS);
1865 ASSERT_TRUE(id > 0);
1866 RState state;
1867 std::string outValue;
1868 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
1869 jsParams.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_STRING, "1"));
1870 state = rm->GetFormatPluralStringById(outValue, id, quantity, jsParams);
1871 EXPECT_EQ(state, ERROR_CODE_RES_ID_FORMAT_ERROR);
1872 }
1873
1874 /*
1875 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest006
1876 * @tc.desc: Test GetFormatPluralStringById function
1877 * @tc.type: FUNC
1878 */
1879 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest006, TestSize.Level1)
1880 {
1881 rmc->AddResource("en", nullptr, "US");
1882 RState state;
1883 ResourceManager::Quantity quantity = { true, 1, 0.0 };
1884 std::string outValue;
1885 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
1886 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, "1"));
1887 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, "1.1"));
1888 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_STRING, "aaa"));
1889 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, "2.123456"));
1890 int id = rmc->GetResId("eat_apple2", ResType::PLURALS);
1891 state = rm->GetFormatPluralStringById(outValue, id, quantity, params);
1892 ASSERT_EQ(SUCCESS, state);
1893 EXPECT_EQ("1 apple, 1.1, aaa, 2.12", outValue);
1894
1895 rmc->TestGetFormatPluralStringById(outValue, id, quantity, 1, 1.1, "aaa");
1896 ASSERT_EQ(SUCCESS, state);
1897 EXPECT_EQ("1 apple, 1.1, aaa, 2.12", outValue);
1898
1899 quantity = { false, 0, 2.1 };
1900 state = rm->GetFormatPluralStringById(outValue, id, quantity, params);
1901 ASSERT_EQ(SUCCESS, state);
1902 EXPECT_EQ("1 apples, 1.1, aaa, 2.12", outValue);
1903
1904 state = rmc->TestGetFormatPluralStringById(outValue, id, quantity, 1, 1.1, "aaa");
1905 ASSERT_EQ(SUCCESS, state);
1906 EXPECT_EQ("1 apples, 1.1, aaa, 2.12", outValue);
1907 }
1908
1909 /*
1910 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest007
1911 * @tc.desc: Test GetFormatPluralStringById function
1912 * @tc.type: FUNC
1913 */
1914 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest007, TestSize.Level1)
1915 {
1916 rmc->AddResource("zh", nullptr, "CN");
1917 int id = rmc->GetResId("eat_apple", ResType::PLURALS);
1918 ASSERT_TRUE(id > 0);
1919 RState state;
1920 std::string outValue;
1921 ResourceManager::Quantity quantity = { true, 1, 0.0 };
1922 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
1923 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_STRING, "1"));
1924 state = rm->GetFormatPluralStringById(outValue, id, quantity, params);
1925 EXPECT_EQ(state, ERROR_CODE_RES_ID_FORMAT_ERROR);
1926 }
1927
1928 /*
1929 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest008
1930 * @tc.desc: Test GetFormatPluralStringById function
1931 * @tc.type: FUNC
1932 */
1933 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest008, TestSize.Level1)
1934 {
1935 rmc->AddResource("zh", nullptr, "CN");
1936 ResourceManager::Quantity quantity = { true, 1, 0.0 };
1937 int id = rmc->GetResId("app_name", ResType::STRING);
1938 ASSERT_TRUE(id > 0);
1939 RState state;
1940 std::string outValue;
1941 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
1942 state = rm->GetFormatPluralStringById(outValue, id, quantity, params);
1943 EXPECT_EQ(state, ERROR_CODE_RES_NOT_FOUND_BY_ID);
1944
1945 state = rmc->TestGetFormatPluralStringById(outValue, id, quantity);
1946 EXPECT_EQ(state, ERROR_CODE_RES_NOT_FOUND_BY_ID);
1947 }
1948
1949 /*
1950 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest009
1951 * @tc.desc: Test GetFormatPluralStringById function
1952 * @tc.type: FUNC
1953 */
1954 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest009, TestSize.Level1)
1955 {
1956 rmc->AddResource("zh", nullptr, "CN");
1957 ResourceManager::Quantity quantity = { true, 1, 0.0 };
1958 int id = rmc->GetResId("eat_apple1", ResType::PLURALS);
1959 RState state;
1960 std::string outValue;
1961 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
1962 state = rm->GetFormatPluralStringById(outValue, id, quantity, params);
1963 EXPECT_EQ(state, ERROR_CODE_RES_REF_TOO_MUCH);
1964
1965 state = rmc->TestGetFormatPluralStringById(outValue, id, quantity);
1966 EXPECT_EQ(state, ERROR_CODE_RES_REF_TOO_MUCH);
1967 }
1968
1969 /*
1970 * @tc.name: ResourceManagerGetFormatPluralStringByIdTest010
1971 * @tc.desc: Test GetFormatPluralStringById function
1972 * @tc.type: FUNC
1973 */
1974 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByIdTest010, TestSize.Level1)
1975 {
1976 rmc->AddResource("zh", nullptr, "CN");
1977 ResourceManager::Quantity quantity = { true, 1, 0.0 };
1978 int id = 0;
1979 RState state;
1980 std::string outValue;
1981 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
1982 state = rm->GetFormatPluralStringById(outValue, id, quantity, params);
1983 EXPECT_EQ(state, ERROR_CODE_RES_ID_NOT_FOUND);
1984
1985 state = rmc->TestGetFormatPluralStringById(outValue, id, quantity);
1986 EXPECT_EQ(state, ERROR_CODE_RES_ID_NOT_FOUND);
1987 }
1988
1989 /*
1990 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest001
1991 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
1992 * @tc.type: FUNC
1993 */
1994 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest001, TestSize.Level1)
1995 {
1996 rmc->AddResource("zh", nullptr, "CN");
1997
1998 int quantity = 1;
1999 rmc->TestPluralStringByName(quantity, "1 apples", true);
2000
2001 quantity = 101;
2002 rmc->TestPluralStringByName(quantity, "101 apples", true);
2003 }
2004
2005 /*
2006 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest002
2007 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
2008 * @tc.type: FUNC
2009 */
2010 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest002, TestSize.Level1)
2011 {
2012 rmc->AddResource("ar", nullptr, "SA");
2013
2014 RState state;
2015 std::string outValue;
2016 state = rm->GetPluralStringByNameFormat(outValue, g_nonExistName, 1, 1);
2017 ASSERT_EQ(ERROR_CODE_RES_NAME_NOT_FOUND, state);
2018 }
2019
2020 /*
2021 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest003
2022 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
2023 * @tc.type: FUNC
2024 */
2025 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest003, TestSize.Level1)
2026 {
2027 bool ret = ((ResourceManagerImpl*)rm)->AddResource(FormatFullPath(g_overlayResFilePath).c_str());
2028 ASSERT_TRUE(ret);
2029 std::string outValue;
2030 const char* eatApple = "eat_apple";
2031 RState state = rm->GetPluralStringByNameFormat(outValue, eatApple, 1, 1);
2032 ASSERT_EQ(ERROR_CODE_RES_NOT_FOUND_BY_NAME, state);
2033 }
2034
2035 /*
2036 * @tc.name: ResourceManagerGetPluralStringByNameFormatTest004
2037 * @tc.desc: Test GetPluralStringByNameFormat function, file case.
2038 * @tc.type: FUNC
2039 */
2040 HWTEST_F(ResourceManagerTestString, ResourceManagerGetPluralStringByNameFormatTest004, TestSize.Level1)
2041 {
2042 rmc->AddColorModeResource(DEVICE_PHONE, LIGHT, SCREEN_DENSITY_LDPI / BASE_DPI);
2043
2044 std::string outValue;
2045 const char* eatApple = "eat_apple1";
2046 int quantity = 1;
2047 RState state = rm->GetPluralStringByNameFormat(outValue, eatApple, quantity);
2048 ASSERT_EQ(ERROR_CODE_RES_REF_TOO_MUCH, state);
2049 }
2050
2051 /*
2052 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest001
2053 * @tc.desc: Test GetFormatPluralStringByName function
2054 * @tc.type: FUNC
2055 */
2056 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest001, TestSize.Level1)
2057 {
2058 rmc->AddResource("zh", nullptr, "CN");
2059 double quantity = 1;
2060 rmc->TestFormatPluralStringByName("eat_apple", quantity, "1 apples");
2061 }
2062
2063 /*
2064 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest002
2065 * @tc.desc: Test GetFormatPluralStringByName function
2066 * @tc.type: FUNC
2067 */
2068 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest002, TestSize.Level1)
2069 {
2070 rmc->AddResource("en", nullptr, "US");
2071 double quantity = 1;
2072 rmc->TestFormatPluralStringByName("eat_apple", quantity, "1 apple");
2073
2074 quantity = 10;
2075 rmc->TestFormatPluralStringByName("eat_apple", quantity, "10 apples");
2076 }
2077
2078 /*
2079 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest003
2080 * @tc.desc: Test GetFormatPluralStringByName function
2081 * @tc.type: FUNC
2082 */
2083 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest003, TestSize.Level1)
2084 {
2085 rmc->AddResource("zh", nullptr, "CN");
2086 double quantity = 1;
2087 RState state;
2088 std::string outValue;
2089 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
2090 state = rm->GetFormatPluralStringByName(outValue, "no_exist_plural", quantity, jsParams);
2091 EXPECT_EQ(state, ERROR_CODE_RES_NAME_NOT_FOUND);
2092 }
2093
2094 /*
2095 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest004
2096 * @tc.desc: Test GetFormatPluralStringByName function
2097 * @tc.type: FUNC
2098 */
2099 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest004, TestSize.Level1)
2100 {
2101 rmc->AddResource("zh", nullptr, "CN");
2102 double quantity = 1;
2103 RState state;
2104 std::string outValue;
2105 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> jsParams;
2106 jsParams.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_STRING, "1"));
2107 state = rm->GetFormatPluralStringByName(outValue, "eat_apple", quantity, jsParams);
2108 EXPECT_EQ(state, ERROR_CODE_RES_NAME_FORMAT_ERROR);
2109 }
2110
2111 /*
2112 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest005
2113 * @tc.desc: Test GetFormatPluralStringByName function
2114 * @tc.type: FUNC
2115 */
2116 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest005, TestSize.Level1)
2117 {
2118 rmc->AddResource("en", nullptr, "US");
2119 RState state;
2120 ResourceManager::Quantity quantity = { true, 1, 0.0 };
2121 std::string outValue;
2122 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
2123 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, "1"));
2124 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, "1.1"));
2125 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_STRING, "aaa"));
2126 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, "2.123456"));
2127 const char* name = "eat_apple2";
2128 state = rm->GetFormatPluralStringByName(outValue, name, quantity, params);
2129 ASSERT_EQ(SUCCESS, state);
2130 EXPECT_EQ("1 apple, 1.1, aaa, 2.12", outValue);
2131
2132 state = rmc->TestGetFormatPluralStringByName(outValue, name, quantity, 1, 1.1, "aaa");
2133 ASSERT_EQ(SUCCESS, state);
2134 EXPECT_EQ("1 apple, 1.1, aaa, 2.12", outValue);
2135
2136 quantity = { false, 0, 2.1 };
2137 state = rm->GetFormatPluralStringByName(outValue, name, quantity, params);
2138 ASSERT_EQ(SUCCESS, state);
2139 EXPECT_EQ("1 apples, 1.1, aaa, 2.12", outValue);
2140
2141 state = rmc->TestGetFormatPluralStringByName(outValue, name, quantity, 1, 1.1, "aaa");
2142 ASSERT_EQ(SUCCESS, state);
2143 EXPECT_EQ("1 apples, 1.1, aaa, 2.12", outValue);
2144 }
2145
2146 /*
2147 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest006
2148 * @tc.desc: Test GetFormatPluralStringByName function
2149 * @tc.type: FUNC
2150 */
2151 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest006, TestSize.Level1)
2152 {
2153 rmc->AddResource("zh", nullptr, "CN");
2154 ResourceManager::Quantity quantity = { true, 1, 0.0 };
2155 RState state;
2156 std::string outValue;
2157 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
2158 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_STRING, "1"));
2159 state = rm->GetFormatPluralStringByName(outValue, "eat_apple", quantity, params);
2160 EXPECT_EQ(state, ERROR_CODE_RES_NAME_FORMAT_ERROR);
2161 }
2162
2163 /*
2164 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest007
2165 * @tc.desc: Test GetFormatPluralStringByName function
2166 * @tc.type: FUNC
2167 */
2168 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest007, TestSize.Level1)
2169 {
2170 rmc->AddResource("zh", nullptr, "CN");
2171 ResourceManager::Quantity quantity = { true, 1, 0.0 };
2172 RState state;
2173 std::string outValue;
2174 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
2175 state = rm->GetFormatPluralStringByName(outValue, "no_exist_plural", quantity, params);
2176 EXPECT_EQ(state, ERROR_CODE_RES_NAME_NOT_FOUND);
2177
2178 state = rmc->TestGetFormatPluralStringByName(outValue, "no_exist_plural", quantity);
2179 EXPECT_EQ(state, ERROR_CODE_RES_NAME_NOT_FOUND);
2180 }
2181
2182 /*
2183 * @tc.name: ResourceManagerGetFormatPluralStringByNameTest008
2184 * @tc.desc: Test GetFormatPluralStringByName function
2185 * @tc.type: FUNC
2186 */
2187 HWTEST_F(ResourceManagerTestString, ResourceManagerGetFormatPluralStringByNameTest008, TestSize.Level1)
2188 {
2189 rmc->AddResource("zh", nullptr, "CN");
2190 ResourceManager::Quantity quantity = { true, 1, 0.0 };
2191 RState state;
2192 std::string outValue;
2193 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
2194 state = rm->GetFormatPluralStringByName(outValue, "eat_apple1", quantity, params);
2195 EXPECT_EQ(state, ERROR_CODE_RES_REF_TOO_MUCH);
2196
2197 state = rmc->TestGetFormatPluralStringByName(outValue, "eat_apple1", quantity);
2198 EXPECT_EQ(state, ERROR_CODE_RES_REF_TOO_MUCH);
2199 }
2200
2201 /*
2202 * @tc.name: ResourceManagerGetStringByNameForMccMncTest001
2203 * @tc.desc: Test GetStringByName
2204 * @tc.type: FUNC
2205 */
2206 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest001, TestSize.Level1)
2207 {
2208 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2209 ASSERT_TRUE(ret);
2210 auto rc = CreateResConfig();
2211 if (rc == nullptr) {
2212 ASSERT_TRUE(false);
2213 }
2214 rc->SetLocaleInfo("en", nullptr, nullptr);
2215 rc->SetDeviceType(DEVICE_TV);
2216 rc->SetColorMode(LIGHT);
2217 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2218 rm->UpdateResConfig(*rc);
2219 delete rc;
2220
2221 RState rState;
2222 std::string outValue;
2223 rState = rm->GetStringByName("mccmnc_str", outValue);
2224 ASSERT_EQ(SUCCESS, rState);
2225 ASSERT_EQ("str_en_us_light", outValue);
2226 }
2227
2228 /*
2229 * @tc.name: ResourceManagerGetStringByNameForMccMncTest002
2230 * @tc.desc: Test GetStringByName
2231 * @tc.type: FUNC
2232 */
2233 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest002, TestSize.Level1)
2234 {
2235 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2236 ASSERT_TRUE(ret);
2237 auto rc = CreateResConfig();
2238 if (rc == nullptr) {
2239 ASSERT_TRUE(false);
2240 }
2241 rc->SetLocaleInfo("zh", nullptr, nullptr);
2242 rc->SetDeviceType(DEVICE_TV);
2243 rc->SetColorMode(LIGHT);
2244 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2245 rm->UpdateResConfig(*rc);
2246 delete rc;
2247
2248 RState rState;
2249 std::string outValue;
2250 rState = rm->GetStringByName("mccmnc_str", outValue);
2251 ASSERT_EQ(SUCCESS, rState);
2252 ASSERT_EQ("str_zh_cn", outValue);
2253 }
2254
2255 /*
2256 * @tc.name: ResourceManagerGetStringByNameForMccMncTest003
2257 * @tc.desc: Test GetStringByName
2258 * @tc.type: FUNC
2259 */
2260 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest003, TestSize.Level1)
2261 {
2262 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2263 ASSERT_TRUE(ret);
2264 auto rc = CreateResConfig();
2265 if (rc == nullptr) {
2266 ASSERT_TRUE(false);
2267 }
2268 rc->SetLocaleInfo("en", nullptr, nullptr);
2269 rc->SetMcc(460);
2270 rc->SetMnc(101);
2271 rc->SetDeviceType(DEVICE_TV);
2272 rc->SetColorMode(LIGHT);
2273 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2274
2275 rm->UpdateResConfig(*rc);
2276 delete rc;
2277
2278 RState rState;
2279 std::string outValue;
2280 rState = rm->GetStringByName("mccmnc_str", outValue);
2281 ASSERT_EQ(SUCCESS, rState);
2282 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2283 }
2284
2285 /*
2286 * @tc.name: ResourceManagerGetStringByNameForMccMncTest004
2287 * @tc.desc: Test GetStringByName
2288 * @tc.type: FUNC
2289 */
2290 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest004, TestSize.Level1)
2291 {
2292 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2293 ASSERT_TRUE(ret);
2294
2295 auto rc = CreateResConfig();
2296 if (rc == nullptr) {
2297 ASSERT_TRUE(false);
2298 }
2299 rc->SetLocaleInfo("en", nullptr, nullptr);
2300 rc->SetMcc(460);
2301 rc->SetMnc(1);
2302 rc->SetDeviceType(DEVICE_TV);
2303 rc->SetColorMode(LIGHT);
2304 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2305 rm->UpdateResConfig(*rc);
2306 delete rc;
2307
2308 RState rState;
2309 std::string outValue;
2310 rState = rm->GetStringByName("mccmnc_str", outValue);
2311 ASSERT_EQ(SUCCESS, rState);
2312 ASSERT_EQ("str_mcc460_mnc001_en", outValue);
2313 }
2314
2315 /*
2316 * @tc.name: ResourceManagerGetStringByNameForMccMncTest005
2317 * @tc.desc: Test GetStringByName
2318 * @tc.type: FUNC
2319 */
2320 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest005, TestSize.Level1)
2321 {
2322 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2323 ASSERT_TRUE(ret);
2324
2325 auto rc = CreateResConfig();
2326 if (rc == nullptr) {
2327 ASSERT_TRUE(false);
2328 }
2329 rc->SetLocaleInfo("en", nullptr, nullptr);
2330 rc->SetMcc(460);
2331 rc->SetMnc(10);
2332 rc->SetDeviceType(DEVICE_TV);
2333 rc->SetColorMode(LIGHT);
2334 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2335 rm->UpdateResConfig(*rc);
2336 delete rc;
2337
2338 RState rState;
2339 std::string outValue;
2340 rState = rm->GetStringByName("mccmnc_str", outValue);
2341 ASSERT_EQ(SUCCESS, rState);
2342 ASSERT_EQ("str_mcc460_mnc010_en", outValue);
2343 }
2344
2345 /*
2346 * @tc.name: ResourceManagerGetStringByNameForMccMncTest006
2347 * @tc.desc: Test GetStringByName
2348 * @tc.type: FUNC
2349 */
2350 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest006, TestSize.Level1)
2351 {
2352 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2353 ASSERT_TRUE(ret);
2354
2355 auto rc = CreateResConfig();
2356 if (rc == nullptr) {
2357 ASSERT_TRUE(false);
2358 }
2359 rc->SetLocaleInfo("en", nullptr, nullptr);
2360 rc->SetMcc(460);
2361 rc->SetMnc(101);
2362 rc->SetDeviceType(DEVICE_TV);
2363 rc->SetColorMode(LIGHT);
2364 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2365 rm->UpdateResConfig(*rc);
2366 delete rc;
2367
2368 RState rState;
2369 std::string outValue;
2370 rState = rm->GetStringByName("mccmnc_str", outValue);
2371 ASSERT_EQ(SUCCESS, rState);
2372 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2373 }
2374
2375 /*
2376 * @tc.name: ResourceManagerGetStringByNameForMccMncTest007
2377 * @tc.desc: Test GetStringByName
2378 * @tc.type: FUNC
2379 */
2380 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest007, TestSize.Level1)
2381 {
2382 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2383 ASSERT_TRUE(ret);
2384
2385 auto rc = CreateResConfig();
2386 if (rc == nullptr) {
2387 ASSERT_TRUE(false);
2388 }
2389 rc->SetLocaleInfo("zh", nullptr, nullptr);
2390 rc->SetMcc(460);
2391 rc->SetMnc(101);
2392 rc->SetDeviceType(DEVICE_TV);
2393 rc->SetColorMode(LIGHT);
2394 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2395 rm->UpdateResConfig(*rc);
2396 delete rc;
2397
2398 RState rState;
2399 std::string outValue;
2400 rState = rm->GetStringByName("mccmnc_str", outValue);
2401 ASSERT_EQ(SUCCESS, rState);
2402 ASSERT_EQ("str_mcc460_mnc101_zh", outValue);
2403 }
2404
2405 /*
2406 * @tc.name: ResourceManagerGetStringByNameForMccMncTest008
2407 * @tc.desc: Test GetStringByName
2408 * @tc.type: FUNC
2409 */
2410 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest008, TestSize.Level1)
2411 {
2412 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2413 ASSERT_TRUE(ret);
2414 auto rc = CreateResConfig();
2415 if (rc == nullptr) {
2416 ASSERT_TRUE(false);
2417 }
2418 rc->SetLocaleInfo("en", nullptr, nullptr);
2419 rc->SetDeviceType(DEVICE_PHONE);
2420 rc->SetColorMode(LIGHT);
2421 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2422 rm->UpdateResConfig(*rc);
2423 delete rc;
2424
2425 RState rState;
2426 std::string outValue;
2427 rState = rm->GetStringByName("mccmnc_str", outValue);
2428 ASSERT_EQ(SUCCESS, rState);
2429 ASSERT_EQ("str_en_us_phone", outValue);
2430 }
2431
2432 /*
2433 * @tc.name: ResourceManagerGetStringByNameForMccMncTest009
2434 * @tc.desc: Test GetStringByName
2435 * @tc.type: FUNC
2436 */
2437 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest009, TestSize.Level1)
2438 {
2439 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2440 ASSERT_TRUE(ret);
2441 auto rc = CreateResConfig();
2442 if (rc == nullptr) {
2443 ASSERT_TRUE(false);
2444 }
2445 rc->SetLocaleInfo("en", nullptr, nullptr);
2446 rc->SetColorMode(LIGHT);
2447 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2448 rm->UpdateResConfig(*rc);
2449 delete rc;
2450
2451 RState rState;
2452 std::string outValue;
2453 rState = rm->GetStringByName("mccmnc_str", outValue);
2454 ASSERT_EQ(SUCCESS, rState);
2455 ASSERT_EQ("str_en_us_light", outValue);
2456 }
2457
2458 /*
2459 * @tc.name: ResourceManagerGetStringByNameForMccMncTest010
2460 * @tc.desc: Test GetStringByName
2461 * @tc.type: FUNC
2462 */
2463 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest010, TestSize.Level1)
2464 {
2465 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2466 ASSERT_TRUE(ret);
2467 auto rc = CreateResConfig();
2468 if (rc == nullptr) {
2469 ASSERT_TRUE(false);
2470 }
2471 rc->SetLocaleInfo("en", nullptr, nullptr);
2472 rc->SetMcc(460);
2473 rc->SetMnc(101);
2474 rc->SetDeviceType(DEVICE_PHONE);
2475 rc->SetColorMode(LIGHT);
2476 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2477 rm->UpdateResConfig(*rc);
2478 delete rc;
2479
2480 RState rState;
2481 std::string outValue;
2482 rState = rm->GetStringByName("mccmnc_str", outValue);
2483 ASSERT_EQ(SUCCESS, rState);
2484 ASSERT_EQ("str_mcc460_mnc101_en_phone", outValue);
2485 }
2486
2487 /*
2488 * @tc.name: ResourceManagerGetStringByNameForMccMncTest011
2489 * @tc.desc: Test GetStringByName
2490 * @tc.type: FUNC
2491 */
2492 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest011, TestSize.Level1)
2493 {
2494 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2495 ASSERT_TRUE(ret);
2496 auto rc = CreateResConfig();
2497 if (rc == nullptr) {
2498 ASSERT_TRUE(false);
2499 }
2500 rc->SetLocaleInfo("en", nullptr, nullptr);
2501 rc->SetMcc(460);
2502 rc->SetMnc(101);
2503 rc->SetColorMode(LIGHT);
2504 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2505 rm->UpdateResConfig(*rc);
2506 delete rc;
2507
2508 RState rState;
2509 std::string outValue;
2510 rState = rm->GetStringByName("mccmnc_str", outValue);
2511 ASSERT_EQ(SUCCESS, rState);
2512 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2513 }
2514
2515 /*
2516 * @tc.name: ResourceManagerGetStringByNameForMccMncTest012
2517 * @tc.desc: Test GetStringByName
2518 * @tc.type: FUNC
2519 */
2520 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest012, TestSize.Level1)
2521 {
2522 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2523 ASSERT_TRUE(ret);
2524 auto rc = CreateResConfig();
2525 if (rc == nullptr) {
2526 ASSERT_TRUE(false);
2527 }
2528 rc->SetLocaleInfo("en", nullptr, nullptr);
2529 rc->SetDeviceType(DEVICE_TV);
2530 rc->SetColorMode(DARK);
2531 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2532 rm->UpdateResConfig(*rc);
2533 delete rc;
2534
2535 RState rState;
2536 std::string outValue;
2537 rState = rm->GetStringByName("mccmnc_str", outValue);
2538 ASSERT_EQ(SUCCESS, rState);
2539 ASSERT_EQ("str_en_us_dark", outValue);
2540 }
2541
2542 /*
2543 * @tc.name: ResourceManagerGetStringByNameForMccMncTest013
2544 * @tc.desc: Test GetStringByName
2545 * @tc.type: FUNC
2546 */
2547 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest013, TestSize.Level1)
2548 {
2549 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2550 ASSERT_TRUE(ret);
2551 auto rc = CreateResConfig();
2552 if (rc == nullptr) {
2553 ASSERT_TRUE(false);
2554 }
2555 rc->SetLocaleInfo("en", nullptr, nullptr);
2556 rc->SetDeviceType(DEVICE_TV);
2557 rc->SetColorMode(LIGHT);
2558 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2559 rm->UpdateResConfig(*rc);
2560 delete rc;
2561
2562 RState rState;
2563 std::string outValue;
2564 rState = rm->GetStringByName("mccmnc_str", outValue);
2565 ASSERT_EQ(SUCCESS, rState);
2566 ASSERT_EQ("str_en_us_light", outValue);
2567 }
2568
2569 /*
2570 * @tc.name: ResourceManagerGetStringByNameForMccMncTest014
2571 * @tc.desc: Test GetStringByName
2572 * @tc.type: FUNC
2573 */
2574 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest014, TestSize.Level1)
2575 {
2576 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2577 ASSERT_TRUE(ret);
2578 auto rc = CreateResConfig();
2579 if (rc == nullptr) {
2580 ASSERT_TRUE(false);
2581 }
2582 rc->SetLocaleInfo("en", nullptr, nullptr);
2583 rc->SetMcc(460);
2584 rc->SetMnc(101);
2585 rc->SetDeviceType(DEVICE_TV);
2586 rc->SetColorMode(DARK);
2587 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2588 rm->UpdateResConfig(*rc);
2589 delete rc;
2590
2591 RState rState;
2592 std::string outValue;
2593 rState = rm->GetStringByName("mccmnc_str", outValue);
2594 ASSERT_EQ(SUCCESS, rState);
2595 ASSERT_EQ("str_mcc460_mnc101_en_dark", outValue);
2596 }
2597
2598 /*
2599 * @tc.name: ResourceManagerGetStringByNameForMccMncTest015
2600 * @tc.desc: Test GetStringByName
2601 * @tc.type: FUNC
2602 */
2603 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest015, TestSize.Level1)
2604 {
2605 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2606 ASSERT_TRUE(ret);
2607 auto rc = CreateResConfig();
2608 if (rc == nullptr) {
2609 ASSERT_TRUE(false);
2610 }
2611 rc->SetLocaleInfo("en", nullptr, nullptr);
2612 rc->SetMcc(460);
2613 rc->SetMnc(101);
2614 rc->SetDeviceType(DEVICE_TV);
2615 rc->SetColorMode(LIGHT);
2616 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2617 rm->UpdateResConfig(*rc);
2618 delete rc;
2619
2620 RState rState;
2621 std::string outValue;
2622 rState = rm->GetStringByName("mccmnc_str", outValue);
2623 ASSERT_EQ(SUCCESS, rState);
2624 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2625 }
2626
2627 /*
2628 * @tc.name: ResourceManagerGetStringByNameForMccMncTest016
2629 * @tc.desc: Test GetStringByName
2630 * @tc.type: FUNC
2631 */
2632 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest016, TestSize.Level1)
2633 {
2634 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2635 ASSERT_TRUE(ret);
2636 auto rc = CreateResConfig();
2637 if (rc == nullptr) {
2638 ASSERT_TRUE(false);
2639 }
2640 rc->SetLocaleInfo("en", nullptr, nullptr);
2641 rc->SetDeviceType(DEVICE_TV);
2642 rc->SetColorMode(LIGHT);
2643 rc->SetScreenDensity(SCREEN_DENSITY_LDPI / BASE_DPI);
2644 rm->UpdateResConfig(*rc);
2645 delete rc;
2646
2647 RState rState;
2648 std::string outValue;
2649 rState = rm->GetStringByName("mccmnc_str", outValue);
2650 ASSERT_EQ(SUCCESS, rState);
2651 ASSERT_EQ("str_en_us_light", outValue);
2652 }
2653
2654 /*
2655 * @tc.name: ResourceManagerGetStringByNameForMccMncTest017
2656 * @tc.desc: Test GetStringByName
2657 * @tc.type: FUNC
2658 */
2659 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest017, TestSize.Level1)
2660 {
2661 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2662 ASSERT_TRUE(ret);
2663 auto rc = CreateResConfig();
2664 if (rc == nullptr) {
2665 ASSERT_TRUE(false);
2666 }
2667 rc->SetLocaleInfo("en", nullptr, nullptr);
2668 rc->SetDeviceType(DEVICE_TV);
2669 rc->SetColorMode(LIGHT);
2670 rc->SetScreenDensity(SCREEN_DENSITY_XLDPI / BASE_DPI);
2671 rm->UpdateResConfig(*rc);
2672 delete rc;
2673
2674 RState rState;
2675 std::string outValue;
2676 rState = rm->GetStringByName("mccmnc_str", outValue);
2677 ASSERT_EQ(SUCCESS, rState);
2678 ASSERT_EQ("str_en_us_light", outValue);
2679 }
2680
2681 /*
2682 * @tc.name: ResourceManagerGetStringByNameForMccMncTest018
2683 * @tc.desc: Test GetStringByName
2684 * @tc.type: FUNC
2685 */
2686 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest018, TestSize.Level1)
2687 {
2688 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2689 ASSERT_TRUE(ret);
2690 auto rc = CreateResConfig();
2691 if (rc == nullptr) {
2692 ASSERT_TRUE(false);
2693 }
2694 rc->SetLocaleInfo("en", nullptr, nullptr);
2695 rc->SetMcc(460);
2696 rc->SetMnc(101);
2697 rc->SetDeviceType(DEVICE_TV);
2698 rc->SetColorMode(LIGHT);
2699 rc->SetScreenDensity(SCREEN_DENSITY_LDPI / BASE_DPI);
2700 rm->UpdateResConfig(*rc);
2701 delete rc;
2702
2703 RState rState;
2704 std::string outValue;
2705 rState = rm->GetStringByName("mccmnc_str", outValue);
2706 ASSERT_EQ(SUCCESS, rState);
2707 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2708 }
2709
2710 /*
2711 * @tc.name: ResourceManagerGetStringByNameForMccMncTest019
2712 * @tc.desc: Test GetStringByName
2713 * @tc.type: FUNC
2714 */
2715 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest019, TestSize.Level1)
2716 {
2717 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2718 ASSERT_TRUE(ret);
2719 auto rc = CreateResConfig();
2720 if (rc == nullptr) {
2721 ASSERT_TRUE(false);
2722 }
2723 rc->SetLocaleInfo("en", nullptr, nullptr);
2724 rc->SetMcc(460);
2725 rc->SetMnc(101);
2726 rc->SetDeviceType(DEVICE_TV);
2727 rc->SetColorMode(LIGHT);
2728 rc->SetScreenDensity(SCREEN_DENSITY_XLDPI / BASE_DPI);
2729 rm->UpdateResConfig(*rc);
2730 delete rc;
2731
2732 RState rState;
2733 std::string outValue;
2734 rState = rm->GetStringByName("mccmnc_str", outValue);
2735 ASSERT_EQ(SUCCESS, rState);
2736 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2737 }
2738
2739 /*
2740 * @tc.name: ResourceManagerGetStringByNameForMccMncTest020
2741 * @tc.desc: Test GetStringByName
2742 * @tc.type: FUNC
2743 */
2744 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest020, TestSize.Level1)
2745 {
2746 bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
2747 ASSERT_TRUE(ret);
2748 auto rc = CreateResConfig();
2749 if (rc == nullptr) {
2750 ASSERT_TRUE(false);
2751 }
2752 rc->SetLocaleInfo("en", nullptr, nullptr);
2753 rc->SetMcc(460);
2754 rc->SetMnc(101);
2755 rc->SetDeviceType(DEVICE_PHONE);
2756 rc->SetColorMode(DARK);
2757 rc->SetScreenDensity(SCREEN_DENSITY_XLDPI / BASE_DPI);
2758 rm->UpdateResConfig(*rc);
2759 delete rc;
2760
2761 RState rState;
2762 std::string outValue;
2763 rState = rm->GetStringByName("mccmnc_str", outValue);
2764 ASSERT_EQ(SUCCESS, rState);
2765 ASSERT_EQ("str_mcc460_mnc101_en_phone_dark_xldpi", outValue);
2766 }
2767
2768 /*
2769 * @tc.name: ResourceManagerGetStringByNameForMccMncTest021
2770 * @tc.desc: Test GetStringByName
2771 * @tc.type: FUNC
2772 */
2773 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest021, TestSize.Level1)
2774 {
2775 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2776 ASSERT_TRUE(ret);
2777 auto rc = CreateResConfig();
2778 if (rc == nullptr) {
2779 ASSERT_TRUE(false);
2780 }
2781 rc->SetLocaleInfo("en", nullptr, nullptr);
2782 rc->SetDeviceType(DEVICE_TV);
2783 rc->SetColorMode(LIGHT);
2784 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2785 rm->UpdateResConfig(*rc);
2786 delete rc;
2787
2788 RState rState;
2789 std::string outValue;
2790 rState = rm->GetStringByName("mccmnc_str", outValue);
2791 ASSERT_EQ(SUCCESS, rState);
2792 ASSERT_EQ("str_en_us_light", outValue);
2793 }
2794
2795 /*
2796 * @tc.name: ResourceManagerGetStringByNameForMccMncTest022
2797 * @tc.desc: Test GetStringByName
2798 * @tc.type: FUNC
2799 */
2800 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest022, TestSize.Level1)
2801 {
2802 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2803 ASSERT_TRUE(ret);
2804 auto rc = CreateResConfig();
2805 if (rc == nullptr) {
2806 ASSERT_TRUE(false);
2807 }
2808 rc->SetLocaleInfo("zh", nullptr, nullptr);
2809 rc->SetDeviceType(DEVICE_TV);
2810 rc->SetColorMode(LIGHT);
2811 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2812 rm->UpdateResConfig(*rc);
2813 delete rc;
2814
2815 RState rState;
2816 std::string outValue;
2817 rState = rm->GetStringByName("mccmnc_str", outValue);
2818 ASSERT_EQ(SUCCESS, rState);
2819 ASSERT_EQ("str_zh_cn", outValue);
2820 }
2821
2822 /*
2823 * @tc.name: ResourceManagerGetStringByNameForMccMncTest023
2824 * @tc.desc: Test GetStringByName
2825 * @tc.type: FUNC
2826 */
2827 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest023, TestSize.Level1)
2828 {
2829 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2830 ASSERT_TRUE(ret);
2831 auto rc = CreateResConfig();
2832 if (rc == nullptr) {
2833 ASSERT_TRUE(false);
2834 }
2835 rc->SetLocaleInfo("en", nullptr, nullptr);
2836 rc->SetMcc(460);
2837 rc->SetMnc(101);
2838 rc->SetDeviceType(DEVICE_TV);
2839 rc->SetColorMode(LIGHT);
2840 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2841
2842 rm->UpdateResConfig(*rc);
2843 delete rc;
2844
2845 RState rState;
2846 std::string outValue;
2847 rState = rm->GetStringByName("mccmnc_str", outValue);
2848 ASSERT_EQ(SUCCESS, rState);
2849 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2850 }
2851
2852 /*
2853 * @tc.name: ResourceManagerGetStringByNameForMccMncTest024
2854 * @tc.desc: Test GetStringByName
2855 * @tc.type: FUNC
2856 */
2857 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest024, TestSize.Level1)
2858 {
2859 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2860 ASSERT_TRUE(ret);
2861
2862 auto rc = CreateResConfig();
2863 if (rc == nullptr) {
2864 ASSERT_TRUE(false);
2865 }
2866 rc->SetLocaleInfo("en", nullptr, nullptr);
2867 rc->SetMcc(460);
2868 rc->SetMnc(1);
2869 rc->SetDeviceType(DEVICE_TV);
2870 rc->SetColorMode(LIGHT);
2871 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2872 rm->UpdateResConfig(*rc);
2873 delete rc;
2874
2875 RState rState;
2876 std::string outValue;
2877 rState = rm->GetStringByName("mccmnc_str", outValue);
2878 ASSERT_EQ(SUCCESS, rState);
2879 ASSERT_EQ("str_mcc460_mnc001_en", outValue);
2880 }
2881
2882 /*
2883 * @tc.name: ResourceManagerGetStringByNameForMccMncTest025
2884 * @tc.desc: Test GetStringByName
2885 * @tc.type: FUNC
2886 */
2887 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest025, TestSize.Level1)
2888 {
2889 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2890 ASSERT_TRUE(ret);
2891
2892 auto rc = CreateResConfig();
2893 if (rc == nullptr) {
2894 ASSERT_TRUE(false);
2895 }
2896 rc->SetLocaleInfo("en", nullptr, nullptr);
2897 rc->SetMcc(460);
2898 rc->SetMnc(10);
2899 rc->SetDeviceType(DEVICE_TV);
2900 rc->SetColorMode(LIGHT);
2901 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2902 rm->UpdateResConfig(*rc);
2903 delete rc;
2904
2905 RState rState;
2906 std::string outValue;
2907 rState = rm->GetStringByName("mccmnc_str", outValue);
2908 ASSERT_EQ(SUCCESS, rState);
2909 ASSERT_EQ("str_mcc460_mnc010_en", outValue);
2910 }
2911
2912 /*
2913 * @tc.name: ResourceManagerGetStringByNameForMccMncTest026
2914 * @tc.desc: Test GetStringByName
2915 * @tc.type: FUNC
2916 */
2917 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest026, TestSize.Level1)
2918 {
2919 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2920 ASSERT_TRUE(ret);
2921
2922 auto rc = CreateResConfig();
2923 if (rc == nullptr) {
2924 ASSERT_TRUE(false);
2925 }
2926 rc->SetLocaleInfo("en", nullptr, nullptr);
2927 rc->SetMcc(460);
2928 rc->SetMnc(101);
2929 rc->SetDeviceType(DEVICE_TV);
2930 rc->SetColorMode(LIGHT);
2931 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2932 rm->UpdateResConfig(*rc);
2933 delete rc;
2934
2935 RState rState;
2936 std::string outValue;
2937 rState = rm->GetStringByName("mccmnc_str", outValue);
2938 ASSERT_EQ(SUCCESS, rState);
2939 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
2940 }
2941
2942 /*
2943 * @tc.name: ResourceManagerGetStringByNameForMccMncTest027
2944 * @tc.desc: Test GetStringByName
2945 * @tc.type: FUNC
2946 */
2947 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest027, TestSize.Level1)
2948 {
2949 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2950 ASSERT_TRUE(ret);
2951
2952 auto rc = CreateResConfig();
2953 if (rc == nullptr) {
2954 ASSERT_TRUE(false);
2955 }
2956 rc->SetLocaleInfo("zh", nullptr, nullptr);
2957 rc->SetMcc(460);
2958 rc->SetMnc(101);
2959 rc->SetDeviceType(DEVICE_TV);
2960 rc->SetColorMode(LIGHT);
2961 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2962 rm->UpdateResConfig(*rc);
2963 delete rc;
2964
2965 RState rState;
2966 std::string outValue;
2967 rState = rm->GetStringByName("mccmnc_str", outValue);
2968 ASSERT_EQ(SUCCESS, rState);
2969 ASSERT_EQ("str_mcc460_mnc101_zh", outValue);
2970 }
2971
2972 /*
2973 * @tc.name: ResourceManagerGetStringByNameForMccMncTest028
2974 * @tc.desc: Test GetStringByName
2975 * @tc.type: FUNC
2976 */
2977 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest028, TestSize.Level1)
2978 {
2979 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
2980 ASSERT_TRUE(ret);
2981 auto rc = CreateResConfig();
2982 if (rc == nullptr) {
2983 ASSERT_TRUE(false);
2984 }
2985 rc->SetLocaleInfo("en", nullptr, nullptr);
2986 rc->SetDeviceType(DEVICE_PHONE);
2987 rc->SetColorMode(LIGHT);
2988 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
2989 rm->UpdateResConfig(*rc);
2990 delete rc;
2991
2992 RState rState;
2993 std::string outValue;
2994 rState = rm->GetStringByName("mccmnc_str", outValue);
2995 ASSERT_EQ(SUCCESS, rState);
2996 ASSERT_EQ("str_en_us_phone", outValue);
2997 }
2998
2999 /*
3000 * @tc.name: ResourceManagerGetStringByNameForMccMncTest029
3001 * @tc.desc: Test GetStringByName
3002 * @tc.type: FUNC
3003 */
3004 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest029, TestSize.Level1)
3005 {
3006 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
3007 ASSERT_TRUE(ret);
3008 auto rc = CreateResConfig();
3009 if (rc == nullptr) {
3010 ASSERT_TRUE(false);
3011 }
3012 rc->SetLocaleInfo("en", nullptr, nullptr);
3013 rc->SetColorMode(LIGHT);
3014 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
3015 rm->UpdateResConfig(*rc);
3016 delete rc;
3017
3018 RState rState;
3019 std::string outValue;
3020 rState = rm->GetStringByName("mccmnc_str", outValue);
3021 ASSERT_EQ(SUCCESS, rState);
3022 ASSERT_EQ("str_en_us_light", outValue);
3023 }
3024
3025 /*
3026 * @tc.name: ResourceManagerGetStringByNameForMccMncTest030
3027 * @tc.desc: Test GetStringByName
3028 * @tc.type: FUNC
3029 */
3030 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest030, TestSize.Level1)
3031 {
3032 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
3033 ASSERT_TRUE(ret);
3034 auto rc = CreateResConfig();
3035 if (rc == nullptr) {
3036 ASSERT_TRUE(false);
3037 }
3038 rc->SetLocaleInfo("en", nullptr, nullptr);
3039 rc->SetMcc(460);
3040 rc->SetMnc(101);
3041 rc->SetDeviceType(DEVICE_PHONE);
3042 rc->SetColorMode(LIGHT);
3043 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
3044 rm->UpdateResConfig(*rc);
3045 delete rc;
3046
3047 RState rState;
3048 std::string outValue;
3049 rState = rm->GetStringByName("mccmnc_str", outValue);
3050 ASSERT_EQ(SUCCESS, rState);
3051 ASSERT_EQ("str_mcc460_mnc101_en_phone", outValue);
3052 }
3053
3054 /*
3055 * @tc.name: ResourceManagerGetStringByNameForMccMncTest031
3056 * @tc.desc: Test GetStringByName
3057 * @tc.type: FUNC
3058 */
3059 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest031, TestSize.Level1)
3060 {
3061 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
3062 ASSERT_TRUE(ret);
3063 auto rc = CreateResConfig();
3064 if (rc == nullptr) {
3065 ASSERT_TRUE(false);
3066 }
3067 rc->SetLocaleInfo("en", nullptr, nullptr);
3068 rc->SetMcc(460);
3069 rc->SetMnc(101);
3070 rc->SetColorMode(LIGHT);
3071 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
3072 rm->UpdateResConfig(*rc);
3073 delete rc;
3074
3075 RState rState;
3076 std::string outValue;
3077 rState = rm->GetStringByName("mccmnc_str", outValue);
3078 ASSERT_EQ(SUCCESS, rState);
3079 ASSERT_EQ("str_mcc460_mnc101_en_light", outValue);
3080 }
3081
3082 /*
3083 * @tc.name: ResourceManagerGetStringByNameForMccMncTest032
3084 * @tc.desc: Test GetStringByName
3085 * @tc.type: FUNC
3086 */
3087 HWTEST_F(ResourceManagerTestString, ResourceManagerGetStringByNameForMccMncTest032, TestSize.Level1)
3088 {
3089 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
3090 ASSERT_TRUE(ret);
3091 auto rc = CreateResConfig();
3092 if (rc == nullptr) {
3093 ASSERT_TRUE(false);
3094 }
3095 rc->SetLocaleInfo("en", nullptr, nullptr);
3096 rc->SetDeviceType(DEVICE_TV);
3097 rc->SetColorMode(DARK);
3098 rc->SetScreenDensity(SCREEN_DENSITY_SDPI / BASE_DPI);
3099 rm->UpdateResConfig(*rc);
3100 delete rc;
3101
3102 RState rState;
3103 std::string outValue;
3104 rState = rm->GetStringByName("mccmnc_str", outValue);
3105 ASSERT_EQ(SUCCESS, rState);
3106 ASSERT_EQ("str_en_us_dark", outValue);
3107 }
3108 }
3109