| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/base/test_data_util.h" | 5 #include "media/base/test_data_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "media/base/decoder_buffer.h" | 11 #include "media/base/decoder_buffer.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 const base::FilePath::CharType kTestDataPath[] = | 15 const base::FilePath::CharType kTestDataPath[] = |
| 16 FILE_PATH_LITERAL("media/test/data"); | 16 FILE_PATH_LITERAL("media/test/data"); |
| 17 | 17 |
| 18 base::FilePath GetTestDataFilePath(const std::string& name) { | 18 base::FilePath GetTestDataFilePath(const std::string& name) { |
| 19 base::FilePath file_path; | 19 base::FilePath file_path; |
| 20 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); | 20 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); |
| 21 return file_path.Append(GetTestDataPath()).AppendASCII(name); | 21 return file_path.Append(GetTestDataPath()).AppendASCII(name); |
| 22 } | 22 } |
| 23 | 23 |
| 24 base::FilePath GetTestDataPath() { | 24 base::FilePath GetTestDataPath() { |
| 25 return base::FilePath(kTestDataPath); | 25 return base::FilePath(kTestDataPath); |
| 26 } | 26 } |
| 27 | 27 |
| 28 std::string GetURLQueryString(const QueryParams& query_params) { | 28 std::string GetURLQueryString(const base::StringPairs& query_params) { |
| 29 std::string query = ""; | 29 std::string query = ""; |
| 30 QueryParams::const_iterator itr = query_params.begin(); | 30 base::StringPairs::const_iterator itr = query_params.begin(); |
| 31 for (; itr != query_params.end(); ++itr) { | 31 for (; itr != query_params.end(); ++itr) { |
| 32 if (itr != query_params.begin()) | 32 if (itr != query_params.begin()) |
| 33 query.append("&"); | 33 query.append("&"); |
| 34 query.append(itr->first + "=" + itr->second); | 34 query.append(itr->first + "=" + itr->second); |
| 35 } | 35 } |
| 36 return query; | 36 return query; |
| 37 } | 37 } |
| 38 | 38 |
| 39 scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { | 39 scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { |
| 40 base::FilePath file_path = GetTestDataFilePath(name); | 40 base::FilePath file_path = GetTestDataFilePath(name); |
| 41 | 41 |
| 42 int64 tmp = 0; | 42 int64 tmp = 0; |
| 43 CHECK(base::GetFileSize(file_path, &tmp)) | 43 CHECK(base::GetFileSize(file_path, &tmp)) |
| 44 << "Failed to get file size for '" << name << "'"; | 44 << "Failed to get file size for '" << name << "'"; |
| 45 | 45 |
| 46 int file_size = base::checked_cast<int>(tmp); | 46 int file_size = base::checked_cast<int>(tmp); |
| 47 | 47 |
| 48 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); | 48 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); |
| 49 CHECK_EQ(file_size, | 49 CHECK_EQ(file_size, |
| 50 base::ReadFile( | 50 base::ReadFile( |
| 51 file_path, reinterpret_cast<char*>(buffer->writable_data()), | 51 file_path, reinterpret_cast<char*>(buffer->writable_data()), |
| 52 file_size)) << "Failed to read '" << name << "'"; | 52 file_size)) << "Failed to read '" << name << "'"; |
| 53 | 53 |
| 54 return buffer; | 54 return buffer; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace media | 57 } // namespace media |
| OLD | NEW |