summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-08-10 11:37:34 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2019-08-10 12:39:03 (GMT)
commit935fbe0b0454163678bc4ef19e1bee95a7a31b4d (patch)
tree794eea739dbd5e5fc184539e4fdd856f8fad3364 /Tests/CMakeLib
parent32a7605e69e3faf56bf51da1641a7ae897d23826 (diff)
downloadCMake-935fbe0b0454163678bc4ef19e1bee95a7a31b4d.zip
CMake-935fbe0b0454163678bc4ef19e1bee95a7a31b4d.tar.gz
CMake-935fbe0b0454163678bc4ef19e1bee95a7a31b4d.tar.bz2
cmStringAlgorithms: Add cmStrToLong and cmStrToULong
This adds the following functions to cmStringAlgorithms: - `cmStrToLong`: moved from `cmSystemTools::StringToLong` - `cmStrToULong`: moved from `cmSystemTools::StringToULong` Overloads of the given functions for `std::string` are added as well.
Diffstat (limited to 'Tests/CMakeLib')
-rw-r--r--Tests/CMakeLib/testStringAlgorithms.cxx35
-rw-r--r--Tests/CMakeLib/testSystemTools.cxx16
2 files changed, 35 insertions, 16 deletions
diff --git a/Tests/CMakeLib/testStringAlgorithms.cxx b/Tests/CMakeLib/testStringAlgorithms.cxx
index 55d2a8f..3b18d0d 100644
--- a/Tests/CMakeLib/testStringAlgorithms.cxx
+++ b/Tests/CMakeLib/testStringAlgorithms.cxx
@@ -167,5 +167,40 @@ int testStringAlgorithms(int /*unused*/, char* /*unused*/ [])
assert_ok(!cmHasLiteralSuffix(str, "ab"), "cmHasLiteralPrefix string not");
}
+ // ----------------------------------------------------------------------
+ // Test cmStrToLong
+ {
+ long value;
+ assert_ok(cmStrToLong("1", &value) && value == 1,
+ "cmStrToLong parses a positive decimal integer.");
+ assert_ok(cmStrToLong(" 1", &value) && value == 1,
+ "cmStrToLong parses a decimal integer after whitespace.");
+
+ assert_ok(cmStrToLong("-1", &value) && value == -1,
+ "cmStrToLong parses a negative decimal integer.");
+ assert_ok(
+ cmStrToLong(" -1", &value) && value == -1,
+ "cmStrToLong parses a negative decimal integer after whitespace.");
+
+ assert_ok(!cmStrToLong("1x", &value),
+ "cmStrToLong rejects trailing content.");
+ }
+
+ // ----------------------------------------------------------------------
+ // Test cmStrToULong
+ {
+ unsigned long value;
+ assert_ok(cmStrToULong("1", &value) && value == 1,
+ "cmStrToULong parses a decimal integer.");
+ assert_ok(cmStrToULong(" 1", &value) && value == 1,
+ "cmStrToULong parses a decimal integer after whitespace.");
+ assert_ok(!cmStrToULong("-1", &value),
+ "cmStrToULong rejects a negative number.");
+ assert_ok(!cmStrToULong(" -1", &value),
+ "cmStrToULong rejects a negative number after whitespace.");
+ assert_ok(!cmStrToULong("1x", &value),
+ "cmStrToULong rejects trailing content.");
+ }
+
return failed;
}
diff --git a/Tests/CMakeLib/testSystemTools.cxx b/Tests/CMakeLib/testSystemTools.cxx
index 121e639..0a757df 100644
--- a/Tests/CMakeLib/testSystemTools.cxx
+++ b/Tests/CMakeLib/testSystemTools.cxx
@@ -94,21 +94,5 @@ int testSystemTools(int /*unused*/, char* /*unused*/ [])
cmPassed("cmSystemTools::strverscmp working");
}
- // ----------------------------------------------------------------------
- // Test cmSystemTools::StringToULong
- {
- unsigned long value;
- cmAssert(cmSystemTools::StringToULong("1", &value) && value == 1,
- "StringToULong parses a decimal integer.");
- cmAssert(cmSystemTools::StringToULong(" 1", &value) && value == 1,
- "StringToULong parses a decimal integer after whitespace.");
- cmAssert(!cmSystemTools::StringToULong("-1", &value),
- "StringToULong rejects a negative number.");
- cmAssert(!cmSystemTools::StringToULong(" -1", &value),
- "StringToULong rejects a negative number after whitespace.");
- cmAssert(!cmSystemTools::StringToULong("1x", &value),
- "StringToULong rejects trailing content.");
- }
-
return failed;
}