aboutsummaryrefslogtreecommitdiff
blob: 1ad9e7f0dd7d0d1044c7ecd95cb491e432d13321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
//===-- FindAllSymbolsTests.cpp - find all symbols unit tests ---*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "FindAllSymbolsAction.h"
#include "HeaderMapCollector.h"
#include "SymbolInfo.h"
#include "SymbolReporter.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/PCHContainerOperations.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "gtest/gtest.h"
#include <memory>
#include <string>
#include <vector>

namespace clang {
namespace find_all_symbols {

static const char HeaderName[] = "symbols.h";

class TestSymbolReporter : public SymbolReporter {
public:
  ~TestSymbolReporter() override {}

  void reportSymbols(llvm::StringRef FileName,
                     const SymbolInfo::SignalMap &NewSymbols) override {
    for (const auto &Entry : NewSymbols)
      Symbols[Entry.first] += Entry.second;
  }

  int seen(const SymbolInfo &Symbol) const {
    auto it = Symbols.find(Symbol);
    return it == Symbols.end() ? 0 : it->second.Seen;
  }

  int used(const SymbolInfo &Symbol) const {
    auto it = Symbols.find(Symbol);
    return it == Symbols.end() ? 0 : it->second.Used;
  }

private:
  SymbolInfo::SignalMap Symbols;
};

class FindAllSymbolsTest : public ::testing::Test {
public:
  int seen(const SymbolInfo &Symbol) { return Reporter.seen(Symbol); }

  int used(const SymbolInfo &Symbol) { return Reporter.used(Symbol); }

  bool runFindAllSymbols(StringRef HeaderCode, StringRef MainCode) {
    llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
        new llvm::vfs::InMemoryFileSystem);
    llvm::IntrusiveRefCntPtr<FileManager> Files(
        new FileManager(FileSystemOptions(), InMemoryFileSystem));

    std::string FileName = "symbol.cc";

    const std::string InternalHeader = "internal/internal_header.h";
    const std::string TopHeader = "<top>";
    // Test .inc header path. The header for `IncHeaderClass` should be
    // internal.h, which will eventually be mapped to <top>.
    std::string IncHeader = "internal/private.inc";
    std::string IncHeaderCode = "class IncHeaderClass {};";

    HeaderMapCollector::RegexHeaderMap RegexMap = {
        {R"(internal_.*\.h$)", TopHeader.c_str()},
    };

    std::string InternalCode =
        "#include \"private.inc\"\nclass Internal {};";
    SymbolInfo InternalSymbol("Internal", SymbolInfo::SymbolKind::Class,
                              TopHeader, {});
    SymbolInfo IncSymbol("IncHeaderClass", SymbolInfo::SymbolKind::Class,
                         TopHeader, {});
    InMemoryFileSystem->addFile(
        IncHeader, 0, llvm::MemoryBuffer::getMemBuffer(IncHeaderCode));
    InMemoryFileSystem->addFile(InternalHeader, 0,
                                llvm::MemoryBuffer::getMemBuffer(InternalCode));

    std::unique_ptr<tooling::FrontendActionFactory> Factory(
        new FindAllSymbolsActionFactory(&Reporter, &RegexMap));

    tooling::ToolInvocation Invocation(
        {std::string("find_all_symbols"), std::string("-fsyntax-only"),
         std::string("-std=c++11"), FileName},
        Factory->create(), Files.get(),
        std::make_shared<PCHContainerOperations>());

    InMemoryFileSystem->addFile(HeaderName, 0,
                                llvm::MemoryBuffer::getMemBuffer(HeaderCode));

    std::string Content = "#include\"" + std::string(HeaderName) +
                          "\"\n"
                          "#include \"" +
                          InternalHeader + "\"";
#if !defined(_MSC_VER) && !defined(__MINGW32__)
    // Test path cleaning for both decls and macros.
    const std::string DirtyHeader = "./internal/./a/b.h";
    Content += "\n#include \"" + DirtyHeader + "\"";
    const std::string CleanHeader = "internal/a/b.h";
    const std::string DirtyHeaderContent =
        "#define INTERNAL 1\nclass ExtraInternal {};";
    InMemoryFileSystem->addFile(
        DirtyHeader, 0, llvm::MemoryBuffer::getMemBuffer(DirtyHeaderContent));
    SymbolInfo DirtyMacro("INTERNAL", SymbolInfo::SymbolKind::Macro,
                          CleanHeader, {});
    SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class,
                           CleanHeader, {});
#endif // _MSC_VER && __MINGW32__
    Content += "\n" + MainCode.str();
    InMemoryFileSystem->addFile(FileName, 0,
                                llvm::MemoryBuffer::getMemBuffer(Content));
    Invocation.run();
    EXPECT_EQ(1, seen(InternalSymbol));
    EXPECT_EQ(1, seen(IncSymbol));
#if !defined(_MSC_VER) && !defined(__MINGW32__)
    EXPECT_EQ(1, seen(DirtySymbol));
    EXPECT_EQ(1, seen(DirtyMacro));
#endif  // _MSC_VER && __MINGW32__
    return true;
  }

protected:
  TestSymbolReporter Reporter;
};

TEST_F(FindAllSymbolsTest, VariableSymbols) {
  static const char Header[] = R"(
      extern int xargc;
      namespace na {
      static bool SSSS = false;
      namespace nb { const long long *XXXX; }
      })";
  static const char Main[] = R"(
      auto y = &na::nb::XXXX;
      int main() { if (na::SSSS) return xargc; }
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("xargc", SymbolInfo::SymbolKind::Variable, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("SSSS", SymbolInfo::SymbolKind::Variable, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("XXXX", SymbolInfo::SymbolKind::Variable, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "nb"},
                       {SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, ExternCSymbols) {
  static const char Header[] = R"(
      extern "C" {
      int C_Func() { return 0; }
      struct C_struct {
        int Member;
      };
      })";
  static const char Main[] = R"(
      C_struct q() {
        int(*ptr)() = C_Func;
        return {0};
      }
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("C_Func", SymbolInfo::SymbolKind::Function, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol =
      SymbolInfo("C_struct", SymbolInfo::SymbolKind::Class, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, CXXRecordSymbols) {
  static const char Header[] = R"(
      struct Glob {};
      struct A; // Not a defintion, ignored.
      class NOP; // Not a defintion, ignored
      namespace na {
      struct A {
        struct AAAA {};
        int x;
        int y;
        void f() {}
      };
      };  //
      )";
  static const char Main[] = R"(
      static Glob glob;
      static na::A::AAAA* a;
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("Glob", SymbolInfo::SymbolKind::Class, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("A", SymbolInfo::SymbolKind::Class, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("AAA", SymbolInfo::SymbolKind::Class, HeaderName,
                      {{SymbolInfo::ContextType::Record, "A"},
                       {SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(0, seen(Symbol));
  EXPECT_EQ(0, used(Symbol));
}

TEST_F(FindAllSymbolsTest, CXXRecordSymbolsTemplate) {
  static const char Header[] = R"(
      template <typename T>
      struct T_TEMP {
        template <typename _Tp1>
        struct rebind { typedef T_TEMP<_Tp1> other; };
      };
      // Ignore specialization.
      template class T_TEMP<char>;

      template <typename T>
      class Observer {
      };
      // Ignore specialization.
      template <> class Observer<int> {};
      )";
  static const char Main[] = R"(
      extern T_TEMP<int>::rebind<char> weirdo;
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("T_TEMP", SymbolInfo::SymbolKind::Class, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, DontIgnoreTemplatePartialSpecialization) {
  static const char Code[] = R"(
      template<class> class Class; // undefined
      template<class R, class... ArgTypes>
      class Class<R(ArgTypes...)> {
      };

      template<class T> void f() {};
      template<> void f<int>() {};
      )";
  runFindAllSymbols(Code, "");
  SymbolInfo Symbol =
      SymbolInfo("Class", SymbolInfo::SymbolKind::Class, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  Symbol = SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
}

TEST_F(FindAllSymbolsTest, FunctionSymbols) {
  static const char Header[] = R"(
      namespace na {
      int gg(int);
      int f(const int &a) { int Local; static int StaticLocal; return 0; }
      static void SSSFFF() {}
      }  // namespace na
      namespace na {
      namespace nb {
      template<typename T>
      void fun(T t) {};
      } // namespace nb
      } // namespace na";
      )";
  static const char Main[] = R"(
      int(*gg)(int) = &na::gg;
      int main() {
        (void)na::SSSFFF;
        na::nb::fun(0);
        return na::f(gg(0));
      }
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("gg", SymbolInfo::SymbolKind::Function, HeaderName,
                 {{SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("SSSFFF", SymbolInfo::SymbolKind::Function, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("fun", SymbolInfo::SymbolKind::Function, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "nb"},
                       {SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, NamespaceTest) {
  static const char Header[] = R"(
      int X1;
      namespace { int X2; }
      namespace { namespace { int X3; } }
      namespace { namespace nb { int X4; } }
      namespace na { inline namespace __1 { int X5; } }
      )";
  static const char Main[] = R"(
      using namespace nb;
      int main() {
        X1 = X2;
        X3 = X4;
        (void)na::X5;
      }
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("X1", SymbolInfo::SymbolKind::Variable, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("X2", SymbolInfo::SymbolKind::Variable, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, ""}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("X3", SymbolInfo::SymbolKind::Variable, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, ""},
                       {SymbolInfo::ContextType::Namespace, ""}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("X4", SymbolInfo::SymbolKind::Variable, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "nb"},
                       {SymbolInfo::ContextType::Namespace, ""}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("X5", SymbolInfo::SymbolKind::Variable, HeaderName,
                      {{SymbolInfo::ContextType::Namespace, "na"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, DecayedTypeTest) {
  static const char Header[] = "void DecayedFunc(int x[], int y[10]) {}";
  static const char Main[] = R"(int main() { DecayedFunc(nullptr, nullptr); })";
  runFindAllSymbols(Header, Main);
  SymbolInfo Symbol = SymbolInfo(
      "DecayedFunc", SymbolInfo::SymbolKind::Function, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, CTypedefTest) {
  static const char Header[] = R"(
      typedef unsigned size_t_;
      typedef struct { int x; } X;
      using XX = X;
      )";
  static const char Main[] = R"(
      size_t_ f;
      template<typename T> struct vector{};
      vector<X> list;
      void foo(const XX&){}
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol = SymbolInfo("size_t_", SymbolInfo::SymbolKind::TypedefName,
                                 HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("X", SymbolInfo::SymbolKind::TypedefName, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol =
      SymbolInfo("XX", SymbolInfo::SymbolKind::TypedefName, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, EnumTest) {
  static const char Header[] = R"(
      enum Glob_E { G1, G2 };
      enum class Altitude { high='h', low='l'};
      enum { A1, A2 };
      class A {
      public:
        enum A_ENUM { X1, X2 };
      };
      enum DECL : int;
      )";
  static const char Main[] = R"(
      static auto flags = G1 | G2;
      static auto alt = Altitude::high;
      static auto nested = A::X1;
      extern DECL whatever;
      static auto flags2 = A1 | A2;
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("Glob_E", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(0, used(Symbol));

  Symbol =
      SymbolInfo("G1", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName,
                 {{SymbolInfo::ContextType::EnumDecl, "Glob_E"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol =
      SymbolInfo("G2", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName,
                 {{SymbolInfo::ContextType::EnumDecl, "Glob_E"}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol =
      SymbolInfo("Altitude", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
  Symbol =
      SymbolInfo("high", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName,
                 {{SymbolInfo::ContextType::EnumDecl, "Altitude"}});
  EXPECT_EQ(0, seen(Symbol));
  EXPECT_EQ(0, used(Symbol));

  Symbol = SymbolInfo("A1", SymbolInfo::SymbolKind::EnumConstantDecl,
                      HeaderName, {{SymbolInfo::ContextType::EnumDecl, ""}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
  Symbol = SymbolInfo("A2", SymbolInfo::SymbolKind::EnumConstantDecl,
                      HeaderName, {{SymbolInfo::ContextType::EnumDecl, ""}});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
  Symbol = SymbolInfo("", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
  EXPECT_EQ(0, seen(Symbol));
  EXPECT_EQ(0, used(Symbol));

  Symbol = SymbolInfo("A_ENUM", SymbolInfo::SymbolKind::EnumDecl, HeaderName,
                      {{SymbolInfo::ContextType::Record, "A"}});
  EXPECT_EQ(0, seen(Symbol));
  EXPECT_EQ(0, used(Symbol));

  Symbol = SymbolInfo("X1", SymbolInfo::SymbolKind::EnumDecl, HeaderName,
                      {{SymbolInfo::ContextType::EnumDecl, "A_ENUM"},
                       {SymbolInfo::ContextType::Record, "A"}});
  EXPECT_EQ(0, seen(Symbol));

  Symbol = SymbolInfo("DECL", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
  EXPECT_EQ(0, seen(Symbol));
}

TEST_F(FindAllSymbolsTest, IWYUPrivatePragmaTest) {
  static const char Header[] = R"(
    // IWYU pragma: private, include "bar.h"
    struct Bar {
    };
  )";
  static const char Main[] = R"(
    Bar bar;
  )";
  runFindAllSymbols(Header, Main);

  SymbolInfo Symbol =
      SymbolInfo("Bar", SymbolInfo::SymbolKind::Class, "bar.h", {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, MacroTest) {
  static const char Header[] = R"(
    #define X
    #define Y 1
    #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
  )";
  static const char Main[] = R"(
    #ifdef X
    int main() { return MAX(0,Y); }
    #endif
  )";
  runFindAllSymbols(Header, Main);
  SymbolInfo Symbol =
      SymbolInfo("X", SymbolInfo::SymbolKind::Macro, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("Y", SymbolInfo::SymbolKind::Macro, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("MAX", SymbolInfo::SymbolKind::Macro, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, MacroTestWithIWYU) {
  static const char Header[] = R"(
    // IWYU pragma: private, include "bar.h"
    #define X 1
    #define Y 1
    #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
  )";
  static const char Main[] = R"(
    #ifdef X
    int main() { return MAX(0,Y); }
    #endif
  )";
  runFindAllSymbols(Header, Main);
  SymbolInfo Symbol =
      SymbolInfo("X", SymbolInfo::SymbolKind::Macro, "bar.h", {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("Y", SymbolInfo::SymbolKind::Macro, "bar.h", {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));

  Symbol = SymbolInfo("MAX", SymbolInfo::SymbolKind::Macro, "bar.h", {});
  EXPECT_EQ(1, seen(Symbol));
  EXPECT_EQ(1, used(Symbol));
}

TEST_F(FindAllSymbolsTest, NoFriendTest) {
  static const char Header[] = R"(
    class WorstFriend {
      friend void Friend();
      friend class BestFriend;
    };
  )";
  runFindAllSymbols(Header, "");
  SymbolInfo Symbol =
      SymbolInfo("WorstFriend", SymbolInfo::SymbolKind::Class, HeaderName, {});
  EXPECT_EQ(1, seen(Symbol));

  Symbol =
      SymbolInfo("Friend", SymbolInfo::SymbolKind::Function, HeaderName, {});
  EXPECT_EQ(0, seen(Symbol));

  Symbol =
      SymbolInfo("BestFriend", SymbolInfo::SymbolKind::Class, HeaderName, {});
  EXPECT_EQ(0, seen(Symbol));
}

} // namespace find_all_symbols
} // namespace clang