This source file includes following definitions.
- TestFileURL
- TEST
#include <string>
#include "base/base_paths.h"
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "media/base/mock_data_source_host.h"
#include "media/base/test_helpers.h"
#include "media/filters/file_data_source.h"
using ::testing::NiceMock;
using ::testing::StrictMock;
namespace media {
class ReadCBHandler {
public:
ReadCBHandler() {}
MOCK_METHOD1(ReadCB, void(int size));
private:
DISALLOW_COPY_AND_ASSIGN(ReadCBHandler);
};
base::FilePath TestFileURL() {
base::FilePath data_dir;
EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir));
data_dir = data_dir.Append(FILE_PATH_LITERAL("media"))
.Append(FILE_PATH_LITERAL("test"))
.Append(FILE_PATH_LITERAL("data"))
.Append(FILE_PATH_LITERAL("ten_byte_file"));
return data_dir;
}
TEST(FileDataSourceTest, ReadData) {
int64 size;
uint8 ten_bytes[10];
FileDataSource data_source;
EXPECT_TRUE(data_source.Initialize(TestFileURL()));
EXPECT_TRUE(data_source.GetSize(&size));
EXPECT_EQ(10, size);
ReadCBHandler handler;
EXPECT_CALL(handler, ReadCB(10));
data_source.Read(0, 10, ten_bytes, base::Bind(
&ReadCBHandler::ReadCB, base::Unretained(&handler)));
EXPECT_EQ('0', ten_bytes[0]);
EXPECT_EQ('5', ten_bytes[5]);
EXPECT_EQ('9', ten_bytes[9]);
EXPECT_CALL(handler, ReadCB(1));
data_source.Read(9, 1, ten_bytes, base::Bind(
&ReadCBHandler::ReadCB, base::Unretained(&handler)));
EXPECT_EQ('9', ten_bytes[0]);
EXPECT_CALL(handler, ReadCB(0));
data_source.Read(10, 10, ten_bytes, base::Bind(
&ReadCBHandler::ReadCB, base::Unretained(&handler)));
EXPECT_CALL(handler, ReadCB(5));
data_source.Read(5, 10, ten_bytes, base::Bind(
&ReadCBHandler::ReadCB, base::Unretained(&handler)));
EXPECT_EQ('5', ten_bytes[0]);
data_source.Stop(NewExpectedClosure());
}
}