• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "locale_config.h"
18 #include "preferred_language.h"
19 
20 using namespace OHOS::Global::I18n;
21 using testing::ext::TestSize;
22 using namespace std;
23 
24 namespace OHOS {
25 namespace Global {
26 namespace I18n {
27 class I18nTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase(void)35 void I18nTest::SetUpTestCase(void)
36 {}
37 
TearDownTestCase(void)38 void I18nTest::TearDownTestCase(void)
39 {}
40 
SetUp(void)41 void I18nTest::SetUp(void)
42 {}
43 
TearDown(void)44 void I18nTest::TearDown(void)
45 {}
46 
47 /**
48  * @tc.name: I18nFuncTest001
49  * @tc.desc: Test I18n PreferredLanguage GetPreferredLocale
50  * @tc.type: FUNC
51  */
52 HWTEST_F(I18nTest, I18nFuncTest001, TestSize.Level1)
53 {
54     string preferredLocale = PreferredLanguage::GetPreferredLocale();
55     EXPECT_TRUE(preferredLocale.size() > 0);
56     string systemLocale = "zh-Hans-CN";
57     if (LocaleConfig::SetSystemLocale(systemLocale)) {
58         if (PreferredLanguage::AddPreferredLanguage("en-US", 0)) {
59             preferredLocale = PreferredLanguage::GetPreferredLocale();
60             EXPECT_EQ(preferredLocale, "en-CN");
61         }
62     }
63 }
64 } // namespace I18n
65 } // namespace Global
66 } // namespace OHOS