1 /*
2  * Copyright (c) 2016, Google Inc.
3  * All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include <vector>
9 
10 #include "path_matching.h"
11 #include "string_compat.h"
12 #include "test_compat.h"
13 
14 namespace perftools {
15 
16 TEST(PathMatching, DeletedSharedObjectMatching) {
17   const std::vector<string> paths = {
18       "lib.so.v1(deleted)",
19       "lib.so.v1(deleted)junk",
20       "lib.so (deleted)",
21       "lib.so_junk_(deleted)",
22       "lib.so   .so junk_(deleted)",
23   };
24   for (const auto& path : paths) {
25     ASSERT_TRUE(IsDeletedSharedObject(path));
26   }
27 }
28 
29 TEST(PathMatching, DeletedSharedObjectNotMatching) {
30   const std::vector<string> paths = {
31       "abc",
32       "lib.so ",
33       "lib.so(deleted)",
34       ".so (deleted)",
35       "lib.sojunk(deleted)",
36       "",
37   };
38 
39   for (const auto& path : paths) {
40     ASSERT_FALSE(IsDeletedSharedObject(path));
41   }
42 }
43 
44 TEST(PathMatching, VersionedSharedObjectMatching) {
45   const std::vector<string> paths = {
46       "lib.so.", "lib.so.abc", "lib.so.1", "lib.so.v1",
47   };
48   for (const auto& path : paths) {
49     ASSERT_TRUE(IsVersionedSharedObject(path));
50   }
51 }
52 
53 TEST(PathMatching, VersionedSharedObjectNotMatching) {
54   const std::vector<string> paths = {
55       "abc", "lib.so(deleted)", ".so.v1", ".so.", "",
56   };
57   for (const auto& path : paths) {
58     ASSERT_FALSE(IsDeletedSharedObject(path));
59   }
60 }
61 
62 }  // namespace perftools
63 
64 int main(int argc, char** argv) {
65   ::testing::InitGoogleTest(&argc, argv);
66   return RUN_ALL_TESTS();
67 }
68