summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-09-21 14:12:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-09-21 14:12:11 (GMT)
commitef1d34b20d88e99de7a8e2f93feb247332cdafda (patch)
tree0d86f4245193d71fbd1d1d14f7a3816f83e5e613 /Tests/CMakeLib
parenta50346c1d0ebf355ba27177817bc4b45259b0810 (diff)
parent8fc822e13a8bf8695e475655f647d5d69f99c414 (diff)
downloadCMake-ef1d34b20d88e99de7a8e2f93feb247332cdafda.zip
CMake-ef1d34b20d88e99de7a8e2f93feb247332cdafda.tar.gz
CMake-ef1d34b20d88e99de7a8e2f93feb247332cdafda.tar.bz2
Merge topic 'parse-large-int'
8fc822e13a file: Avoid strange istringstream crash in cmake.org binaries on Alpine Linux 31f158e4c8 cmStringAlgorithms: Add functions to parse strings to long long integers Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7698
Diffstat (limited to 'Tests/CMakeLib')
-rw-r--r--Tests/CMakeLib/testStringAlgorithms.cxx35
1 files changed, 35 insertions, 0 deletions
diff --git a/Tests/CMakeLib/testStringAlgorithms.cxx b/Tests/CMakeLib/testStringAlgorithms.cxx
index c2706c1..1e6b611 100644
--- a/Tests/CMakeLib/testStringAlgorithms.cxx
+++ b/Tests/CMakeLib/testStringAlgorithms.cxx
@@ -227,6 +227,41 @@ int testStringAlgorithms(int /*unused*/, char* /*unused*/ [])
}
// ----------------------------------------------------------------------
+ // Test cmStrToLongLong
+ {
+ long long value;
+ assert_ok(cmStrToLongLong("1", &value) && value == 1,
+ "cmStrToLongLong parses a positive decimal integer.");
+ assert_ok(cmStrToLongLong(" 1", &value) && value == 1,
+ "cmStrToLongLong parses a decimal integer after whitespace.");
+
+ assert_ok(cmStrToLongLong("-1", &value) && value == -1,
+ "cmStrToLongLong parses a negative decimal integer.");
+ assert_ok(
+ cmStrToLongLong(" -1", &value) && value == -1,
+ "cmStrToLongLong parses a negative decimal integer after whitespace.");
+
+ assert_ok(!cmStrToLongLong("1x", &value),
+ "cmStrToLongLong rejects trailing content.");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test cmStrToULongLong
+ {
+ unsigned long long value;
+ assert_ok(cmStrToULongLong("1", &value) && value == 1,
+ "cmStrToULongLong parses a decimal integer.");
+ assert_ok(cmStrToULongLong(" 1", &value) && value == 1,
+ "cmStrToULongLong parses a decimal integer after whitespace.");
+ assert_ok(!cmStrToULongLong("-1", &value),
+ "cmStrToULongLong rejects a negative number.");
+ assert_ok(!cmStrToULongLong(" -1", &value),
+ "cmStrToULongLong rejects a negative number after whitespace.");
+ assert_ok(!cmStrToULongLong("1x", &value),
+ "cmStrToULongLong rejects trailing content.");
+ }
+
+ // ----------------------------------------------------------------------
// Test cmStrLen
{
constexpr auto len = cmStrLen("Hello world!");