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