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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 Json::Value jsonValue; | 155 Json::Value jsonValue; |
156 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu
mArray; | 156 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu
mArray; |
157 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure(
); | 157 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure(
); |
158 return jsonValue; | 158 return jsonValue; |
159 } | 159 } |
160 | 160 |
161 | 161 |
162 // IndividualImageExpectationsSource class... | 162 // IndividualImageExpectationsSource class... |
163 | 163 |
164 Expectations IndividualImageExpectationsSource::get(const char *testName) { | 164 Expectations IndividualImageExpectationsSource::get(const char *testName) { |
165 SkString path = make_filename(fRootDir.c_str(), "", testName, | 165 SkString path = make_filename(fRootDir.c_str(), "", testName, kPNG_FileE
xtension); |
166 "png"); | |
167 SkBitmap referenceBitmap; | 166 SkBitmap referenceBitmap; |
168 bool decodedReferenceBitmap = | 167 bool decodedReferenceBitmap = |
169 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, | 168 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, |
170 SkBitmap::kARGB_8888_Config, | 169 SkBitmap::kARGB_8888_Config, |
171 SkImageDecoder::kDecodePixels_Mode, | 170 SkImageDecoder::kDecodePixels_Mode, |
172 NULL); | 171 NULL); |
173 if (decodedReferenceBitmap) { | 172 if (decodedReferenceBitmap) { |
174 return Expectations(referenceBitmap); | 173 return Expectations(referenceBitmap); |
175 } else { | 174 } else { |
176 return Expectations(); | 175 return Expectations(); |
177 } | 176 } |
178 } | 177 } |
179 | 178 |
180 | 179 |
181 // JsonExpectationsSource class... | 180 // JsonExpectationsSource class... |
182 | 181 |
183 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) { | 182 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) { |
184 Parse(jsonPath, &fJsonRoot); | 183 Parse(jsonPath, &fJsonRoot); |
185 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults]; | 184 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults]; |
186 } | 185 } |
187 | 186 |
188 Expectations JsonExpectationsSource::get(const char *testName) { | 187 Expectations JsonExpectationsSource::get(const char *testName) { |
189 return Expectations(fJsonExpectedResults[testName]); | 188 SkString testNameWithExtension(testName); |
| 189 testNameWithExtension.append("."); |
| 190 testNameWithExtension.append(kPNG_FileExtension); |
| 191 return Expectations(fJsonExpectedResults[testNameWithExtension.c_str()])
; |
190 } | 192 } |
191 | 193 |
192 /*static*/ SkData* JsonExpectationsSource::ReadIntoSkData(SkStream &stream,
size_t maxBytes) { | 194 /*static*/ SkData* JsonExpectationsSource::ReadIntoSkData(SkStream &stream,
size_t maxBytes) { |
193 if (0 == maxBytes) { | 195 if (0 == maxBytes) { |
194 return SkData::NewEmpty(); | 196 return SkData::NewEmpty(); |
195 } | 197 } |
196 char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes)); | 198 char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes)); |
197 char* bufPtr = bufStart; | 199 char* bufPtr = bufStart; |
198 size_t bytesRemaining = maxBytes; | 200 size_t bytesRemaining = maxBytes; |
199 while (bytesRemaining > 0) { | 201 while (bytesRemaining > 0) { |
(...skipping 27 matching lines...) Expand all Loading... |
227 Json::Reader reader; | 229 Json::Reader reader; |
228 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { | 230 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { |
229 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); | 231 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); |
230 DEBUGFAIL_SEE_STDERR; | 232 DEBUGFAIL_SEE_STDERR; |
231 return false; | 233 return false; |
232 } | 234 } |
233 return true; | 235 return true; |
234 } | 236 } |
235 | 237 |
236 } | 238 } |
OLD | NEW |