Flutter Engine
The 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 <cstring>
6#include <cwchar>
7
8#include "flutter/fml/macros.h"
9#include "flutter/shell/platform/windows/system_utils.h"
10#include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h"
11#include "gtest/gtest.h"
12
13namespace flutter {
14namespace testing {
15
17 WindowsProcTable proc_table;
18 std::vector<LanguageInfo> languages =
20 // There should be at least one language.
21 ASSERT_GE(languages.size(), 1);
22 // The info should have a valid languge.
23 EXPECT_GE(languages[0].language.size(), 2);
24}
25
27 MockWindowsProcTable proc_table;
28 EXPECT_CALL(proc_table, GetThreadPreferredUILanguages)
29 .WillRepeatedly(
30 [](DWORD flags, PULONG count, PZZWSTR languages, PULONG size) {
31 // Languages string ends in a double-null.
32 static const wchar_t lang[] = L"en-US\0";
33 static const size_t lang_len = sizeof(lang) / sizeof(wchar_t);
34 static const int cnt = 1;
35 if (languages == nullptr) {
36 *size = lang_len;
37 *count = cnt;
38 } else if (*size >= lang_len) {
39 memcpy(languages, lang, lang_len * sizeof(wchar_t));
40 }
41 return TRUE;
42 });
43 std::vector<std::wstring> languages = GetPreferredLanguages(proc_table);
44 // There should be at least one language.
45 ASSERT_GE(languages.size(), 1);
46 // The language should be non-empty.
47 EXPECT_FALSE(languages[0].empty());
48 // There should not be a trailing null from the parsing step.
49 EXPECT_EQ(languages[0].size(), wcslen(languages[0].c_str()));
50 EXPECT_EQ(languages[0], L"en-US");
51}
52
53TEST(SystemUtils, ParseLanguageNameGeneric) {
55 EXPECT_EQ(info.language, "en");
56 EXPECT_TRUE(info.region.empty());
57 EXPECT_TRUE(info.script.empty());
58}
59
60TEST(SystemUtils, ParseLanguageNameWithRegion) {
62 EXPECT_EQ(info.language, "hu");
63 EXPECT_EQ(info.region, "HU");
64 EXPECT_TRUE(info.script.empty());
65}
66
67TEST(SystemUtils, ParseLanguageNameWithScript) {
69 EXPECT_EQ(info.language, "us");
70 EXPECT_TRUE(info.region.empty());
71 EXPECT_EQ(info.script, "Latn");
72}
73
74TEST(SystemUtils, ParseLanguageNameWithRegionAndScript) {
75 LanguageInfo info = ParseLanguageName(L"uz-Latn-UZ");
76 EXPECT_EQ(info.language, "uz");
77 EXPECT_EQ(info.region, "UZ");
78 EXPECT_EQ(info.script, "Latn");
79}
80
81TEST(SystemUtils, ParseLanguageNameWithSuplementalLanguage) {
82 LanguageInfo info = ParseLanguageName(L"en-US-x-fabricam");
83 EXPECT_EQ(info.language, "en");
84 EXPECT_EQ(info.region, "US");
85 EXPECT_TRUE(info.script.empty());
86}
87
88// Ensure that ISO 639-2/T codes are handled.
89TEST(SystemUtils, ParseLanguageNameWithThreeCharacterLanguage) {
91 EXPECT_EQ(info.language, "ale");
92 EXPECT_EQ(info.region, "ZZ");
93 EXPECT_TRUE(info.script.empty());
94}
95
96TEST(SystemUtils, GetUserTimeFormat) {
97 // The value varies based on machine; just ensure that something is returned.
98 EXPECT_FALSE(GetUserTimeFormat().empty());
99}
100
101TEST(SystemUtils, Prefer24HourTimeHandlesEmptyFormat) {
102 EXPECT_FALSE(Prefer24HourTime(L""));
103}
104
105TEST(SystemUtils, Prefer24HourTimeHandles12Hour) {
106 EXPECT_FALSE(Prefer24HourTime(L"h:mm:ss tt"));
107}
108
109TEST(SystemUtils, Prefer24HourTimeHandles24Hour) {
110 EXPECT_TRUE(Prefer24HourTime(L"HH:mm:ss"));
111}
112
113} // namespace testing
114} // namespace flutter
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
int count
Definition: FontMgrTest.cpp:50
Mock for the |WindowsProcTable| base class.
EMSCRIPTEN_KEEPALIVE void empty()
FlutterSemanticsFlag flags
TEST(DisplayListComplexity, EmptyDisplayList)
std::wstring GetUserTimeFormat()
std::vector< std::wstring > GetPreferredLanguages(const WindowsProcTable &windows_proc_table)
Definition: system_utils.cc:45
std::vector< LanguageInfo > GetPreferredLanguageInfo()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
LanguageInfo ParseLanguageName(std::wstring language_name)
Definition: system_utils.cc:71
bool Prefer24HourTime(std::wstring time_format)
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678
unsigned long DWORD
Definition: windows_types.h:22