2009-04-01 21:53:23 +00:00
|
|
|
//===----------- Triple.cpp - Triple unit tests ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
TEST(TripleTest, BasicParsing) {
|
|
|
|
Triple T;
|
|
|
|
|
|
|
|
T = Triple("");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("", T.getArchName().str());
|
|
|
|
EXPECT_EQ("", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("", T.getOSName().str());
|
|
|
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("-");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("", T.getArchName().str());
|
|
|
|
EXPECT_EQ("", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("", T.getOSName().str());
|
|
|
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("--");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("", T.getArchName().str());
|
|
|
|
EXPECT_EQ("", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("", T.getOSName().str());
|
|
|
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("---");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("", T.getArchName().str());
|
|
|
|
EXPECT_EQ("", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("", T.getOSName().str());
|
|
|
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("----");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("", T.getArchName().str());
|
|
|
|
EXPECT_EQ("", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("", T.getOSName().str());
|
|
|
|
EXPECT_EQ("-", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("a");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("a", T.getArchName().str());
|
|
|
|
EXPECT_EQ("", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("", T.getOSName().str());
|
|
|
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("a-b");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("a", T.getArchName().str());
|
|
|
|
EXPECT_EQ("b", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("", T.getOSName().str());
|
|
|
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("a-b-c");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("a", T.getArchName().str());
|
|
|
|
EXPECT_EQ("b", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("c", T.getOSName().str());
|
|
|
|
EXPECT_EQ("", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("a-b-c-d");
|
2009-07-26 03:31:47 +00:00
|
|
|
EXPECT_EQ("a", T.getArchName().str());
|
|
|
|
EXPECT_EQ("b", T.getVendorName().str());
|
|
|
|
EXPECT_EQ("c", T.getOSName().str());
|
|
|
|
EXPECT_EQ("d", T.getEnvironmentName().str());
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TripleTest, ParsedIDs) {
|
|
|
|
Triple T;
|
|
|
|
|
|
|
|
T = Triple("i386-apple-darwin");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::Apple, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::Darwin, T.getOS());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("x86_64-pc-linux-gnu");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86_64, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::PC, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::Linux, T.getOS());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("powerpc-dunno-notsure");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::ppc, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::UnknownOS, T.getOS());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T = Triple("huh");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::UnknownArch, T.getArch());
|
2009-08-18 19:26:55 +00:00
|
|
|
|
|
|
|
// Two exceptional cases.
|
|
|
|
|
|
|
|
T = Triple("i386-mingw32");
|
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::PC, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::MinGW32, T.getOS());
|
|
|
|
|
|
|
|
T = Triple("arm-elf");
|
|
|
|
EXPECT_EQ(Triple::arm, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::UnknownOS, T.getOS());
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TripleTest, MutateName) {
|
|
|
|
Triple T;
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::UnknownArch, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::UnknownOS, T.getOS());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T.setArchName("i386");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ("i386--", T.getTriple());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T.setVendorName("pc");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::PC, T.getVendor());
|
|
|
|
EXPECT_EQ("i386-pc-", T.getTriple());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T.setOSName("linux");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::PC, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::Linux, T.getOS());
|
|
|
|
EXPECT_EQ("i386-pc-linux", T.getTriple());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T.setEnvironmentName("gnu");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::PC, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::Linux, T.getOS());
|
|
|
|
EXPECT_EQ("i386-pc-linux-gnu", T.getTriple());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T.setOSName("freebsd");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::PC, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::FreeBSD, T.getOS());
|
|
|
|
EXPECT_EQ("i386-pc-freebsd-gnu", T.getTriple());
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
T.setOSAndEnvironmentName("darwin");
|
2009-06-09 21:48:57 +00:00
|
|
|
EXPECT_EQ(Triple::x86, T.getArch());
|
|
|
|
EXPECT_EQ(Triple::PC, T.getVendor());
|
|
|
|
EXPECT_EQ(Triple::Darwin, T.getOS());
|
|
|
|
EXPECT_EQ("i386-pc-darwin", T.getTriple());
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|