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 = "/user/data";
36 std::string result(value);
37 result.append("/");
38 result.append(fileRelativePath);
39 return result;
40 }
41
PrintIdValues(const HapResource::IdValues * idValues)42 void PrintIdValues(const HapResource::IdValues *idValues)
43 {
44 for (size_t i = 0; i < idValues->GetLimitPathsConst().size(); ++i) {
45 auto limitPath = idValues->GetLimitPathsConst()[i];
46 HILOG_DEBUG("%zu: folder is: %s, value: %s", i, limitPath->GetFolder().c_str(),
47 limitPath->GetIdItem()->ToString().c_str());
48 }
49 }
50
PrintMapString(const std::map<std::string,std::string> & value)51 void PrintMapString(const std::map<std::string, std::string> &value)
52 {
53 auto iter = value.begin();
54 for (; iter != value.end(); ++iter) {
55 std::string key = iter->first;
56 std::string val = iter->second;
57 HILOG_DEBUG("%s : %s", key.c_str(), val.c_str());
58 }
59 }
60
PrintVectorString(const std::vector<std::string> & value)61 void PrintVectorString(const std::vector<std::string> &value)
62 {
63 for (size_t i = 0; i < value.size(); ++i) {
64 std::string val = value[i];
65 HILOG_DEBUG("%zu : %s", i, val.c_str());
66 }
67 }
68
CreateResConfig(const char * language,const char * script,const char * region)69 ResConfig *CreateResConfig(const char *language, const char *script, const char *region)
70 {
71 ResConfig *resConfig = CreateResConfig();
72 if (resConfig == nullptr) {
73 return nullptr;
74 }
75 resConfig->SetLocaleInfo(language, script, region);
76 return resConfig;
77 }
78 } // namespace Resource
79 } // namespace Global
80 } // namespace OHOS
81