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().str());
22 EXPECT_EQ("", T
.getVendorName().str());
23 EXPECT_EQ("", T
.getOSName().str());
24 EXPECT_EQ("", T
.getEnvironmentName().str());
27 EXPECT_EQ("", T
.getArchName().str());
28 EXPECT_EQ("", T
.getVendorName().str());
29 EXPECT_EQ("", T
.getOSName().str());
30 EXPECT_EQ("", T
.getEnvironmentName().str());
33 EXPECT_EQ("", T
.getArchName().str());
34 EXPECT_EQ("", T
.getVendorName().str());
35 EXPECT_EQ("", T
.getOSName().str());
36 EXPECT_EQ("", T
.getEnvironmentName().str());
39 EXPECT_EQ("", T
.getArchName().str());
40 EXPECT_EQ("", T
.getVendorName().str());
41 EXPECT_EQ("", T
.getOSName().str());
42 EXPECT_EQ("", T
.getEnvironmentName().str());
45 EXPECT_EQ("", T
.getArchName().str());
46 EXPECT_EQ("", T
.getVendorName().str());
47 EXPECT_EQ("", T
.getOSName().str());
48 EXPECT_EQ("-", T
.getEnvironmentName().str());
51 EXPECT_EQ("a", T
.getArchName().str());
52 EXPECT_EQ("", T
.getVendorName().str());
53 EXPECT_EQ("", T
.getOSName().str());
54 EXPECT_EQ("", T
.getEnvironmentName().str());
57 EXPECT_EQ("a", T
.getArchName().str());
58 EXPECT_EQ("b", T
.getVendorName().str());
59 EXPECT_EQ("", T
.getOSName().str());
60 EXPECT_EQ("", T
.getEnvironmentName().str());
63 EXPECT_EQ("a", T
.getArchName().str());
64 EXPECT_EQ("b", T
.getVendorName().str());
65 EXPECT_EQ("c", T
.getOSName().str());
66 EXPECT_EQ("", T
.getEnvironmentName().str());
68 T
= Triple("a-b-c-d");
69 EXPECT_EQ("a", T
.getArchName().str());
70 EXPECT_EQ("b", T
.getVendorName().str());
71 EXPECT_EQ("c", T
.getOSName().str());
72 EXPECT_EQ("d", T
.getEnvironmentName().str());
75 TEST(TripleTest
, ParsedIDs
) {
78 T
= Triple("i386-apple-darwin");
79 EXPECT_EQ(Triple::x86
, T
.getArch());
80 EXPECT_EQ(Triple::Apple
, T
.getVendor());
81 EXPECT_EQ(Triple::Darwin
, T
.getOS());
83 T
= Triple("x86_64-pc-linux-gnu");
84 EXPECT_EQ(Triple::x86_64
, T
.getArch());
85 EXPECT_EQ(Triple::PC
, T
.getVendor());
86 EXPECT_EQ(Triple::Linux
, T
.getOS());
88 T
= Triple("powerpc-dunno-notsure");
89 EXPECT_EQ(Triple::ppc
, T
.getArch());
90 EXPECT_EQ(Triple::UnknownVendor
, T
.getVendor());
91 EXPECT_EQ(Triple::UnknownOS
, T
.getOS());
94 EXPECT_EQ(Triple::UnknownArch
, T
.getArch());
96 // Two exceptional cases.
98 T
= Triple("i386-mingw32");
99 EXPECT_EQ(Triple::x86
, T
.getArch());
100 EXPECT_EQ(Triple::PC
, T
.getVendor());
101 EXPECT_EQ(Triple::MinGW32
, T
.getOS());
103 T
= Triple("arm-elf");
104 EXPECT_EQ(Triple::arm
, T
.getArch());
105 EXPECT_EQ(Triple::UnknownVendor
, T
.getVendor());
106 EXPECT_EQ(Triple::UnknownOS
, T
.getOS());
109 TEST(TripleTest
, MutateName
) {
111 EXPECT_EQ(Triple::UnknownArch
, T
.getArch());
112 EXPECT_EQ(Triple::UnknownVendor
, T
.getVendor());
113 EXPECT_EQ(Triple::UnknownOS
, T
.getOS());
115 T
.setArchName("i386");
116 EXPECT_EQ(Triple::x86
, T
.getArch());
117 EXPECT_EQ("i386--", T
.getTriple());
119 T
.setVendorName("pc");
120 EXPECT_EQ(Triple::x86
, T
.getArch());
121 EXPECT_EQ(Triple::PC
, T
.getVendor());
122 EXPECT_EQ("i386-pc-", T
.getTriple());
124 T
.setOSName("linux");
125 EXPECT_EQ(Triple::x86
, T
.getArch());
126 EXPECT_EQ(Triple::PC
, T
.getVendor());
127 EXPECT_EQ(Triple::Linux
, T
.getOS());
128 EXPECT_EQ("i386-pc-linux", T
.getTriple());
130 T
.setEnvironmentName("gnu");
131 EXPECT_EQ(Triple::x86
, T
.getArch());
132 EXPECT_EQ(Triple::PC
, T
.getVendor());
133 EXPECT_EQ(Triple::Linux
, T
.getOS());
134 EXPECT_EQ("i386-pc-linux-gnu", T
.getTriple());
136 T
.setOSName("freebsd");
137 EXPECT_EQ(Triple::x86
, T
.getArch());
138 EXPECT_EQ(Triple::PC
, T
.getVendor());
139 EXPECT_EQ(Triple::FreeBSD
, T
.getOS());
140 EXPECT_EQ("i386-pc-freebsd-gnu", T
.getTriple());
142 T
.setOSAndEnvironmentName("darwin");
143 EXPECT_EQ(Triple::x86
, T
.getArch());
144 EXPECT_EQ(Triple::PC
, T
.getVendor());
145 EXPECT_EQ(Triple::Darwin
, T
.getOS());
146 EXPECT_EQ("i386-pc-darwin", T
.getTriple());