1 /*
2  * Copyright (c) 2023 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 "res_config.h"
25 #include "resource_manager.h"
26 #include "resource_manager_impl.h"
27 #include "test_common.h"
28 #include "utils/errors.h"
29 #include "utils/string_utils.h"
30 #include "utils/utils.h"
31 
32 namespace OHOS {
33 namespace Global {
34 namespace Resource {
35 class ResourceManagerTestCommon {
36 public:
37     static void SetUpTestCase(void);
38 
39     static void TearDownTestCase(void);
40 
41     void SetUp();
42 
43     void TearDown();
44 
45     explicit ResourceManagerTestCommon(ResourceManager *rm);
46 
47     explicit ResourceManagerTestCommon(std::shared_ptr<ResourceManager> rm);
48 
49     ~ResourceManagerTestCommon();
50 public:
51     ResourceManager *rm;
52 
53     std::shared_ptr<ResConfigImpl> defaultResConfig = InitDefaultResConfig();
54 
55     int GetResId(const std::string &name, ResType resType);
56 
57     void TestStringByName(const char *name, const char *cmp);
58 
59     void TestStringById(const char *name, const char *cmp);
60 
61     void TestPluralStringById(int quantity, const char *cmp, bool format = false);
62 
63     void TestPluralStringByName(int quantity, const char *cmp, bool format = false);
64 
65     void TestGetRawFilePathByName(const std::string &name, const std::string &cmp);
66 
67     void AddResource(const char *language, const char *script, const char *region);
68 
69     void AddColorModeResource(DeviceType deviceType, ColorMode colorMode, float screenDensity);
70 
71     void AddHapResource(const char *language, const char *script, const char *region);
72 
73     void TestGetStringArrayById(const char *name);
74 
75     void TestGetStringArrayByName(const char *name);
76 
77     void TestGetStringFormatById(const char *name, const char *cmp);
78 
79     void TestGetStringFormatByName(const char *name, const char *cmp);
80 
81     void TestGetStringFormatById(const char *name,
82         std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp);
83 
84     void TestGetStringFormatByName(const char *name,
85         std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp);
86 
87     void TestGetStringFormatByIdWithVaArgs(const char *name, const char *cmp, ...);
88 
89     void TestGetStringFormatByNameWithVaArgs(const char *name, const char *cmp, ...);
90 
91     void TestGetPatternById(const char *name);
92 
93     void TestGetPatternByName(const char *name);
94 
95     void TestGetThemeById(const char *name);
96 
97     void TestGetThemeByName(const char *appTheme, const char *testTheme);
98 
99     void TestGetBooleanByName(const char *boolean1, const char *booleanRef);
100 
101     void TestGetBooleanById(const char *boolean1, const char *booleanRef);
102 
103     void TestGetIntegerByName(const char* integer1, const char* integerRef);
104 
105     void TestGetIntegerById(const char* integer1, const char* integerRef);
106 
107     void TestGetFloatByName(const char* touchTarget, const char* floatRef);
108 
109     void TestGetFloatById(const char* touchTarget, const char* floatRef);
110 
111     void TestGetIntArrayById(const char* intarray1);
112 
113     void TestGetIntArrayByName(const char* intarray1);
114 
115     void TestGetProfileById(HapResource *tmp);
116 
117     void TestGetProfileByName(HapResource *tmp);
118 
119     void TestGetMediaWithDensityById(HapResource *tmp);
120 
121     void TestGetMediaById(HapResource *tmp);
122 
123     void TestGetMediaWithDensityByName(HapResource *tmp);
124 
125     void TestGetMediaByName(HapResource *tmp);
126 
127     void TestGetDrawableInfoWithDensityById(HapResource *tmp);
128 
129     void TestGetDrawableInfoById(HapResource *tmp);
130 
131     void TestGetDrawableInfoWithDensityByName(HapResource *tmp);
132 
133     void TestGetDrawableInfoByName(HapResource *tmp);
134 
135     void TestGetResourceLimitKeys(uint32_t expectedLimitKeys);
136 };
137 } // namespace Resource
138 } // namespace Global
139 } // namespace OHOS
140 #endif
141