summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib
diff options
context:
space:
mode:
authorKitware Robot <kwrobot@kitware.com>2016-05-16 14:34:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-16 20:05:19 (GMT)
commitd9fd2f5402eeaa345691313658e02b51038f570b (patch)
treedca71b9a7e267f4c6300da3eb770415381726785 /Tests/CMakeLib
parent82df6deaafb36cbbfd450202bb20b320f637751a (diff)
downloadCMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update all our C++ code to a new style defined by `.clang-format`. Use `clang-format` version 3.8. * If you reached this commit for a line in `git blame`, re-run the blame operation starting at the parent of this commit to see older history for the content. * See the parent commit for instructions to rebase a change across this style transition commit.
Diffstat (limited to 'Tests/CMakeLib')
-rw-r--r--Tests/CMakeLib/run_compile_commands.cxx88
-rw-r--r--Tests/CMakeLib/testGeneratedFileStream.cxx86
-rw-r--r--Tests/CMakeLib/testRST.cxx64
-rw-r--r--Tests/CMakeLib/testSystemTools.cxx15
-rw-r--r--Tests/CMakeLib/testUTF8.cxx71
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser.cxx216
-rw-r--r--Tests/CMakeLib/testXMLParser.cxx7
-rw-r--r--Tests/CMakeLib/testXMLSafe.cxx22
8 files changed, 256 insertions, 313 deletions
diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx
index 26ab223..1cfd381 100644
--- a/Tests/CMakeLib/run_compile_commands.cxx
+++ b/Tests/CMakeLib/run_compile_commands.cxx
@@ -1,24 +1,24 @@
#include "cmSystemTools.h"
-class CompileCommandParser {
+class CompileCommandParser
+{
public:
- class CommandType: public std::map<std::string, std::string>
+ class CommandType : public std::map<std::string, std::string>
{
public:
std::string const& at(std::string const& k) const
- {
+ {
const_iterator i = this->find(k);
- if(i != this->end()) { return i->second; }
+ if (i != this->end()) {
+ return i->second;
+ }
static std::string emptyString;
return emptyString;
- }
+ }
};
typedef std::vector<CommandType> TranslationUnitsType;
- CompileCommandParser(std::ifstream *input)
- {
- this->Input = input;
- }
+ CompileCommandParser(std::ifstream* input) { this->Input = input; }
void Parse()
{
@@ -36,54 +36,53 @@ private:
{
this->TranslationUnits = TranslationUnitsType();
ExpectOrDie('[', "at start of compile command file\n");
- do
- {
+ do {
ParseTranslationUnit();
this->TranslationUnits.push_back(this->Command);
- } while(Expect(','));
+ } while (Expect(','));
ExpectOrDie(']', "at end of array");
}
void ParseTranslationUnit()
{
this->Command = CommandType();
- if(!Expect('{')) return;
- if(Expect('}')) return;
- do
- {
+ if (!Expect('{'))
+ return;
+ if (Expect('}'))
+ return;
+ do {
ParseString();
std::string name = this->String;
ExpectOrDie(':', "between name and value");
ParseString();
std::string value = this->String;
this->Command[name] = value;
- } while(Expect(','));
+ } while (Expect(','));
ExpectOrDie('}', "at end of object");
}
void ParseString()
{
this->String = "";
- if(!Expect('"')) return;
- while (!Expect('"'))
- {
+ if (!Expect('"'))
+ return;
+ while (!Expect('"')) {
Expect('\\');
- this->String.append(1,C);
+ this->String.append(1, C);
Next();
- }
+ }
}
bool Expect(char c)
{
- if(this->C == c)
- {
+ if (this->C == c) {
NextNonWhitespace();
return true;
- }
+ }
return false;
}
- void ExpectOrDie(char c, const std::string & message)
+ void ExpectOrDie(char c, const std::string& message)
{
if (!Expect(c))
ErrorExit(std::string("'") + c + "' expected " + message + ".");
@@ -91,51 +90,54 @@ private:
void NextNonWhitespace()
{
- do { Next(); } while (IsWhitespace());
+ do {
+ Next();
+ } while (IsWhitespace());
}
void Next()
{
this->C = char(Input->get());
- if (this->Input->bad()) ErrorExit("Unexpected end of file.");
+ if (this->Input->bad())
+ ErrorExit("Unexpected end of file.");
}
- void ErrorExit(const std::string &message) {
+ void ErrorExit(const std::string& message)
+ {
std::cout << "ERROR: " << message;
exit(1);
}
bool IsWhitespace()
{
- return (this->C == ' ' || this->C == '\t' ||
- this->C == '\n' || this->C == '\r');
+ return (this->C == ' ' || this->C == '\t' || this->C == '\n' ||
+ this->C == '\r');
}
char C;
TranslationUnitsType TranslationUnits;
CommandType Command;
std::string String;
- std::ifstream *Input;
+ std::ifstream* Input;
};
-int main ()
+int main()
{
std::ifstream file("compile_commands.json");
CompileCommandParser parser(&file);
parser.Parse();
- for(CompileCommandParser::TranslationUnitsType::const_iterator
- it = parser.GetTranslationUnits().begin(),
- end = parser.GetTranslationUnits().end(); it != end; ++it)
- {
+ for (CompileCommandParser::TranslationUnitsType::const_iterator
+ it = parser.GetTranslationUnits().begin(),
+ end = parser.GetTranslationUnits().end();
+ it != end; ++it) {
std::vector<std::string> command;
cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command);
- if (!cmSystemTools::RunSingleCommand(
- command, 0, 0, 0, it->at("directory").c_str()))
- {
- std::cout << "ERROR: Failed to run command \""
- << command[0] << "\"" << std::endl;
+ if (!cmSystemTools::RunSingleCommand(command, 0, 0, 0,
+ it->at("directory").c_str())) {
+ std::cout << "ERROR: Failed to run command \"" << command[0] << "\""
+ << std::endl;
exit(1);
- }
}
+ }
return 0;
}
diff --git a/Tests/CMakeLib/testGeneratedFileStream.cxx b/Tests/CMakeLib/testGeneratedFileStream.cxx
index f8ca4af..128cab4 100644
--- a/Tests/CMakeLib/testGeneratedFileStream.cxx
+++ b/Tests/CMakeLib/testGeneratedFileStream.cxx
@@ -12,10 +12,11 @@
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
-#define cmFailed(m1, m2) \
- std::cout << "FAILED: " << m1 << m2 << "\n"; failed=1
+#define cmFailed(m1, m2) \
+ std::cout << "FAILED: " << m1 << m2 << "\n"; \
+ failed = 1
-int testGeneratedFileStream(int, char*[])
+int testGeneratedFileStream(int, char* [])
{
int failed = 0;
cmGeneratedFileStream gm;
@@ -39,54 +40,47 @@ int testGeneratedFileStream(int, char*[])
gm.Open(file4.c_str());
gm << "This is generated file 4";
gm.Close();
- if ( cmSystemTools::FileExists(file1.c_str()) )
- {
- if ( cmSystemTools::FileExists(file2.c_str()) )
- {
- if ( cmSystemTools::FileExists(file3.c_str()) )
- {
- if ( cmSystemTools::FileExists(file4.c_str()) )
- {
- if ( cmSystemTools::FileExists(file1tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str());
- }
- else if ( cmSystemTools::FileExists(file2tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str());
- }
- else if ( cmSystemTools::FileExists(file3tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str());
- }
- else if ( cmSystemTools::FileExists(file4tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str());
- }
- else
- {
+ if (cmSystemTools::FileExists(file1.c_str())) {
+ if (cmSystemTools::FileExists(file2.c_str())) {
+ if (cmSystemTools::FileExists(file3.c_str())) {
+ if (cmSystemTools::FileExists(file4.c_str())) {
+ if (cmSystemTools::FileExists(file1tmp.c_str())) {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary "
+ "file is still here: ",
+ file1tmp.c_str());
+ } else if (cmSystemTools::FileExists(file2tmp.c_str())) {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary "
+ "file is still here: ",
+ file2tmp.c_str());
+ } else if (cmSystemTools::FileExists(file3tmp.c_str())) {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary "
+ "file is still here: ",
+ file3tmp.c_str());
+ } else if (cmSystemTools::FileExists(file4tmp.c_str())) {
+ cmFailed("Something wrong with cmGeneratedFileStream. Temporary "
+ "file is still here: ",
+ file4tmp.c_str());
+ } else {
std::cout << "cmGeneratedFileStream works\n";
- }
}
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str());
- }
- }
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str());
+ } else {
+ cmFailed(
+ "Something wrong with cmGeneratedFileStream. Cannot find file: ",
+ file4.c_str());
}
+ } else {
+ cmFailed("Something wrong with cmGeneratedFileStream. Found file: ",
+ file3.c_str());
}
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str());
- }
- }
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str());
+ } else {
+ cmFailed(
+ "Something wrong with cmGeneratedFileStream. Cannot find file: ",
+ file2.c_str());
}
+ } else {
+ cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ",
+ file1.c_str());
+ }
cmSystemTools::RemoveFile(file1.c_str());
cmSystemTools::RemoveFile(file2.c_str());
cmSystemTools::RemoveFile(file3.c_str());
diff --git a/Tests/CMakeLib/testRST.cxx b/Tests/CMakeLib/testRST.cxx
index 37cb3fa..a575d0d 100644
--- a/Tests/CMakeLib/testRST.cxx
+++ b/Tests/CMakeLib/testRST.cxx
@@ -15,67 +15,57 @@
void reportLine(std::ostream& os, bool ret, std::string line, bool eol)
{
- if(ret)
- {
- os << "\"" << line << "\" (" << (eol?"with EOL":"without EOL") << ")";
- }
- else
- {
+ if (ret) {
+ os << "\"" << line << "\" (" << (eol ? "with EOL" : "without EOL") << ")";
+ } else {
os << "EOF";
- }
+ }
}
int testRST(int argc, char* argv[])
{
- if(argc != 2)
- {
+ if (argc != 2) {
std::cerr << "Usage: testRST <dir>" << std::endl;
return 1;
- }
+ }
std::string dir = argv[1];
- if(dir.empty())
- {
+ if (dir.empty()) {
dir = ".";
- }
+ }
std::string a_name = "testRST.actual";
std::string e_name = dir + "/testRST.expect";
// Process the test RST file.
{
- std::string fname = dir + "/testRST.rst";
- std::ofstream fout(a_name.c_str());
- if(!fout)
- {
- std::cerr << "Could not open output " << a_name << std::endl;
- return 1;
+ std::string fname = dir + "/testRST.rst";
+ std::ofstream fout(a_name.c_str());
+ if (!fout) {
+ std::cerr << "Could not open output " << a_name << std::endl;
+ return 1;
}
- cmRST r(fout, dir);
- if(!r.ProcessFile(fname))
- {
- std::cerr << "Could not open input " << fname << std::endl;
- return 1;
+ cmRST r(fout, dir);
+ if (!r.ProcessFile(fname)) {
+ std::cerr << "Could not open input " << fname << std::endl;
+ return 1;
}
}
// Compare expected and actual outputs.
std::ifstream e_fin(e_name.c_str());
std::ifstream a_fin(a_name.c_str());
- if(!e_fin)
- {
+ if (!e_fin) {
std::cerr << "Could not open input " << e_name << std::endl;
return 1;
- }
- if(!a_fin)
- {
+ }
+ if (!a_fin) {
std::cerr << "Could not open input " << a_name << std::endl;
return 1;
- }
+ }
int lineno = 0;
bool e_ret;
bool a_ret;
- do
- {
+ do {
std::string e_line;
std::string a_line;
bool e_eol;
@@ -83,11 +73,11 @@ int testRST(int argc, char* argv[])
e_ret = cmSystemTools::GetLineFromStream(e_fin, e_line, &e_eol);
a_ret = cmSystemTools::GetLineFromStream(a_fin, a_line, &a_eol);
++lineno;
- if(e_ret != a_ret || e_line != a_line || e_eol != a_eol)
- {
+ if (e_ret != a_ret || e_line != a_line || e_eol != a_eol) {
a_fin.seekg(0, std::ios::beg);
std::cerr << "Actual output does not match that expected on line "
- << lineno << "." << std::endl << "Expected ";
+ << lineno << "." << std::endl
+ << "Expected ";
reportLine(std::cerr, e_ret, e_line, e_eol);
std::cerr << " but got ";
reportLine(std::cerr, a_ret, a_line, a_eol);
@@ -95,7 +85,7 @@ int testRST(int argc, char* argv[])
<< "Actual output:" << std::endl
<< a_fin.rdbuf();
return 1;
- }
- } while(e_ret && a_ret);
+ }
+ } while (e_ret && a_ret);
return 0;
}
diff --git a/Tests/CMakeLib/testSystemTools.cxx b/Tests/CMakeLib/testSystemTools.cxx
index 9309ae3..a3846c0 100644
--- a/Tests/CMakeLib/testSystemTools.cxx
+++ b/Tests/CMakeLib/testSystemTools.cxx
@@ -12,22 +12,21 @@
#include "cmSystemTools.h"
#define cmPassed(m) std::cout << "Passed: " << m << "\n"
-#define cmFailed(m) std::cout << "FAILED: " << m << "\n"; failed=1
+#define cmFailed(m) \
+ std::cout << "FAILED: " << m << "\n"; \
+ failed = 1
-int testSystemTools(int, char*[])
+int testSystemTools(int, char* [])
{
int failed = 0;
// ----------------------------------------------------------------------
// Test cmSystemTools::UpperCase
std::string str = "abc";
std::string strupper = "ABC";
- if(cmSystemTools::UpperCase(str) == strupper)
- {
+ if (cmSystemTools::UpperCase(str) == strupper) {
cmPassed("cmSystemTools::UpperCase is working");
- }
- else
- {
+ } else {
cmFailed("cmSystemTools::UpperCase is working");
- }
+ }
return failed;
}
diff --git a/Tests/CMakeLib/testUTF8.cxx b/Tests/CMakeLib/testUTF8.cxx
index 204a717..1da23fe 100644
--- a/Tests/CMakeLib/testUTF8.cxx
+++ b/Tests/CMakeLib/testUTF8.cxx
@@ -19,8 +19,8 @@ typedef char test_utf8_char[5];
static void test_utf8_char_print(test_utf8_char const c)
{
unsigned char const* d = reinterpret_cast<unsigned char const*>(c);
- printf("[0x%02X,0x%02X,0x%02X,0x%02X]",
- (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ printf("[0x%02X,0x%02X,0x%02X,0x%02X]", (int)d[0], (int)d[1], (int)d[2],
+ (int)d[3]);
}
struct test_utf8_entry
@@ -31,33 +31,29 @@ struct test_utf8_entry
};
static test_utf8_entry const good_entry[] = {
- {1, "\x20\x00\x00\x00", 0x0020}, /* Space. */
- {2, "\xC2\xA9\x00\x00", 0x00A9}, /* Copyright. */
- {3, "\xE2\x80\x98\x00", 0x2018}, /* Open-single-quote. */
- {3, "\xE2\x80\x99\x00", 0x2019}, /* Close-single-quote. */
- {4, "\xF0\xA3\x8E\xB4", 0x233B4}, /* Example from RFC 3629. */
- {0, {0,0,0,0,0}, 0}
+ { 1, "\x20\x00\x00\x00", 0x0020 }, /* Space. */
+ { 2, "\xC2\xA9\x00\x00", 0x00A9 }, /* Copyright. */
+ { 3, "\xE2\x80\x98\x00", 0x2018 }, /* Open-single-quote. */
+ { 3, "\xE2\x80\x99\x00", 0x2019 }, /* Close-single-quote. */
+ { 4, "\xF0\xA3\x8E\xB4", 0x233B4 }, /* Example from RFC 3629. */
+ { 0, { 0, 0, 0, 0, 0 }, 0 }
};
static test_utf8_char const bad_chars[] = {
- "\x80\x00\x00\x00",
- "\xC0\x00\x00\x00",
- "\xE0\x00\x00\x00",
- "\xE0\x80\x80\x00",
- "\xF0\x80\x80\x80",
- {0,0,0,0,0}
+ "\x80\x00\x00\x00", "\xC0\x00\x00\x00", "\xE0\x00\x00\x00",
+ "\xE0\x80\x80\x00", "\xF0\x80\x80\x80", { 0, 0, 0, 0, 0 }
};
static void report_good(bool passed, test_utf8_char const c)
{
- printf("%s: decoding good ", passed?"pass":"FAIL");
+ printf("%s: decoding good ", passed ? "pass" : "FAIL");
test_utf8_char_print(c);
printf(" (%s) ", c);
}
static void report_bad(bool passed, test_utf8_char const c)
{
- printf("%s: decoding bad ", passed?"pass":"FAIL");
+ printf("%s: decoding bad ", passed ? "pass" : "FAIL");
test_utf8_char_print(c);
printf(" ");
}
@@ -65,25 +61,23 @@ static void report_bad(bool passed, test_utf8_char const c)
static bool decode_good(test_utf8_entry const entry)
{
unsigned int uc;
- if(const char* e = cm_utf8_decode_character(entry.str, entry.str+4, &uc))
- {
- int used = static_cast<int>(e-entry.str);
- if(uc != entry.chr)
- {
+ if (const char* e =
+ cm_utf8_decode_character(entry.str, entry.str + 4, &uc)) {
+ int used = static_cast<int>(e - entry.str);
+ if (uc != entry.chr) {
report_good(false, entry.str);
printf("expected 0x%04X, got 0x%04X\n", entry.chr, uc);
return false;
- }
- if(used != entry.n)
- {
+ }
+ if (used != entry.n) {
report_good(false, entry.str);
printf("had %d bytes, used %d\n", entry.n, used);
return false;
- }
+ }
report_good(true, entry.str);
printf("got 0x%04X\n", uc);
return true;
- }
+ }
report_good(false, entry.str);
printf("failed\n");
return false;
@@ -92,34 +86,29 @@ static bool decode_good(test_utf8_entry const entry)
static bool decode_bad(test_utf8_char const s)
{
unsigned int uc = 0xFFFFu;
- const char* e = cm_utf8_decode_character(s, s+4, &uc);
- if(e)
- {
+ const char* e = cm_utf8_decode_character(s, s + 4, &uc);
+ if (e) {
report_bad(false, s);
printf("expected failure, got 0x%04X\n", uc);
return false;
- }
+ }
report_bad(true, s);
printf("failed as expected\n");
return true;
}
-int testUTF8(int, char*[])
+int testUTF8(int, char* [])
{
int result = 0;
- for(test_utf8_entry const* e = good_entry; e->n; ++e)
- {
- if(!decode_good(*e))
- {
+ for (test_utf8_entry const* e = good_entry; e->n; ++e) {
+ if (!decode_good(*e)) {
result = 1;
- }
}
- for(test_utf8_char const* c = bad_chars; (*c)[0]; ++c)
- {
- if(!decode_bad(*c))
- {
+ }
+ for (test_utf8_char const* c = bad_chars; (*c)[0]; ++c) {
+ if (!decode_bad(*c)) {
result = 1;
- }
}
+ }
return result;
}
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser.cxx b/Tests/CMakeLib/testVisualStudioSlnParser.cxx
index b31cc47..f8bcfae 100644
--- a/Tests/CMakeLib/testVisualStudioSlnParser.cxx
+++ b/Tests/CMakeLib/testVisualStudioSlnParser.cxx
@@ -8,177 +8,149 @@
static bool parsedRight(cmVisualStudioSlnParser& parser,
const std::string& file, cmSlnData& data,
cmVisualStudioSlnParser::ParseResult expected =
- cmVisualStudioSlnParser::ResultOK)
+ cmVisualStudioSlnParser::ResultOK)
{
- if (parser.ParseFile(SOURCE_DIR "/testVisualStudioSlnParser_data/" + file
- + "." SLN_EXTENSION,
- data, cmVisualStudioSlnParser::DataGroupProjects))
- {
- if (expected == cmVisualStudioSlnParser::ResultOK)
- {
+ if (parser.ParseFile(SOURCE_DIR "/testVisualStudioSlnParser_data/" + file +
+ "." SLN_EXTENSION,
+ data, cmVisualStudioSlnParser::DataGroupProjects)) {
+ if (expected == cmVisualStudioSlnParser::ResultOK) {
return true;
- }
}
- else
- {
- if (parser.GetParseResult() == expected)
- {
+ } else {
+ if (parser.GetParseResult() == expected) {
return true;
- }
}
+ }
std::cerr << "cmVisualStudioSlnParser mis-parsed " << file
<< "." SLN_EXTENSION << "; expected result " << expected
- << ", got " << parser.GetParseResult()
- << std::endl;
+ << ", got " << parser.GetParseResult() << std::endl;
return false;
}
-int testVisualStudioSlnParser(int, char*[])
+int testVisualStudioSlnParser(int, char* [])
{
cmVisualStudioSlnParser parser;
// Test clean parser
- if (parser.GetParseResult() != cmVisualStudioSlnParser::ResultOK)
- {
- std::cerr << "cmVisualStudioSlnParser initialisation failed"
- << std::endl;
+ if (parser.GetParseResult() != cmVisualStudioSlnParser::ResultOK) {
+ std::cerr << "cmVisualStudioSlnParser initialisation failed" << std::endl;
return 1;
- }
+ }
// Test parsing valid sln
{
- cmSlnData data;
- if (!parsedRight(parser, "valid", data))
- {
- return 1;
+ cmSlnData data;
+ if (!parsedRight(parser, "valid", data)) {
+ return 1;
}
- const std::vector<cmSlnProjectEntry>& projects = data.GetProjects();
- const char * const names[] =
- {
- "3rdParty", "ALL_BUILD", "CMakeLib", "CMakeLibTests",
- "CMakePredefinedTargets", "CPackLib", "CTestDashboardTargets", "CTestLib",
- "Continuous", "Documentation",
- "Experimental", "INSTALL", "KWSys", "LIBCURL", "Nightly",
- "NightlyMemoryCheck", "PACKAGE", "RUN_TESTS", "Tests", "Utilities",
- "Win9xCompat", "ZERO_CHECK", "cmIML_test", "cmake", "cmbzip2", "cmcldeps",
- "cmcompress", "cmcurl", "cmexpat", "cmlibarchive", "cmsys",
- "cmsysEncodeExecutable", "cmsysProcessFwd9x", "cmsysTestDynload",
- "cmsysTestProcess", "cmsysTestSharedForward", "cmsysTestsC",
- "cmsysTestsCxx", "cmsys_c", "cmw9xcom", "cmzlib", "cpack", "ctest",
- "documentation", "memcheck_fail", "pseudo_BC", "pseudo_purify",
- "pseudo_valgrind", "test_clean", "uninstall"
- /* clang-format needs this comment to break after the opening brace */
+ const std::vector<cmSlnProjectEntry>& projects = data.GetProjects();
+ const char* const names[] = {
+ "3rdParty", "ALL_BUILD", "CMakeLib", "CMakeLibTests",
+ "CMakePredefinedTargets", "CPackLib", "CTestDashboardTargets",
+ "CTestLib", "Continuous", "Documentation", "Experimental", "INSTALL",
+ "KWSys", "LIBCURL", "Nightly", "NightlyMemoryCheck", "PACKAGE",
+ "RUN_TESTS", "Tests", "Utilities", "Win9xCompat", "ZERO_CHECK",
+ "cmIML_test", "cmake", "cmbzip2", "cmcldeps", "cmcompress", "cmcurl",
+ "cmexpat", "cmlibarchive", "cmsys", "cmsysEncodeExecutable",
+ "cmsysProcessFwd9x", "cmsysTestDynload", "cmsysTestProcess",
+ "cmsysTestSharedForward", "cmsysTestsC", "cmsysTestsCxx", "cmsys_c",
+ "cmw9xcom", "cmzlib", "cpack", "ctest", "documentation", "memcheck_fail",
+ "pseudo_BC", "pseudo_purify", "pseudo_valgrind", "test_clean",
+ "uninstall"
+ /* clang-format needs this comment to break after the opening brace */
};
- const size_t expectedProjectCount = sizeof(names) / sizeof(*names);
- if (projects.size() != expectedProjectCount)
- {
- std::cerr << "cmVisualStudioSlnParser returned bad number of "
- << "projects (" << projects.size() << " instead of "
- << expectedProjectCount << ')'
- << std::endl;
- return 1;
- }
- for (size_t idx = 0; idx < expectedProjectCount; ++idx)
- {
- if (projects[idx].GetName() != names[idx])
- {
- std::cerr << "cmVisualStudioSlnParser returned bad project #"
- << idx << "; expected \"" << names[idx] << "\", got \""
- << projects[idx].GetName() << '"'
- << std::endl;
+ const size_t expectedProjectCount = sizeof(names) / sizeof(*names);
+ if (projects.size() != expectedProjectCount) {
+ std::cerr << "cmVisualStudioSlnParser returned bad number of "
+ << "projects (" << projects.size() << " instead of "
+ << expectedProjectCount << ')' << std::endl;
return 1;
+ }
+ for (size_t idx = 0; idx < expectedProjectCount; ++idx) {
+ if (projects[idx].GetName() != names[idx]) {
+ std::cerr << "cmVisualStudioSlnParser returned bad project #" << idx
+ << "; expected \"" << names[idx] << "\", got \""
+ << projects[idx].GetName() << '"' << std::endl;
+ return 1;
}
}
- if (projects[0].GetRelativePath() != "Utilities\\3rdParty")
- {
- std::cerr << "cmVisualStudioSlnParser returned bad relative path of "
- << "project 3rdParty; expected \"Utilities\\3rdParty\", "
- << "got \"" << projects[0].GetRelativePath() << '"'
- << std::endl;
- return 1;
+ if (projects[0].GetRelativePath() != "Utilities\\3rdParty") {
+ std::cerr << "cmVisualStudioSlnParser returned bad relative path of "
+ << "project 3rdParty; expected \"Utilities\\3rdParty\", "
+ << "got \"" << projects[0].GetRelativePath() << '"'
+ << std::endl;
+ return 1;
}
- if (projects[2].GetGUID() != "{59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}")
- {
- std::cerr << "cmVisualStudioSlnParser returned bad relative path of "
- << "project CMakeLib; expected "
- << "\"{59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}\", "
- << "got \"" << projects[2].GetGUID() << '"'
- << std::endl;
- return 1;
+ if (projects[2].GetGUID() != "{59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}") {
+ std::cerr << "cmVisualStudioSlnParser returned bad relative path of "
+ << "project CMakeLib; expected "
+ << "\"{59BCCCCD-3AD1-4491-B8F4-C5793AC007E2}\", "
+ << "got \"" << projects[2].GetGUID() << '"' << std::endl;
+ return 1;
}
}
// Test BOM parsing
{
- cmSlnData data;
+ cmSlnData data;
- if (!parsedRight(parser, "bom", data))
- {
- return 1;
+ if (!parsedRight(parser, "bom", data)) {
+ return 1;
}
- if (!parser.GetParseHadBOM())
- {
- std::cerr << "cmVisualStudioSlnParser didn't find BOM in bom."
- << SLN_EXTENSION
- << std::endl;
- return 1;
+ if (!parser.GetParseHadBOM()) {
+ std::cerr << "cmVisualStudioSlnParser didn't find BOM in bom."
+ << SLN_EXTENSION << std::endl;
+ return 1;
}
- if (!parsedRight(parser, "nobom", data))
- {
- return 1;
+ if (!parsedRight(parser, "nobom", data)) {
+ return 1;
}
- if (parser.GetParseHadBOM())
- {
- std::cerr << "cmVisualStudioSlnParser found BOM in nobom."
- << SLN_EXTENSION
- << std::endl;
- return 1;
+ if (parser.GetParseHadBOM()) {
+ std::cerr << "cmVisualStudioSlnParser found BOM in nobom."
+ << SLN_EXTENSION << std::endl;
+ return 1;
}
}
// Test invalid sln
{
- {
- cmSlnData data;
- if (!parsedRight(parser, "err-nonexistent", data,
- cmVisualStudioSlnParser::ResultErrorOpeningInput))
{
- return 1;
+ cmSlnData data;
+ if (!parsedRight(parser, "err-nonexistent", data,
+ cmVisualStudioSlnParser::ResultErrorOpeningInput)) {
+ return 1;
+ }
}
- }
- {
- cmSlnData data;
- if (!parsedRight(parser, "err-empty", data,
- cmVisualStudioSlnParser::ResultErrorReadingInput))
{
- return 1;
+ cmSlnData data;
+ if (!parsedRight(parser, "err-empty", data,
+ cmVisualStudioSlnParser::ResultErrorReadingInput)) {
+ return 1;
+ }
}
- }
- const char * const files[] =
- {
- "header", "projectArgs", "topLevel", "projectContents", "projectSection",
- "global", "unclosed", "strayQuote", "strayParen", "strayQuote2"
- /* clang-format needs this comment to break after the opening brace */
+ const char* const files[] = {
+ "header", "projectArgs", "topLevel", "projectContents",
+ "projectSection", "global", "unclosed", "strayQuote",
+ "strayParen", "strayQuote2"
+ /* clang-format needs this comment to break after the opening brace */
};
- for (size_t idx = 0; idx < sizeof(files) / sizeof(files[0]); ++idx)
- {
- cmSlnData data;
- if (!parsedRight(parser, std::string("err-structure-") + files[idx], data,
- cmVisualStudioSlnParser::ResultErrorInputStructure))
- {
- return 1;
+ for (size_t idx = 0; idx < sizeof(files) / sizeof(files[0]); ++idx) {
+ cmSlnData data;
+ if (!parsedRight(parser, std::string("err-structure-") + files[idx],
+ data,
+ cmVisualStudioSlnParser::ResultErrorInputStructure)) {
+ return 1;
}
}
- {
- cmSlnData data;
- if (!parsedRight(parser, "err-data", data,
- cmVisualStudioSlnParser::ResultErrorInputData))
{
- return 1;
+ cmSlnData data;
+ if (!parsedRight(parser, "err-data", data,
+ cmVisualStudioSlnParser::ResultErrorInputData)) {
+ return 1;
+ }
}
}
- }
// All is well
return 0;
diff --git a/Tests/CMakeLib/testXMLParser.cxx b/Tests/CMakeLib/testXMLParser.cxx
index b5219e2..1fd5113 100644
--- a/Tests/CMakeLib/testXMLParser.cxx
+++ b/Tests/CMakeLib/testXMLParser.cxx
@@ -4,14 +4,13 @@
#include <iostream>
-int testXMLParser(int, char*[])
+int testXMLParser(int, char* [])
{
// TODO: Derive from parser and check attributes.
cmXMLParser parser;
- if(!parser.ParseFile(SOURCE_DIR "/testXMLParser.xml"))
- {
+ if (!parser.ParseFile(SOURCE_DIR "/testXMLParser.xml")) {
std::cerr << "cmXMLParser failed!" << std::endl;
return 1;
- }
+ }
return 0;
}
diff --git a/Tests/CMakeLib/testXMLSafe.cxx b/Tests/CMakeLib/testXMLSafe.cxx
index 9e4960c..34c38fb 100644
--- a/Tests/CMakeLib/testXMLSafe.cxx
+++ b/Tests/CMakeLib/testXMLSafe.cxx
@@ -20,28 +20,26 @@ struct test_pair
};
static test_pair const pairs[] = {
- {"copyright \xC2\xA9", "copyright \xC2\xA9"},
- {"form-feed \f", "form-feed [NON-XML-CHAR-0xC]"},
- {"angles <>", "angles &lt;&gt;"},
- {"ampersand &", "ampersand &amp;"},
- {"bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]"},
- {0,0}
+ { "copyright \xC2\xA9", "copyright \xC2\xA9" },
+ { "form-feed \f", "form-feed [NON-XML-CHAR-0xC]" },
+ { "angles <>", "angles &lt;&gt;" },
+ { "ampersand &", "ampersand &amp;" },
+ { "bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]" },
+ { 0, 0 }
};
-int testXMLSafe(int, char*[])
+int testXMLSafe(int, char* [])
{
int result = 0;
- for(test_pair const* p = pairs; p->in; ++p)
- {
+ for (test_pair const* p = pairs; p->in; ++p) {
cmXMLSafe xs(p->in);
std::ostringstream oss;
oss << xs;
std::string out = oss.str();
- if(out != p->out)
- {
+ if (out != p->out) {
printf("expected [%s], got [%s]\n", p->out, out.c_str());
result = 1;
- }
}
+ }
return result;
}