• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_performance_test.h"
17 
18 #include <chrono>
19 #include <climits>
20 #include <cstring>
21 #include <ctime>
22 #include <gtest/gtest.h>
23 
24 #define private public
25 
26 #include "resource_manager.h"
27 #include "resource_manager_impl.h"
28 #include "test_common.h"
29 #include "utils/errors.h"
30 
31 using namespace OHOS::Global::Resource;
32 using namespace testing::ext;
33 using namespace std;
34 
35 class ResourceManagerPerformanceTest : public testing::Test {
36 public:
37     static void SetUpTestCase(void);
38 
39     static void TearDownTestCase(void);
40 
41     void SetUp();
42 
43     void TearDown();
44 
ResourceManagerPerformanceTest()45     ResourceManagerPerformanceTest() : rm(nullptr)
46     {}
47 
~ResourceManagerPerformanceTest()48     ~ResourceManagerPerformanceTest()
49     {}
50 
51 public:
52     ResourceManager *rm;
53 
54     int GetResId(std::string name, ResType resType) const;
55 };
56 
GetResId(std::string name,ResType resType) const57 int ResourceManagerPerformanceTest::GetResId(std::string name, ResType resType) const
58 {
59     auto idv = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType);
60     if (idv == nullptr) {
61         return -1;
62     }
63 
64     if (idv->GetLimitPathsConst().size() > 0) {
65         return idv->GetLimitPathsConst()[0]->GetIdItem()->id_;
66     }
67     return OBJ_NOT_FOUND;
68 }
69 
SetUpTestCase(void)70 void ResourceManagerPerformanceTest::SetUpTestCase(void)
71 {
72     // step 1: input testsuit setup step
73 }
74 
TearDownTestCase(void)75 void ResourceManagerPerformanceTest::TearDownTestCase(void)
76 {
77     // step 2: input testsuit teardown step
78 }
79 
SetUp(void)80 void ResourceManagerPerformanceTest::SetUp(void)
81 {
82     // PerformanceTest need higher log level
83     g_logLevel = LOG_INFO;
84     this->rm = CreateResourceManager();
85     if (rm == nullptr) {
86         return;
87     }
88     auto rc = CreateResConfig();
89     if (rc == nullptr) {
90         return;
91     }
92     rc->SetLocaleInfo("zh", nullptr, nullptr);
93     rm->UpdateResConfig(*rc);
94     delete rc;
95     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
96     if (!ret) {
97         HILOG_ERROR("AddResource failed. test would fail.");
98     }
99 }
100 
TearDown(void)101 void ResourceManagerPerformanceTest::TearDown(void)
102 {
103     if (this->rm != nullptr) {
104         delete this->rm;
105         this->rm = nullptr;
106     }
107 }
108 
109 /*
110  * @tc.name: ResourceManagerPerformanceFuncTest001
111  * @tc.desc: Test AddResource
112  * @tc.type: FUNC
113  */
114 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest001, TestSize.Level1)
115 {
116     unsigned long long total = 0;
117     double average = 0;
118     for (int k = 0; k < 1000; ++k) {
119         auto tmpRm = CreateResourceManager();
120         if (tmpRm == nullptr) {
121             EXPECT_TRUE(false);
122             return;
123         }
124         auto t1 = std::chrono::high_resolution_clock::now();
125         tmpRm->AddResource(FormatFullPath(g_resFilePath).c_str());
126         auto t2 = std::chrono::high_resolution_clock::now();
127         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
128         delete tmpRm;
129     }
130     average = total / 1000.0;
131     g_logLevel = LOG_DEBUG;
132     HILOG_DEBUG("avg cost 001: %f us", average);
133     EXPECT_LT(average, 9000);
134 };
135 
136 /*
137  * @tc.name: ResourceManagerPerformanceFuncTest002
138  * @tc.desc: Test UpdateResConfig
139  * @tc.type: FUNC
140  */
141 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest002, TestSize.Level1)
142 {
143     unsigned long long total = 0;
144     double average = 0;
145     auto tmpRm = CreateResourceManager();
146     if (tmpRm == nullptr) {
147         EXPECT_TRUE(false);
148         return;
149     }
150     ResConfig *rc = CreateResConfig();
151     if (rc == nullptr) {
152         EXPECT_TRUE(false);
153         delete tmpRm;
154         return;
155     }
156     rc->SetLocaleInfo("en", nullptr, "US");
157     rc->SetDeviceType(DeviceType::DEVICE_CAR);
158     for (int k = 0; k < 1000; ++k) {
159         auto t1 = std::chrono::high_resolution_clock::now();
160         tmpRm->UpdateResConfig(*rc);
161         auto t2 = std::chrono::high_resolution_clock::now();
162         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
163     }
164     delete tmpRm;
165     delete rc;
166     average = total / 1000.0;
167     g_logLevel = LOG_DEBUG;
168     HILOG_DEBUG("avg cost 002: %f us", average);
169     EXPECT_LT(average, 500);
170 };
171 
172 /*
173  * @tc.name: ResourceManagerPerformanceFuncTest003
174  * @tc.desc: Test GetResConfig
175  * @tc.type: FUNC
176  */
177 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest003, TestSize.Level1)
178 {
179     if (rm == nullptr) {
180         EXPECT_TRUE(false);
181         return;
182     }
183     unsigned long long total = 0;
184     double average = 0;
185     ResConfig *rc = CreateResConfig();
186     if (rc == nullptr) {
187         EXPECT_TRUE(false);
188         return;
189     }
190     rc->SetLocaleInfo("en", nullptr, "US");
191     rc->SetDeviceType(DeviceType::DEVICE_CAR);
192     ResConfigImpl rci;
193     for (int k = 0; k < 1000; ++k) {
194         auto t1 = std::chrono::high_resolution_clock::now();
195         rm->GetResConfig(rci);
196         auto t2 = std::chrono::high_resolution_clock::now();
197         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
198     }
199     delete rc;
200     average = total / 1000.0;
201     g_logLevel = LOG_DEBUG;
202     HILOG_DEBUG("avg cost 003: %f us", average);
203     EXPECT_LT(average, 500);
204 };
205 
206 /*
207  * @tc.name: ResourceManagerPerformanceFuncTest004
208  * @tc.desc: Test GetStringByID
209  * @tc.type: FUNC
210  */
211 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest004, TestSize.Level1)
212 {
213     if (rm == nullptr) {
214         EXPECT_TRUE(false);
215         return;
216     }
217     unsigned long long total = 0;
218     double average = 0;
219     string name[] = {"app_name", "title"};
220     vector<uint32_t> ids;
221     int count = 2;
222     for (int i = 0; i < count; ++i) {
223         int id = GetResId(name[i], ResType::STRING);
224         ASSERT_TRUE(id > 0);
225         ids.push_back(static_cast<uint32_t>(id));
226     }
227 
228     std::string outValue;
229     for (int k = 0; k < 1000; ++k) {
230         for (int i = 0; i < count; ++i) {
231             auto t1 = std::chrono::high_resolution_clock::now();
232             rm->GetStringById(ids[i], outValue);
233             auto t2 = std::chrono::high_resolution_clock::now();
234             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
235         }
236     }
237     average = total / (1000.0 * count);
238     g_logLevel = LOG_DEBUG;
239     HILOG_DEBUG("avg cost 004: %f us", average);
240     EXPECT_LT(average, 500);
241 };
242 
243 /*
244  * @tc.name: ResourceManagerPerformanceFuncTest005
245  * @tc.desc: Test GetStringByName
246  * @tc.type: FUNC
247  */
248 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest005, TestSize.Level1)
249 {
250     if (rm == nullptr) {
251         EXPECT_TRUE(false);
252         return;
253     }
254     unsigned long long total = 0;
255     double average = 0;
256     string name[] = {"app_name", "title"};
257     int count = 2;
258     std::string outValue;
259     for (int k = 0; k < 1000; ++k) {
260         for (int i = 0; i < count; ++i) {
261             auto t1 = std::chrono::high_resolution_clock::now();
262             rm->GetStringByName(name[i].c_str(), outValue);
263             auto t2 = std::chrono::high_resolution_clock::now();
264             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
265         }
266     }
267     average = total / (1000.0 * count);
268     g_logLevel = LOG_DEBUG;
269     HILOG_DEBUG("avg cost 005: %f us", average);
270     EXPECT_LT(average, 500);
271 };
272 
273 /*
274  * @tc.name: ResourceManagerPerformanceFuncTest006
275  * @tc.desc: Test GetStringByName
276  * @tc.type: FUNC
277  */
278 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest006, TestSize.Level1)
279 {
280     if (rm == nullptr) {
281         EXPECT_TRUE(false);
282         return;
283     }
284     unsigned long long total = 0;
285     double average = 0;
286     string name[] = {"string_ref", "string_ref2"};
287     int count = 2;
288     std::string outValue;
289     for (int k = 0; k < 1000; ++k) {
290         for (int i = 0; i < count; ++i) {
291             auto t1 = std::chrono::high_resolution_clock::now();
292             rm->GetStringByName(name[i].c_str(), outValue);
293             auto t2 = std::chrono::high_resolution_clock::now();
294             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
295         }
296     }
297     average = total / (1000.0 * count);
298     g_logLevel = LOG_DEBUG;
299     HILOG_DEBUG("avg cost 006: %f us", average);
300     EXPECT_LT(average, 500);
301 };
302 
303 /*
304  * @tc.name: ResourceManagerPerformanceFuncTest007
305  * @tc.desc: Test GetStringFormatById
306  * @tc.type: FUNC
307  */
308 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest007, TestSize.Level1)
309 {
310     if (rm == nullptr) {
311         EXPECT_TRUE(false);
312         return;
313     }
314     unsigned long long total = 0;
315     double average = 0;
316     string name[] = {"app_name", "title"};
317     vector<uint32_t> ids;
318     int count = 2;
319     for (int i = 0; i < count; ++i) {
320         int id = GetResId(name[i], ResType::STRING);
321         ASSERT_TRUE(id > 0);
322         ids.push_back(static_cast<uint32_t>(id));
323     }
324 
325     std::string outValue;
326     for (int k = 0; k < 1000; ++k) {
327         for (int i = 0; i < count; ++i) {
328             auto t1 = std::chrono::high_resolution_clock::now();
329             rm->GetStringFormatById(outValue, ids[i], 12);
330             auto t2 = std::chrono::high_resolution_clock::now();
331             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
332         }
333     }
334     average = total / (1000.0 * count);
335     g_logLevel = LOG_DEBUG;
336     HILOG_DEBUG("avg cost 007: %f us", average);
337     EXPECT_LT(average, 500);
338 };
339 
340 /*
341  * @tc.name: ResourceManagerPerformanceFuncTest008
342  * @tc.desc: Test GetStringFormatByName
343  * @tc.type: FUNC
344  */
345 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest008, TestSize.Level1)
346 {
347     if (rm == nullptr) {
348         EXPECT_TRUE(false);
349         return;
350     }
351     unsigned long long total = 0;
352     double average = 0;
353     string name[] = {"app_name", "title"};
354     int count = 2;
355     std::string outValue;
356     for (int k = 0; k < 1000; ++k) {
357         for (int i = 0; i < count; ++i) {
358             auto t1 = std::chrono::high_resolution_clock::now();
359             rm->GetStringFormatByName(outValue, name[i].c_str(), 123);
360             auto t2 = std::chrono::high_resolution_clock::now();
361             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
362         }
363     }
364     average = total / (1000.0 * count);
365     g_logLevel = LOG_DEBUG;
366     HILOG_DEBUG("avg cost 008: %f us", average);
367     EXPECT_LT(average, 500);
368 };
369 
370 /*
371  * @tc.name: ResourceManagerPerformanceFuncTest009
372  * @tc.desc: Test GetStringArrayById
373  * @tc.type: FUNC
374  */
375 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest009, TestSize.Level1)
376 {
377     if (rm == nullptr) {
378         EXPECT_TRUE(false);
379         return;
380     }
381     unsigned long long total = 0;
382     double average = 0;
383     int id = GetResId("size", ResType::STRINGARRAY);
384     ASSERT_TRUE(id > 0);
385 
386     std::vector<std::string> outValue;
387     for (int k = 0; k < 1000; ++k) {
388         auto t1 = std::chrono::high_resolution_clock::now();
389         rm->GetStringArrayById(id, outValue);
390         auto t2 = std::chrono::high_resolution_clock::now();
391         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
392     }
393     average = total / 1000.0;
394     g_logLevel = LOG_DEBUG;
395     HILOG_DEBUG("avg cost 009: %f us", average);
396     EXPECT_LT(average, 500);
397 };
398 
399 /*
400  * @tc.name: ResourceManagerPerformanceFuncTest010
401  * @tc.desc: Test GetStringArrayByName
402  * @tc.type: FUNC
403  */
404 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest010, TestSize.Level1)
405 {
406     if (rm == nullptr) {
407         EXPECT_TRUE(false);
408         return;
409     }
410     unsigned long long total = 0;
411     double average = 0;
412     std::vector<std::string> outValue;
413     for (int k = 0; k < 1000; ++k) {
414         auto t1 = std::chrono::high_resolution_clock::now();
415         rm->GetStringArrayByName("size", outValue);
416         auto t2 = std::chrono::high_resolution_clock::now();
417         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
418     }
419     average = total / 1000.0;
420     g_logLevel = LOG_DEBUG;
421     HILOG_DEBUG("avg cost 010: %f us", average);
422     EXPECT_LT(average, 500);
423 };
424 
425 /*
426  * @tc.name: ResourceManagerPerformanceFuncTest011
427  * @tc.desc: Test GetPatternById
428  * @tc.type: FUNC
429  */
430 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest011, TestSize.Level1)
431 {
432     if (rm == nullptr) {
433         EXPECT_TRUE(false);
434         return;
435     }
436     unsigned long long total = 0;
437     double average = 0;
438     string name[] = {"base", "child"};
439     vector<uint32_t> ids;
440     int count = 2;
441     for (int i = 0; i < count; ++i) {
442         int id = GetResId(name[i], ResType::PATTERN);
443         ASSERT_TRUE(id > 0);
444         ids.push_back(static_cast<uint32_t>(id));
445     }
446     std::map<std::string, std::string> outValue;
447     for (int k = 0; k < 1000; ++k) {
448         for (int i = 0; i < count; ++i) {
449             auto t1 = std::chrono::high_resolution_clock::now();
450             rm->GetPatternById(ids[i], outValue);
451             auto t2 = std::chrono::high_resolution_clock::now();
452             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
453         }
454     }
455     average = total / (1000.0 * count);
456     g_logLevel = LOG_DEBUG;
457     HILOG_DEBUG("avg cost 011: %f us", average);
458     EXPECT_LT(average, 500);
459 };
460 
461 /*
462  * @tc.name: ResourceManagerPerformanceFuncTest012
463  * @tc.desc: Test GetPatternByName
464  * @tc.type: FUNC
465  */
466 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest012, TestSize.Level1)
467 {
468     if (rm == nullptr) {
469         EXPECT_TRUE(false);
470         return;
471     }
472     unsigned long long total = 0;
473     double average = 0;
474     string name[] = {"base", "child"};
475     int count = 2;
476     std::map<std::string, std::string> outValue;
477     for (int k = 0; k < 1000; ++k) {
478         for (int i = 0; i < count; ++i) {
479             auto t1 = std::chrono::high_resolution_clock::now();
480             rm->GetPatternByName(name[i].c_str(), outValue);
481             auto t2 = std::chrono::high_resolution_clock::now();
482             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
483         }
484     }
485     average = total / (1000.0 * count);
486     g_logLevel = LOG_DEBUG;
487     HILOG_DEBUG("avg cost 012: %f us", average);
488     EXPECT_LT(average, 500);
489 };
490 
491 /*
492  * @tc.name: ResourceManagerPerformanceFuncTest013
493  * @tc.desc: Test GetPluralStringById
494  * @tc.type: FUNC
495  */
496 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest013, TestSize.Level1)
497 {
498     if (rm == nullptr) {
499         EXPECT_TRUE(false);
500         return;
501     }
502     unsigned long long total = 0;
503     double average = 0;
504     int quantity[] = {1, 100};
505     int count = 2;
506     int id = GetResId("eat_apple", ResType::PLURALS);
507     ASSERT_TRUE(id > 0);
508 
509     string outValue;
510     for (int k = 0; k < 1000; ++k) {
511         for (int i = 0; i < count; ++i) {
512             auto t1 = std::chrono::high_resolution_clock::now();
513             rm->GetPluralStringById(id, quantity[i], outValue);
514             auto t2 = std::chrono::high_resolution_clock::now();
515             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
516         }
517     }
518     average = total / (1000.0 * count);
519     g_logLevel = LOG_DEBUG;
520     HILOG_DEBUG("avg cost 013: %f us", average);
521     EXPECT_LT(average, 500);
522 };
523 
524 /*
525  * @tc.name: ResourceManagerPerformanceFuncTest014
526  * @tc.desc: Test GetPluralStringByName
527  * @tc.type: FUNC
528  */
529 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest014, TestSize.Level1)
530 {
531     if (rm == nullptr) {
532         EXPECT_TRUE(false);
533         return;
534     }
535     unsigned long long total = 0;
536     double average = 0;
537     int quantity[] = {1, 100};
538     int count = 2;
539     string outValue;
540     for (int k = 0; k < 1000; ++k) {
541         for (int i = 0; i < count; ++i) {
542             auto t1 = std::chrono::high_resolution_clock::now();
543             rm->GetPluralStringByName("eat_apple", quantity[i], outValue);
544             auto t2 = std::chrono::high_resolution_clock::now();
545             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
546         }
547     }
548     average = total / (1000.0 * count);
549     g_logLevel = LOG_DEBUG;
550     HILOG_DEBUG("avg cost 014: %f us", average);
551     EXPECT_LT(average, 500);
552 };
553 
554 /*
555  * @tc.name: ResourceManagerPerformanceFuncTest015
556  * @tc.desc: Test GetPluralStringByIdFormat
557  * @tc.type: FUNC
558  */
559 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest015, TestSize.Level1)
560 {
561     if (rm == nullptr) {
562         EXPECT_TRUE(false);
563         return;
564     }
565     unsigned long long total = 0;
566     double average = 0;
567     int quantity[] = {1, 100};
568     int count = 2;
569     int id = GetResId("eat_apple", ResType::PLURALS);
570     ASSERT_TRUE(id > 0);
571 
572     string outValue;
573     for (int k = 0; k < 1000; ++k) {
574         for (int i = 0; i < count; ++i) {
575             auto t1 = std::chrono::high_resolution_clock::now();
576             rm->GetPluralStringByIdFormat(outValue, id, quantity[i], quantity[i]);
577             auto t2 = std::chrono::high_resolution_clock::now();
578             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
579         }
580     }
581     average = total / (1000.0 * count);
582     g_logLevel = LOG_DEBUG;
583     HILOG_DEBUG("avg cost 015: %f us", average);
584     EXPECT_LT(average, 500);
585 };
586 
587 /*
588  * @tc.name: ResourceManagerPerformanceFuncTest016
589  * @tc.desc: Test GetPluralStringByNameFormat
590  * @tc.type: FUNC
591  */
592 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest016, TestSize.Level1)
593 {
594     if (rm == nullptr) {
595         EXPECT_TRUE(false);
596         return;
597     }
598     unsigned long long total = 0;
599     double average = 0;
600     int quantity[] = {1, 100};
601     int count = 2;
602     string outValue;
603     for (int k = 0; k < 1000; ++k) {
604         for (int i = 0; i < count; ++i) {
605             auto t1 = std::chrono::high_resolution_clock::now();
606             rm->GetPluralStringByNameFormat(outValue, "eat_apple", quantity[i], quantity[i]);
607             auto t2 = std::chrono::high_resolution_clock::now();
608             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
609         }
610     }
611     average = total / (1000.0 * count);
612     g_logLevel = LOG_DEBUG;
613     HILOG_DEBUG("avg cost 016: %f us", average);
614     EXPECT_LT(average, 500);
615 };
616 
617 /*
618  * @tc.name: ResourceManagerPerformanceFuncTest017
619  * @tc.desc: Test GetThemeById
620  * @tc.type: FUNC
621  */
622 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest017, TestSize.Level1)
623 {
624     if (rm == nullptr) {
625         EXPECT_TRUE(false);
626         return;
627     }
628     unsigned long long total = 0;
629     double average = 0;
630     int id = GetResId("app_theme", ResType::THEME);
631     ASSERT_TRUE(id > 0);
632 
633     std::map<std::string, std::string> outValue;
634     for (int k = 0; k < 1000; ++k) {
635         auto t1 = std::chrono::high_resolution_clock::now();
636         rm->GetThemeById(id, outValue);
637         auto t2 = std::chrono::high_resolution_clock::now();
638         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
639     }
640     average = total / 1000.0;
641     g_logLevel = LOG_DEBUG;
642     HILOG_DEBUG("avg cost 017: %f us", average);
643     EXPECT_LT(average, 500);
644 };
645 
646 /*
647  * @tc.name: ResourceManagerPerformanceFuncTest018
648  * @tc.desc: Test GetThemeByName
649  * @tc.type: FUNC
650  */
651 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest018, TestSize.Level1)
652 {
653     if (rm == nullptr) {
654         EXPECT_TRUE(false);
655         return;
656     }
657     unsigned long long total = 0;
658     double average = 0;
659     std::map<std::string, std::string> outValue;
660     for (int k = 0; k < 1000; ++k) {
661         auto t1 = std::chrono::high_resolution_clock::now();
662         rm->GetThemeByName("app_theme", outValue);
663         auto t2 = std::chrono::high_resolution_clock::now();
664         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
665     }
666     average = total / 1000.0;
667     g_logLevel = LOG_DEBUG;
668     HILOG_DEBUG("avg cost 018: %f us", average);
669     EXPECT_LT(average, 500);
670 };
671 
672 /*
673  * @tc.name: ResourceManagerPerformanceFuncTest019
674  * @tc.desc: Test GetBooleanById
675  * @tc.type: FUNC
676  */
677 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest019, TestSize.Level1)
678 {
679     if (rm == nullptr) {
680         EXPECT_TRUE(false);
681         return;
682     }
683     unsigned long long total = 0;
684     double average = 0;
685     int id = GetResId("boolean_1", ResType::BOOLEAN);
686     ASSERT_TRUE(id > 0);
687 
688     bool outValue = true;
689     for (int k = 0; k < 1000; ++k) {
690         auto t1 = std::chrono::high_resolution_clock::now();
691         rm->GetBooleanById(id, outValue);
692         auto t2 = std::chrono::high_resolution_clock::now();
693         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
694     }
695     average = total / 1000.0;
696     g_logLevel = LOG_DEBUG;
697     HILOG_DEBUG("avg cost 019: %f us", average);
698     EXPECT_LT(average, 500);
699 };
700 
701 /*
702  * @tc.name: ResourceManagerPerformanceFuncTest020
703  * @tc.desc: Test GetBooleanByName
704  * @tc.type: FUNC
705  */
706 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest020, TestSize.Level1)
707 {
708     if (rm == nullptr) {
709         EXPECT_TRUE(false);
710         return;
711     }
712     unsigned long long total = 0;
713     double average = 0;
714     bool outValue = true;
715     for (int k = 0; k < 1000; ++k) {
716         auto t1 = std::chrono::high_resolution_clock::now();
717         rm->GetBooleanByName("boolean_1", outValue);
718         auto t2 = std::chrono::high_resolution_clock::now();
719         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
720     }
721     average = total / 1000.0;
722     g_logLevel = LOG_DEBUG;
723     HILOG_DEBUG("avg cost 020: %f us", average);
724     EXPECT_LT(average, 500);
725 };
726 
727 /*
728  * @tc.name: ResourceManagerPerformanceFuncTest021
729  * @tc.desc: Test GetIntegerById
730  * @tc.type: FUNC
731  */
732 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest021, TestSize.Level1)
733 {
734     if (rm == nullptr) {
735         EXPECT_TRUE(false);
736         return;
737     }
738     unsigned long long total = 0;
739     double average = 0;
740     int id = GetResId("integer_1", ResType::INTEGER);
741     ASSERT_TRUE(id > 0);
742 
743     int outValue = 0;
744     for (int k = 0; k < 1000; ++k) {
745         auto t1 = std::chrono::high_resolution_clock::now();
746         rm->GetIntegerById(id, outValue);
747         auto t2 = std::chrono::high_resolution_clock::now();
748         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
749     }
750     average = total / 1000.0;
751     g_logLevel = LOG_DEBUG;
752     HILOG_DEBUG("avg cost 021: %f us", average);
753     EXPECT_LT(average, 500);
754 };
755 
756 /*
757  * @tc.name: ResourceManagerPerformanceFuncTest022
758  * @tc.desc: Test GetIntegerByName
759  * @tc.type: FUNC
760  */
761 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest022, TestSize.Level1)
762 {
763     if (rm == nullptr) {
764         EXPECT_TRUE(false);
765         return;
766     }
767     unsigned long long total = 0;
768     double average = 0;
769     int outValue = 0;
770     for (int k = 0; k < 1000; ++k) {
771         auto t1 = std::chrono::high_resolution_clock::now();
772         rm->GetIntegerByName("integer_ref", outValue);
773         auto t2 = std::chrono::high_resolution_clock::now();
774         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
775     }
776     average = total / 1000.0;
777     g_logLevel = LOG_DEBUG;
778     HILOG_DEBUG("avg cost 022: %f us", average);
779     EXPECT_LT(average, 500);
780 };
781 
782 /*
783  * @tc.name: ResourceManagerPerformanceFuncTest023
784  * @tc.desc: Test GetFloatById
785  * @tc.type: FUNC
786  */
787 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest023, TestSize.Level1)
788 {
789     if (rm == nullptr) {
790         EXPECT_TRUE(false);
791         return;
792     }
793     unsigned long long total = 0;
794     double average = 0;
795     int id = GetResId("width_appBar_backButton_touchTarget", ResType::FLOAT);
796     ASSERT_TRUE(id > 0);
797 
798     float outValue = 0.0;
799     for (int k = 0; k < 1000; ++k) {
800         auto t1 = std::chrono::high_resolution_clock::now();
801         rm->GetFloatById(id, outValue);
802         auto t2 = std::chrono::high_resolution_clock::now();
803         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
804     }
805     average = total / 1000.0;
806     g_logLevel = LOG_DEBUG;
807     HILOG_DEBUG("avg cost 023: %f us", average);
808     EXPECT_LT(average, 500);
809 };
810 
811 /*
812  * @tc.name: ResourceManagerPerformanceFuncTest024
813  * @tc.desc: Test GetFloatByName
814  * @tc.type: FUNC
815  */
816 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest024, TestSize.Level1)
817 {
818     if (rm == nullptr) {
819         EXPECT_TRUE(false);
820         return;
821     }
822     unsigned long long total = 0;
823     double average = 0;
824     float outValue = 0;
825     for (int k = 0; k < 1000; ++k) {
826         auto t1 = std::chrono::high_resolution_clock::now();
827         rm->GetFloatByName("width_appBar_backButton_touchTarget", outValue);
828         auto t2 = std::chrono::high_resolution_clock::now();
829         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
830     }
831     average = total / 1000.0;
832     g_logLevel = LOG_DEBUG;
833     HILOG_DEBUG("avg cost 024: %f us", average);
834     EXPECT_LT(average, 500);
835 };
836 
837 /*
838  * @tc.name: ResourceManagerPerformanceFuncTest025
839  * @tc.desc: Test GetIntArrayById
840  * @tc.type: FUNC
841  */
842 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest025, TestSize.Level1)
843 {
844     if (rm == nullptr) {
845         EXPECT_TRUE(false);
846         return;
847     }
848     unsigned long long total = 0;
849     double average = 0;
850     int id = GetResId("intarray_1", ResType::INTARRAY);
851     ASSERT_TRUE(id > 0);
852 
853     std::vector<int> outValue;
854     for (int k = 0; k < 1000; ++k) {
855         auto t1 = std::chrono::high_resolution_clock::now();
856         rm->GetIntArrayById(id, outValue);
857         auto t2 = std::chrono::high_resolution_clock::now();
858         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
859     }
860     average = total / 1000.0;
861     g_logLevel = LOG_DEBUG;
862     HILOG_DEBUG("avg cost 025: %f us", average);
863     EXPECT_LT(average, 500);
864 };
865 
866 /*
867  * @tc.name: ResourceManagerPerformanceFuncTest026
868  * @tc.desc: Test GetIntArrayByName
869  * @tc.type: FUNC
870  */
871 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest026, TestSize.Level1)
872 {
873     if (rm == nullptr) {
874         EXPECT_TRUE(false);
875         return;
876     }
877     unsigned long long total = 0;
878     double average = 0;
879     std::vector<int> outValue;
880     for (int k = 0; k < 1000; ++k) {
881         auto t1 = std::chrono::high_resolution_clock::now();
882         rm->GetIntArrayByName("intarray_1", outValue);
883         auto t2 = std::chrono::high_resolution_clock::now();
884         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
885     }
886     average = total / 1000.0;
887     g_logLevel = LOG_DEBUG;
888     HILOG_DEBUG("avg cost 026: %f us", average);
889     EXPECT_LT(average, 500);
890 };
891 
892 /*
893  * @tc.name: ResourceManagerPerformanceFuncTest027
894  * @tc.desc: Test GetColorById
895  * @tc.type: FUNC
896  */
897 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest027, TestSize.Level1)
898 {
899     if (rm == nullptr) {
900         EXPECT_TRUE(false);
901         return;
902     }
903     unsigned long long total = 0;
904     double average = 0;
905     int id = GetResId("divider_color", ResType::COLOR);
906     ASSERT_TRUE(id > 0);
907 
908     uint32_t outValue;
909     for (int k = 0; k < 1000; ++k) {
910         auto t1 = std::chrono::high_resolution_clock::now();
911         rm->GetColorById(id, outValue);
912         auto t2 = std::chrono::high_resolution_clock::now();
913         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
914     }
915     average = total / 1000.0;
916     g_logLevel = LOG_DEBUG;
917     HILOG_DEBUG("avg cost 027: %f us", average);
918     EXPECT_LT(average, 500);
919 };
920 
921 /*
922  * @tc.name: ResourceManagerPerformanceFuncTest028
923  * @tc.desc: Test GetColorByName
924  * @tc.type: FUNC
925  */
926 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest028, TestSize.Level1)
927 {
928     if (rm == nullptr) {
929         EXPECT_TRUE(false);
930         return;
931     }
932     unsigned long long total = 0;
933     double average = 0;
934     uint32_t outValue;
935     for (int k = 0; k < 1000; ++k) {
936         auto t1 = std::chrono::high_resolution_clock::now();
937         rm->GetColorByName("divider_color", outValue);
938         auto t2 = std::chrono::high_resolution_clock::now();
939         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
940     }
941     average = total / 1000.0;
942     g_logLevel = LOG_DEBUG;
943     HILOG_DEBUG("avg cost 028: %f us", average);
944     EXPECT_LT(average, 500);
945 };
946 
947 /*
948  * @tc.name: ResourceManagerPerformanceFuncTest029
949  * @tc.desc: Test GetProfileById
950  * @tc.type: FUNC
951  */
952 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest029, TestSize.Level1)
953 {
954     if (rm == nullptr) {
955         EXPECT_TRUE(false);
956         return;
957     }
958     unsigned long long total = 0;
959     double average = 0;
960     int id = GetResId("test_common", ResType::PROF);
961     ASSERT_TRUE(id > 0);
962 
963     string outValue;
964     for (int k = 0; k < 1000; ++k) {
965         auto t1 = std::chrono::high_resolution_clock::now();
966         rm->GetProfileById(id, outValue);
967         auto t2 = std::chrono::high_resolution_clock::now();
968         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
969     }
970     average = total / 1000.0;
971     g_logLevel = LOG_DEBUG;
972     HILOG_DEBUG("avg cost 029: %f us", average);
973     EXPECT_LT(average, 500);
974 };
975 
976 /*
977  * @tc.name: ResourceManagerPerformanceFuncTest030
978  * @tc.desc: Test GetProfileByName
979  * @tc.type: FUNC
980  */
981 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest030, TestSize.Level1)
982 {
983     if (rm == nullptr) {
984         EXPECT_TRUE(false);
985         return;
986     }
987     unsigned long long total = 0;
988     double average = 0;
989     string outValue;
990     for (int k = 0; k < 1000; ++k) {
991         auto t1 = std::chrono::high_resolution_clock::now();
992         rm->GetProfileByName("test_common", outValue);
993         auto t2 = std::chrono::high_resolution_clock::now();
994         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
995     }
996     average = total / 1000.0;
997     g_logLevel = LOG_DEBUG;
998     HILOG_DEBUG("avg cost 030: %f us", average);
999     EXPECT_LT(average, 500);
1000 };
1001 
1002 /*
1003  * @tc.name: ResourceManagerPerformanceFuncTest031
1004  * @tc.desc: Test GetMediaById
1005  * @tc.type: FUNC
1006  */
1007 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest031, TestSize.Level1)
1008 {
1009     if (rm == nullptr) {
1010         EXPECT_TRUE(false);
1011         return;
1012     }
1013     unsigned long long total = 0;
1014     double average = 0;
1015     int id = GetResId("icon", ResType::MEDIA);
1016     ASSERT_TRUE(id > 0);
1017 
1018     string outValue;
1019     for (int k = 0; k < 1000; ++k) {
1020         auto t1 = std::chrono::high_resolution_clock::now();
1021         rm->GetMediaById(id, outValue);
1022         auto t2 = std::chrono::high_resolution_clock::now();
1023         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1024     }
1025     average = total / 1000.0;
1026     g_logLevel = LOG_DEBUG;
1027     HILOG_DEBUG("avg cost 031: %f us", average);
1028     EXPECT_LT(average, 500);
1029 };
1030 
1031 /*
1032  * @tc.name: ResourceManagerPerformanceFuncTest032
1033  * @tc.desc: Test GetMediaByName
1034  * @tc.type: FUNC
1035  */
1036 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest032, TestSize.Level1)
1037 {
1038     if (rm == nullptr) {
1039         EXPECT_TRUE(false);
1040         return;
1041     }
1042     unsigned long long total = 0;
1043     double average = 0;
1044     string outValue;
1045     for (int k = 0; k < 1000; ++k) {
1046         auto t1 = std::chrono::high_resolution_clock::now();
1047         rm->GetMediaByName("icon", outValue);
1048         auto t2 = std::chrono::high_resolution_clock::now();
1049         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1050     }
1051     average = total / 1000.0;
1052     g_logLevel = LOG_DEBUG;
1053     HILOG_DEBUG("avg cost 032: %f us", average);
1054     EXPECT_LT(average, 500);
1055 };
1056