Index: media/base/test_data_util.cc |
diff --git a/media/base/test_data_util.cc b/media/base/test_data_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b3cb1d8f11a24403ce165945d6149a624df96d24 |
--- /dev/null |
+++ b/media/base/test_data_util.cc |
@@ -0,0 +1,50 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/base/test_data_util.h" |
+ |
+#include "base/file_util.h" |
+#include "base/path_service.h" |
+ |
+namespace media { |
+ |
+bool ReadTestDataFile(const std::string& name, scoped_array<uint8>* buffer, |
+ int* size) { |
+ FilePath file_path; |
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &file_path)) |
+ return false; |
+ |
+ file_path = file_path.Append(FILE_PATH_LITERAL("media")) |
+ .Append(FILE_PATH_LITERAL("test")) |
+ .Append(FILE_PATH_LITERAL("data")) |
+ .AppendASCII(name); |
+ |
+ int64 tmp = 0; |
+ if (!file_util::GetFileSize(file_path, &tmp)) |
+ return false; |
+ |
+ int file_size = static_cast<int>(tmp); |
+ buffer->reset(new uint8[file_size]); |
+ |
+ if (file_size != file_util::ReadFile(file_path, |
+ reinterpret_cast<char*>(buffer->get()), |
+ file_size)) { |
+ buffer->reset(); |
+ return false; |
+ } |
+ |
+ *size = file_size; |
+ return true; |
+} |
+ |
+bool ReadTestDataFile(const std::string& name, scoped_refptr<Buffer>* buffer) { |
+ scoped_array<uint8> buf; |
+ int buf_size; |
+ if (!ReadTestDataFile(name, &buf, &buf_size)) |
+ return false; |
+ *buffer = new DataBuffer(buf.release(), buf_size); |
+ return true; |
+} |
+ |
+} // namespace media |