• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TestFormatPluralStringById(const int id, double quantity, const char *cmp);
66 
67     void TestFormatPluralStringByName(const std::string name, double quantity, const char *cmp);
68 
69     RState TestGetFormatPluralStringById(std::string outValue, const int id,
70         ResourceManager::Quantity quantity, ...);
71 
72     RState TestGetFormatPluralStringByName(std::string outValue, const char *name,
73         ResourceManager::Quantity quantity, ...);
74 
75     void TestGetRawFilePathByName(const std::string &name, const std::string &cmp);
76 
77     void AddResource(const char *language, const char *script, const char *region);
78 
79     void AddColorModeResource(DeviceType deviceType, ColorMode colorMode, float screenDensity);
80 
81     void AddHapResource(const char *language, const char *script, const char *region);
82 
83     void TestGetStringArrayById(const char *name);
84 
85     void TestGetStringArrayByName(const char *name);
86 
87     void TestGetStringFormatById(const char *name, const char *cmp);
88 
89     void TestGetStringFormatByName(const char *name, const char *cmp);
90 
91     void TestGetStringFormatById(const char *name,
92         std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp);
93 
94     void TestGetStringFormatByName(const char *name,
95         std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams,  const char *cmp);
96 
97     void TestGetStringFormatByIdWithVaArgs(const char *name, const char *cmp, ...);
98 
99     void TestGetStringFormatByNameWithVaArgs(const char *name, const char *cmp, ...);
100 
101     void TestGetPatternById(const char *name);
102 
103     void TestGetPatternByName(const char *name);
104 
105     void TestGetThemeById(const char *name);
106 
107     void TestGetThemeByName(const char *appTheme, const char *testTheme);
108 
109     void TestGetBooleanByName(const char *boolean1, const char *booleanRef);
110 
111     void TestGetBooleanById(const char *boolean1, const char *booleanRef);
112 
113     void TestGetIntegerByName(const char* integer1, const char* integerRef);
114 
115     void TestGetIntegerById(const char* integer1, const char* integerRef);
116 
117     void TestGetFloatByName(const char* touchTarget, const char* floatRef);
118 
119     void TestGetFloatById(const char* touchTarget, const char* floatRef);
120 
121     void TestGetIntArrayById(const char* intarray1);
122 
123     void TestGetIntArrayByName(const char* intarray1);
124 
125     void TestGetProfileById(HapResource *tmp);
126 
127     void TestGetProfileByName(HapResource *tmp);
128 
129     void TestGetMediaWithDensityById(HapResource *tmp);
130 
131     void TestGetMediaById(HapResource *tmp);
132 
133     void TestGetMediaWithDensityByName(HapResource *tmp);
134 
135     void TestGetMediaByName(HapResource *tmp);
136 
137     void TestGetDrawableInfoWithDensityById(HapResource *tmp);
138 
139     void TestGetDrawableInfoById(HapResource *tmp);
140 
141     void TestGetDrawableInfoWithDensityByName(HapResource *tmp);
142 
143     void TestGetDrawableInfoByName(HapResource *tmp);
144 
145     void TestGetResourceLimitKeys(uint32_t expectedLimitKeys);
146 };
147 } // namespace Resource
148 } // namespace Global
149 } // namespace OHOS
150 #endif
151