| Index: net/base/mock_file_stream.h
|
| diff --git a/net/base/mock_file_stream.h b/net/base/mock_file_stream.h
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..fd79d89a8a53838740ec6088bc0176102e593094
|
| --- /dev/null
|
| +++ b/net/base/mock_file_stream.h
|
| @@ -0,0 +1,93 @@
|
| +// 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.
|
| +
|
| +// This file defines MockFileStream, a test class for FileStream.
|
| +
|
| +#ifndef NET_BASE_MOCK_FILE_STREAM_H_
|
| +#define NET_BASE_MOCK_FILE_STREAM_H_
|
| +#pragma once
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/compiler_specific.h"
|
| +#include "base/file_path.h"
|
| +#include "net/base/file_stream.h"
|
| +#include "net/base/net_errors.h"
|
| +
|
| +namespace testing {
|
| +
|
| +class MockFileStream : public net::FileStream {
|
| + public:
|
| + MockFileStream() : forced_error_(net::OK) {}
|
| + MockFileStream(base::PlatformFile file, int flags)
|
| + : net::FileStream(file, flags), forced_error_(net::OK) {}
|
| +
|
| + void set_forced_error(int error) { forced_error_ = error; }
|
| + void clear_forced_error() { forced_error_ = net::OK; }
|
| +
|
| + virtual int Open(const FilePath& path, int open_flags) OVERRIDE {
|
| + path_ = path;
|
| + return ReturnError(net::FileStream::Open(path, open_flags));
|
| + }
|
| +
|
| + virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE {
|
| + return ReturnError64(net::FileStream::Seek(whence, offset));
|
| + }
|
| +
|
| + virtual int64 Available() OVERRIDE {
|
| + return ReturnError64(net::FileStream::Available());
|
| + }
|
| +
|
| + virtual int Read(char* buf, int buf_len, net::CompletionCallback* callback)
|
| + OVERRIDE {
|
| + return ReturnError(net::FileStream::Read(buf, buf_len, callback));
|
| + }
|
| +
|
| + virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE {
|
| + return ReturnError(net::FileStream::ReadUntilComplete(buf, buf_len));
|
| + }
|
| +
|
| + virtual int Write(const char* buf,
|
| + int buf_len,
|
| + net::CompletionCallback* callback) OVERRIDE {
|
| + return ReturnError(net::FileStream::Write(buf, buf_len, callback));
|
| + }
|
| +
|
| + virtual int64 Truncate(int64 bytes) OVERRIDE {
|
| + return ReturnError64(net::FileStream::Truncate(bytes));
|
| + }
|
| +
|
| + virtual int Flush() OVERRIDE {
|
| + return ReturnError(net::FileStream::Flush());
|
| + }
|
| +
|
| + const FilePath& get_path() const { return path_; }
|
| +
|
| + private:
|
| + int ReturnError(int function_error) {
|
| + if (forced_error_ != net::OK) {
|
| + int ret = forced_error_;
|
| + clear_forced_error();
|
| + return ret;
|
| + }
|
| +
|
| + return function_error;
|
| + }
|
| +
|
| + int64 ReturnError64(int64 function_error) {
|
| + if (forced_error_ != net::OK) {
|
| + int64 ret = forced_error_;
|
| + clear_forced_error();
|
| + return ret;
|
| + }
|
| +
|
| + return function_error;
|
| + }
|
| +
|
| + int forced_error_;
|
| + FilePath path_;
|
| +};
|
| +
|
| +} // namespace testing
|
| +
|
| +#endif // NET_BASE_MOCK_FILE_STREAM_H_
|
|
|