| Index: webkit/tools/test_shell/image_decoder_unittest.cc
|
| ===================================================================
|
| --- webkit/tools/test_shell/image_decoder_unittest.cc (revision 29088)
|
| +++ webkit/tools/test_shell/image_decoder_unittest.cc (working copy)
|
| @@ -6,6 +6,7 @@
|
|
|
| #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"
|
| @@ -19,7 +20,7 @@
|
|
|
| // Determine if we should test with file specified by |path| based
|
| // on |file_selection| and the |threshold| for the file size.
|
| -bool ShouldSkipFile(const std::wstring& path,
|
| +bool ShouldSkipFile(const FilePath& path,
|
| ImageDecoderTestFileSelection file_selection,
|
| const int64 threshold) {
|
| if (file_selection == TEST_ALL)
|
| @@ -32,16 +33,17 @@
|
|
|
| } // anonymous namespace
|
|
|
| -void ReadFileToVector(const std::wstring& path, Vector<char>* contents) {
|
| +void ReadFileToVector(const FilePath& 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());
|
| }
|
|
|
| -std::wstring GetMD5SumPath(const std::wstring& path) {
|
| - static const std::wstring kDecodedDataExtension(L".md5sum");
|
| - return path + kDecodedDataExtension;
|
| +FilePath GetMD5SumPath(const FilePath& path) {
|
| + static const FilePath::StringType kDecodedDataExtension(
|
| + FILE_PATH_LITERAL(".md5sum"));
|
| + return FilePath(path.value() + kDecodedDataExtension);
|
| }
|
|
|
| #ifdef CALCULATE_MD5_SUMS
|
| @@ -63,18 +65,19 @@
|
| }
|
| #else
|
| void VerifyImage(WebCore::ImageDecoder* decoder,
|
| - const std::wstring& path,
|
| - const std::wstring& md5_sum_path,
|
| + const FilePath& path,
|
| + const FilePath& md5_sum_path,
|
| size_t frame_index) {
|
| // Make sure decoding can complete successfully.
|
| - EXPECT_TRUE(decoder->isSizeAvailable()) << path;
|
| - EXPECT_GE(decoder->frameCount(), frame_index) << path;
|
| + EXPECT_TRUE(decoder->isSizeAvailable()) << path.value();
|
| + EXPECT_GE(decoder->frameCount(), frame_index) << path.value();
|
| WebCore::RGBA32Buffer* image_buffer =
|
| decoder->frameBufferAtIndex(frame_index);
|
| - ASSERT_NE(static_cast<WebCore::RGBA32Buffer*>(NULL), image_buffer) << path;
|
| + ASSERT_NE(static_cast<WebCore::RGBA32Buffer*>(NULL), image_buffer) <<
|
| + path.value();
|
| EXPECT_EQ(WebCore::RGBA32Buffer::FrameComplete, image_buffer->status()) <<
|
| - path;
|
| - EXPECT_FALSE(decoder->failed()) << path;
|
| + path.value();
|
| + EXPECT_FALSE(decoder->failed()) << path.value();
|
|
|
| // Calculate MD5 sum.
|
| MD5Digest actual_digest;
|
| @@ -90,36 +93,39 @@
|
| std::string file_bytes;
|
| file_util::ReadFileToString(md5_sum_path, &file_bytes);
|
| MD5Digest expected_digest;
|
| - ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path;
|
| + ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path.value();
|
| 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;
|
| + path.value();
|
| }
|
| #endif
|
|
|
| void ImageDecoderTest::SetUp() {
|
| FilePath data_dir;
|
| ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir));
|
| - 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_;
|
| + data_dir_ = data_dir.AppendASCII("webkit").
|
| + AppendASCII("data").
|
| + AppendASCII(format_ + "_decoder");
|
| + ASSERT_TRUE(file_util::PathExists(data_dir_)) << data_dir_.value();
|
| }
|
|
|
| -std::vector<std::wstring> ImageDecoderTest::GetImageFiles() const {
|
| - std::wstring pattern = L"*." + format_;
|
| +std::vector<FilePath> ImageDecoderTest::GetImageFiles() const {
|
| +#if defined(OS_WIN)
|
| + std::wstring pattern = ASCIIToWide("*." + format_);
|
| +#else
|
| + std::string pattern = "*." + format_;
|
| +#endif
|
|
|
| - file_util::FileEnumerator enumerator(FilePath::FromWStringHack(data_dir_),
|
| + file_util::FileEnumerator enumerator(data_dir_,
|
| false,
|
| file_util::FileEnumerator::FILES);
|
|
|
| - 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)) {
|
| + std::vector<FilePath> image_files;
|
| + FilePath next_file_name;
|
| + while (!(next_file_name = enumerator.Next()).empty()) {
|
| + if (!MatchPattern(next_file_name.value(), pattern)) {
|
| continue;
|
| }
|
| image_files.push_back(next_file_name);
|
| @@ -128,15 +134,16 @@
|
| return image_files;
|
| }
|
|
|
| -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));
|
| +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));
|
| }
|
|
|
| WebCore::ImageDecoder* ImageDecoderTest::SetupDecoder(
|
| - const std::wstring& path,
|
| + const FilePath& path,
|
| bool split_at_random) const {
|
| Vector<char> image_contents;
|
| ReadFileToVector(path, &image_contents);
|
| @@ -154,7 +161,7 @@
|
| // 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;
|
| + EXPECT_FALSE(decoder->failed()) << path.value();
|
| // 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.
|
| @@ -175,8 +182,8 @@
|
| void ImageDecoderTest::TestDecoding(
|
| ImageDecoderTestFileSelection file_selection,
|
| const int64 threshold) const {
|
| - const std::vector<std::wstring> image_files(GetImageFiles());
|
| - for (std::vector<std::wstring>::const_iterator i(image_files.begin());
|
| + const std::vector<FilePath> image_files(GetImageFiles());
|
| + for (std::vector<FilePath>::const_iterator i = image_files.begin();
|
| i != image_files.end(); ++i) {
|
| if (ShouldSkipFile(*i, file_selection, threshold))
|
| continue;
|
| @@ -189,9 +196,9 @@
|
| decoder->frameBufferAtIndex(0);
|
| if (image_buffer) {
|
| EXPECT_NE(image_buffer->status(),
|
| - WebCore::RGBA32Buffer::FrameComplete) << (*i);
|
| + WebCore::RGBA32Buffer::FrameComplete) << i->value();
|
| }
|
| - EXPECT_TRUE(decoder->failed()) << (*i);
|
| + EXPECT_TRUE(decoder->failed()) << i->value();
|
| continue;
|
| }
|
|
|
| @@ -212,8 +219,8 @@
|
| const Time today = Time::Now().LocalMidnight();
|
| srand(static_cast<unsigned int>(today.ToInternalValue()));
|
|
|
| - const std::vector<std::wstring> image_files(GetImageFiles());
|
| - for (std::vector<std::wstring>::const_iterator i(image_files.begin());
|
| + const std::vector<FilePath> image_files(GetImageFiles());
|
| + for (std::vector<FilePath>::const_iterator i = image_files.begin();
|
| i != image_files.end(); ++i) {
|
| if (ShouldSkipFile(*i, file_selection, threshold))
|
| continue;
|
|
|