Flutter Engine
The Flutter Engine
Macros | Functions
fl_settings_plugin_test.cc File Reference
#include "flutter/shell/platform/linux/fl_settings_plugin.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
#include "flutter/shell/platform/linux/fl_engine_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_value.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/mock_binary_messenger.h"
#include "flutter/shell/platform/linux/testing/mock_settings.h"
#include "flutter/testing/testing.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Macros

#define EXPECT_SETTING(messenger, key, value)
 

Functions

 MATCHER_P2 (HasSetting, key, value, "")
 
 TEST (FlSettingsPluginTest, AlwaysUse24HourFormat)
 
 TEST (FlSettingsPluginTest, PlatformBrightness)
 
 TEST (FlSettingsPluginTest, TextScaleFactor)
 
 TEST (FlSettingsPluginTest, AccessibilityFeatures)
 

Macro Definition Documentation

◆ EXPECT_SETTING

#define EXPECT_SETTING (   messenger,
  key,
  value 
)
Value:
EXPECT_CALL( \
messenger, \
::testing::Eq<FlBinaryMessenger*>(messenger), \
::testing::StrEq("flutter/settings"), HasSetting(key, value), \
::testing::A<GCancellable*>(), ::testing::A<GAsyncReadyCallback>(), \
::testing::A<gpointer>()))
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
uint8_t value

Definition at line 31 of file fl_settings_plugin_test.cc.

Function Documentation

◆ MATCHER_P2()

MATCHER_P2 ( HasSetting  ,
key  ,
value  ,
""   
)

Definition at line 20 of file fl_settings_plugin_test.cc.

20 {
21 g_autoptr(FlJsonMessageCodec) codec = fl_json_message_codec_new();
22 g_autoptr(FlValue) message =
23 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), arg, nullptr);
25 return true;
26 }
27 *result_listener << ::testing::PrintToString(message);
28 return false;
29}
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
Win32Message message
static CStringUniquePtr PrintToString(const char *format,...)
Definition: uri.cc:41

◆ TEST() [1/4]

TEST ( FlSettingsPluginTest  ,
AccessibilityFeatures   
)

Definition at line 120 of file fl_settings_plugin_test.cc.

120 {
121 g_autoptr(FlEngine) engine = make_mock_engine();
123
124 std::vector<FlutterAccessibilityFeature> calls;
126 UpdateAccessibilityFeatures,
127 ([&calls](auto engine, FlutterAccessibilityFeature features) {
128 calls.push_back(features);
129 return kSuccess;
130 }));
131
132 g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
133
134 ::testing::NiceMock<flutter::testing::MockSettings> settings;
135
137 ::testing::Eq<FlSettings*>(settings)))
138 .WillOnce(::testing::Return(false))
139 .WillOnce(::testing::Return(true))
140 .WillOnce(::testing::Return(false))
141 .WillOnce(::testing::Return(true));
142
144 ::testing::Eq<FlSettings*>(settings)))
145 .WillOnce(::testing::Return(true))
146 .WillOnce(::testing::Return(false))
147 .WillOnce(::testing::Return(false))
148 .WillOnce(::testing::Return(true));
149
151 EXPECT_THAT(calls, ::testing::SizeIs(1));
152 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
155
157 EXPECT_THAT(calls, ::testing::SizeIs(2));
158 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(0));
159
161 EXPECT_THAT(calls, ::testing::SizeIs(3));
162 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
164
166 EXPECT_THAT(calls, ::testing::SizeIs(4));
167 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
169}
FlutterAccessibilityFeature
Definition: embedder.h:91
@ kFlutterAccessibilityFeatureHighContrast
Request that UI be rendered with darker colors.
Definition: embedder.h:105
@ kFlutterAccessibilityFeatureDisableAnimations
Request that animations be disabled or simplified.
Definition: embedder.h:98
@ kSuccess
Definition: embedder.h:73
FlutterEngine engine
Definition: main.cc:68
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:599
static FlEngine * make_mock_engine()
gboolean fl_settings_get_high_contrast(FlSettings *self)
Definition: fl_settings.cc:42
void fl_settings_emit_changed(FlSettings *self)
Definition: fl_settings.cc:50
gboolean fl_settings_get_enable_animations(FlSettings *self)
Definition: fl_settings.cc:38
FlSettingsPlugin * fl_settings_plugin_new(FlEngine *engine)
void fl_settings_plugin_start(FlSettingsPlugin *self, FlSettings *settings)
#define MOCK_ENGINE_PROC(proc, mock_impl)
Function-pointer-based versions of the APIs above.
Definition: embedder.h:3319
FlutterEngineUpdateAccessibilityFeaturesFnPtr UpdateAccessibilityFeatures
Definition: embedder.h:3344

◆ TEST() [2/4]

TEST ( FlSettingsPluginTest  ,
AlwaysUse24HourFormat   
)

Definition at line 40 of file fl_settings_plugin_test.cc.

40 {
41 ::testing::NiceMock<flutter::testing::MockSettings> settings;
42 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
43
44 g_autoptr(FlEngine) engine =
45 FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
46 FL_BINARY_MESSENGER(messenger), nullptr));
47 g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
48
49 g_autoptr(FlValue) use_12h = fl_value_new_bool(false);
50 g_autoptr(FlValue) use_24h = fl_value_new_bool(true);
51
53 ::testing::Eq<FlSettings*>(settings)))
54 .WillOnce(::testing::Return(FL_CLOCK_FORMAT_12H))
55 .WillOnce(::testing::Return(FL_CLOCK_FORMAT_24H));
56
57 EXPECT_SETTING(messenger, "alwaysUse24HourFormat", use_12h);
58
60
61 EXPECT_SETTING(messenger, "alwaysUse24HourFormat", use_24h);
62
64}
FlClockFormat fl_settings_get_clock_format(FlSettings *self)
Definition: fl_settings.cc:30
@ FL_CLOCK_FORMAT_12H
Definition: fl_settings.h:23
@ FL_CLOCK_FORMAT_24H
Definition: fl_settings.h:24
#define EXPECT_SETTING(messenger, key, value)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255

◆ TEST() [3/4]

TEST ( FlSettingsPluginTest  ,
PlatformBrightness   
)

Definition at line 66 of file fl_settings_plugin_test.cc.

66 {
67 ::testing::NiceMock<flutter::testing::MockSettings> settings;
68 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
69
70 g_autoptr(FlEngine) engine =
71 FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
72 FL_BINARY_MESSENGER(messenger), nullptr));
73 g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
74
75 g_autoptr(FlValue) light = fl_value_new_string("light");
76 g_autoptr(FlValue) dark = fl_value_new_string("dark");
77
79 ::testing::Eq<FlSettings*>(settings)))
80 .WillOnce(::testing::Return(FL_COLOR_SCHEME_LIGHT))
81 .WillOnce(::testing::Return(FL_COLOR_SCHEME_DARK));
82
83 EXPECT_SETTING(messenger, "platformBrightness", light);
84
86
87 EXPECT_SETTING(messenger, "platformBrightness", dark);
88
90}
FlColorScheme fl_settings_get_color_scheme(FlSettings *self)
Definition: fl_settings.cc:34
@ FL_COLOR_SCHEME_DARK
Definition: fl_settings.h:38
@ FL_COLOR_SCHEME_LIGHT
Definition: fl_settings.h:37
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276

◆ TEST() [4/4]

TEST ( FlSettingsPluginTest  ,
TextScaleFactor   
)

Definition at line 92 of file fl_settings_plugin_test.cc.

92 {
93 ::testing::NiceMock<flutter::testing::MockSettings> settings;
94 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
95
96 g_autoptr(FlEngine) engine =
97 FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
98 FL_BINARY_MESSENGER(messenger), nullptr));
99 g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
100
101 g_autoptr(FlValue) one = fl_value_new_float(1.0);
102 g_autoptr(FlValue) two = fl_value_new_float(2.0);
103
105 ::testing::Eq<FlSettings*>(settings)))
106 .WillOnce(::testing::Return(1.0))
107 .WillOnce(::testing::Return(2.0));
108
109 EXPECT_SETTING(messenger, "textScaleFactor", one);
110
112
113 EXPECT_SETTING(messenger, "textScaleFactor", two);
114
116}
gdouble fl_settings_get_text_scaling_factor(FlSettings *self)
Definition: fl_settings.cc:46
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:269