diff options
Diffstat (limited to 'webkit/tools/test_shell/image_decoder_unittest.cc')
-rw-r--r-- | webkit/tools/test_shell/image_decoder_unittest.cc | 85 |
1 files changed, 39 insertions, 46 deletions
diff --git a/webkit/tools/test_shell/image_decoder_unittest.cc b/webkit/tools/test_shell/image_decoder_unittest.cc index 87af6df..0c73ebd 100644 --- a/webkit/tools/test_shell/image_decoder_unittest.cc +++ b/webkit/tools/test_shell/image_decoder_unittest.cc @@ -6,7 +6,6 @@ #include "webkit/tools/test_shell/image_decoder_unittest.h" -#include "base/file_path.h" #include "base/file_util.h" #include "base/md5.h" #include "base/path_service.h" @@ -20,7 +19,7 @@ namespace { // Determine if we should test with file specified by |path| based // on |file_selection| and the |threshold| for the file size. -bool ShouldSkipFile(const FilePath& path, +bool ShouldSkipFile(const std::wstring& path, ImageDecoderTestFileSelection file_selection, const int64 threshold) { if (file_selection == TEST_ALL) @@ -33,17 +32,16 @@ bool ShouldSkipFile(const FilePath& path, } // anonymous namespace -void ReadFileToVector(const FilePath& path, Vector<char>* contents) { +void ReadFileToVector(const std::wstring& path, Vector<char>* contents) { std::string contents_str; file_util::ReadFileToString(path, &contents_str); contents->resize(contents_str.size()); memcpy(&contents->first(), contents_str.data(), contents_str.size()); } -FilePath GetMD5SumPath(const FilePath& path) { - static const FilePath::StringType kDecodedDataExtension( - FILE_PATH_LITERAL(".md5sum")); - return FilePath(path.value() + kDecodedDataExtension); +std::wstring GetMD5SumPath(const std::wstring& path) { + static const std::wstring kDecodedDataExtension(L".md5sum"); + return path + kDecodedDataExtension; } #ifdef CALCULATE_MD5_SUMS @@ -65,19 +63,18 @@ void SaveMD5Sum(const std::wstring& path, WebCore::RGBA32Buffer* buffer) { } #else void VerifyImage(WebCore::ImageDecoder* decoder, - const FilePath& path, - const FilePath& md5_sum_path, + const std::wstring& path, + const std::wstring& md5_sum_path, size_t frame_index) { // Make sure decoding can complete successfully. - EXPECT_TRUE(decoder->isSizeAvailable()) << path.value(); - EXPECT_GE(decoder->frameCount(), frame_index) << path.value(); + EXPECT_TRUE(decoder->isSizeAvailable()) << path; + EXPECT_GE(decoder->frameCount(), frame_index) << path; WebCore::RGBA32Buffer* image_buffer = decoder->frameBufferAtIndex(frame_index); - ASSERT_NE(static_cast<WebCore::RGBA32Buffer*>(NULL), image_buffer) << - path.value(); + ASSERT_NE(static_cast<WebCore::RGBA32Buffer*>(NULL), image_buffer) << path; EXPECT_EQ(WebCore::RGBA32Buffer::FrameComplete, image_buffer->status()) << - path.value(); - EXPECT_FALSE(decoder->failed()) << path.value(); + path; + EXPECT_FALSE(decoder->failed()) << path; // Calculate MD5 sum. MD5Digest actual_digest; @@ -93,39 +90,36 @@ void VerifyImage(WebCore::ImageDecoder* decoder, std::string file_bytes; file_util::ReadFileToString(md5_sum_path, &file_bytes); MD5Digest expected_digest; - ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path.value(); + ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path; memcpy(&expected_digest, file_bytes.data(), sizeof expected_digest); // Verify that the sums are the same. EXPECT_EQ(0, memcmp(&expected_digest, &actual_digest, sizeof(MD5Digest))) << - path.value(); + path; } #endif void ImageDecoderTest::SetUp() { FilePath data_dir; ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir)); - data_dir_ = data_dir.AppendASCII("webkit"). - AppendASCII("data"). - AppendASCII(format_ + "_decoder"); - ASSERT_TRUE(file_util::PathExists(data_dir_)) << data_dir_.value(); + data_dir_ = data_dir.ToWStringHack(); + file_util::AppendToPath(&data_dir_, L"webkit"); + file_util::AppendToPath(&data_dir_, L"data"); + file_util::AppendToPath(&data_dir_, format_ + L"_decoder"); + ASSERT_TRUE(file_util::PathExists(data_dir_)) << data_dir_; } -std::vector<FilePath> ImageDecoderTest::GetImageFiles() const { -#if defined(OS_WIN) - std::wstring pattern = ASCIIToWide("*." + format_); -#else - std::string pattern = "*." + format_; -#endif +std::vector<std::wstring> ImageDecoderTest::GetImageFiles() const { + std::wstring pattern = L"*." + format_; - file_util::FileEnumerator enumerator(data_dir_, + file_util::FileEnumerator enumerator(FilePath::FromWStringHack(data_dir_), false, file_util::FileEnumerator::FILES); - std::vector<FilePath> image_files; - FilePath next_file_name; - while (!(next_file_name = enumerator.Next()).empty()) { - if (!MatchPattern(next_file_name.value(), pattern)) { + std::vector<std::wstring> image_files; + std::wstring next_file_name; + while ((next_file_name = enumerator.Next().ToWStringHack()) != L"") { + if (!MatchPattern(next_file_name, pattern)) { continue; } image_files.push_back(next_file_name); @@ -134,16 +128,15 @@ std::vector<FilePath> ImageDecoderTest::GetImageFiles() const { return image_files; } -bool ImageDecoderTest::ShouldImageFail(const FilePath& path) const { - static const FilePath::StringType kBadSuffix(FILE_PATH_LITERAL(".bad.")); - return (path.value().length() > (kBadSuffix.length() + format_.length()) && - !path.value().compare(path.value().length() - format_.length() - - kBadSuffix.length(), - kBadSuffix.length(), kBadSuffix)); +bool ImageDecoderTest::ShouldImageFail(const std::wstring& path) const { + static const std::wstring kBadSuffix(L".bad."); + return (path.length() > (kBadSuffix.length() + format_.length()) && + !path.compare(path.length() - format_.length() - kBadSuffix.length(), + kBadSuffix.length(), kBadSuffix)); } WebCore::ImageDecoder* ImageDecoderTest::SetupDecoder( - const FilePath& path, + const std::wstring& path, bool split_at_random) const { Vector<char> image_contents; ReadFileToVector(path, &image_contents); @@ -161,7 +154,7 @@ WebCore::ImageDecoder* ImageDecoderTest::SetupDecoder( // Make sure the image decoder doesn't fail when we ask for the frame buffer // for this partial image. decoder->setData(shared_contents.get(), false); - EXPECT_FALSE(decoder->failed()) << path.value(); + EXPECT_FALSE(decoder->failed()) << path; // NOTE: We can't check that frame 0 is non-NULL, because if this is an ICO // and we haven't yet supplied enough data to read the directory, there is // no framecount and thus no first frame. @@ -182,8 +175,8 @@ WebCore::ImageDecoder* ImageDecoderTest::SetupDecoder( void ImageDecoderTest::TestDecoding( ImageDecoderTestFileSelection file_selection, const int64 threshold) const { - const std::vector<FilePath> image_files(GetImageFiles()); - for (std::vector<FilePath>::const_iterator i = image_files.begin(); + const std::vector<std::wstring> image_files(GetImageFiles()); + for (std::vector<std::wstring>::const_iterator i(image_files.begin()); i != image_files.end(); ++i) { if (ShouldSkipFile(*i, file_selection, threshold)) continue; @@ -196,9 +189,9 @@ void ImageDecoderTest::TestDecoding( decoder->frameBufferAtIndex(0); if (image_buffer) { EXPECT_NE(image_buffer->status(), - WebCore::RGBA32Buffer::FrameComplete) << i->value(); + WebCore::RGBA32Buffer::FrameComplete) << (*i); } - EXPECT_TRUE(decoder->failed()) << i->value(); + EXPECT_TRUE(decoder->failed()) << (*i); continue; } @@ -219,8 +212,8 @@ void ImageDecoderTest::TestChunkedDecoding( const Time today = Time::Now().LocalMidnight(); srand(static_cast<unsigned int>(today.ToInternalValue())); - const std::vector<FilePath> image_files(GetImageFiles()); - for (std::vector<FilePath>::const_iterator i = image_files.begin(); + const std::vector<std::wstring> image_files(GetImageFiles()); + for (std::vector<std::wstring>::const_iterator i(image_files.begin()); i != image_files.end(); ++i) { if (ShouldSkipFile(*i, file_selection, threshold)) continue; |