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("a", T
.getArchName());
52 EXPECT_EQ("", T
.getVendorName());
53 EXPECT_EQ("", T
.getOSName());
54 EXPECT_EQ("", T
.getEnvironmentName());
57 EXPECT_EQ("a", T
.getArchName());
58 EXPECT_EQ("b", T
.getVendorName());
59 EXPECT_EQ("", T
.getOSName());
60 EXPECT_EQ("", T
.getEnvironmentName());
63 EXPECT_EQ("a", T
.getArchName());
64 EXPECT_EQ("b", T
.getVendorName());
65 EXPECT_EQ("c", T
.getOSName());
66 EXPECT_EQ("", T
.getEnvironmentName());
68 T
= Triple("a-b-c-d");
69 EXPECT_EQ("a", T
.getArchName());
70 EXPECT_EQ("b", T
.getVendorName());
71 EXPECT_EQ("c", T
.getOSName());
72 EXPECT_EQ("d", T
.getEnvironmentName());
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());
97 TEST(TripleTest
, MutateName
) {
99 EXPECT_EQ(Triple::UnknownArch
, T
.getArch());
100 EXPECT_EQ(Triple::UnknownVendor
, T
.getVendor());
101 EXPECT_EQ(Triple::UnknownOS
, T
.getOS());
103 T
.setArchName("i386");
104 EXPECT_EQ(Triple::x86
, T
.getArch());
105 EXPECT_EQ("i386--", T
.getTriple());
107 T
.setVendorName("pc");
108 EXPECT_EQ(Triple::x86
, T
.getArch());
109 EXPECT_EQ(Triple::PC
, T
.getVendor());
110 EXPECT_EQ("i386-pc-", T
.getTriple());
112 T
.setOSName("linux");
113 EXPECT_EQ(Triple::x86
, T
.getArch());
114 EXPECT_EQ(Triple::PC
, T
.getVendor());
115 EXPECT_EQ(Triple::Linux
, T
.getOS());
116 EXPECT_EQ("i386-pc-linux", T
.getTriple());
118 T
.setEnvironmentName("gnu");
119 EXPECT_EQ(Triple::x86
, T
.getArch());
120 EXPECT_EQ(Triple::PC
, T
.getVendor());
121 EXPECT_EQ(Triple::Linux
, T
.getOS());
122 EXPECT_EQ("i386-pc-linux-gnu", T
.getTriple());
124 T
.setOSName("freebsd");
125 EXPECT_EQ(Triple::x86
, T
.getArch());
126 EXPECT_EQ(Triple::PC
, T
.getVendor());
127 EXPECT_EQ(Triple::FreeBSD
, T
.getOS());
128 EXPECT_EQ("i386-pc-freebsd-gnu", T
.getTriple());
130 T
.setOSAndEnvironmentName("darwin");
131 EXPECT_EQ(Triple::x86
, T
.getArch());
132 EXPECT_EQ(Triple::PC
, T
.getVendor());
133 EXPECT_EQ(Triple::Darwin
, T
.getOS());
134 EXPECT_EQ("i386-pc-darwin", T
.getTriple());