Flutter Engine
fl_dart_project_test.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 "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
6 
7 #include <gmodule.h>
8 
9 #include <cstdlib>
10 
11 #include "flutter/shell/platform/linux/fl_dart_project_private.h"
12 #include "gtest/gtest.h"
13 
14 TEST(FlDartProjectTest, GetPaths) {
15  g_autoptr(FlDartProject) project = fl_dart_project_new();
16  g_autofree gchar* exe_path = g_file_read_link("/proc/self/exe", nullptr);
17  ASSERT_TRUE(exe_path != nullptr);
18  g_autofree gchar* dir = g_path_get_dirname(exe_path);
19  g_autofree gchar* expected_aot_library_path =
20  g_build_filename(dir, "lib", "libapp.so", nullptr);
21  EXPECT_STREQ(fl_dart_project_get_aot_library_path(project),
22  expected_aot_library_path);
23  g_autofree gchar* expected_assets_path =
24  g_build_filename(dir, "data", "flutter_assets", nullptr);
25  EXPECT_STREQ(fl_dart_project_get_assets_path(project), expected_assets_path);
26  g_autofree gchar* expected_icu_data_path =
27  g_build_filename(dir, "data", "icudtl.dat", nullptr);
28  EXPECT_STREQ(fl_dart_project_get_icu_data_path(project),
29  expected_icu_data_path);
30 }
31 
32 TEST(FlDartProjectTest, EnableMirrors) {
33  g_autoptr(FlDartProject) project = fl_dart_project_new();
34  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
35  EXPECT_FALSE(fl_dart_project_get_enable_mirrors(project));
37  EXPECT_TRUE(fl_dart_project_get_enable_mirrors(project));
38  G_GNUC_END_IGNORE_DEPRECATIONS
39 }
40 
41 TEST(FlDartProjectTest, SwitchesEmpty) {
42  g_autoptr(FlDartProject) project = fl_dart_project_new();
43 
44  // Clear the main environment variable, since test order is not guaranteed.
45  unsetenv("FLUTTER_ENGINE_SWITCHES");
46 
47  g_autoptr(GPtrArray) switches = fl_dart_project_get_switches(project);
48 
49  EXPECT_EQ(switches->len, 0U);
50 }
51 
52 #ifndef FLUTTER_RELEASE
53 TEST(FlDartProjectTest, Switches) {
54  g_autoptr(FlDartProject) project = fl_dart_project_new();
55 
56  setenv("FLUTTER_ENGINE_SWITCHES", "2", 1);
57  setenv("FLUTTER_ENGINE_SWITCH_1", "abc", 1);
58  setenv("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"", 1);
59 
60  g_autoptr(GPtrArray) switches = fl_dart_project_get_switches(project);
61  EXPECT_EQ(switches->len, 2U);
62  EXPECT_STREQ(static_cast<const char*>(g_ptr_array_index(switches, 0)),
63  "--abc");
64  EXPECT_STREQ(static_cast<const char*>(g_ptr_array_index(switches, 1)),
65  "--foo=\"bar, baz\"");
66 }
67 #endif // !FLUTTER_RELEASE
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
G_MODULE_EXPORT const gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
GPtrArray * fl_dart_project_get_switches(FlDartProject *self)
G_MODULE_EXPORT gboolean fl_dart_project_get_enable_mirrors(FlDartProject *self)
TEST(FlDartProjectTest, GetPaths)
return TRUE
Definition: fl_view.cc:107
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
G_MODULE_EXPORT void fl_dart_project_set_enable_mirrors(FlDartProject *self, gboolean enable_mirrors)
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)