1 /*
2 * Copyright (c) 2021-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 "test_common.h"
17
18 #include <climits>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <unistd.h>
22
23 #include "hilog_wrapper.h"
24 #include "utils/errors.h"
25
26 #if defined(__linux__)
27 #include <malloc.h>
28 #endif
29
30 namespace OHOS {
31 namespace Global {
32 namespace Resource {
FormatFullPath(const char * fileRelativePath)33 std::string FormatFullPath(const char *fileRelativePath)
34 {
35 const char *value = "/data/test";
36 std::string result(value);
37 result.append("/");
38 result.append(fileRelativePath);
39 return result;
40 }
41
PrintIdValues(const std::shared_ptr<IdValues> & idValues)42 void PrintIdValues(const std::shared_ptr<IdValues> &idValues)
43 {
44 if (idValues == nullptr) {
45 return;
46 }
47 for (size_t i = 0; i < idValues->GetLimitPathsConst().size(); ++i) {
48 auto limitPath = idValues->GetLimitPathsConst()[i];
49 RESMGR_HILOGD(RESMGR_TAG, "%zu: folder is: %s, value: %s", i,
50 limitPath->GetResConfig()->ToString().c_str(),
51 limitPath->GetIdItem()->ToString().c_str());
52 }
53 }
54
PrintMapString(const std::map<std::string,std::string> & value)55 void PrintMapString(const std::map<std::string, std::string> &value)
56 {
57 auto iter = value.begin();
58 for (; iter != value.end(); ++iter) {
59 std::string key = iter->first;
60 std::string val = iter->second;
61 RESMGR_HILOGD(RESMGR_TAG, "%s : %s", key.c_str(), val.c_str());
62 }
63 }
64
PrintVectorString(const std::vector<std::string> & value)65 void PrintVectorString(const std::vector<std::string> &value)
66 {
67 for (size_t i = 0; i < value.size(); ++i) {
68 std::string val = value[i];
69 RESMGR_HILOGD(RESMGR_TAG, "%zu : %s", i, val.c_str());
70 }
71 }
72
CreateResConfig(const char * language,const char * script,const char * region)73 ResConfig *CreateResConfig(const char *language, const char *script, const char *region)
74 {
75 ResConfig *resConfig = CreateResConfig();
76 if (resConfig == nullptr) {
77 return nullptr;
78 }
79 resConfig->SetLocaleInfo(language, script, region);
80 return resConfig;
81 }
82
GetLocale(const char * language,const char * script,const char * region)83 Locale GetLocale(const char *language, const char *script, const char *region)
84 {
85 UErrorCode errCode = U_ZERO_ERROR;
86 Locale locale = icu::LocaleBuilder().setLanguage(language)
87 .setRegion(region).setScript(script).build(errCode);
88 return locale;
89 }
90
InitDefaultResConfig()91 std::shared_ptr<ResConfigImpl> InitDefaultResConfig()
92 {
93 std::shared_ptr<ResConfigImpl> resConfig = std::make_shared<ResConfigImpl>();
94 if (resConfig == nullptr) {
95 return nullptr;
96 }
97 resConfig->SetAppDarkRes(true);
98 return resConfig;
99 }
100 } // namespace Resource
101 } // namespace Global
102 } // namespace OHOS