From f8a75eef85efc2347c70a20a60fbdf1e0982266c Mon Sep 17 00:00:00 2001 From: Nick Kledzik Date: Wed, 3 Oct 2012 18:15:27 +0000 Subject: [PATCH] Add getAsUnsignedInteger test case that checks that known bad values are rejected llvm-svn: 165136 --- llvm/unittests/ADT/StringRefTest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp index 315eacbaa400..59eed54f0342 100644 --- a/llvm/unittests/ADT/StringRefTest.cpp +++ b/llvm/unittests/ADT/StringRefTest.cpp @@ -456,4 +456,23 @@ TEST(StringRefTest, getAsInteger) { } } + +static const char* BadStrings[] = { + "18446744073709551617" // value just over max + , "123456789012345678901" // value way too large + , "4t23v" // illegal decimal characters + , "0x123W56" // illegal hex characters +}; + + +TEST(StringRefTest, getAsUnsignedIntegerBadStrings) { + uint64_t U64; + for (size_t i = 0; i < array_lengthof(BadStrings); ++i) { + bool IsBadNumber = getAsUnsignedInteger(BadStrings[i], 0, U64); + ASSERT_TRUE(IsBadNumber); + } +} + + + } // end anonymous namespace