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.GetMapping(),
38  actual.GetMapping() + actual.GetSize()));
39 }
40 
41 TEST_F(FuchsiaIntlTest, MakeLocalizationPlatformMessageData_OneLocale) {
42  Profile profile{};
43  profile
44  .set_locales({LocaleId{.id = "en-US-u-ca-gregory-fw-sun-hc-h12-ms-"
45  "ussystem-nu-latn-tz-usnyc"}})
46  .set_calendars({CalendarId{.id = "und-u-gregory"}})
47  .set_time_zones({TimeZoneId{.id = "America/New_York"}})
48  .set_temperature_unit(TemperatureUnit::FAHRENHEIT);
49  const std::string expected =
50  R"({"method":"setLocale","args":["en","US","",""]})";
51  const auto actual = MakeLocalizationPlatformMessageData(profile);
52  ASSERT_EQ(expected, std::string(actual.GetMapping(),
53  actual.GetMapping() + actual.GetSize()));
54 }
55 
56 TEST_F(FuchsiaIntlTest, MakeLocalizationPlatformMessageData_MultipleLocales) {
57  Profile profile{};
58  profile
59  .set_locales({LocaleId{.id = "en-US-u-ca-gregory-fw-sun-hc-h12-ms-"
60  "ussystem-nu-latn-tz-usnyc"},
61  LocaleId{.id = "sl-Latn-IT-nedis"},
62  LocaleId{.id = "zh-Hans"}, LocaleId{.id = "sr-Cyrl-CS"}})
63  .set_calendars({CalendarId{.id = "und-u-gregory"}})
64  .set_time_zones({TimeZoneId{.id = "America/New_York"}})
65  .set_temperature_unit(TemperatureUnit::FAHRENHEIT);
66  const std::string expected =
67  R"({"method":"setLocale","args":["en","US","","","sl","IT","Latn","nedis",)"
68  R"("zh","","Hans","","sr","CS","Cyrl",""]})";
69  const auto actual = MakeLocalizationPlatformMessageData(profile);
70  ASSERT_EQ(expected, std::string(actual.GetMapping(),
71  actual.GetMapping() + actual.GetSize()));
72 }
73 
74 } // namespace
75 } // namespace flutter_runner
void InitializeICU(const std::string &icu_data_path)
Definition: icu_util.cc:103
fml::MallocMapping MakeLocalizationPlatformMessageData(const Profile &intl_profile)
Definition: fuchsia_intl.cc:29
TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies)