9#include "flutter/fml/build_config.h"
10#include "flutter/fml/file.h"
11#include "flutter/fml/mapping.h"
12#include "flutter/fml/paths.h"
13#include "flutter/fml/unique_fd.h"
14#include "gtest/gtest.h"
17 const std::string& contents) {
23 if (mapping.GetSize() != contents.size()) {
27 if (mapping.GetMutableMapping() ==
nullptr) {
31 ::memmove(mapping.GetMutableMapping(), contents.data(), contents.size());
42 return {
reinterpret_cast<const char*
>(mapping.
GetMapping()),
46TEST(FileTest, CreateTemporaryAndUnlink) {
48 ASSERT_NE(dir_name,
"");
51 ASSERT_TRUE(
dir.is_valid());
56TEST(FileTest, ScopedTempDirIsValid) {
58 ASSERT_TRUE(
dir.fd().is_valid());
61TEST(FileTest, CanOpenFileForWriting) {
63 ASSERT_TRUE(
dir.fd().is_valid());
67 ASSERT_TRUE(fd.is_valid());
72TEST(FileTest, CanTruncateAndWrite) {
74 ASSERT_TRUE(
dir.fd().is_valid());
76 std::string contents =
"some contents here";
81 for (
int i = 0;
i < 2;
i++) {
85 ASSERT_TRUE(fd.is_valid());
90 ASSERT_EQ(mapping.GetSize(), contents.size());
91 ASSERT_NE(mapping.GetMutableMapping(),
nullptr);
93 ::memcpy(mapping.GetMutableMapping(), contents.data(), contents.size());
99 ASSERT_TRUE(fd.is_valid());
102 ASSERT_EQ(mapping.
GetSize(), contents.size());
105 0, ::memcmp(mapping.
GetMapping(), contents.data(), contents.size()));
112TEST(FileTest, CreateDirectoryStructure) {
115 std::string contents =
"These are my contents";
119 ASSERT_TRUE(sub.is_valid());
122 ASSERT_TRUE(
file.is_valid());
126 const char* file_path =
"a/b/c/my_contents";
141TEST(FileTest, VisitFilesCanBeCalledTwice) {
147 ASSERT_TRUE(
file.is_valid());
152 const std::string& filename) {
168TEST(FileTest, CanListFilesRecursively) {
174 ASSERT_TRUE(c.is_valid());
180 ASSERT_TRUE(
d.is_valid());
183 ASSERT_TRUE(file1.is_valid());
184 ASSERT_TRUE(file2.is_valid());
185 ASSERT_TRUE(file3.is_valid());
188 std::set<std::string>
names;
190 const std::string& filename) {
191 names.insert(filename);
196 ASSERT_EQ(
names, std::set<std::string>(
197 {
"a",
"b",
"c",
"d",
"file1",
"file2",
"file3"}));
209TEST(FileTest, CanStopVisitEarly) {
215 ASSERT_TRUE(
d.is_valid());
218 std::set<std::string>
names;
220 const std::string& filename) {
221 names.insert(filename);
222 return filename ==
"c" ?
false :
true;
227 ASSERT_EQ(
names, std::set<std::string>({
"a",
"b",
"c"}));
236TEST(FileTest, AtomicWriteTest) {
239 const std::string contents =
"These are my contents.";
241 auto data = std::make_unique<fml::DataMapping>(
242 std::vector<uint8_t>{contents.begin(), contents.end()});
256TEST(FileTest, IgnoreBaseDirWhenPathIsAbsolute) {
260 std::string filename =
"filename.txt";
261 std::string full_path =
264 const std::string contents =
"These are my contents.";
265 auto data = std::make_unique<fml::DataMapping>(
266 std::vector<uint8_t>{contents.begin(), contents.end()});
283TEST(FileTest, EmptyMappingTest) {
291 ASSERT_TRUE(mapping.
IsValid());
292 ASSERT_EQ(mapping.
GetSize(), 0ul);
299TEST(FileTest, MappingDontNeedSafeTest) {
312 ASSERT_TRUE(mapping.
IsValid());
322 ASSERT_TRUE(mapping.IsValid());
323 ASSERT_NE(mapping.GetMutableMapping(),
nullptr);
324 ASSERT_FALSE(mapping.IsDontNeedSafe());
331 ASSERT_TRUE(
dir.fd().is_valid());
332 const char* filename =
"some.txt";
335 ASSERT_TRUE(fd.is_valid());
343TEST(FileTest, FileTestsSupportsUnicode) {
345 ASSERT_TRUE(
dir.fd().is_valid());
346 const char* filename = u8
"äëïöüテスト☃";
349 ASSERT_TRUE(fd.is_valid());
const SkPath & path() const
size_t GetSize() const override
bool IsDontNeedSafe() const override
uint8_t * GetMutableMapping()
const uint8_t * GetMapping() const override
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
static bool WriteStringToFile(const fml::UniqueFD &fd, const std::string &contents)
static std::string ReadStringFromFile(const fml::UniqueFD &fd)
TEST(FileTest, CreateTemporaryAndUnlink)
static const char *const names[]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
std::string JoinPaths(std::initializer_list< std::string > components)
std::string AbsolutePath(const std::string &path)
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
bool IsFile(const std::string &path)
std::string CreateTemporaryDirectory()
bool UnlinkDirectory(const char *path)
bool TruncateFile(const fml::UniqueFD &file, size_t size)
static fml::UniqueFD CreateDirectory(const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
bool FileExists(const fml::UniqueFD &base_directory, const char *path)
bool UnlinkFile(const char *path)
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
bool VisitFilesRecursively(const fml::UniqueFD &directory, const FileVisitor &visitor)
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
std::shared_ptr< const fml::Mapping > data