5#include "flutter/shell/platform/glfw/system_utils.h"
9#include "gtest/gtest.h"
17std::vector<LanguageInfo> SetAndRestoreLanguageAroundGettingLanguageInfo(
20 const char* lc_messages,
22 std::vector<const char*> env_vars{
28 std::map<const char*, const char*> new_values{
29 {env_vars[0], language},
30 {env_vars[1], lc_all},
31 {env_vars[2], lc_messages},
34 std::map<const char*, const char*> prior_values;
35 for (
auto var : env_vars) {
37 if (
value !=
nullptr) {
38 prior_values.emplace(var,
value);
40 const char* new_value = new_values.at(var);
41 if (new_value !=
nullptr) {
42 setenv(var, new_value, 1);
50 for (
auto [var,
value] : prior_values) {
51 setenv(var,
value, 1);
57TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoFull) {
58 const char* locale_string =
"en_GB.ISO-8859-1@euro:en_US:sv:zh_CN.UTF-8";
60 std::vector<LanguageInfo> languages =
61 SetAndRestoreLanguageAroundGettingLanguageInfo(locale_string,
nullptr,
64 EXPECT_EQ(languages.size(), 15UL);
66 EXPECT_STREQ(languages[0].language.c_str(),
"en");
67 EXPECT_STREQ(languages[0].territory.c_str(),
"GB");
68 EXPECT_STREQ(languages[0].codeset.c_str(),
"ISO-8859-1");
69 EXPECT_STREQ(languages[0].modifier.c_str(),
"euro");
71 EXPECT_STREQ(languages[1].language.c_str(),
"en");
72 EXPECT_STREQ(languages[1].territory.c_str(),
"GB");
73 EXPECT_STREQ(languages[1].codeset.c_str(),
"");
74 EXPECT_STREQ(languages[1].modifier.c_str(),
"euro");
76 EXPECT_STREQ(languages[2].language.c_str(),
"en");
77 EXPECT_STREQ(languages[2].territory.c_str(),
"");
78 EXPECT_STREQ(languages[2].codeset.c_str(),
"ISO-8859-1");
79 EXPECT_STREQ(languages[2].modifier.c_str(),
"euro");
81 EXPECT_STREQ(languages[3].language.c_str(),
"en");
82 EXPECT_STREQ(languages[3].territory.c_str(),
"");
83 EXPECT_STREQ(languages[3].codeset.c_str(),
"");
84 EXPECT_STREQ(languages[3].modifier.c_str(),
"euro");
86 EXPECT_STREQ(languages[4].language.c_str(),
"en");
87 EXPECT_STREQ(languages[4].territory.c_str(),
"GB");
88 EXPECT_STREQ(languages[4].codeset.c_str(),
"ISO-8859-1");
89 EXPECT_STREQ(languages[4].modifier.c_str(),
"");
91 EXPECT_STREQ(languages[5].language.c_str(),
"en");
92 EXPECT_STREQ(languages[5].territory.c_str(),
"GB");
93 EXPECT_STREQ(languages[5].codeset.c_str(),
"");
94 EXPECT_STREQ(languages[5].modifier.c_str(),
"");
96 EXPECT_STREQ(languages[6].language.c_str(),
"en");
97 EXPECT_STREQ(languages[6].territory.c_str(),
"");
98 EXPECT_STREQ(languages[6].codeset.c_str(),
"ISO-8859-1");
99 EXPECT_STREQ(languages[6].modifier.c_str(),
"");
101 EXPECT_STREQ(languages[7].language.c_str(),
"en");
102 EXPECT_STREQ(languages[7].territory.c_str(),
"");
103 EXPECT_STREQ(languages[7].codeset.c_str(),
"");
104 EXPECT_STREQ(languages[7].modifier.c_str(),
"");
106 EXPECT_STREQ(languages[8].language.c_str(),
"en");
107 EXPECT_STREQ(languages[8].territory.c_str(),
"US");
108 EXPECT_STREQ(languages[8].codeset.c_str(),
"");
109 EXPECT_STREQ(languages[8].modifier.c_str(),
"");
111 EXPECT_STREQ(languages[9].language.c_str(),
"en");
112 EXPECT_STREQ(languages[9].territory.c_str(),
"");
113 EXPECT_STREQ(languages[9].codeset.c_str(),
"");
114 EXPECT_STREQ(languages[9].modifier.c_str(),
"");
116 EXPECT_STREQ(languages[10].language.c_str(),
"sv");
117 EXPECT_STREQ(languages[10].territory.c_str(),
"");
118 EXPECT_STREQ(languages[10].codeset.c_str(),
"");
119 EXPECT_STREQ(languages[10].modifier.c_str(),
"");
121 EXPECT_STREQ(languages[11].language.c_str(),
"zh");
122 EXPECT_STREQ(languages[11].territory.c_str(),
"CN");
123 EXPECT_STREQ(languages[11].codeset.c_str(),
"UTF-8");
124 EXPECT_STREQ(languages[11].modifier.c_str(),
"");
126 EXPECT_STREQ(languages[12].language.c_str(),
"zh");
127 EXPECT_STREQ(languages[12].territory.c_str(),
"CN");
128 EXPECT_STREQ(languages[12].codeset.c_str(),
"");
129 EXPECT_STREQ(languages[12].modifier.c_str(),
"");
131 EXPECT_STREQ(languages[13].language.c_str(),
"zh");
132 EXPECT_STREQ(languages[13].territory.c_str(),
"");
133 EXPECT_STREQ(languages[13].codeset.c_str(),
"UTF-8");
134 EXPECT_STREQ(languages[13].modifier.c_str(),
"");
136 EXPECT_STREQ(languages[14].language.c_str(),
"zh");
137 EXPECT_STREQ(languages[14].territory.c_str(),
"");
138 EXPECT_STREQ(languages[14].codeset.c_str(),
"");
139 EXPECT_STREQ(languages[14].modifier.c_str(),
"");
142TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoWeird) {
143 const char* locale_string =
"tt_RU@iqtelif.UTF-8";
144 std::vector<LanguageInfo> languages =
145 SetAndRestoreLanguageAroundGettingLanguageInfo(locale_string,
nullptr,
148 EXPECT_EQ(languages.size(), 4UL);
150 EXPECT_STREQ(languages[0].language.c_str(),
"tt");
151 EXPECT_STREQ(languages[0].territory.c_str(),
"RU");
152 EXPECT_STREQ(languages[0].codeset.c_str(),
"");
153 EXPECT_STREQ(languages[0].modifier.c_str(),
"iqtelif.UTF-8");
155 EXPECT_STREQ(languages[1].language.c_str(),
"tt");
156 EXPECT_STREQ(languages[1].territory.c_str(),
"");
157 EXPECT_STREQ(languages[1].codeset.c_str(),
"");
158 EXPECT_STREQ(languages[1].modifier.c_str(),
"iqtelif.UTF-8");
160 EXPECT_STREQ(languages[2].language.c_str(),
"tt");
161 EXPECT_STREQ(languages[2].territory.c_str(),
"RU");
162 EXPECT_STREQ(languages[2].codeset.c_str(),
"");
163 EXPECT_STREQ(languages[2].modifier.c_str(),
"");
165 EXPECT_STREQ(languages[3].language.c_str(),
"tt");
166 EXPECT_STREQ(languages[3].territory.c_str(),
"");
167 EXPECT_STREQ(languages[3].codeset.c_str(),
"");
168 EXPECT_STREQ(languages[3].modifier.c_str(),
"");
171TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoEmpty) {
172 const char* locale_string =
"";
173 std::vector<LanguageInfo> languages =
174 SetAndRestoreLanguageAroundGettingLanguageInfo(
175 locale_string, locale_string, locale_string, locale_string);
177 EXPECT_EQ(languages.size(), 1UL);
179 EXPECT_STREQ(languages[0].language.c_str(),
"C");
185TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoEnvVariableOrdering1) {
186 const char* language =
"de";
187 const char* lc_all =
"en";
188 const char* lc_messages =
"zh";
189 const char*
lang =
"tt";
191 std::vector<LanguageInfo> languages =
192 SetAndRestoreLanguageAroundGettingLanguageInfo(language, lc_all,
195 EXPECT_EQ(languages.size(), 1UL);
196 EXPECT_STREQ(languages[0].language.c_str(), language);
199TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoEnvVariableOrdering2) {
200 const char* lc_all =
"en";
201 const char* lc_messages =
"zh";
202 const char*
lang =
"tt";
204 std::vector<LanguageInfo> languages =
205 SetAndRestoreLanguageAroundGettingLanguageInfo(
nullptr, lc_all,
208 EXPECT_EQ(languages.size(), 1UL);
209 EXPECT_STREQ(languages[0].language.c_str(), lc_all);
212TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoEnvVariableOrdering3) {
213 const char* lc_messages =
"zh";
214 const char*
lang =
"tt";
216 std::vector<LanguageInfo> languages =
217 SetAndRestoreLanguageAroundGettingLanguageInfo(
nullptr,
nullptr,
220 EXPECT_EQ(languages.size(), 1UL);
221 EXPECT_STREQ(languages[0].language.c_str(), lc_messages);
224TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoEnvVariableOrdering4) {
225 const char*
lang =
"tt";
227 std::vector<LanguageInfo> languages =
228 SetAndRestoreLanguageAroundGettingLanguageInfo(
nullptr,
nullptr,
nullptr,
231 EXPECT_EQ(languages.size(), 1UL);
232 EXPECT_STREQ(languages[0].language.c_str(),
lang);
235TEST(FlutterGlfwSystemUtilsTest, GetPreferredLanuageInfoEnvVariableOrdering5) {
236 std::vector<LanguageInfo> languages =
237 SetAndRestoreLanguageAroundGettingLanguageInfo(
nullptr,
nullptr,
nullptr,
240 EXPECT_EQ(languages.size(), 1UL);
241 EXPECT_STREQ(languages[0].language.c_str(),
"C");
244TEST(FlutterGlfwSystemUtilsTest, ConvertToFlutterLocaleEmpty) {
245 std::vector<LanguageInfo> languages;
252TEST(FlutterGlfwSystemUtilsTest, ConvertToFlutterLocaleNonEmpty) {
253 std::vector<LanguageInfo> languages;
254 languages.push_back(LanguageInfo{
"en",
"US",
"",
""});
255 languages.push_back(LanguageInfo{
"tt",
"RU",
"",
"iqtelif.UTF-8"});
256 languages.push_back(LanguageInfo{
"sv",
"",
"",
""});
257 languages.push_back(LanguageInfo{
"de",
"DE",
"UTF-8",
"euro"});
258 languages.push_back(LanguageInfo{
"zh",
"CN",
"UTF-8",
""});
262 EXPECT_EQ(locales.size(), 5UL);
265 EXPECT_STREQ(locales[0].language_code,
"en");
266 EXPECT_STREQ(locales[0].country_code,
"US");
267 EXPECT_EQ(locales[0].script_code,
nullptr);
268 EXPECT_EQ(locales[0].variant_code,
nullptr);
270 EXPECT_STREQ(locales[1].language_code,
"tt");
271 EXPECT_STREQ(locales[1].country_code,
"RU");
272 EXPECT_EQ(locales[1].script_code,
nullptr);
273 EXPECT_STREQ(locales[1].variant_code,
"iqtelif.UTF-8");
275 EXPECT_STREQ(locales[2].language_code,
"sv");
276 EXPECT_EQ(locales[2].country_code,
nullptr);
277 EXPECT_EQ(locales[2].script_code,
nullptr);
278 EXPECT_EQ(locales[2].variant_code,
nullptr);
280 EXPECT_STREQ(locales[3].language_code,
"de");
281 EXPECT_STREQ(locales[3].country_code,
"DE");
282 EXPECT_STREQ(locales[3].script_code,
"UTF-8");
283 EXPECT_STREQ(locales[3].variant_code,
"euro");
285 EXPECT_STREQ(locales[4].language_code,
"zh");
286 EXPECT_STREQ(locales[4].country_code,
"CN");
287 EXPECT_STREQ(locales[4].script_code,
"UTF-8");
288 EXPECT_EQ(locales[4].variant_code,
nullptr);
TEST(FrameTimingsRecorderTest, RecordVsync)
std::vector< FlutterLocale > ConvertToFlutterLocale(const std::vector< LanguageInfo > &languages)
std::vector< LanguageInfo > GetPreferredLanguageInfo()
#define EXPECT_TRUE(handle)