2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2011-12-24 00:41:38 +04:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2016-08-17 02:08:13 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2016-09-05 23:09:49 +03:00
|
|
|
#define cmPassed(m) std::cout << "Passed: " << (m) << "\n"
|
2016-05-16 17:34:04 +03:00
|
|
|
#define cmFailed(m) \
|
2016-09-05 23:09:49 +03:00
|
|
|
std::cout << "FAILED: " << (m) << "\n"; \
|
2016-05-16 17:34:04 +03:00
|
|
|
failed = 1
|
2011-12-24 00:41:38 +04:00
|
|
|
|
2016-09-13 00:13:13 +03:00
|
|
|
#define cmAssert(exp, m) \
|
|
|
|
if ((exp)) { \
|
|
|
|
cmPassed(m); \
|
|
|
|
} else { \
|
|
|
|
cmFailed(m); \
|
|
|
|
}
|
|
|
|
|
2016-08-17 02:49:57 +03:00
|
|
|
int testSystemTools(int /*unused*/, char* /*unused*/ [])
|
2011-12-24 00:41:38 +04:00
|
|
|
{
|
|
|
|
int failed = 0;
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Test cmSystemTools::UpperCase
|
|
|
|
std::string str = "abc";
|
|
|
|
std::string strupper = "ABC";
|
2016-09-13 00:13:13 +03:00
|
|
|
cmAssert(cmSystemTools::UpperCase(str) == strupper,
|
|
|
|
"cmSystemTools::UpperCase");
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// Test cmSystemTools::strverscmp
|
|
|
|
cmAssert(cmSystemTools::strverscmp("", "") == 0, "strverscmp empty string");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("abc", "") > 0,
|
|
|
|
"strverscmp string vs empty string");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("abc", "abc") == 0,
|
|
|
|
"strverscmp same string");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("abd", "abc") > 0,
|
|
|
|
"strverscmp character string");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("abc", "abd") < 0,
|
|
|
|
"strverscmp symmetric");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("12345", "12344") > 0,
|
|
|
|
"strverscmp natural numbers");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("100", "99") > 0,
|
|
|
|
"strverscmp natural numbers different digits");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("12345", "00345") > 0,
|
|
|
|
"strverscmp natural against decimal (same length)");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("99999999999999", "99999999999991") > 0,
|
|
|
|
"strverscmp natural overflow");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("00000000000009", "00000000000001") > 0,
|
|
|
|
"strverscmp deciaml precision");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("a.b.c.0", "a.b.c.000") > 0,
|
|
|
|
"strverscmp multiple zeros");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("lib_1.2_10", "lib_1.2_2") > 0,
|
|
|
|
"strverscmp last number ");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("12lib", "2lib") > 0,
|
|
|
|
"strverscmp first number ");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("02lib", "002lib") > 0,
|
|
|
|
"strverscmp first number decimal ");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("10", "9a") > 0,
|
|
|
|
"strverscmp letter filler ");
|
|
|
|
cmAssert(cmSystemTools::strverscmp("000", "0001") > 0,
|
|
|
|
"strverscmp zero and leading zeros ");
|
|
|
|
|
|
|
|
// test sorting using standard strvercmp input
|
|
|
|
std::vector<std::string> testString;
|
|
|
|
testString.push_back("000");
|
|
|
|
testString.push_back("00");
|
|
|
|
testString.push_back("01");
|
|
|
|
testString.push_back("010");
|
|
|
|
testString.push_back("09");
|
|
|
|
testString.push_back("0");
|
|
|
|
testString.push_back("1");
|
|
|
|
testString.push_back("9");
|
|
|
|
testString.push_back("10");
|
|
|
|
|
|
|
|
// test global ordering of input strings
|
|
|
|
for (size_t i = 0; i < testString.size() - 1; i++) {
|
|
|
|
for (size_t j = i + 1; j < testString.size(); j++) {
|
|
|
|
if (cmSystemTools::strverscmp(testString[i], testString[j]) >= 0) {
|
|
|
|
cmFailed("cmSystemTools::strverscmp error in comparing strings " +
|
|
|
|
testString[i] + " " + testString[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!failed) {
|
|
|
|
cmPassed("cmSystemTools::strverscmp working");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-12-24 00:41:38 +04:00
|
|
|
return failed;
|
|
|
|
}
|