| Flutter Impeller |

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 GoldenDigest * | Instance ()

## Detailed Description

Manages a global variable for tracking instances of golden images.

Definition at line 18 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 }
value
int32_t value
Definition: dl_golden_unittests.cc:459

References value.

Referenced by impeller::GoldenPlaygroundTest::SetUp(), and impeller::testing::GoldenTests::SetUp().

## ◆ 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,
39 kMaxColorDelta});
40 }
kMaxDiffPixelsPercent
static const double kMaxDiffPixelsPercent
Definition: golden_digest.cc:10
kMaxColorDelta
static const int32_t kMaxColorDelta
Definition: golden_digest.cc:11

References kMaxColorDelta, and kMaxDiffPixelsPercent.

Referenced by impeller::GoldenPlaygroundTest::SaveScreenshot().

## ◆ 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 }

Referenced by main(), impeller::GoldenPlaygroundTest::SaveScreenshot(), impeller::GoldenPlaygroundTest::SetUp(), and impeller::testing::GoldenTests::SetUp().

## ◆ 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 }

References impeller::testing::WorkingDirectory::GetFilenamePath().

Referenced by main().

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

- impeller/golden_tests/golden_digest.h
- impeller/golden_tests/golden_digest.cc