fake_filesystem.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. //
  16. #include "update_engine/payload_generator/fake_filesystem.h"
  17. #include <gtest/gtest.h>
  18. namespace chromeos_update_engine {
  19. FakeFilesystem::FakeFilesystem(uint64_t block_size, uint64_t block_count)
  20. : block_size_(block_size), block_count_(block_count) {}
  21. size_t FakeFilesystem::GetBlockSize() const {
  22. return block_size_;
  23. }
  24. size_t FakeFilesystem::GetBlockCount() const {
  25. return block_count_;
  26. }
  27. bool FakeFilesystem::GetFiles(std::vector<File>* files) const {
  28. *files = files_;
  29. return true;
  30. }
  31. void FakeFilesystem::AddFile(const std::string& filename,
  32. const std::vector<Extent>& extents) {
  33. File file;
  34. file.name = filename;
  35. file.extents = extents;
  36. for (const Extent& extent : extents) {
  37. EXPECT_LE(0U, extent.start_block());
  38. EXPECT_LE(extent.start_block() + extent.num_blocks(), block_count_);
  39. }
  40. files_.push_back(file);
  41. }
  42. bool FakeFilesystem::LoadSettings(brillo::KeyValueStore* store) const {
  43. if (minor_version_ < 0)
  44. return false;
  45. store->SetString("PAYLOAD_MINOR_VERSION", std::to_string(minor_version_));
  46. return true;
  47. }
  48. } // namespace chromeos_update_engine