提交 1dbd9ba2 编写于 作者: Y y00314596

add testcase,yangqing3@huawei.com

Signed-off-by: Ny00314596 <yangqing3@huawei.com>
上级 6a011683
......@@ -17,5 +17,9 @@ group("ActsGlobalTest") {
"//test/xts/acts/global_lite/i18n_lite/numberrecall_posix:ActsNumberRecallTest",
"//test/xts/acts/global_lite/i18n_lite/datetime_posix:ActsGlobalDateTimeTest",
"//test/xts/acts/global_lite/i18n_lite/datetimerecall_posix:ActsGlobalDateTimeRecallTest",
"//test/xts/acts/global_lite/i18n_lite/week_plural_number/src:WeekPluralNumbertest",
# depend on the resources
#"//test/xts/acts/global_lite/i18n_lite/resource_parse_load/src:ResourceParseLoadtest",
]
}
# Copyright (C) 2021 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.
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("ResourceParseLoadtest") {
suite_name = "acts"
sources = [
"global_test.cpp",
"hap_manager_test.cpp",
"hap_parser_test.cpp",
"hap_resource_test.cpp",
"locale_info_test.cpp",
"res_config_impl_test.cpp",
"res_config_test.cpp",
"res_desc_test.cpp",
"resource_manager_performance_test.cpp",
"resource_manager_test.cpp",
"string_utils_test.cpp",
"test_common.cpp",
]
include_dirs = [
"//base/global/i18n_lite/interfaces/kits/i18n/include",
"//base/global/resmgr_lite/frameworks/resmgr_lite/include",
"//base/global/resmgr_lite/interfaces/innerkits/include",
]
deps = [
"//base/global/resmgr_lite/frameworks/resmgr_lite:global_resmgr",
#"//third_party/bounds_checking_function:libsec_shared",
]
}
{
"kits": [
{
"push": [
"ResourceParseLoadtest->/data/local/tmp/ResourceParseLoadtest"
],
"type": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ResourceParseLoadtest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "ResourceParseLoadtest Tests"
}
\ No newline at end of file
/*
* Copyright (c) 2021 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 "global_test.h"
#include <gtest/gtest.h>
#include "test_common.h"
#include "utils/errors.h"
#include "utils/string_utils.h"
#define private public
#include "global.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
class GlobalTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void GlobalTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void GlobalTest::TearDownTestCase()
{
// step 2: input testsuit teardown step
}
void GlobalTest::SetUp()
{
// step 3: input testcase setup step
}
void GlobalTest::TearDown()
{
// step 4: input testcase teardown step
}
int GetResId(const std::string &name, ResType resType)
{
auto rc = new ResConfigImpl;
rc->SetLocaleInfo("en", nullptr, "US");
std::string resPath = FormatFullPath(g_resFilePath);
const char *path = resPath.c_str();
const HapResource *pResource = HapResource::LoadFromIndex(path, rc);
int ret = pResource->GetIdByName(name.c_str(), resType);
delete pResource;
delete rc;
return ret;
}
/*
* @tc.name: GlobalFuncTest001
* @tc.desc: Test GLOBAL_ConfigLanguage function, file case.
* @tc.type: FUNC
*/
HWTEST_F(GlobalTest, GlobalFuncTest001, TestSize.Level1)
{
char lan[10];
char region[10];
GLOBAL_ConfigLanguage("en-Latn-US");
int32_t ret = GLOBAL_GetLanguage(lan, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("en"), lan);
ret = GLOBAL_GetRegion(region, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("US"), region);
GLOBAL_ConfigLanguage("en_Latn_US");
ret = GLOBAL_GetLanguage(lan, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("en"), lan);
ret = GLOBAL_GetRegion(region, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("US"), region);
GLOBAL_ConfigLanguage("en-US");
ret = GLOBAL_GetLanguage(lan, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("en"), lan);
ret = GLOBAL_GetRegion(region, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("US"), region);
GLOBAL_ConfigLanguage("en_US");
ret = GLOBAL_GetLanguage(lan, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("en"), lan);
ret = GLOBAL_GetRegion(region, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("US"), region);
GLOBAL_ConfigLanguage("en");
ret = GLOBAL_GetLanguage(lan, 10);
ASSERT_EQ(OK, ret);
ASSERT_EQ(std::string("en"), lan);
}
/*
* @tc.name: GlobalFuncTest002
* @tc.desc: Test GLOBAL_GetValueByName function, file case.
* @tc.type: FUNC
*/
HWTEST_F(GlobalTest, GlobalFuncTest002, TestSize.Level1)
{
GLOBAL_ConfigLanguage("en_Latn_US");
char *values = nullptr;
int32_t ret = GLOBAL_GetValueByName("app_name", FormatFullPath(g_resFilePath).c_str(), &values);
// when ret != OK , values has been freed.
ASSERT_EQ(OK, ret);
EXPECT_EQ(std::string("App Name"), values);
free(values);
}
/*
* @tc.name: GlobalFuncTest003
* @tc.desc: Test GLOBAL_GetValueById function, file case.
* @tc.type: FUNC
*/
HWTEST_F(GlobalTest, GlobalFuncTest003, TestSize.Level1)
{
GLOBAL_ConfigLanguage("en_Latn_US");
char *values = nullptr;
int id = GetResId("app_name", ResType::STRING);
ASSERT_TRUE(id > 0);
int32_t ret = GLOBAL_GetValueById(static_cast<uint32_t>(id), FormatFullPath(g_resFilePath).c_str(), &values);
// when ret != OK , values has been freed.
ASSERT_EQ(OK, ret);
EXPECT_EQ(std::string("App Name"), values);
free(values);
}
/*
* Copyright (c) 2021 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_GLOBAL_TEST_H
#define RESOURCE_MANAGER_GLOBAL_TEST_H
int GlobalFuncTest001();
int GlobalFuncTest002();
int GlobalFuncTest003();
#endif
/*
* Copyright (c) 2021 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 "hap_manager_test.h"
#include <gtest/gtest.h>
#include "test_common.h"
#include "utils/string_utils.h"
#define private public
#include "hap_manager.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
class HapManagerTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HapManagerTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void HapManagerTest::TearDownTestCase()
{
// step 2: input testsuit teardown step
}
void HapManagerTest::SetUp()
{
// step 3: input testcase setup step
HILOG_DEBUG("HapManagerTest setup");
}
void HapManagerTest::TearDown()
{
// step 4: input testcase teardown step
HILOG_DEBUG("HapManagerTest teardown");
}
/*
* this test shows how to load a hap, then find value list by id
* @tc.name: HapManagerFuncTest001
* @tc.desc: Test AddResourcePath & GetResourceList function, file case.
* @tc.type: FUNC
*/
HWTEST_F(HapManagerTest, HapManagerFuncTest001, TestSize.Level1)
{
HapManager *hapManager = new HapManager(new ResConfigImpl);
bool ret = hapManager->AddResourcePath(FormatFullPath(g_resFilePath).c_str());
EXPECT_TRUE(ret);
int id = 16777217;
const HapResource::IdValues *idValues = hapManager->GetResourceList(id);
if (idValues == nullptr) {
delete hapManager;
EXPECT_TRUE(false);
return;
}
PrintIdValues(idValues);
delete hapManager;
}
/*
* this test shows how to reload a hap
* @tc.name: HapManagerFuncTest002
* @tc.desc: Test UpdateResConfig & AddResourcePath function, file case.
* @tc.type: FUNC
*/
HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1)
{
ResConfig *rc = CreateResConfig();
if (rc == nullptr) {
EXPECT_TRUE(false);
return;
}
rc->SetLocaleInfo("en", nullptr, "US");
std::string resPath = FormatFullPath(g_resFilePath);
const char *path = resPath.c_str();
HapManager *hapManager = new HapManager(new ResConfigImpl);
if (hapManager == nullptr) {
delete (rc);
EXPECT_TRUE(false);
return;
}
hapManager->UpdateResConfig(*rc);
bool ret = hapManager->AddResourcePath(path);
EXPECT_TRUE(ret);
int id = 16777228;
const HapResource::IdValues *idValues = hapManager->GetResourceList(id);
if (idValues == nullptr) {
delete (hapManager);
delete (rc);
EXPECT_TRUE(false);
return;
}
EXPECT_EQ(static_cast<size_t>(1), idValues->GetLimitPathsConst().size());
PrintIdValues(idValues);
// reload
ResConfig* rc2 = CreateResConfig();
if (rc2 == nullptr) {
delete (hapManager);
delete (rc);
EXPECT_TRUE(false);
return;
}
rc2->SetLocaleInfo("zh", nullptr, "CN");
hapManager->UpdateResConfig(*rc2);
do {
idValues = hapManager->GetResourceList(id);
if (idValues == nullptr) {
EXPECT_TRUE(false);
break;
}
EXPECT_EQ(static_cast<size_t>(2), idValues->GetLimitPathsConst().size());
PrintIdValues(idValues);
} while (false);
delete (hapManager);
delete (rc2);
delete (rc);
}
\ No newline at end of file
/*
* Copyright (c) 2021 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_HAP_MANAGER_TEST_H
#define RESOURCE_MANAGER_HAP_MANAGER_TEST_H
int HapManagerFuncTest001();
int HapManagerFuncTest002();
#endif
/*
* Copyright (c) 2021 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 "hap_parser_test.h"
#include <gtest/gtest.h>
#include "test_common.h"
#include "utils/string_utils.h"
#define private public
#include "hap_parser.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
class HapParserTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HapParserTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void HapParserTest::TearDownTestCase()
{
// step 2: input testsuit teardown step
}
void HapParserTest::SetUp()
{
// step 3: input testcase setup step
}
void HapParserTest::TearDown()
{
// step 4: input testcase teardown step
}
/*
* @tc.name: HapParserFuncTest001
* @tc.desc: Test CreateResConfigFromKeyParams
* @tc.type: FUNC
*/
HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1)
{
std::vector<KeyParam *> keyParams;
auto kp = new KeyParam();
kp->type_ = LANGUAGES;
kp->value_ = 31336;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = REGION;
kp->value_ = 17230;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = SCREEN_DENSITY;
kp->value_ = SCREEN_DENSITY_SDPI;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = DEVICETYPE;
kp->value_ = DEVICE_CAR;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = DIRECTION;
kp->value_ = DIRECTION_VERTICAL;
kp->InitStr();
keyParams.push_back(kp);
auto config = HapParser::CreateResConfigFromKeyParams(keyParams);
if (config != nullptr) {
EXPECT_EQ(std::string("zh"), config->GetLocaleInfo()->GetLanguage());
EXPECT_EQ(std::string("CN"), config->GetLocaleInfo()->GetRegion());
EXPECT_EQ(std::string("Hans"), config->GetLocaleInfo()->GetScript());
EXPECT_EQ(DEVICE_CAR, config->GetDeviceType());
EXPECT_EQ(DIRECTION_VERTICAL, config->GetDirection());
EXPECT_EQ(SCREEN_DENSITY_SDPI, config->GetScreenDensity());
} else {
EXPECT_TRUE(false);
}
for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) {
delete *kp;
}
delete config;
}
/*
* @tc.name: HapParserFuncTest002
* @tc.desc: Test GetDeviceType
* @tc.type: FUNC
*/
HWTEST_F(HapParserTest, HapParserFuncTest002, TestSize.Level1)
{
ASSERT_EQ(DEVICE_CAR, HapParser::GetDeviceType(DEVICE_CAR));
ASSERT_EQ(DEVICE_PC, HapParser::GetDeviceType(DEVICE_PC));
ASSERT_EQ(DEVICE_PHONE, HapParser::GetDeviceType(DEVICE_PHONE));
ASSERT_EQ(DEVICE_TABLET, HapParser::GetDeviceType(DEVICE_TABLET));
ASSERT_EQ(DEVICE_TV, HapParser::GetDeviceType(DEVICE_TV));
ASSERT_EQ(DEVICE_WEARABLE, HapParser::GetDeviceType(DEVICE_WEARABLE));
ASSERT_EQ(DEVICE_NOT_SET, HapParser::GetDeviceType(1000000));
}
/*
* @tc.name: HapParserFuncTest003
* @tc.desc: Test GetScreenDensity
* @tc.type: FUNC
*/
HWTEST_F(HapParserTest, HapParserFuncTest003, TestSize.Level1)
{
ASSERT_EQ(SCREEN_DENSITY_SDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_SDPI));
ASSERT_EQ(SCREEN_DENSITY_MDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_MDPI));
ASSERT_EQ(SCREEN_DENSITY_LDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_LDPI));
ASSERT_EQ(SCREEN_DENSITY_XLDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_XLDPI));
ASSERT_EQ(SCREEN_DENSITY_XXLDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_XXLDPI));
ASSERT_EQ(SCREEN_DENSITY_XXXLDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_XXXLDPI));
ASSERT_EQ(SCREEN_DENSITY_NOT_SET, HapParser::GetScreenDensity(10000000));
}
/*
* @tc.name: HapParserFuncTest004
* @tc.desc: Test ToFolderPath
* @tc.type: FUNC
*/
HWTEST_F(HapParserTest, HapParserFuncTest004, TestSize.Level1)
{
std::vector<KeyParam *> keyParams;
auto kp = new KeyParam();
kp->type_ = LANGUAGES;
kp->value_ = 31336;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = REGION;
kp->value_ = 17230;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = SCREEN_DENSITY;
kp->value_ = SCREEN_DENSITY_SDPI;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = DEVICETYPE;
kp->value_ = DEVICE_CAR;
kp->InitStr();
keyParams.push_back(kp);
kp = new KeyParam();
kp->type_ = DIRECTION;
kp->value_ = DIRECTION_VERTICAL;
kp->InitStr();
keyParams.push_back(kp);
std::string folder = HapParser::ToFolderPath(keyParams);
ASSERT_EQ("zh_CN-vertical-car-sdpi", folder);
for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) {
delete *kp;
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 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_HAP_RESOURCE_TEST_H
#define RESOURCE_MANAGER_HAP_RESOURCE_TEST_H
int HapParserFuncTest001();
int HapParserFuncTest002();
int HapParserFuncTest003();
int HapParserFuncTest004();
#endif
/*
* Copyright (c) 2021 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 "hap_resource_test.h"
#include <climits>
#include <gtest/gtest.h>
#include "hap_parser.h"
#include "hap_resource.h"
#include "test_common.h"
#include "utils/date_utils.h"
#include "utils/errors.h"
#include "utils/string_utils.h"
#define private public
using namespace OHOS::Global::Resource;
using namespace testing::ext;
class HapResourceTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HapResourceTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void HapResourceTest::TearDownTestCase(void)
{
// step 2: input testsuit teardown step
}
void HapResourceTest::SetUp()
{
// step 3: input testcase setup step
}
void HapResourceTest::TearDown()
{
// step 4: input testcase teardown step
}
/*
* this test shows how to load a hap, defaultConfig set to null
* @tc.name: HapResourceFuncTest001
* @tc.desc: Test Load & GetIdValues & GetIdValuesByName function, file case.
* @tc.type: FUNC
*/
HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level1)
{
auto start = CurrentTimeUsec();
const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
auto cost = CurrentTimeUsec() - start;
HILOG_DEBUG("load cost: %ld us.", cost);
if (pResource == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_EQ(static_cast<size_t>(80), pResource->IdSize());
int id = pResource->GetIdByName("app_name", ResType::STRING);
start = CurrentTimeUsec();
auto idValues = pResource->GetIdValues(id);
cost = CurrentTimeUsec() - start;
EXPECT_EQ(static_cast<size_t>(3), idValues->GetLimitPathsConst().size());
HILOG_DEBUG("GetIdValues by id cost: %ld us.", cost);
PrintIdValues(idValues);
{
auto limitPath = idValues->GetLimitPathsConst()[0];
EXPECT_TRUE(limitPath->GetFolder() == "en_US");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name");
}
{
auto limitPath = idValues->GetLimitPathsConst()[1];
EXPECT_TRUE(limitPath->GetFolder() == "zh_CN");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "应用名称");
}
{
auto limitPath = idValues->GetLimitPathsConst()[2];
EXPECT_TRUE(limitPath->GetFolder() == "default");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About");
}
std::string name = std::string("app_name");
start = CurrentTimeUsec();
auto idValues2 = pResource->GetIdValuesByName(name, ResType::STRING);
cost = CurrentTimeUsec() - start;
EXPECT_EQ(static_cast<size_t>(3), idValues2->GetLimitPathsConst().size());
HILOG_DEBUG("GetIdValues by name cost: %ld us.", cost);
PrintIdValues(idValues);
{
auto limitPath = idValues->GetLimitPathsConst()[0];
EXPECT_TRUE(limitPath->GetFolder() == "en_US");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name");
}
{
auto limitPath = idValues->GetLimitPathsConst()[1];
EXPECT_TRUE(limitPath->GetFolder() == "zh_CN");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "应用名称");
}
{
auto limitPath = idValues->GetLimitPathsConst()[2];
EXPECT_TRUE(limitPath->GetFolder() == "default");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About");
}
delete (pResource);
}
/*
* load a hap, set config en_US
* @tc.name: HapResourceFuncTest002
* @tc.desc: Test Load & GetIdValues & GetIdValuesByName function, file case.
* @tc.type: FUNC
*/
HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1)
{
ResConfigImpl *rc = new ResConfigImpl;
rc->SetLocaleInfo("en", nullptr, "US");
std::string resPath = FormatFullPath(g_resFilePath);
const char *path = resPath.c_str();
auto start = CurrentTimeUsec();
const HapResource *pResource = HapResource::LoadFromIndex(path, rc);
auto cost = CurrentTimeUsec() - start;
HILOG_DEBUG("load cost: %ld us.", cost);
if (pResource == nullptr) {
delete rc;
EXPECT_TRUE(false);
return;
}
EXPECT_EQ(static_cast<size_t>(79), pResource->IdSize());
int id = pResource->GetIdByName("app_name", ResType::STRING);
start = CurrentTimeUsec();
auto idValues = pResource->GetIdValues(id);
cost = CurrentTimeUsec() - start;
EXPECT_EQ(static_cast<size_t>(2), idValues->GetLimitPathsConst().size());
HILOG_DEBUG("GetIdValues by id cost: %ld us.", cost);
PrintIdValues(idValues);
{
auto limitPath = idValues->GetLimitPathsConst()[0];
EXPECT_TRUE(limitPath->GetFolder() == "en_US");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name");
}
{
auto limitPath = idValues->GetLimitPathsConst()[1];
EXPECT_TRUE(limitPath->GetFolder() == "default");
EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name");
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About");
}
std::string name = std::string("app_name");
start = CurrentTimeUsec();
auto idValues2 = pResource->GetIdValuesByName(name, ResType::STRING);
cost = CurrentTimeUsec() - start;
EXPECT_EQ(static_cast<size_t>(2), idValues2->GetLimitPathsConst().size());
HILOG_DEBUG("GetIdValues by name cost: %ld us.", cost);
PrintIdValues(idValues);
{
auto limitPath = idValues2->GetLimitPathsConst()[0];
EXPECT_TRUE(limitPath->GetFolder() == "en_US");
EXPECT_TRUE(limitPath->GetIdItem()->id_ == static_cast<uint32_t>(id));
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name");
}
{
auto limitPath = idValues->GetLimitPathsConst()[1];
EXPECT_TRUE(limitPath->GetFolder() == "default");
EXPECT_TRUE(limitPath->GetIdItem()->id_ == static_cast<uint32_t>(id));
EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About");
}
delete pResource;
delete rc;
}
/*
* load a hap, get a value which is ref
* @tc.name: HapResourceFuncTest003
* @tc.desc: Test GetIdValuesByName function, file case.
* @tc.type: FUNC
*/
HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1)
{
auto start = CurrentTimeUsec();
const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr);
auto cost = CurrentTimeUsec() - start;
HILOG_DEBUG("load cost: %ld us.", cost);
if (pResource == nullptr) {
EXPECT_TRUE(false);
return;
}
auto idv = pResource->GetIdValuesByName(std::string("integer_ref"), ResType::INTEGER);
PrintIdValues(idv);
idv = pResource->GetIdValuesByName(std::string("string_ref"), ResType::STRING);
PrintIdValues(idv);
// ref propagation
idv = pResource->GetIdValuesByName(std::string("string_ref2"), ResType::STRING);
PrintIdValues(idv);
idv = pResource->GetIdValuesByName(std::string("boolean_ref"), ResType::BOOLEAN);
PrintIdValues(idv);
idv = pResource->GetIdValuesByName(std::string("color_ref"), ResType::COLOR);
PrintIdValues(idv);
idv = pResource->GetIdValuesByName(std::string("float_ref"), ResType::FLOAT);
PrintIdValues(idv);
// ref in array ,
idv = pResource->GetIdValuesByName(std::string("intarray_1"), ResType::INTARRAY);
PrintIdValues(idv);
// "parent": was ref too
idv = pResource->GetIdValuesByName(std::string("child"), ResType::PATTERN);
PrintIdValues(idv);
}
ResDesc *LoadFromHap(const char *hapPath, const ResConfigImpl *defaultConfig)
{
std::string errOut;
void *buf = nullptr;
size_t bufLen;
int32_t out = HapParser::ReadIndexFromFile(hapPath,
&buf, bufLen, errOut);
if (out != OK) {
HILOG_ERROR("ReadIndexFromFile failed! retcode:%d,err:%s", out, errOut.c_str());
return nullptr;
}
HILOG_DEBUG("extract success, bufLen:%zu", bufLen);
ResDesc *resDesc = new ResDesc();
out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, defaultConfig);
if (out != OK) {
delete (resDesc);
free(buf);
HILOG_ERROR("ParseResHex failed! retcode:%d", out);
return nullptr;
} else {
HILOG_DEBUG("ParseResHex success:\n%s", resDesc->ToString().c_str());
}
free(buf);
// construct hapresource
return resDesc;
}
/*
* @tc.name: HapResourceFuncTest004
* @tc.desc: Test HapParser::ReadIndexFromFile function, file case.
* @tc.type: FUNC
*/
HWTEST_F(HapResourceTest, HapResourceFuncTest004, TestSize.Level1)
{
// 1. normal case
ResDesc *resDesc = LoadFromHap(FormatFullPath("all.hap").c_str(), nullptr);
ASSERT_TRUE(resDesc != nullptr);
// 2. hap file exists, config.json does not exist
resDesc = LoadFromHap(FormatFullPath("err-config.json-1.hap").c_str(), nullptr);
ASSERT_TRUE(resDesc == nullptr);
// 3. hap file exists, config.json error: missing "moduleName"
resDesc = LoadFromHap(FormatFullPath("err-config.json-2.hap").c_str(), nullptr);
ASSERT_TRUE(resDesc == nullptr);
}
\ No newline at end of file
/*
* Copyright (c) 2021 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_HAP_RESOURCE_TEST_H
#define RESOURCE_MANAGER_HAP_RESOURCE_TEST_H
int HapResourceFuncTest001();
int HapResourceFuncTest002();
int HapResourceFuncTest003();
int HapResourceFuncTest004();
#endif
/*
* Copyright (c) 2021 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 "locale_info_test.h"
#include <chrono>
#include <climits>
#include <cstring>
#include <gtest/gtest.h>
#include "hilog_wrapper.h"
#include "locale_info.h"
#include "test_common.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
class LocaleInfoTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void LocaleInfoTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
}
void LocaleInfoTest::TearDownTestCase(void)
{
// step 2: input testsuit teardown step
}
void LocaleInfoTest::SetUp()
{
}
void LocaleInfoTest::TearDown()
{
}
/*
* @tc.name: LocaleInfoFindAndSortTest001
* @tc.desc: Test FindAndSort
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest001, TestSize.Level1)
{
std::vector<std::string> request;
std::vector<std::string> outValue;
request.push_back("en");
request.push_back("en-CN");
request.push_back("en-US");
request.push_back("en-GB");
request.push_back("");
std::string current = "en-US";
FindAndSort(current, request, outValue);
EXPECT_TRUE(outValue.at(0) == "en-US");
EXPECT_TRUE(outValue.at(1) == "en");
EXPECT_TRUE(outValue.at(2) == "");
EXPECT_TRUE(outValue.at(3) == "en-CN");
EXPECT_TRUE(outValue.at(4) == "en-GB");
}
/*
* @tc.name: LocaleInfoFindAndSortTest002
* @tc.desc: Test FindAndSort
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest002, TestSize.Level1)
{
std::vector<std::string> request;
std::vector<std::string> outValue;
request.push_back("zh-CN");
request.push_back("zh-TW");
request.push_back("zh");
request.push_back("zh-HK");
request.push_back("");
std::string current = "zh-CN";
FindAndSort(current, request, outValue);
EXPECT_TRUE(outValue.at(0) == "zh-CN");
EXPECT_TRUE(outValue.at(1) == "zh");
EXPECT_TRUE(outValue.at(2) == "");
}
/*
* @tc.name: LocaleInfoFindAndSortTest003
* @tc.desc: Test FindAndSort
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest003, TestSize.Level1)
{
std::vector<std::string> request;
std::vector<std::string> outValue;
request.push_back("en");
request.push_back("en-CA");
request.push_back("en-GB");
request.push_back("");
std::string current = "en-CN";
FindAndSort(current, request, outValue);
EXPECT_TRUE(outValue.at(0) == "en");
EXPECT_TRUE(outValue.at(1) == "en-CA");
EXPECT_TRUE(outValue.at(2) == "");
EXPECT_TRUE(outValue.at(3) == "en-GB");
}
/*
* @tc.name: LocaleInfoFindAndSortTest004
* @tc.desc: Test FindAndSort
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest004, TestSize.Level1)
{
std::vector<std::string> request;
std::vector<std::string> outValue;
request.push_back("en");
request.push_back("en-CA");
request.push_back("en-GB");
request.push_back("");
std::string current = "en-Qaag";
FindAndSort(current, request, outValue);
EXPECT_TRUE(outValue.at(0) == "en");
EXPECT_TRUE(outValue.at(1) == "en-GB");
EXPECT_TRUE(outValue.at(2) == "en-CA");
EXPECT_TRUE(outValue.at(3) == "");
}
/*
* @tc.name: LocaleInfoFindAndSortTest005
* @tc.desc: Test FindAndSort
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest005, TestSize.Level1)
{
std::vector<std::string> request;
std::vector<std::string> outValue;
request.push_back("en");
request.push_back("en-001");
request.push_back("en-CA");
request.push_back("en-GB");
request.push_back("");
std::string current = "en-AI";
FindAndSort(current, request, outValue);
EXPECT_TRUE(outValue.at(0) == "en-001");
EXPECT_TRUE(outValue.at(1) == "en");
EXPECT_TRUE(outValue.at(2) == "en-GB");
EXPECT_TRUE(outValue.at(3) == "en-CA");
EXPECT_TRUE(outValue.at(4) == "");
}
/*
* @tc.name: LocaleInfoGetSysDefaultTest001
* @tc.desc: Test GetSysDefault
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
UpdateSysDefault(*localeInfo, false);
const LocaleInfo* currentLocaleInfo = GetSysDefault();
if (currentLocaleInfo == nullptr) {
EXPECT_TRUE(false);
delete localeInfo;
return;
}
EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->GetLanguage()) == 0);
EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoUpdateSysDefaultTest001
* @tc.desc: Test UpdateSysDefault
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
UpdateSysDefault(*localeInfo, false);
const LocaleInfo* currentLocaleInfo = GetSysDefault();
if (currentLocaleInfo == nullptr) {
EXPECT_TRUE(false);
delete localeInfo;
return;
}
EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->GetLanguage()) == 0);
EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = BuildFromString("en-US", '-', state);
UpdateSysDefault(*localeInfo, false);
currentLocaleInfo = GetSysDefault();
if (currentLocaleInfo == nullptr) {
EXPECT_TRUE(false);
delete localeInfo;
return;
}
EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->GetLanguage()) == 0);
EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = BuildFromString("en-Qaag-US", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
UpdateSysDefault(*localeInfo, false);
currentLocaleInfo = GetSysDefault();
if (currentLocaleInfo == nullptr) {
EXPECT_TRUE(false);
delete localeInfo;
return;
}
EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->GetLanguage()) == 0);
EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->GetRegion()) == 0);
EXPECT_TRUE(std::strcmp("Qaag", currentLocaleInfo->GetScript()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoGetLanguageTest001
* @tc.desc: Test LocaleInfo GetLanguage
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoGetRegionTest001
* @tc.desc: Test LocaleInfo GetRegion
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoGetScriptTest001
* @tc.desc: Test LocaleInfo GetScript
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-Hant-CN", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromPartsTest001
* @tc.desc: Test BuildFromParts
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest001, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "CN", state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(state == SUCCESS);
EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0);
EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0);
EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromPartsTest002
* @tc.desc: Test BuildFromParts
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest002, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromParts("zh1", "Hant", "CN", state);
EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromPartsTest003
* @tc.desc: Test BuildFromParts
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest003, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromParts("zh", "Hants", "CN", state);
EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromPartsTest004
* @tc.desc: Test BuildFromParts
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest004, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "C", state);
EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromPartsTest005
* @tc.desc: Test BuildFromParts
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest005, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromParts(nullptr, "Hants", "CN", state);
EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromPartsTest006
* @tc.desc: Test BuildFromParts
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest006, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromParts("zh", nullptr, nullptr, state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(state == SUCCESS);
EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0);
EXPECT_TRUE(localeInfo->GetScript() == nullptr);
EXPECT_TRUE(localeInfo->GetRegion() == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest001
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-Hant-CN", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(state == SUCCESS);
EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0);
EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0);
EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest002
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh1-Hant-CN", '-', state);
EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest003
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("-Hant-CN", '-', state);
EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest004
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(state == SUCCESS);
EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0);
EXPECT_TRUE(localeInfo->GetScript() == nullptr);
EXPECT_TRUE(localeInfo->GetRegion() == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest005
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest005, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("en_US", '_', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(state == SUCCESS);
EXPECT_TRUE(std::strcmp("en", localeInfo->GetLanguage()) == 0);
EXPECT_TRUE(localeInfo->GetScript() == nullptr);
EXPECT_TRUE(std::strcmp("US", localeInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest006
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("en_Latn_US", '&', state);
EXPECT_TRUE(state == NOT_SUPPORT_SEP);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest007
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("en_Latn_US", '_', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(state == SUCCESS);
EXPECT_TRUE(std::strcmp("en", localeInfo->GetLanguage()) == 0);
EXPECT_TRUE(std::strcmp("Latn", localeInfo->GetScript()) == 0);
EXPECT_TRUE(std::strcmp("US", localeInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest008
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-Hants-CN", '-', state);
EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest009
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-Hant-C", '-', state);
EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG);
EXPECT_TRUE(localeInfo == nullptr);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoBuildFromStringTest0010
* @tc.desc: Test BuildFromString
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest0010, TestSize.Level1)
{
RState state = SUCCESS;
LocaleInfo* localeInfo = BuildFromString("zh-CN-xxxx", '-', state);
if (localeInfo == nullptr) {
EXPECT_TRUE(false);
return;
}
EXPECT_TRUE(state == SUCCESS);
EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0);
EXPECT_TRUE(localeInfo->GetScript() == nullptr);
EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0);
delete localeInfo;
localeInfo = nullptr;
}
/*
* @tc.name: LocaleInfoPerformanceFuncTest001
* @tc.desc: Test FindAndSort Performance
* @tc.type: FUNC
*/
HWTEST_F(LocaleInfoTest, LocaleInfoPerformanceFuncTest001, TestSize.Level1)
{
unsigned long long total = 0;
double average = 0;
std::vector<std::string> outValue;
for (int k = 0; k < 1000; ++k) {
auto t1 = std::chrono::high_resolution_clock::now();
std::vector<std::string> request;
std::vector<std::string> outValue;
request.push_back("en");
request.push_back("en-CN");
request.push_back("en-US");
request.push_back("en-GB");
request.push_back("");
std::string current = "en-US";
FindAndSort(current, request, outValue);
auto t2 = std::chrono::high_resolution_clock::now();
total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
}
average = total / 1000.0;
HILOG_DEBUG("avg cost FindAndSort: %f us", average);
EXPECT_LT(average, 500);
};
\ No newline at end of file
/*
* Copyright (c) 2021 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_LOCALE_INFO_TEST_H
#define RESOURCE_MANAGER_LOCALE_INFO_TEST_H
int LocaleInfoFindAndSortTest001();
int LocaleInfoFindAndSortTest002();
int LocaleInfoFindAndSortTest003();
int LocaleInfoFindAndSortTest004();
int LocaleInfoFindAndSortTest005();
int LocaleInfoUpdateSysDefaultTest001();
int LocaleInfoGetSysDefaultTest001();
int LocaleInfoGetLanguageTest001();
int LocaleInfoGetRegionTest001();
int LocaleInfoGetScriptTest001();
int LocaleInfoBuildFromPartsTest001();
int LocaleInfoBuildFromPartsTest002();
int LocaleInfoBuildFromPartsTest003();
int LocaleInfoBuildFromPartsTest004();
int LocaleInfoBuildFromPartsTest005();
int LocaleInfoBuildFromPartsTest006();
int LocaleInfoBuildFromStringTest001();
int LocaleInfoBuildFromStringTest002();
int LocaleInfoBuildFromStringTest003();
int LocaleInfoBuildFromStringTest004();
int LocaleInfoBuildFromStringTest005();
int LocaleInfoBuildFromStringTest006();
int LocaleInfoBuildFromStringTest007();
int LocaleInfoBuildFromStringTest008();
int LocaleInfoBuildFromStringTest009();
int LocaleInfoBuildFromStringTest0010();
int LocaleInfoPerformanceFuncTest001();
#endif // RESOURCE_MANAGER_LOCALE_INFO_TEST_H
/*
* Copyright (c) 2021 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_RES_CONFIG_IMPL_TEST_H
#define RESOURCE_MANAGER_RES_CONFIG_IMPL_TEST_H
int ResConfigImplMatchTest001();
int ResConfigImplMatchTest002();
int ResConfigImplMatchTest003();
int ResConfigImplMatchTest004();
int ResConfigImplMatchTest005();
int ResConfigImplMatchTest006();
int ResConfigImplMatchTest007();
int ResConfigImplMatchTest008();
int ResConfigImplMatchTest009();
int ResConfigImplMatchTest010();
int ResConfigImplMatchTest011();
int ResConfigImplMatchTest012();
int ResConfigImplMatchTest013();
int ResConfigImplMatchTest014();
int ResConfigImplMatchTest015();
int ResConfigImplMatchTest016();
int ResConfigImplMatchTest017();
int ResConfigImplMatchTest018();
int ResConfigImplMatchTest019();
int ResConfigImplMatchTest020();
int ResConfigImplMatchTest021();
int ResConfigImplMatchTest022();
int ResConfigImplMatchTest023();
int ResConfigImplMatchTest024();
int ResConfigImplMatchTest025();
int ResConfigImplMatchTest026();
int ResConfigImplMatchTest027();
int ResConfigImplMatchTest028();
int ResConfigImplMatchTest029();
int ResConfigImplIsMoreSuitableTest001();
int ResConfigImplIsMoreSuitableTest002();
int ResConfigImplIsMoreSuitableTest003();
int ResConfigImplIsMoreSuitableTest004();
int ResConfigImplIsMoreSuitableTest005();
int ResConfigImplIsMoreSuitableTest006();
int ResConfigImplIsMoreSuitableTest007();
int ResConfigImplIsMoreSuitableTest008();
int ResConfigImplIsMoreSuitableTest009();
int ResConfigImplIsMoreSuitableTest010();
int ResConfigImplIsMoreSuitableTest011();
int ResConfigImplIsMoreSuitableTest012();
int ResConfigImplIsMoreSuitableTest013();
int ResConfigImplIsMoreSuitableTest014();
int ResConfigImplIsMoreSuitableTest015();
int ResConfigImplIsMoreSuitableTest016();
int ResConfigImplIsMoreSuitableTest017();
int ResConfigImplIsMoreSuitableTest018();
int ResConfigImplIsMoreSuitableTest019();
int ResConfigImplIsMoreSuitableTest020();
int ResConfigImplIsMoreSuitableTest021();
int ResConfigImplIsMoreSuitableTest022();
int ResConfigImplIsMoreSuitableTest023();
int ResConfigImplIsMoreSuitableTest024();
int ResConfigImplIsMoreSuitableTest025();
int ResConfigImplIsMoreSuitableTest026();
int ResConfigImplIsMoreSuitableTest027();
int ResConfigImplIsMoreSuitableTest028();
int ResConfigImplIsMoreSuitableTest029();
int ResConfigImplIsMoreSuitableTest030();
int ResConfigImplIsMoreSuitableTest031();
int ResConfigImplIsMoreSuitableTest032();
int ResConfigImplIsMoreSuitableTest033();
int ResConfigImplIsMoreSuitableTest034();
int ResConfigImplIsMoreSuitableTest035();
int ResConfigImplIsMoreSuitableTest036();
int ResConfigImplIsMoreSuitableTest037();
int ResConfigImplIsMoreSuitableTest038();
int ResConfigImplIsMoreSuitableTest039();
int ResConfigImplIsMoreSuitableTest040();
int ResConfigImplIsMoreSuitableTest041();
int ResConfigImplIsMoreSuitableTest042();
int ResConfigImplIsMoreSuitableTest043();
int ResConfigImplIsMoreSuitableTest044();
int ResConfigImplIsMoreSuitableTest045();
int ResConfigImplIsMoreSuitableTest046();
int ResConfigImplIsMoreSuitableTest047();
int ResConfigImplIsMoreSuitableTest048();
int ResConfigImplIsMoreSuitableTest049();
int ResConfigImplIsMoreSuitableTest050();
#endif
/*
* Copyright (c) 2021 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 "res_config_test.h"
#include <climits>
#include <cstring>
#include <gtest/gtest.h>
#include "hap_resource.h"
#include "res_config.h"
#include "resource_manager_impl.h"
#include "test_common.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
class ResConfigTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void ResConfigTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void ResConfigTest::TearDownTestCase(void)
{
// step 2: input testsuit teardown step
}
void ResConfigTest::SetUp()
{
}
void ResConfigTest::TearDown()
{
}
/*
* @tc.name: ResConfigFuncTest001
* @tc.desc: Test Config function, non file case.
* @tc.type: FUNC
*/
HWTEST_F(ResConfigTest, ResConfigFuncTest001, TestSize.Level1)
{
ResConfigImpl *rc = new ResConfigImpl;
rc->SetLocaleInfo("en", nullptr, "AU");
ResConfigImpl *current = new ResConfigImpl;
current->SetLocaleInfo("en", nullptr, "GB");
ResConfigImpl *target = new ResConfigImpl;
target->SetLocaleInfo("zh", nullptr, "CN");
EXPECT_TRUE(rc->Match(current));
EXPECT_TRUE(rc->Match(target) == false);
delete target;
delete current;
delete rc;
};
\ No newline at end of file
/*
* Copyright (c) 2021 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_RES_CONFIG_TEST_H
#define RESOURCE_MANAGER_RES_CONFIG_TEST_H
int ResConfigFuncTest001();
#endif
/*
* Copyright (c) 2021 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 "res_desc_test.h"
#include <gtest/gtest.h>
#include "res_desc.h"
#include "test_common.h"
#include "utils/string_utils.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
class ResDescTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void ResDescTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void ResDescTest::TearDownTestCase(void)
{
// step 2: input testsuit teardown step
}
void ResDescTest::SetUp()
{
// step 3: input testcase setup step
HILOG_DEBUG("ResDescTest setup");
}
void ResDescTest::TearDown()
{
// step 4: input testcase teardown step
HILOG_DEBUG("ResDescTest teardown");
}
/*
* @tc.name: ResDescFuncTest001
* @tc.desc: Test IsRef function, non file case.
* @tc.type: FUNC
*/
HWTEST_F(ResDescTest, ResDescFuncTest001, TestSize.Level1)
{
std::string str;
int id;
ResType resType;
str.assign("abc");
EXPECT_TRUE(!IdItem::IsRef(str, resType, id));
str.assign("$abc");
EXPECT_TRUE(!IdItem::IsRef(str, resType, id));
str.assign("$abc:");
EXPECT_TRUE(!IdItem::IsRef(str, resType, id));
str.assign("$abc:abc");
EXPECT_TRUE(!IdItem::IsRef(str, resType, id));
str.assign("$abc:123456");
EXPECT_TRUE(!IdItem::IsRef(str, resType, id));
str.assign("$string:123456");
EXPECT_TRUE(IdItem::IsRef(str, resType, id));
EXPECT_EQ(ResType::STRING, resType);
EXPECT_EQ(123456, id);
str.assign("$boolean:100001");
EXPECT_TRUE(IdItem::IsRef(str, resType, id));
EXPECT_EQ(ResType::BOOLEAN, resType);
EXPECT_EQ(100001, id);
str.assign("$color:66666");
EXPECT_TRUE(IdItem::IsRef(str, resType, id));
EXPECT_EQ(ResType::COLOR, resType);
EXPECT_EQ(66666, id);
str.assign("$float:100002");
EXPECT_TRUE(IdItem::IsRef(str, resType, id));
EXPECT_EQ(ResType::FLOAT, resType);
EXPECT_EQ(100002, id);
str.assign("$integer:2008168");
EXPECT_TRUE(IdItem::IsRef(str, resType, id));
EXPECT_EQ(ResType::INTEGER, resType);
EXPECT_EQ(2008168, id);
str.assign("$pattern:654321");
EXPECT_TRUE(IdItem::IsRef(str, resType, id));
EXPECT_EQ(ResType::PATTERN, resType);
EXPECT_EQ(654321, id);
str.assign("$theme:99999");
EXPECT_TRUE(IdItem::IsRef(str, resType, id));
EXPECT_EQ(ResType::THEME, resType);
EXPECT_EQ(99999, id);
}
void TestKeyParam(KeyType keyType, int value, std::string expectStr)
{
KeyParam keyParam;
keyParam.type_ = keyType;
keyParam.value_ = value;
keyParam.InitStr();
EXPECT_EQ(expectStr, keyParam.str_);
}
/*
* @tc.name: ResDescFuncTest002
* @tc.desc: Test IsRef function, non file case.
* @tc.type: FUNC
*/
HWTEST_F(ResDescTest, ResDescFuncTest002, TestSize.Level1)
{
TestKeyParam(KeyType::LANGUAGES, 25966, "en");
TestKeyParam(KeyType::LANGUAGES, 31336, "zh");
TestKeyParam(KeyType::REGION, 21843, "US");
TestKeyParam(KeyType::REGION, 17230, "CN");
TestKeyParam(KeyType::DIRECTION, 0, VERTICAL);
TestKeyParam(KeyType::DIRECTION, 1, HORIZONTAL);
TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_PHONE, PHONE_STR);
TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_TABLET, TABLET_STR);
TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_CAR, CAR_STR);
TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_PC, PC_STR);
TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_TV, TV_STR);
TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_WEARABLE, WEARABLE_STR);
TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_NOT_SET, "not_device_type");
TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_SDPI, RE_120_STR);
TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_MDPI, RE_160_STR);
TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_LDPI, RE_240_STR);
TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XLDPI, RE_320_STR);
TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XXLDPI, RE_480_STR);
TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XXXLDPI, RE_640_STR);
TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_NOT_SET, "not_screen_density");
}
\ No newline at end of file
/*
* Copyright (c) 2021 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_RES_DESC_TEST_H
#define RESOURCE_MANAGER_RES_DESC_TEST_H
int ResDescFuncTest001();
int ResDescFuncTest002();
#endif
/*
* Copyright (c) 2021 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_PERF_TEST_H
#define RESOURCE_MANAGER_RESOURCE_MANANGER_PERF_TEST_H
int ResourceManagerPerformanceFuncTest001();
int ResourceManagerPerformanceFuncTest002();
int ResourceManagerPerformanceFuncTest003();
int ResourceManagerPerformanceFuncTest004();
int ResourceManagerPerformanceFuncTest005();
int ResourceManagerPerformanceFuncTest006();
int ResourceManagerPerformanceFuncTest007();
int ResourceManagerPerformanceFuncTest008();
int ResourceManagerPerformanceFuncTest009();
int ResourceManagerPerformanceFuncTest010();
int ResourceManagerPerformanceFuncTest011();
int ResourceManagerPerformanceFuncTest012();
int ResourceManagerPerformanceFuncTest013();
int ResourceManagerPerformanceFuncTest014();
int ResourceManagerPerformanceFuncTest015();
int ResourceManagerPerformanceFuncTest016();
int ResourceManagerPerformanceFuncTest017();
int ResourceManagerPerformanceFuncTest018();
int ResourceManagerPerformanceFuncTest019();
int ResourceManagerPerformanceFuncTest020();
int ResourceManagerPerformanceFuncTest021();
int ResourceManagerPerformanceFuncTest022();
int ResourceManagerPerformanceFuncTest023();
int ResourceManagerPerformanceFuncTest024();
int ResourceManagerPerformanceFuncTest025();
int ResourceManagerPerformanceFuncTest026();
int ResourceManagerPerformanceFuncTest027();
int ResourceManagerPerformanceFuncTest028();
int ResourceManagerPerformanceFuncTest029();
int ResourceManagerPerformanceFuncTest030();
int ResourceManagerPerformanceFuncTest031();
int ResourceManagerPerformanceFuncTest032();
#endif
/*
* Copyright (c) 2021 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_H
#define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_H
int ResourceManagerAddResourceTest001();
int ResourceManagerAddResourceTest002();
int ResourceManagerAddResourceTest003();
int ResourceManagerUpdateResConfigTest001();
int ResourceManagerUpdateResConfigTest002();
int ResourceManagerUpdateResConfigTest003();
int ResourceManagerUpdateResConfigTest004();
int ResourceManagerUpdateResConfigTest005();
int ResourceManagerGetResConfigTest001();
int ResourceManagerGetResConfigTest002();
int ResourceManagerGetStringByIdTest001();
int ResourceManagerGetStringByIdTest002();
int ResourceManagerGetStringByIdTest003();
int ResourceManagerGetStringByNameTest001();
int ResourceManagerGetStringByNameTest002();
int ResourceManagerGetStringByNameTest003();
int ResourceManagerGetStringFormatByIdTest001();
int ResourceManagerGetStringFormatByIdTest002();
int ResourceManagerGetStringFormatByNameTest001();
int ResourceManagerGetStringFormatByNameTest002();
int ResourceManagerGetStringArrayByIdTest001();
int ResourceManagerGetStringArrayByIdTest002();
int ResourceManagerGetStringArrayByNameTest001();
int ResourceManagerGetStringArrayByNameTest002();
int ResourceManagerGetPatternByIdTest001();
int ResourceManagerGetPatternByIdTest002();
int ResourceManagerGetPatternByIdTest003();
int ResourceManagerGetPatternByIdTest004();
int ResourceManagerGetPatternByNameTest001();
int ResourceManagerGetPatternByNameTest002();
int ResourceManagerGetPatternByNameTest003();
int ResourceManagerGetPatternByNameTest004();
int ResourceManagerGetPluralStringByIdTest001();
int ResourceManagerGetPluralStringByIdTest002();
int ResourceManagerGetPluralStringByIdTest003();
int ResourceManagerGetPluralStringByIdTest004();
int ResourceManagerGetPluralStringByIdTest005();
int ResourceManagerGetPluralStringByNameTest001();
int ResourceManagerGetPluralStringByNameTest002();
int ResourceManagerGetPluralStringByIdFormatTest001();
int ResourceManagerGetPluralStringByIdFormatTest002();
int ResourceManagerGetPluralStringByNameFormatTest001();
int ResourceManagerGetPluralStringByNameFormatTest002();
int ResourceManagerGetThemeByIdTest001();
int ResourceManagerGetThemeByIdTest002();
int ResourceManagerGetThemeByNameTest001();
int ResourceManagerGetThemeByNameTest002();
int ResourceManagerGetBooleanByIdTest001();
int ResourceManagerGetBooleanByIdTest002();
int ResourceManagerGetBooleanByNameTest001();
int ResourceManagerGetBooleanByNameTest002();
int ResourceManagerGetIntegerByIdTest001();
int ResourceManagerGetIntegerByIdTest002();
int ResourceManagerGetIntegerByNameTest001();
int ResourceManagerGetIntegerByNameTest002();
int ResourceManagerGetFloatByIdTest001();
int ResourceManagerGetFloatByIdTest002();
int ResourceManagerGetFloatByNameTest001();
int ResourceManagerGetFloatByNameTest002();
int ResourceManagerGetIntArrayByIdTest001();
int ResourceManagerGetIntArrayByIdTest002();
int ResourceManagerGetIntArrayByNameTest001();
int ResourceManagerGetIntArrayByNameTest002();
int ResourceManagerGetColorByIdTest001();
int ResourceManagerGetColorByIdTest002();
int ResourceManagerGetColorByNameTest001();
int ResourceManagerGetColorByNameTest002();
int ResourceManagerGetProfileByIdTest001();
int ResourceManagerGetProfileByIdTest002();
int ResourceManagerGetProfileByNameTest001();
int ResourceManagerGetProfileByNameTest002();
int ResourceManagerGetMediaByIdTest001();
int ResourceManagerGetMediaByIdTest002();
int ResourceManagerGetMediaByNameTest001();
int ResourceManagerGetMediaByNameTest002();
int ResourceManagerResolveReferenceTest001();
int ResourceManagerResolveParentReferenceTest001();
int ResourceManagerSameNameTest001();
#endif
/*
* Copyright (c) 2021 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 "string_utils_test.h"
#include <climits>
#include <gtest/gtest.h>
#include <types.h>
#include "test_common.h"
#include "utils/string_utils.h"
using namespace OHOS::Global::Resource;
using namespace testing::ext;
using namespace OHOS::I18N;
class StringUtilsTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void StringUtilsTest::SetUpTestCase(void)
{
// step 1: input testsuit setup step
g_logLevel = LOG_DEBUG;
}
void StringUtilsTest::TearDownTestCase(void)
{
// step 2: input testsuit teardown step
}
void StringUtilsTest::SetUp()
{
// step 3: input testcase setup step
}
void StringUtilsTest::TearDown()
{
// step 4: input testcase teardown step
}
/*
* @tc.name: StringUtilsFuncTest001
* @tc.desc: Test FormatString, none file case.
* @tc.type: FUNC
*/
HWTEST_F(StringUtilsTest, StringUtilsFuncTest001, TestSize.Level1)
{
std::string result = FormatString("%d", 10001);
EXPECT_EQ("10001", result);
result = FormatString("I'm %s, I'm %d", "cici", 5);
EXPECT_EQ("I'm cici, I'm 5", result);
}
\ No newline at end of file
/*
* Copyright (c) 2021 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_STRING_UTILS_TEST_H
#define RESOURCE_MANAGER_STRING_UTILS_TEST_H
int StringUtilsFuncTest001();
#endif
/*
* Copyright (c) 2021 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 "test_common.h"
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include "hilog_wrapper.h"
#include "utils/errors.h"
#if defined(__linux__)
#include <malloc.h>
#endif
namespace OHOS {
namespace Global {
namespace Resource {
std::string FormatFullPath(const char *fileRelativePath)
{
const char *value = "/user/data";
std::string result(value);
result.append("/");
result.append(fileRelativePath);
return result;
}
void PrintIdValues(const HapResource::IdValues *idValues)
{
HILOG_DEBUG("idvalues size: %u", idValues->GetLimitPathsConst().size());
for (size_t i = 0; i < idValues->GetLimitPathsConst().size(); ++i) {
auto limitPath = idValues->GetLimitPathsConst()[i];
HILOG_DEBUG("%zu: folder is: %s, value: %s", i, limitPath->GetFolder().c_str(),
limitPath->GetIdItem()->ToString().c_str());
}
}
void PrintMapString(const std::map<std::string, std::string> &value)
{
auto iter = value.begin();
for (; iter != value.end(); ++iter) {
std::string key = iter->first;
std::string val = iter->second;
HILOG_DEBUG("%s : %s", key.c_str(), val.c_str());
}
}
void PrintVectorString(const std::vector<std::string> &value)
{
for (size_t i = 0; i < value.size(); ++i) {
std::string val = value[i];
HILOG_DEBUG("%zu : %s", i, val.c_str());
}
}
ResConfig *CreateResConfig(const char *language, const char *script, const char *region)
{
ResConfig *resConfig = CreateResConfig();
if (resConfig == nullptr) {
return nullptr;
}
resConfig->SetLocaleInfo(language, script, region);
return resConfig;
}
} // namespace Resource
} // namespace Global
} // namespace OHOS
/*
* Copyright (c) 2021 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_TEST_COMMON_H
#define RESOURCE_MANAGER_TEST_COMMON_H
#include "hap_resource.h"
#include "hilog_wrapper.h"
#include <map>
#include <string>
#include <vector>
// this is relative path
static const char *g_resFilePath = "all/assets/entry/resources.index";
namespace OHOS {
namespace Global {
namespace Resource {
std::string FormatFullPath(const char *fileRelativePath);
void PrintIdValues(const HapResource::IdValues *idValues);
void PrintMapString(const std::map<std::string, std::string> &value);
void PrintVectorString(const std::vector<std::string> &value);
ResConfig *CreateResConfig(const char *language, const char *script, const char *region);
} // namespace Resource
} // namespace Global
} // namespace OHOS
#endif
# Copyright (C) 2021 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.
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("WeekPluralNumbertest") {
suite_name = "acts"
sources = [ "week_plural_number_test.cpp" ]
include_dirs = [
"//base/global/i18n_lite/interfaces/kits/i18n/include",
"//third_party/bounds_checking_function/include",
]
deps = [
"//base/global/i18n_lite/frameworks/i18n:global_i18n",
#"//third_party/bounds_checking_function:libsec_shared",
]
}
{
"kits": [
{
"push": [
"WeekPluralNumbertest->/data/local/tmp/WeekPluralNumbertest"
],
"type": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "WeekPluralNumbertest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "WeekPluralNumbertest Tests"
}
\ No newline at end of file
/*
* Copyright (C) 2021 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 OHOS_GLOBAL_I18N_WEEK_PLURAL_NUMBER_TEST_H
#define OHOS_GLOBAL_I18N_WEEK_PLURAL_NUMBER_TEST_H
int WeekPluralNumberTest0100();
int WeekPluralNumberTest0200();
int WeekPluralNumberTest0300();
int WeekPluralNumberTest0400();
int WeekPluralNumberTest0500();
int WeekPluralNumberTest0600();
int WeekPluralNumberTest0700();
int WeekPluralNumberTest0800();
int WeekPluralNumberTest0900();
int WeekPluralNumberTest1000();
int WeekPluralNumberTest1100();
int WeekPluralNumberTest1200();
int WeekPluralNumberTest1300();
int WeekPluralNumberTest1400();
int WeekPluralNumberTest1500();
int WeekPluralNumberTest1600();
int WeekPluralNumberTest1700();
int WeekPluralNumberTest1800();
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册