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, DartEntrypointArgs) {
42  g_autoptr(FlDartProject) project = fl_dart_project_new();
43 
44  char** retrieved_args =
46 
47  EXPECT_EQ(g_strv_length(retrieved_args), 0U);
48 
49  GPtrArray* args_array = g_ptr_array_new();
50  g_ptr_array_add(args_array, (gpointer) "arg_one");
51  g_ptr_array_add(args_array, (gpointer) "arg_two");
52  g_ptr_array_add(args_array, (gpointer) "arg_three");
53  g_ptr_array_add(args_array, nullptr);
54  gchar** args = (gchar**)g_ptr_array_free(args_array, false);
55 
57 
58  retrieved_args = fl_dart_project_get_dart_entrypoint_arguments(project);
59 
60  // FlDartProject should have done a deep copy of the args
61  EXPECT_NE(retrieved_args, args);
62 
63  EXPECT_EQ(g_strv_length(retrieved_args), 3U);
64 }
65 
66 TEST(FlDartProjectTest, SwitchesEmpty) {
67  g_autoptr(FlDartProject) project = fl_dart_project_new();
68 
69  // Clear the main environment variable, since test order is not guaranteed.
70  unsetenv("FLUTTER_ENGINE_SWITCHES");
71 
72  g_autoptr(GPtrArray) switches = fl_dart_project_get_switches(project);
73 
74  EXPECT_EQ(switches->len, 0U);
75 }
76 
77 #ifndef FLUTTER_RELEASE
78 TEST(FlDartProjectTest, Switches) {
79  g_autoptr(FlDartProject) project = fl_dart_project_new();
80 
81  setenv("FLUTTER_ENGINE_SWITCHES", "2", 1);
82  setenv("FLUTTER_ENGINE_SWITCH_1", "abc", 1);
83  setenv("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"", 1);
84 
85  g_autoptr(GPtrArray) switches = fl_dart_project_get_switches(project);
86  EXPECT_EQ(switches->len, 2U);
87  EXPECT_STREQ(static_cast<const char*>(g_ptr_array_index(switches, 0)),
88  "--abc");
89  EXPECT_STREQ(static_cast<const char*>(g_ptr_array_index(switches, 1)),
90  "--foo=\"bar, baz\"");
91 
92  unsetenv("FLUTTER_ENGINE_SWITCHES");
93  unsetenv("FLUTTER_ENGINE_SWITCH_1");
94  unsetenv("FLUTTER_ENGINE_SWITCH_2");
95 }
96 #endif // !FLUTTER_RELEASE
G_BEGIN_DECLS FlValue * args
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(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)
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)