1 /*
2  * Copyright (c) 2021-2022 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<HapResource::IdValues> & idValues)42 void PrintIdValues(const std::shared_ptr<HapResource::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, limitPath->GetFolder().c_str(),
50             limitPath->GetIdItem()->ToString().c_str());
51     }
52 }
53 
PrintMapString(const std::map<std::string,std::string> & value)54 void PrintMapString(const std::map<std::string, std::string> &value)
55 {
56     auto iter = value.begin();
57     for (; iter != value.end(); ++iter) {
58         std::string key = iter->first;
59         std::string val = iter->second;
60         RESMGR_HILOGD(RESMGR_TAG, "%s : %s", key.c_str(), val.c_str());
61     }
62 }
63 
PrintVectorString(const std::vector<std::string> & value)64 void PrintVectorString(const std::vector<std::string> &value)
65 {
66     for (size_t i = 0; i < value.size(); ++i) {
67         std::string val = value[i];
68         RESMGR_HILOGD(RESMGR_TAG, "%zu : %s", i, val.c_str());
69     }
70 }
71 
CreateResConfig(const char * language,const char * script,const char * region)72 ResConfig *CreateResConfig(const char *language, const char *script, const char *region)
73 {
74     ResConfig *resConfig = CreateResConfig();
75     if (resConfig == nullptr) {
76         return nullptr;
77     }
78     resConfig->SetLocaleInfo(language, script, region);
79     return resConfig;
80 }
81 
GetLocale(const char * language,const char * script,const char * region)82 Locale GetLocale(const char *language, const char *script, const char *region)
83 {
84     UErrorCode errCode = U_ZERO_ERROR;
85     Locale locale  = icu::LocaleBuilder().setLanguage(language)
86         .setRegion(region).setScript(script).build(errCode);
87     return locale;
88 }
89 
InitDefaultResConfig()90 std::shared_ptr<ResConfigImpl> InitDefaultResConfig()
91 {
92     std::shared_ptr<ResConfigImpl> resConfig = std::make_shared<ResConfigImpl>();
93     if (resConfig == nullptr) {
94         return nullptr;
95     }
96     resConfig->SetAppDarkRes(true);
97     return resConfig;
98 }
99 } // namespace Resource
100 } // namespace Global
101 } // namespace OHOS