OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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. | |
4 | |
5 // This file defines MockFileStream, a test class for FileStream. | |
6 | |
7 #ifndef NET_BASE_MOCK_FILE_STREAM_H_ | |
8 #define NET_BASE_MOCK_FILE_STREAM_H_ | |
9 #pragma once | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/file_path.h" | |
14 #include "net/base/file_stream.h" | |
15 #include "net/base/net_errors.h" | |
16 | |
17 namespace testing { | |
18 | |
19 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.
| |
20 public: | |
21 MockFileStream() : forced_error_(net::OK) {} | |
22 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.
| |
23 : net::FileStream(file, flags), forced_error_(net::OK) {} | |
24 | |
25 virtual int Open(const FilePath& path, int open_flags) OVERRIDE { | |
26 path_ = path; | |
27 return ReturnError(net::FileStream::Open(path, open_flags)); | |
28 } | |
29 | |
30 virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE { | |
31 return ReturnError64(net::FileStream::Seek(whence, offset)); | |
32 } | |
33 | |
34 virtual int64 Available() OVERRIDE { | |
35 return ReturnError64(net::FileStream::Available()); | |
36 } | |
37 | |
38 virtual int Read(char* buf, | |
39 int buf_len, | |
40 net::CompletionCallback* callback) OVERRIDE { | |
41 return ReturnError(net::FileStream::Read(buf, buf_len, callback)); | |
42 } | |
43 | |
44 virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE { | |
45 return ReturnError(net::FileStream::ReadUntilComplete(buf, buf_len)); | |
46 } | |
47 | |
48 virtual int Write(const char* buf, | |
49 int buf_len, | |
50 net::CompletionCallback* callback) OVERRIDE { | |
51 return ReturnError(net::FileStream::Write(buf, buf_len, callback)); | |
52 } | |
53 | |
54 virtual int64 Truncate(int64 bytes) OVERRIDE { | |
55 return ReturnError64(net::FileStream::Truncate(bytes)); | |
56 } | |
57 | |
58 virtual int Flush() OVERRIDE { | |
59 return ReturnError(net::FileStream::Flush()); | |
60 } | |
61 | |
62 void set_forced_error(int error) { forced_error_ = error; } | |
63 void clear_forced_error() { forced_error_ = net::OK; } | |
64 const FilePath& get_path() const { return path_; } | |
65 | |
66 private: | |
67 int ReturnError(int function_error) { | |
68 if (forced_error_ != net::OK) { | |
69 int ret = forced_error_; | |
70 clear_forced_error(); | |
71 return ret; | |
72 } | |
73 | |
74 return function_error; | |
75 } | |
76 | |
77 int64 ReturnError64(int64 function_error) { | |
78 if (forced_error_ != net::OK) { | |
79 int64 ret = forced_error_; | |
80 clear_forced_error(); | |
81 return ret; | |
82 } | |
83 | |
84 return function_error; | |
85 } | |
86 | |
87 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.
| |
88 FilePath path_; | |
89 }; | |
90 | |
91 } // namespace testing | |
92 | |
93 #endif // NET_BASE_MOCK_FILE_STREAM_H_ | |
OLD | NEW |