blob: fb75a4b4d7c190dfaee8188e812ef0015fb2519e [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
28TEST(FilterChainTest, EmptyChain) {
29 FilterChain chain;
30 ASSERT_TRUE(chain.Keep("some/random/path"));
31}
32
33TEST(FilterChainTest, SingleFilter) {
34 FilterChain chain;
35 chain.AddFilter(util::make_unique<PrefixFilter>("keep/"));
36
37 ASSERT_FALSE(chain.Keep("removed/path"));
38 ASSERT_TRUE(chain.Keep("keep/path/1"));
39 ASSERT_TRUE(chain.Keep("keep/path/2"));
40}
41
42TEST(FilterChainTest, MultipleFilters) {
43 FilterChain chain;
44 chain.AddFilter(util::make_unique<PrefixFilter>("keep/"));
45 chain.AddFilter(util::make_unique<PrefixFilter>("keep/really/"));
46
47 ASSERT_FALSE(chain.Keep("removed/path"));
48 ASSERT_FALSE(chain.Keep("/keep/really/wrong/prefix"));
49 ASSERT_FALSE(chain.Keep("keep/maybe/1"));
50 ASSERT_TRUE(chain.Keep("keep/really/1"));
51}
52
53} // namespace
54} // namespace aapt