• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_COMMON_H
17 #define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_COMMON_H
18 
19 #include <climits>
20 #include <cstring>
21 #include <gtest/gtest.h>
22 #define private public
23 
24 #include "hap_resource_v1.h"
25 #include "hap_resource_v2.h"
26 #include "res_config.h"
27 #include "resource_manager.h"
28 #include "resource_manager_impl.h"
29 #include "test_common.h"
30 #include "utils/errors.h"
31 #include "utils/string_utils.h"
32 #include "utils/utils.h"
33 
34 namespace OHOS {
35 namespace Global {
36 namespace Resource {
37 class ResourceManagerTestCommon {
38 public:
39     static void SetUpTestCase(void);
40 
41     static void TearDownTestCase(void);
42 
43     void SetUp();
44 
45     void TearDown();
46 
47     explicit ResourceManagerTestCommon(ResourceManager *rm);
48 
49     explicit ResourceManagerTestCommon(std::shared_ptr<ResourceManager> rm);
50 
51     ~ResourceManagerTestCommon();
52 public:
53     ResourceManager *rm;
54 
55     std::shared_ptr<ResConfigImpl> defaultResConfig = InitDefaultResConfig();
56 
57     int GetResId(const std::string &name, ResType resType);
58 
59     void TestStringByName(const char *name, const char *cmp);
60 
61     void TestStringById(const char *name, const char *cmp);
62 
63     void TestPluralStringById(int quantity, const char *cmp, bool format = false);
64 
65     void TestPluralStringByName(int quantity, const char *cmp, bool format = false);
66 
67     void TestFormatPluralStringById(const int id, double quantity, const char *cmp);
68 
69     void TestFormatPluralStringByName(const std::string name, double quantity, const char *cmp);
70 
71     RState TestGetFormatPluralStringById(std::string outValue, const int id,
72         ResourceManager::Quantity quantity, ...);
73 
74     RState TestGetFormatPluralStringByName(std::string outValue, const char *name,
75         ResourceManager::Quantity quantity, ...);
76 
77     void TestGetRawFilePathByName(const std::string &name, const std::string &cmp);
78 
79     void AddResource(const char *language, const char *script, const char *region);
80 
81     void AddColorModeResource(DeviceType deviceType, ColorMode colorMode, float screenDensity);
82 
83     void AddHapResource(const char *language, const char *script, const char *region);
84 
85     void TestGetStringArrayById(const char *name);
86 
87     void TestGetStringArrayByName(const char *name);
88 
89     void TestGetStringFormatById(const char *name, const char *cmp);
90 
91     void TestGetStringFormatByName(const char *name, const char *cmp);
92 
93     void TestGetStringFormatById(const char *name,
94         std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp);
95 
96     void TestGetStringFormatByName(const char *name,
97         std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp);
98 
99     void TestGetStringFormatByIdWithVaArgs(const char *name, const char *cmp, ...);
100 
101     void TestGetStringFormatByNameWithVaArgs(const char *name, const char *cmp, ...);
102 
103     void TestGetPatternById(const char *name);
104 
105     void TestGetPatternByName(const char *name);
106 
107     void TestGetThemeById(const char *name);
108 
109     void TestGetThemeByName(const char *appTheme, const char *testTheme);
110 
111     void TestGetBooleanByName(const char *boolean1, const char *booleanRef);
112 
113     void TestGetBooleanById(const char *boolean1, const char *booleanRef);
114 
115     void TestGetIntegerByName(const char* integer1, const char* integerRef);
116 
117     void TestGetIntegerById(const char* integer1, const char* integerRef);
118 
119     void TestGetFloatByName(const char* touchTarget, const char* floatRef);
120 
121     void TestGetFloatById(const char* touchTarget, const char* floatRef);
122 
123     void TestGetIntArrayById(const char* intarray1);
124 
125     void TestGetIntArrayByName(const char* intarray1);
126 
127     void TestGetProfileById(HapResourceV1 *tmp);
128 
129     void TestGetProfileById(HapResourceV2 *tmp);
130 
131     void TestGetProfileByName(HapResourceV1 *tmp);
132 
133     void TestGetProfileByName(HapResourceV2 *tmp);
134 
135     void TestGetMediaWithDensityById(HapResourceV1 *tmp);
136 
137     void TestGetMediaWithDensityById(HapResourceV2 *tmp);
138 
139     void TestGetMediaById(HapResourceV1 *tmp);
140 
141     void TestGetMediaById(HapResourceV2 *tmp);
142 
143     void TestGetMediaWithDensityByName(HapResourceV1 *tmp);
144 
145     void TestGetMediaWithDensityByName(HapResourceV2 *tmp);
146 
147     void TestGetMediaByName(HapResourceV1 *tmp);
148 
149     void TestGetMediaByName(HapResourceV2 *tmp);
150 
151     void TestGetDrawableInfoWithDensityById(HapResourceV1 *tmp);
152 
153     void TestGetDrawableInfoWithDensityById(HapResourceV2 *tmp);
154 
155     void TestGetDrawableInfoById(HapResourceV1 *tmp);
156 
157     void TestGetDrawableInfoById(HapResourceV2 *tmp);
158 
159     void TestGetDrawableInfoWithDensityByName(HapResourceV1 *tmp);
160 
161     void TestGetDrawableInfoWithDensityByName(HapResourceV2 *tmp);
162 
163     void TestGetDrawableInfoByName(HapResourceV1 *tmp);
164 
165     void TestGetDrawableInfoByName(HapResourceV2 *tmp);
166 
167     void TestGetResourceLimitKeys(uint32_t expectedLimitKeys);
168 };
169 } // namespace Resource
170 } // namespace Global
171 } // namespace OHOS
172 #endif
173