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 // This file defines MockFileStream, a test class for FileStream.
7 #ifndef NET_BASE_MOCK_FILE_STREAM_H_
8 #define NET_BASE_MOCK_FILE_STREAM_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "net/base/file_stream.h"
14 #include "net/base/net_errors.h"
22 class MockFileStream : public net::FileStream {
24 MockFileStream(net::NetLog* net_log)
25 : net::FileStream(net_log), forced_error_(net::OK) {}
27 MockFileStream(base::PlatformFile file, int flags, net::NetLog* net_log)
28 : net::FileStream(file, flags, net_log), forced_error_(net::OK) {}
30 // FileStream methods.
31 virtual int OpenSync(const base::FilePath& path, int open_flags) OVERRIDE;
32 virtual int Seek(net::Whence whence, int64 offset,
33 const Int64CompletionCallback& callback) OVERRIDE;
34 virtual int64 SeekSync(net::Whence whence, int64 offset) OVERRIDE;
35 virtual int64 Available() OVERRIDE;
36 virtual int Read(IOBuffer* buf,
38 const CompletionCallback& callback) OVERRIDE;
39 virtual int ReadSync(char* buf, int buf_len) OVERRIDE;
40 virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE;
41 virtual int Write(IOBuffer* buf,
43 const CompletionCallback& callback) OVERRIDE;
44 virtual int WriteSync(const char* buf, int buf_len) OVERRIDE;
45 virtual int64 Truncate(int64 bytes) OVERRIDE;
46 virtual int Flush(const CompletionCallback& callback) OVERRIDE;
47 virtual int FlushSync() OVERRIDE;
49 void set_forced_error(int error) { forced_error_ = error; }
50 void clear_forced_error() { forced_error_ = net::OK; }
51 int forced_error() const { return forced_error_; }
52 const base::FilePath& get_path() const { return path_; }
55 int ReturnError(int function_error) {
56 if (forced_error_ != net::OK) {
57 int ret = forced_error_;
62 return function_error;
65 int64 ReturnError64(int64 function_error) {
66 if (forced_error_ != net::OK) {
67 int64 ret = forced_error_;
72 return function_error;
79 } // namespace testing
83 #endif // NET_BASE_MOCK_FILE_STREAM_H_