2018-11-07 12:24:35 -08:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
2017-10-25 14:54:20 -07:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
#include "testing.h"
|
|
|
|
|
|
2019-07-09 14:59:34 -07:00
|
|
|
#include "flutter/fml/file.h"
|
|
|
|
|
|
2019-04-20 20:42:46 -07:00
|
|
|
namespace flutter {
|
2017-10-25 14:54:20 -07:00
|
|
|
namespace testing {
|
|
|
|
|
|
2019-04-03 13:38:12 -07:00
|
|
|
std::string GetCurrentTestName() {
|
2019-04-20 20:42:46 -07:00
|
|
|
return ::testing::UnitTest::GetInstance()->current_test_info()->name();
|
2019-04-03 13:38:12 -07:00
|
|
|
}
|
2017-10-25 14:54:20 -07:00
|
|
|
|
2019-08-13 14:53:19 -07:00
|
|
|
fml::UniqueFD OpenFixturesDirectory() {
|
2019-07-09 14:59:34 -07:00
|
|
|
auto fixtures_directory =
|
|
|
|
|
OpenDirectory(GetFixturesPath(), // path
|
|
|
|
|
false, // create
|
|
|
|
|
fml::FilePermission::kRead // permission
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!fixtures_directory.is_valid()) {
|
|
|
|
|
FML_LOG(ERROR) << "Could not open fixtures directory.";
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2019-08-13 14:53:19 -07:00
|
|
|
return fixtures_directory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fml::UniqueFD OpenFixture(std::string fixture_name) {
|
|
|
|
|
if (fixture_name.size() == 0) {
|
|
|
|
|
FML_LOG(ERROR) << "Invalid fixture name.";
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto fixtures_directory = OpenFixturesDirectory();
|
2019-07-09 14:59:34 -07:00
|
|
|
|
|
|
|
|
auto fixture_fd = fml::OpenFile(fixtures_directory, // base directory
|
|
|
|
|
fixture_name.c_str(), // path
|
|
|
|
|
false, // create
|
|
|
|
|
fml::FilePermission::kRead // permission
|
|
|
|
|
);
|
|
|
|
|
if (!fixture_fd.is_valid()) {
|
2019-08-26 11:40:49 -07:00
|
|
|
FML_LOG(ERROR) << "Could not open fixture for path: " << GetFixturesPath()
|
|
|
|
|
<< "/" << fixture_name << ".";
|
2019-07-09 14:59:34 -07:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fixture_fd;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-26 13:33:56 -08:00
|
|
|
std::unique_ptr<fml::Mapping> OpenFixtureAsMapping(std::string fixture_name) {
|
|
|
|
|
return fml::FileMapping::CreateReadOnly(OpenFixture(fixture_name));
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 14:54:20 -07:00
|
|
|
} // namespace testing
|
2019-04-20 20:42:46 -07:00
|
|
|
} // namespace flutter
|