| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef image_expectations_DEFINED | 8 #ifndef image_expectations_DEFINED |
| 9 #define image_expectations_DEFINED | 9 #define image_expectations_DEFINED |
| 10 | 10 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkJSONCPP.h" | 12 #include "SkJSONCPP.h" |
| 13 #include "SkOSFile.h" |
| 13 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 14 | 15 |
| 15 namespace sk_tools { | 16 namespace sk_tools { |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * The digest of an image (either an image we have generated locally, or an
image expectation). | 19 * The digest of an image (either an image we have generated locally, or an
image expectation). |
| 19 * | 20 * |
| 20 * Currently, this is always a uint64_t hash digest of an SkBitmap. | 21 * Currently, this is always a uint64_t hash digest of an SkBitmap. |
| 21 */ | 22 */ |
| 22 class ImageDigest : public SkRefCnt { | 23 class ImageDigest : public SkRefCnt { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 SkAutoTUnref<ImageDigest> fImageDigestRef; | 75 SkAutoTUnref<ImageDigest> fImageDigestRef; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 /** | 78 /** |
| 78 * Collects ImageDigests of actually rendered images, perhaps comparing to e
xpectations. | 79 * Collects ImageDigests of actually rendered images, perhaps comparing to e
xpectations. |
| 79 */ | 80 */ |
| 80 class ImageResultsAndExpectations { | 81 class ImageResultsAndExpectations { |
| 81 public: | 82 public: |
| 82 /** | 83 /** |
| 83 * Adds expectations from a JSON file, returning true if successful. | 84 * Adds expectations from a JSON file, returning true if successful. |
| 85 * |
| 86 * If the file exists but is empty, it succeeds, and there will be no ex
pectations. |
| 87 * If the file does not exist, this will fail. |
| 88 * |
| 89 * Reasoning: |
| 90 * Generating expectations the first time can be a tricky chicken-and-eg
g |
| 91 * proposition. "I need actual results to turn into expectations... but
the only |
| 92 * way to get actual results is to run the tool, and the tool won't run
without |
| 93 * expectations!" |
| 94 * We could make the tool run even if there is no expectations file at a
ll, but it's |
| 95 * better for the tool to fail if the expectations file is not found--th
at will tell us |
| 96 * quickly if files are not being copied around as they should be. |
| 97 * Creating an empty file is an easy way to break the chicken-and-egg cy
cle and generate |
| 98 * the first real expectations. |
| 84 */ | 99 */ |
| 85 bool readExpectationsFile(const char *jsonPath); | 100 bool readExpectationsFile(const char *jsonPath); |
| 86 | 101 |
| 87 /** | 102 /** |
| 88 * Adds this image to the summary of results. | 103 * Adds this image to the summary of results. |
| 89 * | 104 * |
| 90 * @param sourceName name of the source file that generated this result | 105 * @param sourceName name of the source file that generated this result |
| 91 * @param fileName relative path to the image output file on local disk | 106 * @param fileName relative path to the image output file on local disk |
| 92 * @param digest description of the image's contents | 107 * @param digest description of the image's contents |
| 93 * @param tileNumber if not NULL, pointer to tile number | 108 * @param tileNumber if not NULL, pointer to tile number |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 /** | 124 /** |
| 110 * Writes the summary (as constructed so far) to a file. | 125 * Writes the summary (as constructed so far) to a file. |
| 111 * | 126 * |
| 112 * @param filename path to write the summary to | 127 * @param filename path to write the summary to |
| 113 */ | 128 */ |
| 114 void writeToFile(const char *filename) const; | 129 void writeToFile(const char *filename) const; |
| 115 | 130 |
| 116 private: | 131 private: |
| 117 | 132 |
| 118 /** | 133 /** |
| 119 * Read the file contents from jsonPath and parse them into jsonRoot. | 134 * Read the file contents from filePtr and parse them into jsonRoot. |
| 135 * |
| 136 * It is up to the caller to close filePtr after this is done. |
| 120 * | 137 * |
| 121 * Returns true if successful. | 138 * Returns true if successful. |
| 122 */ | 139 */ |
| 123 static bool Parse(const char *jsonPath, Json::Value *jsonRoot); | 140 static bool Parse(SkFILE* filePtr, Json::Value *jsonRoot); |
| 124 | 141 |
| 125 Json::Value fActualResults; | 142 Json::Value fActualResults; |
| 126 Json::Value fExpectedJsonRoot; | 143 Json::Value fExpectedJsonRoot; |
| 127 Json::Value fExpectedResults; | 144 Json::Value fExpectedResults; |
| 128 }; | 145 }; |
| 129 | 146 |
| 130 } // namespace sk_tools | 147 } // namespace sk_tools |
| 131 | 148 |
| 132 #endif // image_expectations_DEFINED | 149 #endif // image_expectations_DEFINED |
| OLD | NEW |