| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "webkit/tools/test_shell/image_decoder_unittest.h" | 7 #include "webkit/tools/test_shell/image_decoder_unittest.h" |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/md5.h" | 10 #include "base/md5.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 memcpy(&contents->first(), contents_str.data(), contents_str.size()); | 39 memcpy(&contents->first(), contents_str.data(), contents_str.size()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 std::wstring GetMD5SumPath(const std::wstring& path) { | 42 std::wstring GetMD5SumPath(const std::wstring& path) { |
| 43 static const std::wstring kDecodedDataExtension(L".md5sum"); | 43 static const std::wstring kDecodedDataExtension(L".md5sum"); |
| 44 return path + kDecodedDataExtension; | 44 return path + kDecodedDataExtension; |
| 45 } | 45 } |
| 46 | 46 |
| 47 #ifdef CALCULATE_MD5_SUMS | 47 #ifdef CALCULATE_MD5_SUMS |
| 48 void SaveMD5Sum(const std::wstring& path, WebCore::RGBA32Buffer* buffer) { | 48 void SaveMD5Sum(const std::wstring& path, WebCore::RGBA32Buffer* buffer) { |
| 49 // Create the file to write. | |
| 50 ScopedHandle handle(CreateFile(path.c_str(), GENERIC_WRITE, 0, | |
| 51 NULL, CREATE_ALWAYS, | |
| 52 FILE_ATTRIBUTE_NORMAL, NULL)); | |
| 53 ASSERT_TRUE(handle.IsValid()); | |
| 54 | |
| 55 // Calculate MD5 sum. | 49 // Calculate MD5 sum. |
| 56 MD5Digest digest; | 50 MD5Digest digest; |
| 57 SkAutoLockPixels bmp_lock(buffer->bitmap()); | 51 scoped_ptr<NativeImageSkia> image_data(buffer->asNewNativeImage()); |
| 58 MD5Sum(buffer->bitmap().getPixels(), | 52 { |
| 59 buffer->rect().width() * buffer->rect().height() * sizeof(unsigned), | 53 SkAutoLockPixels bmp_lock(*image_data); |
| 60 &digest); | 54 MD5Sum(image_data->getPixels(), |
| 55 image_data->width() * image_data->height() * sizeof(uint32_t), |
| 56 &digest); |
| 57 } |
| 61 | 58 |
| 62 // Write sum to disk. | 59 // Write sum to disk. |
| 63 int bytes_written = file_util::WriteFile(path, &digest, sizeof digest); | 60 int bytes_written = file_util::WriteFile(path, |
| 61 reinterpret_cast<const char*>(&digest), sizeof digest); |
| 64 ASSERT_EQ(sizeof digest, bytes_written); | 62 ASSERT_EQ(sizeof digest, bytes_written); |
| 65 } | 63 } |
| 66 #else | 64 #else |
| 67 void VerifyImage(WebCore::ImageDecoder* decoder, | 65 void VerifyImage(WebCore::ImageDecoder* decoder, |
| 68 const std::wstring& path, | 66 const std::wstring& path, |
| 69 const std::wstring& md5_sum_path) { | 67 const std::wstring& md5_sum_path) { |
| 70 // Make sure decoding can complete successfully. | 68 // Make sure decoding can complete successfully. |
| 71 EXPECT_TRUE(decoder->isSizeAvailable()) << path; | 69 EXPECT_TRUE(decoder->isSizeAvailable()) << path; |
| 72 WebCore::RGBA32Buffer* image_buffer = decoder->frameBufferAtIndex(0); | 70 WebCore::RGBA32Buffer* image_buffer = decoder->frameBufferAtIndex(0); |
| 73 ASSERT_NE(static_cast<WebCore::RGBA32Buffer*>(NULL), image_buffer) << path; | 71 ASSERT_NE(static_cast<WebCore::RGBA32Buffer*>(NULL), image_buffer) << path; |
| 74 EXPECT_EQ(WebCore::RGBA32Buffer::FrameComplete, image_buffer->status()) << | 72 EXPECT_EQ(WebCore::RGBA32Buffer::FrameComplete, image_buffer->status()) << |
| 75 path; | 73 path; |
| 76 EXPECT_FALSE(decoder->failed()) << path; | 74 EXPECT_FALSE(decoder->failed()) << path; |
| 77 | 75 |
| 78 // Calculate MD5 sum. | 76 // Calculate MD5 sum. |
| 79 MD5Digest actual_digest; | 77 MD5Digest actual_digest; |
| 80 SkAutoLockPixels bmp_lock(image_buffer->bitmap()); | 78 scoped_ptr<NativeImageSkia> image_data(image_buffer->asNewNativeImage()); |
| 81 MD5Sum(image_buffer->bitmap().getPixels(), image_buffer->rect().width() * | 79 { |
| 82 image_buffer->rect().height() * sizeof(unsigned), &actual_digest); | 80 SkAutoLockPixels bmp_lock(*image_data); |
| 81 MD5Sum(image_data->getPixels(), |
| 82 image_data->width() * image_data->height() * sizeof(uint32_t), |
| 83 &actual_digest); |
| 84 } |
| 83 | 85 |
| 84 // Read the MD5 sum off disk. | 86 // Read the MD5 sum off disk. |
| 85 std::string file_bytes; | 87 std::string file_bytes; |
| 86 file_util::ReadFileToString(md5_sum_path, &file_bytes); | 88 file_util::ReadFileToString(md5_sum_path, &file_bytes); |
| 87 MD5Digest expected_digest; | 89 MD5Digest expected_digest; |
| 88 ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path; | 90 ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path; |
| 89 memcpy(&expected_digest, file_bytes.data(), sizeof expected_digest); | 91 memcpy(&expected_digest, file_bytes.data(), sizeof expected_digest); |
| 90 | 92 |
| 91 // Verify that the sums are the same. | 93 // Verify that the sums are the same. |
| 92 EXPECT_EQ(0, memcmp(&expected_digest, &actual_digest, sizeof(MD5Digest))) << | 94 EXPECT_EQ(0, memcmp(&expected_digest, &actual_digest, sizeof(MD5Digest))) << |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 208 |
| 207 // Make sure passing the complete image results in successful decoding. | 209 // Make sure passing the complete image results in successful decoding. |
| 208 partial_contents->append( | 210 partial_contents->append( |
| 209 &image_contents.data()[partial_size], | 211 &image_contents.data()[partial_size], |
| 210 static_cast<int>(image_contents.size() - partial_size)); | 212 static_cast<int>(image_contents.size() - partial_size)); |
| 211 decoder->setData(partial_contents.get(), true); | 213 decoder->setData(partial_contents.get(), true); |
| 212 VerifyImage(decoder.get(), *i, GetMD5SumPath(*i)); | 214 VerifyImage(decoder.get(), *i, GetMD5SumPath(*i)); |
| 213 } | 215 } |
| 214 } | 216 } |
| 215 #endif | 217 #endif |
| OLD | NEW |