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. 4 5 #include "media/base/test_data_util.h" 6 7 #include "base/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" 12 13 namespace media { 14 15 base::FilePath GetTestDataFilePath(const std::string& name) { 16 base::FilePath file_path; 17 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); 18 19 return file_path.AppendASCII("media") 20 .AppendASCII("test") 21 .AppendASCII("data") 22 .AppendASCII(name); 23 } 24 25 scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { 26 base::FilePath file_path = GetTestDataFilePath(name); 27 28 int64 tmp = 0; 29 CHECK(base::GetFileSize(file_path, &tmp)) 30 << "Failed to get file size for '" << name << "'"; 31 32 int file_size = base::checked_cast<int>(tmp); 33 34 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); 35 CHECK_EQ(file_size, 36 base::ReadFile( 37 file_path, reinterpret_cast<char*>(buffer->writable_data()), 38 file_size)) << "Failed to read '" << name << "'"; 39 40 return buffer; 41 } 42 43 } // namespace media 44