1 //
2 // Copyright (C) 2020 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/cros/excluder_chromeos.h"
18 
19 #include <gtest/gtest.h>
20 
21 #include "update_engine/cros/fake_system_state.h"
22 
23 namespace chromeos_update_engine {
24 
25 namespace {
26 constexpr char kFakeHash[] =
27     "71ff43d76e2488e394e46872f5b066cc25e394c2c3e3790dd319517883b33db1";
28 }  // namespace
29 
30 class ExcluderChromeOSTest : public ::testing::Test {
31  protected:
SetUp()32   void SetUp() override { FakeSystemState::CreateInstance(); }
33 
34   ExcluderChromeOS excluder_;
35 };
36 
TEST_F(ExcluderChromeOSTest,ExclusionCheck)37 TEST_F(ExcluderChromeOSTest, ExclusionCheck) {
38   EXPECT_FALSE(excluder_.IsExcluded(kFakeHash));
39   EXPECT_TRUE(excluder_.Exclude(kFakeHash));
40   EXPECT_TRUE(excluder_.IsExcluded(kFakeHash));
41 }
42 
TEST_F(ExcluderChromeOSTest,ResetFlow)43 TEST_F(ExcluderChromeOSTest, ResetFlow) {
44   EXPECT_TRUE(excluder_.Exclude("abc"));
45   EXPECT_TRUE(excluder_.Exclude(kFakeHash));
46   EXPECT_TRUE(excluder_.IsExcluded("abc"));
47   EXPECT_TRUE(excluder_.IsExcluded(kFakeHash));
48 
49   EXPECT_TRUE(excluder_.Reset());
50   EXPECT_FALSE(excluder_.IsExcluded("abc"));
51   EXPECT_FALSE(excluder_.IsExcluded(kFakeHash));
52 }
53 
54 }  // namespace chromeos_update_engine
55