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/file_util.h" | 7 #include "base/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[] = |
| 16 FILE_PATH_LITERAL("media/test/data"); |
| 17 |
15 base::FilePath GetTestDataFilePath(const std::string& name) { | 18 base::FilePath GetTestDataFilePath(const std::string& name) { |
16 base::FilePath file_path; | 19 base::FilePath file_path; |
17 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); |
| 22 } |
18 | 23 |
19 return file_path.AppendASCII("media") | 24 base::FilePath GetTestDataPath() { |
20 .AppendASCII("test") | 25 return base::FilePath(kTestDataPath); |
21 .AppendASCII("data") | 26 } |
22 .AppendASCII(name); | 27 |
| 28 std::string GetURLQueryString(const QueryParams& query_params) { |
| 29 std::string query = ""; |
| 30 QueryParams::const_iterator itr = query_params.begin(); |
| 31 for (; itr != query_params.end(); ++itr) { |
| 32 if (itr != query_params.begin()) |
| 33 query.append("&"); |
| 34 query.append(itr->first + "=" + itr->second); |
| 35 } |
| 36 return query; |
| 37 } |
| 38 |
| 39 scoped_ptr<net::SpawnedTestServer> StartMediaHttpTestServer() { |
| 40 scoped_ptr<net::SpawnedTestServer> http_test_server; |
| 41 http_test_server.reset(new net::SpawnedTestServer( |
| 42 net::SpawnedTestServer::TYPE_HTTP, |
| 43 net::SpawnedTestServer::kLocalhost, |
| 44 GetTestDataPath())); |
| 45 CHECK(http_test_server->Start()); |
| 46 return http_test_server.Pass(); |
23 } | 47 } |
24 | 48 |
25 scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { | 49 scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { |
26 base::FilePath file_path = GetTestDataFilePath(name); | 50 base::FilePath file_path = GetTestDataFilePath(name); |
27 | 51 |
28 int64 tmp = 0; | 52 int64 tmp = 0; |
29 CHECK(base::GetFileSize(file_path, &tmp)) | 53 CHECK(base::GetFileSize(file_path, &tmp)) |
30 << "Failed to get file size for '" << name << "'"; | 54 << "Failed to get file size for '" << name << "'"; |
31 | 55 |
32 int file_size = base::checked_cast<int>(tmp); | 56 int file_size = base::checked_cast<int>(tmp); |
33 | 57 |
34 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); | 58 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); |
35 CHECK_EQ(file_size, | 59 CHECK_EQ(file_size, |
36 base::ReadFile( | 60 base::ReadFile( |
37 file_path, reinterpret_cast<char*>(buffer->writable_data()), | 61 file_path, reinterpret_cast<char*>(buffer->writable_data()), |
38 file_size)) << "Failed to read '" << name << "'"; | 62 file_size)) << "Failed to read '" << name << "'"; |
39 | 63 |
40 return buffer; | 64 return buffer; |
41 } | 65 } |
42 | 66 |
43 } // namespace media | 67 } // namespace media |
OLD | NEW |