| // Copyright 2021 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "utility.hpp" |
| |
| #include <flashupdate/flash/mock.hpp> |
| #include <flashupdate/info.hpp> |
| #include <flashupdate/ops.hpp> |
| #include <flashupdate/validator.hpp> |
| #include <flashupdate/validator/mock.hpp> |
| |
| #include <fstream> |
| #include <sstream> |
| #include <string> |
| |
| #include <gtest/gtest.h> |
| |
| using ::testing::_; |
| using ::testing::Return; |
| |
| namespace flashupdate |
| { |
| |
| using DescriptorHash = validator::Validator::DescriptorHash; |
| |
| TEST_F(OperationTest, ErasePrimary) |
| { |
| Args args; |
| args.primary = true; |
| |
| EXPECT_THROW( |
| try { ops::erase(args); } catch (const std::runtime_error& e) { |
| EXPECT_STREQ(e.what(), "Does not support primary partition erase"); |
| throw; |
| }, |
| std::runtime_error); |
| } |
| |
| TEST_F(OperationTest, EraseInvalidFlash) |
| { |
| Args args; |
| args.primary = false; |
| args.stagingIndex = 1; |
| |
| flash::Mock flashMockHelper; |
| args.setFlashHelper(&flashMockHelper); |
| |
| EXPECT_CALL(flashMockHelper, getFlash(_, _)).WillOnce(Return(std::nullopt)); |
| |
| EXPECT_THROW( |
| try { ops::erase(args); } catch (const std::runtime_error& e) { |
| EXPECT_STREQ(e.what(), |
| "Failed to find Flash partition for secondary/1"); |
| throw; |
| }, |
| std::runtime_error); |
| } |
| |
| } // namespace flashupdate |