OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "gm_expectations.h" | 8 #include "gm_expectations.h" |
9 #include "SkBitmapHasher.h" | 9 #include "SkBitmapHasher.h" |
10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace skiagm { | 25 namespace skiagm { |
26 | 26 |
27 void gm_fprintf(FILE *stream, const char format[], ...) { | 27 void gm_fprintf(FILE *stream, const char format[], ...) { |
28 va_list args; | 28 va_list args; |
29 va_start(args, format); | 29 va_start(args, format); |
30 fprintf(stream, "GM: "); | 30 fprintf(stream, "GM: "); |
31 vfprintf(stream, format, args); | 31 vfprintf(stream, format, args); |
32 va_end(args); | 32 va_end(args); |
33 } | 33 } |
34 | 34 |
| 35 SkString SkPathJoin(const char *rootPath, const char *relativePath) { |
| 36 SkString result(rootPath); |
| 37 if (!result.endsWith(SkPATH_SEPARATOR)) { |
| 38 result.appendUnichar(SkPATH_SEPARATOR); |
| 39 } |
| 40 result.append(relativePath); |
| 41 return result; |
| 42 } |
| 43 |
35 SkString make_filename(const char path[], | 44 SkString make_filename(const char path[], |
36 const char renderModeDescriptor[], | 45 const char renderModeDescriptor[], |
37 const char *name, | 46 const char *name, |
38 const char suffix[]) { | 47 const char suffix[]) { |
39 SkString filename(path); | 48 SkString filename(name); |
40 if (filename.endsWith(SkPATH_SEPARATOR)) { | 49 filename.append(renderModeDescriptor); |
41 filename.remove(filename.size() - 1, 1); | 50 filename.appendUnichar('.'); |
42 } | 51 filename.append(suffix); |
43 filename.appendf("%c%s%s.%s", SkPATH_SEPARATOR, | 52 return SkPathJoin(path, filename.c_str()); |
44 name, renderModeDescriptor, suffix); | |
45 return filename; | |
46 } | 53 } |
47 | 54 |
48 // TODO(epoger): This currently assumes that the result SkHashDigest was | 55 // TODO(epoger): This currently assumes that the result SkHashDigest was |
49 // generated as an SkHashDigest of an SkBitmap. We'll need to allow for oth
er | 56 // generated as an SkHashDigest of an SkBitmap. We'll need to allow for oth
er |
50 // hash types to cover non-bitmaps. | 57 // hash types to cover non-bitmaps. |
51 Json::Value ActualResultAsJsonValue(const SkHashDigest& result) { | 58 Json::Value ActualResultAsJsonValue(const SkHashDigest& result) { |
52 Json::Value jsonValue; | 59 Json::Value jsonValue; |
53 jsonValue[kJsonKey_ActualResults_AnyStatus_BitmapHash] = asJsonValue(res
ult); | 60 jsonValue[kJsonKey_ActualResults_AnyStatus_BitmapHash] = asJsonValue(res
ult); |
54 return jsonValue; | 61 return jsonValue; |
55 } | 62 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 Json::Value jsonValue; | 162 Json::Value jsonValue; |
156 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu
mArray; | 163 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu
mArray; |
157 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure(
); | 164 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure(
); |
158 return jsonValue; | 165 return jsonValue; |
159 } | 166 } |
160 | 167 |
161 | 168 |
162 // IndividualImageExpectationsSource class... | 169 // IndividualImageExpectationsSource class... |
163 | 170 |
164 Expectations IndividualImageExpectationsSource::get(const char *testName) { | 171 Expectations IndividualImageExpectationsSource::get(const char *testName) { |
165 SkString path = make_filename(fRootDir.c_str(), "", testName, | 172 SkString path = SkPathJoin(fRootDir.c_str(), testName); |
166 "png"); | |
167 SkBitmap referenceBitmap; | 173 SkBitmap referenceBitmap; |
168 bool decodedReferenceBitmap = | 174 bool decodedReferenceBitmap = |
169 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, | 175 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, |
170 SkBitmap::kARGB_8888_Config, | 176 SkBitmap::kARGB_8888_Config, |
171 SkImageDecoder::kDecodePixels_Mode, | 177 SkImageDecoder::kDecodePixels_Mode, |
172 NULL); | 178 NULL); |
173 if (decodedReferenceBitmap) { | 179 if (decodedReferenceBitmap) { |
174 return Expectations(referenceBitmap); | 180 return Expectations(referenceBitmap); |
175 } else { | 181 } else { |
176 return Expectations(); | 182 return Expectations(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 Json::Reader reader; | 233 Json::Reader reader; |
228 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { | 234 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { |
229 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); | 235 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); |
230 DEBUGFAIL_SEE_STDERR; | 236 DEBUGFAIL_SEE_STDERR; |
231 return false; | 237 return false; |
232 } | 238 } |
233 return true; | 239 return true; |
234 } | 240 } |
235 | 241 |
236 } | 242 } |
OLD | NEW |