| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_FILE_WRITER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_FILE_WRITER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_FILE_WRITER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_FILE_WRITER_H__ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "update_engine/file_writer.h" | 9 #include "update_engine/file_writer.h" |
| 10 | 10 |
| 11 // MockFileWriter is an implementation of FileWriter. It will succeed | 11 // MockFileWriter is an implementation of FileWriter. It will succeed |
| 12 // calls to Open(), Close(), but not do any work. All calls to Write() | 12 // calls to Open(), Close(), but not do any work. All calls to Write() |
| 13 // will append the passed data to an internal vector. | 13 // will append the passed data to an internal vector. |
| 14 | 14 |
| 15 namespace chromeos_update_engine { | 15 namespace chromeos_update_engine { |
| 16 | 16 |
| 17 class MockFileWriter : public FileWriter { | 17 class MockFileWriter : public FileWriter { |
| 18 public: | 18 public: |
| 19 MockFileWriter() : was_opened_(false), was_closed_(false) {} | 19 MockFileWriter() : was_opened_(false), was_closed_(false) {} |
| 20 | 20 |
| 21 virtual int Open(const char* path, int flags, mode_t mode) { | 21 virtual int Open(const char* path, int flags, mode_t mode) { |
| 22 CHECK(!was_opened_); | 22 CHECK(!was_opened_); |
| 23 CHECK(!was_closed_); | 23 CHECK(!was_closed_); |
| 24 was_opened_ = true; | 24 was_opened_ = true; |
| 25 return 0; | 25 return 0; |
| 26 } | 26 } |
| 27 | 27 |
| 28 virtual int Write(const void* bytes, size_t count) { | 28 virtual ssize_t Write(const void* bytes, size_t count) { |
| 29 CHECK(was_opened_); | 29 CHECK(was_opened_); |
| 30 CHECK(!was_closed_); | 30 CHECK(!was_closed_); |
| 31 const char* char_bytes = reinterpret_cast<const char*>(bytes); | 31 const char* char_bytes = reinterpret_cast<const char*>(bytes); |
| 32 bytes_.insert(bytes_.end(), char_bytes, char_bytes + count); | 32 bytes_.insert(bytes_.end(), char_bytes, char_bytes + count); |
| 33 return count; | 33 return count; |
| 34 } | 34 } |
| 35 | 35 |
| 36 virtual int Close() { | 36 virtual int Close() { |
| 37 CHECK(was_opened_); | 37 CHECK(was_opened_); |
| 38 CHECK(!was_closed_); | 38 CHECK(!was_closed_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 // These are just to ensure FileWriter methods are called properly. | 50 // These are just to ensure FileWriter methods are called properly. |
| 51 bool was_opened_; | 51 bool was_opened_; |
| 52 bool was_closed_; | 52 bool was_closed_; |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(MockFileWriter); | 54 DISALLOW_COPY_AND_ASSIGN(MockFileWriter); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace chromeos_update_engine | 57 } // namespace chromeos_update_engine |
| 58 | 58 |
| 59 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_FILE_WRITER_H__ | 59 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_FILE_WRITER_H__ |
| OLD | NEW |