| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
 | 2 | // Copyright (C) 2015 The Android Open Source Project | 
 | 3 | // | 
 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 | // you may not use this file except in compliance with the License. | 
 | 6 | // You may obtain a copy of the License at | 
 | 7 | // | 
 | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 | // | 
 | 10 | // Unless required by applicable law or agreed to in writing, software | 
 | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 | // See the License for the specific language governing permissions and | 
 | 14 | // limitations under the License. | 
 | 15 | // | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 16 |  | 
 | 17 | #include "update_engine/payload_generator/fake_filesystem.h" | 
 | 18 |  | 
 | 19 | #include <gtest/gtest.h> | 
 | 20 |  | 
 | 21 | namespace chromeos_update_engine { | 
 | 22 |  | 
| Amin Hassani | 232f8f9 | 2019-01-14 16:15:31 -0800 | [diff] [blame] | 23 | FakeFilesystem::FakeFilesystem(uint64_t block_size, uint64_t block_count) | 
 | 24 |     : block_size_(block_size), block_count_(block_count) {} | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 25 |  | 
 | 26 | size_t FakeFilesystem::GetBlockSize() const { | 
 | 27 |   return block_size_; | 
 | 28 | } | 
 | 29 |  | 
 | 30 | size_t FakeFilesystem::GetBlockCount() const { | 
 | 31 |   return block_count_; | 
 | 32 | } | 
 | 33 |  | 
 | 34 | bool FakeFilesystem::GetFiles(std::vector<File>* files) const { | 
 | 35 |   *files = files_; | 
 | 36 |   return true; | 
 | 37 | } | 
 | 38 |  | 
 | 39 | void FakeFilesystem::AddFile(const std::string& filename, | 
| Chih-Hung Hsieh | 5c6bb1d | 2016-07-27 13:33:15 -0700 | [diff] [blame] | 40 |                              const std::vector<Extent>& extents) { | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 41 |   File file; | 
 | 42 |   file.name = filename; | 
 | 43 |   file.extents = extents; | 
 | 44 |   for (const Extent& extent : extents) { | 
| Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 45 |     EXPECT_LE(0U, extent.start_block()); | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 46 |     EXPECT_LE(extent.start_block() + extent.num_blocks(), block_count_); | 
 | 47 |   } | 
 | 48 |   files_.push_back(file); | 
 | 49 | } | 
 | 50 |  | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 51 | bool FakeFilesystem::LoadSettings(brillo::KeyValueStore* store) const { | 
| Alex Deymo | 2e9533b | 2015-06-26 20:57:06 -0700 | [diff] [blame] | 52 |   if (minor_version_ < 0) | 
 | 53 |     return false; | 
 | 54 |   store->SetString("PAYLOAD_MINOR_VERSION", std::to_string(minor_version_)); | 
 | 55 |   return true; | 
 | 56 | } | 
 | 57 |  | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 58 | }  // namespace chromeos_update_engine |