update_boot_flags_action_unittest.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // Copyright (C) 2018 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/update_boot_flags_action.h"
  17. #include <memory>
  18. #include <utility>
  19. #include <base/bind.h>
  20. #include <gtest/gtest.h>
  21. #include "update_engine/fake_system_state.h"
  22. namespace chromeos_update_engine {
  23. class UpdateBootFlagsActionTest : public ::testing::Test {
  24. public:
  25. FakeSystemState fake_system_state_;
  26. };
  27. TEST_F(UpdateBootFlagsActionTest, SimpleTest) {
  28. auto boot_control = fake_system_state_.fake_boot_control();
  29. auto action = std::make_unique<UpdateBootFlagsAction>(boot_control);
  30. ActionProcessor processor;
  31. processor.EnqueueAction(std::move(action));
  32. EXPECT_FALSE(UpdateBootFlagsAction::updated_boot_flags_);
  33. EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
  34. processor.StartProcessing();
  35. EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
  36. EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
  37. }
  38. TEST_F(UpdateBootFlagsActionTest, DoubleActionTest) {
  39. // Reset the static flags.
  40. UpdateBootFlagsAction::updated_boot_flags_ = false;
  41. UpdateBootFlagsAction::is_running_ = false;
  42. auto boot_control = fake_system_state_.fake_boot_control();
  43. auto action1 = std::make_unique<UpdateBootFlagsAction>(boot_control);
  44. auto action2 = std::make_unique<UpdateBootFlagsAction>(boot_control);
  45. ActionProcessor processor1, processor2;
  46. processor1.EnqueueAction(std::move(action1));
  47. processor2.EnqueueAction(std::move(action2));
  48. EXPECT_FALSE(UpdateBootFlagsAction::updated_boot_flags_);
  49. EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
  50. processor1.StartProcessing();
  51. EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
  52. EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
  53. processor2.StartProcessing();
  54. EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
  55. EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
  56. }
  57. } // namespace chromeos_update_engine