55#include " impeller/golden_tests/golden_digest.h"
66
77#include < fstream>
8+ #include < sstream>
89
910static const double kMaxDiffPixelsPercent = 0.01 ;
1011static const int32_t kMaxColorDelta = 8 ;
@@ -23,6 +24,13 @@ GoldenDigest* GoldenDigest::Instance() {
2324
2425GoldenDigest::GoldenDigest () {}
2526
27+ void GoldenDigest::AddDimension (const std::string& name,
28+ const std::string& value) {
29+ std::stringstream ss;
30+ ss << " \" " << value << " \" " ;
31+ dimensions_[name] = ss.str ();
32+ }
33+
2634void GoldenDigest::AddImage (const std::string& test_name,
2735 const std::string& filename,
2836 int32_t width,
@@ -38,15 +46,28 @@ bool GoldenDigest::Write(WorkingDirectory* working_directory) {
3846 return false ;
3947 }
4048
41- fout << " [" << std::endl;
49+ fout << " {" << std::endl;
50+ fout << " \" dimensions\" : {" << std::endl;
4251 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 ;
4364 for (const auto & entry : entries_) {
4465 if (!is_first) {
4566 fout << " ," << std::endl;
4667 }
4768 is_first = false ;
4869
49- fout << " { "
70+ fout << " { "
5071 << " \" testName\" : \" " << entry.test_name << " \" , "
5172 << " \" filename\" : \" " << entry.filename << " \" , "
5273 << " \" width\" : " << entry.width << " , "
@@ -64,7 +85,9 @@ bool GoldenDigest::Write(WorkingDirectory* working_directory) {
6485 fout << " \" maxColorDelta\" :" << entry.max_color_delta << " " ;
6586 fout << " }" ;
6687 }
67- fout << std::endl << " ]" << std::endl;
88+ fout << std::endl << " ]" << std::endl;
89+
90+ fout << " }" << std::endl;
6891
6992 fout.close ();
7093 return true ;
0 commit comments