summaryrefslogtreecommitdiffstats
path: root/unittests/Support
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-07-21 00:45:20 -0700
committerStephen Hines <srhines@google.com>2014-07-21 00:45:20 -0700
commitc6a4f5e819217e1e12c458aed8e7b122e23a3a58 (patch)
tree81b7dd2bb4370a392f31d332a566c903b5744764 /unittests/Support
parent19c6fbb3e8aaf74093afa08013134b61fa08f245 (diff)
downloadexternal_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.zip
external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.tar.gz
external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.tar.bz2
Update LLVM for rebase to r212749.
Includes a cherry-pick of: r212948 - fixes a small issue with atomic calls Change-Id: Ib97bd980b59f18142a69506400911a6009d9df18
Diffstat (limited to 'unittests/Support')
-rw-r--r--unittests/Support/CMakeLists.txt3
-rw-r--r--unittests/Support/Casting.cpp8
-rw-r--r--unittests/Support/CommandLineTest.cpp2
-rw-r--r--unittests/Support/ConvertUTFTest.cpp1599
-rw-r--r--unittests/Support/DataExtractorTest.cpp2
-rw-r--r--unittests/Support/ErrorOrTest.cpp11
-rw-r--r--unittests/Support/FileOutputBufferTest.cpp25
-rw-r--r--unittests/Support/LockFileManagerTest.cpp6
-rw-r--r--unittests/Support/ManagedStatic.cpp12
-rw-r--r--unittests/Support/MemoryBufferTest.cpp40
-rw-r--r--unittests/Support/MemoryTest.cpp174
-rw-r--r--unittests/Support/Path.cpp47
-rw-r--r--unittests/Support/ProgramTest.cpp60
-rw-r--r--unittests/Support/ScaledNumberTest.cpp536
-rw-r--r--unittests/Support/SpecialCaseListTest.cpp126
-rw-r--r--unittests/Support/StringPool.cpp31
-rw-r--r--unittests/Support/SwapByteOrderTest.cpp108
-rw-r--r--unittests/Support/ThreadLocalTest.cpp4
-rw-r--r--unittests/Support/TimeValueTest.cpp2
-rw-r--r--unittests/Support/YAMLIOTest.cpp96
-rw-r--r--unittests/Support/raw_ostream_test.cpp4
21 files changed, 2637 insertions, 259 deletions
diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt
index 0ea9310..97c5c43 100644
--- a/unittests/Support/CMakeLists.txt
+++ b/unittests/Support/CMakeLists.txt
@@ -29,7 +29,10 @@ add_llvm_unittest(SupportTests
ProcessTest.cpp
ProgramTest.cpp
RegexTest.cpp
+ ScaledNumberTest.cpp
SourceMgrTest.cpp
+ SpecialCaseListTest.cpp
+ StringPool.cpp
SwapByteOrderTest.cpp
ThreadLocalTest.cpp
TimeValueTest.cpp
diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp
index 228c90b..88c7d19 100644
--- a/unittests/Support/Casting.cpp
+++ b/unittests/Support/Casting.cpp
@@ -18,7 +18,7 @@ namespace llvm {
// Used to test illegal cast. If a cast doesn't match any of the "real" ones,
// it will match this one.
struct IllegalCast;
-template <typename T> IllegalCast *cast(...) { return 0; }
+template <typename T> IllegalCast *cast(...) { return nullptr; }
// set up two example classes
// with conversion facility
@@ -90,7 +90,7 @@ static_assert(std::is_same<simplify_type<foo *>::SimpleType, foo *>::value,
namespace {
-const foo *null_foo = NULL;
+const foo *null_foo = nullptr;
bar B;
extern bar &B1;
@@ -175,7 +175,7 @@ TEST(CastingTest, dyn_cast_or_null) {
const bar *B2 = &B;
} // anonymous namespace
-bar *llvm::fub() { return 0; }
+bar *llvm::fub() { return nullptr; }
namespace {
namespace inferred_upcasting {
@@ -203,7 +203,7 @@ TEST(CastingTest, UpcastIsInferred) {
Derived D;
EXPECT_TRUE(isa<Base>(D));
Base *BP = dyn_cast<Base>(&D);
- EXPECT_TRUE(BP != NULL);
+ EXPECT_TRUE(BP != nullptr);
}
diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp
index b0f1eb1..b2d71ab 100644
--- a/unittests/Support/CommandLineTest.cpp
+++ b/unittests/Support/CommandLineTest.cpp
@@ -23,7 +23,7 @@ class TempEnvVar {
TempEnvVar(const char *name, const char *value)
: name(name) {
const char *old_value = getenv(name);
- EXPECT_EQ(NULL, old_value) << old_value;
+ EXPECT_EQ(nullptr, old_value) << old_value;
#if HAVE_SETENV
setenv(name, value, true);
#else
diff --git a/unittests/Support/ConvertUTFTest.cpp b/unittests/Support/ConvertUTFTest.cpp
index 13ea75b..16c9beb 100644
--- a/unittests/Support/ConvertUTFTest.cpp
+++ b/unittests/Support/ConvertUTFTest.cpp
@@ -10,6 +10,8 @@
#include "llvm/Support/ConvertUTF.h"
#include "gtest/gtest.h"
#include <string>
+#include <vector>
+#include <utility>
using namespace llvm;
@@ -63,3 +65,1600 @@ TEST(ConvertUTFTest, HasUTF16BOM) {
HasBOM = hasUTF16ByteOrderMark(ArrayRef<char>("\xfe", 1));
EXPECT_FALSE(HasBOM);
}
+
+struct ConvertUTFResultContainer {
+ ConversionResult ErrorCode;
+ std::vector<unsigned> UnicodeScalars;
+
+ ConvertUTFResultContainer(ConversionResult ErrorCode)
+ : ErrorCode(ErrorCode) {}
+
+ ConvertUTFResultContainer
+ withScalars(unsigned US0 = 0x110000, unsigned US1 = 0x110000,
+ unsigned US2 = 0x110000, unsigned US3 = 0x110000,
+ unsigned US4 = 0x110000, unsigned US5 = 0x110000,
+ unsigned US6 = 0x110000, unsigned US7 = 0x110000) {
+ ConvertUTFResultContainer Result(*this);
+ if (US0 != 0x110000)
+ Result.UnicodeScalars.push_back(US0);
+ if (US1 != 0x110000)
+ Result.UnicodeScalars.push_back(US1);
+ if (US2 != 0x110000)
+ Result.UnicodeScalars.push_back(US2);
+ if (US3 != 0x110000)
+ Result.UnicodeScalars.push_back(US3);
+ if (US4 != 0x110000)
+ Result.UnicodeScalars.push_back(US4);
+ if (US5 != 0x110000)
+ Result.UnicodeScalars.push_back(US5);
+ if (US6 != 0x110000)
+ Result.UnicodeScalars.push_back(US6);
+ if (US7 != 0x110000)
+ Result.UnicodeScalars.push_back(US7);
+ return Result;
+ }
+};
+
+std::pair<ConversionResult, std::vector<unsigned>>
+ConvertUTF8ToUnicodeScalarsLenient(StringRef S) {
+ const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data());
+
+ const UTF8 *SourceNext = SourceStart;
+ std::vector<UTF32> Decoded(S.size(), 0);
+ UTF32 *TargetStart = Decoded.data();
+
+ auto ErrorCode =
+ ConvertUTF8toUTF32(&SourceNext, SourceStart + S.size(), &TargetStart,
+ Decoded.data() + Decoded.size(), lenientConversion);
+
+ Decoded.resize(TargetStart - Decoded.data());
+
+ return std::make_pair(ErrorCode, Decoded);
+}
+
+std::pair<ConversionResult, std::vector<unsigned>>
+ConvertUTF8ToUnicodeScalarsPartialLenient(StringRef S) {
+ const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data());
+
+ const UTF8 *SourceNext = SourceStart;
+ std::vector<UTF32> Decoded(S.size(), 0);
+ UTF32 *TargetStart = Decoded.data();
+
+ auto ErrorCode = ConvertUTF8toUTF32Partial(
+ &SourceNext, SourceStart + S.size(), &TargetStart,
+ Decoded.data() + Decoded.size(), lenientConversion);
+
+ Decoded.resize(TargetStart - Decoded.data());
+
+ return std::make_pair(ErrorCode, Decoded);
+}
+
+::testing::AssertionResult
+CheckConvertUTF8ToUnicodeScalars(ConvertUTFResultContainer Expected,
+ StringRef S, bool Partial = false) {
+ ConversionResult ErrorCode;
+ std::vector<unsigned> Decoded;
+ if (!Partial)
+ std::tie(ErrorCode, Decoded) = ConvertUTF8ToUnicodeScalarsLenient(S);
+ else
+
+ std::tie(ErrorCode, Decoded) = ConvertUTF8ToUnicodeScalarsPartialLenient(S);
+ if (Expected.ErrorCode != ErrorCode)
+ return ::testing::AssertionFailure() << "Expected error code "
+ << Expected.ErrorCode << ", actual "
+ << ErrorCode;
+
+ if (Expected.UnicodeScalars != Decoded)
+ return ::testing::AssertionFailure()
+ << "Expected lenient decoded result:\n"
+ << ::testing::PrintToString(Expected.UnicodeScalars) << "\n"
+ << "Actual result:\n" << ::testing::PrintToString(Decoded);
+
+ return ::testing::AssertionSuccess();
+}
+
+TEST(ConvertUTFTest, UTF8ToUTF32Lenient) {
+
+ //
+ // 1-byte sequences
+ //
+
+ // U+0041 LATIN CAPITAL LETTER A
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x0041), "\x41"));
+
+ //
+ // 2-byte sequences
+ //
+
+ // U+0283 LATIN SMALL LETTER ESH
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x0283),
+ "\xca\x83"));
+
+ // U+03BA GREEK SMALL LETTER KAPPA
+ // U+1F79 GREEK SMALL LETTER OMICRON WITH OXIA
+ // U+03C3 GREEK SMALL LETTER SIGMA
+ // U+03BC GREEK SMALL LETTER MU
+ // U+03B5 GREEK SMALL LETTER EPSILON
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK)
+ .withScalars(0x03ba, 0x1f79, 0x03c3, 0x03bc, 0x03b5),
+ "\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5"));
+
+ //
+ // 3-byte sequences
+ //
+
+ // U+4F8B CJK UNIFIED IDEOGRAPH-4F8B
+ // U+6587 CJK UNIFIED IDEOGRAPH-6587
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x4f8b, 0x6587),
+ "\xe4\xbe\x8b\xe6\x96\x87"));
+
+ // U+D55C HANGUL SYLLABLE HAN
+ // U+AE00 HANGUL SYLLABLE GEUL
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xd55c, 0xae00),
+ "\xed\x95\x9c\xea\xb8\x80"));
+
+ // U+1112 HANGUL CHOSEONG HIEUH
+ // U+1161 HANGUL JUNGSEONG A
+ // U+11AB HANGUL JONGSEONG NIEUN
+ // U+1100 HANGUL CHOSEONG KIYEOK
+ // U+1173 HANGUL JUNGSEONG EU
+ // U+11AF HANGUL JONGSEONG RIEUL
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK)
+ .withScalars(0x1112, 0x1161, 0x11ab, 0x1100, 0x1173, 0x11af),
+ "\xe1\x84\x92\xe1\x85\xa1\xe1\x86\xab\xe1\x84\x80\xe1\x85\xb3"
+ "\xe1\x86\xaf"));
+
+ //
+ // 4-byte sequences
+ //
+
+ // U+E0100 VARIATION SELECTOR-17
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x000E0100),
+ "\xf3\xa0\x84\x80"));
+
+ //
+ // First possible sequence of a certain length
+ //
+
+ // U+0000 NULL
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x0000),
+ StringRef("\x00", 1)));
+
+ // U+0080 PADDING CHARACTER
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x0080),
+ "\xc2\x80"));
+
+ // U+0800 SAMARITAN LETTER ALAF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x0800),
+ "\xe0\xa0\x80"));
+
+ // U+10000 LINEAR B SYLLABLE B008 A
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x10000),
+ "\xf0\x90\x80\x80"));
+
+ // U+200000 (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x88\x80\x80\x80"));
+
+ // U+4000000 (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x84\x80\x80\x80\x80"));
+
+ //
+ // Last possible sequence of a certain length
+ //
+
+ // U+007F DELETE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x007f), "\x7f"));
+
+ // U+07FF (unassigned)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x07ff),
+ "\xdf\xbf"));
+
+ // U+FFFF (noncharacter)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xffff),
+ "\xef\xbf\xbf"));
+
+ // U+1FFFFF (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf7\xbf\xbf\xbf"));
+
+ // U+3FFFFFF (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfb\xbf\xbf\xbf\xbf"));
+
+ // U+7FFFFFFF (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfd\xbf\xbf\xbf\xbf\xbf"));
+
+ //
+ // Other boundary conditions
+ //
+
+ // U+D7FF (unassigned)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xd7ff),
+ "\xed\x9f\xbf"));
+
+ // U+E000 (private use)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xe000),
+ "\xee\x80\x80"));
+
+ // U+FFFD REPLACEMENT CHARACTER
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfffd),
+ "\xef\xbf\xbd"));
+
+ // U+10FFFF (noncharacter)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x10ffff),
+ "\xf4\x8f\xbf\xbf"));
+
+ // U+110000 (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf4\x90\x80\x80"));
+
+ //
+ // Unexpected continuation bytes
+ //
+
+ // A sequence of unexpected continuation bytes that don't follow a first
+ // byte, every byte is a maximal subpart.
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\x80\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xbf\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\x80\xbf\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\x80\xbf\x80\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\x80\xbf\x82\xbf\xaa"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xaa\xb0\xbb\xbf\xaa\xa0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xaa\xb0\xbb\xbf\xaa\xa0\x8f"));
+
+ // All continuation bytes (0x80--0xbf).
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
+ "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
+ "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
+ "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"));
+
+ //
+ // Lonely start bytes
+ //
+
+ // Start bytes of 2-byte sequences (0xc0--0xdf).
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
+ "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020),
+ "\xc0\x20\xc1\x20\xc2\x20\xc3\x20\xc4\x20\xc5\x20\xc6\x20\xc7\x20"
+ "\xc8\x20\xc9\x20\xca\x20\xcb\x20\xcc\x20\xcd\x20\xce\x20\xcf\x20"
+ "\xd0\x20\xd1\x20\xd2\x20\xd3\x20\xd4\x20\xd5\x20\xd6\x20\xd7\x20"
+ "\xd8\x20\xd9\x20\xda\x20\xdb\x20\xdc\x20\xdd\x20\xde\x20\xdf\x20"));
+
+ // Start bytes of 3-byte sequences (0xe0--0xef).
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020),
+ "\xe0\x20\xe1\x20\xe2\x20\xe3\x20\xe4\x20\xe5\x20\xe6\x20\xe7\x20"
+ "\xe8\x20\xe9\x20\xea\x20\xeb\x20\xec\x20\xed\x20\xee\x20\xef\x20"));
+
+ // Start bytes of 4-byte sequences (0xf0--0xf7).
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020),
+ "\xf0\x20\xf1\x20\xf2\x20\xf3\x20\xf4\x20\xf5\x20\xf6\x20\xf7\x20"));
+
+ // Start bytes of 5-byte sequences (0xf8--0xfb).
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\xf9\xfa\xfb"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020),
+ "\xf8\x20\xf9\x20\xfa\x20\xfb\x20"));
+
+ // Start bytes of 6-byte sequences (0xfc--0xfd).
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfc\xfd"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020),
+ "\xfc\x20\xfd\x20"));
+
+ //
+ // Other bytes (0xc0--0xc1, 0xfe--0xff).
+ //
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xc0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xc1"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfe"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xff"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xc0\xc1\xfe\xff"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfe\xfe\xff\xff"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfe\x80\x80\x80\x80\x80"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xff\x80\x80\x80\x80\x80"));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020,
+ 0xfffd, 0x0020, 0xfffd, 0x0020),
+ "\xc0\x20\xc1\x20\xfe\x20\xff\x20"));
+
+ //
+ // Sequences with one continuation byte missing
+ //
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xc2"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xdf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xe0\xa0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xe0\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xe1\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xec\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xed\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xed\x9f"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xee\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xef\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf0\x90\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf0\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf1\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf3\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf4\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf4\x8f\xbf"));
+
+ // Overlong sequences with one trailing byte missing.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xc0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xc1"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xe0\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xe0\x9f"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf0\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf0\x8f\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x80\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x80\x80\x80\x80"));
+
+ // Sequences that represent surrogates with one trailing byte missing.
+ // High surrogates
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xed\xa0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xed\xac"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xed\xaf"));
+ // Low surrogates
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xed\xb0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xed\xb4"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xed\xbf"));
+
+ // Ill-formed 4-byte sequences.
+ // 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+1100xx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf4\x90\x80"));
+ // U+13FBxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf4\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf5\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf6\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf7\x80\x80"));
+ // U+1FFBxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf7\xbf\xbf"));
+
+ // Ill-formed 5-byte sequences.
+ // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+2000xx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x88\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\xbf\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf9\x80\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfa\x80\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfb\x80\x80\x80"));
+ // U+3FFFFxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfb\xbf\xbf\xbf"));
+
+ // Ill-formed 6-byte sequences.
+ // 1111110u 10uuuuuu 10uzzzzz 10zzzyyyy 10yyyyxx 10xxxxxx
+ // U+40000xx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x84\x80\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\xbf\xbf\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfd\x80\x80\x80\x80"));
+ // U+7FFFFFxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfd\xbf\xbf\xbf\xbf"));
+
+ //
+ // Sequences with two continuation bytes missing
+ //
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf0\x90"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf0\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf1\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf3\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf4\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd),
+ "\xf4\x8f"));
+
+ // Overlong sequences with two trailing byte missing.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xe0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf0\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf0\x8f"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x80\x80\x80"));
+
+ // Sequences that represent surrogates with two trailing bytes missing.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xed"));
+
+ // Ill-formed 4-byte sequences.
+ // 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+110yxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf4\x90"));
+ // U+13Fyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf4\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf5\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf6\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf7\x80"));
+ // U+1FFyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf7\xbf"));
+
+ // Ill-formed 5-byte sequences.
+ // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+200yxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x88\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf8\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xf9\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfa\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfb\x80\x80"));
+ // U+3FFFyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfb\xbf\xbf"));
+
+ // Ill-formed 6-byte sequences.
+ // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+4000yxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x84\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\xbf\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfd\x80\x80\x80"));
+ // U+7FFFFyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfd\xbf\xbf\xbf"));
+
+ //
+ // Sequences with three continuation bytes missing
+ //
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf1"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf2"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf3"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf4"));
+
+ // Broken overlong sequences.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf0"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf8\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x80\x80"));
+
+ // Ill-formed 4-byte sequences.
+ // 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+14yyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf5"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf6"));
+ // U+1Cyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf7"));
+
+ // Ill-formed 5-byte sequences.
+ // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+20yyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf8\x88"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf8\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xf9\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfa\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfb\x80"));
+ // U+3FCyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfb\xbf"));
+
+ // Ill-formed 6-byte sequences.
+ // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+400yyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x84\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfc\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfd\x80\x80"));
+ // U+7FFCyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xfd\xbf\xbf"));
+
+ //
+ // Sequences with four continuation bytes missing
+ //
+
+ // Ill-formed 5-byte sequences.
+ // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+uzyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf8"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf9"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfa"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfb"));
+ // U+3zyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfb"));
+
+ // Broken overlong sequences.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf8"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfc\x80"));
+
+ // Ill-formed 6-byte sequences.
+ // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+uzzyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfc\x84"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfc\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfd\x80"));
+ // U+7Fzzyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xfd\xbf"));
+
+ //
+ // Sequences with five continuation bytes missing
+ //
+
+ // Ill-formed 6-byte sequences.
+ // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx
+ // U+uzzyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfc"));
+ // U+uuzzyyxx (invalid)
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfd"));
+
+ //
+ // Consecutive sequences with trailing bytes missing
+ //
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, /**/ 0xfffd, 0xfffd, /**/ 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, /**/ 0xfffd, /**/ 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xc0" "\xe0\x80" "\xf0\x80\x80"
+ "\xf8\x80\x80\x80"
+ "\xfc\x80\x80\x80\x80"
+ "\xdf" "\xef\xbf" "\xf7\xbf\xbf"
+ "\xfb\xbf\xbf\xbf"
+ "\xfd\xbf\xbf\xbf\xbf"));
+
+ //
+ // Overlong UTF-8 sequences
+ //
+
+ // U+002F SOLIDUS
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x002f), "\x2f"));
+
+ // Overlong sequences of the above.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xc0\xaf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xe0\x80\xaf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf0\x80\x80\xaf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x80\x80\x80\xaf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x80\x80\x80\x80\xaf"));
+
+ // U+0000 NULL
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x0000),
+ StringRef("\x00", 1)));
+
+ // Overlong sequences of the above.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xc0\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xe0\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf0\x80\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x80\x80\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x80\x80\x80\x80\x80"));
+
+ // Other overlong sequences.
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xc0\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xc1\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd),
+ "\xc1\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xe0\x9f\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xa0\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf0\x8f\x80\x80"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf0\x8f\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xf8\x87\xbf\xbf\xbf"));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xfc\x83\xbf\xbf\xbf\xbf"));
+
+ //
+ // Isolated surrogates
+ //
+
+ // Unicode 6.3.0:
+ //
+ // D71. High-surrogate code point: A Unicode code point in the range
+ // U+D800 to U+DBFF.
+ //
+ // D73. Low-surrogate code point: A Unicode code point in the range
+ // U+DC00 to U+DFFF.
+
+ // Note: U+E0100 is <DB40 DD00> in UTF16.
+
+ // High surrogates
+
+ // U+D800
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xa0\x80"));
+
+ // U+DB40
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xac\xa0"));
+
+ // U+DBFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xaf\xbf"));
+
+ // Low surrogates
+
+ // U+DC00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xb0\x80"));
+
+ // U+DD00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xb4\x80"));
+
+ // U+DFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd),
+ "\xed\xbf\xbf"));
+
+ // Surrogate pairs
+
+ // U+D800 U+DC00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xa0\x80\xed\xb0\x80"));
+
+ // U+D800 U+DD00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xa0\x80\xed\xb4\x80"));
+
+ // U+D800 U+DFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xa0\x80\xed\xbf\xbf"));
+
+ // U+DB40 U+DC00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xac\xa0\xed\xb0\x80"));
+
+ // U+DB40 U+DD00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xac\xa0\xed\xb4\x80"));
+
+ // U+DB40 U+DFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xac\xa0\xed\xbf\xbf"));
+
+ // U+DBFF U+DC00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xaf\xbf\xed\xb0\x80"));
+
+ // U+DBFF U+DD00
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xaf\xbf\xed\xb4\x80"));
+
+ // U+DBFF U+DFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceIllegal)
+ .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd),
+ "\xed\xaf\xbf\xed\xbf\xbf"));
+
+ //
+ // Noncharacters
+ //
+
+ // Unicode 6.3.0:
+ //
+ // D14. Noncharacter: A code point that is permanently reserved for
+ // internal use and that should never be interchanged. Noncharacters
+ // consist of the values U+nFFFE and U+nFFFF (where n is from 0 to 1016)
+ // and the values U+FDD0..U+FDEF.
+
+ // U+FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfffe),
+ "\xef\xbf\xbe"));
+
+ // U+FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xffff),
+ "\xef\xbf\xbf"));
+
+ // U+1FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x1fffe),
+ "\xf0\x9f\xbf\xbe"));
+
+ // U+1FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x1ffff),
+ "\xf0\x9f\xbf\xbf"));
+
+ // U+2FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x2fffe),
+ "\xf0\xaf\xbf\xbe"));
+
+ // U+2FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x2ffff),
+ "\xf0\xaf\xbf\xbf"));
+
+ // U+3FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x3fffe),
+ "\xf0\xbf\xbf\xbe"));
+
+ // U+3FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x3ffff),
+ "\xf0\xbf\xbf\xbf"));
+
+ // U+4FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x4fffe),
+ "\xf1\x8f\xbf\xbe"));
+
+ // U+4FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x4ffff),
+ "\xf1\x8f\xbf\xbf"));
+
+ // U+5FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x5fffe),
+ "\xf1\x9f\xbf\xbe"));
+
+ // U+5FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x5ffff),
+ "\xf1\x9f\xbf\xbf"));
+
+ // U+6FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x6fffe),
+ "\xf1\xaf\xbf\xbe"));
+
+ // U+6FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x6ffff),
+ "\xf1\xaf\xbf\xbf"));
+
+ // U+7FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x7fffe),
+ "\xf1\xbf\xbf\xbe"));
+
+ // U+7FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x7ffff),
+ "\xf1\xbf\xbf\xbf"));
+
+ // U+8FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x8fffe),
+ "\xf2\x8f\xbf\xbe"));
+
+ // U+8FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x8ffff),
+ "\xf2\x8f\xbf\xbf"));
+
+ // U+9FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x9fffe),
+ "\xf2\x9f\xbf\xbe"));
+
+ // U+9FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x9ffff),
+ "\xf2\x9f\xbf\xbf"));
+
+ // U+AFFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xafffe),
+ "\xf2\xaf\xbf\xbe"));
+
+ // U+AFFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xaffff),
+ "\xf2\xaf\xbf\xbf"));
+
+ // U+BFFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xbfffe),
+ "\xf2\xbf\xbf\xbe"));
+
+ // U+BFFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xbffff),
+ "\xf2\xbf\xbf\xbf"));
+
+ // U+CFFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xcfffe),
+ "\xf3\x8f\xbf\xbe"));
+
+ // U+CFFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xcfffF),
+ "\xf3\x8f\xbf\xbf"));
+
+ // U+DFFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xdfffe),
+ "\xf3\x9f\xbf\xbe"));
+
+ // U+DFFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xdffff),
+ "\xf3\x9f\xbf\xbf"));
+
+ // U+EFFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xefffe),
+ "\xf3\xaf\xbf\xbe"));
+
+ // U+EFFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xeffff),
+ "\xf3\xaf\xbf\xbf"));
+
+ // U+FFFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xffffe),
+ "\xf3\xbf\xbf\xbe"));
+
+ // U+FFFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfffff),
+ "\xf3\xbf\xbf\xbf"));
+
+ // U+10FFFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x10fffe),
+ "\xf4\x8f\xbf\xbe"));
+
+ // U+10FFFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x10ffff),
+ "\xf4\x8f\xbf\xbf"));
+
+ // U+FDD0
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd0),
+ "\xef\xb7\x90"));
+
+ // U+FDD1
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd1),
+ "\xef\xb7\x91"));
+
+ // U+FDD2
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd2),
+ "\xef\xb7\x92"));
+
+ // U+FDD3
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd3),
+ "\xef\xb7\x93"));
+
+ // U+FDD4
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd4),
+ "\xef\xb7\x94"));
+
+ // U+FDD5
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd5),
+ "\xef\xb7\x95"));
+
+ // U+FDD6
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd6),
+ "\xef\xb7\x96"));
+
+ // U+FDD7
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd7),
+ "\xef\xb7\x97"));
+
+ // U+FDD8
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd8),
+ "\xef\xb7\x98"));
+
+ // U+FDD9
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdd9),
+ "\xef\xb7\x99"));
+
+ // U+FDDA
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdda),
+ "\xef\xb7\x9a"));
+
+ // U+FDDB
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfddb),
+ "\xef\xb7\x9b"));
+
+ // U+FDDC
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfddc),
+ "\xef\xb7\x9c"));
+
+ // U+FDDD
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfddd),
+ "\xef\xb7\x9d"));
+
+ // U+FDDE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdde),
+ "\xef\xb7\x9e"));
+
+ // U+FDDF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfddf),
+ "\xef\xb7\x9f"));
+
+ // U+FDE0
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde0),
+ "\xef\xb7\xa0"));
+
+ // U+FDE1
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde1),
+ "\xef\xb7\xa1"));
+
+ // U+FDE2
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde2),
+ "\xef\xb7\xa2"));
+
+ // U+FDE3
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde3),
+ "\xef\xb7\xa3"));
+
+ // U+FDE4
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde4),
+ "\xef\xb7\xa4"));
+
+ // U+FDE5
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde5),
+ "\xef\xb7\xa5"));
+
+ // U+FDE6
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde6),
+ "\xef\xb7\xa6"));
+
+ // U+FDE7
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde7),
+ "\xef\xb7\xa7"));
+
+ // U+FDE8
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde8),
+ "\xef\xb7\xa8"));
+
+ // U+FDE9
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfde9),
+ "\xef\xb7\xa9"));
+
+ // U+FDEA
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdea),
+ "\xef\xb7\xaa"));
+
+ // U+FDEB
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdeb),
+ "\xef\xb7\xab"));
+
+ // U+FDEC
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdec),
+ "\xef\xb7\xac"));
+
+ // U+FDED
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfded),
+ "\xef\xb7\xad"));
+
+ // U+FDEE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdee),
+ "\xef\xb7\xae"));
+
+ // U+FDEF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdef),
+ "\xef\xb7\xaf"));
+
+ // U+FDF0
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf0),
+ "\xef\xb7\xb0"));
+
+ // U+FDF1
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf1),
+ "\xef\xb7\xb1"));
+
+ // U+FDF2
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf2),
+ "\xef\xb7\xb2"));
+
+ // U+FDF3
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf3),
+ "\xef\xb7\xb3"));
+
+ // U+FDF4
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf4),
+ "\xef\xb7\xb4"));
+
+ // U+FDF5
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf5),
+ "\xef\xb7\xb5"));
+
+ // U+FDF6
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf6),
+ "\xef\xb7\xb6"));
+
+ // U+FDF7
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf7),
+ "\xef\xb7\xb7"));
+
+ // U+FDF8
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf8),
+ "\xef\xb7\xb8"));
+
+ // U+FDF9
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdf9),
+ "\xef\xb7\xb9"));
+
+ // U+FDFA
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdfa),
+ "\xef\xb7\xba"));
+
+ // U+FDFB
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdfb),
+ "\xef\xb7\xbb"));
+
+ // U+FDFC
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdfc),
+ "\xef\xb7\xbc"));
+
+ // U+FDFD
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdfd),
+ "\xef\xb7\xbd"));
+
+ // U+FDFE
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdfe),
+ "\xef\xb7\xbe"));
+
+ // U+FDFF
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0xfdff),
+ "\xef\xb7\xbf"));
+}
+
+TEST(ConvertUTFTest, UTF8ToUTF32PartialLenient) {
+ // U+0041 LATIN CAPITAL LETTER A
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(conversionOK).withScalars(0x0041),
+ "\x41", true));
+
+ //
+ // Sequences with one continuation byte missing
+ //
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xc2", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xdf", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xe0\xa0", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xe0\xbf", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xe1\x80", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xec\xbf", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xed\x80", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xed\x9f", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xee\x80", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xef\xbf", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xf0\x90\x80", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xf0\xbf\xbf", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xf1\x80\x80", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xf3\xbf\xbf", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xf4\x80\x80", true));
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted),
+ "\xf4\x8f\xbf", true));
+
+ EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
+ ConvertUTFResultContainer(sourceExhausted).withScalars(0x0041),
+ "\x41\xc2", true));
+}
+
diff --git a/unittests/Support/DataExtractorTest.cpp b/unittests/Support/DataExtractorTest.cpp
index ec8bd3d..81de983 100644
--- a/unittests/Support/DataExtractorTest.cpp
+++ b/unittests/Support/DataExtractorTest.cpp
@@ -94,7 +94,7 @@ TEST(DataExtractorTest, Strings) {
EXPECT_EQ(stringData, DE.getCStr(&offset));
EXPECT_EQ(11U, offset);
- EXPECT_EQ(NULL, DE.getCStr(&offset));
+ EXPECT_EQ(nullptr, DE.getCStr(&offset));
EXPECT_EQ(11U, offset);
}
diff --git a/unittests/Support/ErrorOrTest.cpp b/unittests/Support/ErrorOrTest.cpp
index 18ce507..d76e7d6 100644
--- a/unittests/Support/ErrorOrTest.cpp
+++ b/unittests/Support/ErrorOrTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/Errc.h"
#include "gtest/gtest.h"
#include <memory>
@@ -30,7 +31,7 @@ TEST(ErrorOr, SimpleValue) {
a = t2();
EXPECT_FALSE(a);
- EXPECT_EQ(errc::invalid_argument, a.getError());
+ EXPECT_EQ(a.getError(), errc::invalid_argument);
#ifdef EXPECT_DEBUG_DEATH
EXPECT_DEBUG_DEATH(*a, "Cannot get value when an error exists");
#endif
@@ -54,10 +55,10 @@ struct B {};
struct D : B {};
TEST(ErrorOr, Covariant) {
- ErrorOr<B*> b(ErrorOr<D*>(0));
- b = ErrorOr<D*>(0);
+ ErrorOr<B*> b(ErrorOr<D*>(nullptr));
+ b = ErrorOr<D*>(nullptr);
- ErrorOr<std::unique_ptr<B> > b1(ErrorOr<std::unique_ptr<D> >(0));
- b1 = ErrorOr<std::unique_ptr<D> >(0);
+ ErrorOr<std::unique_ptr<B> > b1(ErrorOr<std::unique_ptr<D> >(nullptr));
+ b1 = ErrorOr<std::unique_ptr<D> >(nullptr);
}
} // end anon namespace
diff --git a/unittests/Support/FileOutputBufferTest.cpp b/unittests/Support/FileOutputBufferTest.cpp
index 0801f85..b086f1e 100644
--- a/unittests/Support/FileOutputBufferTest.cpp
+++ b/unittests/Support/FileOutputBufferTest.cpp
@@ -17,12 +17,13 @@
using namespace llvm;
using namespace llvm::sys;
-#define ASSERT_NO_ERROR(x) \
- if (error_code ASSERT_NO_ERROR_ec = x) { \
- errs() << #x ": did not return errc::success.\n" \
- << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
- << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
- } else {}
+#define ASSERT_NO_ERROR(x) \
+ if (std::error_code ASSERT_NO_ERROR_ec = x) { \
+ errs() << #x ": did not return errc::success.\n" \
+ << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
+ << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
+ } else { \
+ }
namespace {
TEST(FileOutputBuffer, Test) {
@@ -46,11 +47,7 @@ TEST(FileOutputBuffer, Test) {
// Commit buffer.
ASSERT_NO_ERROR(Buffer->commit());
}
- // Verify file exists and starts with special header.
- bool MagicMatches = false;
- ASSERT_NO_ERROR(fs::has_magic(Twine(File1), Twine("AABBCCDDEEFFGGHHIIJJ"),
- MagicMatches));
- EXPECT_TRUE(MagicMatches);
+
// Verify file is correct size.
uint64_t File1Size;
ASSERT_NO_ERROR(fs::file_size(Twine(File1), File1Size));
@@ -86,11 +83,7 @@ TEST(FileOutputBuffer, Test) {
// Commit buffer, but size down to smaller size
ASSERT_NO_ERROR(Buffer->commit(5000));
}
- // Verify file exists and starts with special header.
- bool MagicMatches3 = false;
- ASSERT_NO_ERROR(fs::has_magic(Twine(File3), Twine("AABBCCDDEEFFGGHHIIJJ"),
- MagicMatches3));
- EXPECT_TRUE(MagicMatches3);
+
// Verify file is correct size.
uint64_t File3Size;
ASSERT_NO_ERROR(fs::file_size(Twine(File3), File3Size));
diff --git a/unittests/Support/LockFileManagerTest.cpp b/unittests/Support/LockFileManagerTest.cpp
index 93fa10b..885b7d6 100644
--- a/unittests/Support/LockFileManagerTest.cpp
+++ b/unittests/Support/LockFileManagerTest.cpp
@@ -19,7 +19,7 @@ namespace {
TEST(LockFileManagerTest, Basic) {
SmallString<64> TmpDir;
- error_code EC;
+ std::error_code EC;
EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
ASSERT_FALSE(EC);
@@ -46,7 +46,7 @@ TEST(LockFileManagerTest, Basic) {
TEST(LockFileManagerTest, LinkLockExists) {
SmallString<64> TmpDir;
- error_code EC;
+ std::error_code EC;
EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
ASSERT_FALSE(EC);
@@ -89,7 +89,7 @@ TEST(LockFileManagerTest, LinkLockExists) {
TEST(LockFileManagerTest, RelativePath) {
SmallString<64> TmpDir;
- error_code EC;
+ std::error_code EC;
EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
ASSERT_FALSE(EC);
diff --git a/unittests/Support/ManagedStatic.cpp b/unittests/Support/ManagedStatic.cpp
index 1497f4e..153884b 100644
--- a/unittests/Support/ManagedStatic.cpp
+++ b/unittests/Support/ManagedStatic.cpp
@@ -25,7 +25,7 @@ namespace test1 {
llvm::ManagedStatic<int> ms;
void *helper(void*) {
*ms;
- return NULL;
+ return nullptr;
}
// Valgrind's leak checker complains glibc's stack allocation.
@@ -47,15 +47,13 @@ TEST(Initialize, MultipleThreads) {
void *p1 = test1::allocate_stack(a1);
void *p2 = test1::allocate_stack(a2);
- llvm_start_multithreaded();
pthread_t t1, t2;
- pthread_create(&t1, &a1, test1::helper, NULL);
- pthread_create(&t2, &a2, test1::helper, NULL);
- pthread_join(t1, NULL);
- pthread_join(t2, NULL);
+ pthread_create(&t1, &a1, test1::helper, nullptr);
+ pthread_create(&t2, &a2, test1::helper, nullptr);
+ pthread_join(t1, nullptr);
+ pthread_join(t2, nullptr);
free(p1);
free(p2);
- llvm_stop_multithreaded();
}
#endif
diff --git a/unittests/Support/MemoryBufferTest.cpp b/unittests/Support/MemoryBufferTest.cpp
index 6790d0c..93bf301 100644
--- a/unittests/Support/MemoryBufferTest.cpp
+++ b/unittests/Support/MemoryBufferTest.cpp
@@ -43,15 +43,15 @@ protected:
TEST_F(MemoryBufferTest, get) {
// Default name and null-terminator flag
OwningBuffer MB1(MemoryBuffer::getMemBuffer(data));
- EXPECT_TRUE(0 != MB1.get());
+ EXPECT_TRUE(nullptr != MB1.get());
// RequiresNullTerminator = false
OwningBuffer MB2(MemoryBuffer::getMemBuffer(data, "one", false));
- EXPECT_TRUE(0 != MB2.get());
+ EXPECT_TRUE(nullptr != MB2.get());
// RequiresNullTerminator = true
OwningBuffer MB3(MemoryBuffer::getMemBuffer(data, "two", true));
- EXPECT_TRUE(0 != MB3.get());
+ EXPECT_TRUE(nullptr != MB3.get());
// verify all 3 buffers point to the same address
EXPECT_EQ(MB1->getBufferStart(), MB2->getBufferStart());
@@ -77,11 +77,11 @@ TEST_F(MemoryBufferTest, NullTerminator4K) {
}
OF.close();
- OwningBuffer MB;
- error_code EC = MemoryBuffer::getFile(TestPath.c_str(), MB);
+ ErrorOr<OwningBuffer> MB = MemoryBuffer::getFile(TestPath.c_str());
+ std::error_code EC = MB.getError();
ASSERT_FALSE(EC);
- const char *BufData = MB->getBufferStart();
+ const char *BufData = MB.get()->getBufferStart();
EXPECT_EQ('f', BufData[4095]);
EXPECT_EQ('\0', BufData[4096]);
}
@@ -89,11 +89,11 @@ TEST_F(MemoryBufferTest, NullTerminator4K) {
TEST_F(MemoryBufferTest, copy) {
// copy with no name
OwningBuffer MBC1(MemoryBuffer::getMemBufferCopy(data));
- EXPECT_TRUE(0 != MBC1.get());
+ EXPECT_TRUE(nullptr != MBC1.get());
// copy with a name
OwningBuffer MBC2(MemoryBuffer::getMemBufferCopy(data, "copy"));
- EXPECT_TRUE(0 != MBC2.get());
+ EXPECT_TRUE(nullptr != MBC2.get());
// verify the two copies do not point to the same place
EXPECT_NE(MBC1->getBufferStart(), MBC2->getBufferStart());
@@ -102,25 +102,25 @@ TEST_F(MemoryBufferTest, copy) {
TEST_F(MemoryBufferTest, make_new) {
// 0-sized buffer
OwningBuffer Zero(MemoryBuffer::getNewUninitMemBuffer(0));
- EXPECT_TRUE(0 != Zero.get());
+ EXPECT_TRUE(nullptr != Zero.get());
// uninitialized buffer with no name
OwningBuffer One(MemoryBuffer::getNewUninitMemBuffer(321));
- EXPECT_TRUE(0 != One.get());
+ EXPECT_TRUE(nullptr != One.get());
// uninitialized buffer with name
OwningBuffer Two(MemoryBuffer::getNewUninitMemBuffer(123, "bla"));
- EXPECT_TRUE(0 != Two.get());
+ EXPECT_TRUE(nullptr != Two.get());
// 0-initialized buffer with no name
OwningBuffer Three(MemoryBuffer::getNewMemBuffer(321, data));
- EXPECT_TRUE(0 != Three.get());
+ EXPECT_TRUE(nullptr != Three.get());
for (size_t i = 0; i < 321; ++i)
EXPECT_EQ(0, Three->getBufferStart()[0]);
// 0-initialized buffer with name
OwningBuffer Four(MemoryBuffer::getNewMemBuffer(123, "zeros"));
- EXPECT_TRUE(0 != Four.get());
+ EXPECT_TRUE(nullptr != Four.get());
for (size_t i = 0; i < 123; ++i)
EXPECT_EQ(0, Four->getBufferStart()[0]);
}
@@ -146,14 +146,16 @@ void MemoryBufferTest::testGetOpenFileSlice(bool Reopen) {
EXPECT_FALSE(sys::fs::openFileForRead(TestPath.c_str(), TestFD));
}
- OwningBuffer Buf;
- error_code EC = MemoryBuffer::getOpenFileSlice(TestFD, TestPath.c_str(), Buf,
- 40000, // Size
- 80000 // Offset
- );
+ ErrorOr<OwningBuffer> Buf =
+ MemoryBuffer::getOpenFileSlice(TestFD, TestPath.c_str(),
+ 40000, // Size
+ 80000 // Offset
+ );
+
+ std::error_code EC = Buf.getError();
EXPECT_FALSE(EC);
- StringRef BufData = Buf->getBuffer();
+ StringRef BufData = Buf.get()->getBuffer();
EXPECT_EQ(BufData.size(), 40000U);
EXPECT_EQ(BufData[0], '0');
EXPECT_EQ(BufData[9], '9');
diff --git a/unittests/Support/MemoryTest.cpp b/unittests/Support/MemoryTest.cpp
index fae67a8..8ad90e0 100644
--- a/unittests/Support/MemoryTest.cpp
+++ b/unittests/Support/MemoryTest.cpp
@@ -57,30 +57,30 @@ protected:
};
TEST_P(MappedMemoryTest, AllocAndRelease) {
- error_code EC;
- MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ std::error_code EC;
+ MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), nullptr, Flags,EC);
+ EXPECT_EQ(std::error_code(), EC);
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(sizeof(int), M1.size());
EXPECT_FALSE(Memory::releaseMappedMemory(M1));
}
TEST_P(MappedMemoryTest, MultipleAllocAndRelease) {
- error_code EC;
- MemoryBlock M1 = Memory::allocateMappedMemory(16, 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- MemoryBlock M2 = Memory::allocateMappedMemory(64, 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- MemoryBlock M3 = Memory::allocateMappedMemory(32, 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
-
- EXPECT_NE((void*)0, M1.base());
+ std::error_code EC;
+ MemoryBlock M1 = Memory::allocateMappedMemory(16, nullptr, Flags, EC);
+ EXPECT_EQ(std::error_code(), EC);
+ MemoryBlock M2 = Memory::allocateMappedMemory(64, nullptr, Flags, EC);
+ EXPECT_EQ(std::error_code(), EC);
+ MemoryBlock M3 = Memory::allocateMappedMemory(32, nullptr, Flags, EC);
+ EXPECT_EQ(std::error_code(), EC);
+
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(16U, M1.size());
- EXPECT_NE((void*)0, M2.base());
+ EXPECT_NE((void*)nullptr, M2.base());
EXPECT_LE(64U, M2.size());
- EXPECT_NE((void*)0, M3.base());
+ EXPECT_NE((void*)nullptr, M3.base());
EXPECT_LE(32U, M3.size());
EXPECT_FALSE(doesOverlap(M1, M2));
@@ -89,9 +89,9 @@ TEST_P(MappedMemoryTest, MultipleAllocAndRelease) {
EXPECT_FALSE(Memory::releaseMappedMemory(M1));
EXPECT_FALSE(Memory::releaseMappedMemory(M3));
- MemoryBlock M4 = Memory::allocateMappedMemory(16, 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- EXPECT_NE((void*)0, M4.base());
+ MemoryBlock M4 = Memory::allocateMappedMemory(16, nullptr, Flags, EC);
+ EXPECT_EQ(std::error_code(), EC);
+ EXPECT_NE((void*)nullptr, M4.base());
EXPECT_LE(16U, M4.size());
EXPECT_FALSE(Memory::releaseMappedMemory(M4));
EXPECT_FALSE(Memory::releaseMappedMemory(M2));
@@ -103,11 +103,11 @@ TEST_P(MappedMemoryTest, BasicWrite) {
!((Flags & Memory::MF_READ) && (Flags & Memory::MF_WRITE)))
return;
- error_code EC;
- MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ std::error_code EC;
+ MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), nullptr, Flags,EC);
+ EXPECT_EQ(std::error_code(), EC);
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(sizeof(int), M1.size());
int *a = (int*)M1.base();
@@ -122,23 +122,26 @@ TEST_P(MappedMemoryTest, MultipleWrite) {
if (Flags &&
!((Flags & Memory::MF_READ) && (Flags & Memory::MF_WRITE)))
return;
- error_code EC;
- MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ std::error_code EC;
+ MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), nullptr, Flags,
+ EC);
+ EXPECT_EQ(std::error_code(), EC);
+ MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), nullptr, Flags,
+ EC);
+ EXPECT_EQ(std::error_code(), EC);
+ MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), nullptr, Flags,
+ EC);
+ EXPECT_EQ(std::error_code(), EC);
EXPECT_FALSE(doesOverlap(M1, M2));
EXPECT_FALSE(doesOverlap(M2, M3));
EXPECT_FALSE(doesOverlap(M1, M3));
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(1U * sizeof(int), M1.size());
- EXPECT_NE((void*)0, M2.base());
+ EXPECT_NE((void*)nullptr, M2.base());
EXPECT_LE(8U * sizeof(int), M2.size());
- EXPECT_NE((void*)0, M3.base());
+ EXPECT_NE((void*)nullptr, M3.base());
EXPECT_LE(4U * sizeof(int), M3.size());
int *x = (int*)M1.base();
@@ -159,9 +162,10 @@ TEST_P(MappedMemoryTest, MultipleWrite) {
EXPECT_FALSE(Memory::releaseMappedMemory(M1));
EXPECT_FALSE(Memory::releaseMappedMemory(M3));
- MemoryBlock M4 = Memory::allocateMappedMemory(64 * sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- EXPECT_NE((void*)0, M4.base());
+ MemoryBlock M4 = Memory::allocateMappedMemory(64 * sizeof(int), nullptr,
+ Flags, EC);
+ EXPECT_EQ(std::error_code(), EC);
+ EXPECT_NE((void*)nullptr, M4.base());
EXPECT_LE(64U * sizeof(int), M4.size());
x = (int*)M4.base();
*x = 4;
@@ -176,19 +180,22 @@ TEST_P(MappedMemoryTest, MultipleWrite) {
}
TEST_P(MappedMemoryTest, EnabledWrite) {
- error_code EC;
- MemoryBlock M1 = Memory::allocateMappedMemory(2 * sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
-
- EXPECT_NE((void*)0, M1.base());
+ std::error_code EC;
+ MemoryBlock M1 = Memory::allocateMappedMemory(2 * sizeof(int), nullptr, Flags,
+ EC);
+ EXPECT_EQ(std::error_code(), EC);
+ MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), nullptr, Flags,
+ EC);
+ EXPECT_EQ(std::error_code(), EC);
+ MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), nullptr, Flags,
+ EC);
+ EXPECT_EQ(std::error_code(), EC);
+
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(2U * sizeof(int), M1.size());
- EXPECT_NE((void*)0, M2.base());
+ EXPECT_NE((void*)nullptr, M2.base());
EXPECT_LE(8U * sizeof(int), M2.size());
- EXPECT_NE((void*)0, M3.base());
+ EXPECT_NE((void*)nullptr, M3.base());
EXPECT_LE(4U * sizeof(int), M3.size());
EXPECT_FALSE(Memory::protectMappedMemory(M1, getTestableEquivalent(Flags)));
@@ -216,11 +223,12 @@ TEST_P(MappedMemoryTest, EnabledWrite) {
EXPECT_FALSE(Memory::releaseMappedMemory(M3));
EXPECT_EQ(6, y[6]);
- MemoryBlock M4 = Memory::allocateMappedMemory(16, 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
- EXPECT_NE((void*)0, M4.base());
+ MemoryBlock M4 = Memory::allocateMappedMemory(16, nullptr, Flags, EC);
+ EXPECT_EQ(std::error_code(), EC);
+ EXPECT_NE((void*)nullptr, M4.base());
EXPECT_LE(16U, M4.size());
- EXPECT_EQ(error_code::success(), Memory::protectMappedMemory(M4, getTestableEquivalent(Flags)));
+ EXPECT_EQ(std::error_code(),
+ Memory::protectMappedMemory(M4, getTestableEquivalent(Flags)));
x = (int*)M4.base();
*x = 4;
EXPECT_EQ(4, *x);
@@ -229,19 +237,19 @@ TEST_P(MappedMemoryTest, EnabledWrite) {
}
TEST_P(MappedMemoryTest, SuccessiveNear) {
- error_code EC;
- MemoryBlock M1 = Memory::allocateMappedMemory(16, 0, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ std::error_code EC;
+ MemoryBlock M1 = Memory::allocateMappedMemory(16, nullptr, Flags, EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M2 = Memory::allocateMappedMemory(64, &M1, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M3 = Memory::allocateMappedMemory(32, &M2, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(16U, M1.size());
- EXPECT_NE((void*)0, M2.base());
+ EXPECT_NE((void*)nullptr, M2.base());
EXPECT_LE(64U, M2.size());
- EXPECT_NE((void*)0, M3.base());
+ EXPECT_NE((void*)nullptr, M3.base());
EXPECT_LE(32U, M3.size());
EXPECT_FALSE(doesOverlap(M1, M2));
@@ -254,20 +262,20 @@ TEST_P(MappedMemoryTest, SuccessiveNear) {
}
TEST_P(MappedMemoryTest, DuplicateNear) {
- error_code EC;
+ std::error_code EC;
MemoryBlock Near((void*)(3*PageSize), 16);
MemoryBlock M1 = Memory::allocateMappedMemory(16, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M2 = Memory::allocateMappedMemory(64, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M3 = Memory::allocateMappedMemory(32, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(16U, M1.size());
- EXPECT_NE((void*)0, M2.base());
+ EXPECT_NE((void*)nullptr, M2.base());
EXPECT_LE(64U, M2.size());
- EXPECT_NE((void*)0, M3.base());
+ EXPECT_NE((void*)nullptr, M3.base());
EXPECT_LE(32U, M3.size());
EXPECT_FALSE(Memory::releaseMappedMemory(M1));
@@ -276,20 +284,20 @@ TEST_P(MappedMemoryTest, DuplicateNear) {
}
TEST_P(MappedMemoryTest, ZeroNear) {
- error_code EC;
- MemoryBlock Near(0, 0);
+ std::error_code EC;
+ MemoryBlock Near(nullptr, 0);
MemoryBlock M1 = Memory::allocateMappedMemory(16, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M2 = Memory::allocateMappedMemory(64, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M3 = Memory::allocateMappedMemory(32, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(16U, M1.size());
- EXPECT_NE((void*)0, M2.base());
+ EXPECT_NE((void*)nullptr, M2.base());
EXPECT_LE(64U, M2.size());
- EXPECT_NE((void*)0, M3.base());
+ EXPECT_NE((void*)nullptr, M3.base());
EXPECT_LE(32U, M3.size());
EXPECT_FALSE(doesOverlap(M1, M2));
@@ -302,20 +310,20 @@ TEST_P(MappedMemoryTest, ZeroNear) {
}
TEST_P(MappedMemoryTest, ZeroSizeNear) {
- error_code EC;
+ std::error_code EC;
MemoryBlock Near((void*)(4*PageSize), 0);
MemoryBlock M1 = Memory::allocateMappedMemory(16, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M2 = Memory::allocateMappedMemory(64, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
MemoryBlock M3 = Memory::allocateMappedMemory(32, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(16U, M1.size());
- EXPECT_NE((void*)0, M2.base());
+ EXPECT_NE((void*)nullptr, M2.base());
EXPECT_LE(64U, M2.size());
- EXPECT_NE((void*)0, M3.base());
+ EXPECT_NE((void*)nullptr, M3.base());
EXPECT_LE(32U, M3.size());
EXPECT_FALSE(doesOverlap(M1, M2));
@@ -328,12 +336,12 @@ TEST_P(MappedMemoryTest, ZeroSizeNear) {
}
TEST_P(MappedMemoryTest, UnalignedNear) {
- error_code EC;
+ std::error_code EC;
MemoryBlock Near((void*)(2*PageSize+5), 0);
MemoryBlock M1 = Memory::allocateMappedMemory(15, &Near, Flags, EC);
- EXPECT_EQ(error_code::success(), EC);
+ EXPECT_EQ(std::error_code(), EC);
- EXPECT_NE((void*)0, M1.base());
+ EXPECT_NE((void*)nullptr, M1.base());
EXPECT_LE(sizeof(int), M1.size());
EXPECT_FALSE(Memory::releaseMappedMemory(M1));
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index b79d055..cf2e1ee 100644
--- a/unittests/Support/Path.cpp
+++ b/unittests/Support/Path.cpp
@@ -8,24 +8,30 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Path.h"
+#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
+#ifdef LLVM_ON_WIN32
+#include <winerror.h>
+#endif
+
using namespace llvm;
using namespace llvm::sys;
-#define ASSERT_NO_ERROR(x) \
- if (error_code ASSERT_NO_ERROR_ec = x) { \
- SmallString<128> MessageStorage; \
- raw_svector_ostream Message(MessageStorage); \
- Message << #x ": did not return errc::success.\n" \
- << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
- << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
- GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
- } else {}
+#define ASSERT_NO_ERROR(x) \
+ if (std::error_code ASSERT_NO_ERROR_ec = x) { \
+ SmallString<128> MessageStorage; \
+ raw_svector_ostream Message(MessageStorage); \
+ Message << #x ": did not return errc::success.\n" \
+ << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
+ << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
+ GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
+ } else { \
+ }
namespace {
@@ -352,7 +358,7 @@ TEST_F(FileSystemTest, TempFiles) {
ASSERT_EQ(fs::remove(Twine(TempPath2), false),
errc::no_such_file_or_directory);
- error_code EC = fs::status(TempPath2.c_str(), B);
+ std::error_code EC = fs::status(TempPath2.c_str(), B);
EXPECT_EQ(EC, errc::no_such_file_or_directory);
EXPECT_EQ(B.type(), fs::file_type::file_not_found);
@@ -393,7 +399,7 @@ TEST_F(FileSystemTest, TempFiles) {
"abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2"
"abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0";
EXPECT_EQ(fs::createUniqueFile(Twine(Path270), FileDescriptor, TempPath),
- windows_error::path_not_found);
+ errc::no_such_file_or_directory);
#endif
}
@@ -406,7 +412,7 @@ TEST_F(FileSystemTest, CreateDir) {
}
TEST_F(FileSystemTest, DirectoryIteration) {
- error_code ec;
+ std::error_code ec;
for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec))
ASSERT_NO_ERROR(ec);
@@ -535,9 +541,6 @@ TEST_F(FileSystemTest, Magic) {
StringRef magic(i->magic_str, i->magic_str_len);
file << magic;
file.close();
- bool res = false;
- ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res));
- EXPECT_TRUE(res);
EXPECT_EQ(i->magic, fs::identify_magic(magic));
ASSERT_NO_ERROR(fs::remove(Twine(file_pathname)));
}
@@ -555,9 +558,9 @@ TEST_F(FileSystemTest, CarriageReturn) {
File << '\n';
}
{
- std::unique_ptr<MemoryBuffer> Buf;
- MemoryBuffer::getFile(FilePathname.c_str(), Buf);
- EXPECT_EQ(Buf->getBuffer(), "\r\n");
+ auto Buf = MemoryBuffer::getFile(FilePathname.c_str());
+ EXPECT_TRUE((bool)Buf);
+ EXPECT_EQ(Buf.get()->getBuffer(), "\r\n");
}
{
@@ -566,9 +569,9 @@ TEST_F(FileSystemTest, CarriageReturn) {
File << '\n';
}
{
- std::unique_ptr<MemoryBuffer> Buf;
- MemoryBuffer::getFile(FilePathname.c_str(), Buf);
- EXPECT_EQ(Buf->getBuffer(), "\n");
+ auto Buf = MemoryBuffer::getFile(FilePathname.c_str());
+ EXPECT_TRUE((bool)Buf);
+ EXPECT_EQ(Buf.get()->getBuffer(), "\n");
}
ASSERT_NO_ERROR(fs::remove(Twine(FilePathname)));
}
@@ -581,7 +584,7 @@ TEST_F(FileSystemTest, FileMapping) {
ASSERT_NO_ERROR(
fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath));
// Map in temp file and add some content
- error_code EC;
+ std::error_code EC;
StringRef Val("hello there");
{
fs::mapped_file_region mfr(FileDescriptor,
diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp
index 800df14..4e7316f 100644
--- a/unittests/Support/ProgramTest.cpp
+++ b/unittests/Support/ProgramTest.cpp
@@ -54,7 +54,7 @@ static void CopyEnvironment(std::vector<const char *> &out) {
// environ seems to work for Windows and most other Unices.
char **envp = environ;
#endif
- while (*envp != 0) {
+ while (*envp != nullptr) {
out.push_back(*envp);
++envp;
}
@@ -76,14 +76,14 @@ TEST(ProgramTest, CreateProcessTrailingSlash) {
"--gtest_filter=ProgramTest.CreateProcessTrailingSlash",
"-program-test-string-arg1", "has\\\\ trailing\\",
"-program-test-string-arg2", "has\\\\ trailing\\",
- 0
+ nullptr
};
// Add LLVM_PROGRAM_TEST_CHILD to the environment of the child.
std::vector<const char *> envp;
CopyEnvironment(envp);
envp.push_back("LLVM_PROGRAM_TEST_CHILD=1");
- envp.push_back(0);
+ envp.push_back(nullptr);
std::string error;
bool ExecutionFailed;
@@ -93,7 +93,7 @@ TEST(ProgramTest, CreateProcessTrailingSlash) {
#else
StringRef nul("/dev/null");
#endif
- const StringRef *redirects[] = { &nul, &nul, 0 };
+ const StringRef *redirects[] = { &nul, &nul, nullptr };
int rc = ExecuteAndWait(my_exe, argv, &envp[0], redirects,
/*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error,
&ExecutionFailed);
@@ -114,19 +114,19 @@ TEST(ProgramTest, TestExecuteNoWait) {
const char *argv[] = {
Executable.c_str(),
"--gtest_filter=ProgramTest.TestExecuteNoWait",
- 0
+ nullptr
};
// Add LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT to the environment of the child.
std::vector<const char *> envp;
CopyEnvironment(envp);
envp.push_back("LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT=1");
- envp.push_back(0);
+ envp.push_back(nullptr);
std::string Error;
bool ExecutionFailed;
- ProcessInfo PI1 =
- ExecuteNoWait(Executable, argv, &envp[0], 0, 0, &Error, &ExecutionFailed);
+ ProcessInfo PI1 = ExecuteNoWait(Executable, argv, &envp[0], nullptr, 0,
+ &Error, &ExecutionFailed);
ASSERT_FALSE(ExecutionFailed) << Error;
ASSERT_NE(PI1.Pid, 0) << "Invalid process id";
@@ -144,8 +144,8 @@ TEST(ProgramTest, TestExecuteNoWait) {
EXPECT_EQ(LoopCount, 1u) << "LoopCount should be 1";
- ProcessInfo PI2 =
- ExecuteNoWait(Executable, argv, &envp[0], 0, 0, &Error, &ExecutionFailed);
+ ProcessInfo PI2 = ExecuteNoWait(Executable, argv, &envp[0], nullptr, 0,
+ &Error, &ExecutionFailed);
ASSERT_FALSE(ExecutionFailed) << Error;
ASSERT_NE(PI2.Pid, 0) << "Invalid process id";
@@ -162,15 +162,45 @@ TEST(ProgramTest, TestExecuteNoWait) {
ASSERT_GT(LoopCount, 1u) << "LoopCount should be >1";
}
+TEST(ProgramTest, TestExecuteAndWaitTimeout) {
+ using namespace llvm::sys;
+
+ if (getenv("LLVM_PROGRAM_TEST_TIMEOUT")) {
+ sleep_for(/*seconds*/ 10);
+ exit(0);
+ }
+
+ std::string Executable =
+ sys::fs::getMainExecutable(TestMainArgv0, &ProgramTestStringArg1);
+ const char *argv[] = {
+ Executable.c_str(),
+ "--gtest_filter=ProgramTest.TestExecuteAndWaitTimeout",
+ nullptr
+ };
+
+ // Add LLVM_PROGRAM_TEST_TIMEOUT to the environment of the child.
+ std::vector<const char *> envp;
+ CopyEnvironment(envp);
+ envp.push_back("LLVM_PROGRAM_TEST_TIMEOUT=1");
+ envp.push_back(nullptr);
+
+ std::string Error;
+ bool ExecutionFailed;
+ int RetCode =
+ ExecuteAndWait(Executable, argv, &envp[0], nullptr, /*secondsToWait=*/1, 0,
+ &Error, &ExecutionFailed);
+ ASSERT_EQ(-2, RetCode);
+}
+
TEST(ProgramTest, TestExecuteNegative) {
std::string Executable = "i_dont_exist";
- const char *argv[] = { Executable.c_str(), 0 };
+ const char *argv[] = { Executable.c_str(), nullptr };
{
std::string Error;
bool ExecutionFailed;
- int RetCode =
- ExecuteAndWait(Executable, argv, 0, 0, 0, 0, &Error, &ExecutionFailed);
+ int RetCode = ExecuteAndWait(Executable, argv, nullptr, nullptr, 0, 0,
+ &Error, &ExecutionFailed);
ASSERT_TRUE(RetCode < 0) << "On error ExecuteAndWait should return 0 or "
"positive value indicating the result code";
ASSERT_TRUE(ExecutionFailed);
@@ -180,8 +210,8 @@ TEST(ProgramTest, TestExecuteNegative) {
{
std::string Error;
bool ExecutionFailed;
- ProcessInfo PI =
- ExecuteNoWait(Executable, argv, 0, 0, 0, &Error, &ExecutionFailed);
+ ProcessInfo PI = ExecuteNoWait(Executable, argv, nullptr, nullptr, 0,
+ &Error, &ExecutionFailed);
ASSERT_EQ(PI.Pid, 0)
<< "On error ExecuteNoWait should return an invalid ProcessInfo";
ASSERT_TRUE(ExecutionFailed);
diff --git a/unittests/Support/ScaledNumberTest.cpp b/unittests/Support/ScaledNumberTest.cpp
new file mode 100644
index 0000000..7bbef7e
--- /dev/null
+++ b/unittests/Support/ScaledNumberTest.cpp
@@ -0,0 +1,536 @@
+//===- llvm/unittest/Support/ScaledNumberTest.cpp - ScaledPair tests -----==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/ScaledNumber.h"
+
+#include "llvm/Support/DataTypes.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::ScaledNumbers;
+
+namespace {
+
+template <class UIntT> struct ScaledPair {
+ UIntT D;
+ int S;
+ ScaledPair(const std::pair<UIntT, int16_t> &F) : D(F.first), S(F.second) {}
+ ScaledPair(UIntT D, int S) : D(D), S(S) {}
+
+ bool operator==(const ScaledPair<UIntT> &X) const {
+ return D == X.D && S == X.S;
+ }
+};
+template <class UIntT>
+bool operator==(const std::pair<UIntT, int16_t> &L,
+ const ScaledPair<UIntT> &R) {
+ return ScaledPair<UIntT>(L) == R;
+}
+template <class UIntT>
+void PrintTo(const ScaledPair<UIntT> &F, ::std::ostream *os) {
+ *os << F.D << "*2^" << F.S;
+}
+
+typedef ScaledPair<uint32_t> SP32;
+typedef ScaledPair<uint64_t> SP64;
+
+TEST(ScaledNumberHelpersTest, getRounded) {
+ EXPECT_EQ(getRounded32(0, 0, false), SP32(0, 0));
+ EXPECT_EQ(getRounded32(0, 0, true), SP32(1, 0));
+ EXPECT_EQ(getRounded32(20, 21, true), SP32(21, 21));
+ EXPECT_EQ(getRounded32(UINT32_MAX, 0, false), SP32(UINT32_MAX, 0));
+ EXPECT_EQ(getRounded32(UINT32_MAX, 0, true), SP32(1 << 31, 1));
+
+ EXPECT_EQ(getRounded64(0, 0, false), SP64(0, 0));
+ EXPECT_EQ(getRounded64(0, 0, true), SP64(1, 0));
+ EXPECT_EQ(getRounded64(20, 21, true), SP64(21, 21));
+ EXPECT_EQ(getRounded64(UINT32_MAX, 0, false), SP64(UINT32_MAX, 0));
+ EXPECT_EQ(getRounded64(UINT32_MAX, 0, true), SP64(UINT64_C(1) << 32, 0));
+ EXPECT_EQ(getRounded64(UINT64_MAX, 0, false), SP64(UINT64_MAX, 0));
+ EXPECT_EQ(getRounded64(UINT64_MAX, 0, true), SP64(UINT64_C(1) << 63, 1));
+}
+
+TEST(ScaledNumberHelpersTest, getAdjusted) {
+ const uint64_t Max32In64 = UINT32_MAX;
+ EXPECT_EQ(getAdjusted32(0), SP32(0, 0));
+ EXPECT_EQ(getAdjusted32(0, 5), SP32(0, 5));
+ EXPECT_EQ(getAdjusted32(UINT32_MAX), SP32(UINT32_MAX, 0));
+ EXPECT_EQ(getAdjusted32(Max32In64 << 1), SP32(UINT32_MAX, 1));
+ EXPECT_EQ(getAdjusted32(Max32In64 << 1, 1), SP32(UINT32_MAX, 2));
+ EXPECT_EQ(getAdjusted32(Max32In64 << 31), SP32(UINT32_MAX, 31));
+ EXPECT_EQ(getAdjusted32(Max32In64 << 32), SP32(UINT32_MAX, 32));
+ EXPECT_EQ(getAdjusted32(Max32In64 + 1), SP32(1u << 31, 1));
+ EXPECT_EQ(getAdjusted32(UINT64_MAX), SP32(1u << 31, 33));
+
+ EXPECT_EQ(getAdjusted64(0), SP64(0, 0));
+ EXPECT_EQ(getAdjusted64(0, 5), SP64(0, 5));
+ EXPECT_EQ(getAdjusted64(UINT32_MAX), SP64(UINT32_MAX, 0));
+ EXPECT_EQ(getAdjusted64(Max32In64 << 1), SP64(Max32In64 << 1, 0));
+ EXPECT_EQ(getAdjusted64(Max32In64 << 1, 1), SP64(Max32In64 << 1, 1));
+ EXPECT_EQ(getAdjusted64(Max32In64 << 31), SP64(Max32In64 << 31, 0));
+ EXPECT_EQ(getAdjusted64(Max32In64 << 32), SP64(Max32In64 << 32, 0));
+ EXPECT_EQ(getAdjusted64(Max32In64 + 1), SP64(Max32In64 + 1, 0));
+ EXPECT_EQ(getAdjusted64(UINT64_MAX), SP64(UINT64_MAX, 0));
+}
+
+TEST(ScaledNumberHelpersTest, getProduct) {
+ // Zero.
+ EXPECT_EQ(SP32(0, 0), getProduct32(0, 0));
+ EXPECT_EQ(SP32(0, 0), getProduct32(0, 1));
+ EXPECT_EQ(SP32(0, 0), getProduct32(0, 33));
+
+ // Basic.
+ EXPECT_EQ(SP32(6, 0), getProduct32(2, 3));
+ EXPECT_EQ(SP32(UINT16_MAX / 3 * UINT16_MAX / 5 * 2, 0),
+ getProduct32(UINT16_MAX / 3, UINT16_MAX / 5 * 2));
+
+ // Overflow, no loss of precision.
+ // ==> 0xf00010 * 0x1001
+ // ==> 0xf00f00000 + 0x10010
+ // ==> 0xf00f10010
+ // ==> 0xf00f1001 * 2^4
+ EXPECT_EQ(SP32(0xf00f1001, 4), getProduct32(0xf00010, 0x1001));
+
+ // Overflow, loss of precision, rounds down.
+ // ==> 0xf000070 * 0x1001
+ // ==> 0xf00f000000 + 0x70070
+ // ==> 0xf00f070070
+ // ==> 0xf00f0700 * 2^8
+ EXPECT_EQ(SP32(0xf00f0700, 8), getProduct32(0xf000070, 0x1001));
+
+ // Overflow, loss of precision, rounds up.
+ // ==> 0xf000080 * 0x1001
+ // ==> 0xf00f000000 + 0x80080
+ // ==> 0xf00f080080
+ // ==> 0xf00f0801 * 2^8
+ EXPECT_EQ(SP32(0xf00f0801, 8), getProduct32(0xf000080, 0x1001));
+
+ // Reverse operand order.
+ EXPECT_EQ(SP32(0, 0), getProduct32(1, 0));
+ EXPECT_EQ(SP32(0, 0), getProduct32(33, 0));
+ EXPECT_EQ(SP32(6, 0), getProduct32(3, 2));
+ EXPECT_EQ(SP32(UINT16_MAX / 3 * UINT16_MAX / 5 * 2, 0),
+ getProduct32(UINT16_MAX / 5 * 2, UINT16_MAX / 3));
+ EXPECT_EQ(SP32(0xf00f1001, 4), getProduct32(0x1001, 0xf00010));
+ EXPECT_EQ(SP32(0xf00f0700, 8), getProduct32(0x1001, 0xf000070));
+ EXPECT_EQ(SP32(0xf00f0801, 8), getProduct32(0x1001, 0xf000080));
+
+ // Round to overflow.
+ EXPECT_EQ(SP64(UINT64_C(1) << 63, 64),
+ getProduct64(UINT64_C(10376293541461622786),
+ UINT64_C(16397105843297379211)));
+
+ // Big number with rounding.
+ EXPECT_EQ(SP64(UINT64_C(9223372036854775810), 64),
+ getProduct64(UINT64_C(18446744073709551556),
+ UINT64_C(9223372036854775840)));
+}
+
+TEST(ScaledNumberHelpersTest, getQuotient) {
+ // Zero.
+ EXPECT_EQ(SP32(0, 0), getQuotient32(0, 0));
+ EXPECT_EQ(SP32(0, 0), getQuotient32(0, 1));
+ EXPECT_EQ(SP32(0, 0), getQuotient32(0, 73));
+ EXPECT_EQ(SP32(UINT32_MAX, MaxScale), getQuotient32(1, 0));
+ EXPECT_EQ(SP32(UINT32_MAX, MaxScale), getQuotient32(6, 0));
+
+ // Powers of two.
+ EXPECT_EQ(SP32(1u << 31, -31), getQuotient32(1, 1));
+ EXPECT_EQ(SP32(1u << 31, -30), getQuotient32(2, 1));
+ EXPECT_EQ(SP32(1u << 31, -33), getQuotient32(4, 16));
+ EXPECT_EQ(SP32(7u << 29, -29), getQuotient32(7, 1));
+ EXPECT_EQ(SP32(7u << 29, -30), getQuotient32(7, 2));
+ EXPECT_EQ(SP32(7u << 29, -33), getQuotient32(7, 16));
+
+ // Divide evenly.
+ EXPECT_EQ(SP32(3u << 30, -30), getQuotient32(9, 3));
+ EXPECT_EQ(SP32(9u << 28, -28), getQuotient32(63, 7));
+
+ // Divide unevenly.
+ EXPECT_EQ(SP32(0xaaaaaaab, -33), getQuotient32(1, 3));
+ EXPECT_EQ(SP32(0xd5555555, -31), getQuotient32(5, 3));
+
+ // 64-bit division is hard to test, since divide64 doesn't canonicalized its
+ // output. However, this is the algorithm the implementation uses:
+ //
+ // - Shift divisor right.
+ // - If we have 1 (power of 2), return early -- not canonicalized.
+ // - Shift dividend left.
+ // - 64-bit integer divide.
+ // - If there's a remainder, continue with long division.
+ //
+ // TODO: require less knowledge about the implementation in the test.
+
+ // Zero.
+ EXPECT_EQ(SP64(0, 0), getQuotient64(0, 0));
+ EXPECT_EQ(SP64(0, 0), getQuotient64(0, 1));
+ EXPECT_EQ(SP64(0, 0), getQuotient64(0, 73));
+ EXPECT_EQ(SP64(UINT64_MAX, MaxScale), getQuotient64(1, 0));
+ EXPECT_EQ(SP64(UINT64_MAX, MaxScale), getQuotient64(6, 0));
+
+ // Powers of two.
+ EXPECT_EQ(SP64(1, 0), getQuotient64(1, 1));
+ EXPECT_EQ(SP64(2, 0), getQuotient64(2, 1));
+ EXPECT_EQ(SP64(4, -4), getQuotient64(4, 16));
+ EXPECT_EQ(SP64(7, 0), getQuotient64(7, 1));
+ EXPECT_EQ(SP64(7, -1), getQuotient64(7, 2));
+ EXPECT_EQ(SP64(7, -4), getQuotient64(7, 16));
+
+ // Divide evenly.
+ EXPECT_EQ(SP64(UINT64_C(3) << 60, -60), getQuotient64(9, 3));
+ EXPECT_EQ(SP64(UINT64_C(9) << 58, -58), getQuotient64(63, 7));
+
+ // Divide unevenly.
+ EXPECT_EQ(SP64(0xaaaaaaaaaaaaaaab, -65), getQuotient64(1, 3));
+ EXPECT_EQ(SP64(0xd555555555555555, -63), getQuotient64(5, 3));
+}
+
+TEST(ScaledNumberHelpersTest, getLg) {
+ EXPECT_EQ(0, getLg(UINT32_C(1), 0));
+ EXPECT_EQ(1, getLg(UINT32_C(1), 1));
+ EXPECT_EQ(1, getLg(UINT32_C(2), 0));
+ EXPECT_EQ(3, getLg(UINT32_C(1), 3));
+ EXPECT_EQ(3, getLg(UINT32_C(7), 0));
+ EXPECT_EQ(3, getLg(UINT32_C(8), 0));
+ EXPECT_EQ(3, getLg(UINT32_C(9), 0));
+ EXPECT_EQ(3, getLg(UINT32_C(64), -3));
+ EXPECT_EQ(31, getLg((UINT32_MAX >> 1) + 2, 0));
+ EXPECT_EQ(32, getLg(UINT32_MAX, 0));
+ EXPECT_EQ(-1, getLg(UINT32_C(1), -1));
+ EXPECT_EQ(-1, getLg(UINT32_C(2), -2));
+ EXPECT_EQ(INT32_MIN, getLg(UINT32_C(0), -1));
+ EXPECT_EQ(INT32_MIN, getLg(UINT32_C(0), 0));
+ EXPECT_EQ(INT32_MIN, getLg(UINT32_C(0), 1));
+
+ EXPECT_EQ(0, getLg(UINT64_C(1), 0));
+ EXPECT_EQ(1, getLg(UINT64_C(1), 1));
+ EXPECT_EQ(1, getLg(UINT64_C(2), 0));
+ EXPECT_EQ(3, getLg(UINT64_C(1), 3));
+ EXPECT_EQ(3, getLg(UINT64_C(7), 0));
+ EXPECT_EQ(3, getLg(UINT64_C(8), 0));
+ EXPECT_EQ(3, getLg(UINT64_C(9), 0));
+ EXPECT_EQ(3, getLg(UINT64_C(64), -3));
+ EXPECT_EQ(63, getLg((UINT64_MAX >> 1) + 2, 0));
+ EXPECT_EQ(64, getLg(UINT64_MAX, 0));
+ EXPECT_EQ(-1, getLg(UINT64_C(1), -1));
+ EXPECT_EQ(-1, getLg(UINT64_C(2), -2));
+ EXPECT_EQ(INT32_MIN, getLg(UINT64_C(0), -1));
+ EXPECT_EQ(INT32_MIN, getLg(UINT64_C(0), 0));
+ EXPECT_EQ(INT32_MIN, getLg(UINT64_C(0), 1));
+}
+
+TEST(ScaledNumberHelpersTest, getLgFloor) {
+ EXPECT_EQ(0, getLgFloor(UINT32_C(1), 0));
+ EXPECT_EQ(1, getLgFloor(UINT32_C(1), 1));
+ EXPECT_EQ(1, getLgFloor(UINT32_C(2), 0));
+ EXPECT_EQ(2, getLgFloor(UINT32_C(7), 0));
+ EXPECT_EQ(3, getLgFloor(UINT32_C(1), 3));
+ EXPECT_EQ(3, getLgFloor(UINT32_C(8), 0));
+ EXPECT_EQ(3, getLgFloor(UINT32_C(9), 0));
+ EXPECT_EQ(3, getLgFloor(UINT32_C(64), -3));
+ EXPECT_EQ(31, getLgFloor((UINT32_MAX >> 1) + 2, 0));
+ EXPECT_EQ(31, getLgFloor(UINT32_MAX, 0));
+ EXPECT_EQ(INT32_MIN, getLgFloor(UINT32_C(0), -1));
+ EXPECT_EQ(INT32_MIN, getLgFloor(UINT32_C(0), 0));
+ EXPECT_EQ(INT32_MIN, getLgFloor(UINT32_C(0), 1));
+
+ EXPECT_EQ(0, getLgFloor(UINT64_C(1), 0));
+ EXPECT_EQ(1, getLgFloor(UINT64_C(1), 1));
+ EXPECT_EQ(1, getLgFloor(UINT64_C(2), 0));
+ EXPECT_EQ(2, getLgFloor(UINT64_C(7), 0));
+ EXPECT_EQ(3, getLgFloor(UINT64_C(1), 3));
+ EXPECT_EQ(3, getLgFloor(UINT64_C(8), 0));
+ EXPECT_EQ(3, getLgFloor(UINT64_C(9), 0));
+ EXPECT_EQ(3, getLgFloor(UINT64_C(64), -3));
+ EXPECT_EQ(63, getLgFloor((UINT64_MAX >> 1) + 2, 0));
+ EXPECT_EQ(63, getLgFloor(UINT64_MAX, 0));
+ EXPECT_EQ(INT32_MIN, getLgFloor(UINT64_C(0), -1));
+ EXPECT_EQ(INT32_MIN, getLgFloor(UINT64_C(0), 0));
+ EXPECT_EQ(INT32_MIN, getLgFloor(UINT64_C(0), 1));
+}
+
+TEST(ScaledNumberHelpersTest, getLgCeiling) {
+ EXPECT_EQ(0, getLgCeiling(UINT32_C(1), 0));
+ EXPECT_EQ(1, getLgCeiling(UINT32_C(1), 1));
+ EXPECT_EQ(1, getLgCeiling(UINT32_C(2), 0));
+ EXPECT_EQ(3, getLgCeiling(UINT32_C(1), 3));
+ EXPECT_EQ(3, getLgCeiling(UINT32_C(7), 0));
+ EXPECT_EQ(3, getLgCeiling(UINT32_C(8), 0));
+ EXPECT_EQ(3, getLgCeiling(UINT32_C(64), -3));
+ EXPECT_EQ(4, getLgCeiling(UINT32_C(9), 0));
+ EXPECT_EQ(32, getLgCeiling(UINT32_MAX, 0));
+ EXPECT_EQ(32, getLgCeiling((UINT32_MAX >> 1) + 2, 0));
+ EXPECT_EQ(INT32_MIN, getLgCeiling(UINT32_C(0), -1));
+ EXPECT_EQ(INT32_MIN, getLgCeiling(UINT32_C(0), 0));
+ EXPECT_EQ(INT32_MIN, getLgCeiling(UINT32_C(0), 1));
+
+ EXPECT_EQ(0, getLgCeiling(UINT64_C(1), 0));
+ EXPECT_EQ(1, getLgCeiling(UINT64_C(1), 1));
+ EXPECT_EQ(1, getLgCeiling(UINT64_C(2), 0));
+ EXPECT_EQ(3, getLgCeiling(UINT64_C(1), 3));
+ EXPECT_EQ(3, getLgCeiling(UINT64_C(7), 0));
+ EXPECT_EQ(3, getLgCeiling(UINT64_C(8), 0));
+ EXPECT_EQ(3, getLgCeiling(UINT64_C(64), -3));
+ EXPECT_EQ(4, getLgCeiling(UINT64_C(9), 0));
+ EXPECT_EQ(64, getLgCeiling((UINT64_MAX >> 1) + 2, 0));
+ EXPECT_EQ(64, getLgCeiling(UINT64_MAX, 0));
+ EXPECT_EQ(INT32_MIN, getLgCeiling(UINT64_C(0), -1));
+ EXPECT_EQ(INT32_MIN, getLgCeiling(UINT64_C(0), 0));
+ EXPECT_EQ(INT32_MIN, getLgCeiling(UINT64_C(0), 1));
+}
+
+TEST(ScaledNumberHelpersTest, compare) {
+ EXPECT_EQ(0, compare(UINT32_C(0), 0, UINT32_C(0), 1));
+ EXPECT_EQ(0, compare(UINT32_C(0), 0, UINT32_C(0), -10));
+ EXPECT_EQ(0, compare(UINT32_C(0), 0, UINT32_C(0), 20));
+ EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(64), -3));
+ EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(32), -2));
+ EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(16), -1));
+ EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(8), 0));
+ EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(4), 1));
+ EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(2), 2));
+ EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(1), 3));
+ EXPECT_EQ(-1, compare(UINT32_C(0), 0, UINT32_C(1), 3));
+ EXPECT_EQ(-1, compare(UINT32_C(7), 0, UINT32_C(1), 3));
+ EXPECT_EQ(-1, compare(UINT32_C(7), 0, UINT32_C(64), -3));
+ EXPECT_EQ(1, compare(UINT32_C(9), 0, UINT32_C(1), 3));
+ EXPECT_EQ(1, compare(UINT32_C(9), 0, UINT32_C(64), -3));
+ EXPECT_EQ(1, compare(UINT32_C(9), 0, UINT32_C(0), 0));
+
+ EXPECT_EQ(0, compare(UINT64_C(0), 0, UINT64_C(0), 1));
+ EXPECT_EQ(0, compare(UINT64_C(0), 0, UINT64_C(0), -10));
+ EXPECT_EQ(0, compare(UINT64_C(0), 0, UINT64_C(0), 20));
+ EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(64), -3));
+ EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(32), -2));
+ EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(16), -1));
+ EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(8), 0));
+ EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(4), 1));
+ EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(2), 2));
+ EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(1), 3));
+ EXPECT_EQ(-1, compare(UINT64_C(0), 0, UINT64_C(1), 3));
+ EXPECT_EQ(-1, compare(UINT64_C(7), 0, UINT64_C(1), 3));
+ EXPECT_EQ(-1, compare(UINT64_C(7), 0, UINT64_C(64), -3));
+ EXPECT_EQ(1, compare(UINT64_C(9), 0, UINT64_C(1), 3));
+ EXPECT_EQ(1, compare(UINT64_C(9), 0, UINT64_C(64), -3));
+ EXPECT_EQ(1, compare(UINT64_C(9), 0, UINT64_C(0), 0));
+ EXPECT_EQ(-1, compare(UINT64_MAX, 0, UINT64_C(1), 64));
+}
+
+TEST(ScaledNumberHelpersTest, matchScales) {
+#define MATCH_SCALES(T, LDIn, LSIn, RDIn, RSIn, LDOut, RDOut, SOut) \
+ do { \
+ T LDx = LDIn; \
+ T RDx = RDIn; \
+ T LDy = LDOut; \
+ T RDy = RDOut; \
+ int16_t LSx = LSIn; \
+ int16_t RSx = RSIn; \
+ int16_t Sy = SOut; \
+ \
+ EXPECT_EQ(SOut, matchScales(LDx, LSx, RDx, RSx)); \
+ EXPECT_EQ(LDy, LDx); \
+ EXPECT_EQ(RDy, RDx); \
+ if (LDy) \
+ EXPECT_EQ(Sy, LSx); \
+ if (RDy) \
+ EXPECT_EQ(Sy, RSx); \
+ } while (false)
+
+ MATCH_SCALES(uint32_t, 0, 0, 0, 0, 0, 0, 0);
+ MATCH_SCALES(uint32_t, 0, 50, 7, 1, 0, 7, 1);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 1, 9, 0, UINT32_C(1) << 31, 4, 1);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 2, 9, 0, UINT32_C(1) << 31, 2, 2);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 3, 9, 0, UINT32_C(1) << 31, 1, 3);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 4, 9, 0, UINT32_C(1) << 31, 0, 4);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 30, 4, 9, 0, UINT32_C(1) << 31, 1, 3);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 29, 4, 9, 0, UINT32_C(1) << 31, 2, 2);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 28, 4, 9, 0, UINT32_C(1) << 31, 4, 1);
+ MATCH_SCALES(uint32_t, UINT32_C(1) << 27, 4, 9, 0, UINT32_C(1) << 31, 9, 0);
+ MATCH_SCALES(uint32_t, 7, 1, 0, 50, 7, 0, 1);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 1, 4, UINT32_C(1) << 31, 1);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 2, 2, UINT32_C(1) << 31, 2);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 3, 1, UINT32_C(1) << 31, 3);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 4, 0, UINT32_C(1) << 31, 4);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 30, 4, 1, UINT32_C(1) << 31, 3);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 29, 4, 2, UINT32_C(1) << 31, 2);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 28, 4, 4, UINT32_C(1) << 31, 1);
+ MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 27, 4, 9, UINT32_C(1) << 31, 0);
+
+ MATCH_SCALES(uint64_t, 0, 0, 0, 0, 0, 0, 0);
+ MATCH_SCALES(uint64_t, 0, 100, 7, 1, 0, 7, 1);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 1, 9, 0, UINT64_C(1) << 63, 4, 1);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 2, 9, 0, UINT64_C(1) << 63, 2, 2);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 3, 9, 0, UINT64_C(1) << 63, 1, 3);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 4, 9, 0, UINT64_C(1) << 63, 0, 4);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 62, 4, 9, 0, UINT64_C(1) << 63, 1, 3);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 61, 4, 9, 0, UINT64_C(1) << 63, 2, 2);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 60, 4, 9, 0, UINT64_C(1) << 63, 4, 1);
+ MATCH_SCALES(uint64_t, UINT64_C(1) << 59, 4, 9, 0, UINT64_C(1) << 63, 9, 0);
+ MATCH_SCALES(uint64_t, 7, 1, 0, 100, 7, 0, 1);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 1, 4, UINT64_C(1) << 63, 1);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 2, 2, UINT64_C(1) << 63, 2);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 3, 1, UINT64_C(1) << 63, 3);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 4, 0, UINT64_C(1) << 63, 4);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 62, 4, 1, UINT64_C(1) << 63, 3);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 61, 4, 2, UINT64_C(1) << 63, 2);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 60, 4, 4, UINT64_C(1) << 63, 1);
+ MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 59, 4, 9, UINT64_C(1) << 63, 0);
+}
+
+TEST(ScaledNumberHelpersTest, getSum) {
+ // Zero.
+ EXPECT_EQ(SP32(1, 0), getSum32(0, 0, 1, 0));
+ EXPECT_EQ(SP32(8, -3), getSum32(0, 0, 8, -3));
+ EXPECT_EQ(SP32(UINT32_MAX, 0), getSum32(0, 0, UINT32_MAX, 0));
+
+ // Basic.
+ EXPECT_EQ(SP32(2, 0), getSum32(1, 0, 1, 0));
+ EXPECT_EQ(SP32(3, 0), getSum32(1, 0, 2, 0));
+ EXPECT_EQ(SP32(67, 0), getSum32(7, 0, 60, 0));
+
+ // Different scales.
+ EXPECT_EQ(SP32(3, 0), getSum32(1, 0, 1, 1));
+ EXPECT_EQ(SP32(4, 0), getSum32(2, 0, 1, 1));
+
+ // Loss of precision.
+ EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(1, 32, 1, 0));
+ EXPECT_EQ(SP32(UINT32_C(1) << 31, -31), getSum32(1, -32, 1, 0));
+
+ // Not quite loss of precision.
+ EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, 1), getSum32(1, 32, 1, 1));
+ EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, -32), getSum32(1, -32, 1, -1));
+
+ // Overflow.
+ EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(1, 0, UINT32_MAX, 0));
+
+ // Reverse operand order.
+ EXPECT_EQ(SP32(1, 0), getSum32(1, 0, 0, 0));
+ EXPECT_EQ(SP32(8, -3), getSum32(8, -3, 0, 0));
+ EXPECT_EQ(SP32(UINT32_MAX, 0), getSum32(UINT32_MAX, 0, 0, 0));
+ EXPECT_EQ(SP32(3, 0), getSum32(2, 0, 1, 0));
+ EXPECT_EQ(SP32(67, 0), getSum32(60, 0, 7, 0));
+ EXPECT_EQ(SP32(3, 0), getSum32(1, 1, 1, 0));
+ EXPECT_EQ(SP32(4, 0), getSum32(1, 1, 2, 0));
+ EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(1, 0, 1, 32));
+ EXPECT_EQ(SP32(UINT32_C(1) << 31, -31), getSum32(1, 0, 1, -32));
+ EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, 1), getSum32(1, 1, 1, 32));
+ EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, -32), getSum32(1, -1, 1, -32));
+ EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(UINT32_MAX, 0, 1, 0));
+
+ // Zero.
+ EXPECT_EQ(SP64(1, 0), getSum64(0, 0, 1, 0));
+ EXPECT_EQ(SP64(8, -3), getSum64(0, 0, 8, -3));
+ EXPECT_EQ(SP64(UINT64_MAX, 0), getSum64(0, 0, UINT64_MAX, 0));
+
+ // Basic.
+ EXPECT_EQ(SP64(2, 0), getSum64(1, 0, 1, 0));
+ EXPECT_EQ(SP64(3, 0), getSum64(1, 0, 2, 0));
+ EXPECT_EQ(SP64(67, 0), getSum64(7, 0, 60, 0));
+
+ // Different scales.
+ EXPECT_EQ(SP64(3, 0), getSum64(1, 0, 1, 1));
+ EXPECT_EQ(SP64(4, 0), getSum64(2, 0, 1, 1));
+
+ // Loss of precision.
+ EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(1, 64, 1, 0));
+ EXPECT_EQ(SP64(UINT64_C(1) << 63, -63), getSum64(1, -64, 1, 0));
+
+ // Not quite loss of precision.
+ EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, 1), getSum64(1, 64, 1, 1));
+ EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, -64), getSum64(1, -64, 1, -1));
+
+ // Overflow.
+ EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(1, 0, UINT64_MAX, 0));
+
+ // Reverse operand order.
+ EXPECT_EQ(SP64(1, 0), getSum64(1, 0, 0, 0));
+ EXPECT_EQ(SP64(8, -3), getSum64(8, -3, 0, 0));
+ EXPECT_EQ(SP64(UINT64_MAX, 0), getSum64(UINT64_MAX, 0, 0, 0));
+ EXPECT_EQ(SP64(3, 0), getSum64(2, 0, 1, 0));
+ EXPECT_EQ(SP64(67, 0), getSum64(60, 0, 7, 0));
+ EXPECT_EQ(SP64(3, 0), getSum64(1, 1, 1, 0));
+ EXPECT_EQ(SP64(4, 0), getSum64(1, 1, 2, 0));
+ EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(1, 0, 1, 64));
+ EXPECT_EQ(SP64(UINT64_C(1) << 63, -63), getSum64(1, 0, 1, -64));
+ EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, 1), getSum64(1, 1, 1, 64));
+ EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, -64), getSum64(1, -1, 1, -64));
+ EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(UINT64_MAX, 0, 1, 0));
+}
+
+TEST(ScaledNumberHelpersTest, getDifference) {
+ // Basic.
+ EXPECT_EQ(SP32(0, 0), getDifference32(1, 0, 1, 0));
+ EXPECT_EQ(SP32(1, 0), getDifference32(2, 0, 1, 0));
+ EXPECT_EQ(SP32(53, 0), getDifference32(60, 0, 7, 0));
+
+ // Equals "0", different scales.
+ EXPECT_EQ(SP32(0, 0), getDifference32(2, 0, 1, 1));
+
+ // Subtract "0".
+ EXPECT_EQ(SP32(1, 0), getDifference32(1, 0, 0, 0));
+ EXPECT_EQ(SP32(8, -3), getDifference32(8, -3, 0, 0));
+ EXPECT_EQ(SP32(UINT32_MAX, 0), getDifference32(UINT32_MAX, 0, 0, 0));
+
+ // Loss of precision.
+ EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, 1),
+ getDifference32((UINT32_C(1) << 31) + 1, 1, 1, 0));
+ EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, -31),
+ getDifference32((UINT32_C(1) << 31) + 1, -31, 1, -32));
+
+ // Not quite loss of precision.
+ EXPECT_EQ(SP32(UINT32_MAX, 0), getDifference32(1, 32, 1, 0));
+ EXPECT_EQ(SP32(UINT32_MAX, -32), getDifference32(1, 0, 1, -32));
+
+ // Saturate to "0".
+ EXPECT_EQ(SP32(0, 0), getDifference32(0, 0, 1, 0));
+ EXPECT_EQ(SP32(0, 0), getDifference32(0, 0, 8, -3));
+ EXPECT_EQ(SP32(0, 0), getDifference32(0, 0, UINT32_MAX, 0));
+ EXPECT_EQ(SP32(0, 0), getDifference32(7, 0, 60, 0));
+ EXPECT_EQ(SP32(0, 0), getDifference32(1, 0, 1, 1));
+ EXPECT_EQ(SP32(0, 0), getDifference32(1, -32, 1, 0));
+ EXPECT_EQ(SP32(0, 0), getDifference32(1, -32, 1, -1));
+
+ // Regression tests for cases that failed during bringup.
+ EXPECT_EQ(SP32(UINT32_C(1) << 26, -31),
+ getDifference32(1, 0, UINT32_C(31) << 27, -32));
+
+ // Basic.
+ EXPECT_EQ(SP64(0, 0), getDifference64(1, 0, 1, 0));
+ EXPECT_EQ(SP64(1, 0), getDifference64(2, 0, 1, 0));
+ EXPECT_EQ(SP64(53, 0), getDifference64(60, 0, 7, 0));
+
+ // Equals "0", different scales.
+ EXPECT_EQ(SP64(0, 0), getDifference64(2, 0, 1, 1));
+
+ // Subtract "0".
+ EXPECT_EQ(SP64(1, 0), getDifference64(1, 0, 0, 0));
+ EXPECT_EQ(SP64(8, -3), getDifference64(8, -3, 0, 0));
+ EXPECT_EQ(SP64(UINT64_MAX, 0), getDifference64(UINT64_MAX, 0, 0, 0));
+
+ // Loss of precision.
+ EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, 1),
+ getDifference64((UINT64_C(1) << 63) + 1, 1, 1, 0));
+ EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, -63),
+ getDifference64((UINT64_C(1) << 63) + 1, -63, 1, -64));
+
+ // Not quite loss of precision.
+ EXPECT_EQ(SP64(UINT64_MAX, 0), getDifference64(1, 64, 1, 0));
+ EXPECT_EQ(SP64(UINT64_MAX, -64), getDifference64(1, 0, 1, -64));
+
+ // Saturate to "0".
+ EXPECT_EQ(SP64(0, 0), getDifference64(0, 0, 1, 0));
+ EXPECT_EQ(SP64(0, 0), getDifference64(0, 0, 8, -3));
+ EXPECT_EQ(SP64(0, 0), getDifference64(0, 0, UINT64_MAX, 0));
+ EXPECT_EQ(SP64(0, 0), getDifference64(7, 0, 60, 0));
+ EXPECT_EQ(SP64(0, 0), getDifference64(1, 0, 1, 1));
+ EXPECT_EQ(SP64(0, 0), getDifference64(1, -64, 1, 0));
+ EXPECT_EQ(SP64(0, 0), getDifference64(1, -64, 1, -1));
+}
+
+} // end namespace
diff --git a/unittests/Support/SpecialCaseListTest.cpp b/unittests/Support/SpecialCaseListTest.cpp
new file mode 100644
index 0000000..bb9c351
--- /dev/null
+++ b/unittests/Support/SpecialCaseListTest.cpp
@@ -0,0 +1,126 @@
+//===- SpecialCaseListTest.cpp - Unit tests for SpecialCaseList -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SpecialCaseList.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+class SpecialCaseListTest : public ::testing::Test {
+protected:
+ SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) {
+ std::unique_ptr<MemoryBuffer> MB(MemoryBuffer::getMemBuffer(List));
+ return SpecialCaseList::create(MB.get(), Error);
+ }
+
+ SpecialCaseList *makeSpecialCaseList(StringRef List) {
+ std::string Error;
+ SpecialCaseList *SCL = makeSpecialCaseList(List, Error);
+ assert(SCL);
+ assert(Error == "");
+ return SCL;
+ }
+};
+
+TEST_F(SpecialCaseListTest, Basic) {
+ std::unique_ptr<SpecialCaseList> SCL(
+ makeSpecialCaseList("# This is a comment.\n"
+ "\n"
+ "src:hello\n"
+ "src:bye\n"
+ "src:hi=category\n"
+ "src:z*=category\n"));
+ EXPECT_TRUE(SCL->inSection("src", "hello"));
+ EXPECT_TRUE(SCL->inSection("src", "bye"));
+ EXPECT_TRUE(SCL->inSection("src", "hi", "category"));
+ EXPECT_TRUE(SCL->inSection("src", "zzzz", "category"));
+ EXPECT_FALSE(SCL->inSection("src", "hi"));
+ EXPECT_FALSE(SCL->inSection("fun", "hello"));
+ EXPECT_FALSE(SCL->inSection("src", "hello", "category"));
+}
+
+TEST_F(SpecialCaseListTest, GlobalInitCompat) {
+ std::unique_ptr<SpecialCaseList> SCL(
+ makeSpecialCaseList("global:foo=init\n"));
+ EXPECT_FALSE(SCL->inSection("global", "foo"));
+ EXPECT_FALSE(SCL->inSection("global", "bar"));
+ EXPECT_TRUE(SCL->inSection("global", "foo", "init"));
+ EXPECT_FALSE(SCL->inSection("global", "bar", "init"));
+
+ SCL.reset(makeSpecialCaseList("global-init:foo\n"));
+ EXPECT_FALSE(SCL->inSection("global", "foo"));
+ EXPECT_FALSE(SCL->inSection("global", "bar"));
+ EXPECT_TRUE(SCL->inSection("global", "foo", "init"));
+ EXPECT_FALSE(SCL->inSection("global", "bar", "init"));
+
+ SCL.reset(makeSpecialCaseList("type:t2=init\n"));
+ EXPECT_FALSE(SCL->inSection("type", "t1"));
+ EXPECT_FALSE(SCL->inSection("type", "t2"));
+ EXPECT_FALSE(SCL->inSection("type", "t1", "init"));
+ EXPECT_TRUE(SCL->inSection("type", "t2", "init"));
+
+ SCL.reset(makeSpecialCaseList("global-init-type:t2\n"));
+ EXPECT_FALSE(SCL->inSection("type", "t1"));
+ EXPECT_FALSE(SCL->inSection("type", "t2"));
+ EXPECT_FALSE(SCL->inSection("type", "t1", "init"));
+ EXPECT_TRUE(SCL->inSection("type", "t2", "init"));
+
+ SCL.reset(makeSpecialCaseList("src:hello=init\n"));
+ EXPECT_FALSE(SCL->inSection("src", "hello"));
+ EXPECT_FALSE(SCL->inSection("src", "bye"));
+ EXPECT_TRUE(SCL->inSection("src", "hello", "init"));
+ EXPECT_FALSE(SCL->inSection("src", "bye", "init"));
+
+ SCL.reset(makeSpecialCaseList("global-init-src:hello\n"));
+ EXPECT_FALSE(SCL->inSection("src", "hello"));
+ EXPECT_FALSE(SCL->inSection("src", "bye"));
+ EXPECT_TRUE(SCL->inSection("src", "hello", "init"));
+ EXPECT_FALSE(SCL->inSection("src", "bye", "init"));
+}
+
+TEST_F(SpecialCaseListTest, Substring) {
+ std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("src:hello\n"
+ "fun:foo\n"
+ "global:bar\n"));
+ EXPECT_FALSE(SCL->inSection("src", "othello"));
+ EXPECT_FALSE(SCL->inSection("fun", "tomfoolery"));
+ EXPECT_FALSE(SCL->inSection("global", "bartender"));
+
+ SCL.reset(makeSpecialCaseList("fun:*foo*\n"));
+ EXPECT_TRUE(SCL->inSection("fun", "tomfoolery"));
+ EXPECT_TRUE(SCL->inSection("fun", "foobar"));
+}
+
+TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) {
+ std::string Error;
+ EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error));
+ EXPECT_EQ("Malformed line 1: 'badline'", Error);
+ EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error));
+ EXPECT_EQ("Malformed regex in line 1: 'bad[a-': invalid character range",
+ Error);
+ EXPECT_EQ(nullptr, makeSpecialCaseList("src:a.c\n"
+ "fun:fun(a\n",
+ Error));
+ EXPECT_EQ("Malformed regex in line 2: 'fun(a': parentheses not balanced",
+ Error);
+ EXPECT_EQ(nullptr, SpecialCaseList::create("unexisting", Error));
+ EXPECT_EQ(0U, Error.find("Can't open file 'unexisting':"));
+}
+
+TEST_F(SpecialCaseListTest, EmptySpecialCaseList) {
+ std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList(""));
+ EXPECT_FALSE(SCL->inSection("foo", "bar"));
+}
+
+}
+
+
diff --git a/unittests/Support/StringPool.cpp b/unittests/Support/StringPool.cpp
new file mode 100644
index 0000000..7b7805f
--- /dev/null
+++ b/unittests/Support/StringPool.cpp
@@ -0,0 +1,31 @@
+//===- llvm/unittest/Support/ThreadLocalTest.cpp - Therad Local tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/StringPool.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(PooledStringPtrTest, OperatorEquals) {
+ StringPool pool;
+ const PooledStringPtr a = pool.intern("a");
+ const PooledStringPtr b = pool.intern("b");
+ EXPECT_FALSE(a == b);
+}
+
+TEST(PooledStringPtrTest, OperatorNotEquals) {
+ StringPool pool;
+ const PooledStringPtr a = pool.intern("a");
+ const PooledStringPtr b = pool.intern("b");
+ EXPECT_TRUE(a != b);
+}
+
+}
diff --git a/unittests/Support/SwapByteOrderTest.cpp b/unittests/Support/SwapByteOrderTest.cpp
index 85ac6f3..525cfc1 100644
--- a/unittests/Support/SwapByteOrderTest.cpp
+++ b/unittests/Support/SwapByteOrderTest.cpp
@@ -20,70 +20,70 @@ namespace {
// In these first two tests all of the original_uintx values are truncated
// except for 64. We could avoid this, but there's really no point.
-TEST(SwapByteOrder, UnsignedRoundTrip) {
+TEST(getSwappedBytes, UnsignedRoundTrip) {
// The point of the bit twiddling of magic is to test with and without bits
// in every byte.
uint64_t value = 1;
for (std::size_t i = 0; i <= sizeof(value); ++i) {
uint8_t original_uint8 = static_cast<uint8_t>(value);
EXPECT_EQ(original_uint8,
- sys::SwapByteOrder(sys::SwapByteOrder(original_uint8)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_uint8)));
uint16_t original_uint16 = static_cast<uint16_t>(value);
EXPECT_EQ(original_uint16,
- sys::SwapByteOrder(sys::SwapByteOrder(original_uint16)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_uint16)));
uint32_t original_uint32 = static_cast<uint32_t>(value);
EXPECT_EQ(original_uint32,
- sys::SwapByteOrder(sys::SwapByteOrder(original_uint32)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_uint32)));
uint64_t original_uint64 = static_cast<uint64_t>(value);
EXPECT_EQ(original_uint64,
- sys::SwapByteOrder(sys::SwapByteOrder(original_uint64)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_uint64)));
value = (value << 8) | 0x55; // binary 0101 0101.
}
}
-TEST(SwapByteOrder, SignedRoundTrip) {
+TEST(getSwappedBytes, SignedRoundTrip) {
// The point of the bit twiddling of magic is to test with and without bits
// in every byte.
uint64_t value = 1;
for (std::size_t i = 0; i <= sizeof(value); ++i) {
int8_t original_int8 = static_cast<int8_t>(value);
EXPECT_EQ(original_int8,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int8)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int8)));
int16_t original_int16 = static_cast<int16_t>(value);
EXPECT_EQ(original_int16,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int16)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int16)));
int32_t original_int32 = static_cast<int32_t>(value);
EXPECT_EQ(original_int32,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int32)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int32)));
int64_t original_int64 = static_cast<int64_t>(value);
EXPECT_EQ(original_int64,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int64)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int64)));
// Test other sign.
value *= -1;
original_int8 = static_cast<int8_t>(value);
EXPECT_EQ(original_int8,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int8)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int8)));
original_int16 = static_cast<int16_t>(value);
EXPECT_EQ(original_int16,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int16)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int16)));
original_int32 = static_cast<int32_t>(value);
EXPECT_EQ(original_int32,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int32)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int32)));
original_int64 = static_cast<int64_t>(value);
EXPECT_EQ(original_int64,
- sys::SwapByteOrder(sys::SwapByteOrder(original_int64)));
+ sys::getSwappedBytes(sys::getSwappedBytes(original_int64)));
// Return to normal sign and twiddle.
value *= -1;
@@ -91,38 +91,86 @@ TEST(SwapByteOrder, SignedRoundTrip) {
}
}
-TEST(SwapByteOrder, uint8_t) {
- EXPECT_EQ(uint8_t(0x11), sys::SwapByteOrder(uint8_t(0x11)));
+TEST(getSwappedBytes, uint8_t) {
+ EXPECT_EQ(uint8_t(0x11), sys::getSwappedBytes(uint8_t(0x11)));
}
-TEST(SwapByteOrder, uint16_t) {
- EXPECT_EQ(uint16_t(0x1122), sys::SwapByteOrder(uint16_t(0x2211)));
+TEST(getSwappedBytes, uint16_t) {
+ EXPECT_EQ(uint16_t(0x1122), sys::getSwappedBytes(uint16_t(0x2211)));
}
-TEST(SwapByteOrder, uint32_t) {
- EXPECT_EQ(uint32_t(0x11223344), sys::SwapByteOrder(uint32_t(0x44332211)));
+TEST(getSwappedBytes, uint32_t) {
+ EXPECT_EQ(uint32_t(0x11223344), sys::getSwappedBytes(uint32_t(0x44332211)));
}
-TEST(SwapByteOrder, uint64_t) {
+TEST(getSwappedBytes, uint64_t) {
EXPECT_EQ(uint64_t(0x1122334455667788ULL),
- sys::SwapByteOrder(uint64_t(0x8877665544332211ULL)));
+ sys::getSwappedBytes(uint64_t(0x8877665544332211ULL)));
}
-TEST(SwapByteOrder, int8_t) {
- EXPECT_EQ(int8_t(0x11), sys::SwapByteOrder(int8_t(0x11)));
+TEST(getSwappedBytes, int8_t) {
+ EXPECT_EQ(int8_t(0x11), sys::getSwappedBytes(int8_t(0x11)));
}
-TEST(SwapByteOrder, int16_t) {
- EXPECT_EQ(int16_t(0x1122), sys::SwapByteOrder(int16_t(0x2211)));
+TEST(getSwappedBytes, int16_t) {
+ EXPECT_EQ(int16_t(0x1122), sys::getSwappedBytes(int16_t(0x2211)));
}
-TEST(SwapByteOrder, int32_t) {
- EXPECT_EQ(int32_t(0x11223344), sys::SwapByteOrder(int32_t(0x44332211)));
+TEST(getSwappedBytes, int32_t) {
+ EXPECT_EQ(int32_t(0x11223344), sys::getSwappedBytes(int32_t(0x44332211)));
}
-TEST(SwapByteOrder, int64_t) {
+TEST(getSwappedBytes, int64_t) {
EXPECT_EQ(int64_t(0x1122334455667788LL),
- sys::SwapByteOrder(int64_t(0x8877665544332211LL)));
+ sys::getSwappedBytes(int64_t(0x8877665544332211LL)));
+}
+
+TEST(swapByteOrder, uint8_t) {
+ uint8_t value = 0x11;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(uint8_t(0x11), value);
+}
+
+TEST(swapByteOrder, uint16_t) {
+ uint16_t value = 0x2211;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(uint16_t(0x1122), value);
+}
+
+TEST(swapByteOrder, uint32_t) {
+ uint32_t value = 0x44332211;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(uint32_t(0x11223344), value);
+}
+
+TEST(swapByteOrder, uint64_t) {
+ uint64_t value = 0x8877665544332211ULL;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(uint64_t(0x1122334455667788ULL), value);
+}
+
+TEST(swapByteOrder, int8_t) {
+ int8_t value = 0x11;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(int8_t(0x11), value);
+}
+
+TEST(swapByteOrder, int16_t) {
+ int16_t value = 0x2211;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(int16_t(0x1122), value);
+}
+
+TEST(swapByteOrder, int32_t) {
+ int32_t value = 0x44332211;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(int32_t(0x11223344), value);
+}
+
+TEST(swapByteOrder, int64_t) {
+ int64_t value = 0x8877665544332211LL;
+ sys::swapByteOrder(value);
+ EXPECT_EQ(int64_t(0x1122334455667788LL), value);
}
}
diff --git a/unittests/Support/ThreadLocalTest.cpp b/unittests/Support/ThreadLocalTest.cpp
index dd4d706..ea751be 100644
--- a/unittests/Support/ThreadLocalTest.cpp
+++ b/unittests/Support/ThreadLocalTest.cpp
@@ -25,14 +25,14 @@ struct S {
TEST_F(ThreadLocalTest, Basics) {
ThreadLocal<const S> x;
- EXPECT_EQ(0, x.get());
+ EXPECT_EQ(nullptr, x.get());
S s;
x.set(&s);
EXPECT_EQ(&s, x.get());
x.erase();
- EXPECT_EQ(0, x.get());
+ EXPECT_EQ(nullptr, x.get());
}
}
diff --git a/unittests/Support/TimeValueTest.cpp b/unittests/Support/TimeValueTest.cpp
index 8058812..3d2b978 100644
--- a/unittests/Support/TimeValueTest.cpp
+++ b/unittests/Support/TimeValueTest.cpp
@@ -16,7 +16,7 @@ namespace {
TEST(TimeValue, time_t) {
sys::TimeValue now = sys::TimeValue::now();
- time_t now_t = time(NULL);
+ time_t now_t = time(nullptr);
EXPECT_TRUE(std::abs(static_cast<long>(now_t - now.toEpochTime())) < 2);
}
diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp
index cf95532..8aed980 100644
--- a/unittests/Support/YAMLIOTest.cpp
+++ b/unittests/Support/YAMLIOTest.cpp
@@ -1204,9 +1204,9 @@ TEST(YAMLIO, TestValidatingInput) {
std::vector<MyValidation> docList;
Input yin("--- \nvalue: 3.0\n"
"--- \nvalue: -1.0\n...\n",
- NULL, suppressErrorMessages);
+ nullptr, suppressErrorMessages);
yin >> docList;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1224,10 +1224,10 @@ TEST(YAMLIO, TestColorsReadError) {
"c2: purple\n"
"c3: green\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> map;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1241,11 +1241,11 @@ TEST(YAMLIO, TestFlagsReadError) {
"f2: [ round, hollow ]\n"
"f3: []\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> map;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1260,11 +1260,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint8Error) {
"- 0\n"
"- 257\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1279,11 +1279,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint16Error) {
"- 0\n"
"- 66000\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1298,11 +1298,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint32Error) {
"- 0\n"
"- 5000000000\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1317,11 +1317,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint64Error) {
"- 0\n"
"- 19446744073709551615\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1337,11 +1337,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint8OverError) {
"- 127\n"
"- 128\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1355,11 +1355,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint8UnderError) {
"- 127\n"
"- -129\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1375,11 +1375,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint16UnderError) {
"- -32768\n"
"- -32769\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1394,11 +1394,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint16OverError) {
"- -32768\n"
"- 32768\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1414,11 +1414,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint32UnderError) {
"- -2147483648\n"
"- -2147483649\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1432,11 +1432,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint32OverError) {
"- -2147483648\n"
"- 2147483649\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1452,11 +1452,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint64UnderError) {
"- 9223372036854775807\n"
"- -9223372036854775809\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1470,11 +1470,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint64OverError) {
"- 9223372036854775807\n"
"- 9223372036854775809\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1489,11 +1489,11 @@ TEST(YAMLIO, TestReadBuiltInTypesFloatError) {
"- -123.456\n"
"- 1.2.3\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1508,11 +1508,11 @@ TEST(YAMLIO, TestReadBuiltInTypesDoubleError) {
"- -123.456\n"
"- 1.2.3\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1526,11 +1526,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex8Error) {
"- 0xFE\n"
"- 0x123\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
@@ -1545,11 +1545,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex16Error) {
"- 0xFEFF\n"
"- 0x12345\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1563,11 +1563,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex32Error) {
"- 0xFEFF0000\n"
"- 0x1234556789\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
//
@@ -1581,11 +1581,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex64Error) {
"- 0xFFEEDDCCBBAA9988\n"
"- 0x12345567890ABCDEF0\n"
"...\n",
- /*Ctxt=*/NULL,
+ /*Ctxt=*/nullptr,
suppressErrorMessages);
yin >> seq;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
TEST(YAMLIO, TestMalformedMapFailsGracefully) {
@@ -1593,15 +1593,15 @@ TEST(YAMLIO, TestMalformedMapFailsGracefully) {
{
// We pass the suppressErrorMessages handler to handle the error
// message generated in the constructor of Input.
- Input yin("{foo:3, bar: 5}", /*Ctxt=*/NULL, suppressErrorMessages);
+ Input yin("{foo:3, bar: 5}", /*Ctxt=*/nullptr, suppressErrorMessages);
yin >> doc;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
{
- Input yin("---\nfoo:3\nbar: 5\n...\n", /*Ctxt=*/NULL, suppressErrorMessages);
+ Input yin("---\nfoo:3\nbar: 5\n...\n", /*Ctxt=*/nullptr, suppressErrorMessages);
yin >> doc;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
}
@@ -1673,7 +1673,7 @@ TEST(YAMLIO, TestEmptyStringFailsForMapWithRequiredFields) {
FooBar doc;
Input yin("");
yin >> doc;
- EXPECT_TRUE(yin.error());
+ EXPECT_TRUE(!!yin.error());
}
TEST(YAMLIO, TestEmptyStringSucceedsForMapWithOptionalFields) {
@@ -1685,7 +1685,7 @@ TEST(YAMLIO, TestEmptyStringSucceedsForMapWithOptionalFields) {
TEST(YAMLIO, TestEmptyStringSucceedsForSequence) {
std::vector<uint8_t> seq;
- Input yin("", /*Ctxt=*/NULL, suppressErrorMessages);
+ Input yin("", /*Ctxt=*/nullptr, suppressErrorMessages);
yin >> seq;
EXPECT_FALSE(yin.error());
diff --git a/unittests/Support/raw_ostream_test.cpp b/unittests/Support/raw_ostream_test.cpp
index 2b797b4..44d27d0 100644
--- a/unittests/Support/raw_ostream_test.cpp
+++ b/unittests/Support/raw_ostream_test.cpp
@@ -69,7 +69,7 @@ TEST(raw_ostreamTest, Types_Buffered) {
EXPECT_EQ("1.100000e+00", printToString(1.1));
// void*
- EXPECT_EQ("0x0", printToString((void*) 0));
+ EXPECT_EQ("0x0", printToString((void*) nullptr));
EXPECT_EQ("0xbeef", printToString((void*) 0xbeef));
EXPECT_EQ("0xdeadbeef", printToString((void*) 0xdeadbeef));
@@ -100,7 +100,7 @@ TEST(raw_ostreamTest, Types_Unbuffered) {
EXPECT_EQ("1.100000e+00", printToStringUnbuffered(1.1));
// void*
- EXPECT_EQ("0x0", printToStringUnbuffered((void*) 0));
+ EXPECT_EQ("0x0", printToStringUnbuffered((void*) nullptr));
EXPECT_EQ("0xbeef", printToStringUnbuffered((void*) 0xbeef));
EXPECT_EQ("0xdeadbeef", printToStringUnbuffered((void*) 0xdeadbeef));