Flutter Engine
fuchsia_intl_unittest.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 <fuchsia/intl/cpp/fidl.h>
6 
7 #include "flutter/fml/icu_util.h"
8 #include "gtest/gtest.h"
9 
10 #include "fuchsia_intl.h"
11 
12 using fuchsia::intl::CalendarId;
13 using fuchsia::intl::LocaleId;
14 using fuchsia::intl::Profile;
15 using fuchsia::intl::TemperatureUnit;
16 using fuchsia::intl::TimeZoneId;
17 
18 namespace flutter_runner {
19 namespace {
20 
21 class FuchsiaIntlTest : public testing::Test {
22  public:
23  static void SetUpTestCase() {
24  testing::Test::SetUpTestCase();
25  // The icudtl data must be present as a resource in the package for this
26  // load to succeed.
27  fml::icu::InitializeICU("/pkg/data/icudtl.dat");
28  }
29 };
30 
31 TEST_F(FuchsiaIntlTest, MakeLocalizationPlatformMessageData_SimpleLocale) {
32  Profile profile{};
33  profile.set_locales({LocaleId{.id = "en-US"}});
34  const std::string expected =
35  R"({"method":"setLocale","args":["en","US","",""]})";
36  const auto actual = MakeLocalizationPlatformMessageData(profile);
37  ASSERT_EQ(expected, std::string(actual.begin(), actual.end()));
38 }
39 
40 TEST_F(FuchsiaIntlTest, MakeLocalizationPlatformMessageData_OneLocale) {
41  Profile profile{};
42  profile
43  .set_locales({LocaleId{.id = "en-US-u-ca-gregory-fw-sun-hc-h12-ms-"
44  "ussystem-nu-latn-tz-usnyc"}})
45  .set_calendars({CalendarId{.id = "und-u-gregory"}})
46  .set_time_zones({TimeZoneId{.id = "America/New_York"}})
47  .set_temperature_unit(TemperatureUnit::FAHRENHEIT);
48  const std::string expected =
49  R"({"method":"setLocale","args":["en","US","",""]})";
50  const auto actual = MakeLocalizationPlatformMessageData(profile);
51  ASSERT_EQ(expected, std::string(actual.begin(), actual.end()));
52 }
53 
54 TEST_F(FuchsiaIntlTest, MakeLocalizationPlatformMessageData_MultipleLocales) {
55  Profile profile{};
56  profile
57  .set_locales({LocaleId{.id = "en-US-u-ca-gregory-fw-sun-hc-h12-ms-"
58  "ussystem-nu-latn-tz-usnyc"},
59  LocaleId{.id = "sl-Latn-IT-nedis"},
60  LocaleId{.id = "zh-Hans"}, LocaleId{.id = "sr-Cyrl-CS"}})
61  .set_calendars({CalendarId{.id = "und-u-gregory"}})
62  .set_time_zones({TimeZoneId{.id = "America/New_York"}})
63  .set_temperature_unit(TemperatureUnit::FAHRENHEIT);
64  const std::string expected =
65  R"({"method":"setLocale","args":["en","US","","","sl","IT","Latn","nedis",)"
66  R"("zh","","Hans","","sr","CS","Cyrl",""]})";
67  const auto actual = MakeLocalizationPlatformMessageData(profile);
68  ASSERT_EQ(expected, std::string(actual.begin(), actual.end()));
69 }
70 
71 } // namespace
72 } // namespace flutter_runner
std::vector< uint8_t > MakeLocalizationPlatformMessageData(const Profile &intl_profile)
Definition: fuchsia_intl.cc:30
void InitializeICU(const std::string &icu_data_path)
Definition: icu_util.cc:103
TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies)