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/file_util.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "media/base/decoder_buffer.h"
14 base::FilePath
GetTestDataFilePath(const std::string
& name
) {
15 base::FilePath file_path
;
16 CHECK(PathService::Get(base::DIR_SOURCE_ROOT
, &file_path
));
18 file_path
= file_path
.Append(FILE_PATH_LITERAL("media"))
19 .Append(FILE_PATH_LITERAL("test"))
20 .Append(FILE_PATH_LITERAL("data"))
25 scoped_refptr
<DecoderBuffer
> ReadTestDataFile(const std::string
& name
) {
26 base::FilePath file_path
;
27 CHECK(PathService::Get(base::DIR_SOURCE_ROOT
, &file_path
));
29 file_path
= file_path
.Append(FILE_PATH_LITERAL("media"))
30 .Append(FILE_PATH_LITERAL("test"))
31 .Append(FILE_PATH_LITERAL("data"))
35 CHECK(file_util::GetFileSize(file_path
, &tmp
))
36 << "Failed to get file size for '" << name
<< "'";
38 int file_size
= static_cast<int>(tmp
);
40 scoped_refptr
<DecoderBuffer
> buffer(new DecoderBuffer(file_size
));
41 CHECK_EQ(file_size
, file_util::ReadFile(
42 file_path
, reinterpret_cast<char*>(buffer
->GetWritableData()), file_size
))
43 << "Failed to read '" << name
<< "'";