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 #ifndef WEBKIT_TOOLS_TEST_SHELL_IMAGE_DECODER_UNITTEST_H_ | 5 #ifndef WEBKIT_TOOLS_TEST_SHELL_IMAGE_DECODER_UNITTEST_H_ |
6 #define WEBKIT_TOOLS_TEST_SHELL_IMAGE_DECODER_UNITTEST_H_ | 6 #define WEBKIT_TOOLS_TEST_SHELL_IMAGE_DECODER_UNITTEST_H_ |
7 | 7 |
8 #include <string> | |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "Vector.h" | 10 #include "Vector.h" |
12 #include "ImageDecoder.h" | 11 #include "ImageDecoder.h" |
13 | 12 |
14 #undef LOG | 13 #undef LOG |
15 | 14 |
16 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
17 #include "base/file_path.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
19 | 17 |
20 // If CALCULATE_MD5_SUMS is not defined, then this test decodes a handful of | 18 // If CALCULATE_MD5_SUMS is not defined, then this test decodes a handful of |
21 // image files and compares their MD5 sums to the stored sums on disk. | 19 // image files and compares their MD5 sums to the stored sums on disk. |
22 // | 20 // |
23 // To recalculate the MD5 sums, uncommment CALCULATE_MD5_SUMS. | 21 // To recalculate the MD5 sums, uncommment CALCULATE_MD5_SUMS. |
24 // | 22 // |
25 // The image files and corresponding MD5 sums live in the directory | 23 // The image files and corresponding MD5 sums live in the directory |
26 // chrome/test/data/*_decoder (where "*" is the format being tested). | 24 // chrome/test/data/*_decoder (where "*" is the format being tested). |
27 // | 25 // |
28 // Note: The MD5 sums calculated in this test by little- and big-endian systems | 26 // Note: The MD5 sums calculated in this test by little- and big-endian systems |
29 // will differ, since no endianness correction is done. If we start compiling | 27 // will differ, since no endianness correction is done. If we start compiling |
30 // for big endian machines this should be fixed. | 28 // for big endian machines this should be fixed. |
31 | 29 |
32 //#define CALCULATE_MD5_SUMS | 30 //#define CALCULATE_MD5_SUMS |
33 | 31 |
34 enum ImageDecoderTestFileSelection { | 32 enum ImageDecoderTestFileSelection { |
35 TEST_ALL, | 33 TEST_ALL, |
36 TEST_SMALLER, | 34 TEST_SMALLER, |
37 TEST_BIGGER, | 35 TEST_BIGGER, |
38 }; | 36 }; |
39 | 37 |
40 // Reads the contents of the specified file into the specified vector. | 38 // Reads the contents of the specified file into the specified vector. |
41 void ReadFileToVector(const FilePath& path, Vector<char>* contents); | 39 void ReadFileToVector(const std::wstring& path, Vector<char>* contents); |
42 | 40 |
43 // Returns the path the decoded data is saved at. | 41 // Returns the path the decoded data is saved at. |
44 FilePath GetMD5SumPath(const FilePath& path); | 42 std::wstring GetMD5SumPath(const std::wstring& path); |
45 | 43 |
46 #ifdef CALCULATE_MD5_SUMS | 44 #ifdef CALCULATE_MD5_SUMS |
47 // Saves the MD5 sum to the specified file. | 45 // Saves the MD5 sum to the specified file. |
48 void SaveMD5Sum(const FilePath& path, WebCore::RGBA32Buffer* buffer); | 46 void SaveMD5Sum(const std::wstring& path, WebCore::RGBA32Buffer* buffer); |
49 #else | 47 #else |
50 // Verifies the image. |path| identifies the path the image was loaded from. | 48 // Verifies the image. |path| identifies the path the image was loaded from. |
51 // |frame_index| indicates which index from the decoder we should examine. | 49 // |frame_index| indicates which index from the decoder we should examine. |
52 void VerifyImage(WebCore::ImageDecoder* decoder, | 50 void VerifyImage(WebCore::ImageDecoder* decoder, |
53 const FilePath& path, | 51 const std::wstring& path, |
54 const FilePath& md5_sum_path, | 52 const std::wstring& md5_sum_path, |
55 size_t frame_index); | 53 size_t frame_index); |
56 #endif | 54 #endif |
57 | 55 |
58 class ImageDecoderTest : public testing::Test { | 56 class ImageDecoderTest : public testing::Test { |
59 public: | 57 public: |
60 explicit ImageDecoderTest(const std::string& format) : format_(format) { } | 58 explicit ImageDecoderTest(const std::wstring& format) : format_(format) { } |
61 | 59 |
62 protected: | 60 protected: |
63 virtual void SetUp(); | 61 virtual void SetUp(); |
64 | 62 |
65 // Returns the vector of image files for testing. | 63 // Returns the vector of image files for testing. |
66 std::vector<FilePath> GetImageFiles() const; | 64 std::vector<std::wstring> GetImageFiles() const; |
67 | 65 |
68 // Returns true if the image is bogus and should not be successfully decoded. | 66 // Returns true if the image is bogus and should not be successfully decoded. |
69 bool ShouldImageFail(const FilePath& path) const; | 67 bool ShouldImageFail(const std::wstring& path) const; |
70 | 68 |
71 // Creates and returns an ImageDecoder for the file at the given |path|. If | 69 // Creates and returns an ImageDecoder for the file at the given |path|. If |
72 // |split_at_random| is true, also verifies that breaking the data supplied to | 70 // |split_at_random| is true, also verifies that breaking the data supplied to |
73 // the decoder into two random pieces does not cause problems. | 71 // the decoder into two random pieces does not cause problems. |
74 WebCore::ImageDecoder* SetupDecoder(const FilePath& path, | 72 WebCore::ImageDecoder* SetupDecoder(const std::wstring& path, |
75 bool split_at_random) const; | 73 bool split_at_random) const; |
76 | 74 |
77 // Verifies each of the test image files is decoded correctly and matches the | 75 // Verifies each of the test image files is decoded correctly and matches the |
78 // expected state. |file_selection| and |threshold| can be used to select | 76 // expected state. |file_selection| and |threshold| can be used to select |
79 // files to test based on file size. | 77 // files to test based on file size. |
80 void TestDecoding(ImageDecoderTestFileSelection file_selection, | 78 void TestDecoding(ImageDecoderTestFileSelection file_selection, |
81 const int64 threshold) const; | 79 const int64 threshold) const; |
82 | 80 |
83 void TestDecoding() const { | 81 void TestDecoding() const { |
84 TestDecoding(TEST_ALL, 0); | 82 TestDecoding(TEST_ALL, 0); |
85 } | 83 } |
86 | 84 |
87 #ifndef CALCULATE_MD5_SUMS | 85 #ifndef CALCULATE_MD5_SUMS |
88 // Verifies that decoding still works correctly when the files are split into | 86 // Verifies that decoding still works correctly when the files are split into |
89 // pieces at a random point. |file_selection| and |threshold| can be used to | 87 // pieces at a random point. |file_selection| and |threshold| can be used to |
90 // select files to test based on file size. | 88 // select files to test based on file size. |
91 void TestChunkedDecoding(ImageDecoderTestFileSelection file_selection, | 89 void TestChunkedDecoding(ImageDecoderTestFileSelection file_selection, |
92 const int64 threshold) const; | 90 const int64 threshold) const; |
93 | 91 |
94 void TestChunkedDecoding() const { | 92 void TestChunkedDecoding() const { |
95 TestChunkedDecoding(TEST_ALL, 0); | 93 TestChunkedDecoding(TEST_ALL, 0); |
96 } | 94 } |
97 | 95 |
98 #endif | 96 #endif |
99 | 97 |
100 // Returns the correct type of image decoder for this test. | 98 // Returns the correct type of image decoder for this test. |
101 virtual WebCore::ImageDecoder* CreateDecoder() const = 0; | 99 virtual WebCore::ImageDecoder* CreateDecoder() const = 0; |
102 | 100 |
103 // The format to be decoded, like "bmp" or "ico". | 101 // The format to be decoded, like "bmp" or "ico". |
104 std::string format_; | 102 std::wstring format_; |
105 | 103 |
106 protected: | 104 protected: |
107 // Path to the test files. | 105 // Path to the test files. |
108 FilePath data_dir_; | 106 std::wstring data_dir_; |
109 | 107 |
110 private: | 108 private: |
111 DISALLOW_COPY_AND_ASSIGN(ImageDecoderTest); | 109 DISALLOW_EVIL_CONSTRUCTORS(ImageDecoderTest); |
112 }; | 110 }; |
113 | 111 |
114 #endif // WEBKIT_TOOLS_TEST_SHELL_IMAGE_DECODER_UNITTEST_H_ | 112 #endif // WEBKIT_TOOLS_TEST_SHELL_IMAGE_DECODER_UNITTEST_H_ |
OLD | NEW |