• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "testing.h"
6 
7 #include "flutter/fml/file.h"
8 
9 namespace flutter {
10 namespace testing {
11 
GetCurrentTestName()12 std::string GetCurrentTestName() {
13   return ::testing::UnitTest::GetInstance()->current_test_info()->name();
14 }
15 
OpenFixturesDirectory()16 fml::UniqueFD OpenFixturesDirectory() {
17   auto fixtures_directory =
18       OpenDirectory(GetFixturesPath(),          // path
19                     false,                      // create
20                     fml::FilePermission::kRead  // permission
21       );
22 
23   if (!fixtures_directory.is_valid()) {
24     FML_LOG(ERROR) << "Could not open fixtures directory.";
25     return {};
26   }
27   return fixtures_directory;
28 }
29 
OpenFixture(std::string fixture_name)30 fml::UniqueFD OpenFixture(std::string fixture_name) {
31   if (fixture_name.size() == 0) {
32     FML_LOG(ERROR) << "Invalid fixture name.";
33     return {};
34   }
35 
36   auto fixtures_directory = OpenFixturesDirectory();
37 
38   auto fixture_fd = fml::OpenFile(fixtures_directory,         // base directory
39                                   fixture_name.c_str(),       // path
40                                   false,                      // create
41                                   fml::FilePermission::kRead  // permission
42   );
43   if (!fixture_fd.is_valid()) {
44     FML_LOG(ERROR) << "Could not open fixture for path: " << fixture_name
45                    << ".";
46     return {};
47   }
48 
49   return fixture_fd;
50 }
51 
52 }  // namespace testing
53 }  // namespace flutter
54