mirror of
https://gitee.com/openharmony/global_resource_management
synced 2024-11-23 16:09:52 +00:00
添加UT用例
Signed-off-by: liduo <liduo29@huawei.com>
This commit is contained in:
parent
711eab418d
commit
7fa001dcb4
@ -115,7 +115,6 @@ private:
|
||||
|
||||
static uint16_t EncodeLanguageOrRegion(const char *str, char base);
|
||||
|
||||
static bool StrCompare(const char *left, const char *right, size_t len, bool isCaseSensitive);
|
||||
static constexpr uint64_t ROOT_LOCALE = 0x0;
|
||||
static constexpr uint16_t NULL_LANGUAGE = 0x00;
|
||||
static constexpr uint16_t NULL_REGION = 0x00;
|
||||
|
@ -322,45 +322,6 @@ uint16_t Utils::EncodeLanguageOrRegion(const char *str, char base)
|
||||
BitOperatorNum::BIT_EIGHT) | ((second << BitOperatorNum::BIT_FIVE) | third);
|
||||
};
|
||||
|
||||
bool Utils::StrCompare(const char *left, const char *right, size_t len, bool isCaseSensitive)
|
||||
{
|
||||
if (left == nullptr && right == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (left == nullptr || right == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int rc;
|
||||
unsigned char c1;
|
||||
unsigned char c2;
|
||||
while (len--) {
|
||||
c1 = (unsigned char)*left;
|
||||
c2 = (unsigned char)*right;
|
||||
if (c1 == 0) {
|
||||
if (c2 == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if (c2 == 0) {
|
||||
return false;
|
||||
} else {
|
||||
if (isCaseSensitive) {
|
||||
rc = (int)(c1) - (int)(c2);
|
||||
} else {
|
||||
rc = tolower(c1) - tolower(c2);
|
||||
}
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
++left;
|
||||
++right;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief convert hex char as int value
|
||||
*
|
||||
@ -401,7 +362,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue)
|
||||
uint32_t color = 0;
|
||||
RState parseState = SUCCESS;
|
||||
size_t len = strlen(s);
|
||||
if (*s == '#') {
|
||||
if (*s == '#' && len >= ArrayLen::LEN_FOUR) {
|
||||
if (len == ArrayLen::LEN_FOUR) {
|
||||
color |= 0xFF000000;
|
||||
color |= ParseHex(s[ArrayIndex::INDEX_ONE], parseState) << BitOperatorNum::BIT_TWENTY;
|
||||
|
@ -37,6 +37,8 @@ ohos_unittest("resmgr_test") {
|
||||
"unittest/common/test_common.cpp",
|
||||
"unittest/common/theme_config_test.cpp",
|
||||
"unittest/common/theme_manager_test.cpp",
|
||||
"unittest/utils/psue_manaer_test.cpp",
|
||||
"unittest/utils/utils_test.cpp",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
|
@ -170,6 +170,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest003, TestSize.Level1)
|
||||
rc->SetLocaleInfo("zh", nullptr, "CN");
|
||||
HapManager *hapManager = new HapManager(std::make_shared<ResConfigImpl>());
|
||||
hapManager->UpdateResConfig(*rc);
|
||||
hapManager->ReloadAll();
|
||||
if (hapManager == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
return;
|
||||
@ -211,11 +212,9 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest004, TestSize.Level1)
|
||||
}
|
||||
rc->SetLocaleInfo("en", nullptr, "US");
|
||||
HapManager *hapManager = new HapManager(std::make_shared<ResConfigImpl>());
|
||||
EXPECT_FALSE(hapManager == nullptr);
|
||||
hapManager->UpdateResConfig(*rc);
|
||||
if (hapManager == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
return;
|
||||
}
|
||||
hapManager->ReloadAll();
|
||||
bool ret = hapManager->AddResourcePath(FormatFullPath(g_hapPath).c_str());
|
||||
EXPECT_TRUE(ret);
|
||||
int id = 16777221; // 16777221 means 'AboutPageFA' 'aboutPage_title_primary'
|
||||
|
@ -72,4 +72,31 @@ HWTEST_F(ResConfigTest, ResConfigFuncTest001, TestSize.Level1)
|
||||
EXPECT_TRUE(rc->Match(current));
|
||||
EXPECT_TRUE(!(rc->Match(target)));
|
||||
};
|
||||
|
||||
/*
|
||||
* @tc.name: TestScreenDensity001
|
||||
* @tc.desc: Test ScreenDensity.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ResConfigTest, TestScreenDensity001, TestSize.Level1)
|
||||
{
|
||||
auto rc = std::make_shared<ResConfigImpl>();
|
||||
rc->SetScreenDensityDpi(OHOS::Global::Resource::SCREEN_DENSITY_MDPI);
|
||||
EXPECT_EQ(OHOS::Global::Resource::SCREEN_DENSITY_MDPI, rc->GetScreenDensityDpi());
|
||||
EXPECT_FLOAT_EQ(1, rc->GetScreenDensity());
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestCompleteScript001
|
||||
* @tc.desc: Test CompleteScript.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ResConfigTest, TestCompleteScript001, TestSize.Level1)
|
||||
{
|
||||
auto target = std::make_shared<ResConfigImpl>();
|
||||
target->SetLocaleInfo("zh", nullptr, "CN");
|
||||
target->CompleteScript();
|
||||
EXPECT_TRUE(target->IsCompletedScript());
|
||||
target->CompleteScript();
|
||||
}
|
||||
}
|
@ -297,10 +297,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest006, TestSize.Le
|
||||
// make a fake locale, then getString
|
||||
rmc->AddResource("en", nullptr, "US");
|
||||
ResConfig *rc = CreateResConfig();
|
||||
if (rc == nullptr) {
|
||||
EXPECT_TRUE(false);
|
||||
return;
|
||||
}
|
||||
EXPECT_FALSE(rc == nullptr);
|
||||
rc->SetLocaleInfo("en", nullptr, "XA");
|
||||
RState state = rm->UpdateResConfig(*rc);
|
||||
EXPECT_EQ(SUCCESS, state);
|
||||
@ -309,8 +306,9 @@ HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest006, TestSize.Le
|
||||
std::string outValue;
|
||||
rm->GetStringById(id, outValue);
|
||||
EXPECT_TRUE(outValue != "App Name");
|
||||
|
||||
|
||||
rc->SetLocaleInfo("ar", nullptr, "XB");
|
||||
EXPECT_EQ(SUCCESS, rm->UpdateResConfig(*rc, true));
|
||||
rm->GetStringById(id, outValue);
|
||||
delete rc;
|
||||
EXPECT_TRUE(outValue != "App Name");
|
||||
@ -2057,7 +2055,7 @@ HWTEST_F(ResourceManagerTest, CreateResourceManagerTest001, TestSize.Level1)
|
||||
int32_t userId = 100; // userId is 100
|
||||
std::shared_ptr<ResourceManager> bundleRm =
|
||||
CreateResourceManager("ohos.global.test.all", "entry", hapPath, overlayPath, *rc, appType, userId);
|
||||
EXPECT_TRUE(bundleRm == nullptr);
|
||||
EXPECT_FALSE(bundleRm == nullptr);
|
||||
|
||||
bundleRm = CreateResourceManager("", "entry", hapPath, overlayPath, *rc, appType, userId);
|
||||
EXPECT_TRUE(bundleRm == nullptr);
|
||||
@ -2073,6 +2071,20 @@ HWTEST_F(ResourceManagerTest, GetSystemResourceManagerTest001, TestSize.Level1)
|
||||
{
|
||||
ResourceManager *bundleRm = GetSystemResourceManagerNoSandBox();
|
||||
EXPECT_TRUE(bundleRm != nullptr);
|
||||
EXPECT_TRUE(GetSystemResourceManager() != nullptr);
|
||||
bundleRm = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: AddPatchResourcePathTest001
|
||||
* @tc.desc: Test AddPatchResourcePath function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ResourceManagerTest, AddPatchResourcePathTest001, TestSize.Level1)
|
||||
{
|
||||
std::string path = FormatFullPath(g_resFilePath);
|
||||
ASSERT_TRUE(rm->AddResource(path.c_str()));
|
||||
EXPECT_TRUE(rm->AddPatchResource(path.c_str(), "testPatch"));
|
||||
EXPECT_FALSE(rm->AddPatchResource("not_exit_path", "testPatch"));
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ int ResourceManagerAddResourceTest003(void);
|
||||
int ResourceManagerAddResourceTest004(void);
|
||||
int ResourceManagerAddResourceTest005(void);
|
||||
int ResourceManagerAddResourceTest006(void);
|
||||
int ResourceManagerAddPatchResourcePathTest001(void);
|
||||
int ResourceManagerUpdateResConfigTest001(void);
|
||||
int ResourceManagerUpdateResConfigTest002(void);
|
||||
int ResourceManagerUpdateResConfigTest003(void);
|
||||
|
63
frameworks/resmgr/test/unittest/utils/psue_manaer_test.cpp
Normal file
63
frameworks/resmgr/test/unittest/utils/psue_manaer_test.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 <gtest/gtest.h>
|
||||
#include "utils/psue_manager.h"
|
||||
|
||||
using namespace OHOS::Global::Resource;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace {
|
||||
class PsueManagerTest : public testing::Test {
|
||||
public:
|
||||
void SetUp();
|
||||
|
||||
private:
|
||||
std::shared_ptr<PsueManager> psueManager;
|
||||
};
|
||||
|
||||
void PsueManagerTest::SetUp()
|
||||
{
|
||||
psueManager = std::make_shared<PsueManager>();
|
||||
}
|
||||
|
||||
HWTEST_F(PsueManagerTest, TestBidirectionConvertFunc001, TestSize.Level1)
|
||||
{
|
||||
std::string noAsciiStr = "Hello, 世界!";
|
||||
std::string asciiStr = "123qwe 0.*/";
|
||||
EXPECT_EQ(psueManager->BidirectionConvert(asciiStr), "\u200F\u202E123qwe\u202C\u200F \u200F\u202E0.*/\u202C\u200F");
|
||||
EXPECT_EQ(psueManager->BidirectionConvert(noAsciiStr), noAsciiStr);
|
||||
}
|
||||
|
||||
HWTEST_F(PsueManagerTest, TestConvertFunc001, TestSize.Level1)
|
||||
{
|
||||
std::string noAsciiStr = "Hello, 世界!";
|
||||
std::string longStr = "abcdefghijklmnopqrstuvwxyz0123456789 abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
std::string outValue = "";
|
||||
psueManager->Convert("123", outValue);
|
||||
EXPECT_EQ(outValue, "");
|
||||
psueManager->Convert("abc", outValue);
|
||||
EXPECT_EQ(outValue, "[àbćReÇÉÄß]");
|
||||
outValue = "";
|
||||
psueManager->Convert("", outValue);
|
||||
EXPECT_EQ(outValue, "");
|
||||
psueManager->Convert(noAsciiStr, outValue);
|
||||
EXPECT_EQ(outValue, "[Helló, 世界!ReÇÉÄßÑ¿ÃóèìжД]");
|
||||
psueManager->SetFakeLocaleLevel(3);
|
||||
psueManager->Convert("abc {test} %dabc", outValue);
|
||||
EXPECT_EQ(psueManager->Convert("abc {test} %dabc", outValue), "");
|
||||
}
|
||||
|
||||
} // namespace
|
44
frameworks/resmgr/test/unittest/utils/utils_test.cpp
Normal file
44
frameworks/resmgr/test/unittest/utils/utils_test.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 <gtest/gtest.h>
|
||||
#include "utils/utils.h"
|
||||
|
||||
using namespace OHOS::Global::Resource;
|
||||
using namespace testing::ext;
|
||||
namespace {
|
||||
class UtilsTest : public testing::Test {};
|
||||
|
||||
HWTEST_F(UtilsTest, TestConvertColorToUInt32Func, TestSize.Level1)
|
||||
{
|
||||
uint32_t outValue;
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32(nullptr, outValue), RState::INVALID_FORMAT);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("", outValue), RState::INVALID_FORMAT);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("123", outValue), RState::INVALID_FORMAT);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("#12", outValue), RState::INVALID_FORMAT);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("##12", outValue), RState::INVALID_FORMAT);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("#123", outValue), RState::SUCCESS);
|
||||
EXPECT_EQ(outValue, 4279312947);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("#1233", outValue), RState::SUCCESS);
|
||||
EXPECT_EQ(outValue, 287454003);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("#12334", outValue), RState::INVALID_FORMAT);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("#123344", outValue), RState::SUCCESS);
|
||||
EXPECT_EQ(outValue, 4279382852);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("#12334455", outValue), RState::SUCCESS);
|
||||
EXPECT_EQ(outValue, 305349717);
|
||||
EXPECT_EQ(Utils::ConvertColorToUInt32("#1a3344ff", outValue), RState::SUCCESS);
|
||||
EXPECT_EQ(outValue, 439567615);
|
||||
}
|
||||
} // namespace
|
Loading…
Reference in New Issue
Block a user