1//===- unittests/InstallAPI/HeaderFile.cpp - HeaderFile Test --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "clang/InstallAPI/HeaderFile.h"
10#include "gtest/gtest.h"
11
12using namespace llvm;
13using namespace clang::installapi;
14
15namespace HeaderFileTests {
16
17TEST(HeaderFile, FrameworkIncludes) {
18 const char *Path = "/System/Library/Frameworks/Foo.framework/Headers/Foo.h";
19 std::optional<std::string> IncludeName = createIncludeHeaderName(FullPath: Path);
20 EXPECT_TRUE(IncludeName.has_value());
21 EXPECT_STREQ(IncludeName.value().c_str(), "Foo/Foo.h");
22
23 Path = "/System/Library/Frameworks/Foo.framework/Frameworks/Bar.framework/"
24 "Headers/SimpleBar.h";
25 IncludeName = createIncludeHeaderName(FullPath: Path);
26 EXPECT_TRUE(IncludeName.has_value());
27 EXPECT_STREQ(IncludeName.value().c_str(), "Bar/SimpleBar.h");
28
29 Path = "/tmp/Foo.framework/Versions/A/Headers/SimpleFoo.h";
30 IncludeName = createIncludeHeaderName(FullPath: Path);
31 EXPECT_TRUE(IncludeName.has_value());
32 EXPECT_STREQ(IncludeName.value().c_str(), "Foo/SimpleFoo.h");
33
34 Path = "/System/Library/PrivateFrameworks/Foo.framework/Headers/Foo.h";
35 IncludeName = createIncludeHeaderName(FullPath: Path);
36 EXPECT_TRUE(IncludeName.has_value());
37 EXPECT_STREQ(IncludeName.value().c_str(), "Foo/Foo.h");
38
39 Path = "/AppleInternal/Developer/Library/Frameworks/"
40 "HelloFramework.framework/Headers/HelloFramework.h";
41 IncludeName = createIncludeHeaderName(FullPath: Path);
42 EXPECT_TRUE(IncludeName.has_value());
43 EXPECT_STREQ(IncludeName.value().c_str(), "HelloFramework/HelloFramework.h");
44
45 Path = "/tmp/BuildProducts/Foo.framework/Versions/A/"
46 "PrivateHeaders/Foo+Private.h";
47 IncludeName = createIncludeHeaderName(FullPath: Path);
48 EXPECT_TRUE(IncludeName.has_value());
49 EXPECT_STREQ(IncludeName.value().c_str(), "Foo/Foo+Private.h");
50
51 Path = "/Applications/Xcode.app/Contents/Developer/SDKS/MacOS.sdk/System/"
52 "Library/Frameworks/Foo.framework/PrivateHeaders/Foo_Private.h";
53 IncludeName = createIncludeHeaderName(FullPath: Path);
54 EXPECT_TRUE(IncludeName.has_value());
55 EXPECT_STREQ(IncludeName.value().c_str(), "Foo/Foo_Private.h");
56
57 Path =
58 "/System/Library/PrivateFrameworks/Foo.framework/PrivateHeaders/Foo.hpp";
59 IncludeName = createIncludeHeaderName(FullPath: Path);
60 EXPECT_TRUE(IncludeName.has_value());
61 EXPECT_STREQ(IncludeName.value().c_str(), "Foo/Foo.hpp");
62
63 Path = "/Applications/Xcode.app/Contents/Developer/SDKS/MacOS.sdk/System/"
64 "Library/Frameworks/Foo.framework/Headers/BarDir/Bar.h";
65 IncludeName = createIncludeHeaderName(FullPath: Path);
66 EXPECT_TRUE(IncludeName.has_value());
67 EXPECT_STREQ(IncludeName.value().c_str(), "Foo/BarDir/Bar.h");
68}
69
70TEST(HeaderFile, DylibIncludes) {
71 const char *Path = "/usr/include/foo.h";
72 std::optional<std::string> IncludeName = createIncludeHeaderName(FullPath: Path);
73 EXPECT_TRUE(IncludeName.has_value());
74 EXPECT_STREQ(IncludeName.value().c_str(), "foo.h");
75
76 Path = "/tmp/BuildProducts/usr/include/a/A.h";
77 IncludeName = createIncludeHeaderName(FullPath: Path);
78 EXPECT_TRUE(IncludeName.has_value());
79 EXPECT_STREQ(IncludeName.value().c_str(), "a/A.h");
80
81 Path = "/Applications/Xcode.app/Contents/Developer/SDKS/MacOS.sdk/"
82 "usr/include/simd/types.h";
83 IncludeName = createIncludeHeaderName(FullPath: Path);
84 EXPECT_TRUE(IncludeName.has_value());
85 EXPECT_STREQ(IncludeName.value().c_str(), "simd/types.h");
86
87 Path = "/usr/local/include/hidden/A.h";
88 IncludeName = createIncludeHeaderName(FullPath: Path);
89 EXPECT_TRUE(IncludeName.has_value());
90 EXPECT_STREQ(IncludeName.value().c_str(), "hidden/A.h");
91}
92} // namespace HeaderFileTests
93

source code of clang/unittests/InstallAPI/HeaderFileTest.cpp