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
3 // found in the LICENSE file.
5 #include "media/base/test_data_util.h"
7 #include "base/files/file_util.h"
8 #include "base/logging.h"
9 #include "base/numerics/safe_conversions.h"
10 #include "base/path_service.h"
11 #include "media/base/decoder_buffer.h"
15 const base::FilePath::CharType kTestDataPath
[] =
16 FILE_PATH_LITERAL("media/test/data");
18 base::FilePath
GetTestDataFilePath(const std::string
& name
) {
19 base::FilePath file_path
;
20 CHECK(PathService::Get(base::DIR_SOURCE_ROOT
, &file_path
));
21 return file_path
.Append(GetTestDataPath()).AppendASCII(name
);
24 base::FilePath
GetTestDataPath() {
25 return base::FilePath(kTestDataPath
);
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())
34 query
.append(itr
->first
+ "=" + itr
->second
);
39 scoped_refptr
<DecoderBuffer
> ReadTestDataFile(const std::string
& name
) {
40 base::FilePath file_path
= GetTestDataFilePath(name
);
43 CHECK(base::GetFileSize(file_path
, &tmp
))
44 << "Failed to get file size for '" << name
<< "'";
46 int file_size
= base::checked_cast
<int>(tmp
);
48 scoped_refptr
<DecoderBuffer
> buffer(new DecoderBuffer(file_size
));
51 file_path
, reinterpret_cast<char*>(buffer
->writable_data()),
52 file_size
)) << "Failed to read '" << name
<< "'";