1 /*
2  * Copyright (C) 2017 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 "filter/Filter.h"
18 
19 #include <string>
20 
21 #include "io/Util.h"
22 
23 #include "gtest/gtest.h"
24 
25 namespace aapt {
26 namespace {
27 
TEST(FilterTest,FilterChain)28 TEST(FilterTest, FilterChain) {
29   FilterChain chain;
30   ASSERT_TRUE(chain.Keep("some/random/path"));
31 
32   chain.AddFilter(util::make_unique<PrefixFilter>("keep/"));
33 
34   ASSERT_FALSE(chain.Keep("removed/path"));
35   ASSERT_TRUE(chain.Keep("keep/path/1"));
36   ASSERT_TRUE(chain.Keep("keep/path/2"));
37 
38   chain.AddFilter(util::make_unique<PrefixFilter>("keep/"));
39   chain.AddFilter(util::make_unique<PrefixFilter>("keep/really/"));
40 
41   ASSERT_FALSE(chain.Keep("removed/path"));
42   ASSERT_FALSE(chain.Keep("/keep/really/wrong/prefix"));
43   ASSERT_FALSE(chain.Keep("keep/maybe/1"));
44   ASSERT_TRUE(chain.Keep("keep/really/1"));
45 }
46 
47 }  // namespace
48 }  // namespace aapt
49