blob: db2e69fc90d38ca17f2ea103664281de043c64e4 [file] [log] [blame]
Shane Farmer57669432017-06-19 12:52:04 -07001/*
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
25namespace aapt {
26namespace {
27
Shane Farmer0a5b2012017-06-22 12:24:12 -070028TEST(FilterTest, FilterChain) {
Shane Farmer57669432017-06-19 12:52:04 -070029 FilterChain chain;
30 ASSERT_TRUE(chain.Keep("some/random/path"));
Shane Farmer57669432017-06-19 12:52:04 -070031
Shane Farmer57669432017-06-19 12:52:04 -070032 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"));
Shane Farmer57669432017-06-19 12:52:04 -070037
Shane Farmer57669432017-06-19 12:52:04 -070038 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