/* * Copyright (c) 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 #include "locale_config.h" #include "preferred_language.h" using namespace OHOS::Global::I18n; using testing::ext::TestSize; using namespace std; namespace OHOS { namespace Global { namespace I18n { class I18nTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); }; void I18nTest::SetUpTestCase(void) {} void I18nTest::TearDownTestCase(void) {} void I18nTest::SetUp(void) {} void I18nTest::TearDown(void) {} /** * @tc.name: I18nFuncTest001 * @tc.desc: Test I18n PreferredLanguage GetPreferredLocale * @tc.type: FUNC */ HWTEST_F(I18nTest, I18nFuncTest001, TestSize.Level1) { string preferredLocale = PreferredLanguage::GetPreferredLocale(); EXPECT_TRUE(preferredLocale.size() > 0); string systemLocale = "zh-Hans-CN"; if (LocaleConfig::SetSystemLocale(systemLocale)) { if (PreferredLanguage::AddPreferredLanguage("en-US", 0)) { preferredLocale = PreferredLanguage::GetPreferredLocale(); EXPECT_EQ(preferredLocale, "en-CN"); } } } } // namespace I18n } // namespace Global } // namespace OHOS