1 //===----------- Triple.cpp - Triple unit tests ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/Triple.h"
17 TEST(TripleTest
, BasicParsing
) {
21 EXPECT_EQ(T
.getArchName(), "");
22 EXPECT_EQ(T
.getVendorName(), "");
23 EXPECT_EQ(T
.getOSName(), "");
24 EXPECT_EQ(T
.getEnvironmentName(), "");
27 EXPECT_EQ(T
.getArchName(), "");
28 EXPECT_EQ(T
.getVendorName(), "");
29 EXPECT_EQ(T
.getOSName(), "");
30 EXPECT_EQ(T
.getEnvironmentName(), "");
33 EXPECT_EQ(T
.getArchName(), "");
34 EXPECT_EQ(T
.getVendorName(), "");
35 EXPECT_EQ(T
.getOSName(), "");
36 EXPECT_EQ(T
.getEnvironmentName(), "");
39 EXPECT_EQ(T
.getArchName(), "");
40 EXPECT_EQ(T
.getVendorName(), "");
41 EXPECT_EQ(T
.getOSName(), "");
42 EXPECT_EQ(T
.getEnvironmentName(), "");
45 EXPECT_EQ(T
.getArchName(), "");
46 EXPECT_EQ(T
.getVendorName(), "");
47 EXPECT_EQ(T
.getOSName(), "");
48 EXPECT_EQ(T
.getEnvironmentName(), "-");
51 EXPECT_EQ(T
.getArchName(), "a");
52 EXPECT_EQ(T
.getVendorName(), "");
53 EXPECT_EQ(T
.getOSName(), "");
54 EXPECT_EQ(T
.getEnvironmentName(), "");
57 EXPECT_EQ(T
.getArchName(), "a");
58 EXPECT_EQ(T
.getVendorName(), "b");
59 EXPECT_EQ(T
.getOSName(), "");
60 EXPECT_EQ(T
.getEnvironmentName(), "");
63 EXPECT_EQ(T
.getArchName(), "a");
64 EXPECT_EQ(T
.getVendorName(), "b");
65 EXPECT_EQ(T
.getOSName(), "c");
66 EXPECT_EQ(T
.getEnvironmentName(), "");
68 T
= Triple("a-b-c-d");
69 EXPECT_EQ(T
.getArchName(), "a");
70 EXPECT_EQ(T
.getVendorName(), "b");
71 EXPECT_EQ(T
.getOSName(), "c");
72 EXPECT_EQ(T
.getEnvironmentName(), "d");
75 TEST(TripleTest
, ParsedIDs
) {
78 T
= Triple("i386-apple-darwin");
79 EXPECT_EQ(T
.getArch(), Triple::x86
);
80 EXPECT_EQ(T
.getVendor(), Triple::Apple
);
81 EXPECT_EQ(T
.getOS(), Triple::Darwin
);
83 T
= Triple("x86_64-pc-linux-gnu");
84 EXPECT_EQ(T
.getArch(), Triple::x86_64
);
85 EXPECT_EQ(T
.getVendor(), Triple::PC
);
86 EXPECT_EQ(T
.getOS(), Triple::Linux
);
88 T
= Triple("powerpc-dunno-notsure");
89 EXPECT_EQ(T
.getArch(), Triple::ppc
);
90 EXPECT_EQ(T
.getVendor(), Triple::UnknownVendor
);
91 EXPECT_EQ(T
.getOS(), Triple::UnknownOS
);
94 EXPECT_EQ(T
.getArch(), Triple::UnknownArch
);
97 TEST(TripleTest
, MutateName
) {
99 EXPECT_EQ(T
.getArch(), Triple::UnknownArch
);
100 EXPECT_EQ(T
.getVendor(), Triple::UnknownVendor
);
101 EXPECT_EQ(T
.getOS(), Triple::UnknownOS
);
103 T
.setArchName("i386");
104 EXPECT_EQ(T
.getArch(), Triple::x86
);
105 EXPECT_EQ(T
.getTriple(), "i386--");
107 T
.setVendorName("pc");
108 EXPECT_EQ(T
.getArch(), Triple::x86
);
109 EXPECT_EQ(T
.getVendor(), Triple::PC
);
110 EXPECT_EQ(T
.getTriple(), "i386-pc-");
112 T
.setOSName("linux");
113 EXPECT_EQ(T
.getArch(), Triple::x86
);
114 EXPECT_EQ(T
.getVendor(), Triple::PC
);
115 EXPECT_EQ(T
.getOS(), Triple::Linux
);
116 EXPECT_EQ(T
.getTriple(), "i386-pc-linux");
118 T
.setEnvironmentName("gnu");
119 EXPECT_EQ(T
.getArch(), Triple::x86
);
120 EXPECT_EQ(T
.getVendor(), Triple::PC
);
121 EXPECT_EQ(T
.getOS(), Triple::Linux
);
122 EXPECT_EQ(T
.getTriple(), "i386-pc-linux-gnu");
124 T
.setOSName("freebsd");
125 EXPECT_EQ(T
.getArch(), Triple::x86
);
126 EXPECT_EQ(T
.getVendor(), Triple::PC
);
127 EXPECT_EQ(T
.getOS(), Triple::FreeBSD
);
128 EXPECT_EQ(T
.getTriple(), "i386-pc-freebsd-gnu");
130 T
.setOSAndEnvironmentName("darwin");
131 EXPECT_EQ(T
.getArch(), Triple::x86
);
132 EXPECT_EQ(T
.getVendor(), Triple::PC
);
133 EXPECT_EQ(T
.getOS(), Triple::Darwin
);
134 EXPECT_EQ(T
.getTriple(), "i386-pc-darwin");