Flutter Engine
system_utils_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <cwchar>
6 
7 #include "flutter/shell/platform/windows/system_utils.h"
8 #include "gtest/gtest.h"
9 
10 namespace flutter {
11 namespace testing {
12 
14  std::vector<LanguageInfo> languages = GetPreferredLanguageInfo();
15  // There should be at least one language.
16  ASSERT_GE(languages.size(), 1);
17  // The info should have a valid languge.
18  EXPECT_GE(languages[0].language.size(), 2);
19 }
20 
21 TEST(SystemUtils, GetPreferredLanguages) {
22  std::vector<std::wstring> languages = GetPreferredLanguages();
23  // There should be at least one language.
24  ASSERT_GE(languages.size(), 1);
25  // The language should be non-empty.
26  EXPECT_FALSE(languages[0].empty());
27  // There should not be a trailing null from the parsing step.
28  EXPECT_EQ(languages[0].size(), wcslen(languages[0].c_str()));
29 }
30 
31 TEST(SystemUtils, ParseLanguageNameGeneric) {
32  LanguageInfo info = ParseLanguageName(L"en");
33  EXPECT_EQ(info.language, "en");
34  EXPECT_TRUE(info.region.empty());
35  EXPECT_TRUE(info.script.empty());
36 }
37 
38 TEST(SystemUtils, ParseLanguageNameWithRegion) {
39  LanguageInfo info = ParseLanguageName(L"hu-HU");
40  EXPECT_EQ(info.language, "hu");
41  EXPECT_EQ(info.region, "HU");
42  EXPECT_TRUE(info.script.empty());
43 }
44 
45 TEST(SystemUtils, ParseLanguageNameWithScript) {
46  LanguageInfo info = ParseLanguageName(L"us-Latn");
47  EXPECT_EQ(info.language, "us");
48  EXPECT_TRUE(info.region.empty());
49  EXPECT_EQ(info.script, "Latn");
50 }
51 
52 TEST(SystemUtils, ParseLanguageNameWithRegionAndScript) {
53  LanguageInfo info = ParseLanguageName(L"uz-Latn-UZ");
54  EXPECT_EQ(info.language, "uz");
55  EXPECT_EQ(info.region, "UZ");
56  EXPECT_EQ(info.script, "Latn");
57 }
58 
59 TEST(SystemUtils, ParseLanguageNameWithSuplementalLanguage) {
60  LanguageInfo info = ParseLanguageName(L"en-US-x-fabricam");
61  EXPECT_EQ(info.language, "en");
62  EXPECT_EQ(info.region, "US");
63  EXPECT_TRUE(info.script.empty());
64 }
65 
66 // Ensure that ISO 639-2/T codes are handled.
67 TEST(SystemUtils, ParseLanguageNameWithThreeCharacterLanguage) {
68  LanguageInfo info = ParseLanguageName(L"ale-ZZ");
69  EXPECT_EQ(info.language, "ale");
70  EXPECT_EQ(info.region, "ZZ");
71  EXPECT_TRUE(info.script.empty());
72 }
73 
74 } // namespace testing
75 } // namespace flutter
std::string language
Definition: system_utils.h:17
std::vector< std::wstring > GetPreferredLanguages()
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
LanguageInfo ParseLanguageName(std::wstring language_name)
std::vector< LanguageInfo > GetPreferredLanguageInfo()
TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithNoMutations)