Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
impeller::testing::GoldenDigest Class Reference

Manages a global variable for tracking instances of golden images. More...

#include <golden_digest.h>

Public Member Functions

void AddDimension (const std::string &name, const std::string &value)
 
void AddImage (const std::string &test_name, const std::string &filename, int32_t width, int32_t height)
 
bool Write (WorkingDirectory *working_directory)
 

Static Public Member Functions

static GoldenDigestInstance ()
 

Detailed Description

Manages a global variable for tracking instances of golden images.

Definition at line 19 of file golden_digest.h.

Member Function Documentation

◆ AddDimension()

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

Definition at line 27 of file golden_digest.cc.

28 {
29 std::stringstream ss;
30 ss << "\"" << value << "\"";
31 dimensions_[name] = ss.str();
32}
uint8_t value
const char * name
Definition fuchsia.cc:50

◆ AddImage()

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

Definition at line 34 of file golden_digest.cc.

37 {
38 entries_.push_back({test_name, filename, width, height, kMaxDiffPixelsPercent,
40}
static const double kMaxDiffPixelsPercent
static const int32_t kMaxColorDelta
int32_t height
int32_t width

◆ Instance()

GoldenDigest * impeller::testing::GoldenDigest::Instance ( )
static

Definition at line 18 of file golden_digest.cc.

18 {
19 if (!instance_) {
20 instance_ = new GoldenDigest();
21 }
22 return instance_;
23}

◆ Write()

bool impeller::testing::GoldenDigest::Write ( WorkingDirectory working_directory)

Writes a "digest.json" file to working_directory.

Returns true on success.

Definition at line 42 of file golden_digest.cc.

42 {
43 std::ofstream fout;
44 fout.open(working_directory->GetFilenamePath("digest.json"));
45 if (!fout.good()) {
46 return false;
47 }
48
49 fout << "{" << std::endl;
50 fout << " \"dimensions\": {" << std::endl;
51 bool is_first = true;
52 for (const auto& dimension : dimensions_) {
53 if (!is_first) {
54 fout << "," << std::endl;
55 }
56 is_first = false;
57 fout << " \"" << dimension.first << "\": " << dimension.second;
58 }
59 fout << std::endl << " }," << std::endl;
60 fout << " \"entries\":" << std::endl;
61
62 fout << " [" << std::endl;
63 is_first = true;
64 for (const auto& entry : entries_) {
65 if (!is_first) {
66 fout << "," << std::endl;
67 }
68 is_first = false;
69
70 fout << " { " << "\"testName\" : \"" << entry.test_name << "\", "
71 << "\"filename\" : \"" << entry.filename << "\", "
72 << "\"width\" : " << entry.width << ", "
73 << "\"height\" : " << entry.height << ", ";
74
75 if (entry.max_diff_pixels_percent ==
76 static_cast<int64_t>(entry.max_diff_pixels_percent)) {
77 fout << "\"maxDiffPixelsPercent\" : " << entry.max_diff_pixels_percent
78 << ".0, ";
79 } else {
80 fout << "\"maxDiffPixelsPercent\" : " << entry.max_diff_pixels_percent
81 << ", ";
82 }
83
84 fout << "\"maxColorDelta\":" << entry.max_color_delta << " ";
85 fout << "}";
86 }
87 fout << std::endl << " ]" << std::endl;
88
89 fout << "}" << std::endl;
90
91 fout.close();
92 return true;
93}

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