!421 代码及分支覆盖率整改

Merge pull request !421 from zhangdd_ewan/OpenHarmony-4.0-Beta1
This commit is contained in:
openharmony_ci 2023-05-23 15:04:19 +00:00 committed by Gitee
commit 11864d3c35
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 311 additions and 27 deletions

View File

@ -29,6 +29,9 @@ ohos_unittest("intl_test") {
"//third_party/icu/icu4c/source/common",
"//third_party/icu/icu4c/source/common/unicode",
"//third_party/icu/icu4c/source/i18n",
"//third_party/libphonenumber/cpp/src",
"//third_party/libphonenumber",
"//third_party/protobuf/src",
]
external_deps = [ "init:libbegetutil" ]
@ -37,6 +40,8 @@ ohos_unittest("intl_test") {
"//third_party/googletest:gtest_main",
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/libphonenumber/cpp:phonenumber_standard",
"//third_party/libpng:libpng",
]
}

View File

@ -18,15 +18,27 @@
#include <vector>
#include "collator.h"
#include "character.h"
#include "date_time_format.h"
#include "locale_compare.h"
#include "locale_config.h"
#include "locale_info.h"
#include "measure_data.h"
#include "number_format.h"
#include "phone_number_format.h"
#include "plural_rules.h"
#include "preferred_language.h"
#include "relative_time_format.h"
#include "utils.h"
#include "i18n_break_iterator.h"
#include "i18n_calendar.h"
#include "i18n_timezone.h"
#include "i18n_types.h"
#include "index_util.h"
#include "intl_test.h"
#include "system_locale_manager.h"
#include "taboo_utils.h"
#include "utils.h"
using namespace OHOS::Global::I18n;
using testing::ext::TestSize;
@ -1786,36 +1798,291 @@ HWTEST_F(IntlTest, IntlFuncTest0045, TestSize.Level1)
*/
HWTEST_F(IntlTest, IntlFuncTest0046, TestSize.Level1)
{
for (int i =0;i< 1 ;i++){
//北京
vector<std::string> Beijing = I18nTimeZone::GetTimezoneIdByLocation(116.3, 39.5);
EXPECT_TRUE(Beijing.size() == 1 && Beijing[0] == "Asia/Shanghai");
//洛杉矶
vector<std::string> LosAngeles = I18nTimeZone::GetTimezoneIdByLocation(-118.1, 34.0);
EXPECT_TRUE(LosAngeles.size() == 1 && LosAngeles[0] == "America/Los_Angeles");
//里约热内卢
vector<std::string> RIO = I18nTimeZone::GetTimezoneIdByLocation(-43.1, -22.5);
EXPECT_TRUE(RIO.size() == 1 && RIO[0] == "America/Sao_Paulo");
//悉尼
vector<std::string> Sydney = I18nTimeZone::GetTimezoneIdByLocation(150.5, -33.55);
EXPECT_TRUE(Sydney.size() == 1 && Sydney[0] == "Australia/Sydney");
//乌鲁木齐
vector<std::string> Urumqi = I18nTimeZone::GetTimezoneIdByLocation(87.7, 43.8);
EXPECT_TRUE(Urumqi.size() == 2);
bool containsShanghai = false;
bool containsUrumqi = false;
for(int i=0;i < Urumqi.size();i++){
if(Urumqi[i] == "Asia/Shanghai"){
containsShanghai = true;
}
if(Urumqi[i] == "Asia/Urumqi"){
containsUrumqi = true;
}
//北京
vector<std::string> Beijing = I18nTimeZone::GetTimezoneIdByLocation(116.3, 39.5);
EXPECT_TRUE(Beijing.size() == 1 && Beijing[0] == "Asia/Shanghai");
//洛杉矶
vector<std::string> LosAngeles = I18nTimeZone::GetTimezoneIdByLocation(-118.1, 34.0);
EXPECT_TRUE(LosAngeles.size() == 1 && LosAngeles[0] == "America/Los_Angeles");
//里约热内卢
vector<std::string> RIO = I18nTimeZone::GetTimezoneIdByLocation(-43.1, -22.5);
EXPECT_TRUE(RIO.size() == 1 && RIO[0] == "America/Sao_Paulo");
//悉尼
vector<std::string> Sydney = I18nTimeZone::GetTimezoneIdByLocation(150.5, -33.55);
EXPECT_TRUE(Sydney.size() == 1 && Sydney[0] == "Australia/Sydney");
//乌鲁木齐
vector<std::string> Urumqi = I18nTimeZone::GetTimezoneIdByLocation(87.7, 43.8);
EXPECT_TRUE(Urumqi.size() == 2);
bool containsShanghai = false;
bool containsUrumqi = false;
for(unsigned int i = 0; i < Urumqi.size(); i++){
if(Urumqi[i] == "Asia/Shanghai"){
containsShanghai = true;
}
if(Urumqi[i] == "Asia/Urumqi"){
containsUrumqi = true;
}
EXPECT_TRUE(containsShanghai);
EXPECT_TRUE(containsUrumqi);
}
EXPECT_TRUE(containsShanghai);
EXPECT_TRUE(containsUrumqi);
}
/**
* @tc.name: IntlFuncTest0047
* @tc.desc: Test Intl LocaleConfig GetBlockedLanguages
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0047, TestSize.Level1)
{
std::unordered_set<std::string> languageSet = LocaleConfig::GetBlockedLanguages();
EXPECT_TRUE(languageSet.size() == 1);
}
/**
* @tc.name: IntlFuncTest0048
* @tc.desc: Test Intl LocaleConfig GetBlockedRegions
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0048, TestSize.Level1)
{
std::unordered_set<std::string> regionSet = LocaleConfig::GetBlockedRegions();
EXPECT_TRUE(regionSet.size() == 0);
}
/**
* @tc.name: IntlFuncTest0049
* @tc.desc: Test Intl LocaleConfig GetLanguageBlockedRegions
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0049, TestSize.Level1)
{
std::unordered_set<std::string> blockedRegionSet = LocaleConfig::GetLanguageBlockedRegions();
EXPECT_EQ(blockedRegionSet.size(), 0);
std::string systemLanguage = LocaleConfig::GetSystemLanguage();
EXPECT_EQ(systemLanguage, "zh-Hans");
std::string systemRegion = LocaleConfig::GetSystemRegion();
EXPECT_EQ(systemRegion, "CN");
std::string systemLocale = LocaleConfig::GetSystemLocale();
EXPECT_EQ(systemLocale, "zh-Hans-CN");
const std::string locale = "zh-CN";
bool isRTL = LocaleConfig::IsRTL(locale);
EXPECT_TRUE(!isRTL);
std::string validLocale = LocaleConfig::GetValidLocale(locale);
EXPECT_EQ(validLocale, "zh-CN");
bool is24HourClock = LocaleConfig::Is24HourClock();
EXPECT_TRUE(!is24HourClock);
bool set24HourClock = LocaleConfig::Set24HourClock(true);
EXPECT_TRUE(!set24HourClock);
bool permission = LocaleConfig::CheckPermission();
EXPECT_TRUE(!permission);
bool usingLocalDigit = LocaleConfig::SetUsingLocalDigit(true);
EXPECT_TRUE(!usingLocalDigit);
usingLocalDigit = LocaleConfig::GetUsingLocalDigit();
EXPECT_TRUE(!usingLocalDigit);
}
/**
* @tc.name: IntlFuncTest0050
* @tc.desc: Test Intl PreferredLanguage AddPreferredLanguageExist
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0050, TestSize.Level1)
{
const std::string langugae = "zh-CN";
const std::string langugaeDe = "de-DE";
I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
PreferredLanguage::AddPreferredLanguage(langugae, 0, errorCode);
EXPECT_TRUE(errorCode != I18nErrorCode::SUCCESS);
PreferredLanguage::AddPreferredLanguage(langugaeDe, 1, errorCode);
EXPECT_TRUE(errorCode != I18nErrorCode::SUCCESS);
PreferredLanguage::AddPreferredLanguage(langugae, 3, errorCode);
EXPECT_TRUE(errorCode != I18nErrorCode::SUCCESS);
std::vector<std::string> list = PreferredLanguage::GetPreferredLanguageList();
EXPECT_EQ(list.size(), 1);
std::string firstPreferredLanguage = PreferredLanguage::GetFirstPreferredLanguage();
EXPECT_EQ(firstPreferredLanguage, "zh-Hans");
std::string preferredLocale = PreferredLanguage::GetPreferredLocale();
EXPECT_EQ(preferredLocale, "zh-CN");
bool flag = PreferredLanguage::RemovePreferredLanguage(0);
EXPECT_TRUE(!flag);
}
/**
* @tc.name: IntlFuncTest0051
* @tc.desc: Test Intl I18nCalendar
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0051, TestSize.Level1)
{
I18nCalendar *calendar = new I18nCalendar("zh-Hans-CN");
I18nCalendar *calendar2 = new I18nCalendar("zh-Hans-CN", CalendarType::CHINESE);
calendar->SetTime(1684742124645);
calendar->Set(1989, 5, 23);
std::string tzId = calendar2->GetTimeZone();
EXPECT_EQ(tzId, "Central Standard Time");
calendar->SetTimeZone("Asia/Shanghai");
int32_t minimalDaysInFirstWeek = calendar->GetMinimalDaysInFirstWeek();
EXPECT_EQ(minimalDaysInFirstWeek, 1);
int32_t firstDayOfWeek = calendar->GetFirstDayOfWeek();
EXPECT_EQ(firstDayOfWeek, 1);
bool isWeekend = calendar2->IsWeekend();
EXPECT_TRUE(isWeekend);
delete calendar;
delete calendar2;
}
/**
* @tc.name: IntlFuncTest0052
* @tc.desc: Test Intl IndexUtil
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0052, TestSize.Level1)
{
IndexUtil *indexUtil = new IndexUtil("zh-CN");
std::vector<std::string> indexList = indexUtil->GetIndexList();
EXPECT_EQ(indexList.size(), 28);
indexUtil->AddLocale("en-US");
std::string indexStr = indexUtil->GetIndex("A");
EXPECT_EQ(indexStr, "A");
delete indexUtil;
}
/**
* @tc.name: IntlFuncTest0053
* @tc.desc: Test Intl PhoneNumberFormat
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0053, TestSize.Level1)
{
map<string, string> options = {
{ "type", "national" }
};
PhoneNumberFormat *phoneNumberFormat = new PhoneNumberFormat("zh-CN", options);
std::string location = phoneNumberFormat->getLocationName("18622350085", "zh-CN");
EXPECT_EQ(location, "天津市");
bool flag = phoneNumberFormat->isValidPhoneNumber("+8618622350085");
EXPECT_TRUE(flag);
std::string number = "+8618622350085";
std::string formated = phoneNumberFormat->format(number);
EXPECT_EQ(formated, "186 2235 0085");
delete phoneNumberFormat;
}
/**
* @tc.name: IntlFuncTest0054
* @tc.desc: Test Intl TabooUtils
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0054, TestSize.Level1)
{
TabooUtils *tabooUtils = new TabooUtils();
std::string res1 = tabooUtils->ReplaceCountryName("CN", "en", "China");
EXPECT_EQ(res1, "China");
std::string res2 = tabooUtils->ReplaceLanguageName("zh", "en", "chinese");
EXPECT_EQ(res2, "chinese");
delete tabooUtils;
}
/**
* @tc.name: IntlFuncTest0055
* @tc.desc: Test Intl LocaleCompare
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0055, TestSize.Level1)
{
int32_t result = LocaleCompare::Compare("zh-CN", "zh-Hans-CN");
EXPECT_EQ(result, 9);
I18nBreakIterator *i18nBreakIterator = new I18nBreakIterator("zh-Hans-CN");
bool isBoundary = i18nBreakIterator->IsBoundary(6);
EXPECT_TRUE(!isBoundary);
int32_t current = i18nBreakIterator->Current();
EXPECT_EQ(current, 0);
int32_t first = i18nBreakIterator->First();
EXPECT_EQ(first, 0);
int32_t last = i18nBreakIterator->Last();
EXPECT_EQ(last, 0);
int32_t previous = i18nBreakIterator->Previous();
EXPECT_EQ(previous, -1);
int32_t next6 = i18nBreakIterator->Next(6);
EXPECT_EQ(next6, -1);
delete i18nBreakIterator;
}
/**
* @tc.name: IntlFuncTest0056
* @tc.desc: Test Intl SystemLocaleManager
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0056, TestSize.Level1)
{
SystemLocaleManager *systemLocaleManager = new SystemLocaleManager();
std::vector<std::string> languages = {"en", "de", "es", "fr"};
SortOptions sortOptions = {"en-US", true, true};
std::vector<LocaleItem> languageInfos = systemLocaleManager->GetLanguageInfoArray(languages, sortOptions);
EXPECT_EQ(languageInfos.size(), 4);
const std::vector<std::string> countries = {"US", "GB", "DE", "CA"};
std::vector<LocaleItem> countryInfos = systemLocaleManager->GetCountryInfoArray(countries, sortOptions);
EXPECT_EQ(countryInfos.size(), 4);
delete systemLocaleManager;
}
/**
* @tc.name: IntlFuncTest0057
* @tc.desc: Test Intl Utils
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0057, TestSize.Level1)
{
bool isDigit = IsDigit("55");
EXPECT_TRUE(isDigit);
bool isSpaceChar = IsSpaceChar(" ");
EXPECT_TRUE(isSpaceChar);
bool isWhiteSpace = IsWhiteSpace(" ");
EXPECT_TRUE(isWhiteSpace);
bool isRTLCharacter = IsRTLCharacter("^");
EXPECT_TRUE(!isRTLCharacter);
bool isIdeoGraphic = IsIdeoGraphic("&&*");
EXPECT_TRUE(!isIdeoGraphic);
bool isLetter = IsLetter("cccUt");
EXPECT_TRUE(isLetter);
bool isLowerCase = IsLowerCase("abc");
EXPECT_TRUE(isLowerCase);
bool isUpperCase = IsUpperCase("AbC");
EXPECT_TRUE(isUpperCase);
std::string getType = GetType("$$%");
EXPECT_EQ(getType, "U_CURRENCY_SYMBOL");
}
/**
* @tc.name: IntlFuncTest0058
* @tc.desc: Test Intl MeasureData
* @tc.type: FUNC
*/
HWTEST_F(IntlTest, IntlFuncTest0058, TestSize.Level1)
{
std::string timezoneId = "Asia/Shanghai";
I18nTimeZone *i18nTimeZone = new I18nTimeZone(timezoneId, true);
int32_t offset = i18nTimeZone->GetOffset(1684742124645);
EXPECT_EQ(offset, 28800000);
int32_t rawOffset = i18nTimeZone->GetRawOffset();
EXPECT_EQ(rawOffset, 28800000);
std::string tzId = i18nTimeZone->GetID();
EXPECT_EQ(tzId, "Asia/Shanghai");
std::string displayName = i18nTimeZone->GetDisplayName();
EXPECT_EQ(displayName, "中国标准时间");
std::string displayName2 = i18nTimeZone->GetDisplayName(true);
EXPECT_EQ(displayName2, "中国标准时间");
std::string displayName4 = i18nTimeZone->GetDisplayName("zh-CN", true);
EXPECT_EQ(displayName4, "中国标准时间");
std::unique_ptr<I18nTimeZone> timezone = I18nTimeZone::CreateInstance(timezoneId, true);
I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
std::set<std::string> set0 = I18nTimeZone::GetAvailableIDs(errorCode);
EXPECT_EQ(set0.size(), 437);
std::set<std::string> set1 = I18nTimeZone::GetAvailableZoneCityIDs();
EXPECT_EQ(set1.size(), 24);
delete i18nTimeZone;
uint32_t mask = GetMask("CN");
EXPECT_EQ(mask, 2462);
}
} // namespace I18n
} // namespace Global

View File

@ -65,6 +65,18 @@ int IntlFuncTest0043(void);
int IntlFuncTest0044(void);
int IntlFuncTest0045(void);
int IntlFuncTest0046(void);
int IntlFuncTest0047(void);
int IntlFuncTest0048(void);
int IntlFuncTest0049(void);
int IntlFuncTest0050(void);
int IntlFuncTest0051(void);
int IntlFuncTest0052(void);
int IntlFuncTest0053(void);
int IntlFuncTest0054(void);
int IntlFuncTest0055(void);
int IntlFuncTest0056(void);
int IntlFuncTest0057(void);
int IntlFuncTest0058(void);
} // namespace I18n
} // namespace Global
} // namespace OHOS