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 "gmock/gmock.h"
25 #include "gtest/gtest.h"
26 #include "perfetto/base/build_config.h"
27 #include "perfetto/base/scoped_file.h"
28 #include "perfetto/base/temp_file.h"
29 #include "perfetto/base/utils.h"
30 
31 namespace perfetto {
32 namespace {
33 
TEST(PrefixFinderTest,Basic)34 TEST(PrefixFinderTest, Basic) {
35   PrefixFinder pr(4);
36   pr.AddPath("/a/1");
37   pr.AddPath("/a/2");
38   pr.AddPath("/a/3");
39   pr.AddPath("/b/4");
40   pr.AddPath("/b/5");
41 
42   pr.Finalize();
43 
44   ASSERT_EQ(pr.GetPrefix("/a/1")->ToString(), "");
45   ASSERT_EQ(pr.GetPrefix("/a/2")->ToString(), "");
46   ASSERT_EQ(pr.GetPrefix("/a/3")->ToString(), "");
47   ASSERT_EQ(pr.GetPrefix("/b/4")->ToString(), "/b");
48   ASSERT_EQ(pr.GetPrefix("/b/5")->ToString(), "/b");
49 }
50 
51 }  // namespace
52 }  // namespace perfetto
53