Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::testing::GoldenDigestManager Class Reference

#include <golden_digest_manager.h>

Public Member Functions

 GoldenDigestManager (const std::string &working_directory)
 
 ~GoldenDigestManager ()
 
const std::string & GetWorkingDirectory () const
 
std::string GetFullPath (const std::string &filename) const
 
void AddDimension (const std::string &name, const std::string &value)
 
void AddImage (const std::string &test_name, const std::string &golden_filename, int32_t width, int32_t height)
 
bool Write ()
 
void ClearDigestData ()
 

Detailed Description

Manages a global variable for tracking a directory containing instances of golden images.

Definition at line 17 of file golden_digest_manager.h.

Constructor & Destructor Documentation

◆ GoldenDigestManager()

impeller::testing::GoldenDigestManager::GoldenDigestManager ( const std::string &  working_directory)
explicit

Constructs a GoldenDigest that will accumulate golden image filenames and Dimension key/value pairs for the specified working directory and write them to a file named "digest.json" in that directory when |Write| is called.

Definition at line 19 of file golden_digest_manager.cc.

21 : working_directory_(working_directory_path) {}

◆ ~GoldenDigestManager()

impeller::testing::GoldenDigestManager::~GoldenDigestManager ( )

Definition at line 23 of file golden_digest_manager.cc.

23 {
24 if (entries_written_ < entries_.size() ||
25 dimensions_written_ < dimensions_.size()) {
26 FML_LOG(WARNING) //
27 << "golden digest at " << working_directory_ //
28 << " incomplete, with only " //
29 << dimensions_written_ << " out of " //
30 << dimensions_.size() << " dimensions " //
31 << "and " //
32 << entries_written_ << " out of " //
33 << entries_.size() << " image entries" //
34 << " written";
35 }
36}
#define FML_LOG(severity)
Definition logging.h:101

References FML_LOG.

Member Function Documentation

◆ AddDimension()

void impeller::testing::GoldenDigestManager::AddDimension ( const std::string &  name,
const std::string &  value 
)

Definition at line 47 of file golden_digest_manager.cc.

48 {
49 std::stringstream ss;
50 ss << "\"" << value << "\"";
51 dimensions_[name] = ss.str();
52}
int32_t value
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27

References flutter::name, and value.

◆ AddImage()

void impeller::testing::GoldenDigestManager::AddImage ( const std::string &  test_name,
const std::string &  golden_filename,
int32_t  width,
int32_t  height 
)

Definition at line 54 of file golden_digest_manager.cc.

57 {
58 entries_.push_back({test_name, filename, width, height, kMaxDiffPixelsPercent,
60}
static const double kMaxDiffPixelsPercent
static const int32_t kMaxColorDelta
int32_t height
int32_t width

References height, kMaxColorDelta, kMaxDiffPixelsPercent, and width.

◆ ClearDigestData()

void impeller::testing::GoldenDigestManager::ClearDigestData ( )

Clears all accumulated dimension and golden image data if the digest should not be written.

(Failing to call either this method or the |Write| method causes a warning to be written to the console about unwritten data left in the digest manater.)

Definition at line 123 of file golden_digest_manager.cc.

123 {
124 dimensions_.clear();
125 entries_.clear();
126
127 dimensions_written_ = 0u;
128 entries_written_ = 0u;
129}

◆ GetFullPath()

std::string impeller::testing::GoldenDigestManager::GetFullPath ( const std::string &  filename) const

Definition at line 42 of file golden_digest_manager.cc.

43 {
44 return fml::paths::JoinPaths({working_directory_, filename});
45}
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14

References fml::paths::JoinPaths().

Referenced by Write().

◆ GetWorkingDirectory()

const std::string & impeller::testing::GoldenDigestManager::GetWorkingDirectory ( ) const

Definition at line 38 of file golden_digest_manager.cc.

38 {
39 return working_directory_;
40}

◆ Write()

bool impeller::testing::GoldenDigestManager::Write ( )

Writes a "digest.json" file to the working directory.

(Failing to call either this method or the |ClearDigestData| method causes a warning to be written to the console about unwritten data left in the digest manater.)

Returns true on success.

Definition at line 62 of file golden_digest_manager.cc.

62 {
63 std::ofstream fout;
64 fout.open(GetFullPath("digest.json"));
65 if (!fout.good()) {
66 return false;
67 }
68
69 // If we wrote some stuff before, this will be an update on top of that
70 // work, rewriting the file again from the beginning. This allows test
71 // suites to defensively write the digest after every group of tests.
72 dimensions_written_ = 0u;
73 entries_written_ = 0u;
74
75 fout << "{" << std::endl;
76 fout << " \"dimensions\": {" << std::endl;
77 bool is_first = true;
78 for (const auto& dimension : dimensions_) {
79 if (!is_first) {
80 fout << "," << std::endl;
81 }
82 is_first = false;
83 fout << " \"" << dimension.first << "\": " << dimension.second;
84 dimensions_written_++;
85 }
86 fout << std::endl << " }," << std::endl;
87 fout << " \"entries\":" << std::endl;
88
89 fout << " [" << std::endl;
90 is_first = true;
91 for (const auto& entry : entries_) {
92 if (!is_first) {
93 fout << "," << std::endl;
94 }
95 is_first = false;
96
97 fout << " { " << "\"testName\" : \"" << entry.test_name << "\", "
98 << "\"filename\" : \"" << entry.filename << "\", "
99 << "\"width\" : " << entry.width << ", "
100 << "\"height\" : " << entry.height << ", ";
101
102 if (entry.max_diff_pixels_percent ==
103 static_cast<int64_t>(entry.max_diff_pixels_percent)) {
104 fout << "\"maxDiffPixelsPercent\" : " << entry.max_diff_pixels_percent
105 << ".0, ";
106 } else {
107 fout << "\"maxDiffPixelsPercent\" : " << entry.max_diff_pixels_percent
108 << ", ";
109 }
110
111 fout << "\"maxColorDelta\":" << entry.max_color_delta << " ";
112 fout << "}";
113 entries_written_++;
114 }
115 fout << std::endl << " ]" << std::endl;
116
117 fout << "}" << std::endl;
118
119 fout.close();
120 return true;
121}
std::string GetFullPath(const std::string &filename) const

References GetFullPath().


The documentation for this class was generated from the following files: