!412 资源超大源文件整改

Merge pull request !412 from maoziduanl/master
This commit is contained in:
openharmony_ci 2023-08-07 01:34:09 +00:00 committed by Gitee
commit 6449b02703
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 4924 additions and 4560 deletions

View File

@ -29,6 +29,10 @@ ohos_unittest("resmgr_test") {
"unittest/common/res_desc_test.cpp",
"unittest/common/resource_manager_performance_test.cpp",
"unittest/common/resource_manager_test.cpp",
"unittest/common/resource_manager_test_common.cpp",
"unittest/common/resource_manager_test_hap.cpp",
"unittest/common/resource_manager_test_media.cpp",
"unittest/common/resource_manager_test_string.cpp",
"unittest/common/string_utils_test.cpp",
"unittest/common/test_common.cpp",
]

View File

@ -140,9 +140,8 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level0)
delete (pResource);
}
void GetIdValuesByNameFuncTest002(const HapResource *pResource)
void GetIdValuesByNameFuncTest002(const HapResource *pResource, int id)
{
int id = pResource->GetIdByName("app_name", ResType::STRING);
std::string name = std::string("app_name");
auto start = CurrentTimeUsec();
auto idValues = pResource->GetIdValuesByName(name, ResType::STRING);
@ -210,7 +209,7 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1)
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name");
}
GetIdValuesByNameFuncTest002(pResource);
GetIdValuesByNameFuncTest002(pResource, id);
delete pResource;
delete rc;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -32,36 +32,6 @@ int ResourceManagerUpdateResConfigTest004(void);
int ResourceManagerUpdateResConfigTest005(void);
int ResourceManagerGetResConfigTest001(void);
int ResourceManagerGetResConfigTest002(void);
int ResourceManagerGetStringByIdTest001(void);
int ResourceManagerGetStringByIdTest002(void);
int ResourceManagerGetStringByIdTest003(void);
int ResourceManagerGetStringByIdTest004(void);
int ResourceManagerGetStringByIdTest005(void);
int ResourceManagerGetStringByNameTest001(void);
int ResourceManagerGetStringByNameTest002(void);
int ResourceManagerGetStringByNameTest003(void);
int ResourceManagerGetStringByNameTest004(void);
int ResourceManagerGetStringByNameTest005(void);
int ResourceManagerGetStringFormatByIdTest001(void);
int ResourceManagerGetStringFormatByIdTest002(void);
int ResourceManagerGetStringFormatByIdTest003(void);
int ResourceManagerGetStringFormatByIdTest004(void);
int ResourceManagerGetStringFormatByIdTest005(void);
int ResourceManagerGetStringFormatByIdTest006(void);
int ResourceManagerGetStringFormatByIdTest007(void);
int ResourceManagerGetStringFormatByIdTest008(void);
int ResourceManagerGetStringFormatByNameTest001(void);
int ResourceManagerGetStringFormatByNameTest002(void);
int ResourceManagerGetStringFormatByNameTest003(void);
int ResourceManagerGetStringFormatByNameTest004(void);
int ResourceManagerGetStringFormatByNameTest005(void);
int ResourceManagerGetStringFormatByNameTest006(void);
int ResourceManagerGetStringFormatByNameTest007(void);
int ResourceManagerGetStringFormatByNameTest008(void);
int ResourceManagerGetStringArrayByIdTest001(void);
int ResourceManagerGetStringArrayByIdTest002(void);
int ResourceManagerGetStringArrayByNameTest001(void);
int ResourceManagerGetStringArrayByNameTest002(void);
int ResourceManagerGetPatternByIdTest001(void);
int ResourceManagerGetPatternByIdTest002(void);
int ResourceManagerGetPatternByIdTest003(void);
@ -70,21 +40,6 @@ int ResourceManagerGetPatternByNameTest001(void);
int ResourceManagerGetPatternByNameTest002(void);
int ResourceManagerGetPatternByNameTest003(void);
int ResourceManagerGetPatternByNameTest004(void);
int ResourceManagerGetPluralStringByIdTest001(void);
int ResourceManagerGetPluralStringByIdTest002(void);
int ResourceManagerGetPluralStringByIdTest003(void);
int ResourceManagerGetPluralStringByIdTest004(void);
int ResourceManagerGetPluralStringByIdTest005(void);
int ResourceManagerGetPluralStringByNameTest001(void);
int ResourceManagerGetPluralStringByNameTest002(void);
int ResourceManagerGetPluralStringByIdFormatTest001(void);
int ResourceManagerGetPluralStringByIdFormatTest002(void);
int ResourceManagerGetPluralStringByIdFormatTest003(void);
int ResourceManagerGetPluralStringByIdFormatTest004(void);
int ResourceManagerGetPluralStringByNameFormatTest001(void);
int ResourceManagerGetPluralStringByNameFormatTest002(void);
int ResourceManagerGetPluralStringByNameFormatTest003(void);
int ResourceManagerGetPluralStringByNameFormatTest004(void);
int ResourceManagerGetThemeByIdTest001(void);
int ResourceManagerGetThemeByIdTest002(void);
int ResourceManagerGetThemeByNameTest001(void);
@ -119,75 +74,10 @@ int ResourceManagerGetColorByNameTest009(void);
int ResourceManagerGetColorByNameTest010(void);
int ResourceManagerGetColorByNameTest011(void);
int ResourceManagerGetColorByNameTest012(void);
int ResourceManagerGetStringByNameForMccMncTest001(void);
int ResourceManagerGetStringByNameForMccMncTest002(void);
int ResourceManagerGetStringByNameForMccMncTest003(void);
int ResourceManagerGetStringByNameForMccMncTest004(void);
int ResourceManagerGetStringByNameForMccMncTest005(void);
int ResourceManagerGetStringByNameForMccMncTest006(void);
int ResourceManagerGetStringByNameForMccMncTest007(void);
int ResourceManagerGetStringByNameForMccMncTest008(void);
int ResourceManagerGetStringByNameForMccMncTest009(void);
int ResourceManagerGetStringByNameForMccMncTest010(void);
int ResourceManagerGetStringByNameForMccMncTest011(void);
int ResourceManagerGetStringByNameForMccMncTest012(void);
int ResourceManagerGetStringByNameForMccMncTest013(void);
int ResourceManagerGetStringByNameForMccMncTest014(void);
int ResourceManagerGetStringByNameForMccMncTest015(void);
int ResourceManagerGetStringByNameForMccMncTest016(void);
int ResourceManagerGetStringByNameForMccMncTest017(void);
int ResourceManagerGetStringByNameForMccMncTest018(void);
int ResourceManagerGetStringByNameForMccMncTest019(void);
int ResourceManagerGetStringByNameForMccMncTest020(void);
int ResourceManagerGetProfileByIdTest001(void);
int ResourceManagerGetProfileByIdTest002(void);
int ResourceManagerGetProfileByNameTest001(void);
int ResourceManagerGetProfileByNameTest002(void);
int ResourceManagerGetMediaByIdTest001(void);
int ResourceManagerGetMediaByIdTest002(void);
int ResourceManagerGetMediaByIdTest003(void);
int ResourceManagerGetMediaByIdTest004(void);
int ResourceManagerGetMediaByIdTest005(void);
int ResourceManagerGetMediaByIdTest006(void);
int ResourceManagerGetMediaByIdTest007(void);
int ResourceManagerGetMediaByIdTest008(void);
int ResourceManagerGetMediaByIdTest009(void);
int ResourceManagerGetMediaByIdTest010(void);
int ResourceManagerGetMediaByIdTest011(void);
int ResourceManagerGetMediaByIdTest012(void);
int ResourceManagerGetMediaByIdTest013(void);
int ResourceManagerGetMediaByIdTest014(void);
int ResourceManagerGetMediaByIdTest015(void);
int ResourceManagerGetMediaByIdTest016(void);
int ResourceManagerGetMediaByIdTest017(void);
int ResourceManagerGetMediaByIdTest018(void);
int ResourceManagerGetMediaByIdTest019(void);
int ResourceManagerGetMediaByIdTest020(void);
int ResourceManagerGetMediaByIdTest021(void);
int ResourceManagerGetMediaByIdTest022(void);
int ResourceManagerGetMediaByIdTest023(void);
int ResourceManagerGetMediaByNameTest001(void);
int ResourceManagerGetMediaByNameTest002(void);
int ResourceManagerGetMediaByNameTest003(void);
int ResourceManagerGetMediaByNameTest004(void);
int ResourceManagerGetMediaByNameTest005(void);
int ResourceManagerGetMediaByNameTest006(void);
int ResourceManagerGetMediaByNameTest007(void);
int ResourceManagerGetMediaByNameTest008(void);
int ResourceManagerGetMediaByNameTest009(void);
int ResourceManagerGetMediaByNameTest010(void);
int ResourceManagerGetMediaByNameTest011(void);
int ResourceManagerGetMediaByNameTest012(void);
int ResourceManagerGetMediaByNameTest013(void);
int ResourceManagerGetMediaByNameTest014(void);
int ResourceManagerGetMediaByNameTest015(void);
int ResourceManagerGetMediaByNameTest016(void);
int ResourceManagerGetMediaByNameTest017(void);
int ResourceManagerGetMediaByNameTest018(void);
int ResourceManagerGetMediaByNameTest019(void);
int ResourceManagerGetMediaByNameTest020(void);
int ResourceManagerGetMediaByNameTest021(void);
int ResourceManagerGetMediaByNameTest022(void);
int ResourceManagerGetStringByIdForInputDeviceTest001(void);
int ResourceManagerGetStringByIdForInputDeviceTest002(void);
int ResourceManagerGetStringByIdForInputDeviceTest003(void);
@ -213,64 +103,6 @@ int ResourceManagerResolveReferenceTest002(void);
int ResourceManagerResolveParentReferenceTest001(void);
int ResourceManagerSameNameTest001(void);
int RawFileTest001(void);
int ResourceManagerAddResourceFromHapTest001(void);
int ResourceManagerGetStringByIdFromHapTest002(void);
int ResourceManagerGetStringByIdFromHapTest003(void);
int ResourceManagerGetStringByNameFromHapTest004(void);
int ResourceManagerGetStringByNameFromHapTest005(void);
int ResourceManagerGetStringFormatByIdFromHapTest006(void);
int ResourceManagerGetStringFormatByNameFromHapTest007(void);
int ResourceManagerGetStringArrayByIdFromHapTest008(void);
int ResourceManagerGetStringArrayByNameFromHapTest009(void);
int ResourceManagerGetPatternByIdFromHapTest0010(void);
int ResourceManagerGetPatternByNameFromHapTest0011(void);
int ResourceManagerGetPluralStringByIdFromHapTest0012(void);
int ResourceManagerGetPluralStringByIdFromHapTest0013(void);
int ResourceManagerGetPluralStringByIdFromHapTest0014(void);
int ResourceManagerGetPluralStringByIdFromHapTest0015(void);
int ResourceManagerGetPluralStringByNameFromHapTest0016(void);
int ResourceManagerGetPluralStringByIdFormatFromHapTest0017(void);
int ResourceManagerGetPluralStringByNameFormatFromHapTest0018(void);
int ResourceManagerGetThemeByIdFromHapTest0019(void);
int ResourceManagerGetThemeByNameFromHapTest0020(void);
int ResourceManagerGetBooleanByIdFromHapTest0021(void);
int ResourceManagerGetBooleanByNameFromHapTest0022(void);
int ResourceManagerGetIntegerByIdFromHapTest0023(void);
int ResourceManagerGetIntegerByNameFromHapTest0024(void);
int ResourceManagerGetFloatByIdFromHapTest0025(void);
int ResourceManagerGetFloatByNameFromHapTest0026(void);
int ResourceManagerGetIntArrayByIdFromHapTest0027(void);
int ResourceManagerGetIntArrayByNameFromHapTest0028(void);
int ResourceManagerGetProfileByIdFromHapTest0029(void);
int ResourceManagerGetProfileByNameFromHapTest0030(void);
int ResourceManagerGetMediaByIdFromHapTest0031(void);
int ResourceManagerGetMediaByIdFromHapTest0032(void);
int ResourceManagerGetMediaByNameFromHapTest0033(void);
int ResourceManagerGetMediaByNameFromHapTest0034(void);
int ResourceManagerGetProfileDataByIdFromHapTest0035(void);
int ResourceManagerGetProfileDataByNameFromHapTest0036(void);
int ResourceManagerGetMediaDataByNameFromHapTest0037(void);
int ResourceManagerGetMediaDataByIdFromHapTest0038(void);
int ResourceManagerGetMediaDataBase64ByNameFromHapTest0039(void);
int ResourceManagerGetMediaDataBase64ByIdFromHapTest0040(void);
int ResourceManagerGetMediaDataByIdFromHapTest0041(void);
int ResourceManagerGetMediaDataByNameFromHapTest0042(void);
int ResourceManagerGetMediaBase64DataByIdFromHapTest0043(void);
int ResourceManagerGetMediaBase64DataByNameFromHapTest0044(void);
int RawFileTestFromHap0045(void);
int RawFileTestFromHap0046(void);
int RawFileTestFromHap0047(void);
int RawFileTestFromHap0048(void);
int ResourceManagerOverlayTest001(void);
int ResourceManagerOverlayTest002(void);
int ResourceManagerOverlayTest003(void);
int ResourceManagerOverlayTest004(void);
int ResourceManagerOverlayTest005(void);
int ResourceManagerOverlayTest006(void);
int ResourceManagerUtilsTest001(void);
int ResourceManagerGetResourceLimitKeysTest001(void);
int ResourceManagerGetResourceLimitKeysTest002(void);
int ResourceManagerGetResourceLimitKeysTest003(void);
} // namespace Resource
} // namespace Global
} // namespace OHOS

View File

@ -0,0 +1,520 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "resource_manager_test_common.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
ResourceManagerTestCommon::ResourceManagerTestCommon(ResourceManager *rm) : rm(rm)
{}
ResourceManagerTestCommon::~ResourceManagerTestCommon()
{}
void ResourceManagerTestCommon::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void ResourceManagerTestCommon::TearDownTestCase(void)
{
// step 2: input testsuit teardown step
}
void ResourceManagerTestCommon::SetUp(void)
{
this->rm = CreateResourceManager();
}
void ResourceManagerTestCommon::TearDown(void)
{
delete this->rm;
}
int ResourceManagerTestCommon::GetResId(std::string name, ResType resType)
{
auto idv = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType);
if (idv.size() == 0) {
return -1;
}
PrintIdValues(idv[0]);
if (idv[0]->GetLimitPathsConst().size() > 0) {
return idv[0]->GetLimitPathsConst()[0]->GetIdItem()->id_;
}
return OBJ_NOT_FOUND;
}
void ResourceManagerTestCommon::TestStringByName(const char *name, const char *cmp)
{
RState rState;
std::string outValue;
rState = rm->GetStringByName(name, outValue);
ASSERT_EQ(SUCCESS, rState);
HILOG_DEBUG("%s : %s", name, outValue.c_str());
ASSERT_EQ(std::string(cmp), outValue);
}
void ResourceManagerTestCommon::TestStringById(const char *name, const char *cmp)
{
RState rState;
std::string outValue;
int id = GetResId(name, ResType::STRING);
ASSERT_TRUE(id > 0);
rState = rm->GetStringById(id, outValue);
ASSERT_EQ(SUCCESS, rState);
ASSERT_EQ(std::string(cmp), outValue);
}
void ResourceManagerTestCommon::AddResource(const char *language, const char *script, const char *region)
{
if (language != nullptr || region != nullptr) {
auto rc = CreateResConfig();
if (rc == nullptr) {
EXPECT_TRUE(false);
return;
}
rc->SetLocaleInfo(language, script, region);
rm->UpdateResConfig(*rc);
delete rc;
}
bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
ASSERT_TRUE(ret);
}
void ResourceManagerTestCommon::AddHapResource(const char *language, const char *script, const char *region)
{
if (language != nullptr || region != nullptr) {
auto rc = CreateResConfig();
if (rc == nullptr) {
EXPECT_TRUE(false);
return;
}
rc->SetLocaleInfo(language, script, region);
rm->UpdateResConfig(*rc);
delete rc;
}
bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str());
ASSERT_TRUE(ret);
}
void ResourceManagerTestCommon::AddColorModeResource(DeviceType deviceType, ColorMode colorMode,
float screenDensity)
{
auto rc = CreateResConfig();
if (rc == nullptr) {
EXPECT_TRUE(false);
return;
}
rc->SetLocaleInfo("zh", nullptr, nullptr);
rc->SetDeviceType(deviceType);
rc->SetColorMode(colorMode);
rc->SetScreenDensity(screenDensity);
rm->UpdateResConfig(*rc);
delete rc;
bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
ASSERT_TRUE(ret);
}
void ResourceManagerTestCommon::TestPluralStringById(int quantity, const char *cmp, bool format)
{
RState ret;
std::string outValue;
int id = GetResId("eat_apple", ResType::PLURALS);
ASSERT_TRUE(id > 0);
if (format) {
ret = rm->GetPluralStringByIdFormat(outValue, id, quantity, quantity);
} else {
ret = rm->GetPluralStringById(id, quantity, outValue);
}
ASSERT_EQ(SUCCESS, ret);
ASSERT_EQ(std::string(cmp), outValue);
}
void ResourceManagerTestCommon::TestPluralStringByName(int quantity, const char *cmp, bool format)
{
RState ret;
std::string outValue;
const char *name = "eat_apple";
if (format) {
ret = rm->GetPluralStringByNameFormat(outValue, name, quantity, quantity);
} else {
ret = rm->GetPluralStringByName(name, quantity, outValue);
}
ASSERT_EQ(SUCCESS, ret);
ASSERT_EQ(std::string(cmp), outValue);
}
void ResourceManagerTestCommon::TestGetRawFilePathByName(const std::string &name, const std::string &cmp)
{
std::string outValue;
rm->GetRawFilePathByName(name, outValue);
HILOG_DEBUG("%s : %s", name.c_str(), outValue.c_str());
ASSERT_EQ(cmp, outValue);
}
void ResourceManagerTestCommon::TestGetProfileById(HapResource *tmp)
{
tmp->Init();
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/profile/test_profile.json");
std::string outValue;
RState state;
int id = GetResId("test_profile", ResType::PROF);
EXPECT_TRUE(id > 0);
state = rm->GetProfileById(id, outValue);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(res, outValue);
}
void ResourceManagerTestCommon::TestGetProfileByName(HapResource *tmp)
{
tmp->Init();
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/profile/test_profile.json");
std::string outValue;
RState state;
state = rm->GetProfileByName("test_profile", outValue);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(res, outValue);
}
void ResourceManagerTestCommon::TestGetMediaById(HapResource *tmp)
{
tmp->Init();
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/media/icon1.png");
std::string outValue;
RState state;
int id = GetResId("icon1", ResType::MEDIA);
EXPECT_TRUE(id > 0);
state = rm->GetMediaById(id, outValue);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(res, outValue);
}
void ResourceManagerTestCommon::TestGetMediaWithDensityById(HapResource *tmp)
{
tmp->Init();
std::string res = tmp->GetResourcePath();
res.append("entry/resources/sdpi/media/icon.png");
auto rc = CreateResConfig();
if (rc == nullptr) {
EXPECT_TRUE(false);
return;
}
rc->SetDeviceType(DEVICE_TV);
rc->SetColorMode(COLOR_MODE_NOT_SET);
rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
rm->UpdateResConfig(*rc);
delete rc;
int density = 120;
std::string outValue;
RState state;
int id = GetResId("icon", ResType::MEDIA);
EXPECT_TRUE(id > 0);
state = rm->GetMediaById(id, outValue, density);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(res, outValue);
}
void ResourceManagerTestCommon::TestGetMediaByName(HapResource *tmp)
{
tmp->Init();
std::string res = tmp->GetResourcePath();
res.append("entry/resources/base/media/icon1.png");
std::string outValue;
RState state;
state = rm->GetMediaByName("icon1", outValue);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(res, outValue);
}
void ResourceManagerTestCommon::TestGetMediaWithDensityByName(HapResource *tmp)
{
tmp->Init();
std::string res = tmp->GetResourcePath();
res.append("entry/resources/sdpi/media/icon.png");
auto rc = CreateResConfig();
if (rc == nullptr) {
EXPECT_TRUE(false);
return;
}
rc->SetDeviceType(DEVICE_PHONE);
rc->SetColorMode(COLOR_MODE_NOT_SET);
rc->SetScreenDensity(SCREEN_DENSITY_NOT_SET);
rm->UpdateResConfig(*rc);
delete rc;
uint32_t density = 120;
std::string outValue;
RState state;
state = rm->GetMediaByName("icon", outValue, density);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(res, outValue);
}
void ResourceManagerTestCommon::TestGetStringFormatById(const char *name, const char *cmp)
{
int id = GetResId(name, ResType::STRING);
ASSERT_TRUE(id > 0);
std::string outValue;
RState state = rm->GetStringFormatById(outValue, id, 101);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(cmp, outValue);
}
void ResourceManagerTestCommon::TestGetStringFormatByName(const char *name, const char *cmp)
{
std::string outValue;
RState state;
state = rm->GetStringFormatByName(outValue, name, 101);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(cmp, outValue);
}
void ResourceManagerTestCommon::TestGetStringArrayById(const char *name)
{
std::vector<std::string> outValue;
int id = GetResId(name, ResType::STRINGARRAY);
RState state;
state = rm->GetStringArrayById(id, outValue);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(static_cast<size_t>(4), outValue.size());
PrintVectorString(outValue);
}
void ResourceManagerTestCommon::TestGetStringFormatById(const char *name,
std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams, const char *cmp)
{
bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
ASSERT_TRUE(ret);
uint32_t id = GetResId(name, ResType::STRING);
ASSERT_TRUE(id > 0);
std::string outValue;
RState state = rm->GetStringFormatById(id, outValue, jsParams);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(cmp, outValue);
}
void ResourceManagerTestCommon::TestGetStringFormatByName(const char *name,
std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams, const char *cmp)
{
bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
ASSERT_TRUE(ret);
std::string outValue;
RState state = rm->GetStringFormatByName(name, outValue, jsParams);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(cmp, outValue);
}
void ResourceManagerTestCommon::TestGetStringArrayByName(const char *name)
{
std::vector<std::string> outValue;
RState state;
state = rm->GetStringArrayByName(name, outValue);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(static_cast<size_t>(4), outValue.size());
PrintVectorString(outValue);
}
void ResourceManagerTestCommon::TestGetPatternById(const char *name)
{
std::map<std::string, std::string> outValue;
int id = GetResId(name, ResType::PATTERN);
RState state;
state = rm->GetPatternById(id, outValue);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(static_cast<size_t>(3), outValue.size());
PrintMapString(outValue);
}
void ResourceManagerTestCommon::TestGetPatternByName(const char *name)
{
std::map<std::string, std::string> outValue;
RState state;
state = rm->GetPatternByName(name, outValue);
ASSERT_EQ(SUCCESS, state);
ASSERT_EQ(static_cast<size_t>(3), outValue.size());
PrintMapString(outValue);
}
void ResourceManagerTestCommon::TestGetThemeById(const char *name)
{
std::map<std::string, std::string> outValue;
RState state;
int id = GetResId(name, ResType::THEME);
ASSERT_TRUE(id > 0);
state = rm->GetThemeById(id, outValue);
ASSERT_EQ(SUCCESS, state);
}
void ResourceManagerTestCommon::TestGetThemeByName(const char *appTheme, const char *testTheme)
{
std::map<std::string, std::string> outValue;
RState state;
state = rm->GetThemeByName(appTheme, outValue);
ASSERT_EQ(SUCCESS, state);
PrintMapString(outValue);
state = rm->GetThemeByName(testTheme, outValue);
ASSERT_EQ(SUCCESS, state);
}
void ResourceManagerTestCommon::TestGetBooleanById(const char* boolean1, const char* booleanRef)
{
bool outValue = true;
RState state;
int id = GetResId(boolean1, ResType::BOOLEAN);
ASSERT_TRUE(id > 0);
state = rm->GetBooleanById(id, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_TRUE(outValue);
id = GetResId(booleanRef, ResType::BOOLEAN);
ASSERT_TRUE(id > 0);
state = rm->GetBooleanById(id, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_TRUE(outValue);
}
void ResourceManagerTestCommon::TestGetBooleanByName(const char* boolean1, const char* booleanRef)
{
bool outValue = true;
RState state;
state = rm->GetBooleanByName(boolean1, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_TRUE(outValue);
state = rm->GetBooleanByName(booleanRef, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_TRUE(outValue);
}
void ResourceManagerTestCommon::TestGetIntegerById(const char* integer1, const char* integerRef)
{
int outValue;
RState state;
int id = GetResId(integer1, ResType::INTEGER);
ASSERT_TRUE(id > 0);
state = rm->GetIntegerById(id, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(101, outValue);
id = GetResId(integerRef, ResType::INTEGER);
ASSERT_TRUE(id > 0);
state = rm->GetIntegerById(id, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(101, outValue);
}
void ResourceManagerTestCommon::TestGetIntegerByName(const char* integer1, const char* integerRef)
{
int outValue;
RState state;
state = rm->GetIntegerByName(integer1, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(101, outValue);
state = rm->GetIntegerByName(integerRef, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(101, outValue);
}
void ResourceManagerTestCommon::TestGetFloatById(const char* touchTarget, const char* floatRef)
{
float outValue;
RState state;
int id = GetResId(touchTarget, ResType::FLOAT);
ASSERT_TRUE(id > 0);
state = rm->GetFloatById(id, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(48, outValue); // 48vp
std::string unit;
state = rm->GetFloatById(id, outValue, unit);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(48, outValue); // 48vp
EXPECT_EQ("vp", unit);
id = GetResId(floatRef, ResType::FLOAT);
ASSERT_TRUE(id > 0);
state = rm->GetFloatById(id, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(707, outValue); // 707vp
}
void ResourceManagerTestCommon::TestGetFloatByName(const char* touchTarget, const char* floatRef)
{
float outValue;
RState state;
state = rm->GetFloatByName(touchTarget, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(48, outValue); // 48vp
std::string unit;
state = rm->GetFloatByName(touchTarget, outValue, unit);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(48, outValue); // 48vp
EXPECT_EQ("vp", unit);
state = rm->GetFloatByName(floatRef, outValue);
ASSERT_EQ(SUCCESS, state);
EXPECT_EQ(707, outValue); // 707vp
}
void ResourceManagerTestCommon::TestGetIntArrayById(const char* intarray1)
{
std::vector<int> outValue;
RState state;
int id = GetResId(intarray1, ResType::INTARRAY);
EXPECT_TRUE(id > 0);
state = rm->GetIntArrayById(id, outValue);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(static_cast<uint32_t>(3), outValue.size());
EXPECT_EQ(100, outValue[0]);
EXPECT_EQ(200, outValue[1]);
EXPECT_EQ(101, outValue[2]);
}
void ResourceManagerTestCommon::TestGetIntArrayByName(const char* intarray1)
{
std::vector<int> outValue;
RState state;
state = rm->GetIntArrayByName(intarray1, outValue);
EXPECT_TRUE(state == SUCCESS);
EXPECT_EQ(static_cast<uint32_t>(3), outValue.size());
EXPECT_EQ(100, outValue[0]);
EXPECT_EQ(200, outValue[1]);
EXPECT_EQ(101, outValue[2]);
}
void ResourceManagerTestCommon::TestGetResourceLimitKeys(uint32_t expectedLimitKeys)
{
uint32_t limitKeys = rm->GetResourceLimitKeys();
limitKeys &= expectedLimitKeys;
EXPECT_EQ(limitKeys, expectedLimitKeys);
}

View File

@ -0,0 +1,124 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_COMMON_H
#define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_COMMON_H
#include <climits>
#include <cstring>
#include <gtest/gtest.h>
#define private public
#include "res_config.h"
#include "resource_manager.h"
#include "resource_manager_impl.h"
#include "test_common.h"
#include "utils/errors.h"
#include "utils/string_utils.h"
#include "utils/utils.h"
namespace OHOS {
namespace Global {
namespace Resource {
class ResourceManagerTestCommon {
public:
void SetUpTestCase(void);
void TearDownTestCase(void);
void SetUp();
void TearDown();
ResourceManagerTestCommon(ResourceManager *rm);
~ResourceManagerTestCommon();
public:
ResourceManager *rm;
int GetResId(std::string name, ResType resType);
void TestStringByName(const char *name, const char *cmp);
void TestStringById(const char *name, const char *cmp);
void TestPluralStringById(int quantity, const char *cmp, bool format = false);
void TestPluralStringByName(int quantity, const char *cmp, bool format = false);
void TestGetRawFilePathByName(const std::string &name, const std::string &cmp);
void AddResource(const char *language, const char *script, const char *region);
void AddColorModeResource(DeviceType deviceType, ColorMode colorMode, float screenDensity);
void AddHapResource(const char *language, const char *script, const char *region);
void TestGetStringArrayById(const char *name);
void TestGetStringArrayByName(const char *name);
void TestGetStringFormatById(const char *name, const char *cmp);
void TestGetStringFormatByName(const char *name, const char *cmp);
void TestGetStringFormatById(const char *name,
std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams, const char *cmp);
void TestGetStringFormatByName(const char *name,
std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams, const char *cmp);
void TestGetPatternById(const char *name);
void TestGetPatternByName(const char *name);
void TestGetThemeById(const char *name);
void TestGetThemeByName(const char *appTheme, const char *testTheme);
void TestGetBooleanByName(const char *boolean1, const char *booleanRef);
void TestGetBooleanById(const char *boolean1, const char *booleanRef);
void TestGetIntegerByName(const char* integer1, const char* integerRef);
void TestGetIntegerById(const char* integer1, const char* integerRef);
void TestGetFloatByName(const char* touchTarget, const char* floatRef);
void TestGetFloatById(const char* touchTarget, const char* floatRef);
void TestGetIntArrayById(const char* intarray1);
void TestGetIntArrayByName(const char* intarray1);
void TestGetProfileById(HapResource *tmp);
void TestGetProfileByName(HapResource *tmp);
void TestGetMediaWithDensityById(HapResource *tmp);
void TestGetMediaById(HapResource *tmp);
void TestGetMediaWithDensityByName(HapResource *tmp);
void TestGetMediaByName(HapResource *tmp);
void TestGetResourceLimitKeys(uint32_t expectedLimitKeys);
};
} // namespace Resource
} // namespace Global
} // namespace OHOS
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,83 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_HAP_H
#define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_HAP_H
namespace OHOS {
namespace Global {
namespace Resource {
int ResourceManagerAddResourceFromHapTest001(void);
int ResourceManagerGetStringByIdFromHapTest002(void);
int ResourceManagerGetStringByIdFromHapTest003(void);
int ResourceManagerGetStringByNameFromHapTest004(void);
int ResourceManagerGetStringByNameFromHapTest005(void);
int ResourceManagerGetStringFormatByIdFromHapTest006(void);
int ResourceManagerGetStringFormatByNameFromHapTest007(void);
int ResourceManagerGetStringArrayByIdFromHapTest008(void);
int ResourceManagerGetStringArrayByNameFromHapTest009(void);
int ResourceManagerGetPatternByIdFromHapTest0010(void);
int ResourceManagerGetPatternByNameFromHapTest0011(void);
int ResourceManagerGetPluralStringByIdFromHapTest0012(void);
int ResourceManagerGetPluralStringByIdFromHapTest0013(void);
int ResourceManagerGetPluralStringByIdFromHapTest0014(void);
int ResourceManagerGetPluralStringByIdFromHapTest0015(void);
int ResourceManagerGetPluralStringByNameFromHapTest0016(void);
int ResourceManagerGetPluralStringByIdFormatFromHapTest0017(void);
int ResourceManagerGetPluralStringByNameFormatFromHapTest0018(void);
int ResourceManagerGetThemeByIdFromHapTest0019(void);
int ResourceManagerGetThemeByNameFromHapTest0020(void);
int ResourceManagerGetBooleanByIdFromHapTest0021(void);
int ResourceManagerGetBooleanByNameFromHapTest0022(void);
int ResourceManagerGetIntegerByIdFromHapTest0023(void);
int ResourceManagerGetIntegerByNameFromHapTest0024(void);
int ResourceManagerGetFloatByIdFromHapTest0025(void);
int ResourceManagerGetFloatByNameFromHapTest0026(void);
int ResourceManagerGetIntArrayByIdFromHapTest0027(void);
int ResourceManagerGetIntArrayByNameFromHapTest0028(void);
int ResourceManagerGetProfileByIdFromHapTest0029(void);
int ResourceManagerGetProfileByNameFromHapTest0030(void);
int ResourceManagerGetMediaByIdFromHapTest0031(void);
int ResourceManagerGetMediaByIdFromHapTest0032(void);
int ResourceManagerGetMediaByNameFromHapTest0033(void);
int ResourceManagerGetMediaByNameFromHapTest0034(void);
int ResourceManagerGetProfileDataByIdFromHapTest0035(void);
int ResourceManagerGetProfileDataByNameFromHapTest0036(void);
int ResourceManagerGetMediaDataByNameFromHapTest0037(void);
int ResourceManagerGetMediaDataByIdFromHapTest0038(void);
int ResourceManagerGetMediaDataBase64ByNameFromHapTest0039(void);
int ResourceManagerGetMediaDataBase64ByIdFromHapTest0040(void);
int ResourceManagerGetMediaDataByIdFromHapTest0041(void);
int ResourceManagerGetMediaDataByNameFromHapTest0042(void);
int ResourceManagerGetMediaBase64DataByIdFromHapTest0043(void);
int ResourceManagerGetMediaBase64DataByNameFromHapTest0044(void);
int RawFileTestFromHap0045(void);
int RawFileTestFromHap0046(void);
int RawFileTestFromHap0047(void);
int RawFileTestFromHap0048(void);
int ResourceManagerOverlayTest001(void);
int ResourceManagerOverlayTest002(void);
int ResourceManagerOverlayTest003(void);
int ResourceManagerOverlayTest004(void);
int ResourceManagerOverlayTest005(void);
int ResourceManagerOverlayTest006(void);
int ResourceManagerUtilsTest001(void);
int ResourceManagerGetResourceLimitKeysTest001(void);
int ResourceManagerGetResourceLimitKeysTest002(void);
int ResourceManagerGetResourceLimitKeysTest003(void);
} // namespace Resource
} // namespace Global
} // namespace OHOS
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_MEDIA_H
#define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_MEDIA_H
namespace OHOS {
namespace Global {
namespace Resource {
int ResourceManagerGetMediaByIdTest001(void);
int ResourceManagerGetMediaByIdTest002(void);
int ResourceManagerGetMediaByIdTest003(void);
int ResourceManagerGetMediaByIdTest004(void);
int ResourceManagerGetMediaByIdTest005(void);
int ResourceManagerGetMediaByIdTest006(void);
int ResourceManagerGetMediaByIdTest007(void);
int ResourceManagerGetMediaByIdTest008(void);
int ResourceManagerGetMediaByIdTest009(void);
int ResourceManagerGetMediaByIdTest010(void);
int ResourceManagerGetMediaByIdTest011(void);
int ResourceManagerGetMediaByIdTest012(void);
int ResourceManagerGetMediaByIdTest013(void);
int ResourceManagerGetMediaByIdTest014(void);
int ResourceManagerGetMediaByIdTest015(void);
int ResourceManagerGetMediaByIdTest016(void);
int ResourceManagerGetMediaByIdTest017(void);
int ResourceManagerGetMediaByIdTest018(void);
int ResourceManagerGetMediaByIdTest019(void);
int ResourceManagerGetMediaByIdTest020(void);
int ResourceManagerGetMediaByIdTest021(void);
int ResourceManagerGetMediaByIdTest022(void);
int ResourceManagerGetMediaByIdTest023(void);
int ResourceManagerGetMediaByNameTest001(void);
int ResourceManagerGetMediaByNameTest002(void);
int ResourceManagerGetMediaByNameTest003(void);
int ResourceManagerGetMediaByNameTest004(void);
int ResourceManagerGetMediaByNameTest005(void);
int ResourceManagerGetMediaByNameTest006(void);
int ResourceManagerGetMediaByNameTest007(void);
int ResourceManagerGetMediaByNameTest008(void);
int ResourceManagerGetMediaByNameTest009(void);
int ResourceManagerGetMediaByNameTest010(void);
int ResourceManagerGetMediaByNameTest011(void);
int ResourceManagerGetMediaByNameTest012(void);
int ResourceManagerGetMediaByNameTest013(void);
int ResourceManagerGetMediaByNameTest014(void);
int ResourceManagerGetMediaByNameTest015(void);
int ResourceManagerGetMediaByNameTest016(void);
int ResourceManagerGetMediaByNameTest017(void);
int ResourceManagerGetMediaByNameTest018(void);
int ResourceManagerGetMediaByNameTest019(void);
int ResourceManagerGetMediaByNameTest020(void);
int ResourceManagerGetMediaByNameTest021(void);
int ResourceManagerGetMediaByNameTest022(void);
} // namespace Resource
} // namespace Global
} // namespace OHOS
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_MEDIA_H
#define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_MEDIA_H
namespace OHOS {
namespace Global {
namespace Resource {
int ResourceManagerGetStringByIdTest001(void);
int ResourceManagerGetStringByIdTest002(void);
int ResourceManagerGetStringByIdTest003(void);
int ResourceManagerGetStringByIdTest004(void);
int ResourceManagerGetStringByIdTest005(void);
int ResourceManagerGetStringByNameTest001(void);
int ResourceManagerGetStringByNameTest002(void);
int ResourceManagerGetStringByNameTest003(void);
int ResourceManagerGetStringByNameTest004(void);
int ResourceManagerGetStringByNameTest005(void);
int ResourceManagerGetStringFormatByIdTest001(void);
int ResourceManagerGetStringFormatByIdTest002(void);
int ResourceManagerGetStringFormatByIdTest003(void);
int ResourceManagerGetStringFormatByIdTest004(void);
int ResourceManagerGetStringFormatByIdTest005(void);
int ResourceManagerGetStringFormatByIdTest006(void);
int ResourceManagerGetStringFormatByIdTest007(void);
int ResourceManagerGetStringFormatByIdTest008(void);
int ResourceManagerGetStringFormatByNameTest001(void);
int ResourceManagerGetStringFormatByNameTest002(void);
int ResourceManagerGetStringFormatByNameTest003(void);
int ResourceManagerGetStringFormatByNameTest004(void);
int ResourceManagerGetStringFormatByNameTest005(void);
int ResourceManagerGetStringFormatByNameTest006(void);
int ResourceManagerGetStringFormatByNameTest007(void);
int ResourceManagerGetStringFormatByNameTest008(void);
int ResourceManagerGetStringArrayByIdTest001(void);
int ResourceManagerGetStringArrayByIdTest002(void);
int ResourceManagerGetStringArrayByNameTest001(void);
int ResourceManagerGetStringArrayByNameTest002(void);
int ResourceManagerGetPluralStringByIdTest001(void);
int ResourceManagerGetPluralStringByIdTest002(void);
int ResourceManagerGetPluralStringByIdTest003(void);
int ResourceManagerGetPluralStringByIdTest004(void);
int ResourceManagerGetPluralStringByIdTest005(void);
int ResourceManagerGetPluralStringByNameTest001(void);
int ResourceManagerGetPluralStringByNameTest002(void);
int ResourceManagerGetPluralStringByIdFormatTest001(void);
int ResourceManagerGetPluralStringByIdFormatTest002(void);
int ResourceManagerGetPluralStringByIdFormatTest003(void);
int ResourceManagerGetPluralStringByIdFormatTest004(void);
int ResourceManagerGetPluralStringByNameFormatTest001(void);
int ResourceManagerGetPluralStringByNameFormatTest002(void);
int ResourceManagerGetPluralStringByNameFormatTest003(void);
int ResourceManagerGetPluralStringByNameFormatTest004(void);
int ResourceManagerGetStringByNameForMccMncTest001(void);
int ResourceManagerGetStringByNameForMccMncTest002(void);
int ResourceManagerGetStringByNameForMccMncTest003(void);
int ResourceManagerGetStringByNameForMccMncTest004(void);
int ResourceManagerGetStringByNameForMccMncTest005(void);
int ResourceManagerGetStringByNameForMccMncTest006(void);
int ResourceManagerGetStringByNameForMccMncTest007(void);
int ResourceManagerGetStringByNameForMccMncTest008(void);
int ResourceManagerGetStringByNameForMccMncTest009(void);
int ResourceManagerGetStringByNameForMccMncTest010(void);
int ResourceManagerGetStringByNameForMccMncTest011(void);
int ResourceManagerGetStringByNameForMccMncTest012(void);
int ResourceManagerGetStringByNameForMccMncTest013(void);
int ResourceManagerGetStringByNameForMccMncTest014(void);
int ResourceManagerGetStringByNameForMccMncTest015(void);
int ResourceManagerGetStringByNameForMccMncTest016(void);
int ResourceManagerGetStringByNameForMccMncTest017(void);
int ResourceManagerGetStringByNameForMccMncTest018(void);
int ResourceManagerGetStringByNameForMccMncTest019(void);
int ResourceManagerGetStringByNameForMccMncTest020(void);
} // namespace Resource
} // namespace Global
} // namespace OHOS
#endif

View File

@ -26,7 +26,10 @@
// this is relative path
static const char *g_resFilePath = "all/assets/entry/resources.index";
static const char *g_hapPath = "all.hap";
static const char *g_nonExistName = "non_existent_name";
static const char *g_overlayResFilePath = "overlay/assets/entry/resources.index";
static const float BASE_DPI = 160.0f;
static const int NON_EXIST_ID = 1111;
namespace OHOS {
namespace Global {