From cbb8360b30d6ac872c8f5b5ebc86e3a02e9e8c2b Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 29 Sep 2014 16:25:35 +0200 Subject: [PATCH] Added version attribute to .cfg files (#5928) --- cfg/avr.cfg | 2 +- cfg/gtk.cfg | 2 +- cfg/posix.cfg | 2 +- cfg/qt.cfg | 2 +- cfg/sdl.cfg | 2 +- cfg/std.cfg | 2 +- cfg/windows.cfg | 2 +- cli/cmdlineparser.cpp | 3 +++ lib/library.cpp | 8 ++++++++ lib/library.h | 2 +- test/testlibrary.cpp | 37 +++++++++++++++++++++++++++++++++++++ 11 files changed, 56 insertions(+), 8 deletions(-) diff --git a/cfg/avr.cfg b/cfg/avr.cfg index cc6b3f388..35a7622c5 100644 --- a/cfg/avr.cfg +++ b/cfg/avr.cfg @@ -1,6 +1,6 @@ - + diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index 5071aa3a7..651fdf60e 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -1,6 +1,6 @@ - + diff --git a/cfg/posix.cfg b/cfg/posix.cfg index e05ef139c..755f648da 100644 --- a/cfg/posix.cfg +++ b/cfg/posix.cfg @@ -1,5 +1,5 @@ - + false 0:999999 true false diff --git a/cfg/qt.cfg b/cfg/qt.cfg index 88a836b72..eb972b8da 100644 --- a/cfg/qt.cfg +++ b/cfg/qt.cfg @@ -1,5 +1,5 @@ - + diff --git a/cfg/sdl.cfg b/cfg/sdl.cfg index a8eaeabb8..452a0b5ef 100644 --- a/cfg/sdl.cfg +++ b/cfg/sdl.cfg @@ -1,5 +1,5 @@ - + false false false diff --git a/cfg/std.cfg b/cfg/std.cfg index 4a798f0e0..7b74e6335 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1,5 +1,5 @@ - + true false false diff --git a/cfg/windows.cfg b/cfg/windows.cfg index 98240c663..8480b6785 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -1,5 +1,5 @@ - + CreatePen CreateBrushIndirect diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index d45b6e5c9..31d786e24 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -531,6 +531,9 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) case Library::BAD_ATTRIBUTE_VALUE: errmsg = "Bad attribute value"; break; + case Library::UNSUPPORTED_FORMAT: + errmsg = "File is of unsupported format version"; + break; } if (!err.reason.empty()) errmsg += " '" + err.reason + "'"; diff --git a/lib/library.cpp b/lib/library.cpp index 27dde7a9d..a8fddffce 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -93,6 +93,14 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) if (strcmp(rootnode->Name(),"def") != 0) return Error(BAD_ELEMENT, rootnode->Name()); + const char* format_string = rootnode->Attribute("format"); + int format = 1; + if (format_string) + format = atoi(format_string); + + if (format > 1) + return Error(UNSUPPORTED_FORMAT); + for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { std::string nodename = node->Name(); if (nodename == "memory" || nodename == "resource") { diff --git a/lib/library.h b/lib/library.h index d02c2d005..c4cf908e0 100644 --- a/lib/library.h +++ b/lib/library.h @@ -46,7 +46,7 @@ class CPPCHECKLIB Library { public: Library(); - enum ErrorCode { OK, FILE_NOT_FOUND, BAD_XML, BAD_ELEMENT, MISSING_ATTRIBUTE, BAD_ATTRIBUTE, BAD_ATTRIBUTE_VALUE }; + enum ErrorCode { OK, FILE_NOT_FOUND, BAD_XML, BAD_ELEMENT, MISSING_ATTRIBUTE, BAD_ATTRIBUTE, BAD_ATTRIBUTE_VALUE, UNSUPPORTED_FORMAT }; class Error { public: diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index 8934b4aee..88336984d 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -39,6 +39,7 @@ private: TEST_CASE(memory2); // define extra "free" allocation functions TEST_CASE(resource); TEST_CASE(podtype); + TEST_CASE(version); } void empty() const { @@ -274,6 +275,42 @@ private: ASSERT_EQUALS(2U, type ? type->size : 0U); ASSERT_EQUALS(0, type ? type->sign : '?'); } + + void version() const { + { + const char xmldata [] = "\n" + "\n" + ""; + tinyxml2::XMLDocument doc; + doc.Parse(xmldata, sizeof(xmldata)); + + Library library; + Library::Error err = library.load(doc); + ASSERT_EQUALS(err.errorcode, Library::OK); + } + { + const char xmldata [] = "\n" + "\n" + ""; + tinyxml2::XMLDocument doc; + doc.Parse(xmldata, sizeof(xmldata)); + + Library library; + Library::Error err = library.load(doc); + ASSERT_EQUALS(err.errorcode, Library::OK); + } + { + const char xmldata [] = "\n" + "\n" + ""; + tinyxml2::XMLDocument doc; + doc.Parse(xmldata, sizeof(xmldata)); + + Library library; + Library::Error err = library.load(doc); + ASSERT_EQUALS(err.errorcode, Library::UNSUPPORTED_FORMAT); + } + } }; REGISTER_TEST(TestLibrary)