Flutter Engine
fl_dart_project_test.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
#include <gmodule.h>
#include <cstdlib>
#include "flutter/shell/platform/linux/fl_dart_project_private.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (FlDartProjectTest, GetPaths)
 
 TEST (FlDartProjectTest, EnableMirrors)
 
 TEST (FlDartProjectTest, DartEntrypointArgs)
 
 TEST (FlDartProjectTest, SwitchesEmpty)
 
 TEST (FlDartProjectTest, Switches)
 

Function Documentation

◆ TEST() [1/5]

TEST ( FlDartProjectTest  ,
GetPaths   
)

Definition at line 14 of file fl_dart_project_test.cc.

References fl_dart_project_get_aot_library_path(), fl_dart_project_get_assets_path(), fl_dart_project_get_icu_data_path(), and fl_dart_project_new().

14  {
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 }
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)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)

◆ TEST() [2/5]

TEST ( FlDartProjectTest  ,
EnableMirrors   
)

Definition at line 32 of file fl_dart_project_test.cc.

References fl_dart_project_get_enable_mirrors(), fl_dart_project_new(), fl_dart_project_set_enable_mirrors(), and TRUE.

32  {
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 }
G_MODULE_EXPORT gboolean fl_dart_project_get_enable_mirrors(FlDartProject *self)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
G_MODULE_EXPORT void fl_dart_project_set_enable_mirrors(FlDartProject *self, gboolean enable_mirrors)

◆ TEST() [3/5]

TEST ( FlDartProjectTest  ,
DartEntrypointArgs   
)

Definition at line 41 of file fl_dart_project_test.cc.

References args, fl_dart_project_get_dart_entrypoint_arguments(), fl_dart_project_new(), and fl_dart_project_set_dart_entrypoint_arguments().

41  {
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 }
G_BEGIN_DECLS FlValue * args
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 FlDartProject * fl_dart_project_new()

◆ TEST() [4/5]

TEST ( FlDartProjectTest  ,
SwitchesEmpty   
)

Definition at line 66 of file fl_dart_project_test.cc.

References fl_dart_project_get_switches(), and fl_dart_project_new().

66  {
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 }
GPtrArray * fl_dart_project_get_switches(FlDartProject *self)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()

◆ TEST() [5/5]

TEST ( FlDartProjectTest  ,
Switches   
)

Definition at line 78 of file fl_dart_project_test.cc.

References fl_dart_project_get_switches(), and fl_dart_project_new().

78  {
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 }
GPtrArray * fl_dart_project_get_switches(FlDartProject *self)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()