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 "src/traced/probes/filesystem/prefix_finder.h"
18
19 #include <fcntl.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <sys/stat.h>
23
24 #include "perfetto/base/build_config.h"
25 #include "perfetto/ext/base/scoped_file.h"
26 #include "perfetto/ext/base/temp_file.h"
27 #include "perfetto/ext/base/utils.h"
28 #include "test/gtest_and_gmock.h"
29
30 namespace perfetto {
31 namespace {
32
TEST(PrefixFinderTest,Basic)33 TEST(PrefixFinderTest, Basic) {
34 PrefixFinder pr(4);
35 pr.AddPath("/a/1");
36 pr.AddPath("/a/2");
37 pr.AddPath("/a/3");
38 pr.AddPath("/b/4");
39 pr.AddPath("/b/5");
40
41 pr.Finalize();
42
43 ASSERT_EQ(pr.GetPrefix("/a/1")->ToString(), "");
44 ASSERT_EQ(pr.GetPrefix("/a/2")->ToString(), "");
45 ASSERT_EQ(pr.GetPrefix("/a/3")->ToString(), "");
46 ASSERT_EQ(pr.GetPrefix("/b/4")->ToString(), "/b");
47 ASSERT_EQ(pr.GetPrefix("/b/5")->ToString(), "/b");
48 }
49
50 } // namespace
51 } // namespace perfetto
52