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 { | |
wtc
2011/08/29 18:17:05
IMPORTANT: I believe the top-level namespace "test
ahendrickson
2011/08/29 19:42:38
Now using the net::testing namespace.
| |
18 | |
19 class MockFileStream : public net::FileStream { | |
20 public: | |
21 MockFileStream() : forced_error_(net::OK) {} | |
22 | |
23 MockFileStream(base::PlatformFile file, int flags) | |
24 : net::FileStream(file, flags), forced_error_(net::OK) {} | |
25 | |
26 // FileStream methods. | |
27 virtual int Open(const FilePath& path, int open_flags) OVERRIDE; | |
28 virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE; | |
29 virtual int64 Available() OVERRIDE; | |
30 virtual int Read(char* buf, | |
31 int buf_len, | |
32 net::CompletionCallback* callback) OVERRIDE; | |
33 virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE; | |
34 virtual int Write(const char* buf, | |
35 int buf_len, | |
36 net::CompletionCallback* callback) OVERRIDE; | |
37 virtual int64 Truncate(int64 bytes) OVERRIDE; | |
38 virtual int Flush() OVERRIDE; | |
wtc
2011/08/29 18:17:05
IMPORTANT: You didn't override the following metho
ahendrickson
2011/08/29 19:42:38
Yes. Close() does not return an error code, so it
wtc
2011/08/29 20:03:59
It seems that if MockFileStream::Open() fails, the
| |
39 | |
40 void set_forced_error(int error) { forced_error_ = error; } | |
41 void clear_forced_error() { forced_error_ = net::OK; } | |
42 const FilePath& get_path() const { return path_; } | |
43 | |
44 private: | |
45 int ReturnError(int function_error) { | |
46 if (forced_error_ != net::OK) { | |
47 int ret = forced_error_; | |
48 clear_forced_error(); | |
49 return ret; | |
50 } | |
51 | |
52 return function_error; | |
53 } | |
54 | |
55 int64 ReturnError64(int64 function_error) { | |
56 if (forced_error_ != net::OK) { | |
57 int64 ret = forced_error_; | |
58 clear_forced_error(); | |
59 return ret; | |
60 } | |
61 | |
62 return function_error; | |
63 } | |
64 | |
65 int forced_error_; | |
66 FilePath path_; | |
67 }; | |
68 | |
69 } // namespace testing | |
70 | |
71 #endif // NET_BASE_MOCK_FILE_STREAM_H_ | |
OLD | NEW |