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..8f40e1c307ab4f99aa0f22556dc5de474559927d |
--- /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 { |
cbentzel
2011/08/29 15:05:27
You should run a try-job through one of the clang
ahendrickson
2011/08/29 16:30:53
Done.
|
+ public: |
+ MockFileStream() : forced_error_(net::OK) {} |
+ MockFileStream(base::PlatformFile file, int flags) |
cbentzel
2011/08/29 15:05:27
Nit: newline between these two.
ahendrickson
2011/08/29 16:30:53
Done.
|
+ : net::FileStream(file, flags), 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()); |
+ } |
+ |
+ void set_forced_error(int error) { forced_error_ = error; } |
+ void clear_forced_error() { forced_error_ = net::OK; } |
+ 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_; |
cbentzel
2011/08/29 15:05:27
Nit: indentation looks off relative to the other c
cbentzel
2011/08/29 15:05:27
Should this be an int64? Or are the upcasts from i
ahendrickson
2011/08/29 16:30:53
They are acceptable, and this prevents having to d
ahendrickson
2011/08/29 16:30:53
Done.
|
+ FilePath path_; |
+}; |
+ |
+} // namespace testing |
+ |
+#endif // NET_BASE_MOCK_FILE_STREAM_H_ |